Skip to main content
The Z3 Go bindings provide a comprehensive interface to Z3’s C API through CGO. This reference documents all major types and operations.

Package Import

All operations are accessed through the z3 package.

Core Types

Context

The context manages all Z3 objects and operations.
function
Creates a new Z3 context with default configuration.Example:
function
Creates a context with custom configuration.Example:
method
Sets a global parameter.Common parameters:
  • timeout: Timeout in milliseconds
  • proof: Enable proof generation (true/false)
  • model: Enable model generation (true/false)

Config

Configuration object for context creation.

Expr

Represents Z3 expressions (formulas, terms, variables). Methods:
  • String() string - Get string representation
  • Sort() *Sort - Get the sort (type) of this expression
  • IsConst() bool - Check if expression is a constant
  • IsApp() bool - Check if expression is a function application

Sort

Represents Z3 sorts (types). Methods:
  • String() string - Get string representation
  • Kind() SortKind - Get the kind of sort

Creating Variables and Constants

Boolean

method
Creates a Boolean variable.
method
Creates the true Boolean constant.
method
Creates the false Boolean constant.

Integer and Real

method
Creates an integer variable.
method
Creates a real variable.
method
Creates an integer constant.Example:
method
Creates a rational constant (num/den).Example:

Bit-Vectors

method
Creates a bit-vector variable.Example:
method
Creates a bit-vector constant.Example:

Boolean Operations

method
Logical AND. Accepts multiple arguments.Example:
method
Logical OR.
method
Logical NOT.
method
Logical implication (lhs → rhs).
method
If-and-only-if (lhs ↔ rhs).
method
Exclusive OR.
method
All arguments are pairwise distinct.

Arithmetic Operations

method
Addition. Supports multiple arguments.
method
Subtraction.
method
Multiplication.
method
Division. Integer division for Int, real division for Real.
method
Modulo (integer only).
method
Remainder (integer only).
method
Exponentiation.

Comparison Operations

method
Equality.
method
Less than.
method
Less than or equal.
method
Greater than.
method
Greater than or equal.

Bit-Vector Operations

Arithmetic

  • MkBVAdd(lhs, rhs *Expr) *Expr - Addition
  • MkBVSub(lhs, rhs *Expr) *Expr - Subtraction
  • MkBVMul(lhs, rhs *Expr) *Expr - Multiplication
  • MkBVUDiv(lhs, rhs *Expr) *Expr - Unsigned division
  • MkBVSDiv(lhs, rhs *Expr) *Expr - Signed division
  • MkBVURem(lhs, rhs *Expr) *Expr - Unsigned remainder
  • MkBVSRem(lhs, rhs *Expr) *Expr - Signed remainder
  • MkBVSMod(lhs, rhs *Expr) *Expr - Signed modulo
  • MkBVNeg(expr *Expr) *Expr - Negation

Bitwise

  • MkBVAnd(lhs, rhs *Expr) *Expr - Bitwise AND
  • MkBVOr(lhs, rhs *Expr) *Expr - Bitwise OR
  • MkBVXor(lhs, rhs *Expr) *Expr - Bitwise XOR
  • MkBVNot(expr *Expr) *Expr - Bitwise NOT
  • MkBVNand(lhs, rhs *Expr) *Expr - Bitwise NAND
  • MkBVNor(lhs, rhs *Expr) *Expr - Bitwise NOR
  • MkBVXnor(lhs, rhs *Expr) *Expr - Bitwise XNOR

Shifts and Rotations

  • MkBVShl(lhs, rhs *Expr) *Expr - Shift left
  • MkBVLShr(lhs, rhs *Expr) *Expr - Logical shift right
  • MkBVAShr(lhs, rhs *Expr) *Expr - Arithmetic shift right
  • MkBVRotateLeft(expr *Expr, i uint) *Expr - Rotate left
  • MkBVRotateRight(expr *Expr, i uint) *Expr - Rotate right

