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]))
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]))
def testFunCombination(self): thy = basic.load_theory('logic_base') macro = logic_macro.fun_combination_macro() f_eq_g = Term.mk_equals(f, g) fx_eq_gx = Term.mk_equals(f(x), g(x)) th = Thm.assume(f_eq_g) res = Thm([f_eq_g], fx_eq_gx) self.assertEqual(macro.eval(thy, x, [th]), res) prf = Proof(f_eq_g) prf.add_item(1, "fun_combination", args=x, prevs=[0]) rpt = ProofReport() self.assertEqual(thy.check_proof(prf, rpt), res) self.assertEqual(rpt.macros_expand, {"fun_combination"}) self.assertEqual(rpt.prim_steps, 3)
def testArgCombination(self): thy = basic.load_theory('logic_base') macro = logic_macro.arg_combination_macro() x_eq_y = Term.mk_equals(x, y) fx_eq_fy = Term.mk_equals(f(x), f(y)) th = Thm.assume(x_eq_y) res = Thm([x_eq_y], fx_eq_fy) self.assertEqual(macro.eval(thy, f, [th]), res) prf = Proof(x_eq_y) prf.add_item(1, "arg_combination", args=f, prevs=[0]) rpt = ProofReport() self.assertEqual(thy.check_proof(prf, rpt), res) self.assertEqual(rpt.macros_expand, {"arg_combination"}) self.assertEqual(rpt.prim_steps, 3)
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)
def testAssume(self): self.assertEqual(Thm.assume(A), Thm([A], A))