MkSolver() public méthode

Creates a new (incremental) solver.
This solver also uses a set of builtin tactics for handling the first check-sat command, and check-sat commands that take more than a given number of milliseconds to be solved.
public MkSolver ( Symbol logic = null ) : Solver
logic Symbol
Résultat Solver
Exemple #1
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", 32);
            BitVecExpr y = ctx.MkBVConst("y", 32);

            BitVecExpr two = ctx.MkBV(2, 32);
            BitVecExpr three = ctx.MkBV(3, 32);
            BitVecExpr tf = ctx.MkBV(24, 32);

            Solver s = ctx.MkSolver();
            s.Assert(ctx.MkEq(ctx.MkBVLSHR(x, two), three));
            Console.WriteLine(s.Check());
            Console.WriteLine(s.Model);

            s = ctx.MkSolver();
            s.Assert(ctx.MkEq(ctx.MkBVSHL(x, two), three));
            Console.WriteLine(s.Check());

            s = ctx.MkSolver();
            s.Assert(ctx.MkEq(ctx.MkBVRotateLeft(x, two), three));
            Console.WriteLine(s.Check());
            Console.WriteLine(s.Model);

            s = ctx.MkSolver();
            s.Assert(ctx.MkEq(ctx.MkBVSHL(x, two), tf));
            Console.WriteLine(s.Check());
            Console.WriteLine(s.Model);
        }
    }
Exemple #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", 32);
            BitVecExpr[] powers = new BitVecExpr[32];
            for (uint i = 0; i < 32; i++)
                powers[i] = ctx.MkBVSHL(ctx.MkBV(1, 32), ctx.MkBV(i, 32));

            BoolExpr step_zero = ctx.MkEq(ctx.MkBVAND(x, ctx.MkBVSub(x, ctx.MkBV(1, 32))), ctx.MkBV(0, 32));

            BoolExpr fast = ctx.MkAnd(ctx.MkNot(ctx.MkEq(x, ctx.MkBV(0, 32))),
                                      step_zero);

            BoolExpr slow = ctx.MkFalse();
            foreach (BitVecExpr p in powers)
                slow = ctx.MkOr(slow, ctx.MkEq(x, p));

        TestDriver.CheckString(fast, "(and (not (= x #x00000000)) (= (bvand x (bvsub x #x00000001)) #x00000000))");

            Solver s = ctx.MkSolver();
            s.Assert(ctx.MkNot(ctx.MkEq(fast, slow)));
            TestDriver.CheckUNSAT(s.Check());

            s = ctx.MkSolver();
            s.Assert(ctx.MkNot(step_zero));
            TestDriver.CheckSAT(s.Check());
        }
    }
Exemple #3
0
    public void Run()
    {
        Dictionary<string, string> cfg = new Dictionary<string, string>() {
            { "AUTO_CONFIG", "true" },
            { "MODEL", "true" } };

        using (Context ctx = new Context(cfg))
        {
            EnumSort color = ctx.MkEnumSort("Color", new string[] { "red", "green", "blue" });

            Expr red = color.Consts[0];
            Expr green = color.Consts[1];
            Expr blue = color.Consts[2];

            Console.WriteLine(ctx.MkEq(green, blue));
            Console.WriteLine(ctx.MkEq(green, blue).Simplify());

            Expr c = ctx.MkConst("c", color);

            Solver s = ctx.MkSolver();
            s.Assert(ctx.MkNot(ctx.MkEq(c, green)));
            s.Assert(ctx.MkNot(ctx.MkEq(c, blue)));
            Console.WriteLine(s.Check());
            Console.WriteLine(s.Model);
        }
    }
Exemple #4
0
    public void Run()
    {
        Dictionary<string, string> cfg = new Dictionary<string, string>() { };

        using (Context ctx = new Context(cfg))
        {
            FuncDecl f = ctx.MkFuncDecl("f", ctx.IntSort, ctx.IntSort);
            FuncDecl g = ctx.MkFuncDecl("g", ctx.IntSort, ctx.IntSort);

            IntExpr a = ctx.MkIntConst("a");
            IntExpr b = ctx.MkIntConst("b");
            IntExpr c = ctx.MkIntConst("c");

            IntExpr x = ctx.MkIntConst("x");

            Solver s = ctx.MkSolver();
            Params p = ctx.MkParams();
            p.Add("AUTO_CONFIG", false);
            p.Add("MBQI", false);
            s.Parameters = p;

            s.Assert(ctx.MkForall(new Expr[] { x }, ctx.MkEq(f[g[x]], x), 1, new Pattern[] { ctx.MkPattern(f[g[x]]) }));
            s.Assert(ctx.MkEq(a, g[b]));
            s.Assert(ctx.MkEq(b, c));
            s.Assert(ctx.MkDistinct(f[a], c));

            Console.WriteLine(s);
            Console.WriteLine(s.Check());
        }
    }
