Exemplo n.º 1
0
    def testProofItem(self):
        test_data = [
            (ProofItem(0, "theorem", args="conjD1"), "0: theorem conjD1", {
                'id': 0,
                'th': '',
                'rule': 'theorem',
                'args': 'conjD1',
                'prevs': []
            }),
            (ProofItem(1, "assume", args=A_to_B), "1: assume implies A B", {
                'id': 1,
                'th': '',
                'rule': 'assume',
                'args': 'implies A B',
                'prevs': []
            }),
            (ProofItem(5, "substitution", args={
                "A": B,
                "B": A
            }, prevs=[4]), "5: substitution {A: B, B: A} from 4", {
                'id': 5,
                'th': '',
                'rule': 'substitution',
                'args': '{A: B, B: A}',
                'prevs': [4]
            }),
            (ProofItem(6, "implies_elim",
                       prevs=[5, 3]), "6: implies_elim from 5, 3", {
                           'id': 6,
                           'th': '',
                           'rule': 'implies_elim',
                           'args': '',
                           'prevs': [5, 3]
                       }),
            (ProofItem(1,
                       "apply_theorem_for",
                       args=("conjD2", {}, {
                           "A": B,
                           "B": A
                       }),
                       prevs=[0]),
             "1: apply_theorem_for conjD2, {}, {A: B, B: A} from 0", {
                 'id': 1,
                 'th': '',
                 'rule': 'apply_theorem_for',
                 'args': 'conjD2, {A: B, B: A}',
                 'prevs': [0]
             })
        ]

        for item, s, d in test_data:
            self.assertEqual(str(item), s)
Exemplo n.º 2
0
 def testRule3(self):
     A = Var('A', boolT)
     B = Var('B', boolT)
     goal = Thm([], disj(B, A))
     prev = ProofTermAtom(0, Thm.assume(B))
     pt = tactic.rule().get_proof_term(thy, ProofTerm.sorry(goal), args='disjI1', prevs=[prev])
     prf = pt.export(prefix=(1,), subproof=False)
     self.assertEqual(prf.items[0], ProofItem(1, 'apply_theorem_for', args=('disjI1', {}, {'A': B, 'B': A}), prevs=[0]))
Exemplo n.º 3
0
 def testRule2(self):
     A = Var('A', boolT)
     B = Var('B', boolT)
     goal = Thm([], disj(B, A))
     prev = ProofTermAtom(0, Thm.assume(disj(A, B)))
     pt = tactic.rule().get_proof_term(thy, ProofTerm.sorry(goal), args='disjE', prevs=[prev])
     prf = pt.export(prefix=(1,), subproof=False)
     self.assertEqual(prf.items[2], ProofItem(3, 'apply_theorem', args='disjE', prevs=[0, 1, 2]))
Exemplo n.º 4
0
 def set_line(self, id, rule, *, args=None, prevs=None, th=None):
     """Set the item with the given id to the following data."""
     id = ItemID(id)
     prf = self.prf.get_parent_proof(id)
     prf.items[id.last()] = ProofItem(id,
                                      rule,
                                      args=args,
                                      prevs=prevs,
                                      th=th)
     self.check_proof(compute_only=True)
Exemplo n.º 5
0
 def testRewrite2(self):
     Ta = TVar("a")
     a = Var("a", Ta)
     b = Var("b", Ta)
     eq_a = Term.mk_equals(a, a)
     goal = Thm.mk_equals(mk_if(eq_a, b, a), b)
     rewrite_tac = tactic.rewrite()
     pt = rewrite_tac.get_proof_term(thy, ProofTerm.sorry(goal), args='if_P')
     prf = pt.export()
     self.assertEqual(prf.items[0], ProofItem(0, 'sorry', th=Thm.mk_equals(a, a)))
     self.assertEqual(thy.check_proof(prf), goal)
Exemplo n.º 6
0
    def add_line_before(self, id, n):
        """Add n lines before the given id."""
        id = ItemID(id)
        prf = self.prf.get_parent_proof(id)
        split = id.last()
        new_items = [ProofItem(id.incr_id(i), "") for i in range(n)]
        prf.items = prf.items[:split] + new_items + prf.items[split:]
        for item in prf.items[split + n:]:
            item.incr_proof_item(id, n)

        self.check_proof(compute_only=True)
Exemplo n.º 7
0
    def add_line_after(self, id):
        """Add given line after the given id."""
        id = id_force_tuple(id)
        prf = self.prf.get_parent_proof(id)
        new_id = incr_id(id, 1)
        split = new_id[-1]
        prf.items = prf.items[:split] + [ProofItem(new_id, "")
                                         ] + prf.items[split:]
        for item in prf.items[split + 1:]:
            incr_proof_item(item, new_id, 1)

        self.check_proof(compute_only=True)
