Int) and real (Real) numbers, providing a comprehensive set of operations for linear and non-linear arithmetic reasoning.
Sorts
Integer Sort
Create the integer sort:Z3_mk_int_sort (api_arith.cpp:33)
Real Sort
Create the real (rational) sort:Z3_mk_real_sort (api_arith.cpp:42)
Numeric Literals
Integer Literals
Rational Literals
Create rational numbers:Z3_mk_real creates rationals with numerator and denominator (api_arith.cpp:65)
Arithmetic Operations
Addition
Z3_mk_add (api_arith.cpp:79)
Subtraction
Z3_mk_sub handles multiple arguments (api_arith.cpp:131)
Multiplication
Z3_mk_mul (api_arith.cpp:80)
Division
Z3 distinguishes between integer and real division:Z3_mk_div automatically selects OP_DIV for reals or OP_IDIV for integers (api_arith.cpp:85)
Modulo and Remainder
Z3_mk_mod- modulo operation (api_arith.cpp:82)Z3_mk_rem- remainder operation (api_arith.cpp:83)
Power
Z3_mk_power (api_arith.cpp:81)
Unary Minus
Z3_mk_unary_minus (api_arith.cpp:150)
Absolute Value
Z3_mk_abs (api_arith.cpp:126)
Comparison Predicates
Less Than / Less Than or Equal
Z3_mk_lt(api_arith.cpp:103)Z3_mk_le(api_arith.cpp:105)
Greater Than / Greater Than or Equal
Z3_mk_gt(api_arith.cpp:104)Z3_mk_ge(api_arith.cpp:106)
Type Conversion
Integer to Real
Z3_mk_int2real (api_arith.cpp:127)
Real to Integer
Z3_mk_real2int (api_arith.cpp:128)
Is Integer
Test if a real value is an integer:Z3_mk_is_int (api_arith.cpp:129)
Advanced Features
Divisibility Constraint
Express that one integer divides another:Z3_mk_divides(c, n, arg) - creates constraint that constant n divides arg (api_arith.cpp:108)
Algebraic Numbers
Z3 supports irrational algebraic numbers (roots of polynomials):Z3_is_algebraic_number- check if expression is algebraicZ3_get_algebraic_number_lower- get lower bound approximationZ3_get_algebraic_number_upper- get upper bound approximation
Rational Number Components
Extract numerator and denominator from rationals:Z3_get_numerator(api_arith.cpp:206)Z3_get_denominator(api_arith.cpp:222)
Complete Example
Implementation Notes
- Linear arithmetic uses efficient simplex-based decision procedures
- Non-linear arithmetic uses cylindrical algebraic decomposition (CAD) and other techniques
- Mixed integer-real problems are supported
- The theory handles both decidable fragments (linear) and semi-decidable fragments (non-linear)
References
- Implementation:
src/api/api_arith.cpp - Theory plugin:
src/ast/arith_decl_plugin.h - Solver:
src/smt/theory_arith.h
