Ejemplo n.º 1
0
        internal Quantifier(Context ctx, bool isForall, Expr[] bound, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null)
            : base(ctx, IntPtr.Zero)
        {
            Debug.Assert(ctx != null);
            Debug.Assert(body != null);

            Debug.Assert(patterns == null || patterns.All(p => p != null));
            Debug.Assert(noPatterns == null || noPatterns.All(np => np != null));
            Debug.Assert(bound == null || bound.All(n => n != null));

            Context.CheckContextMatch <Expr>(noPatterns);
            Context.CheckContextMatch <Pattern>(patterns);
            //Context.CheckContextMatch(bound);
            Context.CheckContextMatch(body);

            if (noPatterns == null && quantifierID == null && skolemID == null)
            {
                NativeObject = Native.Z3_mk_quantifier_const(ctx.nCtx, (byte)(isForall ? 1 : 0), weight,
                                                             AST.ArrayLength(bound), AST.ArrayToNative(bound),
                                                             AST.ArrayLength(patterns), AST.ArrayToNative(patterns),
                                                             body.NativeObject);
            }
            else
            {
                NativeObject = Native.Z3_mk_quantifier_const_ex(ctx.nCtx, (byte)(isForall ? 1 : 0), weight,
                                                                AST.GetNativeObject(quantifierID), AST.GetNativeObject(skolemID),
                                                                AST.ArrayLength(bound), AST.ArrayToNative(bound),
                                                                AST.ArrayLength(patterns), AST.ArrayToNative(patterns),
                                                                AST.ArrayLength(noPatterns), AST.ArrayToNative(noPatterns),
                                                                body.NativeObject);
            }
        }
