You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
681 B

  1. from z3 import *
  2. s = Solver()
  3. bv_size = 4
  4. a, b = BitVecs('a b', bv_size)
  5. x = BitVec('x', bv_size)
  6. lhs,rhs = BitVecs('lhs rhs', bv_size)
  7. s.add(lhs == ((x+a)^b)-a)
  8. s.add(rhs == ((x-a)^b)+a)
  9. s.push()
  10. s.add(ForAll(x, lhs == rhs))
  11. # enumerate all possible solutions:
  12. results=[]
  13. while True:
  14. if s.check() == sat:
  15. m = s.model()
  16. print (m)
  17. results.append(m)
  18. block = []
  19. block = [a != m[a].as_long(), b != m[b].as_long()]
  20. s.add(Or(block))
  21. else:
  22. print ("results total=", len(results))
  23. break
  24. #print(s.sexpr())
  25. s.pop()
  26. s.add(Exists(x, lhs != rhs))
  27. result = s.check()
  28. print(result)
  29. if result == sat:
  30. print(f"Example where lhs != rhs: {s.model()}")