from z3 import * # lecture 15, slide 36 and on # declare the variables x and y x = Bool('x') y = Bool('y') # declare the 'next state' variables x_ and y_ x_ = Bool('x_') y_ = Bool('y_') # define R as manually computed R = Or(And(x_ == x, y_ != y), And(x_ != x, y_ == y)) # define the property we are interested in phi = And(x, y) # substitute the 'next state' variables phi_ = substitute(phi, (x, x_), (y, y_)) # define EX_phi using the definition EX_phi = Exists([x_, y_], And(R, phi_)) # use the quantifier elimination 'tactic' quant_elim = Tactic('qe') # apply the qe tactic result = quant_elim(EX_phi)[0][0] #print the result print(result)