internal ArraySort(Context ctx, Sort[] domain, Sort range) : base(ctx, Native.Z3_mk_array_sort_n(ctx.nCtx, (uint)domain.Length, AST.ArrayToNative(domain), range.NativeObject)) { Contract.Requires(ctx != null); Contract.Requires(domain != null); Contract.Requires(range != null); }
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); } }
internal ArraySort(Context ctx, Sort[] domain, Sort range) : base(ctx, Native.Z3_mk_array_sort_n(ctx.nCtx, (uint)domain.Length, AST.ArrayToNative(domain), range.NativeObject)) { Debug.Assert(ctx != null); Debug.Assert(domain != null); Debug.Assert(range != null); }
[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); } }
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); }
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); }
internal TupleSort(Context ctx, Symbol name, uint numFields, Symbol[] fieldNames, Sort[] fieldSorts) : base(ctx, IntPtr.Zero) { Debug.Assert(ctx != null); Debug.Assert(name != null); IntPtr t = IntPtr.Zero; IntPtr[] f = new IntPtr[numFields]; NativeObject = Native.Z3_mk_tuple_sort(ctx.nCtx, name.NativeObject, numFields, Symbol.ArrayToNative(fieldNames), AST.ArrayToNative(fieldSorts), ref t, f); }
internal TupleSort(Context ctx, Symbol name, uint numFields, Symbol[] fieldNames, Sort[] fieldSorts) : base(ctx) { Contract.Requires(ctx != null); Contract.Requires(name != null); IntPtr t = IntPtr.Zero; NativeObject = Native.Z3_mk_tuple_sort(ctx.nCtx, name.NativeObject, numFields, Symbol.ArrayToNative(fieldNames), AST.ArrayToNative(fieldSorts), ref t, new IntPtr[numFields]); }
[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); }
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); }
[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); } }
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); } }
/// <summary> /// Checks whether the assertions in the context are consistent or not. /// </summary> public static Status Check(Context ctx, List <BoolExpr> core, ref Model model, ref Expr proof, params Expr[] assumptions) { Z3_lbool r; model = null; proof = null; if (assumptions == null || assumptions.Length == 0) { r = (Z3_lbool)Native.Z3_check(ctx.nCtx); } else { IntPtr mdl = IntPtr.Zero, prf = IntPtr.Zero; uint core_size = 0; IntPtr[] native_core = new IntPtr[assumptions.Length]; r = (Z3_lbool)Native.Z3_check_assumptions(ctx.nCtx, (uint)assumptions.Length, AST.ArrayToNative(assumptions), ref mdl, ref prf, ref core_size, native_core); for (uint i = 0; i < core_size; i++) { core.Add((BoolExpr)Expr.Create(ctx, native_core[i])); } if (mdl != IntPtr.Zero) { model = new Model(ctx, mdl); } if (prf != IntPtr.Zero) { proof = Expr.Create(ctx, prf); } } switch (r) { case Z3_lbool.Z3_L_TRUE: return(Status.SATISFIABLE); case Z3_lbool.Z3_L_FALSE: return(Status.UNSATISFIABLE); default: return(Status.UNKNOWN); } }
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); }
/// <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); } }
/// <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); } }
/// <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)); }
/// <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); } }
/// <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)); }
/// <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))); }
/// <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)); } switch (r) { case Z3_lbool.Z3_L_TRUE: return(Status.SATISFIABLE); case Z3_lbool.Z3_L_FALSE: return(Status.UNSATISFIABLE); default: return(Status.UNKNOWN); } }
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); }