I want to print primes below 20 using Z3. The following program prints 2, 3, 5, and 7, but not 11, 13, 17, or 19.
Any idea what is wrong although isPrime(11), isPrime(13), isPrime(17), or isPrime(19) are all satisfied in my testing.
from z3 import *
def isPrime(x):
y = Int('y')
return And(x > 1, Not(Exists(y, And(y < x, 1 < y, x % y == 0))))
s = Solver()
x = Int('x')
s.add(isPrime(x))
s.add(x < 20)
while s.check() == sat:
ans = s.model()[x]
print(ans)
s.add(x != ans)