MkOr() public method

Create an expression representing t[0] or t[1] or ....
public MkOr ( ) : BoolExpr
return BoolExpr
コード例 #1
0
ファイル: tactic.5.cs プロジェクト: ExiaHan/z3test
    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);
        }
    }
コード例 #2
0
ファイル: install.2.cs プロジェクト: ExiaHan/z3test
    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");

            Console.WriteLine("Check 1");
            InstallCheck(ctx, new BoolExpr[] {
                                DependsOn(ctx, a, new BoolExpr[] { b, c, z }),
                                DependsOn(ctx, b, new BoolExpr[] { d }),
                                DependsOn(ctx, c, new BoolExpr[] { ctx.MkOr(d, e), ctx.MkOr(f, g) }),
                                Conflict(ctx, d, e),
                                Conflict(ctx, d, g),
                                a, z });

            Console.WriteLine("Check 2");
            InstallCheck(ctx, new BoolExpr[] {
                                DependsOn(ctx, a, new BoolExpr[] { b, c, z }),
                                DependsOn(ctx, b, new BoolExpr[] { d }),
                                DependsOn(ctx, c, new BoolExpr[] { ctx.MkOr(d, e), ctx.MkOr(f, g) }),
                                Conflict(ctx, d, e),
                                Conflict(ctx, d, g),
                                a, z, g });
        }
    }
コード例 #3
0
ファイル: tactic.4.cs プロジェクト: ExiaHan/z3test
    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]);
        }
    }
コード例 #4
0
ファイル: tst7.cs プロジェクト: ahorn/z3test
    public void Run()
    {
        using (Context ctx = new Context())
        {
            BoolExpr p = ctx.MkBoolConst("p");
            BoolExpr q = ctx.MkBoolConst("q");
            Console.WriteLine(ctx.MkAnd(p, q));
            Console.WriteLine(ctx.MkOr(p, q));
            Console.WriteLine(ctx.MkAnd(p, ctx.MkTrue()));
            Console.WriteLine(ctx.MkOr(p, ctx.MkFalse()));
            Console.WriteLine(ctx.MkNot(p));
            Console.WriteLine(ctx.MkImplies(p, q));
            Console.WriteLine(ctx.MkEq(p, q).Simplify());
            Console.WriteLine(ctx.MkEq(p, q));

            BoolExpr r = ctx.MkBoolConst("r");

            Console.WriteLine(ctx.MkNot(ctx.MkEq(p, ctx.MkNot(ctx.MkEq(q, r)))));
            Console.WriteLine(ctx.MkNot(ctx.MkEq(ctx.MkNot(ctx.MkEq(p, q)), r)));
            Console.WriteLine(ctx.MkEq(p, ctx.MkTrue()));
            Console.WriteLine(ctx.MkEq(p, ctx.MkFalse()));
            Console.WriteLine(ctx.MkEq(p, ctx.MkTrue()).Simplify());
            Console.WriteLine(ctx.MkEq(p, ctx.MkFalse()).Simplify());
            Console.WriteLine(ctx.MkEq(p, p).Simplify());
            Console.WriteLine(ctx.MkEq(p, q).Simplify());
            Console.WriteLine(ctx.MkAnd(p, q, r));
            Console.WriteLine(ctx.MkOr(p, q, r));

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

            Console.WriteLine(x is BoolExpr);
            Console.WriteLine(p is BoolExpr);
            Console.WriteLine(ctx.MkAnd(p, q) is BoolExpr);
            Console.WriteLine(p is BoolExpr);
            Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1)) is BoolExpr);
            Console.WriteLine(p.IsAnd);
            Console.WriteLine(ctx.MkOr(p, q).IsOr);
            Console.WriteLine(ctx.MkAnd(p, q).IsAnd);
            Console.WriteLine(x.IsNot);
            Console.WriteLine(p.IsNot);
            Console.WriteLine(ctx.MkNot(p));
            Console.WriteLine(ctx.MkNot(p).IsDistinct);
            Console.WriteLine(ctx.MkEq(p, q).IsDistinct);
            Console.WriteLine(ctx.MkDistinct(p, q).IsDistinct);
            Console.WriteLine(ctx.MkDistinct(x, ctx.MkAdd(x, ctx.MkInt(1)), ctx.MkAdd(x, ctx.MkInt(2))).IsDistinct);

            Console.WriteLine();

            Console.WriteLine(ctx.MkBool(true));
            Console.WriteLine(ctx.MkBool(false));
            Console.WriteLine(ctx.BoolSort);

            Context ctx1 = new Context();
            Console.WriteLine(ctx1.MkBool(true));
            Console.WriteLine(ctx1.BoolSort);
            Console.WriteLine(ctx1.MkBool(true).Sort == ctx1.BoolSort);
            Console.WriteLine(ctx1.MkBool(true).Sort == ctx.BoolSort);
            Console.WriteLine(ctx1.MkBool(true).Sort != ctx.BoolSort);
        }
    }
