def to_constraint(self): if isinstance(self.args[1],Some): if self.args[1].if_value() != None: return And(Implies(self.args[1].args[1], lg.Exists([self.args[1].args[0]], And(self.args[1].args[1],Equals(self.args[0],self.args[1].if_value())))), Or(lg.Exists([self.args[1].args[0]],self.args[1].args[1]), Equals(self.args[0],self.args[1].else_value()))) return lg.ForAll([self.args[1].args[0]], Implies(self.args[1].args[1], lu.substitute(self.args[1].args[1],{self.args[1].args[0]:self.args[0]}))) if is_individual(self.args[0]): return Equals(*self.args) return Iff(*self.args)
if __name__ == '__main__': S = UninterpretedSort('S') X, Y, Z = (Var(n, S) for n in ['X', 'Y', 'Z']) BinRel = FunctionSort(S, S, Boolean) leq = Const('leq', BinRel) transitive1 = ForAll((X, Y, Z), Implies(And(leq(X, Y), leq(Y, Z)), leq(X, Z))) transitive2 = ForAll((X, Y, Z), Or(Not(leq(X, Y)), Not(leq(Y, Z)), leq(X, Z))) transitive3 = Not( Exists((X, Y, Z), And(leq(X, Y), leq(Y, Z), Not(leq(X, Z))))) antisymmetric = ForAll((X, Y), Implies(And(leq(X, Y), leq(Y, X), true), Eq(Y, X))) print z3_implies(transitive1, transitive2) print z3_implies(transitive2, transitive3) print z3_implies(transitive3, transitive1) print z3_implies(transitive3, antisymmetric) print print z3_implies(true, Iff(transitive1, transitive2)) print x, y = (Const(n, S) for n in ['x', 'y']) b = Const('b', Boolean) print z3_implies(b, Eq(Ite(b, x, y), x)) print z3_implies(Not(b), Eq(Ite(b, x, y), y)) print z3_implies(Not(Eq(x, y)), Iff(Eq(Ite(b, x, y), x), b))
def to_constraint(self): if is_individual(self.args[0]): return Equals(*self.args) return Iff(*self.args)
assert f1 == cf1 print f2 = And(ps(XT), pt(xs)) cf2 = concretize_sorts(f2) print repr(f2) print repr(cf2) print f3 = Exists([TT], And(ps(XT), TT(xs))) cf3 = concretize_sorts(f3) print repr(f3) print repr(cf3) print f4 = Iff(xt, Ite(yt, xt, XT)) cf4 = concretize_sorts(f4) print repr(f4) print repr(cf4) print # TODO: add more tests, specifically a test that checks # unification across different quantified bodies """ c10 = Concept('c10',[X], And(p(X), Not(q(X)))) c01 = Concept('c01',[X], And(Not(p(X)), q(X))) c00 = Concept('c00',[X], And(Not(p(X)), Not(q(X)))) crn = Concept([X, Y], Or(r(X,Y), n(X,Y))) X, Y, _ = (Var(n, T) for n in ['X', 'Y', 'Z'])