Exemple #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");

            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);
        }
    }
Exemple #6
0
        public static bool sat(BoolExpr f1)
        {
            Solver s = ctx.MkSolver();

            s.Assert(f1.expr);
            return(s.Check() == Status.SATISFIABLE);
        }
Exemple #7
0
    public void Run()
    {
        Dictionary<string, string> cfg = new Dictionary<string, string>() {
            { "AUTO_CONFIG", "true" } };

        using (Context ctx = new Context(cfg))
        {
            Sort A = ctx.MkUninterpretedSort("A");
            Sort B = ctx.MkUninterpretedSort("B");

            FuncDecl f = ctx.MkFuncDecl("f", A, B);

            Expr a1 = ctx.MkConst("a1", A);
            Expr a2 = ctx.MkConst("a2", A);
            Expr b = ctx.MkConst("b", B);
            Expr x = ctx.MkConst("x", A);
            Expr y = ctx.MkConst("y", A);

            Solver s = ctx.MkSolver();

            s.Assert(ctx.MkNot(ctx.MkEq(a1, a2)));
            s.Assert(ctx.MkEq(f[a1], b));
            s.Assert(ctx.MkEq(f[a2], b));
            s.Assert(ctx.MkForall(new Expr[] { x, y }, ctx.MkImplies(ctx.MkEq(f[x], f[y]),
                                                                     ctx.MkEq(x, y)),
                                                       1,
                                                       new Pattern[] { ctx.MkPattern(f[x], f[y]) }));
            Console.WriteLine(s);
            Console.WriteLine(s.Check());
        }
    }
Exemple #8
0
        public static Expr EeAndGt(String left1, int left2, String right1, int right2)
        {
            using (Context ctx = new Context())
            {
                Expr a = ctx.MkConst(left1, ctx.MkIntSort());
                Expr b = ctx.MkNumeral(left2, ctx.MkIntSort());
                Expr c = ctx.MkConst(right1, ctx.MkIntSort());
                Expr d = ctx.MkNumeral(right2, ctx.MkIntSort());

                Solver s = ctx.MkSolver();
                s.Assert(ctx.MkAnd(ctx.MkEq((ArithExpr)a, (ArithExpr)b), ctx.MkGt((ArithExpr)c, (ArithExpr)d)));
                s.Check();

                BoolExpr testing = ctx.MkAnd(ctx.MkEq((ArithExpr)a, (ArithExpr)b), ctx.MkGt((ArithExpr)c, (ArithExpr)d));
                Model model = Check(ctx, testing, Status.SATISFIABLE);

                Expr result2;
                Model m2 = s.Model;
                foreach (FuncDecl d2 in m2.Decls)
                {
                    result2 = m2.ConstInterp(d2);
                    return result2;
                }
            }
            return null;
        }
Exemple #9
0
    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));
        }
    }
Exemple #10
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)) );
        }
    }
Exemple #11
0
    public void Run()
    {
        Dictionary<string, string> cfg = new Dictionary<string, string>() {
            { "AUTO_CONFIG", "true" } };

        using (Context ctx = new Context(cfg))
        {
            BoolExpr a = ctx.MkBoolConst("a");
            BoolExpr b = ctx.MkBoolConst("b");
            BoolExpr c = ctx.MkBoolConst("c");
            BoolExpr d = ctx.MkBoolConst("d");
            BoolExpr e = ctx.MkBoolConst("e");
            BoolExpr f = ctx.MkBoolConst("f");
            BoolExpr g = ctx.MkBoolConst("g");
            BoolExpr z = ctx.MkBoolConst("z");

            Solver s = ctx.MkSolver();

            s.Assert(DependsOn(ctx, a, new BoolExpr[] { b, c, z }));
            s.Assert(DependsOn(ctx, b, new BoolExpr[] { d }));
            s.Assert(DependsOn(ctx, c, new BoolExpr[] { ctx.MkOr(d, e), ctx.MkOr(f, g) }));
            s.Assert(Conflict(ctx, d, e));
            s.Assert(a);
            s.Assert(z);

            Console.WriteLine(s.Check());
            Console.WriteLine(s.Model);
        }
    }
