t[0] + t[1] + ...
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> 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() { 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> 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" }, { "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)) { 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()) { 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() { using (Context ctx = new Context()) { Expr a1 = ctx.MkAdd(ctx.MkRealConst("x"), ctx.MkReal(1)); Expr a2 = ctx.MkAdd(ctx.MkRealConst("x"), ctx.MkReal(1)); Console.WriteLine(a1.GetHashCode() == a2.GetHashCode()); Expr a3 = ctx.MkAdd(ctx.MkRealConst("x"), ctx.MkReal(2)); Console.WriteLine(a3.GetHashCode() == a1.GetHashCode()); } }
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 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" } }; using (Context ctx = new Context(cfg)) { IntExpr x = ctx.MkIntConst("x"); IntExpr y = ctx.MkIntConst("y"); Console.WriteLine(ctx.MkAdd(x, y).FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_ADD); Console.WriteLine(ctx.MkAdd(x, y).FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_SUB); } }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" } }; Context ctx = new Context(cfg); RealExpr x = ctx.MkRealConst("x"); RealExpr y = ctx.MkRealConst("y"); Console.WriteLine(ctx.MkPower(ctx.MkAdd(x, y), ctx.MkReal(3))); Console.WriteLine(ctx.MkPower(x, ctx.MkAdd(y, ctx.MkReal(3)))); }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" } }; using (Context ctx = new Context(cfg)) { RealExpr d = ctx.MkRealConst("d"); RealExpr a = ctx.MkRealConst("a"); RealExpr t = ctx.MkRealConst("t"); RealExpr v_i = ctx.MkRealConst("v_i"); RealExpr v_f = ctx.MkRealConst("v_f"); BoolExpr[] equations = new BoolExpr[] { ctx.MkEq(d, ctx.MkAdd(ctx.MkMul(v_i, t), ctx.MkDiv(ctx.MkMul(a, ctx.MkPower(t, ctx.MkReal(2))), ctx.MkReal(2)))), ctx.MkEq(v_f, ctx.MkAdd(v_i, ctx.MkMul(a, t))) }; Console.WriteLine("Kinematic equations: "); foreach (BoolExpr e in equations) Console.WriteLine(e); BoolExpr[] problem = new BoolExpr[] { ctx.MkEq(v_i, ctx.MkReal(0)), ctx.MkEq(t, ctx.MkReal("4.10")), ctx.MkEq(a, ctx.MkReal(6)) }; Console.WriteLine("Problem: "); foreach (BoolExpr p in problem) Console.WriteLine(p); Solver s = ctx.MkSolver(); s.Assert(equations); s.Assert(problem); if (s.Check() != Status.SATISFIABLE) throw new Exception("BUG"); Console.WriteLine("Solution: "); Console.WriteLine(s.Model); Console.WriteLine("Decimal Solution: "); foreach (FuncDecl f in s.Model.ConstDecls) Console.WriteLine(f.Name + " = " + ((RatNum)s.Model.ConstInterp(f)).ToDecimalString(10)); } }
public void Run() { Dictionary<string, string> cfg = new Dictionary<string, string>() { { "AUTO_CONFIG", "true" } }; using (Context ctx = new Context(cfg)) { IntExpr[] X = new IntExpr[5]; for (uint i = 0; i < 5; i++) X[i] = ctx.MkIntConst(string.Format("x_{0}", i)); RealExpr[] Y = new RealExpr[5]; for (uint i = 0; i < 5; i++) Y[i] = ctx.MkRealConst(string.Format("y_{0}", i)); BoolExpr[] P = new BoolExpr[5]; for (uint i = 0; i < 5; i++) P[i] = ctx.MkBoolConst(string.Format("p_{0}", i)); foreach (Expr x in X) Console.WriteLine(x); foreach (Expr x in Y) Console.WriteLine(x); foreach (Expr x in P) Console.WriteLine(x); foreach (ArithExpr y in Y) Console.WriteLine(ctx.MkPower(y, ctx.MkReal(2))); ArithExpr[] Yp = new ArithExpr[Y.Length]; for (uint i = 0; i < Y.Length; i++) Yp[i] = ctx.MkPower(Y[i], ctx.MkReal(2)); Console.WriteLine(ctx.MkAdd(Yp)); } }
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" } }; using (Context ctx = new Context(cfg)) { RealExpr x = ctx.MkRealConst("x"); RealExpr y = ctx.MkRealConst("y"); Params ps = ctx.MkParams(); ps.Add(":som", true); Expr q = ctx.MkPower(ctx.MkAdd(x, y), ctx.MkReal(3)); q = q.Simplify(ps); Console.WriteLine(ps); Console.WriteLine(q); ps = ctx.MkParams(); ps.Add(":mul-to-power", true); q = q.Simplify(ps); Console.WriteLine(ps); Console.WriteLine(q); } }
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() { 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() { 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)) { 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)) { 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 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() { 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" } }; Context ctx = new Context(cfg); RealExpr x = ctx.MkRealConst("x"); RealExpr y = ctx.MkRealConst("y"); RealExpr z = ctx.MkRealConst("z"); RatNum two = ctx.MkReal(2); Console.WriteLine(ctx.MkAdd(ctx.MkSub(ctx.MkMul(x, y), ctx.MkPower(y, two)), ctx.MkPower(z, two))); Console.WriteLine(ctx.MkSub(ctx.MkAdd(ctx.MkMul(x, y), ctx.MkPower(y, two)), ctx.MkPower(z, two))); Console.WriteLine(ctx.MkMul(ctx.MkAdd(x, y), z)); }
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)) { RealExpr x = ctx.MkRealConst("x"); IntExpr y = ctx.MkIntConst("y"); RealExpr a, b, c; a = ctx.MkRealConst("a"); b = ctx.MkRealConst("b"); c = ctx.MkRealConst("c"); IntExpr s, r; s = ctx.MkIntConst("s"); r = ctx.MkIntConst("r"); TestDriver.CheckString(ctx.MkAdd(x, ctx.MkInt2Real(y), ctx.MkReal(1), ctx.MkAdd(a, ctx.MkInt2Real(s))), "(+ x (to_real y) 1.0 a (to_real s))"); TestDriver.CheckString(ctx.MkAdd(ctx.MkInt2Real(y), c), "(+ (to_real y) c)"); } }
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() { 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 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 static void add(IntExpr f1, IntExpr f2, out IntExpr e) { e = new IntExpr(ctx.MkAdd(f1.expr, f2.expr)); }