public MkGoal ( bool models = true, bool unsatCores = false, bool proofs = false ) : |
||
models | bool | Indicates whether model generation should be enabled. |
unsatCores | bool | Indicates whether unsat core generation should be enabled. |
proofs | bool | Indicates whether proof generation should be enabled. |
return |
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)) { 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"); 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"); 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"); 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 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" } }; 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" } }; 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); } }
/// <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) { } }
/// <summary> /// A simple array example. /// </summary> /// <param name="ctx"></param> static void ArrayExample1(Context ctx) { Console.WriteLine("ArrayExample1"); Goal g = ctx.MkGoal(true); ArraySort asort = ctx.MkArraySort(ctx.IntSort, ctx.MkBitVecSort(32)); ArrayExpr aex = (ArrayExpr)ctx.MkConst(ctx.MkSymbol("MyArray"), asort); Expr sel = ctx.MkSelect(aex, ctx.MkInt(0)); g.Assert(ctx.MkEq(sel, ctx.MkBV(42, 32))); Symbol xs = ctx.MkSymbol("x"); IntExpr xc = (IntExpr)ctx.MkConst(xs, ctx.IntSort); Symbol fname = ctx.MkSymbol("f"); Sort[] domain = { ctx.IntSort }; FuncDecl fd = ctx.MkFuncDecl(fname, domain, ctx.IntSort); Expr[] fargs = { ctx.MkConst(xs, ctx.IntSort) }; IntExpr fapp = (IntExpr)ctx.MkApp(fd, fargs); g.Assert(ctx.MkEq(ctx.MkAdd(xc, fapp), ctx.MkInt(123))); Solver s = ctx.MkSolver(); foreach (BoolExpr a in g.Formulas) s.Assert(a); Console.WriteLine("Solver: " + s); Status q = s.Check(); Console.WriteLine("Status: " + q); if (q != Status.SATISFIABLE) throw new TestFailedException(); Console.WriteLine("Model = " + s.Model); Console.WriteLine("Interpretation of MyArray:\n" + s.Model.FuncInterp(aex.FuncDecl)); Console.WriteLine("Interpretation of x:\n" + s.Model.ConstInterp(xc)); Console.WriteLine("Interpretation of f:\n" + s.Model.FuncInterp(fd)); Console.WriteLine("Interpretation of MyArray as Term:\n" + s.Model.FuncInterp(aex.FuncDecl)); }
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(); }
/// <summary> /// Demonstrates how to use the ParOr tactic. /// </summary> static void ParOrExample(Context ctx) { Console.WriteLine("ParOrExample"); BitVecSort bvs = ctx.MkBitVecSort(32); Expr x = ctx.MkConst("x", bvs); Expr y = ctx.MkConst("y", bvs); BoolExpr q = ctx.MkEq(x, y); Goal g = ctx.MkGoal(true); g.Assert(q); Tactic t1 = ctx.MkTactic("qfbv"); Tactic t2 = ctx.MkTactic("qfbv"); Tactic p = ctx.ParOr(t1, t2); ApplyResult ar = p.Apply(g); if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedSat) throw new TestFailedException(); }
/// <summary> /// Shows how to use Solver(logic) /// </summary> /// <param name="ctx"></param> static void LogicExample(Context ctx) { Console.WriteLine("LogicTest"); Microsoft.Z3.Global.ToggleWarningMessages(true); BitVecSort bvs = ctx.MkBitVecSort(32); Expr x = ctx.MkConst("x", bvs); Expr y = ctx.MkConst("y", bvs); BoolExpr eq = ctx.MkEq(x, y); // Use a solver for QF_BV Solver s = ctx.MkSolver("QF_BV"); s.Assert(eq); Status res = s.Check(); Console.WriteLine("solver result: " + res); // Or perhaps a tactic for QF_BV Goal g = ctx.MkGoal(true); g.Assert(eq); Tactic t = ctx.MkTactic("qfbv"); ApplyResult ar = t.Apply(g); Console.WriteLine("tactic result: " + ar); if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedSat) throw new TestFailedException(); }