Exemple #12
0
    public void Run()
    {
        Dictionary<string, string> cfg = new Dictionary<string, string>() {
            { "AUTO_CONFIG", "true" } };

        using (Context ctx = new Context(cfg))
        {
            Sort A = ctx.MkUninterpretedSort("A");
            Expr x = ctx.MkConst("x", A);
            Expr y = ctx.MkConst("y", A);
            FuncDecl f = ctx.MkFuncDecl("f", A, A);

            Solver s = ctx.MkSolver();
            s.Assert(ctx.MkEq(f[f[x]], x),
                     ctx.MkEq(f[x], y),
                     ctx.MkNot(ctx.MkEq(x, y)));

            Console.WriteLine(s.Check());
            Model m = s.Model;
            Console.WriteLine(m);
            Console.WriteLine("interpretation assigned to A: ");
            foreach (Expr a in m.SortUniverse(A))
                Console.WriteLine(a);
        }
    }
Exemple #13
0
    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);
        }
    }
Exemple #14
0
    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);
        }
    }
Exemple #15
0
        static void Prove(Z3.Context ctx, BoolExpr f, bool useMBQI = false, params BoolExpr[] assumptions)
        {
            Console.WriteLine("Proving: " + f);
            Solver s = ctx.MkSolver();
            Params p = ctx.MkParams();

            p.Add("mbqi", useMBQI);
            s.Parameters = p;
            foreach (BoolExpr a in assumptions)
            {
                s.Assert(a);
            }
            s.Assert(ctx.MkNot(f));
            Status q = s.Check();

            switch (q)
            {
            case Status.UNKNOWN:
                Console.WriteLine("Unknown because: " + s.ReasonUnknown);
                break;

            case Status.SATISFIABLE:
                throw new Exception("Test failed");

            case Status.UNSATISFIABLE:
                Console.WriteLine("OK, proof: " + s.Proof);
                break;
            }
        }
Exemple #16
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.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());
        }
    }
Exemple #17
0
    public void Run()
    {
        using (Context ctx = new Context())
        {
            Sort U = ctx.MkUninterpretedSort("U");
            FuncDecl f = ctx.MkFuncDecl("f", U, U);
            Expr a = ctx.MkConst("a", U);
            Expr b = ctx.MkConst("b", U);
            Expr c = ctx.MkConst("c", U);

            Solver s = ctx.MkSolver();
            s.Assert(ctx.MkEq(f[f[a]], b),
                     ctx.MkNot(ctx.MkEq(f[b], c)),
                     ctx.MkEq(f[c], c));
            Console.WriteLine(s.Check());
            Model m = s.Model;
            foreach (FuncDecl d in m.Decls)
                if (d.DomainSize == 0)
                    Console.WriteLine(d.Name + " -> " + m.ConstInterp(d));
                else
                    Console.WriteLine(d.Name + " -> " + m.FuncInterp(d));

            Console.WriteLine(m.NumSorts);
            Console.WriteLine(m.Sorts[0]);

            foreach(Sort srt in m.Sorts)
                Console.WriteLine(srt);

            foreach (Expr v in m.SortUniverse(U))
                Console.WriteLine(v);
        }
    }
Exemple #18
0
    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);
        }
    }
Exemple #19
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", 32);
            BitVecExpr y = ctx.MkBVConst("y", 32);

            BoolExpr q = ctx.MkAnd(ctx.MkEq(ctx.MkBVAdd(x, y), ctx.MkBV(2, 32)),
                                   ctx.MkBVSGT(x, ctx.MkBV(0, 32)),
                                   ctx.MkBVSGT(y, ctx.MkBV(0, 32)));

            Console.WriteLine(q);

            Solver s = ctx.MkSolver();
            s.Assert(q);
            Console.WriteLine(s.Check());
            Console.WriteLine(s.Model);

            q = ctx.MkEq(ctx.MkBVAND(x, y), ctx.MkBVNeg(y));
            Console.WriteLine(q);

            s = ctx.MkSolver();
            s.Assert(q);
            Console.WriteLine(s.Check());
            Console.WriteLine(s.Model);

            q = ctx.MkBVSLT(x, ctx.MkBV(0, 32));
            Console.WriteLine(q);

            s = ctx.MkSolver();
            s.Assert(q);
            Console.WriteLine(s.Check());
            Console.WriteLine(s.Model);

            q = ctx.MkBVULT(x, ctx.MkBV(0, 32));
            Console.WriteLine(q);

            s = ctx.MkSolver();
            s.Assert(q);
            Console.WriteLine(s.Check());
        }
    }
Exemple #20
0
    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));
        }
    }
