Example #1
0
 def get_proof_term(self, t):
     pt = refl(t)
     if t.is_conj():
         return pt.on_rhs(binop_conv(self), norm_conj_conjunction())
     elif t.is_disj():
         return pt.on_rhs(binop_conv(self), norm_disj_disjunction())
     elif t.is_equals():
         lhs, rhs = t.lhs, t.rhs
         if lhs == rhs:
             return pt.on_rhs(rewr_conv('eq_mean_true'))
         elif lhs == true:  # (true ⟷ P) ⟷ P
             return pt.on_rhs(rewr_conv('eq_sym_eq'),
                              rewr_conv('eq_true', sym=True))
         elif rhs == true:  # (P ⟷ true) ⟷ P
             return pt.on_rhs(rewr_conv('eq_true', sym=True))
         elif lhs == false:  # (false ⟷ P) ⟷ ¬P
             return pt.on_rhs(rewr_conv('eq_sym_eq'),
                              rewr_conv('eq_false', sym=True))
         elif rhs == true:  # (P ⟷ false) ⟷ ¬P
             return pt.on_rhs(rewr_conv('eq_false', sym=True))
         else:
             return pt.on_rhs(binop_conv(self))
     elif t.is_not() and (t.arg.is_conj() or t.arg.is_disj()
                          or t.arg.is_not() or t.arg == true
                          or t.arg == false):
         return pt.on_rhs(nnf_conv(), self)
     elif t.is_not() and t.arg.is_equals():
         return pt.on_rhs(nnf_conv())
     else:
         return pt
Example #2
0
File: nat.py Project: bzhan/holpy
 def get_proof_term(self, t):
     pt = refl(t)
     if theory.thy.has_theorem('mult_comm'):
         # Full conversion, with or without binary numbers
         if t.is_number():
             return pt
         elif t.is_comb('Suc', 1):
             return pt.on_rhs(rewr_conv("add_1_right", sym=True),
                              norm_full())
         elif t.is_plus():
             return pt.on_rhs(binop_conv(norm_full()),
                              norm_add_polynomial())
         elif t.is_times():
             return pt.on_rhs(binop_conv(norm_full()),
                              norm_mult_polynomial())
         else:
             return pt
     elif theory.thy.has_theorem('add_assoc'):
         # Conversion using only AC rules for addition
         if t.is_number():
             return pt
         elif t.is_comb('Suc', 1):
             return pt.on_rhs(rewr_conv("add_1_right", sym=True),
                              norm_full())
         elif t.is_plus():
             return pt.on_rhs(binop_conv(norm_full()), norm_add_1())
         else:
             return pt
     else:
         return pt
Example #3
0
    def get_proof_term(self, thy, t):
        if is_binary(t):
            cv = all_conv()
        elif is_Suc(t):
            cv = then_conv(rewr_conv("add_1_right", sym=True), norm_full())
        elif is_plus(t):
            cv = then_conv(binop_conv(norm_full()), norm_add_polynomial())
        elif is_times(t):
            cv = then_conv(binop_conv(norm_full()), norm_mult_polynomial())
        else:
            cv = all_conv()

        return cv.get_proof_term(thy, t)
Example #4
0
 def get_proof_term(self, thy, t):
     pt = refl(t)
     if is_binary(t):
         return pt
     else:
         if t.head == Suc:
             return pt.on_rhs(thy, arg_conv(self), Suc_conv())
         elif t.head == plus:
             return pt.on_rhs(thy, binop_conv(self), add_conv())
         elif t.head == times:
             return pt.on_rhs(thy, binop_conv(self), mult_conv())
         else:
             raise ConvException()
