MkSelect() public method

Array read.
The argument a is the array and i is the index of the array that gets read. The node a must have an array sort [domain -> range], and i must have the sort domain. The sort of the result is range. MkArraySort MkStore
public MkSelect ( ArrayExpr a, Expr i ) : Expr
a ArrayExpr
i Expr
return Expr
Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
    public void Run()
    {
        using (Context ctx = new Context())
        {
            RealExpr x = ctx.MkRealConst("x");
            RealExpr y = ctx.MkRealConst("y");
            RealExpr z = ctx.MkRealConst("z");

            FuncDecl f = ctx.MkFuncDecl("f", ctx.RealSort, ctx.RealSort);
            Solver s = ctx.MkSolver();

            s.Assert(ctx.MkGt(x, ctx.MkReal(10)),
                     ctx.MkEq(y, ctx.MkAdd(x, ctx.MkReal(3))),
                     ctx.MkLt(y, ctx.MkReal(15)),
                     ctx.MkGt((RealExpr)f[x], ctx.MkReal(2)),
                     ctx.MkNot(ctx.MkEq(f[y], f[x])));

            Console.WriteLine(s.Check());

            Model m = s.Model;

            foreach (FuncDecl fd in m.Decls)
                Console.Write(" " + fd.Name);
            Console.WriteLine();

            foreach (FuncDecl fd in m.Decls)
            {
                if (fd.DomainSize == 0)
                    Console.WriteLine(fd.Name + " -> " + m.ConstInterp(fd));
                else
                    Console.WriteLine(fd.Name + " -> " + m.FuncInterp(fd));
            }

            Console.WriteLine(m.Evaluate(ctx.MkAdd(z, ctx.MkReal(1))));
            Console.WriteLine(m.Evaluate(ctx.MkAdd(z, ctx.MkReal(1)), true));
            Console.WriteLine(m.Evaluate(z));

            FuncInterp fi = m.FuncInterp(f);

            Console.WriteLine(fi.Else);
            Console.WriteLine(fi.NumEntries);
            Console.WriteLine(fi.Entries[0]);
            Console.WriteLine(fi.Entries[0].NumArgs);
            Console.WriteLine(fi.Entries[0].Args[0]);
            Console.WriteLine(fi.Entries[0].Value);

            ArrayExpr a = ctx.MkArrayConst("a", ctx.RealSort, ctx.RealSort);
            s.Assert(ctx.MkGt((RealExpr)ctx.MkSelect(a, x), ctx.MkReal(10)),
                     ctx.MkGt((RealExpr)ctx.MkSelect(a, y), ctx.MkReal(20)));

            Console.WriteLine(s);
            Console.WriteLine(s.Check());
            Console.WriteLine(s.Model);
            Console.WriteLine(s.Model.Evaluate(a));
            Console.WriteLine(s.Model.FuncInterp(a.FuncDecl));
        }
    }
Exemplo n.º 3
0
    public void Run()
    {
        Dictionary<string, string> cfg = new Dictionary<string, string>() {
            { "AUTO_CONFIG", "true" },
            { "MODEL", "true" } };

        using (Context ctx = new Context(cfg))
        {
            ArrayExpr X = ctx.MkArrayConst("A", ctx.IntSort, ctx.IntSort);

            Expr q = ctx.MkGe(
                        ctx.MkAdd((IntExpr)ctx.MkSelect(X, ctx.MkInt(0)),
                                  (IntExpr)ctx.MkSelect(X, ctx.MkInt(1)),
                                  (IntExpr)ctx.MkSelect(X, ctx.MkInt(2))),
                        ctx.MkInt(0));

            Console.WriteLine(q);
            Console.WriteLine(q.Simplify());
        }
    }
Exemplo n.º 4
0
 public void Run()
 {
     using (Context ctx = new Context())
     {
         ArrayExpr a = ctx.MkArrayConst("a", ctx.IntSort, ctx.IntSort);
         FuncDecl f = ctx.MkFuncDecl("f", ctx.IntSort, ctx.IntSort);
         ArrayExpr m = ctx.MkMap(f, a);
         Console.WriteLine(m);
         Console.WriteLine(m.IsArrayMap);
         Console.WriteLine(a.IsArrayMap);
         Console.WriteLine(m.IsSelect);
         Console.WriteLine(ctx.MkSelect(m, ctx.MkInt(0)).IsSelect);
         Console.WriteLine(ctx.MkStore(m, ctx.MkInt(0), ctx.MkInt(1)).IsStore);
         Console.WriteLine(ctx.MkStore(m, ctx.MkInt(0), ctx.MkInt(1)));
         Console.WriteLine(m.IsStore);
         Console.WriteLine(m.FuncDecl);
         Console.WriteLine(m.FuncDecl.Parameters[0].FuncDecl);
         Console.WriteLine(m.FuncDecl.Parameters[0].FuncDecl[ctx.MkInt(0)]);
         Console.WriteLine(ctx.MkSelect(m, ctx.MkInt(10)));
     }
 }
