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"); RealExpr z = ctx.MkRealConst("z"); RatNum zero = ctx.MkReal(0); RatNum two = ctx.MkReal(2); Goal g = ctx.MkGoal(); g.Assert(ctx.MkGe(ctx.MkSub(ctx.MkPower(x, two), ctx.MkPower(y, two)), zero)); Probe p = ctx.MkProbe("num-consts"); Probe p2 = ctx.Gt(p, ctx.Const(2)); Tactic t = ctx.Cond(p2, ctx.MkTactic("simplify"), ctx.MkTactic("factor")); Console.WriteLine(t[g]); g = ctx.MkGoal(); g.Assert(ctx.MkGe(ctx.MkAdd(x, x, y, z), zero)); g.Assert(ctx.MkGe(ctx.MkSub(ctx.MkPower(x, two), ctx.MkPower(y, two)), zero)); 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 dog = ctx.MkIntConst("dog"); IntExpr cat = ctx.MkIntConst("cat"); IntExpr mouse = ctx.MkIntConst("mouse"); Solver s = ctx.MkSolver(); s.Assert(ctx.MkGe(dog, ctx.MkInt(1))); s.Assert(ctx.MkGe(cat, ctx.MkInt(1))); s.Assert(ctx.MkGe(mouse, ctx.MkInt(1))); s.Assert(ctx.MkEq(ctx.MkAdd(dog, cat, mouse), ctx.MkInt(100))); s.Assert(ctx.MkEq(ctx.MkAdd(ctx.MkMul(ctx.MkInt(1500), dog), ctx.MkMul(ctx.MkInt(100), cat), ctx.MkMul(ctx.MkInt(25), mouse)), ctx.MkInt(10000))); 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 = new IntExpr[20]; IntExpr[] y = new IntExpr[20]; for (uint i = 0; i < 20; i++) { x[i] = ctx.MkIntConst(string.Format("x_{0}", i)); y[i] = ctx.MkIntConst(string.Format("y_{0}", i)); } BoolExpr f = ctx.MkAnd(ctx.MkGe(ctx.MkAdd(x), ctx.MkInt(0)), ctx.MkGe(ctx.MkAdd(y), ctx.MkInt(0))); Console.WriteLine("now: " + ctx.GetParamValue("PP_MAX_DEPTH")); ctx.UpdateParamValue("PP_MAX_DEPTH", "1"); Console.WriteLine(f); ctx.UpdateParamValue("PP_MAX_DEPTH", "100"); ctx.UpdateParamValue("PP_MAX_NUM_LINES", "10"); Console.WriteLine(f); ctx.UpdateParamValue("PP_MAX_NUM_LINES", "20"); ctx.UpdateParamValue("PP_MAX_WIDTH", "300"); Console.WriteLine(f); Console.WriteLine("now: " + ctx.GetParamValue("PP_MAX_WIDTH")); } }
public static Expr EeAndGe(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.MkGe((ArithExpr)c, (ArithExpr)d))); s.Check(); BoolExpr testing = ctx.MkAnd(ctx.MkEq((ArithExpr)a, (ArithExpr)b), ctx.MkGe((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> 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"); RealExpr y = ctx.MkRealConst("y"); Console.WriteLine((ctx.MkAdd(x, ctx.MkInt(1))).Sort); Console.WriteLine((ctx.MkAdd(y, ctx.MkReal(1))).Sort); Console.WriteLine((ctx.MkGe(x, ctx.MkInt(2))).Sort); } }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" }, { "MODEL", "true" } }; using (Context ctx = new Context(cfg)) { ArrayExpr X = ctx.MkArrayConst("A", ctx.IntSort, ctx.IntSort); Expr q = ctx.MkGe( ctx.MkAdd((IntExpr)ctx.MkSelect(X, ctx.MkInt(0)), (IntExpr)ctx.MkSelect(X, ctx.MkInt(1)), (IntExpr)ctx.MkSelect(X, ctx.MkInt(2))), ctx.MkInt(0)); Console.WriteLine(q); Console.WriteLine(q.Simplify()); } }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" } }; using (Context ctx = new Context(cfg)) { FuncDecl f = ctx.MkFuncDecl("f", new Sort[] { ctx.IntSort, ctx.IntSort }, ctx.IntSort); IntExpr x = ctx.MkIntConst("x"); IntExpr y = ctx.MkIntConst("y"); Console.WriteLine(ctx.MkForall(new Expr[] { x, y }, ctx.MkEq(f[x, y], ctx.MkInt(0)))); Console.WriteLine(ctx.MkExists(new Expr[] { x }, ctx.MkGe((ArithExpr)f[x, x], ctx.MkInt(0)))); IntExpr a = ctx.MkIntConst("a"); IntExpr b = ctx.MkIntConst("b"); Solver s = ctx.MkSolver(); s.Assert(ctx.MkForall(new Expr[] { x }, ctx.MkEq(f[x, x], ctx.MkInt(0)))); s.Assert(ctx.MkEq(f[a, b], ctx.MkInt(1))); Console.WriteLine(s.Check()); Console.WriteLine(s.Model); } }
/// <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(); }
protected void Clique(Context ctx, Edge[] edges, uint n) { uint num = 0; foreach (Edge e in edges) { if (e.v0 >= num) num = e.v0 + 1; if (e.v1 >= num) num = e.v1 + 1; } Solver S = ctx.MkSolver(); IntExpr [] In = new IntExpr[num]; for (uint i = 0; i < num; i++) { In[i] = ctx.MkIntConst(String.Format("in_{0}", i)); S.Assert(ctx.MkLe(ctx.MkInt(0), In[i])); S.Assert(ctx.MkLe(In[i], ctx.MkInt(1))); } ArithExpr sum = ctx.MkInt(0); foreach (IntExpr e in In) sum = ctx.MkAdd(sum, e); S.Assert(ctx.MkGe(sum, ctx.MkInt(n))); IntNum[][] matrix = new IntNum[num][]; for (uint i = 0; i < num; i++) { matrix[i] = new IntNum[i]; for (uint j = 0; j < i; j++) matrix[i][j] = ctx.MkInt(0); } foreach (Edge e in edges) { uint s = e.v0; uint t = e.v1; if (s < t) { s = e.v1; t = e.v0; } matrix[s][t] = ctx.MkInt(1); } for (uint i = 0; i < num; i++) for (uint j = 0; j < i; j++) if (i != j) if (matrix[i][j].Int == 0) S.Assert(ctx.MkOr(ctx.MkEq(In[i], ctx.MkInt(0)), ctx.MkEq(In[j], ctx.MkInt(0)))); Status r = S.Check(); if (r == Status.UNSATISFIABLE) Console.WriteLine("no solution"); else if (r == Status.UNKNOWN) { Console.Write("failed"); Console.WriteLine(S.ReasonUnknown); } else { Console.WriteLine("solution found"); Model m = S.Model; Console.Write("{ "); foreach (FuncDecl cfd in m.ConstDecls) { IntNum q = (IntNum)m.ConstInterp(cfd); if (q.Int == 1) Console.Write(" " + cfd.Name); } Console.WriteLine(" }"); Console.Write("{ "); for (uint i = 0; i < num; i++) { IntNum q = (IntNum)m.Evaluate(In[i]); if (q.Int == 1) Console.Write(" " + In[i]); } Console.WriteLine(" }"); } }
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(); } }