问题
Given two boolexpr b1,b2 say
b1=x1>=4&&x2>=5
b2=x2>=5&&x1>=4
Can we use .net API for Z3 to know whether b1 and b2 are actually the same constraint? )(meaning that the value of x1 and x2 allowed by b1 and b2 are the same)
回答1:
Yes. You want to prove that b1 equals b2, which you can do by showing the negation of b1 == b2 is unsatisfiable. Here's an example showing how to do this in Z3Py, and you can use basically the same steps in the .NET API: http://rise4fun.com/Z3Py/M4R1
x1, x2 = Reals('x1 x2')
b1=And(x1>=4, x2>=5)
b2=And(x2>=5, x1>=4)
s = Solver()
proposition = b1 == b2 # assertion is whether b1 and b2 are equal
s.add(Not(proposition))
# proposition proved if negation of proposition is unsat
print s.check() # unsat
b1=And(x1>=3, x2>=5) # note difference
b2=And(x2>=5, x1>=4)
s = Solver()
proposition = b1 == b2
s.add(Not(proposition))
print s.check() # sat
来源:https://stackoverflow.com/questions/12283181/whether-two-boolexpr-are-equal