Example #1
0
 def testConjComm(self):
     """Proof of A & B --> B & A."""
     state = ProofState.init_state(thy, [A, B], [conj(A, B)], conj(B, A))
     state.apply_backward_step(1, "conjI")
     state.apply_backward_step(1, "conjD2", prevs=[0])
     state.apply_backward_step(2, "conjD1", prevs=[0])
     self.assertEqual(state.check_proof(no_gaps=True), Thm.mk_implies(conj(A, B), conj(B, A)))
Example #2
0
 def testJsonData(self):
     state = ProofState.parse_init_state(
         thy, {'vars': {'A': 'bool', 'B': 'bool'}, 'prop': "A & B --> B & A"})
     json_data = state.json_data()
     self.assertEqual(len(json_data['vars']), 2)
     self.assertEqual(len(json_data['proof']), 3)
     self.assertIn('report', json_data)
Example #3
0
 def testApplyInduction(self):
     thy = basic.load_theory('nat')
     n = Var("n", nat.natT)
     state = ProofState.init_state(thy, [n], [], Term.mk_equals(nat.plus(n, nat.zero), n))
     state.apply_induction(0, "nat_induct", "n")
     self.assertEqual(state.check_proof(), Thm([], Term.mk_equals(nat.plus(n, nat.zero), n)))
     self.assertEqual(len(state.prf.items), 3)
Example #4
0
    def testAddLineAfter(self):
        state = ProofState.init_state(thy, [A, B], [conj(A, B)], conj(B, A))

        state.add_line_after(0)
        self.assertEqual(len(state.prf.items), 4)
        self.assertEqual(state.check_proof(), Thm.mk_implies(conj(A, B), conj(B, A)))
        self.assertEqual(state.prf.items[1].rule, "")
Example #5
0
 def testDoubleNegInv(self):
     """Proof of ~~A --> A."""
     state = ProofState.init_state(thy, [A], [neg(neg(A))], A)
     state.apply_cases(1, A)
     state.introduction(1)
     state.introduction(2)
     state.apply_backward_step((2, 1), "negE_gen", prevs=[0])
     self.assertEqual(state.check_proof(no_gaps=True), Thm.mk_implies(neg(neg(A)), A))
Example #6
0
 def testDisjComm(self):
     """Proof of A | B --> B | A."""
     state = ProofState.init_state(thy, [A, B], [disj(A, B)], disj(B, A))
     state.apply_backward_step(1, "disjE", prevs=[0])
     state.introduction(1)
     state.apply_backward_step((1, 1), "disjI2", prevs=[(1, 0)])
     state.introduction(2)
     state.apply_backward_step((2, 1), "disjI1", prevs=[(2, 0)])
     self.assertEqual(state.check_proof(no_gaps=True), Thm.mk_implies(disj(A, B), disj(B, A)))
Example #7
0
 def testParseProof2(self):
     data = {
         'vars': {},
         'proof': [
             {'id': 0, 'rule': 'variable', 'args': "a, 'a", 'prevs': [], 'th': ''}
         ]
     }
     state = ProofState.parse_proof(thy, data)
     self.assertEqual(len(state.prf.items), 1)
Example #8
0
 def testIntroduction3(self):
     Ta = TVar("a")
     A = Var("A", TFun(Ta, boolT))
     B = Var("B", TFun(Ta, boolT))
     x = Var("x", Ta)
     state = ProofState.init_state(thy, [A, B], [], Term.mk_all(x, imp(A(x), B(x))))
     state.introduction(0, ["x"])
     self.assertEqual(state.check_proof(), Thm([], Term.mk_all(x, imp(A(x), B(x)))))
     self.assertEqual(len(state.prf.items), 1)
     self.assertEqual(len(state.prf.items[0].subproof.items), 4)
Example #9
0
 def testRewriteGoalWithAssum(self):
     Ta = TVar("a")
     a = Var("a", Ta)
     b = Var("b", Ta)
     eq_a = Term.mk_equals(a, a)
     if_t = logic.mk_if(eq_a, b, a)
     state = ProofState.init_state(thy, [a, b], [], Term.mk_equals(if_t, b))
     state.rewrite_goal(0, "if_P")
     state.set_line(0, "reflexive", args=a)
     self.assertEqual(state.check_proof(no_gaps=True), Thm.mk_equals(if_t, b))
Example #10
0
 def testPierce(self):
     thy = basic.load_theory('logic_base')
     state = ProofState.init_state(thy, [A, B], [imp(imp(A, B), A)], A)
     state.apply_cases(1, A)
     state.introduction(1)
     state.introduction(2)
     state.apply_prev((2, 1), 0)
     state.introduction((2, 1))
     state.apply_backward_step((2, 1, 1), 'negE_gen', prevs=[(2, 0)])
     self.assertEqual(state.check_proof(no_gaps=True), Thm([], imp(imp(imp(A, B), A), A)))
