A lightweight Julia interface to SMT solvers via SMT-LIB2, designed for verification, synthesis, and symbolic automation.
SMTLib.jl is a Julia package that generates and consumes SMT-LIB2, the standard language for communicating with SMT solvers such as Z3, CVC5, Yices, and MathSAT. It gives you a clean Julia API for building constraints, checking satisfiability, and parsing models — with support for quantifiers, optimization, theory helpers, unsat cores, and more.
-
Solver auto-detection — discover installed solvers on PATH
-
SMT-LIB2 generation — emit solver-ready programs from Julia expressions
-
Model parsing — pull structured model values back into Julia
-
Incremental solving — push/pop contexts for interactive workflows
-
Quantifiers —
forallandexistsfor first-order reasoning -
Optimization —
minimize!,maximize!,optimize(Z3 via νZ) -
Theory helpers — bitvectors, floating-point sorts, arrays, regex sorts
-
Named assertions & unsat cores —
get_unsat_corefor debugging UNSAT results -
Statistics —
get_statisticsfor solver performance introspection -
Model evaluation —
evaluateexpressions against a solved model -
Convenience macro —
@smtfor concise constraint specification -
Solver options —
set_option!for fine-grained solver configuration -
Timeouts — control solver budgets deterministically
-
Zero dependencies — pure Julia
using SMTLib
ctx = SMTContext(logic=:QF_LIA)
declare(ctx, :x, Int)
declare(ctx, :y, Int)
assert!(ctx, :(x + y == 10))
assert!(ctx, :(x > 0))
assert!(ctx, :(y > 0))
result = check_sat(ctx)
@show result.status
@show result.model| Type | Description |
|---|---|
|
Solver descriptor (name, path, capabilities) |
|
Result of |
|
Solver session holding declarations, assertions, and options |
| Function | Description |
|---|---|
|
Declare a constant or function |
|
Add a constraint to the context |
|
Check satisfiability, return |
|
Retrieve model after SAT result |
|
Clear all declarations and assertions |
| Function | Description |
|---|---|
|
Push a new assertion scope |
|
Pop the most recent assertion scope |
| Function | Description |
|---|---|
|
Find a specific solver on PATH |
|
List all detected solvers |
|
Set solver option (e.g. |
| Function | Description |
|---|---|
|
Convert Julia expression to SMT-LIB2 string |
|
Parse SMT-LIB2 string into Julia structure |
| Function | Description |
|---|---|
|
Universal quantification |
|
Existential quantification |
| Function | Description |
|---|---|
|
Add minimization objective |
|
Add maximization objective |
|
Solve with optimization objectives |
| Function | Description |
|---|---|
|
Bitvector literal |
|
Floating-point sort constructor |
|
Array sort constructor |
|
Regular expression sort constructor |
| Function | Description |
|---|---|
|
Solver performance statistics |
|
Evaluate expression in a model |
|
Extract unsat core from UNSAT result |
ctx = SMTContext(logic=:LIA)
declare(ctx, :f, Int => Int)
# For all x, f(x) > x
assert!(ctx, forall([:x => Int], :(f(x) > x)))
result = check_sat(ctx)ctx = SMTContext(logic=:QF_LIA)
declare(ctx, :x, Int)
declare(ctx, :y, Int)
assert!(ctx, :(x + y >= 10))
assert!(ctx, :(x >= 0))
assert!(ctx, :(y >= 0))
minimize!(ctx, :(x + y))
result = optimize(ctx)
@show result.model # x=10, y=0 or x=0, y=10Standard Julia package structure:
SMTLib.jl/ ├── src/ # Core library ├── test/ # Unit tests (468 assertions) ├── Project.toml # Package metadata └── README.adoc # This file
SMTLib.jl is used by Axiom.jl for solver interaction and verification workflows. This repo keeps the SMT interface modular and independently reusable.
Stable, used across the Hyperpolymath verification stack. 468 test assertions covering solver discovery, SMT-LIB generation, parsing, quantifiers, optimization, theory helpers, unsat cores, and integration tests.
-
Barrett, C. & Tinelli, C. "Satisfiability Modulo Theories." In Handbook of Model Checking, Springer, 2018, pp. 305-343. — Comprehensive handbook chapter on SMT.
-
Kroening, D. & Strichman, O. Decision Procedures: An Algorithmic Point of View. 2nd ed., Springer, 2016. — Comprehensive text on decision procedures underlying SMT.
-
Bradley, A.R. & Manna, Z. The Calculus of Computation: Decision Procedures with Applications to Verification. Springer, 2007. — Verification foundations and decision procedures.
-
Biere, A., Heule, M., van Maaren, H., & Walsh, T. (eds.) Handbook of Satisfiability. 2nd ed., IOS Press, 2021. — Comprehensive reference for SAT/SMT.
-
de Moura, L. & Bjørner, N. "Z3: An Efficient SMT Solver." In TACAS 2008, LNCS 4963, Springer, 2008, pp. 337-340. — Z3 solver.
-
Barrett, C., Stump, A., & Tinelli, C. "The SMT-LIB Standard: Version 2.6." Technical report, 2017. — The SMT-LIB2 language standard.
-
Bjørner, N., Phan, A.-D., & Fleckenstein, L. "νZ — An Optimizing SMT Solver." In TACAS 2015, LNCS 9035, Springer, 2015, pp. 194-199. — Z3 optimization extensions.
-
Barbosa, H. et al. "cvc5: A Versatile and Industrial-Strength SMT Solver." In TACAS 2022, LNCS 13243, Springer, 2022, pp. 415-442. — CVC5 solver.
Palimpsest-MPL License v1.0 (PMPL-1.0-or-later) — see LICENSE.