MkEq() public méthode

Creates the equality x = y.
public MkEq ( Expr x, Expr y ) : BoolExpr
x Expr
y Expr
Résultat BoolExpr
Exemple #1
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 #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()
    {
        using (Context ctx = new Context())
        {
            Sort U = ctx.MkUninterpretedSort("U");
            Console.WriteLine(U);
            Expr a = ctx.MkConst("a", U);

            a = ctx.MkConst("a", U);
            Expr b = ctx.MkConst("b", U);
            Expr c = ctx.MkConst("c", U);

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

            Console.WriteLine(ctx.MkAnd(ctx.MkEq(a, b), ctx.MkEq(a, c)));
            Console.WriteLine(U == ctx.IntSort);

            Sort U2 = ctx.MkUninterpretedSort("U");
            Console.WriteLine(U == U2);

            U2 = ctx.MkUninterpretedSort("U2");
            Console.WriteLine(U == U2);
            Console.WriteLine(ctx.MkDistinct(a, b, c));

            FuncDecl f = ctx.MkFuncDecl("f", new Sort[] { U, U }, U);
            Console.WriteLine(ctx.MkEq(f[a,b], b));
        }
    }
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 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 #6
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 #7
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 #8
0
        /// <summary>
        /// Prove <tt>store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3))</tt>.
        /// </summary>
        /// <remarks>This example demonstrates how to use the array theory.</remarks>
        public static void ArrayExample2(Context ctx)
        {
            Console.WriteLine("ArrayExample2");

            Sort int_type = ctx.IntSort;
            Sort array_type = ctx.MkArraySort(int_type, int_type);

            ArrayExpr a1 = (ArrayExpr)ctx.MkConst("a1", array_type);
            ArrayExpr a2 = ctx.MkArrayConst("a2", int_type, int_type);
            Expr i1 = ctx.MkConst("i1", int_type);
            Expr i2 = ctx.MkConst("i2", int_type);
            Expr i3 = ctx.MkConst("i3", int_type);
            Expr v1 = ctx.MkConst("v1", int_type);
            Expr v2 = ctx.MkConst("v2", int_type);

            Expr st1 = ctx.MkStore(a1, i1, v1);
            Expr st2 = ctx.MkStore(a2, i2, v2);

            Expr sel1 = ctx.MkSelect(a1, i3);
            Expr sel2 = ctx.MkSelect(a2, i3);

            /* create antecedent */
            BoolExpr antecedent = ctx.MkEq(st1, st2);

            /* create consequent: i1 = i3 or  i2 = i3 or select(a1, i3) = select(a2, i3) */
            BoolExpr consequent = ctx.MkOr(new BoolExpr[] { ctx.MkEq(i1, i3), ctx.MkEq(i2, i3), ctx.MkEq(sel1, sel2) });

            /* prove store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3)) */
            BoolExpr thm = ctx.MkImplies(antecedent, consequent);
            Console.WriteLine("prove: store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3))");
            Console.WriteLine("{0}", (thm));
            Prove(ctx, thm);
        }
Exemple #9
0
    public void Run()
    {
        using (Context ctx = new Context())
        {
            BoolExpr p = ctx.MkBoolConst("p");
            Console.WriteLine(ctx.MkNot(p));
            Console.WriteLine(ctx.MkNot(p));
            IntExpr x = ctx.MkIntConst("x");
            IntExpr y = ctx.MkIntConst("y");

            Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1)));
            Console.WriteLine(ctx.MkAdd(ctx.MkInt(1), x));
            Console.WriteLine(ctx.MkAdd(x, y));
            Console.WriteLine(ctx.MkMul(ctx.MkInt(2), x));
            Console.WriteLine(ctx.MkMul(x, ctx.MkInt(2)));
            Console.WriteLine(ctx.MkMul(x, y));
            Console.WriteLine(ctx.MkDiv(x, y));
            Console.WriteLine(ctx.MkMod(x, y));
            Console.WriteLine(ctx.MkEq(x, y));
            Console.WriteLine(ctx.MkDistinct(x, y, x));
            Console.WriteLine(ctx.MkNot(ctx.MkEq(x, y)));
            Console.WriteLine(ctx.MkEq(x, y));
            Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1)));
            Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1)));

            BoolExpr q = ctx.MkBoolConst("q");
            Console.WriteLine(ctx.MkNot(p));
            Console.WriteLine(ctx.MkNot(p));
            Console.WriteLine(ctx.MkAnd(p, q));
            Console.WriteLine(ctx.MkAnd(p, q));
            Console.WriteLine(ctx.MkEq(x, y));
        }
    }
Exemple #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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]);
        }
    }
Exemple #17
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 #18
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 #19
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 #20
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 #21
0
        //Constructor
        public Z3Context()
        {
            //Initialize Config and Context
            _config = new Config();
            _config.SetParamValue("MODEL", "true"); // corresponds to /m switch
            _config.SetParamValue("MACRO_FINDER", "true");
            _context = new Context(_config);

            //Setup custom conversion method BoolToInt (boolean -> integer)----------------------------------------------------------------
            FuncDecl boolToInt = _context.MkFuncDecl("BoolToInt", _context.MkBoolSort(), _context.MkIntSort());
            Term i = _context.MkConst("i", _context.MkBoolSort());
            Term fDef = _context.MkIte(_context.MkEq(i, _context.MkTrue()), _context.MkIntNumeral(1), _context.MkIntNumeral(0)); // x == true => 1, x == false => 0
            Term fStatement = _context.MkForall(0, new Term[] { i }, null, _context.MkEq(_context.MkApp(boolToInt, i), fDef));
            _context.AssertCnstr(fStatement);

            //
            _functions.Add("BoolToInt", new Z3Function(boolToInt));
            //-----------------------------------------------------------------------------------------------------------------------------
        }
