Overview
A model is a satisfying assignment for a set of formulas. When Z3 determines a formula is satisfiable, it can produce a model that shows concrete values making the formula true.Getting Models
Fromexamples/c++/example.cpp:45:
Model Evaluation
Fromexamples/c++/example.cpp:56:
Iterating Over Models
Fromexamples/c++/example.cpp:58:
Structured Iteration
Fromexamples/c++/example.cpp:59:
Model Completeness
Models may not assign values to all variables in your problem—only those relevant to satisfying the constraints.
Function Interpretations
Models can include interpretations of uninterpreted functions: Fromexamples/c++/example.cpp:77:
Inspecting Function Interpretations
Array Models
Model Evaluation Options
Creating Models Programmatically
Fromexamples/c++/example.cpp:1354:
Model Conversion
When using tactics, you may need to convert models between goals: Fromexamples/c++/example.cpp:680:
Model String Representation
Evaluating Complex Expressions
Datatype Models
Model Validation
Verify a model satisfies the original constraints:Enumerating Multiple Models
Pretty Printing Models
Model Parameters
Best Practices
Check before accessing
Check before accessing
Always verify
check() == sat before calling model():Use model_completion wisely
Use model_completion wisely
model_completion=True assigns arbitrary values to unconstrained variables. Use when you need complete assignments.Cache evaluations
Cache evaluations
Model evaluation can be expensive. Cache results if evaluating the same expression multiple times.
Validate models in debug mode
Validate models in debug mode
During development, validate that models actually satisfy constraints.
Related Topics
Solvers
Generating models with solvers
Expressions
Building expressions to evaluate
SMT Solving
Satisfiability and models
References
- Model API:
src/api/api_model.cpp - Model implementation:
src/model/model.h - Examples:
examples/c++/example.cpp:45-66,examples/c++/example.cpp:252-270
