def norm(t, pts=None): """The main normalization function. The function should always succeed. It returns an equality whose left side is t. If no normalization is available, it returns t = t. """ if debug_auto: print("Norm:", t, [str(pt.prop) for pt in pts]) # Do not normalize variables and abstractions if t.is_var() or t.is_abs(): return refl(t) # No further work for numbers if t.is_number(): return refl(t) # Record if not pts and t in norm_record: return norm_record[t] eq_pt = refl(t.head) # First normalize each argument for arg in t.args: eq_pt = eq_pt.combination(norm(arg, pts)) # Next, apply each normalization rule if t.head in global_autos_norm: ori_rhs = eq_pt.rhs for f in global_autos_norm[t.head]: try: if isinstance(f, Conv): eq_pt = eq_pt.on_rhs(f) else: eq_pt = eq_pt.transitive(f(eq_pt.rhs, pts)) except ConvException: continue if eq_pt.rhs.head != t.head: # Head changed, should try something else break if eq_pt.rhs == ori_rhs: # Unchanged, normalization stops here res_pt = eq_pt else: # Head changed, continue apply norm eq_pt2 = norm(eq_pt.rhs, pts) if eq_pt2.lhs != eq_pt.rhs: eq_pt2 = eq_pt2.on_lhs(top_conv(eta_conv())) res_pt = eq_pt.transitive(eq_pt2) else: # No normalization rule available for this head res_pt = eq_pt if not pts: norm_record[t] = res_pt return res_pt
def get_proof_term(self, t): eq_t = norm(t, self.conds) if t == eq_t.rhs: return refl(t) else: return ProofTerm('auto', args=eq_t.prop, prevs=self.conds, th=eq_t.th)
def real_solver(self, args): refl_pt = conv.refl(args).on_rhs( conv.top_conv(conv.rewr_conv("real_ge_le_same_num")), conv.top_conv(conv.rewr_conv("de_morgan_thm1")), conv.top_conv(real.norm_neg_real_ineq_conv()), conv.top_conv(real.real_simplex_form()), conv.top_conv(real.real_const_compares()), proplogic.norm_full()) if refl_pt.rhs == true: return refl_pt.on_prop(conv.rewr_conv("eq_true", sym=True)) pt_result = real_th_lemma([refl_pt.rhs]) return refl_pt.symmetric().equal_elim(pt_result)
def int_solver(self, args): refl_pt = conv.refl(args).on_rhs( conv.top_conv(conv.rewr_conv("int_eq_leq_geq")), conv.top_conv(conv.rewr_conv("de_morgan_thm1")), conv.top_conv(integer.int_norm_neg_compares()), conv.top_conv(integer.omega_form_conv()), conv.top_conv(integer.int_const_compares()), proplogic.norm_full()) if refl_pt.rhs == true: return refl_pt.on_prop(conv.rewr_conv("eq_true", sym=True)) try: pt_result = int_th_lemma_1_simplex(refl_pt.rhs) except: pt_result = int_th_lemma_1_omega(refl_pt.rhs) return refl_pt.symmetric().equal_elim(pt_result)
def get_proof_term(self, t): assert is_interval(t), "numseg_conv" mt, nt = t.args m, n = mt.dest_number(), nt.dest_number() pt = refl(t) if n < m: less_goal = nat.less(nt, mt) less_pt = nat.nat_const_less_macro().get_proof_term(less_goal, []) return pt.on_rhs(rewr_conv("natseg_emptyI", conds=[less_pt])) else: le_goal = nat.less_eq(mt, nt) le_pt = nat.nat_const_less_eq_macro().get_proof_term(le_goal, []) return pt.on_rhs(rewr_conv("natseg_lrec", conds=[le_pt]), arg_conv(arg1_conv(nat.nat_conv())), arg_conv(self))
def norm_fun(t, pts): for th_name in th_names: if theory.thy.has_theorem(th_name): th = theory.get_theorem(th_name) else: continue try: inst = matcher.first_order_match(th.concl.lhs, t) except matcher.MatchException: continue As, C = th.prop.subst_norm(inst).strip_implies() try: pts = [solve(A, pts) for A in As] except TacticException: continue return apply_theorem(th_name, *pts, concl=C) # No rewriting available return refl(t)