Python Other
Latest commit fad65c3 Nov 27, 2017 @mikand mikand Merge pull request #458 from pysmt/strings_theory
Strings Theory
Permalink
Failed to load latest commit information.
SMT-LIB SMTLIB Benchmark: Revised Util Aug 20, 2017
ci CI: Enable build with and without cython Aug 20, 2017
docs Docs: Clarified use of .serialize with example Nov 18, 2017
examples Examples: parallel.py avoid Strings Theory Nov 23, 2017
pysmt Merge pull request #458 from pysmt/strings_theory Nov 27, 2017
.coveragerc Coverage: Omit test/ directory Oct 16, 2016
.gitignore Imported pySMT version 0.2.1 Dec 1, 2014
.landscape.yaml Small, syntactic refactoring to improve overall code style and landsc… Jun 10, 2015
.travis.yml CI: Re-enable cache Nov 23, 2017
CONTRIBUTING Minor formatting Oct 13, 2016
CONTRIBUTORS Docs: Extend CONTRIBUTORS list May 23, 2017
LICENSE Imported pySMT version 0.2.1 Dec 1, 2014
MANIFEST.in Updated setup.py to create links to executables pysmt, pysmt-shell an… Mar 7, 2015
NOTICE Imported pySMT version 0.2.1 Dec 1, 2014
README.rst Fixed typo in README (too trivial for PR) Oct 30, 2017
appveyor.yml Z3: Upgrade to version 4.5.0 Aug 19, 2017
dev-requirements.txt CI: Adding Appveyor configuration May 24, 2015
health_check.sh Imported pySMT version 0.2.1 Dec 1, 2014
install.py Refactored solver installing architecture following #198. Nov 7, 2015
make_distrib.sh Dist: Updated version of six.py for pypi pkg. Apr 15, 2016
run_all_tests.sh Imported pySMT version 0.2.1 Dec 1, 2014
run_tests.sh BV: Enforcing positive values in BV Numbers. Apr 28, 2015
setup.py Change version to 0.6.1 Dec 2, 2016
shell.py Fixed binaries in pypi distribution (#48) Mar 15, 2015

README.rst

pySMT: a Python API for SMT

Build Status Coverage Documentation Status Latest PyPI version Apache License Google groups

pySMT makes working with Satisfiability Modulo Theory simple:

  • Define formulae in a simple, intuitive, and solver independent way
  • Solve your formulae using one of the native solvers, or by wrapping any SMT-Lib complaint solver,
  • Dump your problems in the SMT-Lib format,
  • and more...

PySMT Architecture Overview

Usage

>>> from pysmt.shortcuts import Symbol, And, Not, is_sat
>>>
>>> varA = Symbol("A") # Default type is Boolean
>>> varB = Symbol("B")
>>> f = And(varA, Not(varB))
>>> f
(A & (! B))
>>> is_sat(f)
True
>>> g = f.substitute({varB: varA})
>>> g
(A & (! A))
>>> is_sat(g)
False

A More Complex Example

Is there a value for each letter (between 1 and 9) so that H+E+L+L+O = W+O+R+L+D = 25?

from pysmt.shortcuts import Symbol, And, GE, LT, Plus, Equals, Int, get_model
from pysmt.typing import INT

hello = [Symbol(s, INT) for s in "hello"]
world = [Symbol(s, INT) for s in "world"]
letters = set(hello+world)
domains = And([And(GE(l, Int(1)),
                   LT(l, Int(10))) for l in letters])

sum_hello = Plus(hello) # n-ary operators can take lists
sum_world = Plus(world) # as arguments
problem = And(Equals(sum_hello, sum_world),
              Equals(sum_hello, Int(25)))
formula = And(domains, problem)

print("Serialization of the formula:")
print(formula)

model = get_model(formula)
if model:
  print(model)
else:
  print("No solution found")

Check out more examples in the examples/ directory and the documentation on ReadTheDocs

Supported Theories and Solvers

pySMT provides methods to define a formula in Linear Real Arithmetic (LRA), Real Difference Logic (RDL), Equalities and Uninterpreted Functions (EUF), Bit-Vectors (BV), Arrays (A) and their combinations. The following solvers are supported through native APIs:

Additionally, you can use any SMT-LIB 2 compliant solver.

PySMT assumes that the python bindings for the SMT Solver are installed and accessible from your PYTHONPATH.

pySMT works on both Python 3.5 and Python 2.7.

Installation

You can install the latest stable release of pySMT from PyPI:

# pip install pysmt

this will additionally install the pysmt-install command, that can be used to install the solvers: e.g.,

$ pysmt-install --check

will show you which solvers have been found in your PYTHONPATH. PySMT does not depend directly on any solver, but if you want to perform solving, you need to have at least one solver installed. This can be used by pySMT via its native API, or passing through an SMT-LIB file.

The script pysmt-install can be used to simplify the installation of the solvers:

$ pysmt-install --msat

will install MathSAT 5. Once the installation is complete, you can use the option --env to obtain a string to update your PYTHONPATH:

$ pysmt-install --env
export PYTHONPATH="/home/pysmt/.smt_solvers/python-bindings-2.7:${PYTHONPATH}"

By default the solvers are installed in your home directory in the folder .smt_solvers. pysmt-install has many options to customize its behavior.

Note: This script does not install required dependencies for building the solver (e.g., make or gcc) and has been tested mainly on Linux Debian/Ubuntu systems. We suggest that you refer to the documentation of each solver to understand how to install it with its python bindings.

For Yices, picosat, and CUDD, we use external wrappers:

For instruction on how to use any SMT-LIB complaint solver with pySMT see examples/generic_smtlib.py

For more information, refer to online documentation on ReadTheDocs

Solvers Support

The following table summarizes the features supported via pySMT for each of the available solvers.

Solver pySMT name Supported Theories Quantifiers
MathSAT msat UF, LIA, LRA, BV, AX No
Z3 z3 UF, LIA, LRA, BV, AX, NRA, NIA Yes
CVC4 cvc4 UF, LIA, LRA, BV, AX Yes
Yices yices UF, LIA, LRA, BV No
SMT-Lib Interface <custom> UF, LIA, LRA, BV, AX Yes
PicoSAT picosat [None] No
Boolector btor UF, BV, AX No
BDD (CUDD) bdd [None] Yes

The following table summarizes the features supported via pySMT for each of the available quantifier eliminators

Quantifier Eliminator pySMT name Supported Logics
MathSAT FM msat-fm LRA
MathSAT LW msat-lw LRA, LIA
Z3 z3 LRA, LIA
BDD (CUDD) bdd BOOL

Unsat-Core extraction is currently supported on: MathSAT and Z3.

The following table summarizes the features supported via pySMT for each of the available Craig interpolators

Interpolator pySMT name Supported Logics
MathSAT msat QF_UFLIA, QF_UFLRA, QF_BV
Z3 z3 QF_UFLIA, QF_UFLRA

License

pySMT is released under the APACHE 2.0 License.

For further questions, feel free to open an issue, or write to pysmt@googlegroups.com (Browse the Archive).