21using System.Diagnostics;
22using System.Collections.Generic;
38 Debug.Assert(a !=
null);
51 Debug.Assert(f !=
null);
55 throw new Z3Exception(
"Non-zero arity functions have FunctionInterpretations as a model. Use FuncInterp.");
57 IntPtr n = Native.Z3_model_get_const_interp(
Context.nCtx, NativeObject, f.NativeObject);
71 Debug.Assert(f !=
null);
79 IntPtr n = Native.Z3_model_get_const_interp(
Context.nCtx, NativeObject, f.NativeObject);
87 if (Native.Z3_is_as_array(
Context.nCtx, n) == 0)
88 throw new Z3Exception(
"Argument was not an array constant");
89 IntPtr fd = Native.Z3_get_as_array_func_decl(
Context.nCtx, n);
96 throw new Z3Exception(
"Constant functions do not have a function interpretation; use ConstInterp");
101 IntPtr n = Native.Z3_model_get_func_interp(
Context.nCtx, NativeObject, f.NativeObject);
102 if (n == IntPtr.Zero)
114 get {
return Native.Z3_model_get_num_consts(
Context.nCtx, NativeObject); }
127 for (uint i = 0; i < n; i++)
136 public IEnumerable<KeyValuePair<FuncDecl, Expr>>
Consts
141 for (uint i = 0; i < nc; ++i)
144 IntPtr n = Native.Z3_model_get_const_interp(
Context.nCtx, NativeObject, f.NativeObject);
145 if (n == IntPtr.Zero)
continue;
146 yield
return new KeyValuePair<FuncDecl, Expr>(f,
Expr.Create(
Context, n));
156 get {
return Native.Z3_model_get_num_funcs(
Context.nCtx, NativeObject); }
169 for (uint i = 0; i < n; i++)
185 uint n = nFuncs + nConsts;
187 for (uint i = 0; i < nConsts; i++)
189 for (uint i = 0; i < nFuncs; i++)
222 Debug.Assert(t !=
null);
224 IntPtr v = IntPtr.Zero;
225 if (Native.Z3_model_eval(
Context.nCtx, NativeObject, t.NativeObject, (
byte)(completion ? 1 : 0), ref v) == (
byte)0)
236 Debug.Assert(t !=
null);
238 return Eval(t, completion);
245 using var r =
Eval(t,
true);
246 return Native.Z3_get_numeral_double(
Context.nCtx, r.NativeObject);
252 public uint
NumSorts {
get {
return Native.Z3_model_get_num_sorts(
Context.nCtx, NativeObject); } }
271 for (uint i = 0; i < n; i++)
272 res[i] =
Sort.Create(
Context, Native.Z3_model_get_sort(
Context.nCtx, NativeObject, i));
285 Debug.Assert(s !=
null);
297 return Native.Z3_model_to_string(
Context.nCtx, NativeObject);
304 Debug.Assert(ctx !=
null);
307 internal class DecRefQueue : IDecRefQueue
309 public DecRefQueue() : base() { }
310 public DecRefQueue(uint move_limit) : base(move_limit) { }
311 internal override void IncRef(
Context ctx, IntPtr obj)
313 Native.Z3_model_inc_ref(ctx.nCtx, obj);
316 internal override void DecRef(
Context ctx, IntPtr obj)
318 Native.Z3_model_dec_ref(ctx.nCtx, obj);
322 internal override void IncRef(IntPtr o)
328 internal override void DecRef(IntPtr o)
Expr[] ToExprArray()
Translates an ASTVector into an Expr[]
The main interaction with Z3 happens via the Context.
IDecRefQueue Model_DRQ
Model DRQ
FuncDecl FuncDecl
The function declaration of the function that is applied in this expression.
uint Arity
The arity of the function declaration
A function interpretation is represented as a finite map and an 'else' value. Each entry in the finit...
A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model.
ModelEvaluationFailedException()
An exception that is thrown when model evaluation fails.
A Model contains interpretations (assignments) of constants and functions.
FuncDecl[] Decls
All symbols that have an interpretation in the model.
Expr ConstInterp(Expr a)
Retrieves the interpretation (the assignment) of a in the model.
Expr Evaluate(Expr t, bool completion=false)
Alias for Eval.
FuncDecl[] FuncDecls
The function declarations of the function interpretations in the model.
double Double(Expr t)
Evaluate expression to a double, assuming it is a numeral already.
FuncInterp FuncInterp(FuncDecl f)
Retrieves the interpretation (the assignment) of a non-constant f in the model.
Expr[] SortUniverse(Sort s)
The finite set of distinct values that represent the interpretation for sort s .
Sort[] Sorts
The uninterpreted sorts that the model has an interpretation for.
IEnumerable< KeyValuePair< FuncDecl, Expr > > Consts
Enumerate constants in model.
FuncDecl[] ConstDecls
The function declarations of the constants in the model.
override string ToString()
Conversion of models to strings.
uint NumFuncs
The number of function interpretations in the model.
Expr ConstInterp(FuncDecl f)
Retrieves the interpretation (the assignment) of f in the model.
Expr Eval(Expr t, bool completion=false)
Evaluates the expression t in the current model.
uint NumConsts
The number of constants that have an interpretation in the model.
uint NumSorts
The number of uninterpreted sorts that the model has an interpretation for.
The Sort class implements type information for ASTs.
The exception base class for error reporting from Z3
Internal base class for interfacing with native Z3 objects. Should not be used externally.
Context Context
Access Context object
Z3_sort_kind
The different kinds of Z3 types (See Z3_get_sort_kind).