Comparisons

  • MkBVULT(lhs, rhs *Expr) *Expr - Unsigned less than
  • MkBVSLT(lhs, rhs *Expr) *Expr - Signed less than
  • MkBVULE(lhs, rhs *Expr) *Expr - Unsigned less or equal
  • MkBVSLE(lhs, rhs *Expr) *Expr - Signed less or equal
  • MkBVUGE(lhs, rhs *Expr) *Expr - Unsigned greater or equal
  • MkBVSGE(lhs, rhs *Expr) *Expr - Signed greater or equal
  • MkBVUGT(lhs, rhs *Expr) *Expr - Unsigned greater than
  • MkBVSGT(lhs, rhs *Expr) *Expr - Signed greater than

Extraction and Extension

  • MkConcat(lhs, rhs *Expr) *Expr - Concatenate bit-vectors
  • MkExtract(high, low uint, expr *Expr) *Expr - Extract bits [high:low]
  • MkSignExt(i uint, expr *Expr) *Expr - Sign extension
  • MkZeroExt(i uint, expr *Expr) *Expr - Zero extension
  • MkRepeat(i uint, expr *Expr) *Expr - Repeat bit-vector

Floating-Point Operations

Sorts

  • MkFPSort(ebits, sbits uint) *Sort - Custom FP sort (ebits exponent, sbits significand)
  • MkFPSort16() *Sort - IEEE 754 half precision (16-bit)
  • MkFPSort32() *Sort - IEEE 754 single precision (32-bit)
  • MkFPSort64() *Sort - IEEE 754 double precision (64-bit)
  • MkFPSort128() *Sort - IEEE 754 quadruple precision (128-bit)
  • MkFPRoundingModeSort() *Sort - Rounding mode sort

Special Values

  • MkFPInf(sort *Sort, negative bool) *Expr - Infinity
  • MkFPNaN(sort *Sort) *Expr - Not-a-Number
  • MkFPZero(sort *Sort, negative bool) *Expr - Zero (+0.0 or -0.0)

Arithmetic

  • MkFPAdd(rm, lhs, rhs *Expr) *Expr - Addition with rounding mode
  • MkFPSub(rm, lhs, rhs *Expr) *Expr - Subtraction
  • MkFPMul(rm, lhs, rhs *Expr) *Expr - Multiplication
  • MkFPDiv(rm, lhs, rhs *Expr) *Expr - Division
  • MkFPFMA(rm, x, y, z *Expr) *Expr - Fused multiply-add: x*y+z
  • MkFPSqrt(rm, expr *Expr) *Expr - Square root
  • MkFPRem(lhs, rhs *Expr) *Expr - Remainder
  • MkFPAbs(expr *Expr) *Expr - Absolute value
  • MkFPNeg(expr *Expr) *Expr - Negation

Comparisons

  • MkFPLT(lhs, rhs *Expr) *Expr - Less than
  • MkFPGT(lhs, rhs *Expr) *Expr - Greater than
  • MkFPLE(lhs, rhs *Expr) *Expr - Less or equal
  • MkFPGE(lhs, rhs *Expr) *Expr - Greater or equal
  • MkFPEq(lhs, rhs *Expr) *Expr - Equality

Predicates

  • MkFPIsNaN(expr *Expr) *Expr - Is NaN
  • MkFPIsInf(expr *Expr) *Expr - Is infinite
  • MkFPIsZero(expr *Expr) *Expr - Is zero
  • MkFPIsNormal(expr *Expr) *Expr - Is normal
  • MkFPIsSubnormal(expr *Expr) *Expr - Is subnormal
  • MkFPIsNegative(expr *Expr) *Expr - Is negative
  • MkFPIsPositive(expr *Expr) *Expr - Is positive

String/Sequence Operations

Creation

  • MkStringSort() *Sort - String sort
  • MkSeqSort(elemSort *Sort) *Sort - Sequence sort
  • MkString(value string) *Expr - String constant
  • MkEmptySeq(sort *Sort) *Expr - Empty sequence

