ports/math/py-z3-solver/files/example-power-of-two.py
Yuri Victorovich 5c1f797943 math/py-z3-solver: update 4.8.17 → 4.13.2
This fixes the problem from bug#280689.

PR:		280689
2024-10-07 20:44:40 -07:00

15 lines
380 B
Python

# example from https://ericpony.github.io/z3py-tutorial/guide-examples.htm
from z3 import BitVec, And, Or, prove
x = BitVec('x', 32)
powers = [ 2**i for i in range(32) ]
fast = And(x != 0, x & (x - 1) == 0)
slow = Or([ x == p for p in powers ])
print (fast)
prove(fast == slow)
print ("trying to prove buggy version...")
fast = x & (x - 1) == 0
prove(fast == slow)