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


C# Context.MkBound方法代码示例

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


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

示例1: Run

    public void Run()
    {
        using (Context ctx = new Context()) {
            ctx.UpdateParamValue("DL_ENGINE","1");
            ctx.UpdateParamValue("DL_PDR_USE_FARKAS","true");
        //          ctx.UpdateParamValue("VERBOSE","2");
            var s = ctx.MkFixedpoint();
            BoolSort B = ctx.BoolSort;
            IntSort I = ctx.IntSort;
            FuncDecl mc = ctx.MkFuncDecl("mc", new Sort[]{I, I}, B);
            ArithExpr x = (ArithExpr)ctx.MkBound(0,I);
            ArithExpr y = (ArithExpr)ctx.MkBound(1,I);
            ArithExpr z = (ArithExpr)ctx.MkBound(2,I);
            s.RegisterRelation(mc);
            BoolExpr gt = ctx.MkGt(x, ctx.MkInt(100));
            s.AddRule(ctx.MkImplies(gt,(BoolExpr)mc[x,ctx.MkSub(x,ctx.MkInt(10))]));
            s.AddRule(ctx.MkImplies(ctx.MkAnd(ctx.MkNot(gt),
                                      (BoolExpr) mc[ctx.MkAdd(x,ctx.MkInt(11)),y],
                                      (BoolExpr) mc[y,z]),
                                      (BoolExpr) mc[x,z]));
            Console.WriteLine(s.Query(ctx.MkAnd((BoolExpr)mc[x,y], ctx.MkGt(y,ctx.MkInt(100)))));
            Console.WriteLine(s.GetAnswer());

            Console.WriteLine(s.Query(ctx.MkAnd((BoolExpr)mc[x,y], ctx.MkLt(y,ctx.MkInt(91)))));
            Console.WriteLine(s.GetAnswer());
        }
    }
开发者ID:ExiaHan,项目名称:z3test,代码行数:27,代码来源:fixedpoint4.cs

示例2: Run

 public void Run()
 {
     using (Context ctx = new Context()) {
         var s = ctx.MkFixedpoint();
         BoolSort B = ctx.BoolSort;
         Sort BV8   = ctx.MkBitVecSort(8);
         FuncDecl edge = ctx.MkFuncDecl("edge", new Sort[]{BV8, BV8}, B);
         FuncDecl path = ctx.MkFuncDecl("path", new Sort[]{BV8, BV8}, B);
         BitVecExpr x = (BitVecExpr)ctx.MkBound(0,BV8);
         BitVecExpr y = (BitVecExpr)ctx.MkBound(1,BV8);
         BitVecExpr z = (BitVecExpr)ctx.MkBound(2,BV8);
         s.RegisterRelation(edge);
         s.RegisterRelation(path);
         s.AddRule(ctx.MkImplies((BoolExpr)edge[x,y],(BoolExpr)path[x,y]));
         s.AddRule(ctx.MkImplies(ctx.MkAnd((BoolExpr)path[x,y],(BoolExpr)path[y,z]),
                                 (BoolExpr)path[x,z]));
         for (uint i = 0; i < 128; ++i) {
            s.AddFact(edge, i, i+1);
         }
         Console.WriteLine(s.Query((BoolExpr)path[ctx.MkBV(0,8),ctx.MkBV(129,8)]));
         Console.WriteLine(s.GetAnswer());
         Console.WriteLine(s.Query((BoolExpr)path[ctx.MkBV(0,8),ctx.MkBV(128,8)]));
         Console.WriteLine(s.GetAnswer());
         Console.WriteLine(s.Query((BoolExpr)path[x,ctx.MkBV(20,8)]));
         Console.WriteLine(s.GetAnswer());
         Console.WriteLine(s.Query(ctx.MkAnd((BoolExpr)path[x,y],
                                             (BoolExpr)path[y,ctx.MkBV(20,8)])));
         Console.WriteLine(s.GetAnswer());
     }
 }
开发者ID:ahorn,项目名称:z3test,代码行数:30,代码来源:fixedpoint.7.cs

示例3: InjAxiom

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

示例4: Run

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

        using (Context ctx = new Context(cfg))
        {
            FuncDecl f = ctx.MkFuncDecl("f", new Sort[] { ctx.IntSort, ctx.IntSort }, ctx.IntSort);
            IntExpr x = ctx.MkIntConst("x");
            IntExpr y = ctx.MkIntConst("y");

            Quantifier qf = ctx.MkForall(new Expr[] { x, y }, ctx.MkEq(f[x, y], ctx.MkInt(0)));
            Console.WriteLine(qf.Body);

            Expr v1 = qf.Body.Args[0].Args[0];
            Console.WriteLine(v1);
            Console.WriteLine(v1 == ctx.MkBound(1, ctx.IntSort));
        }
    }
开发者ID:ExiaHan,项目名称:z3test,代码行数:19,代码来源:quant.2.cs

