Inheritance: Z3Object, IComparable
Example #1
0
        /// <summary>
        /// Stores or replaces a new key/value pair in the map.
        /// </summary>
        /// <param name="k">The key AST</param>
        /// <param name="v">The value AST</param>
        public void Insert(AST k, AST v)
        {
            Contract.Requires(k != null);
            Contract.Requires(v != null);

            Native.Z3_ast_map_insert(Context.nCtx, NativeObject, k.NativeObject, v.NativeObject);
        }
Example #2
0
        /// <summary>
        /// Finds the value associated with the key <paramref name="k"/>.
        /// </summary>
        /// <remarks>
        /// This function signs an error when <paramref name="k"/> is not a key in the map.
        /// </remarks>
        /// <param name="k">An AST</param>    
        public AST Find(AST k)
        {
            Contract.Requires(k != null);
            Contract.Ensures(Contract.Result<AST>() != null);

            return new AST(Context, Native.Z3_ast_map_find(Context.nCtx, NativeObject, k.NativeObject));
        }
Example #3
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);
 }
Example #4
0
 internal Parameter(Z3_parameter_kind k, AST a)
 {
     this.kind = k;
     this.ast = a;
 }
Example #5
0
        /// <summary>
        /// Erases the key <paramref name="k"/> from the map.
        /// </summary>
        /// <param name="k">An AST</param>
        public void Erase(AST k)
        {
            Contract.Requires(k != null);

            Native.Z3_ast_map_erase(Context.nCtx, NativeObject, k.NativeObject);
        }
Example #6
0
 /// <summary>
 /// Translates an AST vector into an AST[]
 /// </summary>    
 public AST[] ToArray()
 {
     uint n = Size;
     AST[] res = new AST[n];
     for (uint i = 0; i < n; i++)
         res[i] = AST.Create(this.Context, this[i].NativeObject);
     return res;
 }
Example #7
0
        /// <summary>
        /// Update named rule into in the fixedpoint solver.
        /// </summary>
        public void UpdateRule(BoolExpr rule, Symbol name)
        {
            Debug.Assert(rule != null);

            Context.CheckContextMatch(rule);
            Native.Z3_fixedpoint_update_rule(Context.nCtx, NativeObject, rule.NativeObject, AST.GetNativeObject(name));
        }
Example #8
0
        /// <summary>
        /// Checks whether the assertions in the solver are consistent or not.
        /// </summary>
        /// <remarks>
        /// <seealso cref="Model"/>
        /// <seealso cref="UnsatCore"/>
        /// <seealso cref="Proof"/>
        /// </remarks>
        public Status Check(params Expr[] assumptions)
        {
            Z3_lbool r;

            if (assumptions == null || assumptions.Length == 0)
            {
                r = (Z3_lbool)Native.Z3_solver_check(Context.nCtx, NativeObject);
            }
            else
            {
                r = (Z3_lbool)Native.Z3_solver_check_assumptions(Context.nCtx, NativeObject, (uint)assumptions.Length, AST.ArrayToNative(assumptions));
            }
            return(lboolToStatus(r));
        }
Example #9
0
        /// <summary>
        /// Checks whether the assertions in the solver are consistent or not.
        /// </summary>
        /// <remarks>
        /// <seealso cref="Model"/>
        /// <seealso cref="UnsatCore"/>
        /// <seealso cref="Proof"/>
        /// </remarks>
        public Status Check(IEnumerable <BoolExpr> assumptions)
        {
            Z3_lbool r;

            BoolExpr[] asms = assumptions.ToArray();
            if (asms.Length == 0)
            {
                r = (Z3_lbool)Native.Z3_solver_check(Context.nCtx, NativeObject);
            }
            else
            {
                r = (Z3_lbool)Native.Z3_solver_check_assumptions(Context.nCtx, NativeObject, (uint)asms.Length, AST.ArrayToNative(asms));
            }
            return(lboolToStatus(r));
        }
Example #10
0
        /// <summary>
        /// Erases the key <paramref name="k"/> from the map.
        /// </summary>
        /// <param name="k">An AST</param>
        public void Erase(AST k)
        {
            Contract.Requires(k != null);

            Native.Z3_ast_map_erase(Context.nCtx, NativeObject, k.NativeObject);
        }
Example #11
0
        /// <summary>
        /// Checks whether the map contains the key <paramref name="k"/>.
        /// </summary>
        /// <param name="k">An AST</param>
        /// <returns>True if <paramref name="k"/> is a key in the map, false otherwise.</returns>
        public bool Contains(AST k)
        {
            Contract.Requires(k != null);

            return(Native.Z3_ast_map_contains(Context.nCtx, NativeObject, k.NativeObject) != 0);
        }
Example #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(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);
            }
        }
Example #13
0
        /// <summary>
        /// Add rule into the fixedpoint solver.
        /// </summary>
        public void AddRule(BoolExpr rule, Symbol name = null)
        {
            Contract.Requires(rule != null);

            Context.CheckContextMatch(rule);
            Native.Z3_fixedpoint_add_rule(Context.nCtx, NativeObject, rule.NativeObject, AST.GetNativeObject(name));
        }
Example #14
0
        /// <summary>
        /// Add the AST <paramref name="a"/> to the back of the vector. The size
        /// is increased by 1.
        /// </summary>
        /// <param name="a">An AST</param>
        public void Push(AST a)
        {
            Contract.Requires(a != null);

            Native.Z3_ast_vector_push(Context.nCtx, NativeObject, a.NativeObject);
        }