Exemplo n.º 8
0
def parse_proof_rule(thy, ctxt, data):
    """Parse a proof rule.

    data is a dictionary containing id, rule, args, prevs, and th.
    The result is a ProofItem object.

    This need to be written by hand because different proof rules
    require different parsing of the arguments.

    """
    id, rule = data['id'], data['rule']

    if rule == "":
        return ProofItem(id, "")

    if data['th'] == "":
        th = None
    else:
        th = parse_thm(thy, ctxt, data['th'])

    sig = thy.get_proof_rule_sig(rule)
    args = parse_args(thy, ctxt, sig, data['args'])
    return ProofItem(id, rule, args=args, prevs=data['prevs'], th=th)
Exemplo n.º 9
0
    def testParseProofRule(self):
        test_data = [
            ({
                'id': "0",
                'rule': "theorem",
                'args': "conjD1",
                'prevs': [],
                'th': ""
            }, ProofItem(0, "theorem", args="conjD1", prevs=[])),
            ({
                'id': "2",
                'rule': "implies_elim",
                'args': "",
                'prevs': ["1", "0"],
                'th': ""
            }, ProofItem(2, "implies_elim", prevs=[1, 0])),
            ({
                'id': "5",
                'rule': "substitution",
                'args': "{A: B, B: A}",
                'prevs': ["4"],
                'th': ""
            }, ProofItem(5, "substitution", args={
                'A': B,
                'B': A
            }, prevs=[4])),
            ({
                'id': "8",
                'rule': "implies_intr",
                'args': "conj A B",
                'prevs': ["7"],
                'th': ""
            }, ProofItem(8,
                         "implies_intr",
                         args=logic.mk_conj(A, B),
                         prevs=[7])),
            ({
                'id': "0",
                'rule': "sorry",
                'args': "",
                'prevs': [],
                'th': "conj A B |- conj B A"
            },
             ProofItem(0,
                       "sorry",
                       th=Thm([logic.mk_conj(A, B)], logic.mk_conj(B, A)))),
            ({
                'id': "1",
                'rule': "",
                'args': "",
                'prevs': [],
                'th': ""
            }, ProofItem(1, "")),
            ({
                'id': "5",
                'rule': "apply_theorem_for",
                'args': "disjI1, {}, {A: B, B: A}",
                'prevs': [4],
                'th': ""
            },
             ProofItem(5,
                       "apply_theorem_for",
                       args=("disjI1", {}, {
                           'A': B,
                           'B': A
                       }),
                       prevs=[4])),
        ]

        for s, res in test_data:
            self.assertEqual(parser.parse_proof_rule(thy, ctxt, s), res)
Exemplo n.º 10
0
    def testParseProofRule(self):
        A = Var('A', BoolType)
        B = Var('B', BoolType)
        test_data = [
            ({
                'id': "0",
                'rule': "theorem",
                'args': "conjD1",
                'prevs': [],
                'th': ""
            }, ProofItem(0, "theorem", args="conjD1", prevs=[])),
            ({
                'id': "2",
                'rule': "implies_elim",
                'args': "",
                'prevs': ["1", "0"],
                'th': ""
            }, ProofItem(2, "implies_elim", prevs=[1, 0])),
            ({
                'id': "5",
                'rule': "substitution",
                'args': "{A: B, B: A}",
                'prevs': ["4"],
                'th': ""
            }, ProofItem(5, "substitution", args=Inst(A=B, B=A), prevs=[4])),
            ({
                'id': "8",
                'rule': "implies_intr",
                'args': "conj A B",
                'prevs': ["7"],
                'th': ""
            }, ProofItem(8, "implies_intr", args=And(A, B), prevs=[7])),
            ({
                'id': "0",
                'rule': "sorry",
                'args': "",
                'prevs': [],
                'th': "conj A B |- conj B A"
            }, ProofItem(0, "sorry", th=Thm([And(A, B)], And(B, A)))),
            ({
                'id': "1",
                'rule': "",
                'args': "",
                'prevs': [],
                'th': ""
            }, ProofItem(1, "")),
            ({
                'id': "5",
                'rule': "apply_theorem_for",
                'args': "disjI1, {A: B, B: A}",
                'prevs': [4],
                'th': ""
            },
             ProofItem(5,
                       "apply_theorem_for",
                       args=("disjI1", Inst(A=B, B=A)),
                       prevs=[4])),
        ]

        context.set_context('logic_base', vars={'A': 'bool', 'B': 'bool'})
        for s, res in test_data:
            self.assertEqual(parser.parse_proof_rule(s), res)