PySMT is a Python library designed for solver-agnostic manipulation and solving of Satisfiability Modulo Theories (SMT) formulae. It provides a unified API to define, manipulate, and solve SMT problems using various SMT-LIB compliant solvers. The library is actively maintained, with regular releases, and its current stable version is 0.9.6.
pip install pysmtVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates defining Boolean SMT variables, constructing a logical formula, checking its satisfiability using a shortcut, performing variable substitution, and using an explicit solver to extract a model.
Upgrade to Python 3.5+ (recommended) or higher. For Python 2.7, use PySMT <0.9.0.
Import specific textual operators from `pysmt.shortcuts` (e.g., `from pysmt.shortcuts import And, Or, Not`) and use them directly for better code readability and to avoid unexpected operator precedence issues.
Run `python -m pysmt install --<solver-name>` (e.g., `python -m pysmt install --z3`) to install a solver. If issues persist, check `pysmt-install --check` and ensure your `PYTHONPATH` includes the solver bindings directory, especially for non-standard installations.
Update imports and references to use `pysmt.constants.Fraction` (or `Integer`, `Numerals`) instead of previous locations like `pysmt.numeral` or `pysmt.utils`.
Remove calls to `Solver.declare_variable` as variables are typically declared via `Symbol()` and added to the solver with `add_assertion()`. For solver options, consult the documentation for solver-specific configuration or use the `Solver` constructor's `options` argument if available.
Install a solver using `python -m pysmt install --<solver-name>` (e.g., `python -m pysmt install --z3`). Verify installation with `pysmt-install --check`. If the solver was installed manually or in a non-standard location, ensure its Python bindings directory is added to your `PYTHONPATH`.
Ensure all operands in SMT expressions are `FNode` objects. For Python boolean literals, use `Bool(True)` or `Bool(False)` from `pysmt.shortcuts`. Better yet, use explicit logical operators like `And()`, `Or()`, `Not()` to avoid ambiguity and improve clarity.
After running `python -m pysmt install`, check the output for the location of the installed bindings. If they are not in a standard `site-packages` directory, you might need to manually add the path to your `PYTHONPATH` environment variable. For example, `export PYTHONPATH=$HOME/.smt_solvers/python_bindings:$PYTHONPATH`.