1

When calling Z3py's Exists function subsequently on different variables and formulas, I get the exact same result. Is that some sort of Python problem or is Z3 broken here? How to fix? The following minimal example illustrates the problem:

from z3 import *
a, a0, a1, b, b0, b1 = Ints('a a0 a1 b b0 b1')
x, y = Bools('x y')
s = Solver()
formula = Implies(x, And(a>0,b1<0))
substitution1 = substitute(formula,(a1,a0),(b1,b0))
substitution2 = substitute(formula,(a1,a0),(b1,b0),(a,a1),(b,b1))
print substitution1
print substitution2
exist1 = Exists([a,b],substitution1)
exist2 = Exists([a1,b1],substitution2)
print exist1
print exist2

Output:

Implies(x, And(a > 0, b0 < 0))
Implies(x, And(a1 > 0, b0 < 0))
Exists([a, b], Implies(x, And(a > 0, b0 < 0)))
Exists([a, b], Implies(x, And(a > 0, b0 < 0)))
Fightclub
  • 13
  • 2

1 Answers1

0

Thanks for reporting that. Z3 is in fact correct about this, but the output is confusing. Internally, Z3 uses deBrujin indices and the names of bound variables are immaterial. When a quantifier is created that has the same body (and patterns, no_patterns, etc) then the exactly same expression that was seen before is used, to avoid having to solve the same quantified constraint as before. This creates the confusing situation as suddenly the names of bound variables seem to have changed.

In the example given here, the bodies of both quantifiers are indeed identical and the names of variables do not matter. Z3 could use any names for those variables, but it chooses to use the ones that were used when the quantifier was created the first time. We could disable that, e.g., by adding

compare_arrays(to_quantifier(n1)->get_decl_names(),
               to_quantifier(n2)->get_decl_names(),
               to_quantifier(n1)->get_num_decls()) &&

at src/ast/ast.cpp:470. This however would likely have a negative impact on Z3's performance on some benchmarks, so I will not make this change. If you would like to use it, you can add it to your local copy of Z3 of course.

Christoph Wintersteiger
  • 8,234
  • 1
  • 16
  • 30