In Z3 (Python), I found a way to see which are the models of a formula. See the post Z3: finding all satisfying models and a piece of code of it below:
a = Int('a')
b = Int('b')
s = Solver()
s.add(1 <= a)
s.add(a <= 20)
s.add(1 <= b)
s.add(b <= 20)
s.add(a >= 2*b)
while s.check() == sat:
print s.model()
s.add(Or(a != s.model()[a], b != s.model()[b]))
Now, I would like to count how many models are there. Of course, I could add a counter in the loop:
def count_models (s):
counter = 0
while s.check() == sat:
print s.model()
s.add(Or(a != s.model()[a], b != s.model()[b]))
counter = counter + 1
return counter
However, I would like to know whether there is any native function to do so. Something like s.count_models
. Any help?