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


C# Context.MkConst方法代码示例

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


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

示例1: Run

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

示例2: 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

示例3: 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

示例4: 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

示例5: Run

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

示例6: MkRandomExpr

 /// <summary>
 /// Generates a slightly randomized expression.
 /// </summary>
 static BoolExpr MkRandomExpr(Context ctx, System.Random rng)
 {
     int limit = 1073741823;
         Sort i = ctx.IntSort;
         Sort b = ctx.BoolSort;
         Symbol sr1 = ctx.MkSymbol(rng.Next(0, limit));
         Symbol sr2 = ctx.MkSymbol(rng.Next(0, limit));
         Symbol sr3 = ctx.MkSymbol(rng.Next(0, limit));
         FuncDecl r1 = ctx.MkFuncDecl(sr1, i, b);
         FuncDecl r2 = ctx.MkFuncDecl(sr2, i, b);
         FuncDecl r3 = ctx.MkFuncDecl(sr3, i, b);
         Symbol s = ctx.MkSymbol(rng.Next(0, limit));
         Expr x = ctx.MkConst(s, i);
         BoolExpr r1x = (BoolExpr)ctx.MkApp(r1, x);
         BoolExpr r2x = (BoolExpr)ctx.MkApp(r2, x);
         BoolExpr r3x = (BoolExpr)ctx.MkApp(r3, x);
         Expr[] vars = { x };
         BoolExpr rl1 = ctx.MkForall(vars, ctx.MkImplies(r1x, r2x));
         BoolExpr rl2 = ctx.MkForall(vars, ctx.MkImplies(r2x, r1x));
         BoolExpr rl3 = (BoolExpr)ctx.MkApp(r1, ctx.MkInt(3));
         BoolExpr q = (BoolExpr)ctx.MkApp(r3, ctx.MkInt(2));
         BoolExpr a1 = ctx.MkNot(q);
         BoolExpr q1 = ctx.MkExists(vars, ctx.MkAnd(r3x, r2x));
         BoolExpr q2 = ctx.MkExists(vars, ctx.MkAnd(r3x, r1x));
         BoolExpr[] all = { a1, q1, q2 };
         return ctx.MkAnd(all);
 }
开发者ID:ExiaHan,项目名称:z3test,代码行数:30,代码来源:memory.cs

示例7: 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

示例8: Run

    public void Run()
    {
        Dictionary<string, string> cfg = new Dictionary<string, string>() {
            { "AUTO_CONFIG", "true" } };

        using (Context ctx = new Context(cfg))
        {
            Expr x = ctx.MkConst("x", ctx.IntSort);

            Console.WriteLine(x == ctx.MkIntConst("x"));

            BoolExpr a = (BoolExpr)ctx.MkConst("a", ctx.BoolSort);
            BoolExpr b = (BoolExpr)ctx.MkConst("b", ctx.BoolSort);
            Console.WriteLine(ctx.MkAnd(a, b));
        }
    }
开发者ID:ahorn,项目名称:z3test,代码行数:16,代码来源:expr.8.cs

示例9: Run

    public void Run()
    {
        Dictionary<string, string> cfg = new Dictionary<string, string>() {
            { "AUTO_CONFIG", "true" },
            { "MODEL", "true" } };

        using (Context ctx = new Context(cfg))
        {
            Constructor c_leaf = ctx.MkConstructor("leaf", "is_leaf", new string[] { "val" }, new Sort[] { ctx.IntSort });
            Constructor c_node = ctx.MkConstructor("node", "is_node", new string[] { "left", "right" }, new Sort[] { null, null }, new uint[] { 1, 1 });
            Constructor[] constr_1 = new Constructor[] { c_leaf, c_node };

            Constructor c_nil = ctx.MkConstructor("nil", "is_nil");
            Constructor c_cons = ctx.MkConstructor("cons", "is_cons", new string[] { "car", "cdr" }, new Sort[] { null, null }, new uint[] { 0, 1 });
            Constructor[] constr_2 = new Constructor[] { c_nil, c_cons };

            DatatypeSort[] ts = ctx.MkDatatypeSorts(new string[] { "Tree", "TreeList" },
                                                    new Constructor[][] { constr_1, constr_2 });

            DatatypeSort Tree = ts[0];
            DatatypeSort TreeList = ts[1];

            FuncDecl leaf = Tree.Constructors[0];
            FuncDecl node = Tree.Constructors[1];
            FuncDecl val = Tree.Accessors[0][0];

            FuncDecl nil = TreeList.Constructors[0];
            FuncDecl cons = TreeList.Constructors[1];

            Expr t1 = leaf[ctx.MkInt(10)];
            Expr tl1 = cons[t1, nil.Apply()];
            Expr t2 = node[tl1, nil.Apply()];

            Console.WriteLine(t2);
            Console.WriteLine(val.Apply(t1).Simplify());

            t1 = ctx.MkConst("t1", TreeList);
            t2 = ctx.MkConst("t2", TreeList);
            Expr t3 = ctx.MkConst("t3", TreeList);

            Solver s = ctx.MkSolver();
            s.Assert(ctx.MkDistinct(t1, t2, t3));
            Console.WriteLine(s.Check());
            Console.WriteLine(s.Model);
        }
    }
开发者ID:ahorn,项目名称:z3test,代码行数:46,代码来源:datatype.5.cs

示例10: ArrayExample2

        /// <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);
        }
开发者ID:sslab-gatech,项目名称:juxta,代码行数:37,代码来源:Program.cs

示例11: CheckLessThan

        public static void CheckLessThan(int a, String b)
        {
            // Console.WriteLine("This test worked" + a + " " + b);

            using (Context ctx = new Context())
            {
                // 3 < x
                Expr x = ctx.MkConst(b, ctx.MkIntSort());
                Expr value = ctx.MkNumeral(a, ctx.MkIntSort());
                BoolExpr test = ctx.MkLt((ArithExpr)value,(ArithExpr) x);
                Model model = Check(ctx, test, Status.SATISFIABLE);
            }
        }
开发者ID:izmaxx,项目名称:ExcelVBA,代码行数:13,代码来源:Program.cs

示例12: Main

        static void Main(string[] args)
        {
            using (Context ctx = new Context())
            {
                Expr x = ctx.MkConst("x", ctx.MkIntSort());
                Expr zero = ctx.MkNumeral(0, ctx.MkIntSort());

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

                Status result = s.Check();
                Console.WriteLine(result);
            }
        }
开发者ID:izmaxx,项目名称:ExcelVBA,代码行数:14,代码来源:Z3.cs

示例13: Run

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

示例14: Run

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

示例15: Z3Context

        //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));
            //-----------------------------------------------------------------------------------------------------------------------------
        }
开发者ID:dswingle,项目名称:openconfigurator,代码行数:20,代码来源:Z3Engine.cs


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