t1 < t2
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() { 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() { 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() { 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"); 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)) { 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 static void CheckLessThan(int a, String b) { // Console.WriteLine("This test worked" + a + " " + b); using (Context ctx = new Context()) { // 3 < x Expr x = ctx.MkConst(b, ctx.MkIntSort()); Expr value = ctx.MkNumeral(a, ctx.MkIntSort()); BoolExpr test = ctx.MkLt((ArithExpr)value,(ArithExpr) x); Model model = Check(ctx, test, Status.SATISFIABLE); } }
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); } }
static void Main(string[] args) { using (Context ctx = new Context()) { Expr x = ctx.MkConst("x", ctx.MkIntSort()); Expr zero = ctx.MkNumeral(0, ctx.MkIntSort()); Solver s = ctx.MkSolver(); s.Assert(ctx.MkLt((ArithExpr)zero, (ArithExpr)x)); // 0<x Status result = s.Check(); Console.WriteLine(result); } }
/// <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> /// Prove <tt>not(g(g(x) - g(y)) = g(z)), x + z <= y <= x implies z < 0 </tt>. /// Then, show that <tt>z < -1</tt> is not implied. /// </summary> /// <remarks>This example demonstrates how to combine uninterpreted functions /// and arithmetic.</remarks> public static void ProveExample2(Context ctx) { Console.WriteLine("ProveExample2"); /* declare function g */ Sort I = ctx.IntSort; FuncDecl g = ctx.MkFuncDecl("g", I, I); /* create x, y, and z */ IntExpr x = ctx.MkIntConst("x"); IntExpr y = ctx.MkIntConst("y"); IntExpr z = ctx.MkIntConst("z"); /* create gx, gy, gz */ Expr gx = ctx.MkApp(g, x); Expr gy = ctx.MkApp(g, y); Expr gz = ctx.MkApp(g, z); /* create zero */ IntExpr zero = ctx.MkInt(0); /* assert not(g(g(x) - g(y)) = g(z)) */ ArithExpr gx_gy = ctx.MkSub((IntExpr)gx, (IntExpr)gy); Expr ggx_gy = ctx.MkApp(g, gx_gy); BoolExpr eq = ctx.MkEq(ggx_gy, gz); BoolExpr c1 = ctx.MkNot(eq); /* assert x + z <= y */ ArithExpr x_plus_z = ctx.MkAdd(x, z); BoolExpr c2 = ctx.MkLe(x_plus_z, y); /* assert y <= x */ BoolExpr c3 = ctx.MkLe(y, x); /* prove z < 0 */ BoolExpr f = ctx.MkLt(z, zero); Console.WriteLine("prove: not(g(g(x) - g(y)) = g(z)), x + z <= y <= x implies z < 0"); Prove(ctx, f, false, c1, c2, c3); /* disprove z < -1 */ IntExpr minus_one = ctx.MkInt(-1); f = ctx.MkLt(z, minus_one); Console.WriteLine("disprove: not(g(g(x) - g(y)) = g(z)), x + z <= y <= x implies z < -1"); Disprove(ctx, f, false, c1, c2, c3); }
/// <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))); }
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(); } }
public static Expr GtOrLt(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.MkOr(ctx.MkGt((ArithExpr)a, (ArithExpr)b), ctx.MkLt((ArithExpr)c, (ArithExpr)d))); s.Check(); BoolExpr testing = ctx.MkOr(ctx.MkGt((ArithExpr)a, (ArithExpr)b), ctx.MkLt((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; }