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()) { 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()); } }
/// <summary> /// Generates a slightly randomized expression. /// </summary> static BoolExpr MkRandomExpr(Context ctx, System.Random rng) { int limit = 1073741823; Sort i = ctx.IntSort; Sort b = ctx.BoolSort; Symbol sr1 = ctx.MkSymbol(rng.Next(0, limit)); Symbol sr2 = ctx.MkSymbol(rng.Next(0, limit)); Symbol sr3 = ctx.MkSymbol(rng.Next(0, limit)); FuncDecl r1 = ctx.MkFuncDecl(sr1, i, b); FuncDecl r2 = ctx.MkFuncDecl(sr2, i, b); FuncDecl r3 = ctx.MkFuncDecl(sr3, i, b); Symbol s = ctx.MkSymbol(rng.Next(0, limit)); Expr x = ctx.MkConst(s, i); BoolExpr r1x = (BoolExpr)ctx.MkApp(r1, x); BoolExpr r2x = (BoolExpr)ctx.MkApp(r2, x); BoolExpr r3x = (BoolExpr)ctx.MkApp(r3, x); Expr[] vars = { x }; BoolExpr rl1 = ctx.MkForall(vars, ctx.MkImplies(r1x, r2x)); BoolExpr rl2 = ctx.MkForall(vars, ctx.MkImplies(r2x, r1x)); BoolExpr rl3 = (BoolExpr)ctx.MkApp(r1, ctx.MkInt(3)); BoolExpr q = (BoolExpr)ctx.MkApp(r3, ctx.MkInt(2)); BoolExpr a1 = ctx.MkNot(q); BoolExpr q1 = ctx.MkExists(vars, ctx.MkAnd(r3x, r2x)); BoolExpr q2 = ctx.MkExists(vars, ctx.MkAnd(r3x, r1x)); BoolExpr[] all = { a1, q1, q2 }; return ctx.MkAnd(all); }
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()) { BoolExpr p = ctx.MkBoolConst("p"); BoolExpr q = ctx.MkBoolConst("q"); Console.WriteLine(ctx.MkAnd(p, q)); Console.WriteLine(ctx.MkOr(p, q)); Console.WriteLine(ctx.MkAnd(p, ctx.MkTrue())); Console.WriteLine(ctx.MkOr(p, ctx.MkFalse())); Console.WriteLine(ctx.MkNot(p)); Console.WriteLine(ctx.MkImplies(p, q)); Console.WriteLine(ctx.MkEq(p, q).Simplify()); Console.WriteLine(ctx.MkEq(p, q)); BoolExpr r = ctx.MkBoolConst("r"); Console.WriteLine(ctx.MkNot(ctx.MkEq(p, ctx.MkNot(ctx.MkEq(q, r))))); Console.WriteLine(ctx.MkNot(ctx.MkEq(ctx.MkNot(ctx.MkEq(p, q)), r))); Console.WriteLine(ctx.MkEq(p, ctx.MkTrue())); Console.WriteLine(ctx.MkEq(p, ctx.MkFalse())); Console.WriteLine(ctx.MkEq(p, ctx.MkTrue()).Simplify()); Console.WriteLine(ctx.MkEq(p, ctx.MkFalse()).Simplify()); Console.WriteLine(ctx.MkEq(p, p).Simplify()); Console.WriteLine(ctx.MkEq(p, q).Simplify()); Console.WriteLine(ctx.MkAnd(p, q, r)); Console.WriteLine(ctx.MkOr(p, q, r)); IntExpr x = ctx.MkIntConst("x"); Console.WriteLine(x is BoolExpr); Console.WriteLine(p is BoolExpr); Console.WriteLine(ctx.MkAnd(p, q) is BoolExpr); Console.WriteLine(p is BoolExpr); Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1)) is BoolExpr); Console.WriteLine(p.IsAnd); Console.WriteLine(ctx.MkOr(p, q).IsOr); Console.WriteLine(ctx.MkAnd(p, q).IsAnd); Console.WriteLine(x.IsNot); Console.WriteLine(p.IsNot); Console.WriteLine(ctx.MkNot(p)); Console.WriteLine(ctx.MkNot(p).IsDistinct); Console.WriteLine(ctx.MkEq(p, q).IsDistinct); Console.WriteLine(ctx.MkDistinct(p, q).IsDistinct); Console.WriteLine(ctx.MkDistinct(x, ctx.MkAdd(x, ctx.MkInt(1)), ctx.MkAdd(x, ctx.MkInt(2))).IsDistinct); Console.WriteLine(); Console.WriteLine(ctx.MkBool(true)); Console.WriteLine(ctx.MkBool(false)); Console.WriteLine(ctx.BoolSort); Context ctx1 = new Context(); Console.WriteLine(ctx1.MkBool(true)); Console.WriteLine(ctx1.BoolSort); Console.WriteLine(ctx1.MkBool(true).Sort == ctx1.BoolSort); Console.WriteLine(ctx1.MkBool(true).Sort == ctx.BoolSort); Console.WriteLine(ctx1.MkBool(true).Sort != ctx.BoolSort); } }
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 = 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 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)) { IntExpr x = ctx.MkIntConst("x"); Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1)).GetHashCode() == ctx.MkAdd(ctx.MkInt(1), x).GetHashCode()); Console.WriteLine(x.Sort.GetHashCode() == ctx.IntSort.GetHashCode()); } }
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 = 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() { using (Context ctx = new Context()) { IntExpr x = ctx.MkIntConst("x"); Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1))); } }
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" }, { "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()); } }
private Expr[,] prepareExpr(int numVertices, List <Tuple <uint, uint> > edges) { using (Microsoft.Z3.Context ctx = new Microsoft.Z3.Context()){ Expr[,] R = new Expr[numVertices, numVertices]; for (uint i = 0; i < numVertices; i++) { for (uint j = 0; j < numVertices; j++) { if (edges.Any(tuple => tuple.Item1 == i && tuple.Item2 == j)) { R[i, j] = ctx.MkInt(1); } else { R[i, j] = ctx.MkInt(0); } } } return(R); } }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" }, { "MODEL", "true" } }; using (Context ctx = new Context(cfg)) { Sort I = ctx.IntSort; ArrayExpr A = ctx.MkArrayConst("A", I, I); IntExpr x = ctx.MkIntConst("x"); Console.WriteLine(ctx.MkSelect(A, x)); Console.WriteLine(ctx.MkStore(A, x, ctx.MkInt(10))); Expr q = ctx.MkSelect(ctx.MkStore(A, ctx.MkInt(2), ctx.MkAdd(x, ctx.MkInt(1))), ctx.MkInt(2)); 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)) { 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()) { BoolExpr p = ctx.MkBoolConst("p"); Console.WriteLine(ctx.MkNot(p)); Console.WriteLine(ctx.MkNot(p)); IntExpr x = ctx.MkIntConst("x"); IntExpr y = ctx.MkIntConst("y"); Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1))); Console.WriteLine(ctx.MkAdd(ctx.MkInt(1), x)); Console.WriteLine(ctx.MkAdd(x, y)); Console.WriteLine(ctx.MkMul(ctx.MkInt(2), x)); Console.WriteLine(ctx.MkMul(x, ctx.MkInt(2))); Console.WriteLine(ctx.MkMul(x, y)); Console.WriteLine(ctx.MkDiv(x, y)); Console.WriteLine(ctx.MkMod(x, y)); Console.WriteLine(ctx.MkEq(x, y)); Console.WriteLine(ctx.MkDistinct(x, y, x)); Console.WriteLine(ctx.MkNot(ctx.MkEq(x, y))); Console.WriteLine(ctx.MkEq(x, y)); Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1))); Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1))); BoolExpr q = ctx.MkBoolConst("q"); Console.WriteLine(ctx.MkNot(p)); Console.WriteLine(ctx.MkNot(p)); Console.WriteLine(ctx.MkAnd(p, q)); Console.WriteLine(ctx.MkAnd(p, q)); Console.WriteLine(ctx.MkEq(x, y)); } }
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" }, { "MODEL", "true" } }; using (Context ctx = new Context(cfg)) { ListSort L = ctx.MkListSort("List", ctx.IntSort); FuncDecl cons = L.ConsDecl; FuncDecl car = L.HeadDecl; FuncDecl cdr = L.TailDecl; Expr nil = L.Nil; Expr l1 = cons[ctx.MkInt(10), cons[ctx.MkInt(20), nil]]; Console.WriteLine(l1); Console.WriteLine(cdr[l1].Simplify()); Console.WriteLine(car[l1].Simplify()); Console.WriteLine(ctx.MkEq(l1, nil).Simplify()); } }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" }, { "PROOF_MODE", "2" } }; using (Context ctx = new Context(cfg)) { ArrayExpr AllOne = ctx.MkConstArray(ctx.IntSort, ctx.MkInt(1)); IntExpr a = ctx.MkIntConst("a"); IntExpr i = ctx.MkIntConst("i"); Solver s = ctx.MkSolver(); s.Assert(ctx.MkEq(a, ctx.MkSelect(AllOne, i))); Console.WriteLine(s.Check()); s = ctx.MkSolver(); s.Assert(ctx.MkEq(a, ctx.MkSelect(AllOne, i))); s.Assert(ctx.MkNot(ctx.MkEq(a, ctx.MkInt(1)))); Console.WriteLine(s.Check()); } }
public void Run() { using (Context ctx1 = new Context(new Dictionary<string, string>() { { ":relevancy", "0" } })) using (Context ctx2 = new Context(new Dictionary<string, string>() { { ":model", "false" }, { ":pp-decimal", "true" }, { ":relevancy", "2" }, { ":pp-decimal-precision", "50" } })) { IntExpr x = ctx1.MkIntConst("x"); IntExpr _x = (IntExpr) x.Translate(ctx2); Console.WriteLine(ctx2.MkEq(_x, ctx1.MkAdd(x, ctx1.MkInt(1)).Translate(ctx2))); Console.WriteLine(ctx2.MkPower(ctx2.MkReal(2), ctx2.MkReal(1, 2)).Simplify()); Console.WriteLine(ctx1.MkPower(ctx1.MkReal(2), ctx1.MkReal(1, 2)).Simplify()); Solver s = ctx1.MkSolver(); s.Assert(ctx1.MkEq(x, ctx1.MkInt(2))); Console.WriteLine(s); Console.WriteLine(s.Check()); Console.WriteLine(s.Model); s = ctx2.MkSolver(); s.Assert(ctx2.MkEq(_x, ctx2.MkInt(2))); Console.WriteLine(s.Check()); try { Console.WriteLine(s.Model); } catch (Z3Exception ex) { Console.WriteLine("failed: " + ex.Message); } } }
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); } }
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 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, 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, c1, c2, c3); }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" }, { "MODEL", "true" } }; using (Context ctx = new Context(cfg)) { Constructor c_leaf = ctx.MkConstructor("leaf", "is_leaf", new string[] { "val" }, new Sort[] { ctx.IntSort }); Constructor c_node = ctx.MkConstructor("node", "is_node", new string[] { "left", "right" }, new Sort[] { null, null }, new uint[] { 1, 1 }); Constructor[] constr_1 = new Constructor[] { c_leaf, c_node }; Constructor c_nil = ctx.MkConstructor("nil", "is_nil"); Constructor c_cons = ctx.MkConstructor("cons", "is_cons", new string[] { "car", "cdr" }, new Sort[] { null, null }, new uint[] { 0, 1 }); Constructor[] constr_2 = new Constructor[] { c_nil, c_cons }; DatatypeSort[] ts = ctx.MkDatatypeSorts(new string[] { "Tree", "TreeList" }, new Constructor[][] { constr_1, constr_2 }); DatatypeSort Tree = ts[0]; DatatypeSort TreeList = ts[1]; FuncDecl leaf = Tree.Constructors[0]; FuncDecl node = Tree.Constructors[1]; FuncDecl val = Tree.Accessors[0][0]; FuncDecl nil = TreeList.Constructors[0]; FuncDecl cons = TreeList.Constructors[1]; Expr t1 = leaf[ctx.MkInt(10)]; Expr tl1 = cons[t1, nil.Apply()]; Expr t2 = node[tl1, nil.Apply()]; Console.WriteLine(t2); Console.WriteLine(val.Apply(t1).Simplify()); t1 = ctx.MkConst("t1", TreeList); t2 = ctx.MkConst("t2", TreeList); Expr t3 = ctx.MkConst("t3", TreeList); Solver s = ctx.MkSolver(); s.Assert(ctx.MkDistinct(t1, t2, t3)); 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)) { ArithExpr[] Q = new ArithExpr[8]; for (uint i = 0; i < 8; i++) Q[i] = ctx.MkIntConst(string.Format("Q_{0}", i + 1)); BoolExpr[] val_c = new BoolExpr[8]; for (uint i = 0; i < 8; i++) val_c[i] = ctx.MkAnd(ctx.MkLe(ctx.MkInt(1), Q[i]), ctx.MkLe(Q[i], ctx.MkInt(8))); BoolExpr col_c = ctx.MkDistinct(Q); BoolExpr[][] diag_c = new BoolExpr[8][]; for (uint i = 0; i < 8; i++) { diag_c[i] = new BoolExpr[i]; for (uint j = 0; j < i; j++) diag_c[i][j] = (BoolExpr)ctx.MkITE(ctx.MkEq(ctx.MkInt(i), ctx.MkInt(j)), ctx.MkTrue(), ctx.MkAnd(ctx.MkNot(ctx.MkEq(ctx.MkSub(Q[i], Q[j]), ctx.MkSub(ctx.MkInt(i), ctx.MkInt(j)))), ctx.MkNot(ctx.MkEq(ctx.MkSub(Q[i], Q[j]), ctx.MkSub(ctx.MkInt(j), ctx.MkInt(i)))))); } Solver s = ctx.MkSolver(); s.Assert(val_c); s.Assert(col_c); foreach (var c in diag_c) s.Assert(c); 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)) { FuncDecl f = ctx.MkFuncDecl("f", new Sort[] { ctx.IntSort, ctx.IntSort }, ctx.IntSort); IntExpr x = ctx.MkIntConst("x"); IntExpr y = ctx.MkIntConst("y"); Quantifier qf = ctx.MkForall(new Expr[] { x, y }, ctx.MkEq(f[x, y], ctx.MkInt(0))); Console.WriteLine(qf.Body); Expr v1 = qf.Body.Args[0].Args[0]; Console.WriteLine(v1); Console.WriteLine(v1 == ctx.MkBound(1, ctx.IntSort)); } }
public void Run() { using (Context ctx = new Context()) { ArrayExpr a = ctx.MkArrayConst("a", ctx.IntSort, ctx.IntSort); FuncDecl f = ctx.MkFuncDecl("f", ctx.IntSort, ctx.IntSort); ArrayExpr m = ctx.MkMap(f, a); Console.WriteLine(m); Console.WriteLine(m.IsArrayMap); Console.WriteLine(a.IsArrayMap); Console.WriteLine(m.IsSelect); Console.WriteLine(ctx.MkSelect(m, ctx.MkInt(0)).IsSelect); Console.WriteLine(ctx.MkStore(m, ctx.MkInt(0), ctx.MkInt(1)).IsStore); Console.WriteLine(ctx.MkStore(m, ctx.MkInt(0), ctx.MkInt(1))); Console.WriteLine(m.IsStore); Console.WriteLine(m.FuncDecl); Console.WriteLine(m.FuncDecl.Parameters[0].FuncDecl); Console.WriteLine(m.FuncDecl.Parameters[0].FuncDecl[ctx.MkInt(0)]); Console.WriteLine(ctx.MkSelect(m, ctx.MkInt(10))); } }
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"); Console.WriteLine("is expression: " + (x is Expr)); Expr n = ctx.MkAdd(x, ctx.MkInt(1)); Console.WriteLine("is application: " + (x.IsNumeral || x.IsExpr)); Console.WriteLine("decl: " + n.FuncDecl); Console.WriteLine("num args: " + n.NumArgs); for (uint i = 0; i < n.NumArgs; i++) Console.WriteLine("arg(" + i + ") -> " + n.Args[i]); } }
public static void intConst(BigInteger i, out IntExpr e) { e = new IntExpr(ctx.MkInt((int)i)); }