Exemplo n.º 1
0
    def get_proof_term(self, thy, goal, *, args=None, prevs=None):
        assert isinstance(prevs,
                          list) and len(prevs) == 1, "rewrite_goal_with_prev"
        pt = prevs[0]

        init_As = goal.hyps
        C = goal.prop
        cv = then_conv(top_sweep_conv(rewr_conv(pt, match_vars=False)),
                       top_conv(beta_conv()))

        eq_th = cv.eval(thy, C)
        new_goal = eq_th.prop.rhs

        new_As = list(set(eq_th.hyps) - set(init_As))
        new_As_pts = [ProofTerm.sorry(Thm(init_As, A)) for A in new_As]
        if Term.is_equals(new_goal) and new_goal.lhs == new_goal.rhs:
            return ProofTermDeriv('rewrite_goal_with_prev',
                                  thy,
                                  args=C,
                                  prevs=[pt] + new_As_pts)
        else:
            new_goal_pts = ProofTerm.sorry(Thm(init_As, new_goal))
            return ProofTermDeriv('rewrite_goal_with_prev',
                                  thy,
                                  args=C,
                                  prevs=[pt, new_goal_pts] + new_As_pts)
Exemplo n.º 2
0
    def get_proof_term(self, thy, args, pts):
        assert len(pts) == 1 and isinstance(
            args, str), "rewrite_fact_macro: signature"

        th_name = args
        eq_pt = ProofTerm.theorem(thy, th_name)
        cv = then_conv(top_sweep_conv(rewr_conv(eq_pt)), top_conv(beta_conv()))
        return pts[0].on_prop(thy, cv)
Exemplo n.º 3
0
 def get_proof_term(self, thy, goal, pts):
     f, (P, c, Q) = goal.strip_comb()
     T = Q.get_type().domain_type()
     pt = vcg(thy, T, goal)
     for A in reversed(pt.hyps):
         pt = ProofTerm.implies_intr(A, pt)
     return pt.on_assums(thy, rewr_conv("Entail_def"),
                         top_conv(beta_conv()),
                         top_conv(function.fun_upd_eval_conv()))
Exemplo n.º 4
0
 def testBottomBetaConv(self):
     cv = bottom_conv(beta_conv())
     t = lf(lf(x))
     res = f(f(x, x), f(x, x))
     res_th = eq(t, res)
     self.assertEqual(cv.eval(thy, t), res_th)
     prf = cv.get_proof_term(thy, t).export()
     self.assertEqual(len(prf.items), 4)
     self.assertEqual(thy.check_proof(prf), res_th)
Exemplo n.º 5
0
 def testBottomBetaConvLarge(self):
     """Stress test for beta conversion in the bottom-up order."""
     cv = bottom_conv(beta_conv())
     t = x
     res = x
     for i in range(8):
         t = lf(t)
         res = f(res, res)
     prf = cv.get_proof_term(thy, t).export()
     self.assertEqual(cv.eval(thy, t), eq(t, res))
     self.assertEqual(len(prf.items), 22)
     self.assertEqual(thy.check_proof(prf), eq(t, res))
Exemplo n.º 6
0
    def testTopBetaConvAbs(self):
        cv = top_conv(beta_conv())

        # %x. (%a. f a) x reduces to %x. f x.
        a = Var("a", Ta)
        t = abs(x, abs(a, f(a))(x))
        res = abs(x, f(x))

        prf = cv.get_proof_term(thy, t).export()
        self.assertEqual(cv.eval(thy, t), eq(t, res))
        self.assertEqual(len(prf.items), 2)
        self.assertEqual(thy.check_proof(prf), eq(t, res))
Exemplo n.º 7
0
def norm_term(t):
    # Collect list of theorems that can be used.
    cvs = []
    for th_name in norm_thms:
        if isinstance(th_name, str) and theory.thy.has_theorem(th_name):
            cvs.append(conv.try_conv(conv.rewr_conv(th_name)))
        elif theory.thy.has_theorem(th_name[0]):
            cvs.append(conv.try_conv(conv.rewr_conv(th_name[0], sym=True)))
    cvs.append(conv.try_conv(conv.beta_conv()))
    cv = conv.top_conv(conv.every_conv(*cvs))
    while True:
        rhs = cv.eval(t).rhs
        if rhs == t:
            break
        else:
            t = rhs
    return fologic.simplify(t)
Exemplo n.º 8
0
    def get_proof_term(self, thy, args, pts):
        assert isinstance(args, tuple) and len(args) == 2 and \
               isinstance(args[0], str) and isinstance(args[1], Term), "rewrite_goal_macro: signature"

        name, goal = args
        eq_pt = ProofTerm.theorem(thy, name)
        if self.backward:
            eq_pt = ProofTerm.symmetric(eq_pt)
        cv = then_conv(top_conv(rewr_conv(eq_pt)), top_conv(beta_conv()))
        pt = cv.get_proof_term(thy, goal)  # goal = th.prop
        pt = ProofTerm.symmetric(pt)  # th.prop = goal
        if Term.is_equals(pt.prop.lhs) and pt.prop.lhs.lhs == pt.prop.lhs.rhs:
            pt = ProofTerm.equal_elim(pt, ProofTerm.reflexive(pt.prop.lhs.lhs))
        else:
            pt = ProofTerm.equal_elim(pt, pts[0])  # goal
            pts = pts[1:]

        for A in pts:
            pt = ProofTerm.implies_elim(ProofTerm.implies_intr(A.prop, pt), A)
        return pt