Ejemplo n.º 2
0
        [ContractVerification(false)] // F: Clousot ForAll decompilation gets confused below. Setting verification off until I fixed the bug
        internal Quantifier(Context ctx, bool isForall, Expr[] bound, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null)
            : base(ctx, IntPtr.Zero)
        {
            Contract.Requires(ctx != null);
            Contract.Requires(body != null);

            Contract.Requires(patterns == null || Contract.ForAll(patterns, p => p != null));
            Contract.Requires(noPatterns == null || Contract.ForAll(noPatterns, np => np != null));
            Contract.Requires(bound == null || Contract.ForAll(bound, n => n != null));

            Context.CheckContextMatch <Expr>(noPatterns);
            Context.CheckContextMatch <Pattern>(patterns);
            //Context.CheckContextMatch(bound);
            Context.CheckContextMatch(body);

            if (noPatterns == null && quantifierID == null && skolemID == null)
            {
                NativeObject = Native.Z3_mk_quantifier_const(ctx.nCtx, (isForall) ? 1 : 0, weight,
                                                             AST.ArrayLength(bound), AST.ArrayToNative(bound),
                                                             AST.ArrayLength(patterns), AST.ArrayToNative(patterns),
                                                             body.NativeObject);
            }
            else
            {
                NativeObject = Native.Z3_mk_quantifier_const_ex(ctx.nCtx, (isForall) ? 1 : 0, weight,
                                                                AST.GetNativeObject(quantifierID), AST.GetNativeObject(skolemID),
                                                                AST.ArrayLength(bound), AST.ArrayToNative(bound),
                                                                AST.ArrayLength(patterns), AST.ArrayToNative(patterns),
                                                                AST.ArrayLength(noPatterns), AST.ArrayToNative(noPatterns),
                                                                body.NativeObject);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Instrument the Datalog engine on which table representation to use for recursive predicate.
        /// </summary>
        public void SetPredicateRepresentation(FuncDecl f, Symbol[] kinds)
        {
            Contract.Requires(f != null);

            Native.Z3_fixedpoint_set_predicate_representation(Context.nCtx, NativeObject,
                                                              f.NativeObject, AST.ArrayLength(kinds), Symbol.ArrayToNative(kinds));
        }
Ejemplo n.º 4
0
        internal Constructor(Context ctx, Symbol name, Symbol recognizer, Symbol[] fieldNames,
                             Sort[] sorts, uint[] sortRefs)
            : base(ctx)
        {
            Contract.Requires(ctx != null);
            Contract.Requires(name != null);
            Contract.Requires(recognizer != null);

            n = AST.ArrayLength(fieldNames);

            if (n != AST.ArrayLength(sorts))
            {
                throw new Z3Exception("Number of field names does not match number of sorts");
            }
            if (sortRefs != null && sortRefs.Length != n)
            {
                throw new Z3Exception("Number of field names does not match number of sort refs");
            }

            if (sortRefs == null)
            {
                sortRefs = new uint[n];
            }

            NativeObject = Native.Z3_mk_constructor(ctx.nCtx, name.NativeObject, recognizer.NativeObject,
                                                    n,
                                                    Symbol.ArrayToNative(fieldNames),
                                                    Sort.ArrayToNative(sorts),
                                                    sortRefs);
        }
Ejemplo n.º 5
0
 internal FuncDecl(Context ctx, Symbol name, Sort[] domain, Sort range)
     : base(ctx, Native.Z3_mk_func_decl(ctx.nCtx, name.NativeObject, AST.ArrayLength(domain), AST.ArrayToNative(domain), range.NativeObject))
 {
     Contract.Requires(ctx != null);
     Contract.Requires(name != null);
     Contract.Requires(range != null);
 }
Ejemplo n.º 6
0
 internal FuncDecl(Context ctx, Symbol name, Sort[] domain, Sort range, bool is_rec)
     : base(ctx, Native.Z3_mk_rec_func_decl(ctx.nCtx, name.NativeObject, AST.ArrayLength(domain), AST.ArrayToNative(domain), range.NativeObject))
 {
     Debug.Assert(ctx != null);
     Debug.Assert(name != null);
     Debug.Assert(range != null);
 }
Ejemplo n.º 7
0
 internal FuncDecl(Context ctx, string prefix, Sort[] domain, Sort range)
     : base(ctx, Native.Z3_mk_fresh_func_decl(ctx.nCtx, prefix,
                                              AST.ArrayLength(domain), AST.ArrayToNative(domain),
                                              range.NativeObject))
 {
     Contract.Requires(ctx != null);
     Contract.Requires(range != null);
 }
Ejemplo n.º 8
0
        internal Lambda(Context ctx, Expr[] bound, Expr body)
            : base(ctx, IntPtr.Zero)
        {
            Debug.Assert(ctx != null);
            Debug.Assert(body != null);

            Debug.Assert(bound != null && bound.Length > 0 && bound.All(n => n != null));

            Context.CheckContextMatch <Expr>(bound);
            Context.CheckContextMatch(body);

            NativeObject = Native.Z3_mk_lambda_const(ctx.nCtx,
                                                     AST.ArrayLength(bound), AST.ArrayToNative(bound),
                                                     body.NativeObject);
        }
Ejemplo n.º 9
0
        [ContractVerification(false)] // F: Clousot ForAll decompilation gets confused below. Setting verification off until I fixed the bug
        internal Lambda(Context ctx, Expr[] bound, Expr body)
            : base(ctx, IntPtr.Zero)
        {
            Contract.Requires(ctx != null);
            Contract.Requires(body != null);

            Contract.Requires(bound != null && bound.Length > 0 && Contract.ForAll(bound, n => n != null));

            Context.CheckContextMatch <Expr>(bound);
            Context.CheckContextMatch(body);

            NativeObject = Native.Z3_mk_lambda_const(ctx.nCtx,
                                                     AST.ArrayLength(bound), AST.ArrayToNative(bound),
                                                     body.NativeObject);
        }
Ejemplo n.º 10
0
        [ContractVerification(false)] // F: Clousot ForAll decompilation gets confused below. Setting verification off until I fixed the bug
        internal Quantifier(Context ctx, bool isForall, Sort[] sorts, Symbol[] names, Expr body,
                            uint weight         = 1, Pattern[] patterns = null, Expr[] noPatterns = null,
                            Symbol quantifierID = null, Symbol skolemID = null
                            )
            : base(ctx)
        {
            Contract.Requires(ctx != null);
            Contract.Requires(sorts != null);
            Contract.Requires(names != null);
            Contract.Requires(body != null);
            Contract.Requires(sorts.Length == names.Length);
            Contract.Requires(Contract.ForAll(sorts, s => s != null));
            Contract.Requires(Contract.ForAll(names, n => n != null));
            Contract.Requires(patterns == null || Contract.ForAll(patterns, p => p != null));
            Contract.Requires(noPatterns == null || Contract.ForAll(noPatterns, np => np != null));

            Context.CheckContextMatch(patterns);
            Context.CheckContextMatch(noPatterns);
            Context.CheckContextMatch(sorts);
            Context.CheckContextMatch(names);
            Context.CheckContextMatch(body);

            if (sorts.Length != names.Length)
            {
                throw new Z3Exception("Number of sorts does not match number of names");
            }

            IntPtr[] _patterns = AST.ArrayToNative(patterns);

            if (noPatterns == null && quantifierID == null && skolemID == null)
            {
                NativeObject = Native.Z3_mk_quantifier(ctx.nCtx, (isForall) ? 1 : 0, weight,
                                                       AST.ArrayLength(patterns), AST.ArrayToNative(patterns),
                                                       AST.ArrayLength(sorts), AST.ArrayToNative(sorts),
                                                       Symbol.ArrayToNative(names),
                                                       body.NativeObject);
            }
            else
            {
                NativeObject = Native.Z3_mk_quantifier_ex(ctx.nCtx, (isForall) ? 1 : 0, weight,
                                                          AST.GetNativeObject(quantifierID), AST.GetNativeObject(skolemID),
                                                          AST.ArrayLength(patterns), AST.ArrayToNative(patterns),
                                                          AST.ArrayLength(noPatterns), AST.ArrayToNative(noPatterns),
                                                          AST.ArrayLength(sorts), AST.ArrayToNative(sorts),
                                                          Symbol.ArrayToNative(names),
                                                          body.NativeObject);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Query the fixedpoint solver.
        /// A query is an array of relations.
        /// The query is satisfiable if there is an instance of some relation that is non-empty.
        /// The query is unsatisfiable if there are no derivations satisfying any of the relations.
        /// </summary>
        public Status Query(FuncDecl[] relations)
        {
            Contract.Requires(relations != null);
            Contract.Requires(Contract.ForAll(0, relations.Length, i => relations[i] != null));

            Context.CheckContextMatch(relations);
            Z3_lbool r = (Z3_lbool)Native.Z3_fixedpoint_query_relations(Context.nCtx, NativeObject,
                                                                        AST.ArrayLength(relations), AST.ArrayToNative(relations));

            switch (r)
            {
            case Z3_lbool.Z3_L_TRUE: return(Status.SATISFIABLE);

            case Z3_lbool.Z3_L_FALSE: return(Status.UNSATISFIABLE);

            default: return(Status.UNKNOWN);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Query the fixedpoint solver.
        /// A query is an array of relations.
        /// The query is satisfiable if there is an instance of some relation that is non-empty.
        /// The query is unsatisfiable if there are no derivations satisfying any of the relations.
        /// </summary>
        public Status Query(params FuncDecl[] relations)
        {
            Debug.Assert(relations != null);
            Debug.Assert(relations.All(rel => rel != null));

            Context.CheckContextMatch <FuncDecl>(relations);
            Z3_lbool r = (Z3_lbool)Native.Z3_fixedpoint_query_relations(Context.nCtx, NativeObject,
                                                                        AST.ArrayLength(relations), AST.ArrayToNative(relations));

            switch (r)
            {
            case Z3_lbool.Z3_L_TRUE: return(Status.SATISFIABLE);

            case Z3_lbool.Z3_L_FALSE: return(Status.UNSATISFIABLE);

            default: return(Status.UNKNOWN);
            }
        }
Ejemplo n.º 13
0
        internal Quantifier(Context ctx, bool isForall, Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null)
            : base(ctx, IntPtr.Zero)
        {
            Debug.Assert(ctx != null);
            Debug.Assert(sorts != null);
            Debug.Assert(names != null);
            Debug.Assert(body != null);
            Debug.Assert(sorts.Length == names.Length);
            Debug.Assert(sorts.All(s => s != null));
            Debug.Assert(names.All(n => n != null));
            Debug.Assert(patterns == null || patterns.All(p => p != null));
            Debug.Assert(noPatterns == null || noPatterns.All(np => np != null));

            Context.CheckContextMatch <Pattern>(patterns);
            Context.CheckContextMatch <Expr>(noPatterns);
            Context.CheckContextMatch <Sort>(sorts);
            Context.CheckContextMatch <Symbol>(names);
            Context.CheckContextMatch(body);

            if (sorts.Length != names.Length)
            {
                throw new Z3Exception("Number of sorts does not match number of names");
            }

            if (noPatterns == null && quantifierID == null && skolemID == null)
            {
                NativeObject = Native.Z3_mk_quantifier(ctx.nCtx, (byte)(isForall ? 1 : 0), weight,
                                                       AST.ArrayLength(patterns), AST.ArrayToNative(patterns),
                                                       AST.ArrayLength(sorts), AST.ArrayToNative(sorts),
                                                       Symbol.ArrayToNative(names),
                                                       body.NativeObject);
            }
            else
            {
                NativeObject = Native.Z3_mk_quantifier_ex(ctx.nCtx, (byte)(isForall ? 1 : 0), weight,
                                                          AST.GetNativeObject(quantifierID), AST.GetNativeObject(skolemID),
                                                          AST.ArrayLength(patterns), AST.ArrayToNative(patterns),
                                                          AST.ArrayLength(noPatterns), AST.ArrayToNative(noPatterns),
                                                          AST.ArrayLength(sorts), AST.ArrayToNative(sorts),
                                                          Symbol.ArrayToNative(names),
                                                          body.NativeObject);
            }
        }
Ejemplo n.º 14
0
        internal Lambda(Context ctx, Sort[] sorts, Symbol[] names, Expr body)
            : base(ctx, IntPtr.Zero)
        {
            Debug.Assert(ctx != null);
            Debug.Assert(sorts != null);
            Debug.Assert(names != null);
            Debug.Assert(body != null);
            Debug.Assert(sorts.Length == names.Length);
            Debug.Assert(sorts.All(s => s != null));
            Debug.Assert(names.All(n => n != null));
            Context.CheckContextMatch <Sort>(sorts);
            Context.CheckContextMatch <Symbol>(names);
            Context.CheckContextMatch(body);

            if (sorts.Length != names.Length)
            {
                throw new Z3Exception("Number of sorts does not match number of names");
            }

            NativeObject = Native.Z3_mk_lambda(ctx.nCtx,
                                               AST.ArrayLength(sorts), AST.ArrayToNative(sorts),
                                               Symbol.ArrayToNative(names),
                                               body.NativeObject);
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Convert benchmark given as set of axioms, rules and queries to a string.
 /// </summary>
 public string ToString(BoolExpr[] queries)
 {
     return(Native.Z3_fixedpoint_to_string(Context.nCtx, NativeObject,
                                           AST.ArrayLength(queries), AST.ArrayToNative(queries)));
 }