Skip to content

Commit

Permalink
Add tiny little Z3 examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sampsyo committed May 8, 2018
1 parent d62fb68 commit 567f860
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Install our only Python dependency, [Lark][]:

$ pip install --user lark-parser

Witness the magic of Z3:

$ python3 ex0.py

Run a simple example to see how to synthesize values, which is stolen from [Aws Albarghouthi][aws]'s [primer][]:

$ python3 ex1.py
Expand Down
24 changes: 24 additions & 0 deletions ex0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import z3


def ex0():
x = z3.Int('x')
print(solve(x / 7 == 6))

y = z3.BitVec('y', 8)
print(solve(y << 3 == 336))

z = z3.Int('z')
n = z3.Int('n')
print(solve(z3.ForAll([z], z * n == z)))


def solve(phi):
s = z3.Solver()
s.add(phi)
s.check()
return s.model()


if __name__ == '__main__':
ex0()

0 comments on commit 567f860

Please sign in to comment.