Exemplo n.º 9
0
    def get_proof_term(self, thy, args, pts):
        assert isinstance(args, Term), "rewrite_goal_macro: signature"

        goal = args
        eq_pt = pts[0]
        pts = pts[1:]
        if self.backward:
            eq_pt = ProofTerm.symmetric(eq_pt)
        cv = then_conv(top_sweep_conv(rewr_conv(eq_pt, match_vars=False)),
                       top_conv(beta_conv()))
        pt = cv.get_proof_term(thy, goal)  # goal = th.prop
        pt = ProofTerm.symmetric(pt)  # th.prop = goal
        if Term.is_equals(pt.prop.lhs) and pt.prop.lhs.lhs == pt.prop.lhs.rhs:
            pt = ProofTerm.equal_elim(pt, ProofTerm.reflexive(pt.prop.lhs.rhs))
        else:
            pt = ProofTerm.equal_elim(pt, pts[0])
            pts = pts[1:]

        for A in pts:
            pt = ProofTerm.implies_elim(ProofTerm.implies_intr(A.prop, pt), A)
        return pt
Exemplo n.º 10
0
    def get_proof_term(self, thy, goal, args=None, prevs=None):
        th_name = args

        init_As = goal.hyps
        C = goal.prop
        cv = then_conv(top_conv(rewr_conv(th_name)), top_conv(beta_conv()))
        eq_th = cv.eval(thy, C)
        new_goal = eq_th.prop.rhs

        new_As = list(eq_th.hyps)
        new_As_pts = [ProofTerm.sorry(Thm(init_As, A)) for A in new_As]
        if Term.is_equals(new_goal) and new_goal.lhs == new_goal.rhs:
            return ProofTermDeriv('rewrite_goal',
                                  thy,
                                  args=(th_name, C),
                                  prevs=new_As_pts)
        else:
            new_goal_pts = ProofTerm.sorry(Thm(init_As, new_goal))
            return ProofTermDeriv('rewrite_goal',
                                  thy,
                                  args=(th_name, C),
                                  prevs=[new_goal_pts] + new_As_pts)
Exemplo n.º 11
0
    def search(self, state, id, prevs):
        if len(prevs) != 1:
            return []

        prev_th = state.get_proof_item(prevs[0]).th
        cur_th = state.get_proof_item(id).th

        if not prev_th.prop.is_equals():
            return []

        pt = ProofTermAtom(prevs[0], prev_th)
        cv = then_conv(top_sweep_conv(rewr_conv(pt, match_vars=False)),
                       top_conv(beta_conv()))
        eq_th = cv.eval(state.thy, cur_th.prop)
        new_goal = eq_th.prop.rhs

        new_As = list(set(eq_th.hyps) - set(cur_th.hyps))
        if cur_th.prop != new_goal:
            if Term.is_equals(new_goal) and new_goal.lhs == new_goal.rhs:
                return [{"_goal": new_As}]
            else:
                return [{"_goal": [new_goal] + new_As}]
        else:
            return []
Exemplo n.º 12
0
    def get_proof_term(self, thy, args, pts):
        tyinst, inst = dict(), dict()
        if self.with_inst:
            name, tyinst, inst = args
        else:
            name = args
        th = thy.get_theorem(name)

        if not self.with_inst:
            As = th.assums
            for idx, pt in enumerate(pts):
                matcher.first_order_match_incr(As[idx], pt.prop,
                                               (tyinst, inst))

        pt = ProofTerm.substitution(
            inst, ProofTerm.subst_type(tyinst, ProofTerm.theorem(thy, name)))
        if pt.prop.beta_norm() == pt.prop:
            pt2 = pt
        else:
            pt2 = top_conv(beta_conv()).apply_to_pt(thy, pt)
        for pt in pts:
            pt2 = ProofTerm.implies_elim(pt2, pt)

        return pt2
Exemplo n.º 13
0
 def testTryConv(self):
     cv = try_conv(beta_conv())
     t = lf(x)
     self.assertEqual(cv.eval(thy, t), Thm.beta_conv(t))
     self.assertEqual(cv.eval(thy, x), Thm.reflexive(x))
Exemplo n.º 14
0
 def testBetaConvFail(self):
     cv = beta_conv()
     self.assertRaises(ConvException, cv.eval, thy, x)
     self.assertRaises(ConvException, cv.get_proof_term, thy, x)
Exemplo n.º 15
0
 def testBetaConv(self):
     cv = beta_conv()
     t = lf(x)
     self.assertEqual(cv.eval(thy, t), Thm.beta_conv(t))
     self.assertEqual(thy.check_proof(cv.get_proof_term(thy, t).export()),
                      Thm.beta_conv(t))
Exemplo n.º 16
0
 def get_proof_term(self, thy, args, pts):
     eq_pt, pt = pts
     cv = then_conv(top_sweep_conv(rewr_conv(eq_pt, match_vars=False)),
                    top_conv(beta_conv()))
     return pt.on_prop(thy, cv)
Exemplo n.º 17
0
 def eval(self, thy, args, ths):
     assert args is None, "beta_norm_macro"
     cv = top_conv(beta_conv())
     eq_th = cv.eval(thy, ths[0].prop)
     return Thm(ths[0].hyps, eq_th.prop.arg)
Exemplo n.º 18
0
 def get_proof_term(self, thy, args, pts):
     assert args is None, "beta_norm_macro"
     return top_conv(beta_conv()).apply_to_pt(thy, pts[0])