t1 > t2
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" } }; using (Context ctx = new Context(cfg)) { RealExpr x = ctx.MkRealConst("x"); RealExpr y = ctx.MkRealConst("y"); RatNum zero = ctx.MkReal(0); RatNum two = ctx.MkReal(2); Goal g = ctx.MkGoal(); g.Assert(ctx.MkGt(x, zero)); g.Assert(ctx.MkGt(y, zero)); g.Assert(ctx.MkEq(x, ctx.MkAdd(y, two))); Console.WriteLine(g); Tactic t1 = ctx.MkTactic("simplify"); Tactic t2 = ctx.MkTactic("solve-eqs"); Tactic t = ctx.AndThen(t1, t2); Console.WriteLine(t[g]); } }
public static Expr EeAndGt(String left1, int left2, String right1, int right2) { using (Context ctx = new Context()) { Expr a = ctx.MkConst(left1, ctx.MkIntSort()); Expr b = ctx.MkNumeral(left2, ctx.MkIntSort()); Expr c = ctx.MkConst(right1, ctx.MkIntSort()); Expr d = ctx.MkNumeral(right2, ctx.MkIntSort()); Solver s = ctx.MkSolver(); s.Assert(ctx.MkAnd(ctx.MkEq((ArithExpr)a, (ArithExpr)b), ctx.MkGt((ArithExpr)c, (ArithExpr)d))); s.Check(); BoolExpr testing = ctx.MkAnd(ctx.MkEq((ArithExpr)a, (ArithExpr)b), ctx.MkGt((ArithExpr)c, (ArithExpr)d)); Model model = Check(ctx, testing, Status.SATISFIABLE); Expr result2; Model m2 = s.Model; foreach (FuncDecl d2 in m2.Decls) { result2 = m2.ConstInterp(d2); return result2; } } return null; }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" } }; using (Context ctx = new Context(cfg)) { RealExpr x = ctx.MkRealConst("x"); RealExpr y = ctx.MkRealConst("y"); Solver s = ctx.MkSolver(); s.Assert(ctx.MkGt(x, ctx.MkReal(1)), ctx.MkGt(y, ctx.MkReal(1)), ctx.MkOr(ctx.MkGt(ctx.MkAdd(x, y), ctx.MkReal(1)), ctx.MkLt(ctx.MkSub(x, y), ctx.MkReal(2)))); Console.WriteLine("asserted constraints: "); foreach (var c in s.Assertions) Console.WriteLine(c); Console.WriteLine(s.Check()); Console.WriteLine(s.Statistics); Console.WriteLine("stats for last check: "); foreach (Statistics.Entry e in s.Statistics.Entries) Console.WriteLine(e); } }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" } }; using (Context ctx = new Context(cfg)) { BoolExpr p1 = ctx.MkBoolConst("p1"); BoolExpr p2 = ctx.MkBoolConst("p2"); BoolExpr p3 = ctx.MkBoolConst("p3"); IntExpr x = ctx.MkIntConst("x"); IntExpr y = ctx.MkIntConst("y"); Solver s = ctx.MkSolver(); s.Assert(ctx.MkImplies(p1, ctx.MkGt(x, ctx.MkInt(10))), ctx.MkImplies(p1, ctx.MkGt(y, x)), ctx.MkImplies(p2, ctx.MkLt(y, ctx.MkInt(5))), ctx.MkImplies(p3, ctx.MkGt(y, ctx.MkInt(0)))); Console.WriteLine(s); Console.WriteLine(s.Check(p1, p2, p3)); Console.WriteLine("Core: "); foreach (Expr e in s.UnsatCore) Console.WriteLine(e); Console.WriteLine(s.Check(p1, p3)); Console.WriteLine(s.Model); } }
public void Run() { using (Context ctx = new Context()) { ctx.UpdateParamValue("DL_ENGINE","1"); ctx.UpdateParamValue("DL_PDR_USE_FARKAS","true"); // ctx.UpdateParamValue("VERBOSE","2"); var s = ctx.MkFixedpoint(); BoolSort B = ctx.BoolSort; IntSort I = ctx.IntSort; FuncDecl mc = ctx.MkFuncDecl("mc", new Sort[]{I, I}, B); ArithExpr x = (ArithExpr)ctx.MkBound(0,I); ArithExpr y = (ArithExpr)ctx.MkBound(1,I); ArithExpr z = (ArithExpr)ctx.MkBound(2,I); s.RegisterRelation(mc); BoolExpr gt = ctx.MkGt(x, ctx.MkInt(100)); s.AddRule(ctx.MkImplies(gt,(BoolExpr)mc[x,ctx.MkSub(x,ctx.MkInt(10))])); s.AddRule(ctx.MkImplies(ctx.MkAnd(ctx.MkNot(gt), (BoolExpr) mc[ctx.MkAdd(x,ctx.MkInt(11)),y], (BoolExpr) mc[y,z]), (BoolExpr) mc[x,z])); Console.WriteLine(s.Query(ctx.MkAnd((BoolExpr)mc[x,y], ctx.MkGt(y,ctx.MkInt(100))))); Console.WriteLine(s.GetAnswer()); Console.WriteLine(s.Query(ctx.MkAnd((BoolExpr)mc[x,y], ctx.MkLt(y,ctx.MkInt(91))))); Console.WriteLine(s.GetAnswer()); } }
public void Run() { using (Context ctx = new Context()) { RealExpr x = ctx.MkRealConst("x"); RealExpr y = ctx.MkRealConst("y"); RealExpr z = ctx.MkRealConst("z"); FuncDecl f = ctx.MkFuncDecl("f", ctx.RealSort, ctx.RealSort); Solver s = ctx.MkSolver(); s.Assert(ctx.MkGt(x, ctx.MkReal(10)), ctx.MkEq(y, ctx.MkAdd(x, ctx.MkReal(3))), ctx.MkLt(y, ctx.MkReal(15)), ctx.MkGt((RealExpr)f[x], ctx.MkReal(2)), ctx.MkNot(ctx.MkEq(f[y], f[x]))); Console.WriteLine(s.Check()); Model m = s.Model; foreach (FuncDecl fd in m.Decls) Console.Write(" " + fd.Name); Console.WriteLine(); foreach (FuncDecl fd in m.Decls) { if (fd.DomainSize == 0) Console.WriteLine(fd.Name + " -> " + m.ConstInterp(fd)); else Console.WriteLine(fd.Name + " -> " + m.FuncInterp(fd)); } Console.WriteLine(m.Evaluate(ctx.MkAdd(z, ctx.MkReal(1)))); Console.WriteLine(m.Evaluate(ctx.MkAdd(z, ctx.MkReal(1)), true)); Console.WriteLine(m.Evaluate(z)); FuncInterp fi = m.FuncInterp(f); Console.WriteLine(fi.Else); Console.WriteLine(fi.NumEntries); Console.WriteLine(fi.Entries[0]); Console.WriteLine(fi.Entries[0].NumArgs); Console.WriteLine(fi.Entries[0].Args[0]); Console.WriteLine(fi.Entries[0].Value); ArrayExpr a = ctx.MkArrayConst("a", ctx.RealSort, ctx.RealSort); s.Assert(ctx.MkGt((RealExpr)ctx.MkSelect(a, x), ctx.MkReal(10)), ctx.MkGt((RealExpr)ctx.MkSelect(a, y), ctx.MkReal(20))); Console.WriteLine(s); Console.WriteLine(s.Check()); Console.WriteLine(s.Model); Console.WriteLine(s.Model.Evaluate(a)); Console.WriteLine(s.Model.FuncInterp(a.FuncDecl)); } }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" } }; using (Context ctx = new Context(cfg)) { RealExpr x = ctx.MkRealConst("x"); RealExpr y = ctx.MkRealConst("y"); RealExpr z = ctx.MkRealConst("z"); RealExpr zero = ctx.MkReal(0); RealExpr one = ctx.MkReal(1); Goal g = ctx.MkGoal(); g.Assert(ctx.MkOr(ctx.MkEq(x, zero), ctx.MkEq(x, one))); g.Assert(ctx.MkOr(ctx.MkEq(y, zero), ctx.MkEq(y, one))); g.Assert(ctx.MkOr(ctx.MkEq(z, zero), ctx.MkEq(z, one))); g.Assert(ctx.MkGt(ctx.MkAdd(x, y, z), ctx.MkReal(2))); Tactic t = ctx.Repeat(ctx.OrElse(ctx.MkTactic("split-clause"), ctx.MkTactic("skip"))); Console.WriteLine(t[g]); t = ctx.Repeat(ctx.OrElse(ctx.MkTactic("split-clause"), ctx.MkTactic("skip")), 1); Console.WriteLine(t[g]); t = ctx.Then(ctx.Repeat(ctx.OrElse(ctx.MkTactic("split-clause"), ctx.MkTactic("skip"))), ctx.MkTactic("solve-eqs")); Console.WriteLine(t[g]); } }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" }, { "MODEL", "true" } }; using (Context ctx = new Context(cfg)) { RealExpr x = ctx.MkRealConst("x"); RealExpr y = ctx.MkRealConst("y"); Solver s = ctx.MkSolver(); s.Assert(ctx.MkAnd(ctx.MkEq(ctx.MkAdd(x, ctx.MkReal("10000000000000000000000")), y), ctx.MkGt(y, ctx.MkReal("20000000000000000")))); s.Check(); Console.WriteLine(s.Model); Expr q = ctx.MkAdd(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 2)), ctx.MkPower(ctx.MkReal(3), ctx.MkReal(1, 2))); Console.WriteLine(q); AlgebraicNum an = (AlgebraicNum)q.Simplify(); Console.WriteLine(an); Console.WriteLine("[" + an.ToLower(10) + "," + an.ToUpper(10) + "]"); Console.WriteLine(an.ToDecimal(10)); } }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" } }; using (Context ctx = new Context(cfg)) { RealExpr x = ctx.MkRealConst("x"); RealExpr y = ctx.MkRealConst("y"); RealExpr z = ctx.MkRealConst("z"); RealExpr zero = ctx.MkReal(0); RealExpr one = ctx.MkReal(1); Goal g = ctx.MkGoal(); g.Assert(ctx.MkOr(ctx.MkEq(x, zero), ctx.MkEq(x, one))); g.Assert(ctx.MkOr(ctx.MkEq(y, zero), ctx.MkEq(y, one))); g.Assert(ctx.MkOr(ctx.MkEq(z, zero), ctx.MkEq(z, one))); g.Assert(ctx.MkGt(ctx.MkAdd(x, y, z), ctx.MkReal(2))); Tactic t = ctx.Repeat(ctx.OrElse(ctx.MkTactic("split-clause"), ctx.MkTactic("skip"))); ApplyResult ar = t[g]; foreach (var sg in ar.Subgoals) Console.WriteLine(sg); } }
public void Run() { Dictionary<string, string> settings = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" }, { "MODEL", "true" } }; using (Context ctx = new Context(settings)) { IntExpr a = ctx.MkIntConst("a"); IntExpr b = ctx.MkIntConst("b"); IntExpr c = ctx.MkIntConst("c"); RealExpr d = ctx.MkRealConst("d"); RealExpr e = ctx.MkRealConst("e"); BoolExpr q = ctx.MkAnd( ctx.MkGt(a, ctx.MkAdd(b, ctx.MkInt(2))), ctx.MkEq(a, ctx.MkAdd(ctx.MkMul(ctx.MkInt(2), c), ctx.MkInt(10))), ctx.MkLe(ctx.MkAdd(c, b), ctx.MkInt(1000)), ctx.MkGe(d, e)); Solver s = ctx.MkSolver(); s.Assert(q); Console.WriteLine(s.Check()); Console.WriteLine(s.Model); } }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" } }; using (Context ctx = new Context(cfg)) { IntExpr x = ctx.MkIntConst("x"); IntExpr y = ctx.MkIntConst("y"); Solver s = ctx.MkSolver(); Console.WriteLine(s); s.Assert(ctx.MkGt(x, ctx.MkInt(10)), ctx.MkEq(y, ctx.MkAdd(x, ctx.MkInt(2)))); Console.WriteLine(s); Console.WriteLine("solving s"); Console.WriteLine(s.Check()); Console.WriteLine("creating new scope"); s.Push(); s.Assert(ctx.MkLt(y, ctx.MkInt(11))); Console.WriteLine(s); Console.WriteLine("solving updated constraints"); Console.WriteLine(s.Check()); Console.WriteLine("restoring"); s.Pop(); Console.WriteLine(s); Console.WriteLine("solving restored constraints"); Console.WriteLine(s.Check()); } }
public void Run() { using (Context ctx = new Context()) { RealExpr x = ctx.MkRealConst("x"); RealExpr y = ctx.MkRealConst("y"); Goal g = ctx.MkGoal(); g.Assert(ctx.MkGt(x, ctx.MkReal(10)), ctx.MkEq(y, ctx.MkAdd(x, ctx.MkReal(1)))); g.Assert(ctx.MkGt(y, ctx.MkReal(1))); Console.WriteLine(ctx.MkProbe("num-consts").Apply(g)); Console.WriteLine(ctx.MkProbe("size").Apply(g)); Console.WriteLine(ctx.MkProbe("num-exprs").Apply(g)); } }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" } }; using (Context ctx = new Context(cfg)) { ArithExpr[] a = new ArithExpr[5]; for (uint x = 0; x < 5; x++) a[x] = ctx.MkInt(x+1); foreach (Expr e in a) Console.WriteLine(e); ArithExpr[] X = new ArithExpr[5]; for (uint i = 0; i < 5; i++) X[i] = ctx.MkIntConst(string.Format("x{0}", i)); ArithExpr[] Y = new ArithExpr[5]; for (uint i = 0; i < 5; i++) Y[i] = ctx.MkIntConst(string.Format("y{0}", i)); foreach (Expr e in X) Console.WriteLine(e); ArithExpr[] X_plus_Y = new ArithExpr[5]; for (uint i = 0; i < 5; i++) X_plus_Y[i] = ctx.MkAdd(X[i], Y[i]); foreach (Expr e in X_plus_Y) Console.WriteLine(e); BoolExpr[] X_gt_Y = new BoolExpr[5]; for (uint i = 0; i < 5; i++) X_gt_Y[i] = ctx.MkGt(X[i], Y[i]); foreach (Expr e in X_gt_Y) Console.WriteLine(e); Console.WriteLine(ctx.MkAnd(X_gt_Y)); Expr[][] matrix = new Expr[3][]; for (uint i = 0; i < 3; i++) { matrix[i] = new Expr[3]; for (uint j = 0; j < 3; j++) matrix[i][j] = ctx.MkIntConst(string.Format("x_{0}_{1}", i + 1, j + 1)); } foreach(Expr[] row in matrix) { foreach(Expr e in row) Console.Write(" " + e); Console.WriteLine(); } } }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" } }; using (Context ctx = new Context(cfg)) { Params p = ctx.MkParams(); p.Add(":arith-lhs", true); p.Add(":som", true); Solver s = ctx.Then(ctx.With(ctx.MkTactic("simplify"), p), ctx.MkTactic("normalize-bounds"), ctx.MkTactic("lia2pb"), ctx.MkTactic("pb2bv"), ctx.MkTactic("bit-blast"), ctx.MkTactic("sat")).Solver; IntExpr x = ctx.MkIntConst("x"); IntExpr y = ctx.MkIntConst("y"); IntExpr z = ctx.MkIntConst("z"); s.Assert(new BoolExpr[] { ctx.MkGt(x, ctx.MkInt(0)), ctx.MkLt(x, ctx.MkInt(10)), ctx.MkGt(y, ctx.MkInt(0)), ctx.MkLt(y, ctx.MkInt(10)), ctx.MkGt(z, ctx.MkInt(0)), ctx.MkLt(z, ctx.MkInt(10)), ctx.MkEq(ctx.MkAdd(ctx.MkMul(ctx.MkInt(3), y), ctx.MkMul(ctx.MkInt(2), x)), z) }); Console.WriteLine(s.Check()); Console.WriteLine(s.Model); s.Reset(); s.Assert(ctx.MkEq(ctx.MkAdd(ctx.MkMul(ctx.MkInt(3), y), ctx.MkMul(ctx.MkInt(2), x)), z)); Console.WriteLine(s.Check()); } }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" } }; using (Context ctx = new Context(cfg)) { IntExpr x = ctx.MkIntConst("x"); IntExpr y = ctx.MkIntConst("y"); Solver s1 = ctx.MkSolver(); s1.Assert(new BoolExpr[] { ctx.MkGt(x, ctx.MkInt(10)), ctx.MkGt(y, ctx.MkInt(10)) }); Solver s2 = ctx.MkSolver(); Console.WriteLine(s2); s2.Assert(s1.Assertions); Console.WriteLine(s2); } }
public void Run() { using (Context ctx = new Context()) { RealExpr x = ctx.MkRealConst("x"); RealExpr y = ctx.MkRealConst("y"); Goal g = ctx.MkGoal(); g.Assert(ctx.MkGt(x, ctx.MkReal(10)), ctx.MkEq(y, ctx.MkAdd(x, ctx.MkReal(1)))); g.Assert(ctx.MkGt(y, ctx.MkReal(1))); Tactic t = ctx.MkTactic("simplify"); ApplyResult r = t.Apply(g); Console.WriteLine(r); Console.WriteLine(g.Size); foreach (Goal s in r.Subgoals) Console.WriteLine(s); Console.WriteLine("Old goal: "); Console.WriteLine(g); t = ctx.Then(ctx.MkTactic("simplify"), ctx.MkTactic("solve-eqs")); r = t.Apply(g); Console.WriteLine(r); Solver solver = ctx.MkSolver(); foreach (BoolExpr f in r.Subgoals[0].Formulas) solver.Assert(f); Console.WriteLine(solver); Console.WriteLine(solver.Check()); Console.WriteLine(solver.Model); Console.WriteLine("applying model convert"); Console.WriteLine(r.ConvertModel(0, solver.Model)); Console.WriteLine("done"); } }
public void Run() { using (Context ctx = new Context()) { FuncDecl f = ctx.MkFuncDecl("f", new Sort[] { ctx.IntSort, ctx.RealSort }, ctx.IntSort); try { Console.WriteLine(f.Domain[3]); } catch (IndexOutOfRangeException ex) { Console.WriteLine("failed: " + ex.Message); } IntExpr x = ctx.MkIntConst("x"); Console.WriteLine(f[ctx.MkInt(1), ctx.MkReal(1)]); Console.WriteLine(f[ctx.MkInt(1), ctx.MkReal(1)].Sort); Console.WriteLine(f[ctx.MkInt(1), ctx.MkReal(1)].NumArgs); foreach (Expr e in f[ctx.MkAdd(x, ctx.MkInt(1)), ctx.MkReal(1)].Args) Console.WriteLine(e); Console.WriteLine(f[ctx.MkAdd(x, ctx.MkInt(1)), ctx.MkReal(1)].Args[0]); Console.WriteLine(f[ctx.MkAdd(x, ctx.MkInt(1)), ctx.MkReal(1)].Args[0].Equals(ctx.MkAdd(x, ctx.MkInt(1)))); Console.WriteLine(f[ctx.MkAdd(x, ctx.MkInt(1)), ctx.MkReal(1)].FuncDecl[ctx.MkInt(2), ctx.MkInt2Real((IntExpr)ctx.MkAdd(x, ctx.MkInt(1)))]); Console.WriteLine(ctx.MkInt(1).IsExpr); Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1)).IsExpr); Console.WriteLine(ctx.MkForall(new Expr[] { x }, ctx.MkGt(x, ctx.MkInt(0))).IsExpr); Console.WriteLine(ctx.MkInt(1).IsConst); Console.WriteLine(x.IsConst); Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1)).IsConst); Console.WriteLine(ctx.MkForall(new Expr[] { x }, ctx.MkGt(x, ctx.MkInt(0))).IsConst); Console.WriteLine(ctx.MkForall(new Expr[] { x }, ctx.MkGt(x, ctx.MkInt(0))).Body.Args[0]); Console.WriteLine(ctx.MkForall(new Expr[] { x }, ctx.MkGt(x, ctx.MkInt(0))).Body.Args[0].IsExpr); Console.WriteLine(ctx.MkForall(new Expr[] { x }, ctx.MkGt(x, ctx.MkInt(0))).Body.Args[0].IsConst); Console.WriteLine(ctx.MkForall(new Expr[] { x }, ctx.MkGt(x, ctx.MkInt(0))).Body.Args[0].IsVar); Console.WriteLine(x.IsVar); Console.WriteLine(ctx.MkITE(ctx.MkTrue(), x, ctx.MkAdd(x, ctx.MkInt(1)))); Context ctx1 = new Context(); Console.WriteLine(ctx1.MkITE(ctx1.MkTrue(), x.Translate(ctx1), ctx.MkAdd(x, ctx.MkInt(1)).Translate(ctx1))); Console.WriteLine(ctx.MkITE(ctx.MkTrue(), ctx.MkInt(1), ctx.MkInt(1))); Console.WriteLine(ctx.MkDistinct(x, ctx.MkAdd(x, ctx.MkInt(1)), ctx.MkAdd(x, ctx.MkInt(2)))); Console.WriteLine(ctx1.MkAnd(ctx1.MkDistinct(x.Translate(ctx1), ctx1.MkInt(1)), ctx1.MkGt((IntExpr)x.Translate(ctx1), ctx1.MkInt(0)))); } }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" } }; using (Context ctx = new Context(cfg)) { Tactic t = ctx.Then(ctx.MkTactic("simplify"), ctx.MkTactic("normalize-bounds"), ctx.MkTactic("solve-eqs")); IntExpr x = ctx.MkIntConst("x"); IntExpr y = ctx.MkIntConst("y"); IntExpr z = ctx.MkIntConst("z"); Goal g = ctx.MkGoal(); g.Assert(ctx.MkGt(x, ctx.MkInt(10))); g.Assert(ctx.MkEq(y, ctx.MkAdd(x, ctx.MkInt(3)))); g.Assert(ctx.MkGt(z, y)); ApplyResult r = t[g]; Console.WriteLine(r); Solver s = ctx.MkSolver(); s.Assert(r.Subgoals[0].Formulas); Console.WriteLine(s.Check()); Console.WriteLine("subgoal model"); Model sgm = s.Model; Console.WriteLine(sgm); Console.WriteLine("converted model"); Model m = r.ConvertModel(0, sgm); Console.WriteLine(m); Console.WriteLine(m.Evaluate(x)); } }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" } }; using (Context ctx = new Context(cfg)) { RealExpr x = ctx.MkRealConst("x"); RealExpr y = ctx.MkRealConst("y"); RealExpr z = ctx.MkRealConst("z"); Goal g = ctx.MkGoal(); g.Assert(ctx.MkGt(ctx.MkAdd(x, y, z), ctx.MkReal(0))); Probe p = ctx.MkProbe("num-consts"); Console.WriteLine("num-consts: " + p.Apply(g)); Tactic t = ctx.FailIf(ctx.Gt(p, ctx.Const(2))); try { t.Apply(g); } catch (Z3Exception ex) { Console.WriteLine("Tactic failed: " + ex.Message); } Console.WriteLine("trying again..."); g = ctx.MkGoal(); g.Assert(ctx.MkGt(ctx.MkAdd(x, y), ctx.MkReal(0))); Console.WriteLine(t[g]); } }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" } }; using (Context ctx = new Context(cfg)) { IntExpr x = ctx.MkIntConst("x"); IntExpr y = ctx.MkIntConst("y"); Solver s = ctx.MkTactic("smt").Solver; s.Assert(ctx.MkGt(x, ctx.MkAdd(y, ctx.MkInt(1)))); Console.WriteLine(s.Check()); Console.WriteLine(s.Model); } }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" } }; using (Context ctx = new Context(cfg)) { RealExpr x = ctx.MkRealConst("x"); RealExpr y = ctx.MkRealConst("y"); Goal g = ctx.MkGoal(); g.Assert(ctx.MkOr(ctx.MkLt(x, ctx.MkReal(0)), ctx.MkGt(x, ctx.MkReal(0)))); g.Assert(ctx.MkEq(x, ctx.MkAdd(y, ctx.MkReal(1)))); g.Assert(ctx.MkLt(y, ctx.MkReal(0))); Tactic t = ctx.MkTactic("split-clause"); ApplyResult ar = t[g]; foreach (var sg in ar.Subgoals) Console.WriteLine(sg); } }
public override BoolExpr toZ3Bool(Context ctx) { switch (this.comparison_operator) { case ComparisonOperator.EQ: return ctx.MkEq(this.arithmetic_operand1.toZ3Int(ctx), this.arithmetic_operand2.toZ3Int(ctx)); case ComparisonOperator.NEQ: return ctx.MkNot(ctx.MkEq(this.arithmetic_operand1.toZ3Int(ctx), this.arithmetic_operand2.toZ3Int(ctx))); case ComparisonOperator.LEQ: return ctx.MkLe(this.arithmetic_operand1.toZ3Int(ctx), this.arithmetic_operand2.toZ3Int(ctx)); case ComparisonOperator.LT: return ctx.MkLt(this.arithmetic_operand1.toZ3Int(ctx), this.arithmetic_operand2.toZ3Int(ctx)); case ComparisonOperator.GEQ: return ctx.MkGe(this.arithmetic_operand1.toZ3Int(ctx), this.arithmetic_operand2.toZ3Int(ctx)); case ComparisonOperator.GT: return ctx.MkGt(this.arithmetic_operand1.toZ3Int(ctx), this.arithmetic_operand2.toZ3Int(ctx)); default: throw new ArgumentOutOfRangeException(); } }
static void ModelConverterTest(Context ctx) { Console.WriteLine("ModelConverterTest"); ArithExpr xr = (ArithExpr)ctx.MkConst(ctx.MkSymbol("x"), ctx.MkRealSort()); ArithExpr yr = (ArithExpr)ctx.MkConst(ctx.MkSymbol("y"), ctx.MkRealSort()); Goal g4 = ctx.MkGoal(true); g4.Assert(ctx.MkGt(xr, ctx.MkReal(10, 1))); g4.Assert(ctx.MkEq(yr, ctx.MkAdd(xr, ctx.MkReal(1, 1)))); g4.Assert(ctx.MkGt(yr, ctx.MkReal(1, 1))); ApplyResult ar = ApplyTactic(ctx, ctx.MkTactic("simplify"), g4); if (ar.NumSubgoals == 1 && (ar.Subgoals[0].IsDecidedSat || ar.Subgoals[0].IsDecidedUnsat)) throw new TestFailedException(); ar = ApplyTactic(ctx, ctx.AndThen(ctx.MkTactic("simplify"), ctx.MkTactic("solve-eqs")), g4); if (ar.NumSubgoals == 1 && (ar.Subgoals[0].IsDecidedSat || ar.Subgoals[0].IsDecidedUnsat)) throw new TestFailedException(); Solver s = ctx.MkSolver(); foreach (BoolExpr e in ar.Subgoals[0].Formulas) s.Assert(e); Status q = s.Check(); Console.WriteLine("Solver says: " + q); Console.WriteLine("Model: \n" + s.Model); Console.WriteLine("Converted Model: \n" + ar.ConvertModel(0, s.Model)); if (q != Status.SATISFIABLE) throw new TestFailedException(); }
/// <summary> /// Demonstrate how to use #Eval. /// </summary> public static void EvalExample1(Context ctx) { Console.WriteLine("EvalExample1"); IntExpr x = ctx.MkIntConst("x"); IntExpr y = ctx.MkIntConst("y"); IntExpr two = ctx.MkInt(2); Solver solver = ctx.MkSolver(); /* assert x < y */ solver.Assert(ctx.MkLt(x, y)); /* assert x > 2 */ solver.Assert(ctx.MkGt(x, two)); /* find model for the constraints above */ Model model = null; if (Status.SATISFIABLE == solver.Check()) { model = solver.Model; Console.WriteLine("{0}", model); Console.WriteLine("\nevaluating x+y"); Expr v = model.Evaluate(ctx.MkAdd(x, y)); if (v != null) { Console.WriteLine("result = {0}", (v)); } else { Console.WriteLine("Failed to evaluate: x+y"); } } else { Console.WriteLine("BUG, the constraints are satisfiable."); } }
/// <summary> /// Show how push & pop can be used to create "backtracking" points. /// </summary> /// <remarks>This example also demonstrates how big numbers can be /// created in ctx.</remarks> public static void PushPopExample1(Context ctx) { Console.WriteLine("PushPopExample1"); /* create a big number */ IntSort int_type = ctx.IntSort; IntExpr big_number = ctx.MkInt("1000000000000000000000000000000000000000000000000000000"); /* create number 3 */ IntExpr three = (IntExpr)ctx.MkNumeral("3", int_type); /* create x */ IntExpr x = ctx.MkIntConst("x"); Solver solver = ctx.MkSolver(); /* assert x >= "big number" */ BoolExpr c1 = ctx.MkGe(x, big_number); Console.WriteLine("assert: x >= 'big number'"); solver.Assert(c1); /* create a backtracking point */ Console.WriteLine("push"); solver.Push(); /* assert x <= 3 */ BoolExpr c2 = ctx.MkLe(x, three); Console.WriteLine("assert: x <= 3"); solver.Assert(c2); /* context is inconsistent at this point */ if (solver.Check() != Status.UNSATISFIABLE) throw new TestFailedException(); /* backtrack: the constraint x <= 3 will be removed, since it was asserted after the last ctx.Push. */ Console.WriteLine("pop"); solver.Pop(1); /* the context is consistent again. */ if (solver.Check() != Status.SATISFIABLE) throw new TestFailedException(); /* new constraints can be asserted... */ /* create y */ IntExpr y = ctx.MkIntConst("y"); /* assert y > x */ BoolExpr c3 = ctx.MkGt(y, x); Console.WriteLine("assert: y > x"); solver.Assert(c3); /* the context is still consistent. */ if (solver.Check() != Status.SATISFIABLE) throw new TestFailedException(); }
/// <summary> /// Find a model for <tt>x < y + 1, x > 2</tt>. /// Then, assert <tt>not(x = y)</tt>, and find another model. /// </summary> public static void FindModelExample2(Context ctx) { Console.WriteLine("FindModelExample2"); IntExpr x = ctx.MkIntConst("x"); IntExpr y = ctx.MkIntConst("y"); IntExpr one = ctx.MkInt(1); IntExpr two = ctx.MkInt(2); ArithExpr y_plus_one = ctx.MkAdd(y, one); BoolExpr c1 = ctx.MkLt(x, y_plus_one); BoolExpr c2 = ctx.MkGt(x, two); BoolExpr q = ctx.MkAnd(c1, c2); Console.WriteLine("model for: x < y + 1, x > 2"); Model model = Check(ctx, q, Status.SATISFIABLE); Console.WriteLine("x = {0}, y = {1}", (model.Evaluate(x)), (model.Evaluate(y))); /* assert not(x = y) */ BoolExpr x_eq_y = ctx.MkEq(x, y); BoolExpr c3 = ctx.MkNot(x_eq_y); q = ctx.MkAnd(q, c3); Console.WriteLine("model for: x < y + 1, x > 2, not(x = y)"); model = Check(ctx, q, Status.SATISFIABLE); Console.WriteLine("x = {0}, y = {1}", (model.Evaluate(x)), (model.Evaluate(y))); }