当前位置: 首页>>代码示例>>C#>>正文


C# Context.MkSolver方法代码示例

本文整理汇总了C#中Microsoft.Z3.Context.MkSolver方法的典型用法代码示例。如果您正苦于以下问题:C# Context.MkSolver方法的具体用法?C# Context.MkSolver怎么用?C# Context.MkSolver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Z3.Context的用法示例。


在下文中一共展示了Context.MkSolver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

    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());
        }
    }
开发者ID:ExiaHan,项目名称:z3test,代码行数:32,代码来源:bit.1.cs

示例2: Run

    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);
        }
    }
开发者ID:ahorn,项目名称:z3test,代码行数:34,代码来源:bitvec.3.cs

示例3: Run

    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);
        }
    }
开发者ID:ahorn,项目名称:z3test,代码行数:26,代码来源:datatype.4.cs

示例4: Run

    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);
        }
    }
开发者ID:ahorn,项目名称:z3test,代码行数:29,代码来源:install.1.cs

示例5: EeAndGt

        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;
        }
开发者ID:izmaxx,项目名称:VBADataGenerator,代码行数:26,代码来源:Program.cs

示例6: Run

    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));
        }
    }
开发者ID:ExiaHan,项目名称:z3test,代码行数:31,代码来源:arith.5.cs

示例7: Run

    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)) );
        }
    }
开发者ID:ahorn,项目名称:z3test,代码行数:32,代码来源:tactic.7.cs

示例8: Run

    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);
        }
    }
开发者ID:ahorn,项目名称:z3test,代码行数:31,代码来源:unsatcore.cs

示例9: Run

    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);
        }
    }
开发者ID:ahorn,项目名称:z3test,代码行数:25,代码来源:uninterp.cs

示例10: Run

    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);
        }
    }
开发者ID:ahorn,项目名称:z3test,代码行数:26,代码来源:arith.2.cs

示例11: Run

    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);
        }
    }
开发者ID:ExiaHan,项目名称:z3test,代码行数:26,代码来源:dog_cat_mouse.cs

示例12: Run

    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);
        }
    }
开发者ID:ExiaHan,项目名称:z3test,代码行数:29,代码来源:z3py.12.cs

示例13: Run

    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());
        }
    }
开发者ID:ExiaHan,项目名称:z3test,代码行数:32,代码来源:z3py.10.cs

示例14: Run

    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());
        }
    }
开发者ID:ExiaHan,项目名称:z3test,代码行数:30,代码来源:quant.6.cs

示例15: Run

    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());
        }
    }
开发者ID:ahorn,项目名称:z3test,代码行数:31,代码来源:quant.7.cs


注:本文中的Microsoft.Z3.Context.MkSolver方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。