23using System.Collections.Generic;
25using System.Diagnostics;
29 using Z3_ast = System.IntPtr;
53 if (Native.Z3_get_arity(ntvContext.nCtx, f) != 0)
54 throw new Z3Exception(
"Non-zero arity functions have FunctionInterpretations as a model. Use FuncInterp.");
56 return Native.Z3_model_get_const_interp(ntvContext.nCtx, NativeObject, f);
68 if (Native.Z3_get_arity(ntvContext.nCtx, f) == 0)
70 IntPtr n = Native.Z3_model_get_const_interp(ntvContext.nCtx, NativeObject, f);
78 if (Native.Z3_is_as_array(ntvContext.nCtx, n) == 0)
79 throw new Z3Exception(
"Argument was not an array constant");
80 var fd = Native.Z3_get_as_array_func_decl(ntvContext.nCtx, n);
86 throw new Z3Exception(
"Constant functions do not have a function interpretation; use ConstInterp");
91 IntPtr n = Native.Z3_model_get_func_interp(ntvContext.nCtx, NativeObject, f);
106 get {
return Native.Z3_model_get_num_consts(ntvContext.nCtx, NativeObject); }
120 for (uint i = 0; i < n; i++)
121 res[i] = Native.Z3_model_get_const_decl(ntvContext.nCtx, NativeObject, i);
130 public IEnumerable<KeyValuePair<Z3_func_decl, Z3_ast>>
Consts
135 for (uint i = 0; i < nc; ++i)
137 var f = Native.Z3_model_get_const_decl(ntvContext.nCtx, NativeObject, i);
138 IntPtr n = Native.Z3_model_get_const_interp(ntvContext.nCtx, NativeObject, f);
139 if (n == IntPtr.Zero)
continue;
140 yield
return new KeyValuePair<Z3_func_decl, Z3_ast>(f, n);
150 get {
return Native.Z3_model_get_num_funcs(ntvContext.nCtx, NativeObject); }
163 for (uint i = 0; i < n; i++)
164 res[i] = Native.Z3_model_get_func_decl(ntvContext.nCtx, NativeObject, i);
179 uint n = nFuncs + nConsts;
181 for (uint i = 0; i < nConsts; i++)
182 res[i] = Native.Z3_model_get_const_decl(ntvContext.nCtx, NativeObject, i);
183 for (uint i = 0; i < nFuncs; i++)
184 res[nConsts + i] = Native.Z3_model_get_func_decl(ntvContext.nCtx, NativeObject, i);
217 IntPtr v = IntPtr.Zero;
218 if (Native.Z3_model_eval(ntvContext.nCtx, NativeObject, t, (
byte)(completion ? 1 : 0), ref v) == (
byte)0)
234 var r =
Eval(t,
true);
235 return Native.Z3_get_numeral_double(ntvContext.nCtx, r);
246 public KeyValuePair<Z3_ast, Z3_ast>[]
Updates;
274 var r =
Eval(t,
true);
276 var updates =
new Dictionary<Z3_ast, Z3_ast>();
287 result.Else = ntvContext.GetAppArg(r, 0);
288 result.Updates = updates.ToArray();
289 result.Domain = updates.Keys.ToArray();
290 result.Range = updates.Values.ToArray();
296 updates[ntvContext.GetAppArg(r, 1)] = ntvContext.GetAppArg(r, 2);
297 r = ntvContext.GetAppArg(r, 0);
309 public uint
NumSorts {
get {
return Native.Z3_model_get_num_sorts(ntvContext.nCtx, NativeObject); } }
328 for (uint i = 0; i < n; i++)
329 res[i] = Native.Z3_model_get_sort(ntvContext.nCtx, NativeObject, i);
341 return Native.Z3_model_to_string(ntvContext.nCtx, NativeObject);
352 Debug.Assert(ctx !=
null);
353 Native.Z3_model_inc_ref(ctx.nCtx, obj);
370 if (NativeObject != IntPtr.Zero)
372 Native.Z3_model_dec_ref(ntvContext.nCtx, NativeObject);
373 NativeObject = IntPtr.Zero;
375 GC.SuppressFinalize(
this);
The main interaction with Z3 happens via the Context. NativeContext allows for efficient wrapper-redu...
Z3_ast_kind GetAstKind(Z3_ast ast)
Get the AST kind from IntPtr
uint GetNumArgs(Z3_app app)
Return number of arguments for app
Z3_decl_kind GetDeclKind(Z3_func_decl decl)
Get the Decl kind from IntPtr
Z3_func_decl GetAppDecl(Z3_ast ast)
Get App Decl from IntPtr
A function interpretation is represented as a finite map and an 'else' value. Each entry in the finit...
An array value obtained by untangling a model assignment.
Z3_ast[] Range
Range for array Updates.Values
Z3_ast[] Domain
Domain for array Updates.Keys
Z3_ast Else
default Else case
KeyValuePair< Z3_ast, Z3_ast >[] Updates
One dimensional array of indices where the array is updated
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.
Z3_ast ConstInterp(Z3_ast a)
Retrieves the interpretation (the assignment) of a in the model.
bool TryGetArrayValue(Z3_ast t, out ArrayValue result)
Convert the interpretation of t into a sequence of array updates
Z3_sort[] Sorts
The uninterpreted sorts that the model has an interpretation for.
Z3_func_decl[] FuncDecls
The function declarations of the function interpretations in the model.
double Double(Z3_ast t)
Evaluate expression to a double, assuming it is a numeral already.
void Dispose()
Disposes of the underlying native Z3 object.
IEnumerable< KeyValuePair< Z3_func_decl, Z3_ast > > Consts
Enumerate constants in model.
NativeFuncInterp FuncInterp(Z3_func_decl f)
Retrieves the interpretation (the assignment) of a non-constant f in the model.
Z3_ast Eval(Z3_ast t, bool completion=false)
Evaluates the expression t in the current model.
Z3_func_decl[] Decls
All symbols that have an interpretation in the model.
override string ToString()
Conversion of models to strings.
Z3_ast Evaluate(Z3_ast t, bool completion=false)
Alias for Eval.
Z3_ast ConstFuncInterp(Z3_func_decl f)
Retrieves the interpretation (the assignment) of f in the model.
Z3_func_decl[] ConstDecls
The function declarations of the constants in the model.
uint NumFuncs
The number of function interpretations in the 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 exception base class for error reporting from Z3
Z3_ast_kind
The different kinds of Z3 AST (abstract syntax trees). That is, terms, formulas and types.
Z3_decl_kind
The different kinds of interpreted function kinds.
Z3_sort_kind
The different kinds of Z3 types (See Z3_get_sort_kind).
System.IntPtr Z3_func_decl