Skip to main content

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

From examples/c++/example.cpp:45:

Model Evaluation

From examples/c++/example.cpp:56:

Iterating Over Models

From examples/c++/example.cpp:58:

Structured Iteration

From examples/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: From examples/c++/example.cpp:77:

Inspecting Function Interpretations

Array Models

Model Evaluation Options

Creating Models Programmatically

From examples/c++/example.cpp:1354:

Model Conversion

When using tactics, you may need to convert models between goals: From examples/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

Always verify check() == sat before calling model():
model_completion=True assigns arbitrary values to unconstrained variables. Use when you need complete assignments.
Model evaluation can be expensive. Cache results if evaluating the same expression multiple times.
During development, validate that models actually satisfy constraints.

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