Browse files

Merge pull request #451 from pysmt/i414/examples_theory_combination

Examples: Theory Combination
  • Loading branch information...
mikand committed Dec 26, 2017
2 parents 120cc08 + 2b419ec commit 765d2ce65d2c752409fb5c1cd55e6defa5b72e16
Showing with 47 additions and 0 deletions.
  1. +1 −0 examples/README.rst
  2. +46 −0 examples/
@@ -18,3 +18,4 @@ This directory contains examples to get you started using pySMT. Suggested order
13. ` </examples/>`_ : Shows the use of UNSAT Core as debugging tools
14. ` </examples/>`_ : Equivalence checking of XOR rewriting using BitVectors
15. ` </examples/>`_ : Quantifier Elimination of an LRA formula
16. ` </examples/>`_ : Combine multiple theories (Array, BitVectors, Integer, and Reals) in the same formula
@@ -0,0 +1,46 @@
# This example requires a solver that supports QF_AUFLIRA
# e.g. MathSat or Z3
# Theory combination is the possibility of mixing theories with an SMT
# problem. This goes beyond having subexpressions belonging to
# different theories, and really requires mixing theories in the same
# expression.
# In this example, we use four theories supported by pySMT:
# BitVectors, Integers, Reals, and Arrays.
from pysmt.shortcuts import Symbol, BV, Real, And, BVToNatural, ToReal
from pysmt.shortcuts import get_model
from pysmt.typing import BV8, REAL, INT, ArrayType
# We create a map from BitVectors to Reals, so that each bitvector
# value (interpreted as unary number) is equal to the Real
# value.
# The map is represented by an Array of type BV8 -> Real
map_type = ArrayType(BV8, REAL)
my_map = Symbol("my_map", map_type)
# Fill-up the map, by defining all 256 values:
for i in range(0, 255):
my_map = my_map.Store(BV(i, 8), Real(i))
# We want to find find a value for which our relation does not work.
# In other words, we ask if there is a value for the bitvector
# s.t. the corresponding value in the array is different from the
# unary interpretation of the bitvector.
bv_var = Symbol("bv", BV8)
int_var = Symbol("int", INT)
real_var = Symbol("real", REAL)
f = And(
# Convert the BV into INT
# Convert the INT into REAL
# Compare the value stored in the map with the REAL value
print(get_model(f)) # Indeed our range only gets up to 254!!!

0 comments on commit 765d2ce

Please sign in to comment.