def has_rewrite(th, t, *, sym=False, conds=None): """Returns whether a rewrite is possible on a subterm of t. This can serve as a pre-check for top_sweep_conv, top_conv, and bottom_conv applied to rewr_conv. th -- either the name of a theorem, or the theorem itself. t -- target of rewriting. conds -- optional list of theorems matching assumptions of th. """ if isinstance(th, str): th = theory.get_theorem(th) if sym: th = Thm.symmetric(th) As, C = th.prop.strip_implies() if conds is None: conds = [] if not C.is_equals() or len(As) != len(conds): return False if set(term.get_svars(As + [C.lhs])) != set(term.get_svars(As + [C])): return False ts = [cond.prop for cond in conds] inst = Inst() try: inst = matcher.first_order_match_list(As, ts, inst) except matcher.MatchException: return False def rec(t): if not t.is_open() and matcher.can_first_order_match(C.lhs, t, inst): return True if t.is_comb(): return rec(t.fun) or rec(t.arg) elif t.is_abs(): _, body = t.dest_abs() return rec(body) else: return False return rec(t)
def testSymmetric(self): th = Thm([A], Term.mk_equals(x, y)) self.assertEqual(Thm.symmetric(th), Thm([A], Term.mk_equals(y, x)))
def testSymmetric(self): th = Thm([A], Eq(x,y)) self.assertEqual(Thm.symmetric(th), Thm([A], Eq(y,x)))