Overview
In Z3, all terms, formulas, and types are represented as Abstract Syntax Trees (ASTs). The expression system is the foundation for building and manipulating logical formulas.AST Hierarchy
Z3’s AST nodes form a hierarchy:Core AST Types
Z3_sort - Type/Sort
Z3_sort - Type/Sort
Represents types in Z3’s type system:
- Basic sorts:
Bool,Int,Real - Bit-vector sorts:
(_ BitVec n) - Array sorts:
(Array Domain Range) - Datatypes: user-defined algebraic types
- Uninterpreted sorts: abstract types
Z3_func_decl - Function Declaration
Z3_func_decl - Function Declaration
Declares functions and constants:
- Constants: 0-arity functions
- Uninterpreted functions: no specified meaning
- Interpreted functions: built-in operations (+, *, etc.)
Z3_app - Function Application
Z3_app - Function Application
Applications of functions to arguments:
- Constants are 0-arity applications
- Operations like
x + yare applications of+to[x, y]
Creating Sorts
Creating Expressions
Constants and Variables
Numerals
Function Applications
Expression Kinds
Fromz3_api.h:170, Z3 defines these AST kinds:
Boolean Formulas
Arithmetic Expressions
Bit-Vector Operations
Array Expressions
Expression Traversal
Fromexamples/c++/example.cpp:807:
Expression Simplification
If-Then-Else Terms
Substitution
Fromexamples/c++/example.cpp:1147:
Memory Management
Related Topics
SMT Solving
Learn about satisfiability checking
Solvers
Using expressions with solvers
Quantifiers
Quantified expressions
References
- Z3 API:
src/api/z3_api.h:7-179 - AST implementation:
src/api/api_ast.cpp - Examples:
examples/c++/example.cpp
