ParseSMTLIBString() public méthode

Parse the given string using the SMT-LIB parser.
The symbol table of the parser can be initialized using the given sorts and declarations. The symbols in the arrays sortNames and declNames don't need to match the names of the sorts and declarations in the arrays sorts and decls. This is a useful feature since we can use arbitrary names to reference sorts and declarations.
public ParseSMTLIBString ( string str, Symbol sortNames = null, Microsoft.Z3.Sort sorts = null, Symbol declNames = null, FuncDecl decls = null ) : void
str string
sortNames Symbol
sorts Microsoft.Z3.Sort
declNames Symbol
decls FuncDecl
Résultat void
Exemple #1
0
        /// <summary>
        /// Assert the axiom: function f is commutative.
        /// </summary>
        /// <remarks>
        /// This example uses the SMT-LIB parser to simplify the axiom construction.
        /// </remarks>
        private static BoolExpr CommAxiom(Context ctx, FuncDecl f)
        {
            Sort t = f.Range;
            Sort[] dom = f.Domain;

            if (dom.Length != 2 ||
                !t.Equals(dom[0]) ||
                !t.Equals(dom[1]))
            {
                Console.WriteLine("{0} {1} {2} {3}", dom.Length, dom[0], dom[1], t);
                throw new Exception("function must be binary, and argument types must be equal to return type");
            }

            string bench = string.Format("(benchmark comm :formula (forall (x {0}) (y {1}) (= ({2} x y) ({3} y x))))",
                             t.Name, t.Name, f.Name, f.Name);
            ctx.ParseSMTLIBString(bench, new Symbol[] { t.Name }, new Sort[] { t }, new Symbol[] { f.Name }, new FuncDecl[] { f });
            return ctx.SMTLIBFormulas[0];
        }
Exemple #2
0
        /// <summary>
        /// Demonstrates how to handle parser errors using Z3 error handling support.
        /// </summary>
        /// <remarks></remarks>
        public static void ParserExample5(Context ctx)
        {
            Console.WriteLine("ParserExample5");

            try
            {
                ctx.ParseSMTLIBString(
                    /* the following string has a parsing error: missing parenthesis */
                         "(benchmark tst :extrafuns ((x Int (y Int)) :formula (> x y) :formula (> x 0))");
            }
            catch (Z3Exception e)
            {
                Console.WriteLine("Z3 error: {0}", e);
            }
        }
Exemple #3
0
        /// <summary>
        /// Display the declarations, assumptions and formulas in a SMT-LIB string.
        /// </summary>
        public static void ParserExample4(Context ctx)
        {
            Console.WriteLine("ParserExample4");

            ctx.ParseSMTLIBString
            ("(benchmark tst :extrafuns ((x Int) (y Int)) :assumption (= x 20) :formula (> x y) :formula (> x 0))");
            foreach (var decl in ctx.SMTLIBDecls)
            {
                Console.WriteLine("Declaration: {0}", decl);
            }
            foreach (var f in ctx.SMTLIBAssumptions)
            {
                Console.WriteLine("Assumption: {0}", f);
            }
            foreach (var f in ctx.SMTLIBFormulas)
            {
                Console.WriteLine("Formula: {0}", f);
            }
        }
Exemple #4
0
        /// <summary>
        /// Demonstrates how to initialize the parser symbol table.
        /// </summary>
        public static void ParserExample3(Context ctx)
        {
            Console.WriteLine("ParserExample3");

            /* declare function g */
            Sort I = ctx.MkIntSort();
            FuncDecl g = ctx.MkFuncDecl("g", new Sort[] { I, I }, I);

            BoolExpr ca = CommAxiom(ctx, g);

            ctx.ParseSMTLIBString("(benchmark tst :formula (forall (x Int) (y Int) (implies (= x y) (= (gg x 0) (gg 0 y)))))",
             null, null,
             new Symbol[] { ctx.MkSymbol("gg") },
             new FuncDecl[] { g });

            BoolExpr thm = ctx.SMTLIBFormulas[0];
            Console.WriteLine("formula: {0}", thm);
            Prove(ctx, thm, false, ca);
        }
Exemple #5
0
        /// <summary>
        /// Demonstrates how to initialize the parser symbol table.
        /// </summary>
        public static void ParserExample2(Context ctx)
        {
            Console.WriteLine("ParserExample2");

            Symbol[] declNames = { ctx.MkSymbol("a"), ctx.MkSymbol("b") };
            FuncDecl a = ctx.MkConstDecl(declNames[0], ctx.MkIntSort());
            FuncDecl b = ctx.MkConstDecl(declNames[1], ctx.MkIntSort());
            FuncDecl[] decls = new FuncDecl[] { a, b };

            ctx.ParseSMTLIBString("(benchmark tst :formula (> a b))",
                                 null, null, declNames, decls);
            BoolExpr f = ctx.SMTLIBFormulas[0];
            Console.WriteLine("formula: {0}", f);
            Check(ctx, f, Status.SATISFIABLE);
        }
Exemple #6
0
        /// <summary>
        /// Demonstrates how to use the SMTLIB parser.
        /// </summary>
        public static void ParserExample1(Context ctx)
        {
            Console.WriteLine("ParserExample1");

            ctx.ParseSMTLIBString("(benchmark tst :extrafuns ((x Int) (y Int)) :formula (> x y) :formula (> x 0))");
            foreach (BoolExpr f in ctx.SMTLIBFormulas)
                Console.WriteLine("formula {0}", f);

            Model m = Check(ctx, ctx.MkAnd(ctx.SMTLIBFormulas), Status.SATISFIABLE);
        }