public bool VisitToRealOp(VCExprNAry node, LineariserOptions options) { WriteApplication("to_real", node, options); return(true); }
public void Linearise(VCExpr expr, LineariserOptions options) { Contract.Requires(expr != null); Contract.Requires(options != null); expr.Accept <bool, LineariserOptions>(this, options); }
public bool VisitGeOp(VCExprNAry node, LineariserOptions options) { WriteApplication(">=", node, options); return(true); }
public bool VisitSubtype3Op(VCExprNAry node, LineariserOptions options) { WriteApplication("UOrdering3", node, options); return(true); }
public bool VisitBvConcatOp(VCExprNAry node, LineariserOptions options) { WriteApplication("concat", node, options); return(true); }
public bool VisitPowOp(VCExprNAry node, LineariserOptions options) { WriteApplication("real_pow", node, options); return(true); }
public bool VisitEqOp(VCExprNAry node, LineariserOptions options) { return(PrintEq(node, options)); }
public bool VisitIfThenElseOp(VCExprNAry node, LineariserOptions options) { WriteApplication("ite", node, options); return(true); }
/////////////////////////////////////////////////////////////////////////////////// private void WriteApplication(string opName, IEnumerable <VCExpr> /*!>!*/ args, LineariserOptions options) { Contract.Requires(cce.NonNullElements(args)); Contract.Requires(options != null); Contract.Assert(opName != null); bool hasArgs = false; foreach (VCExpr e in args) { Contract.Assert(e != null); if (!hasArgs) { wr.Write("({0}", opName); } wr.Write(" "); ExprLineariser.Linearise(e, options); hasArgs = true; } if (hasArgs) { wr.Write(")"); } else { wr.Write("{0}", opName); } }
/////////////////////////////////////////////////////////////////////////////////// public bool VisitNotOp(VCExprNAry node, LineariserOptions options) { WriteApplication("not", node, options); // arguments can be both terms and formulas return(true); }
private void WriteTriggers(List <VCTrigger /*!>!*/> triggers, LineariserOptions options) { Contract.Requires(options != null); Contract.Requires(triggers != null); // first, count how many neg/pos triggers there are int negTriggers = 0; int posTriggers = 0; foreach (VCTrigger vcTrig in triggers) { Contract.Assert(vcTrig != null); if (vcTrig.Pos) { posTriggers++; } else { negTriggers++; } } if (posTriggers > 0) { foreach (VCTrigger vcTrig in triggers) { Contract.Assert(vcTrig != null); if (vcTrig.Pos) { wr.Write(" :pattern ("); foreach (VCExpr e in vcTrig.Exprs) { Contract.Assert(e != null); wr.Write(" "); var subPat = e; var nary = e as VCExprNAry; if (nary != null && (nary.Op == VCExpressionGenerator.NeqOp || nary.Op == VCExpressionGenerator.EqOp)) { if (nary[0] is VCExprLiteral) { subPat = nary[1]; } else if (nary[1] is VCExprLiteral) { subPat = nary[0]; } } Linearise(subPat, options); } wr.Write(")\n"); } } } else if (negTriggers > 0) { // if also positive triggers are given, the SMT solver (at least Z3) // will ignore the negative patterns and output a warning. Therefore // we never specify both negative and positive triggers foreach (VCTrigger vcTrig in triggers) { Contract.Assert(vcTrig != null); if (!vcTrig.Pos) { wr.Write(" :no-pattern "); Contract.Assert(vcTrig.Exprs.Count == 1); Linearise(vcTrig.Exprs[0], options); wr.Write("\n"); } } } }
///////////////////////////////////////////////////////////////////////////////////// public bool Visit(VCExprQuantifier node, LineariserOptions options) { Contract.Assert(node.TypeParameters.Count == 0); UnderQuantifier++; Namer.PushScope(); try { string kind = node.Quan == Quantifier.ALL ? "forall" : "exists"; wr.Write("({0} (", kind); for (int i = 0; i < node.BoundVars.Count; i++) { VCExprVar var = node.BoundVars[i]; Contract.Assert(var != null); string printedName = Namer.GetQuotedLocalName(var, var.Name); Contract.Assert(printedName != null); wr.Write("({0} {1}) ", printedName, TypeToString(var.Type)); } wr.Write(") "); VCQuantifierInfos infos = node.Infos; var weight = QKeyValue.FindIntAttribute(infos.attributes, "weight", 1); if (!ProverOptions.UseWeights) { weight = 1; } var hasAttrs = node.Triggers.Count > 0 || infos.qid != null || weight != 1 || infos.uniqueId != -1; if (hasAttrs) { wr.Write("(! "); } Linearise(node.Body, options); if (hasAttrs) { wr.Write("\n"); if (infos.qid != null) { wr.Write(" :qid {0}\n", SMTLibNamer.QuoteId(infos.qid)); } if (weight != 1) { wr.Write(" :weight {0}\n", weight); } if (infos.uniqueId != -1) { wr.Write(" :skolemid |{0}|\n", infos.uniqueId); } WriteTriggers(node.Triggers, options); wr.Write(")"); } wr.Write(")"); return(true); } finally { UnderQuantifier--; Namer.PopScope(); } }
///////////////////////////////////////////////////////////////////////////////////// public bool Visit(VCExprVar node, LineariserOptions options) { wr.Write(Namer.GetQuotedName(node, node.Name)); return(true); }
public bool VisitFloatEqOp(VCExprNAry node, LineariserOptions options) { WriteApplication("fp.eq", node, options); return(true); }
///////////////////////////////////////////////////////////////////////////////////// public bool Visit(VCExprNAry node, LineariserOptions options) { VCExprOp op = node.Op; Contract.Assert(op != null); var booleanOps = new HashSet <VCExprOp>(); booleanOps.Add(VCExpressionGenerator.NotOp); booleanOps.Add(VCExpressionGenerator.ImpliesOp); booleanOps.Add(VCExpressionGenerator.AndOp); booleanOps.Add(VCExpressionGenerator.OrOp); if (booleanOps.Contains(op)) { Stack <VCExpr> exprs = new Stack <VCExpr>(); exprs.Push(node); while (exprs.Count > 0) { VCExpr expr = exprs.Pop(); if (expr == null) { wr.Write(")"); continue; } wr.Write(" "); VCExprNAry naryExpr = expr as VCExprNAry; if (naryExpr == null || !booleanOps.Contains(naryExpr.Op)) { Linearise(expr, options); continue; } else if (naryExpr.Op.Equals(VCExpressionGenerator.NotOp)) { wr.Write("(not"); } else if (naryExpr.Op.Equals(VCExpressionGenerator.ImpliesOp)) { wr.Write("(=>"); } else if (naryExpr.Op.Equals(VCExpressionGenerator.AndOp)) { wr.Write("(and"); } else { System.Diagnostics.Debug.Assert(naryExpr.Op.Equals(VCExpressionGenerator.OrOp)); wr.Write("(or"); } exprs.Push(null); for (int i = naryExpr.Arity - 1; i >= 0; i--) { exprs.Push(naryExpr[i]); } } return(true); } if (OptimizationRequests != null && (node.Op.Equals(VCExpressionGenerator.MinimizeOp) || node.Op.Equals(VCExpressionGenerator.MaximizeOp))) { string optOp = node.Op.Equals(VCExpressionGenerator.MinimizeOp) ? "minimize" : "maximize"; OptimizationRequests.Add(string.Format("({0} {1})", optOp, ToString(node[0], Namer, ProverOptions, NamedAssumes))); Linearise(node[1], options); return(true); } if (node.Op is VCExprSoftOp) { Linearise(node[1], options); return(true); } if (node.Op.Equals(VCExpressionGenerator.NamedAssumeOp)) { var exprVar = node[0] as VCExprVar; NamedAssumes.Add(exprVar); Linearise(node[1], options); return(true); } return(node.Accept <bool, LineariserOptions /*!*/>(OpLineariser, options)); }