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"); 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)) { 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"); 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"); 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> 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()) { 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" } }; 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)) { 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() { 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() { 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()) { 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() { 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() { using (Context ctx = new Context()) { RealExpr x = ctx.MkRealConst("x"); RealExpr y = ctx.MkRealConst("y"); Solver s = ctx.Then(ctx.MkTactic("simplify"), ctx.MkTactic("nlsat")).Solver; s.Assert(ctx.MkEq(ctx.MkPower(x, ctx.MkReal(2)), ctx.MkReal(2)), ctx.MkEq(ctx.MkPower(y, ctx.MkReal(3)), ctx.MkAdd(x, ctx.MkReal(1)))); Console.WriteLine(s.Check()); ctx.UpdateParamValue(":pp-decimal", "true"); Console.WriteLine(s.Model); Console.WriteLine(s.Statistics); foreach (string k in s.Statistics.Keys) Console.WriteLine(k); Console.WriteLine("NLSAT stages: " + s.Statistics["nlsat stages"].Value); Console.WriteLine("NLSAT propagations: " + s.Statistics["nlsat propagations"].Value); } }
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)) { 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 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()) { 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() { 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() { using (Context ctx = new Context()) { Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 2)).Simplify()); ctx.UpdateParamValue(":pp-decimal-precision", "50"); ctx.UpdateParamValue(":pp-decimal", "true"); Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 2)).Simplify()); ctx.UpdateParamValue(":pp-decimal-precision", "20"); Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 2)).Simplify()); } }
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)) { RealExpr x = ctx.MkRealConst("x"); RealExpr y = ctx.MkRealConst("y"); Params ps = ctx.MkParams(); ps.Add(":arith-lhs", true); Expr q = ctx.MkEq(x, ctx.MkAdd(y, ctx.MkReal(2))); 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)) { try { Expr n = ctx.MkReal("1/0"); Console.WriteLine(n); } catch (Z3Exception ex) { Console.WriteLine("failed: " + ex.Message); } Console.WriteLine("done"); } }
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" } }; Context ctx = new Context(cfg); Context.ToggleWarningMessages(false); IntExpr x = ctx.MkIntConst("x"); try { Solver s = ctx.MkSolver(); s.Assert(ctx.MkEq(x, ctx.MkReal("3/2"))); Console.WriteLine(s.Check()); } catch (Z3Exception ex) { Console.WriteLine("Exception: " + ex.Message); } }
/// <summary> /// A basic example of how to use quantifiers. /// </summary> static void MyQuantifierExample(Context ctx) { Console.WriteLine("MyQuantifierExample"); RealExpr x1 = ctx.MkRealConst("x1"); RealExpr x2 = ctx.MkRealConst("x2"); BoolExpr body_vars = ctx.MkEq(ctx.MkAdd(x1, x2), ctx.MkReal(15)); BoolExpr body_const = ctx.MkEq(ctx.MkSub(x1, x2), ctx.MkReal(4)); Solver s = ctx.MkSolver(); s.Assert(body_vars); s.Assert(body_const); Status q = s.Check(); Model m = s.Model; Console.WriteLine(m.ToString()); Console.WriteLine("Quantifier x1: " + m.Evaluate(x1, true)); Console.WriteLine("Quantifier x2: " + m.Evaluate(x2, true)); }
public void Run() { using (Context ctx = new Context()) { RealExpr x = ctx.MkRealConst("x"); RealExpr y = ctx.MkRealConst("y"); RealExpr z = ctx.MkRealConst("z"); IntExpr a = ctx.MkIntConst("a"); IntExpr b = ctx.MkIntConst("b"); IntExpr c = ctx.MkIntConst("c"); ctx.UpdateParamValue(":pp-flat-assoc", "false"); Console.WriteLine(ctx.MkAdd(x, y, ctx.MkInt2Real(a))); Console.WriteLine(ctx.MkAdd(x, ctx.MkReal(1))); Console.WriteLine(ctx.MkAdd(ctx.MkReal(2), y)); Console.WriteLine(ctx.MkMul(x, y)); Console.WriteLine(ctx.MkAdd(ctx.MkInt(2), ctx.MkInt(3))); Console.WriteLine(ctx.MkMul(ctx.MkReal(2), x)); Console.WriteLine(ctx.MkAdd(ctx.MkInt2Real((IntExpr)ctx.MkAdd(ctx.MkInt(2), ctx.MkInt(3))), x)); Console.WriteLine(ctx.MkAdd((RealExpr)ctx.MkInt2Real((IntExpr)ctx.MkAdd(ctx.MkInt(2), ctx.MkInt(3))).Simplify(), x)); Console.WriteLine(ctx.MkAdd(a, b, ctx.MkInt(1))); Console.WriteLine(ctx.MkDiv(x, y)); Console.WriteLine(ctx.MkDiv(x, ctx.MkReal(2))); Console.WriteLine(ctx.MkDiv(ctx.MkReal(2), y)); Console.WriteLine(ctx.MkDiv(a, ctx.MkInt(2))); Console.WriteLine(ctx.MkDiv(ctx.MkAdd(a, b), ctx.MkInt(2))); Console.WriteLine(ctx.MkDiv(ctx.MkInt(3), a)); Console.WriteLine(ctx.MkMod(a, b)); Console.WriteLine(ctx.MkMod(a, ctx.MkInt(2))); Console.WriteLine(ctx.MkMod(ctx.MkInt(3), a)); Console.WriteLine(ctx.MkSub(a, ctx.MkInt(2))); Console.WriteLine(ctx.MkUnaryMinus(a)); Console.WriteLine(ctx.MkUnaryMinus(x)); Console.WriteLine(ctx.MkSub(a, b)); Console.WriteLine(a.IsAdd); Console.WriteLine(ctx.MkAdd(a, b).IsAdd); Console.WriteLine(ctx.MkSub(a, b).IsAdd); Console.WriteLine(ctx.MkInt(10).IsAdd); Console.WriteLine(ctx.MkMul(a, b).IsMul); Console.WriteLine(ctx.MkMul(x, ctx.MkInt2Real(b)).IsMul); Console.WriteLine(ctx.MkAdd(a, b).IsMul); Console.WriteLine(ctx.MkDiv(a, ctx.MkInt(2)).IsDiv); Console.WriteLine(ctx.MkDiv(ctx.MkReal(3), x).IsDiv); Console.WriteLine(ctx.MkDiv(x,y).IsDiv); Console.WriteLine(ctx.MkDiv(a, ctx.MkInt(2)).IsIDiv); Console.WriteLine(ctx.MkAdd(ctx.MkInt(2), ctx.MkInt(3)).Simplify().IsAdd); Console.WriteLine(); Console.WriteLine(a is ArithExpr); Console.WriteLine(ctx.MkInt(2) is ArithExpr); Console.WriteLine(ctx.MkAdd(a, b) is ArithExpr); Console.WriteLine(ctx.MkBoolConst("p") is ArithExpr); Console.WriteLine(ctx.MkInt(2) is IntNum); Console.WriteLine(ctx.MkInt(2) is RatNum); Console.WriteLine(ctx.MkReal(2, 3)); Console.WriteLine(ctx.MkReal(2, 3).IsReal); Console.WriteLine(ctx.MkReal(2, 3) is ArithExpr); Console.WriteLine(ctx.MkReal(2, 3).IsConst); Console.WriteLine(ctx.MkReal(2, 3).Simplify() is RatNum); Console.WriteLine(ctx.MkReal(2, 3).Simplify().IsRatNum); Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 2)).Simplify().IsAlgebraicNumber); Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 2)).Simplify() is AlgebraicNum); Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 2)).IsAlgebraicNumber); Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 2)) is AlgebraicNum); Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 2))); Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 3))); } }
/// <summary> /// Some basic tests. /// </summary> static void BasicTests(Context ctx) { Console.WriteLine("BasicTests"); Symbol qi = ctx.MkSymbol(1); Symbol fname = ctx.MkSymbol("f"); Symbol x = ctx.MkSymbol("x"); Symbol y = ctx.MkSymbol("y"); Sort bs = ctx.MkBoolSort(); Sort[] domain = { bs, bs }; FuncDecl f = ctx.MkFuncDecl(fname, domain, bs); Expr fapp = ctx.MkApp(f, ctx.MkConst(x, bs), ctx.MkConst(y, bs)); Expr[] fargs2 = { ctx.MkFreshConst("cp", bs) }; Sort[] domain2 = { bs }; Expr fapp2 = ctx.MkApp(ctx.MkFreshFuncDecl("fp", domain2, bs), fargs2); BoolExpr trivial_eq = ctx.MkEq(fapp, fapp); BoolExpr nontrivial_eq = ctx.MkEq(fapp, fapp2); Goal g = ctx.MkGoal(true); g.Assert(trivial_eq); g.Assert(nontrivial_eq); Console.WriteLine("Goal: " + g); Solver solver = ctx.MkSolver(); foreach (BoolExpr a in g.Formulas) solver.Assert(a); if (solver.Check() != Status.SATISFIABLE) throw new TestFailedException(); ApplyResult ar = ApplyTactic(ctx, ctx.MkTactic("simplify"), g); if (ar.NumSubgoals == 1 && (ar.Subgoals[0].IsDecidedSat || ar.Subgoals[0].IsDecidedUnsat)) throw new TestFailedException(); ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g); if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedSat) throw new TestFailedException(); g.Assert(ctx.MkEq(ctx.MkNumeral(1, ctx.MkBitVecSort(32)), ctx.MkNumeral(2, ctx.MkBitVecSort(32)))); ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g); if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat) throw new TestFailedException(); Goal g2 = ctx.MkGoal(true, true); ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g2); if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedSat) throw new TestFailedException(); g2 = ctx.MkGoal(true, true); g2.Assert(ctx.MkFalse()); ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g2); if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat) throw new TestFailedException(); Goal g3 = ctx.MkGoal(true, true); Expr xc = ctx.MkConst(ctx.MkSymbol("x"), ctx.IntSort); Expr yc = ctx.MkConst(ctx.MkSymbol("y"), ctx.IntSort); g3.Assert(ctx.MkEq(xc, ctx.MkNumeral(1, ctx.IntSort))); g3.Assert(ctx.MkEq(yc, ctx.MkNumeral(2, ctx.IntSort))); BoolExpr constr = ctx.MkEq(xc, yc); g3.Assert(constr); ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g3); if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat) throw new TestFailedException(); ModelConverterTest(ctx); // Real num/den test. RatNum rn = ctx.MkReal(42, 43); Expr inum = rn.Numerator; Expr iden = rn.Denominator; Console.WriteLine("Numerator: " + inum + " Denominator: " + iden); if (inum.ToString() != "42" || iden.ToString() != "43") throw new TestFailedException(); if (rn.ToDecimalString(3) != "0.976?") throw new TestFailedException(); BigIntCheck(ctx, ctx.MkReal("-1231231232/234234333")); BigIntCheck(ctx, ctx.MkReal("-123123234234234234231232/234234333")); BigIntCheck(ctx, ctx.MkReal("-234234333")); BigIntCheck(ctx, ctx.MkReal("234234333/2")); string bn = "1234567890987654321"; if (ctx.MkInt(bn).BigInteger.ToString() != bn) throw new TestFailedException(); if (ctx.MkBV(bn, 128).BigInteger.ToString() != bn) throw new TestFailedException(); if (ctx.MkBV(bn, 32).BigInteger.ToString() == bn) throw new TestFailedException(); // Error handling test. try { IntExpr i = ctx.MkInt("1/2"); throw new TestFailedException(); // unreachable } catch (Z3Exception) { } }
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(); }