Skip to content
Browse files

Imported pySMT version 0.2.1

  • Loading branch information
marcogario committed Dec 1, 2014
0 parents commit 0a99a78c30d162736a41a1fa4feac9e1eab564a0
Showing with 18,397 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +202 −0 LICENSE
  3. +3 −0
  4. +13 −0 NOTICE
  5. +108 −0 README.txt
  6. +54 −0 SMT-LIB/
  7. +77 −0 SMT-LIB/
  8. +5 −0 SMT-LIB/
  9. +37 −0 SMT-LIB/smtlib.urls
  10. +55 −0 docs/CHANGES.rst
  11. +177 −0 docs/Makefile
  12. +17 −0 docs/api_ref.rst
  13. +29 −0 docs/code_snippets/
  14. +27 −0 docs/code_snippets/
  15. +7 −0 docs/code_snippets/
  16. +269 −0 docs/
  17. +44 −0 docs/development.rst
  18. +96 −0 docs/getting_started.rst
  19. +26 −0 docs/index.rst
  20. +19 −0 docs/intro.rst
  21. +24 −0
  22. +6 −0
  23. +5 −0
  24. +12 −0 patches/cvc4_wrapper.patch
  25. +13 −0 patches/z3.py_patch
  26. +17 −0 pysmt/
  27. +137 −0 pysmt/
  28. +75 −0 pysmt/
  29. +106 −0 pysmt/
  30. +55 −0 pysmt/
  31. +269 −0 pysmt/
  32. +309 −0 pysmt/
  33. +535 −0 pysmt/
  34. +557 −0 pysmt/
  35. +45 −0 pysmt/
  36. +291 −0 pysmt/
  37. +290 −0 pysmt/
  38. +287 −0 pysmt/
  39. +393 −0 pysmt/
  40. +17 −0 pysmt/smtlib/
  41. +49 −0 pysmt/smtlib/
  42. +783 −0 pysmt/smtlib/
  43. +257 −0 pysmt/smtlib/
  44. +260 −0 pysmt/smtlib/
  45. +112 −0 pysmt/smtlib/
  46. +17 −0 pysmt/solvers/
  47. +302 −0 pysmt/solvers/
  48. +62 −0 pysmt/solvers/
  49. +517 −0 pysmt/solvers/
  50. +31 −0 pysmt/solvers/
  51. +328 −0 pysmt/solvers/
  52. +274 −0 pysmt/solvers/
  53. +362 −0 pysmt/solvers/
  54. +419 −0 pysmt/solvers/
  55. +227 −0 pysmt/
  56. +61 −0 pysmt/test/
  57. +12 −0 pysmt/test/configs/config1.ini
  58. +5 −0 pysmt/test/configs/config_bad.ini
  59. +313 −0 pysmt/test/
  60. +34 −0 pysmt/test/
  61. +17 −0 pysmt/test/smtlib/
  62. +2 −0 pysmt/test/smtlib/bin/README
  63. +5 −0 pysmt/test/smtlib/bin/
  64. +4 −0 pysmt/test/smtlib/bin/
  65. +5 −0 pysmt/test/smtlib/bin/
  66. +104 −0 pysmt/test/smtlib/
  67. +41 −0 pysmt/test/smtlib/small_set/LRA/intersection-example-simple.proof-node394346.smt2
  68. +42 −0 pysmt/test/smtlib/small_set/LRA/intersection-example-simple.proof-node679466.smt2
  69. +27 −0 pysmt/test/smtlib/small_set/LRA/water_tank-node21140.smt2
  70. +27 −0 pysmt/test/smtlib/small_set/LRA/water_tank-node22228.smt2
  71. +27 −0 pysmt/test/smtlib/small_set/LRA/water_tank-node24658.smt2
  72. +27 −0 pysmt/test/smtlib/small_set/LRA/water_tank-node9350.smt2
  73. +45 −0 pysmt/test/smtlib/small_set/QF_LIA/prp-20-46.smt2
  74. +45 −0 pysmt/test/smtlib/small_set/QF_LIA/prp-21-46.smt2
  75. +45 −0 pysmt/test/smtlib/small_set/QF_LIA/prp-22-46.smt2
  76. +45 −0 pysmt/test/smtlib/small_set/QF_LIA/prp-23-46.smt2
  77. +46 −0 pysmt/test/smtlib/small_set/QF_LIA/prp-23-47.smt2
  78. +45 −0 pysmt/test/smtlib/small_set/QF_LIA/prp-24-46.smt2
  79. +46 −0 pysmt/test/smtlib/small_set/QF_LIA/prp-24-47.smt2
  80. +47 −0 pysmt/test/smtlib/small_set/QF_LIA/prp-24-48.smt2
  81. +45 −0 pysmt/test/smtlib/small_set/QF_LIA/prp-25-46.smt2
  82. +46 −0 pysmt/test/smtlib/small_set/QF_LIA/prp-25-47.smt2
  83. +47 −0 pysmt/test/smtlib/small_set/QF_LIA/prp-25-48.smt2
  84. +48 −0 pysmt/test/smtlib/small_set/QF_LIA/prp-25-49.smt2
  85. +17 −0 pysmt/test/smtlib/small_set/QF_LIRA/lira1.smt2
  86. +41 −0 pysmt/test/smtlib/small_set/QF_LIRA/prp-20-46.smt2
  87. +146 −0 pysmt/test/smtlib/small_set/QF_LRA/simple_startup_11nodes.abstract.base.smt2
  88. +157 −0 pysmt/test/smtlib/small_set/QF_LRA/simple_startup_12nodes.synchro.base.smt2
  89. +179 −0 pysmt/test/smtlib/small_set/QF_LRA/simple_startup_14nodes.abstract.base.smt2
  90. +182 −0 pysmt/test/smtlib/small_set/QF_LRA/simple_startup_14nodes.synchro.induct.smt2
  91. +190 −0 pysmt/test/smtlib/small_set/QF_LRA/simple_startup_15nodes.abstract.base.smt2
  92. +73 −0 pysmt/test/smtlib/small_set/QF_LRA/simple_startup_3nodes.bug.induct.smt2
  93. +69 −0 pysmt/test/smtlib/small_set/QF_LRA/simple_startup_4nodes.synchro.base.smt2
  94. +128 −0 pysmt/test/smtlib/small_set/QF_LRA/simple_startup_8nodes.missing.induct.smt2
  95. +113 −0 pysmt/test/smtlib/small_set/QF_LRA/simple_startup_8nodes.synchro.base.smt2
  96. +116 −0 pysmt/test/smtlib/small_set/QF_LRA/simple_startup_8nodes.synchro.induct.smt2
  97. +124 −0 pysmt/test/smtlib/small_set/QF_LRA/simple_startup_9nodes.abstract.base.smt2
  98. +203 −0 pysmt/test/smtlib/small_set/QF_LRA/uart-10.induction.cvc.smt2
  99. +220 −0 pysmt/test/smtlib/small_set/QF_LRA/uart-11.induction.cvc.smt2
  100. +271 −0 pysmt/test/smtlib/small_set/QF_LRA/uart-14.induction.cvc.smt2
  101. +305 −0 pysmt/test/smtlib/small_set/QF_LRA/uart-16.induction.cvc.smt2
  102. +339 −0 pysmt/test/smtlib/small_set/QF_LRA/uart-18.induction.cvc.smt2
  103. +475 −0 pysmt/test/smtlib/small_set/QF_LRA/uart-26.induction.cvc.smt2
  104. +135 −0 pysmt/test/smtlib/small_set/QF_LRA/uart-6.induction.cvc.smt2
  105. +169 −0 pysmt/test/smtlib/small_set/QF_LRA/uart-8.induction.cvc.smt2
  106. +39 −0 pysmt/test/smtlib/small_set/negative/wrong1.smt2
  107. +131 −0 pysmt/test/smtlib/
  108. +55 −0 pysmt/test/smtlib/
  109. +26 −0 pysmt/test/smtlib/
  110. +26 −0 pysmt/test/smtlib/
  111. +26 −0 pysmt/test/smtlib/
  112. +26 −0 pysmt/test/smtlib/
  113. +36 −0 pysmt/test/smtlib/
  114. +132 −0 pysmt/test/smtlib/
  115. +108 −0 pysmt/test/
  116. +80 −0 pysmt/test/
  117. +116 −0 pysmt/test/
  118. +76 −0 pysmt/test/
  119. +649 −0 pysmt/test/
  120. +53 −0 pysmt/test/
  121. +66 −0 pysmt/test/
  122. +135 −0 pysmt/test/
  123. +51 −0 pysmt/test/
  124. +89 −0 pysmt/test/
  125. +171 −0 pysmt/test/
  126. +131 −0 pysmt/test/
  127. +120 −0 pysmt/test/
  128. +133 −0 pysmt/test/
  129. +304 −0 pysmt/test/
  130. +116 −0 pysmt/test/
  131. +200 −0 pysmt/test/
  132. +186 −0 pysmt/test/
  133. +217 −0 pysmt/
  134. +140 −0 pysmt/
  135. +17 −0 pysmt/utils/
  136. +358 −0 pysmt/utils/
  137. +38 −0 pysmt/walkers/
  138. +174 −0 pysmt/walkers/
  139. +134 −0 pysmt/walkers/
  140. +102 −0 pysmt/walkers/
  141. +62 −0 pysmt/walkers/
  142. +28 −0
  143. +29 −0
  144. +16 −0
  145. +136 −0