Example #5
0
File: nat.py Project: bzhan/holpy
 def get_proof_term(self, t):
     pt = refl(t)
     if t.is_number():
         return pt
     elif t.is_comb('Suc', 1):
         return pt.on_rhs(arg_conv(self), arg_conv(rewr_of_nat_conv()),
                          Suc_conv(), rewr_of_nat_conv(sym=True))
     elif t.is_plus():
         return pt.on_rhs(binop_conv(self), binop_conv(rewr_of_nat_conv()),
                          add_conv(), rewr_of_nat_conv(sym=True))
     elif t.is_times():
         return pt.on_rhs(binop_conv(self), binop_conv(rewr_of_nat_conv()),
                          mult_conv(), rewr_of_nat_conv(sym=True))
     else:
         raise ConvException("nat_conv")
Example #6
0
File: real.py Project: bzhan/holpy
 def get_proof_term(self, t):
     pt = refl(t)
     is_l_atom = (dest_monomial(t.arg1) == t.arg1)
     is_r_atom = (dest_monomial(t.arg) == t.arg)
     if is_l_atom and is_r_atom:
         return pt.on_rhs(norm_mult_monomial(self.conds))
     elif is_l_atom and not is_r_atom:
         if t.arg.is_number():
             return pt.on_rhs(rewr_conv('real_mult_comm'),
                              try_conv(rewr_conv('real_mul_rid')),
                              try_conv(rewr_conv('real_mul_lzero')))
         else:
             return pt.on_rhs(arg_conv(rewr_conv('real_mult_comm')),
                              rewr_conv('real_mult_assoc'),
                              rewr_conv('real_mult_comm'),
                              arg_conv(norm_mult_monomial(self.conds)))
     elif not is_l_atom and is_r_atom:
         if t.arg1.is_number():
             return pt.on_rhs(try_conv(rewr_conv('real_mul_rid')),
                              try_conv(rewr_conv('real_mul_lzero')))
         else:
             return pt.on_rhs(rewr_conv('real_mult_assoc', sym=True),
                              arg_conv(norm_mult_monomial(self.conds)))
     else:
         return pt.on_rhs(
             binop_conv(to_coeff_form()),  # (c_1 * m_1) * (c_2 * m_2)
             rewr_conv('real_mult_assoc'),  # (c_1 * m_1 * c_2) * m_2
             arg1_conv(swap_mult_r()),  # (c_1 * c_2 * m_1) * m_2
             arg1_conv(arg1_conv(real_eval_conv())),  # (c_1c_2 * m_1) * m_2
             rewr_conv('real_mult_assoc', sym=True),  # c_1c_2 * (m_1 * m_2)
             arg_conv(norm_mult_monomial(self.conds)),
             from_coeff_form())
Example #7
0
File: real.py Project: bzhan/holpy
    def get_proof_term(self, t):
        pt = refl(t).on_rhs(binop_conv(to_exponent_form()))
        if pt.rhs.arg1.is_comb('exp', 1) and pt.rhs.arg.is_comb('exp', 1):
            # Both sides are exponentials
            return pt.on_rhs(rewr_conv('real_exp_add', sym=True),
                             arg_conv(auto.auto_conv(self.conds)))
        elif pt.rhs.arg1.is_nat_power() and pt.rhs.arg.is_nat_power():
            # Both sides are natural number powers, simply add
            return pt.on_rhs(rewr_conv('real_pow_add', sym=True),
                             arg_conv(nat.nat_conv()))
        else:
            # First check that x > 0 can be proved. If not, just return
            # without change.
            x = pt.rhs.arg1.arg1
            try:
                x_gt_0 = auto.solve(x > 0, self.conds)
            except TacticException:
                return refl(t)

            # Convert both sides to real powers
            if pt.rhs.arg1.is_nat_power():
                pt = pt.on_rhs(arg1_conv(rewr_conv('rpow_pow', sym=True)))
            if pt.rhs.arg.is_nat_power():
                pt = pt.on_rhs(arg_conv(rewr_conv('rpow_pow', sym=True)))
            pt = pt.on_rhs(rewr_conv('rpow_add', sym=True, conds=[x_gt_0]),
                           arg_conv(real_eval_conv()))

            # Simplify back to nat if possible
            if pt.rhs.arg.is_comb('of_nat', 1):
                pt = pt.on_rhs(rewr_conv('rpow_pow'),
                               arg_conv(rewr_conv('nat_of_nat_def', sym=True)))

            return pt.on_rhs(from_exponent_form())
