21 using System.Diagnostics.Contracts;
23 namespace Microsoft.Z3
28 [ContractVerification(
true)]
38 Contract.Ensures(Contract.Result<
Expr>() != null);
41 return Expr.Create(
Context, Native.Z3_simplify(Context.nCtx, NativeObject));
43 return Expr.Create(Context, Native.Z3_simplify_ex(Context.nCtx, NativeObject, p.NativeObject));
53 Contract.Ensures(Contract.Result<
FuncDecl>() != null);
64 get {
return (
Z3_lbool)Native.Z3_get_bool_value(Context.nCtx, NativeObject); }
72 get {
return Native.Z3_get_app_num_args(Context.nCtx, NativeObject); }
82 Contract.Ensures(Contract.Result<
Expr[]>() != null);
86 for (uint i = 0; i < n; i++)
98 Contract.Requires(args != null);
99 Contract.Requires(Contract.ForAll(args, a => a != null));
101 Context.CheckContextMatch(args);
102 if (IsApp && args.Length != NumArgs)
103 throw new Z3Exception(
"Number of arguments does not match");
104 NativeObject = Native.Z3_update_term(Context.nCtx, NativeObject, (uint)args.Length,
Expr.ArrayToNative(args));
117 Contract.Requires(from != null);
118 Contract.Requires(to != null);
119 Contract.Requires(Contract.ForAll(from, f => f != null));
120 Contract.Requires(Contract.ForAll(to, t => t != null));
121 Contract.Ensures(Contract.Result<
Expr>() != null);
123 Context.CheckContextMatch(from);
124 Context.CheckContextMatch(to);
125 if (from.Length != to.Length)
126 throw new Z3Exception(
"Argument sizes do not match");
127 return Expr.Create(
Context, Native.Z3_substitute(Context.nCtx, NativeObject, (uint)from.Length,
Expr.ArrayToNative(from), Expr.ArrayToNative(to)));
136 Contract.Requires(from != null);
137 Contract.Requires(to != null);
138 Contract.Ensures(Contract.Result<
Expr>() != null);
140 return Substitute(
new Expr[] { from },
new Expr[] { to });
151 Contract.Requires(to != null);
152 Contract.Requires(Contract.ForAll(to, t => t != null));
153 Contract.Ensures(Contract.Result<
Expr>() != null);
155 Context.CheckContextMatch(to);
156 return Expr.Create(
Context, Native.Z3_substitute_vars(Context.nCtx, NativeObject, (uint)to.Length,
Expr.ArrayToNative(to)));
166 Contract.Requires(ctx != null);
167 Contract.Ensures(Contract.Result<
Expr>() != null);
169 if (ReferenceEquals(
Context, ctx))
172 return Expr.Create(ctx, Native.Z3_translate(Context.nCtx, NativeObject, ctx.nCtx));
180 return base.ToString();
186 public bool IsNumeral
188 get {
return Native.Z3_is_numeral_ast(Context.nCtx, NativeObject) != 0; }
195 public bool IsWellSorted
197 get {
return Native.Z3_is_well_sorted(Context.nCtx, NativeObject) != 0; }
207 Contract.Ensures(Contract.Result<
Sort>() != null);
208 return Sort.Create(
Context, Native.Z3_get_sort(Context.nCtx, NativeObject));
218 get {
return IsApp && NumArgs == 0 && FuncDecl.DomainSize == 0; }
222 #region Integer Numerals
228 get {
return IsNumeral &&
IsInt; }
232 #region Real Numerals
238 get {
return IsNumeral && IsReal; }
242 #region Algebraic Numbers
243 public bool IsAlgebraicNumber
248 get {
return Native.Z3_is_algebraic_number(Context.nCtx, NativeObject) != 0; }
252 #region Term Kind Tests
254 #region Boolean Terms
265 Native.Z3_get_sort(Context.nCtx, NativeObject)) != 0);
326 #region Interpolation
334 #region Arithmetic Terms
343 Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_sort(Context.nCtx, NativeObject)) == (uint)
Z3_sort_kind.Z3_INT_SORT);
352 get {
return Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_sort(Context.nCtx, NativeObject)) == (uint)
Z3_sort_kind.Z3_REAL_SORT; }
515 #region Bit-vector terms
521 get {
return Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_sort(Context.nCtx, NativeObject)) == (uint)
Z3_sort_kind.Z3_BV_SORT; }
1312 #region Relational Terms
1313 public bool IsRelation
1321 Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_sort(Context.nCtx, NativeObject))
1434 #region Finite domain terms
1435 public bool IsFiniteDomain
1443 Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_sort(Context.nCtx, NativeObject)) == (uint)
Z3_sort_kind.Z3_FINITE_DOMAIN_SORT);
1453 #region Floating-point terms
1459 get {
return Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_sort(Context.nCtx, NativeObject)) == (uint)
Z3_sort_kind.Z3_FLOATING_POINT_SORT; }
1467 get {
return Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_sort(Context.nCtx, NativeObject)) == (uint)
Z3_sort_kind.Z3_ROUNDING_MODE_SORT; }
1473 public bool IsFPNumeral {
get {
return IsFP && IsNumeral; } }
1478 public bool IsFPRMNumeral {
get {
return IsFPRM && IsNumeral; } }
1533 public bool IsFPRMExpr {
1536 (FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY||
1537 FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN ||
1538 FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_FPA_RM_TOWARD_POSITIVE ||
1539 FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_FPA_RM_TOWARD_NEGATIVE ||
1729 #region Bound Variables
1754 throw new Z3Exception(
"Term is not a bound variable.");
1756 Contract.EndContractBlock();
1758 return Native.Z3_get_index_value(Context.nCtx, NativeObject);
1764 internal protected Expr(
Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
1771 internal override void CheckNativeObject(IntPtr obj)
1773 if (Native.Z3_is_app(Context.nCtx, obj) == 0 &&
1776 throw new Z3Exception("Underlying
object is not a term");
1777 base.CheckNativeObject(obj);
1782 internal static Expr Create(Context ctx, FuncDecl f, params Expr[] arguments)
1784 Contract.Requires(ctx != null);
1785 Contract.Requires(f != null);
1786 Contract.Ensures(Contract.Result<Expr>() != null);
1788 IntPtr obj = Native.Z3_mk_app(ctx.nCtx, f.NativeObject,
1789 AST.ArrayLength(arguments),
1790 AST.ArrayToNative(arguments));
1791 return Create(ctx, obj);
1795 new internal static Expr Create(Context ctx, IntPtr obj)
1797 Contract.Requires(ctx != null);
1798 Contract.Ensures(Contract.Result<Expr>() != null);
1802 return new Quantifier(ctx, obj);
1803 IntPtr s = Native.Z3_get_sort(ctx.nCtx, obj);
1806 if (Native.Z3_is_algebraic_number(ctx.nCtx, obj) != 0)
1807 return new AlgebraicNum(ctx, obj);
1809 if (Native.Z3_is_numeral_ast(ctx.nCtx, obj) != 0)
1813 case Z3_sort_kind.Z3_INT_SORT:
return new IntNum(ctx, obj);
1814 case Z3_sort_kind.Z3_REAL_SORT:
return new RatNum(ctx, obj);
1815 case Z3_sort_kind.Z3_BV_SORT:
return new BitVecNum(ctx, obj);
1816 case Z3_sort_kind.Z3_FLOATING_POINT_SORT:
return new FPNum(ctx, obj);
1817 case Z3_sort_kind.Z3_ROUNDING_MODE_SORT:
return new FPRMNum(ctx, obj);
1823 case Z3_sort_kind.Z3_BOOL_SORT:
return new BoolExpr(ctx, obj);
1824 case Z3_sort_kind.Z3_INT_SORT:
return new IntExpr(ctx, obj);
1825 case Z3_sort_kind.Z3_REAL_SORT:
return new RealExpr(ctx, obj);
1826 case Z3_sort_kind.Z3_BV_SORT:
return new BitVecExpr(ctx, obj);
1827 case Z3_sort_kind.Z3_ARRAY_SORT:
return new ArrayExpr(ctx, obj);
1828 case Z3_sort_kind.Z3_DATATYPE_SORT:
return new DatatypeExpr(ctx, obj);
1829 case Z3_sort_kind.Z3_FLOATING_POINT_SORT:
return new FPExpr(ctx, obj);
1830 case Z3_sort_kind.Z3_ROUNDING_MODE_SORT:
return new FPRMExpr(ctx, obj);
1833 return new Expr(ctx, obj);
Z3_sort_kind
The different kinds of Z3 types (See Z3_get_sort_kind).
Expr Simplify(Params p=null)
Returns a simplified version of the expression.
static uint Z3_get_sort_kind(Z3_context a0, Z3_sort a1)
Expr SubstituteVars(Expr[] to)
Substitute the free variables in the expression with the expressions in to
Expr Substitute(Expr[] from, Expr[] to)
Substitute every occurrence of from[i] in the expression with to[i], for i smaller than num_exprs...
Z3_ast_kind Z3_API Z3_get_ast_kind(Z3_context c, Z3_ast a)
Return the kind of the given AST.
Z3_ast_kind
The different kinds of Z3 AST (abstract syntax trees). That is, terms, formulas and types...
static Z3_sort Z3_get_sort(Z3_context a0, Z3_ast a1)
new Expr Translate(Context ctx)
Translates (copies) the term to the Context ctx .
override string ToString()
Returns a string representation of the expression.
static Z3_ast Z3_get_app_arg(Z3_context a0, Z3_app a1, uint a2)
static int Z3_is_eq_sort(Z3_context a0, Z3_sort a1, Z3_sort a2)
A Params objects represents a configuration in the form of Symbol/value pairs.
void Update(Expr[] args)
Update the arguments of the expression using the arguments args The number of new arguments should c...
The main interaction with Z3 happens via the Context.
The Sort class implements type information for ASTs.
The exception base class for error reporting from Z3
The abstract syntax tree (AST) class.
static int Z3_is_app(Z3_context a0, Z3_ast a1)
Expr Substitute(Expr from, Expr to)
Substitute every occurrence of from in the expression with to.
static Z3_func_decl Z3_get_app_decl(Z3_context a0, Z3_app a1)
static Z3_sort Z3_mk_bool_sort(Z3_context a0)
static int Z3_is_numeral_ast(Z3_context a0, Z3_ast a1)