Example #15
0
        /// <summary>
        /// Add the AST <paramref name="a"/> to the back of the vector. The size
        /// is increased by 1.
        /// </summary>
        /// <param name="a">An AST</param>
        public void Push(AST a)
        {
            Debug.Assert(a != null);

            Native.Z3_ast_vector_push(Context.nCtx, NativeObject, a.NativeObject);
        }
Example #16
0
        /// <summary>
        /// Finds the value associated with the key <paramref name="k"/>.
        /// </summary>
        /// <remarks>
        /// This function signs an error when <paramref name="k"/> is not a key in the map.
        /// </remarks>
        /// <param name="k">An AST</param>
        public AST Find(AST k)
        {
            Debug.Assert(k != null);

            return(new AST(Context, Native.Z3_ast_map_find(Context.nCtx, NativeObject, k.NativeObject)));
        }
Example #17
0
        /// <summary>
        /// Erases the key <paramref name="k"/> from the map.
        /// </summary>
        /// <param name="k">An AST</param>
        public void Erase(AST k)
        {
            Debug.Assert(k != null);

            Native.Z3_ast_map_erase(Context.nCtx, NativeObject, k.NativeObject);
        }
Example #18
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, IntPtr.Zero)
        {
            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 <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, (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);
            }
        }
Example #19
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);
            }
        }
Example #20
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);
            }
        }
Example #21
0
 /// <summary>
 /// Convert benchmark given as set of axioms, rules and queries to a string.
 /// </summary>
 public string ToString(params BoolExpr[] queries)
 {
     return(Native.Z3_fixedpoint_to_string(Context.nCtx, NativeObject,
                                           AST.ArrayLength(queries), AST.ArrayToNative(queries)));
 }
Example #22
0
 internal Parameter(Z3_parameter_kind k, AST a)
 {
     this.kind = k;
     this.ast  = a;
 }
Example #23
0
        /// <summary>
        /// Checks whether the map contains the key <paramref name="k"/>.
        /// </summary>
        /// <param name="k">An AST</param>
        /// <returns>True if <paramref name="k"/> is a key in the map, false otherwise.</returns>
        public bool Contains(AST k)
        {
            Contract.Requires(k != null);

            return Native.Z3_ast_map_contains(Context.nCtx, NativeObject, k.NativeObject) != 0;
        }
Example #24
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);
 }
Example #25
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);
 }
Example #26
0
        /// <summary>
        /// Check satisfiability of asserted constraints.
        /// Produce a model that (when the objectives are bounded and
        /// don't use strict inequalities) meets the objectives.
        /// </summary>
        ///
        public Status Check(params Expr[] assumptions)
        {
            Z3_lbool r = (Z3_lbool)Native.Z3_optimize_check(Context.nCtx, NativeObject, (uint)assumptions.Length, AST.ArrayToNative(assumptions));

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

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

            default:
                return(Status.UNKNOWN);
            }
        }
Example #27
0
        /// <summary>
        /// Add the AST <paramref name="a"/> to the back of the vector. The size
        /// is increased by 1.
        /// </summary>
        /// <param name="a">An AST</param>
        public void Push(AST a)
        {
            Contract.Requires(a != null);

            Native.Z3_ast_vector_push(Context.nCtx, NativeObject, a.NativeObject);
        }
Example #28
0
        /// <summary>
        /// Checks whether the map contains the key <paramref name="k"/>.
        /// </summary>
        /// <param name="k">An AST</param>
        /// <returns>True if <paramref name="k"/> is a key in the map, false otherwise.</returns>
        public bool Contains(AST k)
        {
            Debug.Assert(k != null);

            return(0 != Native.Z3_ast_map_contains(Context.nCtx, NativeObject, k.NativeObject));
        }
Example #29
0
 /// <summary>
 /// Unwraps an AST.
 /// </summary>
 /// <remarks>This function is used for transitions between native and 
 /// managed objects. It returns the native pointer to the AST. Note that 
 /// AST objects are reference counted and unwrapping an AST disables automatic
 /// reference counting, i.e., all references to the IntPtr that is returned 
 /// must be handled externally and through native calls (see e.g., 
 /// <seealso cref="Native.Z3_inc_ref"/>).</remarks>
 /// <seealso cref="WrapAST"/>
 /// <param name="a">The AST to unwrap.</param>
 public IntPtr UnwrapAST(AST a)
 {
     return a.NativeObject;
 }
Example #30
0
        /// <summary>
        /// Checks whether the assertions in the solver are consistent or not.
        /// </summary>
        /// <remarks>
        /// <seealso cref="Model"/>
        /// <seealso cref="UnsatCore"/>
        /// <seealso cref="Proof"/>
        /// </remarks>
        public Status Check(params Expr[] assumptions)
        {
            Z3_lbool r;

            if (assumptions == null)
            {
                r = (Z3_lbool)Native.Z3_solver_check(Context.nCtx, NativeObject);
            }
            else
            {
                r = (Z3_lbool)Native.Z3_solver_check_assumptions(Context.nCtx, NativeObject, (uint)assumptions.Length, AST.ArrayToNative(assumptions));
            }
            switch (r)
            {
            case Z3_lbool.Z3_L_TRUE: return(Status.SATISFIABLE);

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

            default: return(Status.UNKNOWN);
            }
        }