def atom_less(t1, t2): """Compare two atoms, put constants in front.""" if not t1.has_var() and t2.has_var(): return True elif not t2.has_var() and t1.has_var(): return False else: return term_ord.fast_compare(t1, t2) < 0
def compare_fst(p1, p2): if isinstance(p1[0], Term): return term_ord.fast_compare(p1[0], p2[0]) else: if len(p1[0]) != len(p2[0]): return term_ord.compare_atom(len(p1[0]), len(p2[0])) for i in range(len(p1[0])): if p1[0][i] != p2[0][i]: return compare_fst(p1[0][i], p2[0][i]) return 0
def compare_atom(t1, t2): """Compare two atoms, placing numbers last.""" if t1.is_number() and t2.is_number(): return 0 elif t1.is_number(): return 1 elif t2.is_number(): return -1 else: return term_ord.fast_compare(t1, t2)
def omega_compare_monomial(t1, t2): """Assume t1 and t2 are in the form c1 * body1 and c2 * body2, compare body1 with body2.""" if t1.is_number() and t2.is_number(): return 0 if t1.is_number() and not t2.is_number(): return 1 if not t1.is_number() and t2.is_number(): return -1 else: return term_ord.fast_compare(t1.arg, t2.arg)
def get_proof_term(self, t): pt = refl(t) if t.arg1 == true: return pt.on_rhs(rewr_conv('conj_true_left')) elif t.arg == true: return pt.on_rhs(rewr_conv('conj_true_right')) elif t.arg1 == false: return pt.on_rhs(rewr_conv('conj_false_right')) elif t.arg == false: return pt.on_rhs(rewr_conv('conj_false_left')) elif t.arg.is_conj(): if t.arg1 == Not(t.arg.arg1): # A /\ (A_1 /\ ... /\ A_n) return pt.on_rhs(rewr_conv('conj_assoc'), arg1_conv(rewr_conv('conj_neg_pos')), rewr_conv('conj_false_right')) elif Not(t.arg1) == t.arg.arg1: return pt.on_rhs(rewr_conv('conj_assoc'), arg1_conv(rewr_conv('conj_pos_neg')), rewr_conv('conj_false_right')) cp = term_ord.fast_compare(t.arg1, t.arg.arg1) if cp > 0: return pt.on_rhs(swap_conj_r(), arg_conv(self), try_conv(self)) elif cp == 0: return pt.on_rhs(rewr_conv('conj_assoc'), arg1_conv(rewr_conv('conj_same_atom'))) else: return pt else: if t.arg == Not(t.arg1): return pt.on_rhs(rewr_conv('conj_pos_neg')) elif t.arg1 == Not(t.arg): return pt.on_rhs(rewr_conv('conj_neg_pos')) cp = term_ord.fast_compare(t.arg1, t.arg) if cp > 0: return pt.on_rhs(swap_conj_r()) elif cp == 0: return pt.on_rhs(rewr_conv('conj_same_atom')) else: return pt
def compare_atom(t1, t2): """Assume t1 and t2 are in the form a_i^{e_i} and a_j^{e_j}, compare a_i with a_j.""" return term_ord.fast_compare(t1.arg1, t2.arg1)
def compare_monomial(t1, t2): """Compare two monomials by their body.""" if has_binary_thms(): return term_ord.fast_compare(dest_monomial(t1), dest_monomial(t2)) else: return term_ord.fast_compare(t1, t2)