Example #8
0
 def get_proof_term(self, t):
     if t.is_conj():
         return then_conv(
             binop_conv(norm_conj_assoc()),
             norm_conj_assoc_clauses()
         ).get_proof_term(t)
     else:
         return all_conv().get_proof_term(t)
Example #9
0
 def get_proof_term(self, t):
     pt = refl(t)
     if t.is_plus() or t.is_minus():
         return pt.on_rhs(binop_conv(self), norm_add_polynomial())
     elif t.is_times():
         return pt.on_rhs(binop_conv(self), norm_mult_polynomials())
     elif t.is_number():
         return pt
     elif t.is_nat_power() and t.arg.is_number(
     ):  # rewrite x ^ n to 1 * x ^ n
         return pt.on_rhs(rewr_conv('int_mul_1_l', sym=True))
     elif t.is_uminus():
         pt_mul_neg1 = pt.on_rhs(rewr_conv('int_poly_neg1'))
         pt_new = self.get_proof_term(pt_mul_neg1.prop.rhs)
         return pt.transitive(pt_mul_neg1).transitive(pt_new)
     else:  # rewrite x to 1 * x ^ 1
         return pt.on_rhs(rewr_conv('int_pow_1_r', sym=True),
                          rewr_conv('int_mul_1_l', sym=True))
Example #10
0
 def get_proof_term(self, t):
     pt = refl(t)
     if t.is_not():
         if t.arg == true:
             return pt.on_rhs(rewr_conv('not_true'))
         elif t.arg == false:
             return pt.on_rhs(rewr_conv('not_false'))
         elif t.arg.is_not():
             return pt.on_rhs(rewr_conv('double_neg'), self)
         elif t.arg.is_conj():
             return pt.on_rhs(rewr_conv('de_morgan_thm1'), arg1_conv(self),
                              arg_conv(self))
         elif t.arg.is_disj():
             return pt.on_rhs(rewr_conv('de_morgan_thm2'), arg1_conv(self),
                              arg_conv(self))
         elif t.arg.is_equals() and t.arg.lhs.get_type() == BoolType:
             return pt.on_rhs(rewr_conv('neg_iff'), binop_conv(self))
         else:
             return pt
     elif t.is_disj() or t.is_conj() or t.is_equals():
         return pt.on_rhs(arg1_conv(self), arg_conv(self))
     else:
         return pt
Example #11
0
def norm_mem_interval(pt):
    """Normalize membership in interval."""
    return pt.on_prop(arg_conv(binop_conv(auto.auto_conv())))
Example #12
0
File: real.py Project: bzhan/holpy
 def get_proof_term(self, t):
     return refl(t).on_rhs(binop_conv(to_coeff_form()),
                           rewr_conv('real_add_rdistrib', sym=True),
                           arg1_conv(real_eval_conv()), from_coeff_form())
Example #13
0
File: nat.py Project: bzhan/holpy
    def get_proof_term(self, goal, pts):
        assert len(pts) == 0 and self.can_eval(goal), "nat_const_ineq_macro"

        m, n = goal.arg.args
        pt = ineq_proof_term(m.dest_number(), n.dest_number())
        return pt.on_prop(arg_conv(binop_conv(rewr_of_nat_conv(sym=True))))
Example #14
0
File: nat.py Project: bzhan/holpy
 def get_proof_term(self, t):
     return refl(t).on_rhs(binop_conv(to_coeff_form()),
                           rewr_conv("distrib_l", sym=True),
                           arg_conv(nat_conv()), from_coeff_form())
Example #15
0
def combine_monomial(thy):
    """Combine two monomials with the same body."""
    return every_conv(binop_conv(to_coeff_form()),
                      rewr_conv("distrib_l", sym=True), arg_conv(nat_conv()),
                      from_coeff_form())