Exemple #21
0
 public void Run()
 {
     using (Context ctx = new Context())
     {
         BoolExpr e = ctx.MkFalse();
         Solver s = ctx.MkSolver();
         s.Assert(e);
         Console.WriteLine(s.Check());
     }
 }
Exemple #22
0
    public static void Main()
    {
        Context ctx = new Context();

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

        Solver s = ctx.MkSolver();
        s.Parameters = p;
        s.Check(); // Complains by throwing an assertion (OK).
    }
Exemple #23
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 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);
        }
    }
Exemple #24
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();
    }
Exemple #25
0
    public void Run()
    {
        Dictionary<string, string> cfg = new Dictionary<string, string>() {
            { "AUTO_CONFIG", "true" },
            { "MODEL", "true" } };

        using (Context ctx = new Context(cfg))
        {
            Solver s = ctx.MkSolver();
            Console.WriteLine(s.Check());
            Console.WriteLine(s.Model);
        }
    }
Exemple #26
0
        static void Main(string[] args)
        {
            using (Context ctx = new Context())
            {
                Expr x = ctx.MkConst("x", ctx.MkIntSort());
                Expr zero = ctx.MkNumeral(0, ctx.MkIntSort());

                Solver s = ctx.MkSolver();
                s.Assert(ctx.MkLt((ArithExpr)zero, (ArithExpr)x)); // 0<x

                Status result = s.Check();
                Console.WriteLine(result);
            }
        }
Exemple #27
0
    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());
        }
    }
Exemple #28
0
    public void Run()
    {
        Dictionary<string, string> cfg = new Dictionary<string, string>() {
            { "AUTO_CONFIG", "true" },
            { "MODEL", "true" } };

        using (Context ctx = new Context(cfg))
        {
            Constructor cred = ctx.MkConstructor("red", "is_red");
            Constructor cgreen = ctx.MkConstructor("green", "is_green");
            Constructor cblue = ctx.MkConstructor("blue", "is_blue");

            DatatypeSort color = ctx.MkDatatypeSort("Color", new Constructor[] { cred, cgreen, cblue });

            Expr Red = ctx.MkConst(color.Constructors[0]);
            Expr Green = ctx.MkConst(color.Constructors[1]);
            Expr Blue = ctx.MkConst(color.Constructors[2]);

            Expr c = ctx.MkConst("c", color);

            Solver s = ctx.MkSolver();
            s.Assert(ctx.MkNot(ctx.MkOr(ctx.MkEq(c, Red), ctx.MkEq(c, Green), ctx.MkEq(c, Blue))));
            Console.WriteLine(s.Check()); // must be unsat

            BoolExpr c_is_red = (BoolExpr)color.Recognizers[0][c];
            BoolExpr c_is_green = (BoolExpr)color.Recognizers[1][c];
            BoolExpr c_is_blue = (BoolExpr)color.Recognizers[2][c];

            s = ctx.MkSolver();
            s.Assert(ctx.MkOr(c_is_red, c_is_green, c_is_blue));
            Console.WriteLine(s.Check()); // must be sat

            s = ctx.MkSolver();
            s.Assert(ctx.MkNot(ctx.MkOr(c_is_red, c_is_green, c_is_blue)));
            Console.WriteLine(s.Check()); // must be unsat
        }
    }
Exemple #29
0
    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));
        }
    }
Exemple #30
0
 static Model Check(Context ctx, BoolExpr f, Status sat)
 {
     Solver s = ctx.MkSolver();
     s.Assert(f);
     if (s.Check() != sat)
     {
         return null;
     };
     if (sat == Status.SATISFIABLE)
     {
         Console.WriteLine("Data:" + s.Model);
         return s.Model;
     }
     else
         return null;
 }
Exemple #31
0
    public static void Main()
    {
        Context ctx = new Context();

        Params p = ctx.MkParams();
        p.Add("smt.arith.nl", true);
        p.Add("smt.arith.nl.rounds", 42);

        Solver s = ctx.MkSolver();
        s.Parameters = p;
        Console.WriteLine(s); // says "(solver)"

        s = ctx.MkSimpleSolver();
        s.Parameters = p;
        Console.WriteLine(s); // should also say "(solver)"
    }
Exemple #32
0
    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);
        }
    }
Exemple #33
0
        static Model Check(Z3.Context ctx, BoolExpr f, Status sat)
        {
            Solver s = ctx.MkSolver();

            s.Assert(f);
            if (s.Check() != sat)
            {
                throw new Exception("Test Failed");
            }
            if (sat == Status.SATISFIABLE)
            {
                return(s.Model);
            }
            else
            {
                return(null);
            }
        }
Exemple #34
0
 public Solver Solver()
 => Context.MkSolver();