Skip to main content
The arithmetic theory in Z3 supports both integer (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:
C API: Z3_mk_int_sort (api_arith.cpp:33)

Real Sort

Create the real (rational) sort:
C API: Z3_mk_real_sort (api_arith.cpp:42)

Numeric Literals

Integer Literals

Rational Literals

Create rational numbers:
C API: Z3_mk_real creates rationals with numerator and denominator (api_arith.cpp:65)

Arithmetic Operations

Addition

C API: Z3_mk_add (api_arith.cpp:79)

Subtraction

C API: Z3_mk_sub handles multiple arguments (api_arith.cpp:131)

Multiplication

C API: Z3_mk_mul (api_arith.cpp:80)

Division

Z3 distinguishes between integer and real division:
C API: Z3_mk_div automatically selects OP_DIV for reals or OP_IDIV for integers (api_arith.cpp:85)

Modulo and Remainder

C API:
  • Z3_mk_mod - modulo operation (api_arith.cpp:82)
  • Z3_mk_rem - remainder operation (api_arith.cpp:83)

Power

C API: Z3_mk_power (api_arith.cpp:81)

Unary Minus

C API: Z3_mk_unary_minus (api_arith.cpp:150)

Absolute Value

C API: Z3_mk_abs (api_arith.cpp:126)

Comparison Predicates

Less Than / Less Than or Equal

C API:
  • Z3_mk_lt (api_arith.cpp:103)
  • Z3_mk_le (api_arith.cpp:105)

Greater Than / Greater Than or Equal

C API:
  • Z3_mk_gt (api_arith.cpp:104)
  • Z3_mk_ge (api_arith.cpp:106)

Type Conversion

Integer to Real

C API: Z3_mk_int2real (api_arith.cpp:127)

Real to Integer

C API: Z3_mk_real2int (api_arith.cpp:128)

Is Integer

Test if a real value is an integer:
C API: Z3_mk_is_int (api_arith.cpp:129)

Advanced Features

Divisibility Constraint

Express that one integer divides another:
C API: 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):
C API Functions (api_arith.cpp:158-204):
  • Z3_is_algebraic_number - check if expression is algebraic
  • Z3_get_algebraic_number_lower - get lower bound approximation
  • Z3_get_algebraic_number_upper - get upper bound approximation

Rational Number Components

Extract numerator and denominator from rationals:
C API:
  • 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