Exemplo n.º 1
0
    def testExport3(self):
        """Case with atoms."""
        pt1 = ProofTerm.atom(0, Thm([], Eq(x, y)))
        pt2 = ProofTerm.atom(1, Thm([], Eq(y, z)))
        pt3 = pt1.transitive(pt2)

        prf = Proof()
        prf.add_item(0, rule="sorry", th=Thm([], Eq(x, y)))
        prf.add_item(1, rule="sorry", th=Thm([], Eq(y, z)))
        pt3.export(prf=prf)

        self.assertEqual(theory.check_proof(prf), Thm([], Eq(x, z)))
Exemplo n.º 2
0
    def search(self, state, id, prevs, data=None):
        cur_item = state.get_proof_item(id)
        prevs = [
            ProofTerm.atom(prev,
                           state.get_proof_item(prev).th) for prev in prevs
        ]

        results = []

        def search_thm(th_name):
            try:
                pt = tactic.resolve().get_proof_term(cur_item.th,
                                                     args=th_name,
                                                     prevs=prevs)
                results.append({
                    "theorem": th_name,
                    "_goal": [gap.prop for gap in pt.gaps]
                })
            except (AssertionError, matcher.MatchException):
                pass

        if data:
            search_thm(data['theorem'])
        else:
            for th_name in theory.thy.get_data("theorems"):
                if 'hint_resolve' in theory.thy.get_attributes(th_name):
                    search_thm(th_name)

        return sorted(results, key=lambda d: d['theorem'])
Exemplo n.º 3
0
    def apply(self, state, id, data, prevs):
        try:
            prev_pts = [
                ProofTerm.atom(prev,
                               state.get_proof_item(prev).th) for prev in prevs
            ]
            sym_b = 'sym' in data and data['sym'] == 'true'
            pt = logic.rewrite_fact_macro(sym=sym_b).get_proof_term(
                data['theorem'], prev_pts)
        except InvalidDerivationException as e:
            raise e

        state.add_line_before(id, 1)
        if 'sym' in data and data['sym'] == 'true':
            state.set_line(id,
                           'rewrite_fact_sym',
                           args=data['theorem'],
                           prevs=prevs)
        else:
            state.set_line(id,
                           'rewrite_fact',
                           args=data['theorem'],
                           prevs=prevs)

        id2 = id.incr_id(1)
        new_id = state.find_goal(state.get_proof_item(id2).th, id2)
        if new_id is not None:
            state.replace_id(id2, new_id)
Exemplo n.º 4
0
    def search(self, state, id, prevs, data=None):
        cur_item = state.get_proof_item(id)
        prevs = [
            ProofTerm.atom(prev,
                           state.get_proof_item(prev).th) for prev in prevs
        ]

        results = []

        def search_thm(th_name):
            try:
                pt = tactic.rule().get_proof_term(cur_item.th,
                                                  args=th_name,
                                                  prevs=prevs)
                results.append({
                    "theorem": th_name,
                    "_goal": [gap.prop for gap in pt.gaps]
                })
            except theory.ParameterQueryException:
                # In this case, still suggest the result
                results.append({"theorem": th_name})
            except (AssertionError, matcher.MatchException):
                pass

        if data:
            search_thm(data['theorem'])
        else:
            for th_name in theory.thy.get_data("theorems"):
                if 'hint_backward' in theory.thy.get_attributes(th_name) or \
                   ('hint_backward1' in theory.thy.get_attributes(th_name) and len(prevs) >= 1):
                    search_thm(th_name)

        return sorted(results, key=lambda d: d['theorem'])
Exemplo n.º 5
0
    def search(self, state, id, prevs, data=None):
        cur_item = state.get_proof_item(id)
        prevs = [
            ProofTerm.atom(prev,
                           state.get_proof_item(prev).th) for prev in prevs
        ]

        results = []

        def search_thm(th_name, sym):
            try:
                sym_b = True if sym == 'true' else False
                pt = tactic.rewrite_goal(sym=sym_b).get_proof_term(
                    cur_item.th, args=th_name, prevs=prevs)
                results.append({
                    "theorem": th_name,
                    "sym": sym,
                    "_goal": [gap.prop for gap in pt.gaps]
                })
            except (AssertionError, matcher.MatchException) as e:
                pass

        if data:
            sym = 'false'
            if 'sym' in data:
                sym = data['sym']
            search_thm(data['theorem'], sym)
        else:
            for th_name in theory.thy.get_data("theorems"):
                if 'hint_rewrite' in theory.thy.get_attributes(th_name):
                    search_thm(th_name, 'false')
                if 'hint_rewrite_sym' in theory.thy.get_attributes(th_name):
                    search_thm(th_name, 'true')

        return sorted(results, key=lambda d: d['theorem'])
Exemplo n.º 6
0
    def search(self, state, id, prevs, data=None):
        cur_item = state.get_proof_item(id)
        prevs = [
            ProofTerm.atom(prev,
                           state.get_proof_item(prev).th) for prev in prevs
        ]

        results = []

        def search_thm(th_name, sym):
            try:
                sym_b = True if sym == 'true' else False
                pt = logic.rewrite_fact_macro(sym=sym_b).get_proof_term(
                    th_name, prevs)
                results.append({
                    "theorem": th_name,
                    "sym": sym,
                    "_fact": [pt.prop]
                })
            except (AssertionError, matcher.MatchException,
                    InvalidDerivationException) as e:
                # print(e)
                pass

        if data:
            search_thm(data['theorem'], data['sym'])
        else:
            for th_name in theory.thy.get_data("theorems"):
                if 'hint_rewrite' in theory.thy.get_attributes(th_name):
                    search_thm(th_name, 'false')
                if 'hint_rewrite_sym' in theory.thy.get_attributes(th_name):
                    search_thm(th_name, 'true')

        return sorted(results, key=lambda d: d['theorem'])