コード例 #5
0
ファイル: install.1.cs プロジェクト: ahorn/z3test
    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);
        }
    }
コード例 #6
0
ファイル: bit.1.cs プロジェクト: ExiaHan/z3test
    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());
        }
    }
コード例 #7
0
ファイル: z3py.12.cs プロジェクト: ExiaHan/z3test
    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);
        }
    }
コード例 #8
0
ファイル: Program.cs プロジェクト: sslab-gatech/juxta
        /// <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);
        }
コード例 #9
0
ファイル: install.2.cs プロジェクト: ExiaHan/z3test
 public BoolExpr Conflict(Context ctx, params BoolExpr[] packs)
 {
     BoolExpr q = ctx.MkFalse();
     foreach (BoolExpr p in packs)
         q = ctx.MkOr(q, ctx.MkNot(p));
     return q;
 }
コード例 #10
0
ファイル: datatype.3.cs プロジェクト: ExiaHan/z3test
    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
        }
    }
コード例 #11
0
ファイル: bit.2.cs プロジェクト: ExiaHan/z3test
    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 zero = ctx.MkBV(0, 32);

            BoolExpr trick = ctx.MkBVSLT(ctx.MkBVXOR(x, y), zero);

            BoolExpr opposite = ctx.MkOr(ctx.MkAnd(ctx.MkBVSLT(x, zero), ctx.MkBVSGE(y, zero)),
                                         ctx.MkAnd(ctx.MkBVSGE(x, zero), ctx.MkBVSLT(y, zero)));

            Solver s = ctx.MkSolver();
            s.Assert(ctx.MkNot(ctx.MkEq(trick, opposite)));
            Console.WriteLine(s.Check());

        }
    }
コード例 #12
0
ファイル: tactic.2.cs プロジェクト: ahorn/z3test
    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);

        }
    }
コード例 #13
0
ファイル: quant.3.cs プロジェクト: ExiaHan/z3test
    public void Run()
    {
        Dictionary<string, string> cfg = new Dictionary<string, string>() {
            { "AUTO_CONFIG", "true" } };

        using (Context ctx = new Context(cfg))
        {
            Sort T = ctx.MkUninterpretedSort("Type");
            FuncDecl subtype = ctx.MkFuncDecl("subtype", new Sort[] { T, T }, ctx.BoolSort);
            FuncDecl array_of = ctx.MkFuncDecl("array_of", T, T);
            Expr root = ctx.MkConst("root", T);

            Expr x = ctx.MkConst("x", T);
            Expr y = ctx.MkConst("y", T);
            Expr z = ctx.MkConst("z", T);

            BoolExpr[] axioms = new BoolExpr[] {
                ctx.MkForall(new Expr[] { x }, subtype[x, x]),
                ctx.MkForall(new Expr[] { x, y , z }, ctx.MkImplies(ctx.MkAnd((BoolExpr)subtype[x,y], (BoolExpr)subtype[y,z]), (BoolExpr)subtype[x,z])),
                ctx.MkForall(new Expr[] { x, y }, ctx.MkImplies(ctx.MkAnd((BoolExpr)subtype[x, y], (BoolExpr)subtype[y,x]), ctx.MkEq(x, y))),
                ctx.MkForall(new Expr[] { x, y, z }, ctx.MkImplies(ctx.MkAnd((BoolExpr)subtype[x,y],(BoolExpr)subtype[x,z]),
                                                                   ctx.MkOr((BoolExpr)subtype[y,z], (BoolExpr)subtype[z,y]))),
                ctx.MkForall(new Expr[] { x, y }, ctx.MkImplies((BoolExpr)subtype[x,y], (BoolExpr)subtype[array_of[x], array_of[y]])),
                ctx.MkForall(new Expr[] { x }, (BoolExpr) subtype[root, x])
            };

            Solver s = ctx.MkSolver();
            s.Assert(axioms);
            Console.WriteLine(s);
            Console.WriteLine(s.Check());
            Expr[] universe = s.Model.SortUniverse(T);
            foreach (var e in universe)
                Console.WriteLine(e);
            Console.WriteLine(s.Model);
        }
    }