Example #11
0
    def testAddLineBefore(self):
        state = ProofState.init_state(thy, [A, B], [conj(A, B)], conj(B, A))

        state.add_line_before(2, 1)
        self.assertEqual(len(state.prf.items), 4)
        self.assertEqual(state.check_proof(), Thm.mk_implies(conj(A, B), conj(B, A)))

        state.add_line_before(2, 3)
        self.assertEqual(len(state.prf.items), 7)
        self.assertEqual(state.check_proof(), Thm.mk_implies(conj(A, B), conj(B, A)))
Example #12
0
def init_empty_proof():
    """Initialize empty proof."""
    data = json.loads(request.get_data().decode("utf-8"))
    if data:
        thy = basic.load_theory(data['theory_name'],
                                limit=('thm', data['thm_name']),
                                user=user_info['username'])
        cell = ProofState.parse_init_state(thy, data)
        cells[data['id']] = cell
        return jsonify(cell.json_data())
    return jsonify({})
Example #13
0
 def testMultZeroRight(self):
     """Proof of n * 0 = 0 by induction."""
     thy = basic.load_theory('nat')
     n = Var("n", nat.natT)
     state = ProofState.init_state(thy, [n], [], Term.mk_equals(nat.times(n, nat.zero), nat.zero))
     state.apply_induction(0, "nat_induct", "n")
     state.rewrite_goal(0, "times_def_1")
     state.introduction(1, names=["n"])
     state.rewrite_goal((1, 2), "times_def_2")
     state.rewrite_goal((1, 2), "plus_def_1")
     self.assertEqual(state.check_proof(no_gaps=True), Thm.mk_equals(nat.times(n, nat.zero), nat.zero))
Example #14
0
 def testParseProof(self):
     data = {
         'vars': {'A': 'bool', 'B': 'bool'},
         'proof': [
             {'id': 0, 'rule': 'assume', 'args': 'A & B', 'prevs': [], 'th': ''},
             {'id': 1, 'rule': 'sorry', 'args': '', 'prevs': [], 'th': 'A & B |- B & A'},
             {'id': 2, 'rule': 'implies_intr', 'args': 'A & B', 'prevs': [1], 'th': ''}
         ]
     }
     state = ProofState.parse_proof(thy, data)
     self.assertEqual(len(state.vars), 2)
     self.assertEqual(len(state.prf.items), 3)
Example #15
0
 def testAVal(self):
     thy = basic.load_theory('expr')
     th = thy.get_theorem('aval_test2')
     state = ProofState.init_state(thy, [], [], th.prop)
     state.rewrite_goal(0, "aval_def_3")
     state.rewrite_goal(0, "aval_def_2")
     state.rewrite_goal(0, "aval_def_1")
     state.rewrite_goal(0, "fun_upd_def")
     state.rewrite_goal(0, "if_not_P")
     state.set_line(0, "nat_norm", args=Term.mk_equals(nat.plus(nat.zero, nat.to_binary(5)), nat.to_binary(5)))
     state.apply_backward_step(1, "nat_zero_Suc_neq")
     self.assertEqual(state.check_proof(no_gaps=True), th)
Example #16
0
 def testAppendNil(self):
     """Proof of xs @ [] = xs by induction."""
     thy = basic.load_theory('list')
     Ta = TVar("a")
     xs = Var("xs", list.listT(Ta))
     nil = list.nil(Ta)
     state = ProofState.init_state(thy, [xs], [], Term.mk_equals(list.mk_append(xs, nil), xs))
     state.apply_induction(0, "list_induct", "xs")
     state.apply_backward_step(0, "append_def_1")
     state.introduction(1, names=["x", "xs"])
     state.rewrite_goal((1, 3), "append_def_2")
     self.assertEqual(state.get_ctxt((1, 3)), {'x': Ta, 'xs': list.listT(Ta)})
     state.rewrite_goal_with_prev((1, 3), (1, 2))
     self.assertEqual(state.check_proof(no_gaps=True), Thm.mk_equals(list.mk_append(xs, nil), xs))
Example #17
0
def init_saved_proof():
    """Load saved proof."""
    data = json.loads(request.get_data().decode("utf-8"))
    if data:
        try:
            thy = basic.load_theory(data['theory_name'],
                                    limit=('thm', data['thm_name']),
                                    user=user_info['username'])
            cell = ProofState.parse_proof(thy, data)
            cells[data['id']] = cell
            return jsonify(cell.json_data())
        except Exception as e:
            error = {"failed": e.__class__.__name__, "message": str(e)}
        return jsonify(error)
    return jsonify({})
Example #18
0
 def testExistsConj(self):
     """Proof of (?x. A x & B x) --> (?x. A x) & (?x. B x)."""
     Ta = TVar("a")
     A = Var("A", TFun(Ta, boolT))
     B = Var("B", TFun(Ta, boolT))
     x = Var("x", Ta)
     ex_conj = exists(x, conj(A(x), B(x)))
     conj_ex = conj(exists(x, A(x)), exists(x, B(x)))
     state = ProofState.init_state(thy, [A, B], [ex_conj], conj_ex)
     state.apply_backward_step(1, "exE", prevs=[0])
     state.introduction(1, "x")
     state.apply_backward_step((1, 2), "conjI")
     state.apply_forward_step((1, 2), "conjD1", prevs=[(1, 1)])
     state.apply_backward_step((1, 3), "exI", prevs=[(1, 2)])
     state.apply_forward_step((1, 4), "conjD2", prevs=[(1, 1)])
     state.apply_backward_step((1, 5), "exI", prevs=[(1, 4)])
     self.assertEqual(state.check_proof(no_gaps=True), Thm.mk_implies(ex_conj, conj_ex))