Exemplo n.º 7
0
    def apply_tactic(self, id, tactic, args=None, prevs=None):
        id = ItemID(id)
        prevs = [ItemID(prev) for prev in prevs] if prevs else []
        prevs = [
            ProofTerm.atom(prev,
                           self.get_proof_item(prev).th) for prev in prevs
        ]

        cur_item = self.get_proof_item(id)
        assert cur_item.rule == "sorry", "apply_tactic: id is not a gap"

        pt = tactic.get_proof_term(cur_item.th, args=args, prevs=prevs)
        new_prf = pt.export(prefix=id, subproof=False)

        self.add_line_before(id, len(new_prf.items) - 1)
        for i, item in enumerate(new_prf.items):
            cur_id = item.id
            prf = self.prf.get_parent_proof(cur_id)
            prf.items[cur_id.last()] = item
        self.check_proof(compute_only=True)

        # Test if the goals are already proved:
        for item in new_prf.items:
            if item.rule == 'sorry':
                new_id = self.find_goal(
                    self.get_proof_item(item.id).th, item.id)
                if new_id is not None:
                    self.replace_id(item.id, new_id)

        # Resolve trivial subgoals
        for item in new_prf.items:
            if item.rule == 'sorry':
                if logic.trivial_macro().can_eval(item.th.prop):
                    self.set_line(item.id, 'trivial', args=item.th.prop)
Exemplo n.º 8
0
    def expand(self, prefix, args, prevs):
        """Obtain the detailed proof of the derivation.
        
        Input is the current id prefix, the current theory,
        argument of the proof method, and the list of ids and statements
        of previous theorems.

        """
        pts = tuple([ProofTerm.atom(id, prev) for id, prev in prevs])
        return self.get_proof_term(args, pts).export(prefix)
Exemplo n.º 9
0
 def search(self, state, id, prevs, data=None):
     prevs = [
         ProofTerm.atom(prev,
                        state.get_proof_item(prev).th) for prev in prevs
     ]
     try:
         macro = logic.rewrite_fact_with_prev_macro()
         pt = macro.get_proof_term(args=None, pts=prevs)
         return [{"_fact": [pt.prop]}]
     except (AssertionError, matcher.MatchException):
         return []
Exemplo n.º 10
0
 def search(self, state, id, prevs, data=None):
     try:
         cur_item = state.get_proof_item(id)
         prevs = [
             ProofTerm.atom(prev,
                            state.get_proof_item(prev).th) for prev in prevs
         ]
         pt = tactic.rewrite_goal_with_prev().get_proof_term(cur_item.th,
                                                             args=None,
                                                             prevs=prevs)
     except (AssertionError, matcher.MatchException):
         return []
     else:
         return [{"_goal": [gap.prop for gap in pt.gaps]}]
Exemplo n.º 11
0
 def search(self, state, id, prevs, data=None):
     cur_item = state.get_proof_item(id)
     prevs = [
         ProofTerm.atom(prev,
                        state.get_proof_item(prev).th) for prev in prevs
     ]
     try:
         pt = tactic.apply_prev().get_proof_term(cur_item.th,
                                                 args=None,
                                                 prevs=prevs)
         return [{"_goal": [gap.prop for gap in pt.gaps]}]
     except (AssertionError, matcher.MatchException):
         return []
     except theory.ParameterQueryException:
         # In this case, still suggest the result
         return [{}]
Exemplo n.º 12
0
    def apply(self, state, id, data, prevs):
        try:
            prev_pts = [
                ProofTerm.atom(prev,
                               state.get_proof_item(prev).th) for prev in prevs
            ]
            pt = logic.rewrite_fact_with_prev_macro().get_proof_term(
                None, prev_pts)
        except AssertionError as e:
            raise e

        state.add_line_before(id, 1)
        state.set_line(id, 'rewrite_fact_with_prev', prevs=prevs)

        id2 = id.incr_id(1)
        new_id = state.find_goal(state.get_proof_item(id2).th, id2)
        if new_id is not None:
            state.replace_id(id2, new_id)
Exemplo n.º 13
0
    def run_test(self,
                 thy_name,
                 tactic,
                 *,
                 vars=None,
                 prevs=None,
                 goal,
                 args=None,
                 new_goals=None,
                 failed=None):
        """Test a single invocation of a tactic."""
        context.set_context(thy_name, vars=vars)

        assms = [parser.parse_term(prev)
                 for prev in prevs] if prevs is not None else []
        prf = Proof(*assms)
        prevs = [
            ProofTerm.atom(i, Thm.assume(assm)) for i, assm in enumerate(assms)
        ]
        goal = parser.parse_term(goal)
        goal_pt = ProofTerm.sorry(Thm(assms, goal))

        # Invoke the tactic to get the proof term
        if failed is not None:
            self.assertRaises(failed,
                              tactic.get_proof_term,
                              goal_pt,
                              prevs=prevs,
                              args=args)
            return

        pt = tactic.get_proof_term(goal_pt, prevs=prevs, args=args)

        # Export and check proof
        prefix = ItemID(len(prevs) -
                        1) if len(prevs) > 0 else ItemID(len(prevs))
        prf = pt.export(prefix=prefix, prf=prf, subproof=False)
        self.assertEqual(theory.check_proof(prf), Thm(assms, goal))

        # Test agreement of new goals
        new_goals = [parser.parse_term(new_goal) for new_goal in new_goals
                     ] if new_goals is not None else []
        concls = [goal.prop for goal in prf.get_sorrys()]
        self.assertEqual(new_goals, concls)