MkTactic() public method

Creates a new Tactic.
public MkTactic ( string name ) : Microsoft.Z3.Tactic
name string
return Microsoft.Z3.Tactic
Esempio n. 1
0
    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]);
        }
    }
Esempio n. 2
0
    public void Run()
    {
        Dictionary<string, string> cfg = new Dictionary<string, string>() {
            { "AUTO_CONFIG", "true" } };

        using (Context ctx = new Context(cfg))
        {
            BitVecExpr x = ctx.MkBVConst("x", 16);
            BitVecExpr y = ctx.MkBVConst("y", 16);

            Params p = ctx.MkParams();
            p.Add(":mul2concat", true);

            Tactic t = ctx.Then(ctx.UsingParams(ctx.MkTactic("simplify"), p),
                                ctx.MkTactic("solve-eqs"),
                                ctx.MkTactic("bit-blast"),
                                ctx.MkTactic("aig"),
                                ctx.MkTactic("sat"));
            Solver s = ctx.MkSolver(t);

            s.Assert(ctx.MkEq(ctx.MkBVAdd(ctx.MkBVMul(x, ctx.MkBV(32, 16)), y), ctx.MkBV(13, 16)));
            s.Assert(ctx.MkBVSLT(ctx.MkBVAND(x, y), ctx.MkBV(10, 16)));
            s.Assert(ctx.MkBVSGT(y, ctx.MkBV(-100, 16)));

            Console.WriteLine(s.Check());
            Model m = s.Model;
            Console.WriteLine(m);

            Console.WriteLine(ctx.MkBVAdd(ctx.MkBVMul(x, ctx.MkBV(32, 16)), y) + " == " + m.Evaluate(ctx.MkBVAdd(ctx.MkBVMul(x, ctx.MkBV(32, 16)), y)));
            Console.WriteLine(ctx.MkBVAND(x, y) + " == " + m.Evaluate(ctx.MkBVAND(x, y)) );
        }
    }
Esempio n. 3
0
    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);
        }
    }
Esempio n. 4
0
    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]);
        }
    }
Esempio n. 5
0
    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]);
        }
    }
Esempio n. 6
0
    public void Run()
    {
        Dictionary<string, string> cfg = new Dictionary<string, string>() {
            { "AUTO_CONFIG", "true" } };

        using (Context ctx = new Context(cfg))
        {
            BitVecExpr x = ctx.MkBVConst("x", 16);
            BitVecExpr y = ctx.MkBVConst("y", 16);

            Tactic t = ctx.Then(ctx.MkTactic("simplify"), ctx.MkTactic("solve-eqs"), ctx.MkTactic("bit-blast"), ctx.MkTactic("sat"));
            Solver s = ctx.MkSolver(t);

            s.Assert(ctx.MkEq(ctx.MkBVOR(x, y), ctx.MkBV(13, 16)));
            s.Assert(ctx.MkBVSGT(x, y));

            Console.WriteLine(s.Check());
            Console.WriteLine(s.Model);
        }
    }
Esempio n. 7
0
    public static void Main()
    {
        Context ctx = new Context();

        Params p = ctx.MkParams();
        p.Add("blah", "blah"); // invalid parameter name

        Tactic t1 = ctx.MkTactic("smt");
        Tactic t2 = ctx.UsingParams(t1, p);
        Solver s = ctx.MkSolver(t2);
        s.Check();
    }
Esempio n. 8
0
    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");
        }
    }
Esempio n. 9
0
    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));
        }
    }
Esempio n. 10
0
    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);
        }
    }
Esempio n. 11
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");
            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);
        }
    }
Esempio n. 12
0
    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);

        }
    }
Esempio n. 13
0
    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());
        }
    }
Esempio n. 14
0
        /// <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)
            {
            }
        }
Esempio n. 15
0
        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();
        }
Esempio n. 16
0
        /// <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();
        }
Esempio n. 17
0
        /// <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();
        }