Operations

  • MkSeqConcat(exprs ...*Expr) *Expr - Concatenation
  • MkSeqLength(seq *Expr) *Expr - Length
  • MkSeqAt(seq, index *Expr) *Expr - Character at index
  • MkSeqExtract(seq, offset, length *Expr) *Expr - Substring
  • MkSeqPrefix(prefix, seq *Expr) *Expr - Prefix predicate
  • MkSeqSuffix(suffix, seq *Expr) *Expr - Suffix predicate
  • MkSeqContains(container, contained *Expr) *Expr - Contains predicate
  • MkSeqIndexOf(seq, substr, offset *Expr) *Expr - Index of substring
  • MkSeqReplace(seq, src, dst *Expr) *Expr - Replace substring
  • MkStrToInt(str *Expr) *Expr - String to integer
  • MkIntToStr(i *Expr) *Expr - Integer to string

Array Operations

  • MkArraySort(domain, range *Sort) *Sort - Create array sort
  • MkSelect(array, index *Expr) *Expr - Read: array[index]
  • MkStore(array, index, value *Expr) *Expr - Write: array[index := value]
  • MkConstArray(domain *Sort, value *Expr) *Expr - Constant array
  • MkArrayDefault(array *Expr) *Expr - Default value

Datatypes

Lists

Creates a list datatype with constructors and accessors.

Tuples

Enumerations

Solver

Creation

method
Creates a new general-purpose solver.
method
Creates a solver for a specific logic (e.g., “QF_LIA”, “QF_BV”).

Adding Constraints

method
Adds a constraint to the solver.
method
Adds a constraint with a tracker for unsat core.

Checking Satisfiability

method
Checks satisfiability. Returns:
  • z3.Satisfiable (LTrue)
  • z3.Unsatisfiable (LFalse)
  • z3.Unknown (LUndef)
method
Checks satisfiability under assumptions.

Backtracking

method
Creates a backtracking point.
method
Backtracks n levels.
method
Removes all assertions.

Results

method
Returns the model if result was satisfiable.
method
Returns the unsat core (requires tracked assertions).
method
Returns the proof (if proof generation enabled).
method
Returns solver statistics.

Model

method
Evaluates expression in model. Returns (value, ok).Parameters:
  • expr: Expression to evaluate
  • modelCompletion: Assign default values to unbound variables
method
Number of constant interpretations.
method
Number of function interpretations.
method
Get i-th constant declaration.
method
Get constant interpretation.

Optimize

Solver for optimization problems.
Methods:
  • Assert(constraint *Expr) - Add hard constraint
  • AssertSoft(constraint *Expr, weight, group string) - Add soft constraint
  • Maximize(expr *Expr) uint - Add maximization objective
  • Minimize(expr *Expr) uint - Add minimization objective
  • Check(assumptions ...*Expr) LBool - Check and optimize
  • Model() *Model - Get optimal model
  • GetLower/Upper(index uint) *Expr - Get objective bounds
  • Push/Pop() - Backtracking

Tactics

Tactics provide goal-based solving.
Common tactics:
  • "simplify" - Simplification
  • "solve-eqs" - Solve equations
  • "qe" - Quantifier elimination
  • "sat" - SAT solver
  • "smt" - SMT solver
  • "qfnra" - Nonlinear real arithmetic
Combinators:
  • AndThen(t1, t2 *Tactic, tactics ...*Tactic) *Tactic - Sequential
  • OrElse(t1, t2 *Tactic) *Tactic - Try first, fallback
  • Repeat(t *Tactic, max uint) *Tactic - Repeat tactic

Constants and Enums

LBool

Satisfiability result:
Convenience constants:

Further Reading

Getting Started

Practical examples and tutorials

C API Reference

Underlying C API documentation

Z3 Guide

Comprehensive Z3 guide

GitHub Source

Go bindings source code