@@ -0,0 +1,2 @@
@@ -0,0 +1,202 @@

Apache License
Version 2.0, January 2004


1. Definitions.

"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.

"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.

"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.

"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.

"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.

"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.

"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).

"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.

"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."

"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.

2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.

3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.

4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:

(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and

(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and

(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and

(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.

You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.

5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.

6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.

7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
implied, including, without limitation, any warranties or conditions
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.

8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.

9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.


APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
@@ -0,0 +1,3 @@
include LICENSE.txt, README.txt
recursive-include docs *.txt
@@ -0,0 +1,13 @@
Copyright 2014 Andrea Micheli and Marco Gario

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
@@ -0,0 +1,108 @@
pySMT: A library for SMT formulae manipulation and solving

pySMT makes working with Satisfiability Modulo Theory simple.

Among others, you can:
* Define formulae in a solver independent way in a simple and
inutitive way,
* Write ad-hoc simplifiers and operators,
* Dump your problems in the SMT-Lib format,
* Solve them using one of the native solvers, or by wrapping any
SMT-Lib complaint solver.


* Python ( >= 2.6
* MathSAT ( >= 5 (Optional)
* Z3 ( >= 4 (Optional)
* CVC4 ( (Optional)
* Yices 2 ( (Optional)

The library assumes that the python binding for the SMT Solver are installed
and accessible from your PYTHONPATH.
For Yices 2 we rely on pyices (

The current version supports MathSAT 5, Z3 4 CVC4 and Yices 2.

Supported Theories

pySMT provides methods to define a formula in Linear Real Arithmetic
(LRA), Real Difference Logic (RDL), their combination (LIRA) and
Equalities and Uninterpreted Functions (EUF).


from pysmt.shortcuts import Symbol, And, Not, FALSE, Solver

with Solver() as solver:

varA = Symbol("A") # Default type is Boolean
varB = Symbol("B")

f = And([varA, Not(varB)])


g = f.substitute({varB:varA})


res = solver.solve()
assert not res

h = And(g, FALSE())
simp_h = h.simplify()
print(h, "-->", simp_h)

A more complex example is the following:

Lets consider the letters composing the words *HELLO* and *WORLD*,
with a possible integer value between 1 and 10 to each of them.

Is there a value for each letter so that H+E+L+L+O = W+O+R+L+D = 36?

The following is the pySMT code for solving this problem:
from pysmt.shortcuts import Symbol, LE, GE, Int, And, Equals, Plus, Solver
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( LE(Int(1), l),
GE(Int(10), l) ) 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:")

# Use context to create and free a solver. Solver are selected by name
# and can be used in a uniform way (try name="msat")
with Solver(name="z3") as solver:
if solver.solve():
for l in letters:
print("%s = %s" %(l, solver.get_value(l)))
print("No solution found")
@@ -0,0 +1,54 @@
# Downloads and Extracts the specified SMTLIB benchmark

import urllib
import zipfile
import os.path
import sys

class BenchmarkNotFoundError(Exception):

def load_data(filename):
with open(filename, "r") as fin:
raw_data = fin.readlines()
return (line.split() for line in raw_data)

def get_available_benchmarks(data):
return (d[0] for d in data)

def download_benchmark(benchmark, target_file, force_download=False):
for (name, url) in load_data("smtlib.urls"):
if name == benchmark:
if force_download or not os.path.exists(name):
urllib.urlretrieve(url, target_file)
raise BenchmarkNotFoundError()

def download_benchmarks(benchmarks, verbose=True):
for (name, target) in benchmarks:
if verbose: print("Downloading %s..." % name)
download_benchmark(name, target)
if verbose: print("Completed.")

def unzip_benchmarks(benchmarks, verbose=True):
for (name, target) in benchmarks:
if verbose: print("Extracting %s..." % name)
with zipfile.ZipFile(target, "r") as z:

if verbose: print("Completed.")

if __name__ == "__main__":
benchmarks = [ ("LIA", ""),
("LRA", ""),
("QF_IDL", ""),
("QF_LIA", ""),
("QF_LRA", ""),
("QF_RDL", ""),



0 comments on commit 0a99a78

Please sign in to comment.
You can’t perform that action at this time.