コード例 #14
0
ファイル: Program.cs プロジェクト: izmaxx/VBADataGenerator
        public static Expr GtOrNe(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.MkOr(ctx.MkGt((ArithExpr)a, (ArithExpr)b), ctx.MkNot(ctx.MkEq((ArithExpr)c, (ArithExpr)d))));
                s.Check();

                BoolExpr testing = ctx.MkOr(ctx.MkGt((ArithExpr)a, (ArithExpr)b), ctx.MkNot(ctx.MkEq((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;
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: perillaseed/z3
        /// <summary>
        /// Extract unsatisfiable core example with AssertAndTrack
        /// </summary>
        public static void UnsatCoreAndProofExample2(Context ctx)
        {
            Console.WriteLine("UnsatCoreAndProofExample2");

            Solver solver = ctx.MkSolver();

            BoolExpr pa = ctx.MkBoolConst("PredA");
            BoolExpr pb = ctx.MkBoolConst("PredB");
            BoolExpr pc = ctx.MkBoolConst("PredC");
            BoolExpr pd = ctx.MkBoolConst("PredD");

            BoolExpr f1 = ctx.MkAnd(new BoolExpr[] { pa, pb, pc });
            BoolExpr f2 = ctx.MkAnd(new BoolExpr[] { pa, ctx.MkNot(pb), pc });
            BoolExpr f3 = ctx.MkOr(ctx.MkNot(pa), ctx.MkNot(pc));
            BoolExpr f4 = pd;

            BoolExpr p1 = ctx.MkBoolConst("P1");
            BoolExpr p2 = ctx.MkBoolConst("P2");
            BoolExpr p3 = ctx.MkBoolConst("P3");
            BoolExpr p4 = ctx.MkBoolConst("P4");

            solver.AssertAndTrack(f1, p1);
            solver.AssertAndTrack(f2, p2);
            solver.AssertAndTrack(f3, p3);
            solver.AssertAndTrack(f4, p4);
            Status result = solver.Check();

            if (result == Status.UNSATISFIABLE)
            {
                Console.WriteLine("unsat");
                Console.WriteLine("core: ");
                foreach (Expr c in solver.UnsatCore)
                {
                    Console.WriteLine("{0}", c);
                }
            }
        }
コード例 #16
0
ファイル: Program.cs プロジェクト: perillaseed/z3
        /// <summary>
        /// Create a forest of trees.
        /// </summary>
        /// <remarks>
        /// forest ::= nil | cons(tree, forest)
        /// tree   ::= nil | cons(forest, forest)
        /// </remarks>
        public static void ForestExample(Context ctx)
        {
            Console.WriteLine("ForestExample");

            Sort tree, forest;
            FuncDecl nil1_decl, is_nil1_decl, cons1_decl, is_cons1_decl, car1_decl, cdr1_decl;
            FuncDecl nil2_decl, is_nil2_decl, cons2_decl, is_cons2_decl, car2_decl, cdr2_decl;
            Expr nil1, nil2, t1, t2, t3, t4, f1, f2, f3, l1, l2, x, y, u, v;

            //
            // Declare the names of the accessors for cons.
            // Then declare the sorts of the accessors.
            // For this example, all sorts refer to the new types 'forest' and 'tree'
            // being declared, so we pass in null for both sorts1 and sorts2.
            // On the other hand, the sort_refs arrays contain the indices of the
            // two new sorts being declared. The first element in sort1_refs
            // points to 'tree', which has index 1, the second element in sort1_refs array
            // points to 'forest', which has index 0.
            //
            Symbol[] head_tail1 = new Symbol[] { ctx.MkSymbol("head"), ctx.MkSymbol("tail") };
            Sort[] sorts1 = new Sort[] { null, null };
            uint[] sort1_refs = new uint[] { 1, 0 }; // the first item points to a tree, the second to a forest

            Symbol[] head_tail2 = new Symbol[] { ctx.MkSymbol("car"), ctx.MkSymbol("cdr") };
            Sort[] sorts2 = new Sort[] { null, null };
            uint[] sort2_refs = new uint[] { 0, 0 }; // both items point to the forest datatype.
            Constructor nil1_con, cons1_con, nil2_con, cons2_con;
            Constructor[] constructors1 = new Constructor[2], constructors2 = new Constructor[2];
            Symbol[] sort_names = { ctx.MkSymbol("forest"), ctx.MkSymbol("tree") };

            /* build a forest */
            nil1_con = ctx.MkConstructor(ctx.MkSymbol("nil"), ctx.MkSymbol("is_nil"), null, null, null);
            cons1_con = ctx.MkConstructor(ctx.MkSymbol("cons1"), ctx.MkSymbol("is_cons1"), head_tail1, sorts1, sort1_refs);
            constructors1[0] = nil1_con;
            constructors1[1] = cons1_con;

            /* build a tree */
            nil2_con = ctx.MkConstructor(ctx.MkSymbol("nil2"), ctx.MkSymbol("is_nil2"), null, null, null);
            cons2_con = ctx.MkConstructor(ctx.MkSymbol("cons2"), ctx.MkSymbol("is_cons2"), head_tail2, sorts2, sort2_refs);
            constructors2[0] = nil2_con;
            constructors2[1] = cons2_con;


            Constructor[][] clists = new Constructor[][] { constructors1, constructors2 };

            Sort[] sorts = ctx.MkDatatypeSorts(sort_names, clists);
            forest = sorts[0];
            tree = sorts[1];

            //
            // Now that the datatype has been created.
            // Query the constructors for the constructor
            // functions, testers, and field accessors.
            //
            nil1_decl = nil1_con.ConstructorDecl;
            is_nil1_decl = nil1_con.TesterDecl;
            cons1_decl = cons1_con.ConstructorDecl;
            is_cons1_decl = cons1_con.TesterDecl;
            FuncDecl[] cons1_accessors = cons1_con.AccessorDecls;
            car1_decl = cons1_accessors[0];
            cdr1_decl = cons1_accessors[1];

            nil2_decl = nil2_con.ConstructorDecl;
            is_nil2_decl = nil2_con.TesterDecl;
            cons2_decl = cons2_con.ConstructorDecl;
            is_cons2_decl = cons2_con.TesterDecl;
            FuncDecl[] cons2_accessors = cons2_con.AccessorDecls;
            car2_decl = cons2_accessors[0];
            cdr2_decl = cons2_accessors[1];


            nil1 = ctx.MkConst(nil1_decl);
            nil2 = ctx.MkConst(nil2_decl);
            f1 = ctx.MkApp(cons1_decl, nil2, nil1);
            t1 = ctx.MkApp(cons2_decl, nil1, nil1);
            t2 = ctx.MkApp(cons2_decl, f1, nil1);
            t3 = ctx.MkApp(cons2_decl, f1, f1);
            t4 = ctx.MkApp(cons2_decl, nil1, f1);
            f2 = ctx.MkApp(cons1_decl, t1, nil1);
            f3 = ctx.MkApp(cons1_decl, t1, f1);


            /* nil != cons(nil,nil) */
            Prove(ctx, ctx.MkNot(ctx.MkEq(nil1, f1)));
            Prove(ctx, ctx.MkNot(ctx.MkEq(nil2, t1)));


            /* cons(x,u) = cons(x, v) => u = v */
            u = ctx.MkConst("u", forest);
            v = ctx.MkConst("v", forest);
            x = ctx.MkConst("x", tree);
            y = ctx.MkConst("y", tree);
            l1 = ctx.MkApp(cons1_decl, x, u);
            l2 = ctx.MkApp(cons1_decl, y, v);
            Prove(ctx, ctx.MkImplies(ctx.MkEq(l1, l2), ctx.MkEq(u, v)));
            Prove(ctx, ctx.MkImplies(ctx.MkEq(l1, l2), ctx.MkEq(x, y)));

            /* is_nil(u) or is_cons(u) */
            Prove(ctx, ctx.MkOr((BoolExpr)ctx.MkApp(is_nil1_decl, u),
                                (BoolExpr)ctx.MkApp(is_cons1_decl, u)));

            /* occurs check u != cons(x,u) */
            Prove(ctx, ctx.MkNot(ctx.MkEq(u, l1)));
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: perillaseed/z3
        /// <summary>
        /// Create a binary tree datatype.
        /// </summary>
        public static void TreeExample(Context ctx)
        {
            Console.WriteLine("TreeExample");

            Sort cell;
            FuncDecl nil_decl, is_nil_decl, cons_decl, is_cons_decl, car_decl, cdr_decl;
            Expr nil, l1, l2, x, y, u, v;
            BoolExpr fml, fml1;
            string[] head_tail = new string[] { "car", "cdr" };
            Sort[] sorts = new Sort[] { null, null };
            uint[] sort_refs = new uint[] { 0, 0 };
            Constructor nil_con, cons_con;

            nil_con = ctx.MkConstructor("nil", "is_nil", null, null, null);
            cons_con = ctx.MkConstructor("cons", "is_cons", head_tail, sorts, sort_refs);
            Constructor[] constructors = new Constructor[] { nil_con, cons_con };

            cell = ctx.MkDatatypeSort("cell", constructors);

            nil_decl = nil_con.ConstructorDecl;
            is_nil_decl = nil_con.TesterDecl;
            cons_decl = cons_con.ConstructorDecl;
            is_cons_decl = cons_con.TesterDecl;
            FuncDecl[] cons_accessors = cons_con.AccessorDecls;
            car_decl = cons_accessors[0];
            cdr_decl = cons_accessors[1];

            nil = ctx.MkConst(nil_decl);
            l1 = ctx.MkApp(cons_decl, nil, nil);
            l2 = ctx.MkApp(cons_decl, l1, nil);

            /* nil != cons(nil, nil) */
            Prove(ctx, ctx.MkNot(ctx.MkEq(nil, l1)));

            /* cons(x,u) = cons(x, v) => u = v */
            u = ctx.MkConst("u", cell);
            v = ctx.MkConst("v", cell);
            x = ctx.MkConst("x", cell);
            y = ctx.MkConst("y", cell);
            l1 = ctx.MkApp(cons_decl, x, u);
            l2 = ctx.MkApp(cons_decl, y, v);
            Prove(ctx, ctx.MkImplies(ctx.MkEq(l1, l2), ctx.MkEq(u, v)));
            Prove(ctx, ctx.MkImplies(ctx.MkEq(l1, l2), ctx.MkEq(x, y)));

            /* is_nil(u) or is_cons(u) */
            Prove(ctx, ctx.MkOr((BoolExpr)ctx.MkApp(is_nil_decl, u), (BoolExpr)ctx.MkApp(is_cons_decl, u)));

            /* occurs check u != cons(x,u) */
            Prove(ctx, ctx.MkNot(ctx.MkEq(u, l1)));

            /* destructors: is_cons(u) => u = cons(car(u),cdr(u)) */
            fml1 = ctx.MkEq(u, ctx.MkApp(cons_decl, ctx.MkApp(car_decl, u), ctx.MkApp(cdr_decl, u)));
            fml = ctx.MkImplies((BoolExpr)ctx.MkApp(is_cons_decl, u), fml1);
            Console.WriteLine("Formula {0}", fml);
            Prove(ctx, fml);

            Disprove(ctx, fml1);
        }
コード例 #18
0
ファイル: Program.cs プロジェクト: perillaseed/z3
        /// <summary>
        /// Create a list datatype.
        /// </summary>
        public static void ListExample(Context ctx)
        {
            Console.WriteLine("ListExample");

            Sort int_ty;
            ListSort int_list;
            Expr nil, l1, l2, x, y, u, v;
            BoolExpr fml, fml1;

            int_ty = ctx.MkIntSort();

            int_list = ctx.MkListSort(ctx.MkSymbol("int_list"), int_ty);

            nil = ctx.MkConst(int_list.NilDecl);
            l1 = ctx.MkApp(int_list.ConsDecl, ctx.MkInt(1), nil);
            l2 = ctx.MkApp(int_list.ConsDecl, ctx.MkInt(2), nil);

            /* nil != cons(1, nil) */
            Prove(ctx, ctx.MkNot(ctx.MkEq(nil, l1)));

            /* cons(2,nil) != cons(1, nil) */
            Prove(ctx, ctx.MkNot(ctx.MkEq(l1, l2)));

            /* cons(x,nil) = cons(y, nil) => x = y */
            x = ctx.MkConst("x", int_ty);
            y = ctx.MkConst("y", int_ty);
            l1 = ctx.MkApp(int_list.ConsDecl, x, nil);
            l2 = ctx.MkApp(int_list.ConsDecl, y, nil);
            Prove(ctx, ctx.MkImplies(ctx.MkEq(l1, l2), ctx.MkEq(x, y)));

            /* cons(x,u) = cons(x, v) => u = v */
            u = ctx.MkConst("u", int_list);
            v = ctx.MkConst("v", int_list);
            l1 = ctx.MkApp(int_list.ConsDecl, x, u);
            l2 = ctx.MkApp(int_list.ConsDecl, y, v);
            Prove(ctx, ctx.MkImplies(ctx.MkEq(l1, l2), ctx.MkEq(u, v)));
            Prove(ctx, ctx.MkImplies(ctx.MkEq(l1, l2), ctx.MkEq(x, y)));

            /* is_nil(u) or is_cons(u) */
            Prove(ctx, ctx.MkOr((BoolExpr)ctx.MkApp(int_list.IsNilDecl, u),
                           (BoolExpr)ctx.MkApp(int_list.IsConsDecl, u)));

            /* occurs check u != cons(x,u) */
            Prove(ctx, ctx.MkNot(ctx.MkEq(u, l1)));

            /* destructors: is_cons(u) => u = cons(head(u),tail(u)) */
            fml1 = ctx.MkEq(u, ctx.MkApp(int_list.ConsDecl, ctx.MkApp(int_list.HeadDecl, u),
                              ctx.MkApp(int_list.TailDecl, u)));
            fml = ctx.MkImplies((BoolExpr)ctx.MkApp(int_list.IsConsDecl, u), fml1);
            Console.WriteLine("Formula {0}", fml);

            Prove(ctx, fml);

            Disprove(ctx, fml1);
        }
コード例 #19
0
ファイル: Program.cs プロジェクト: perillaseed/z3
        /// <summary>
        /// Create an enumeration data type.
        /// </summary>
        public static void EnumExample(Context ctx)
        {
            Console.WriteLine("EnumExample");

            Symbol name = ctx.MkSymbol("fruit");

            EnumSort fruit = ctx.MkEnumSort(ctx.MkSymbol("fruit"), new Symbol[] { ctx.MkSymbol("apple"), ctx.MkSymbol("banana"), ctx.MkSymbol("orange") });

            Console.WriteLine("{0}", (fruit.Consts[0]));
            Console.WriteLine("{0}", (fruit.Consts[1]));
            Console.WriteLine("{0}", (fruit.Consts[2]));

            Console.WriteLine("{0}", (fruit.TesterDecls[0]));
            Console.WriteLine("{0}", (fruit.TesterDecls[1]));
            Console.WriteLine("{0}", (fruit.TesterDecls[2]));

            Expr apple = fruit.Consts[0];
            Expr banana = fruit.Consts[1];
            Expr orange = fruit.Consts[2];

            /* Apples are different from oranges */
            Prove(ctx, ctx.MkNot(ctx.MkEq(apple, orange)));

            /* Apples pass the apple test */
            Prove(ctx, (BoolExpr)ctx.MkApp(fruit.TesterDecls[0], apple));

            /* Oranges fail the apple test */
            Disprove(ctx, (BoolExpr)ctx.MkApp(fruit.TesterDecls[0], orange));
            Prove(ctx, (BoolExpr)ctx.MkNot((BoolExpr)ctx.MkApp(fruit.TesterDecls[0], orange)));

            Expr fruity = ctx.MkConst("fruity", fruit);

            /* If something is fruity, then it is an apple, banana, or orange */

            Prove(ctx, ctx.MkOr(new BoolExpr[] { ctx.MkEq(fruity, apple), ctx.MkEq(fruity, banana), ctx.MkEq(fruity, orange) }));
        }
コード例 #20
0
    /*!
       \brief Extract unsatisfiable core example
    */
    public void unsat_core_and_proof_example()
    {
        if (this.z3 != null)
        {
            this.z3.Dispose();
        }
        Dictionary<string, string> cfg = new Dictionary<string, string>() {
            { "PROOF_MODE", "2" } };
        this.z3 = new Context(cfg);
        this.solver = z3.MkSolver();

        BoolExpr pa = mk_bool_var("PredA");
        BoolExpr pb = mk_bool_var("PredB");
        BoolExpr pc = mk_bool_var("PredC");
        BoolExpr pd = mk_bool_var("PredD");
        BoolExpr p1 = mk_bool_var("P1");
        BoolExpr p2 = mk_bool_var("P2");
        BoolExpr p3 = mk_bool_var("P3");
        BoolExpr p4 = mk_bool_var("P4");
        BoolExpr[] assumptions = new BoolExpr[] { z3.MkNot(p1), z3.MkNot(p2), z3.MkNot(p3), z3.MkNot(p4) };
        BoolExpr f1 = z3.MkAnd(new BoolExpr[] { pa, pb, pc });
        BoolExpr f2 = z3.MkAnd(new BoolExpr[] { pa, z3.MkNot(pb), pc });
        BoolExpr f3 = z3.MkOr(z3.MkNot(pa), z3.MkNot(pc));
        BoolExpr f4 = pd;

        solver.Assert(z3.MkOr(f1, p1));
        solver.Assert(z3.MkOr(f2, p2));
        solver.Assert(z3.MkOr(f3, p3));
        solver.Assert(z3.MkOr(f4, p4));
        Status result = solver.Check(assumptions);

        if (result == Status.UNSATISFIABLE)
        {
            Console.WriteLine("unsat");
            Console.WriteLine("proof: {0}", solver.Proof);
            foreach (Expr c in solver.UnsatCore)
            {
                Console.WriteLine("{0}", c);
            }
        }
    }
コード例 #21
0
 public override BoolExpr toZ3Bool(Context ctx)
 {
     switch (this.logical_operator)
     {
         case LogicalOperator.True:
             return ctx.MkTrue();
         case LogicalOperator.False:
             return ctx.MkFalse();
         case LogicalOperator.And:
             return ctx.MkAnd(new BoolExpr[] { boolean_operand1.toZ3Bool(ctx), boolean_operand2.toZ3Bool(ctx) });
         case LogicalOperator.Or:
             return ctx.MkOr(new BoolExpr[] { boolean_operand1.toZ3Bool(ctx), boolean_operand2.toZ3Bool(ctx) });
         case LogicalOperator.Not:
             return ctx.MkNot(boolean_operand1.toZ3Bool(ctx));
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
コード例 #22
0
ファイル: Program.cs プロジェクト: abhishekudupa/z3-4.3.1
        /// <summary>
        /// Extract unsatisfiable core example 
        /// </summary>
        public static void UnsatCoreAndProofExample()
        {
            Console.WriteLine("UnsatCoreAndProofExample");

            Dictionary<string, string> cfg = new Dictionary<string, string>() { { "PROOF_MODE", "2" } };

            using (Context ctx = new Context(cfg))
            {
                Solver solver = ctx.MkSolver();

                BoolExpr pa = ctx.MkBoolConst("PredA");
                BoolExpr pb = ctx.MkBoolConst("PredB");
                BoolExpr pc = ctx.MkBoolConst("PredC");
                BoolExpr pd = ctx.MkBoolConst("PredD");
                BoolExpr p1 = ctx.MkBoolConst("P1");
                BoolExpr p2 = ctx.MkBoolConst("P2");
                BoolExpr p3 = ctx.MkBoolConst("P3");
                BoolExpr p4 = ctx.MkBoolConst("P4");
                BoolExpr[] assumptions = new BoolExpr[] { ctx.MkNot(p1), ctx.MkNot(p2), ctx.MkNot(p3), ctx.MkNot(p4) };
                BoolExpr f1 = ctx.MkAnd(new BoolExpr[] { pa, pb, pc });
                BoolExpr f2 = ctx.MkAnd(new BoolExpr[] { pa, ctx.MkNot(pb), pc });
                BoolExpr f3 = ctx.MkOr(ctx.MkNot(pa), ctx.MkNot(pc));
                BoolExpr f4 = pd;

                solver.Assert(ctx.MkOr(f1, p1));
                solver.Assert(ctx.MkOr(f2, p2));
                solver.Assert(ctx.MkOr(f3, p3));
                solver.Assert(ctx.MkOr(f4, p4));
                Status result = solver.Check(assumptions);

                if (result == Status.UNSATISFIABLE)
                {
                    Console.WriteLine("unsat");
                    Console.WriteLine("proof: {0}", solver.Proof);
                    Console.WriteLine("core: ");
                    foreach (Expr c in solver.UnsatCore)
                    {
                        Console.WriteLine("{0}", c);
                    }
                }
            }
        }
コード例 #23
0
ファイル: install.1.cs プロジェクト: ahorn/z3test
 public BoolExpr Conflict(Context ctx, BoolExpr p1, BoolExpr p2)
 {
     return ctx.MkOr(ctx.MkNot(p1), ctx.MkNot(p2));
 }
コード例 #24
0
ファイル: clique.cs プロジェクト: ahorn/z3test
    protected void Clique(Context ctx, Edge[] edges, uint n)
    {
        uint num = 0;
        foreach (Edge e in edges)
        {
            if (e.v0 >= num)
                num = e.v0 + 1;
            if (e.v1 >= num)
                num = e.v1 + 1;
        }

        Solver S = ctx.MkSolver();

        IntExpr [] In = new IntExpr[num];

        for (uint i = 0; i < num; i++)
        {
            In[i] = ctx.MkIntConst(String.Format("in_{0}", i));
            S.Assert(ctx.MkLe(ctx.MkInt(0), In[i]));
            S.Assert(ctx.MkLe(In[i], ctx.MkInt(1)));
        }

        ArithExpr sum = ctx.MkInt(0);
        foreach (IntExpr e in In)
            sum = ctx.MkAdd(sum, e);
        S.Assert(ctx.MkGe(sum, ctx.MkInt(n)));

        IntNum[][] matrix = new IntNum[num][];

        for (uint i = 0; i < num; i++)
        {
            matrix[i] = new IntNum[i];
            for (uint j = 0; j < i; j++)
                matrix[i][j] = ctx.MkInt(0);
        }

        foreach (Edge e in edges)
        {
            uint s = e.v0;
            uint t = e.v1;
            if (s < t) {
                s = e.v1;
                t = e.v0;
            }
            matrix[s][t] = ctx.MkInt(1);
        }

        for (uint i = 0; i < num; i++)
            for (uint j = 0; j < i; j++)
                if (i != j)
                    if (matrix[i][j].Int == 0)
                        S.Assert(ctx.MkOr(ctx.MkEq(In[i], ctx.MkInt(0)),
                                          ctx.MkEq(In[j], ctx.MkInt(0))));

        Status r = S.Check();
        if (r == Status.UNSATISFIABLE)
            Console.WriteLine("no solution");
        else if (r == Status.UNKNOWN)
        {
            Console.Write("failed");
            Console.WriteLine(S.ReasonUnknown);
        }
        else
        {
            Console.WriteLine("solution found");
            Model m = S.Model;

            Console.Write("{ ");
            foreach (FuncDecl cfd in m.ConstDecls)
            {
                IntNum q = (IntNum)m.ConstInterp(cfd);
                if (q.Int == 1)
                    Console.Write(" " + cfd.Name);
            }
            Console.WriteLine(" }");

            Console.Write("{ ");
            for (uint i = 0; i < num; i++)
            {
                IntNum q = (IntNum)m.Evaluate(In[i]);
                if (q.Int == 1)
                    Console.Write(" " + In[i]);
            }
            Console.WriteLine(" }");
        }
    }