Skip to main content

Overview

The Expression API provides functions for creating and manipulating Z3 abstract syntax trees (ASTs), which represent terms, formulas, and types.

Types

Z3_ast

Abstract syntax tree node - the fundamental data structure in Z3 for representing terms, formulas, and types.

Z3_app

A kind of AST used to represent function applications. Subtype of Z3_ast.

Z3_ast_kind

The different kinds of Z3 AST nodes:

Z3_symbol

Lisp-like symbol used to name types, constants, and functions. Can be created using strings or integers.

Symbol Creation

Z3_mk_int_symbol

Create a Z3 symbol using an integer.
Z3_symbol
New symbol

Z3_mk_string_symbol

Create a Z3 symbol using a C string.
Z3_symbol
New symbol
Example:

Boolean Expressions

Z3_mk_true

Create the true Boolean constant.
Z3_ast
The true constant

Z3_mk_false

Create the false Boolean constant.
Z3_ast
The false constant

Z3_mk_eq

Create an equality expression (l = r).
Z3_ast
Equality expression
Example:

Z3_mk_distinct

Create an n-ary distinct predicate (all arguments are pairwise distinct).
Z3_ast
Distinct predicate

Z3_mk_not

Create a negation (not a).
Z3_ast
Negated expression

Z3_mk_and

Create an n-ary conjunction (and).
Z3_ast
Conjunction
Example:

Z3_mk_or

Create an n-ary disjunction (or).
Z3_ast
Disjunction

Z3_mk_implies

Create an implication (t1 implies t2).
Z3_ast
Implication

Z3_mk_ite

Create an if-then-else expression.
Z3_ast
If-then-else expression
Example:

Constants and Applications

Z3_mk_const

Create a constant (0-arity function application).
Z3_ast
Constant expression
Example:

Z3_mk_app

Create a function application.
Z3_ast
Function application

Numeral Creation

Z3_mk_int

Create a numeral of a given sort from an integer.
Z3_ast
Numeral expression
Example:

Z3_mk_unsigned_int

Create a numeral from an unsigned integer.
Z3_ast
Numeral expression

Z3_mk_int64

Create a numeral from a 64-bit integer.
Z3_ast
Numeral expression

Z3_mk_numeral

Create a numeral from a string representation.
Z3_ast
Numeral expression
Example:

AST Inspection

Z3_get_ast_kind

Return the kind of the given AST.
Z3_ast_kind
Kind of AST node

Z3_is_app

Return true if the given AST is an application.
bool
True if application, false otherwise

Z3_to_app

Convert an AST to an application.
Z3_app
Application

Z3_get_app_decl

Return the declaration of a function application.
Z3_func_decl
Function declaration

Z3_get_app_num_args

Return the number of arguments of a function application.
unsigned
Number of arguments

Z3_get_app_arg

Return the i-th argument of a function application.
Z3_ast
i-th argument

Complete Example