Skip to main content

Overview

The Model API provides functions for extracting and interpreting models - satisfying assignments returned by the solver when a formula is satisfiable.

Types

Z3_model

A model for the constraints asserted into the logical context. Contains interpretations for constants and functions.

Z3_func_interp

Interpretation of a function in a model. Represents the graph of a function.

Z3_func_entry

Representation of a function interpretation entry at a particular point.

Model Creation and Reference Counting

Z3_mk_model

Create an empty model.
Z3_model
New empty model

Z3_model_inc_ref

Increment the reference counter of the model.

Z3_model_dec_ref

Decrement the reference counter of the model. Example:

Evaluating Expressions

Z3_model_eval

Evaluate an expression in the model.
bool
True if evaluation succeeded
Description: Model completion assigns default values to constants not assigned by the model. Example:

Constant Interpretation

Z3_model_get_num_consts

Return the number of constants assigned by the model.
unsigned
Number of constants

Z3_model_get_const_decl

Return the i-th constant declaration.
Z3_func_decl
Constant declaration

Z3_model_get_const_interp

Return the interpretation of a constant.
Z3_ast
Value of the constant (NULL if not assigned)
Example:

Z3_model_has_interp

Check if model has an interpretation for a declaration.
bool
True if interpretation exists

Function Interpretation

Z3_model_get_num_funcs

Return the number of function interpretations.
unsigned
Number of functions

Z3_model_get_func_decl

Return the i-th function declaration.
Z3_func_decl
Function declaration

Z3_model_get_func_interp

Return the interpretation of a function.
Z3_func_interp
Function interpretation

Function Interpretation Details

Z3_func_interp_get_num_entries

Return the number of entries in the function graph.
unsigned
Number of entries

Z3_func_interp_get_entry

Return the i-th entry in the function graph.
Z3_func_entry
Function entry

Z3_func_interp_get_else

Return the ‘else’ value (default) for a function interpretation.
Z3_ast
Default value

Z3_func_entry_get_value

Return the result value of a function entry.
Z3_ast
Result value

Z3_func_entry_get_num_args

Return the number of arguments in a function entry.
unsigned
Number of arguments

Z3_func_entry_get_arg

Return the i-th argument of a function entry.
Z3_ast
Argument value

Sort Universe

Z3_model_get_num_sorts

Return the number of uninterpreted sorts with finite interpretations.
unsigned
Number of sorts

Z3_model_get_sort

Return the i-th uninterpreted sort.
Z3_sort
Uninterpreted sort

Z3_model_get_sort_universe

Return the finite set of elements representing the interpretation of sort s.
Z3_ast_vector
Vector of elements in the sort’s universe

Model Conversion

Z3_model_to_string

Convert model to a string representation.
Z3_string
String representation
Example:

Complete Example