Browse Source

initialized with lecture 1 examples

main
sp 10 months ago
commit
f7b8d78fe8
  1. 52
      Lecture1/bitvectors_signedness.py
  2. 17
      Lecture1/intro_booleans.py
  3. 6
      Lecture1/intro_booleans.smt
  4. 11
      Lecture1/intro_booleans_solution.py
  5. 20
      Lecture1/material_implication.py
  6. 9
      Lecture1/material_implication.smt
  7. 29
      Lecture1/material_implication_solution.py
  8. 15
      Lecture1/weird_xor.py
  9. 26
      Lecture1/weird_xor_solution.py

52
Lecture1/bitvectors_signedness.py

@ -0,0 +1,52 @@
from z3 import *
solver = Solver()
bvX = BitVec("bvX", 8)
solver.add(bvX + 1 < bvX - 1)
print(f"Current 'state' of the solver:\n {solver.sexpr()}")
input("Hit Enter.")
result = solver.check()
print(result)
if result == sat:
print("=== Model ===")
for var in solver.model().decls():
print(f"M: {var}: int:{solver.model()[bvX].as_long()}, binary:{bin(solver.model()[bvX].as_long())} \t | type: {type(solver.model()[var])}")
print("=============")
solver.add(BVAddNoOverflow(bvX, 1, True))
solver.add(BVSubNoUnderflow(bvX, 1, True))
input("Hit Enter.")
print(f"Current 'state' of the solver:\n {solver.sexpr()}")
input("Hit Enter.")
result = solver.check()
print(result)
if result == sat:
print("=== Model ===")
for var in solver.model().decls():
print(f"M: {var}: int:{solver.model()[bvX].as_long()}, binary:{bin(solver.model()[bvX].as_long())} \t | type: {type(solver.model()[var])}")
print("=============")

17
Lecture1/intro_booleans.py

@ -0,0 +1,17 @@
from z3 import *
a, b = Bools("a b")
solver = Solver()
solver.add(Not(a))
solver.add(Or(a,b))
#solver.add(And(Not(a), Or(a,b)))
result = solver.check()
print(result)
model = solver.model()
print(model)
#for var in model.decls():
# print(f"{var}: {model[var]} \t(:{type(model[var])})")

6
Lecture1/intro_booleans.smt

@ -0,0 +1,6 @@
(declare-const a Bool)
(declare-const b Bool)
(assert (not a))
(assert (or a b))
(check-sat)
(get-model)

11
Lecture1/intro_booleans_solution.py

@ -0,0 +1,11 @@
from z3 import *
a, b = Bools("a b")
solver = Solver()
solver.add(Not(b))
solver.add(Or(a,b))
result = solver.check()
model = solver.model()
print(model)

20
Lecture1/material_implication.py

@ -0,0 +1,20 @@
# coding: utf-8
import os, sys
import time
from z3 import *
# TODO: Check Equivalence of
# - p -> q
# - !p | q
# create the solver
solver = Solver()
result = solver.check()
print(solver.sexpr())
print(result)

9
Lecture1/material_implication.smt

@ -0,0 +1,9 @@
(declare-fun b () Bool)
(declare-fun a () Bool)
(declare-fun l () Bool)
(declare-fun r () Bool)
(assert (= l (=> a b)))
(assert (= r (or (not a) b)))
(assert (distinct r l))
(check-sat)
(get-model)

29
Lecture1/material_implication_solution.py

@ -0,0 +1,29 @@
# coding: utf-8
import os, sys
import time
from z3 import *
# create the solver
solver = Solver()
a, b = Bools("a b")
l, r = Bools("l r")
solver.add(l == Implies(a, b))
solver.add(r == Or(Not(a), b))
solver.add(Distinct(r,l))
result = solver.check()
print(solver.sexpr())
print(result)
### A different way ###
solver = Solver()
a, b = Bools("a b")
l = Implies(a,b)
r = Or(Not(a),b)
solver.add(Distinct(l,r))
result = solver.check()
print(result)

15
Lecture1/weird_xor.py

@ -0,0 +1,15 @@
#!/usr/bin/python
from z3 import *
# TODO: Check for equivalence:
## - (((y & x)*-2) + (y+x))
## - x^y
s= Solver()
result = s.check()
print(result)
if result == sat:
print(s.model())

26
Lecture1/weird_xor_solution.py

HTTP/1.1 200 OK Content-Type: text/html; charset=UTF-8 Set-Cookie: i_like_gitea=7a886ba9f853c4b8; Path=/; HttpOnly; SameSite=Lax Set-Cookie: _csrf=vcioy-VjQdGQY60RvlQz8Eqajm86MTczNzYzNDE2OTgzMTE2MTM2Mw; Path=/; Expires=Fri, 24 Jan 2025 12:09:29 GMT; HttpOnly; SameSite=Lax Set-Cookie: macaron_flash=; Path=/; Max-Age=0; HttpOnly; SameSite=Lax X-Frame-Options: SAMEORIGIN Date: Thu, 23 Jan 2025 12:09:30 GMT Transfer-Encoding: chunked e486 sp/tempest - tempest - Gitea: Git with a cup of tea

3521 Commits (a9e01b869828e00c524c26037b9ba16aa1698efc)
 

@ -0,0 +1,26 @@
#!/usr/bin/python
from z3 import *
x = BitVec('x', 32)
y = BitVec('y', 32)
s = Solver()
Author SHA1 Message Date
Thomas Heinemann 556da4de5e Minor changes 13 years ago
Thomas Heinemann 8e460897f0 Minor corrections (Memory initialization in AtomicProposition) and 13 years ago
Thomas Heinemann a0e07c2022 Parser for labelling files including new data structure managing 13 years ago
Thomas Heinemann e5048cabb6 Closed memory leaks. 13 years ago
PBerger 307b85e331 Edited static_sparse_matrix.h, replaced all calloc/malloc calls with std::new 13 years ago
PBerger 6f970f27fe Added atomic propositions/labels 13 years ago
PBerger decb6b8006 Fixed CMakeLists.txt for Google Test to work with VS2012 13 years ago
PBerger a21a338a26 Included external 3rd Party content for Google Test Framework 13 years ago
Thomas Heinemann d37b23a5c5 - Additional "wrong header" testcase for the tra parser 13 years ago
Thomas Heinemann 395d2822b5 CMakeLists.txt: Enable debug symbols only on GCC (as e.g. Visual 13 years ago
Thomas Heinemann b846680445 Updated CMakeLists.txt to new location of MRMCConfig.h.in 13 years ago
Thomas Heinemann 5c7c23f4d6 Some minor changes (especially limiting the range of variables if 13 years ago
Thomas Heinemann 40de04a1fe Added missing files (exceptions) 13 years ago
Thomas Heinemann ebc0db4750 Formatting 13 years ago
Thomas Heinemann a908faf1a1 Worked on TODO's (minor stuff) 13 years ago
Thomas Heinemann 2c44c80bdb - Parser 13 years ago
Thomas Heinemann 60abde4968 Added dependency on thread in CMakeLists.txt 13 years ago
PBerger 3dac4e4a6a Fixed BUILD hints 13 years ago
PBerger 31d2c70acc Added temporary Find* files for CMake 13 years ago
PBerger 4cd75789ac Updated styleguides 13 years ago
PBerger 9da2eaf3d1 Initial Import into Git 13 years ago
0