MkBound() public méthode

Creates a new bound variable.
public MkBound ( uint index, Microsoft.Z3.Sort ty ) : Expr
index uint The de-Bruijn index of the variable
ty Microsoft.Z3.Sort The sort of the variable
Résultat Expr
Exemple #1
0
    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());
        }
    }
Exemple #2
0
 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());
     }
 }
Exemple #3
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 #4
0
    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));
        }
    }
Exemple #5
0
 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());
     }
 }
Exemple #6
0
        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)));
        }
Exemple #7
0
        /// <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());
        }