Example #19
0
 def testFunUpdTriv(self):
     thy = basic.load_theory('function')
     Ta = TVar("a")
     Tb = TVar("b")
     f = Var("f", TFun(Ta, Tb))
     a = Var("a", Ta)
     x = Var("x", Ta)
     prop = Term.mk_equals(function.mk_fun_upd(f, a, f(a)), f)
     state = ProofState.init_state(thy, [f, a], [], prop)
     state.apply_backward_step(0, "extension")
     state.introduction(0, names=["x"])
     state.rewrite_goal((0, 1), "fun_upd_eval")
     state.apply_cases((0, 1), Term.mk_equals(x, a))
     state.introduction((0, 1))
     state.rewrite_goal((0, 1, 1), "if_P")
     state.rewrite_goal_with_prev((0, 1, 1), (0, 1, 0))
     state.introduction((0, 2))
     state.rewrite_goal((0, 2, 1), "if_not_P")
     self.assertEqual(state.check_proof(no_gaps=True), Thm([], prop))
Example #20
0
 def testIntroduction2(self):
     state = ProofState.init_state(thy, [A, B], [], imp(A, B, conj(A, B)))
     state.introduction(0)
     self.assertEqual(state.check_proof(), Thm.mk_implies(A, B, conj(A, B)))
Example #21
0
 def testGetCtxt(self):
     state = ProofState.init_state(thy, [A, B], [conj(A, B)], conj(B, A))
     self.assertEqual(state.get_ctxt(0), {'A': boolT, 'B': boolT})
Example #22
0
 def testApplyBackwardStepThms(self):
     state = ProofState.init_state(thy, [A, B], [conj(A, B)], conj(B, A))
     search_res = state.apply_search(1, method.apply_backward_step())
     self.assertEqual([res['theorem'] for res in search_res], ["conjI"])
Example #23
0
 def testApplyForwardStep2(self):
     state = ProofState.init_state(thy, [A, B], [conj(A, B)], conj(B, A))
     state.apply_forward_step(1, "conjD2", prevs=[0])
     self.assertEqual(state.check_proof(), Thm.mk_implies(conj(A, B), conj(B, A)))
     item = state.get_proof_item((1,))
     self.assertEqual(item.th.concl, B)
Example #24
0
 def testApplyBackwardStepThms3(self):
     """Example of two results."""
     state = ProofState.init_state(thy, [A, B], [disj(A, B)], disj(B, A))
     search_res = state.apply_search(1, method.apply_backward_step())
     self.assertEqual([res['theorem'] for res in search_res], ["disjI1", "disjI2"])
Example #25
0
 def testParseInitState(self):
     state = ProofState.parse_init_state(
         thy, {'vars': {'A': 'bool', 'B': 'bool'}, 'prop': "A & B --> B & A"})
     self.assertEqual(len(state.prf.items), 3)
     self.assertEqual(state.check_proof(), Thm.mk_implies(conj(A, B), conj(B, A)))
Example #26
0
 def testInitProof2(self):
     state = ProofState.init_state(thy, [A, B], [A, B], conj(A, B))
     self.assertEqual(len(state.prf.items), 4)
     self.assertEqual(state.check_proof(), Thm.mk_implies(A, B, conj(A, B)))
Example #27
0
 def testApplyBackwardStep(self):
     state = ProofState.init_state(thy, [A, B], [conj(A, B)], conj(B, A))
     state.apply_backward_step(1, "conjI")
     self.assertEqual(state.check_proof(), Thm.mk_implies(conj(A, B), conj(B, A)))
     self.assertEqual(len(state.rpt.gaps), 2)
Example #28
0
 def testApplyForwardStepThms2(self):
     state = ProofState.init_state(thy, [A, B], [disj(A, B)], disj(B, A))
     search_res = state.apply_search(1, method.apply_forward_step(), prevs=[0])
     self.assertEqual([res['theorem'] for res in search_res], [])
Example #29
0
 def testApplyBackwardStep2(self):
     """Case where one or more assumption also needs to be matched."""
     state = ProofState.init_state(thy, [A, B], [disj(A, B)], disj(B, A))
     state.apply_backward_step(1, "disjE", prevs=[0])
     self.assertEqual(state.check_proof(), Thm.mk_implies(disj(A, B), disj(B, A)))
     self.assertEqual(len(state.rpt.gaps), 2)
Example #30
0
 def testRewriteGoalThms(self):
     thy = basic.load_theory('nat')
     n = Var("n", nat.natT)
     state = ProofState.init_state(thy, [n], [], Term.mk_equals(nat.plus(nat.zero, n), n))
     search_res = state.apply_search(0, method.rewrite_goal())
     self.assertEqual([res['theorem'] for res in search_res], ["plus_def_1"])