Exemplo n.º 5
0
    public void Run()
    {
        Dictionary<string, string> cfg = new Dictionary<string, string>() {
            { "AUTO_CONFIG", "true" },
            { "MODEL", "true" } };

        using (Context ctx = new Context(cfg))
        {
            Sort I = ctx.IntSort;
            ArrayExpr A = ctx.MkArrayConst("A", I, I);
            IntExpr x = ctx.MkIntConst("x");

            Console.WriteLine(ctx.MkSelect(A, x));
            Console.WriteLine(ctx.MkStore(A, x, ctx.MkInt(10)));

            Expr q = ctx.MkSelect(ctx.MkStore(A, ctx.MkInt(2), ctx.MkAdd(x, ctx.MkInt(1))), ctx.MkInt(2));

            Console.WriteLine(q);
            Console.WriteLine(q.Simplify());
        }
    }
Exemplo n.º 6
0
    public void Run()
    {
        Dictionary<string, string> cfg = new Dictionary<string, string>() {
            { "AUTO_CONFIG", "true" },
            { "PROOF_MODE", "2" } };

        using (Context ctx = new Context(cfg))
        {
            ArrayExpr AllOne = ctx.MkConstArray(ctx.IntSort, ctx.MkInt(1));

            IntExpr a = ctx.MkIntConst("a");
            IntExpr i = ctx.MkIntConst("i");

            Solver s = ctx.MkSolver();
            s.Assert(ctx.MkEq(a, ctx.MkSelect(AllOne, i)));
            Console.WriteLine(s.Check());

            s = ctx.MkSolver();
            s.Assert(ctx.MkEq(a, ctx.MkSelect(AllOne, i)));
            s.Assert(ctx.MkNot(ctx.MkEq(a, ctx.MkInt(1))));
            Console.WriteLine(s.Check());
        }
    }
Exemplo n.º 7
0
    public void Run()
    {
        Dictionary<string, string> cfg = new Dictionary<string, string>() {
            { "AUTO_CONFIG", "true" },
            { "MODEL", "true" } };

        using (Context ctx = new Context(cfg))
        {
            ArrayExpr A = ctx.MkArrayConst("A", ctx.IntSort, ctx.IntSort);

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

            Solver s = ctx.MkSolver();
            s.Assert(ctx.MkEq(ctx.MkSelect(A, x), x));
            s.Assert(ctx.MkEq(ctx.MkStore(A, x, y), A));
            Console.WriteLine(s);
            Console.WriteLine(s.Check());
            Console.WriteLine(s.Model);
        }
    }
Exemplo n.º 8
0
        /// <summary>
        /// A simple array example.
        /// </summary>
        /// <param name="ctx"></param>
        static void ArrayExample1(Context ctx)
        {
            Console.WriteLine("ArrayExample1");

            Goal g = ctx.MkGoal(true);
            ArraySort asort = ctx.MkArraySort(ctx.IntSort, ctx.MkBitVecSort(32));
            ArrayExpr aex = (ArrayExpr)ctx.MkConst(ctx.MkSymbol("MyArray"), asort);
            Expr sel = ctx.MkSelect(aex, ctx.MkInt(0));
            g.Assert(ctx.MkEq(sel, ctx.MkBV(42, 32)));
            Symbol xs = ctx.MkSymbol("x");
            IntExpr xc = (IntExpr)ctx.MkConst(xs, ctx.IntSort);

            Symbol fname = ctx.MkSymbol("f");
            Sort[] domain = { ctx.IntSort };
            FuncDecl fd = ctx.MkFuncDecl(fname, domain, ctx.IntSort);
            Expr[] fargs = { ctx.MkConst(xs, ctx.IntSort) };
            IntExpr fapp = (IntExpr)ctx.MkApp(fd, fargs);

            g.Assert(ctx.MkEq(ctx.MkAdd(xc, fapp), ctx.MkInt(123)));

            Solver s = ctx.MkSolver();
            foreach (BoolExpr a in g.Formulas)
                s.Assert(a);
            Console.WriteLine("Solver: " + s);

            Status q = s.Check();
            Console.WriteLine("Status: " + q);

            if (q != Status.SATISFIABLE)
                throw new TestFailedException();

            Console.WriteLine("Model = " + s.Model);

            Console.WriteLine("Interpretation of MyArray:\n" + s.Model.FuncInterp(aex.FuncDecl));
            Console.WriteLine("Interpretation of x:\n" + s.Model.ConstInterp(xc));
            Console.WriteLine("Interpretation of f:\n" + s.Model.FuncInterp(fd));
            Console.WriteLine("Interpretation of MyArray as Term:\n" + s.Model.FuncInterp(aex.FuncDecl));
        }