Exemple #22
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());
        }
    }
Exemple #23
0
    public void Run()
    {
        Dictionary<string, string> cfg = new Dictionary<string, string>() {
            { "AUTO_CONFIG", "true" } };

        using (Context ctx = new Context(cfg))
        {
            ArithExpr[] Q = new ArithExpr[8];
            for (uint i = 0; i < 8; i++)
                Q[i] = ctx.MkIntConst(string.Format("Q_{0}", i + 1));

            BoolExpr[] val_c = new BoolExpr[8];
            for (uint i = 0; i < 8; i++)
                val_c[i] = ctx.MkAnd(ctx.MkLe(ctx.MkInt(1), Q[i]),
                                     ctx.MkLe(Q[i], ctx.MkInt(8)));

            BoolExpr col_c = ctx.MkDistinct(Q);

            BoolExpr[][] diag_c = new BoolExpr[8][];
            for (uint i = 0; i < 8; i++)
            {
                diag_c[i] = new BoolExpr[i];
                for (uint j = 0; j < i; j++)
                    diag_c[i][j] = (BoolExpr)ctx.MkITE(ctx.MkEq(ctx.MkInt(i), ctx.MkInt(j)),
                                             ctx.MkTrue(),
                                             ctx.MkAnd(ctx.MkNot(ctx.MkEq(ctx.MkSub(Q[i], Q[j]),
                                                                          ctx.MkSub(ctx.MkInt(i), ctx.MkInt(j)))),
                                                       ctx.MkNot(ctx.MkEq(ctx.MkSub(Q[i], Q[j]),
                                                                          ctx.MkSub(ctx.MkInt(j), ctx.MkInt(i))))));
            }

            Solver s = ctx.MkSolver();
            s.Assert(val_c);
            s.Assert(col_c);
            foreach (var c in diag_c)
                s.Assert(c);

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

        using (Context ctx = new Context(cfg))
        {
            ArrayExpr A = ctx.MkArrayConst("A", ctx.IntSort, ctx.IntSort);

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

            Solver s = ctx.MkSolver();
            s.Assert(ctx.MkEq(ctx.MkSelect(A, x), x));
            s.Assert(ctx.MkEq(ctx.MkStore(A, x, y), A));
            Console.WriteLine(s);
            Console.WriteLine(s.Check());
            Console.WriteLine(s.Model);
        }
    }
Exemple #25
0
        /// <summary>
        /// Create axiom: function f is injective in the i-th argument.
        /// </summary>
        /// <remarks>
        /// The following axiom is produced:
        /// <c>
        /// forall (x_0, ..., x_n) finv(f(x_0, ..., x_i, ..., x_{n-1})) = x_i
        /// </c>
        /// Where, <code>finv</code>is a fresh function declaration.
        /// </summary>
        public static BoolExpr InjAxiom(Context ctx, FuncDecl f, int i)
        {
            Sort[] domain = f.Domain;
            uint sz = f.DomainSize;

            if (i >= sz)
            {
                Console.WriteLine("failed to create inj axiom");
                return null;
            }

            /* declare the i-th inverse of f: finv */
            Sort finv_domain = f.Range;
            Sort finv_range = domain[i];
            FuncDecl finv = ctx.MkFuncDecl("f_fresh", finv_domain, finv_range);

            /* allocate temporary arrays */
            Expr[] xs = new Expr[sz];
            Symbol[] names = new Symbol[sz];
            Sort[] types = new Sort[sz];

            /* fill types, names and xs */

            for (uint j = 0; j < sz; j++)
            {
                types[j] = domain[j];
                names[j] = ctx.MkSymbol(String.Format("x_{0}", j));
                xs[j] = ctx.MkBound(j, types[j]);
            }
            Expr x_i = xs[i];

            /* create f(x_0, ..., x_i, ..., x_{n-1}) */
            Expr fxs = f[xs];

            /* create f_inv(f(x_0, ..., x_i, ..., x_{n-1})) */
            Expr finv_fxs = finv[fxs];

            /* create finv(f(x_0, ..., x_i, ..., x_{n-1})) = x_i */
            Expr eq = ctx.MkEq(finv_fxs, x_i);

            /* use f(x_0, ..., x_i, ..., x_{n-1}) as the pattern for the quantifier */
            Pattern p = ctx.MkPattern(new Expr[] { fxs });

            /* create & assert quantifier */
            BoolExpr q = ctx.MkForall(
                types, /* types of quantified variables */
                names, /* names of quantified variables */
                eq,
                1,
                new Pattern[] { p } /* patterns */);

            return q;
        }
Exemple #26
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]);
        }
    }
Exemple #27
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);
        }
    }
Exemple #28
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);
        }
    }
Exemple #29
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 #30
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);

            Console.WriteLine(ctx.MkBVAdd(x, ctx.MkBV(2, 16)));

            Console.WriteLine(ctx.MkBVSub(ctx.MkBVAdd(x, y), ctx.MkBV(1, 16)).Simplify());

            BitVecExpr a = ctx.MkBV(-1, 16);
            BitVecExpr b = ctx.MkBV(65535, 16);
            Console.WriteLine(ctx.MkEq(a, b).Simplify());

            a = ctx.MkBV(-1, 32);
            b = ctx.MkBV(65535, 32);
            Console.WriteLine(ctx.MkEq(a, b).Simplify());
        }
    }
Exemple #31
0
 public static void cmp(IntExpr f1, IntExpr f2, out BoolExpr e)
 {
     e = new BoolExpr(ctx.MkEq(f1.expr, f2.expr));
 }