示例5: Run

 public void Run()
 {
     using (Context ctx = new Context()) {
         var s = ctx.MkFixedpoint();
         BoolSort B = ctx.BoolSort;
         Sort BV8     = ctx.MkBitVecSort(8);
         FuncDecl f = ctx.MkFuncDecl("f", BV8, B);
         FuncDecl g = ctx.MkFuncDecl("g", BV8, B);
         BitVecExpr b0 = (BitVecExpr)ctx.MkBound(0,BV8);
         s.RegisterRelation(f);
         s.RegisterRelation(g);
         s.AddRule((BoolExpr)f[b0]);
         BitVecExpr mask0 = ctx.MkBV(0xFE,8);
         BoolExpr even = ctx.MkEq(b0,ctx.MkBVAND(b0,mask0));
         s.AddRule(ctx.MkImplies(ctx.MkAnd((BoolExpr)f[b0],even), (BoolExpr)g[b0]));
         Console.WriteLine(s.Query((BoolExpr)g[b0]));
         Console.WriteLine(s.GetAnswer());
     }
 }
开发者ID:ExiaHan,项目名称:z3test,代码行数:19,代码来源:fixedpoint2.cs

示例6: QuantifierExample2

        static void QuantifierExample2(Context ctx)
        {

            Console.WriteLine("QuantifierExample2");

            Expr q1, q2;
            FuncDecl f = ctx.MkFuncDecl("f", ctx.IntSort, ctx.IntSort);
            FuncDecl g = ctx.MkFuncDecl("g", ctx.IntSort, ctx.IntSort);

            // Quantifier with Exprs as the bound variables.
            {
                Expr x = ctx.MkConst("x", ctx.IntSort);
                Expr y = ctx.MkConst("y", ctx.IntSort);
                Expr f_x = ctx.MkApp(f, x);
                Expr f_y = ctx.MkApp(f, y);
                Expr g_y = ctx.MkApp(g, y);
                Pattern[] pats = new Pattern[] { ctx.MkPattern(new Expr[] { f_x, g_y }) };
                Expr[] no_pats = new Expr[] { f_y };
                Expr[] bound = new Expr[2] { x, y };
                Expr body = ctx.MkAnd(ctx.MkEq(f_x, f_y), ctx.MkEq(f_y, g_y));

                q1 = ctx.MkForall(bound, body, 1, null, no_pats, ctx.MkSymbol("q"), ctx.MkSymbol("sk"));

                Console.WriteLine("{0}", q1);
            }

            // Quantifier with de-Brujin indices.
            {
                Expr x = ctx.MkBound(1, ctx.IntSort);
                Expr y = ctx.MkBound(0, ctx.IntSort);
                Expr f_x = ctx.MkApp(f, x);
                Expr f_y = ctx.MkApp(f, y);
                Expr g_y = ctx.MkApp(g, y);
                Pattern[] pats = new Pattern[] { ctx.MkPattern(new Expr[] { f_x, g_y }) };
                Expr[] no_pats = new Expr[] { f_y };
                Symbol[] names = new Symbol[] { ctx.MkSymbol("x"), ctx.MkSymbol("y") };
                Sort[] sorts = new Sort[] { ctx.IntSort, ctx.IntSort };
                Expr body = ctx.MkAnd(ctx.MkEq(f_x, f_y), ctx.MkEq(f_y, g_y));

                q2 = ctx.MkForall(sorts, names, body, 1,
                                         null, // pats,
                                         no_pats,
                                         ctx.MkSymbol("q"),
                                         ctx.MkSymbol("sk")
                                        );
                Console.WriteLine("{0}", q2);
            }

            Console.WriteLine("{0}", (q1.Equals(q2)));
        }
开发者ID:perillaseed,项目名称:z3,代码行数:50,代码来源:Program.cs

示例7: QuantifierExample1

        /// <summary>
        /// A basic example of how to use quantifiers.
        /// </summary>
        static void QuantifierExample1(Context ctx)
        {
            Console.WriteLine("QuantifierExample");

            Sort[] types = new Sort[3];
            IntExpr[] xs = new IntExpr[3];
            Symbol[] names = new Symbol[3];
            IntExpr[] vars = new IntExpr[3];

            for (uint j = 0; j < 3; j++)
            {
                types[j] = ctx.IntSort;
                names[j] = ctx.MkSymbol(String.Format("x_{0}", j));
                xs[j] = (IntExpr)ctx.MkConst(names[j], types[j]);
                vars[j] = (IntExpr)ctx.MkBound(2 - j, types[j]); // <-- vars reversed!
            }

            Expr body_vars = ctx.MkAnd(ctx.MkEq(ctx.MkAdd(vars[0], ctx.MkInt(1)), ctx.MkInt(2)),
                                        ctx.MkEq(ctx.MkAdd(vars[1], ctx.MkInt(2)),
                                                       ctx.MkAdd(vars[2], ctx.MkInt(3))));

            Expr body_const = ctx.MkAnd(ctx.MkEq(ctx.MkAdd(xs[0], ctx.MkInt(1)), ctx.MkInt(2)),
                                        ctx.MkEq(ctx.MkAdd(xs[1], ctx.MkInt(2)),
                                                       ctx.MkAdd(xs[2], ctx.MkInt(3))));

            Expr x = ctx.MkForall(types, names, body_vars, 1, null, null, ctx.MkSymbol("Q1"), ctx.MkSymbol("skid1"));
            Console.WriteLine("Quantifier X: " + x.ToString());

            Expr y = ctx.MkForall(xs, body_const, 1, null, null, ctx.MkSymbol("Q2"), ctx.MkSymbol("skid2"));
            Console.WriteLine("Quantifier Y: " + y.ToString());
        }
开发者ID:perillaseed,项目名称:z3,代码行数:34,代码来源:Program.cs


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