Пример #1
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)
Пример #2
0
 def testAddZeroRight(self):
     """Proof of n + 0 = n by induction."""
     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")
     state.rewrite_goal(0, "plus_def_1")
     state.introduction(1, names=["n"])
     state.rewrite_goal((1, 2), "plus_def_2")
     state.rewrite_goal_with_prev((1, 2), (1, 1))
     self.assertEqual(state.check_proof(no_gaps=True), Thm.mk_equals(nat.plus(n, nat.zero), n))
Пример #3
0
 def testRewrite(self):
     n = Var('n', natT)
     goal = Thm.mk_equals(plus(zero, n), n)
     rewrite_tac = tactic.rewrite()
     pt = rewrite_tac.get_proof_term(thy, ProofTerm.sorry(goal), args='plus_def_1')
     prf = pt.export()
     self.assertEqual(thy.check_proof(prf), goal)
Пример #4
0
 def testInduct(self):
     n = Var('n', natT)
     goal = Thm([], Term.mk_equals(plus(n, zero), n))
     induct_tac = tactic.var_induct()
     pt = induct_tac.get_proof_term(thy, ProofTerm.sorry(goal), args=('nat_induct', n))
     prf = pt.export()
     self.assertEqual(thy.check_proof(prf), goal)
Пример #5
0
 def testRule4(self):
     n = Var('n', natT)
     goal = Thm([], Term.mk_equals(plus(n, zero), n))
     inst = {'P': Term.mk_abs(n, goal.prop), 'x': n}
     pt = tactic.rule().get_proof_term(thy, ProofTerm.sorry(goal), args=('nat_induct', ({}, inst)))
     prf = pt.export()
     self.assertEqual(thy.check_proof(prf), goal)
Пример #6
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)
Пример #7
0
 def testAddZeroRight(self):
     """Proof of n + 0 = n by induction."""
     thy = basic.load_theory('nat')
     n = Var("n", nat.natT)
     eq = Term.mk_equals
     prf = Proof()
     prf.add_item(0, "theorem", args="nat_induct")
     prf.add_item(1,
                  "substitution",
                  args={
                      "P": Term.mk_abs(n, eq(nat.plus(n, nat.zero), n)),
                      "x": n
                  },
                  prevs=[0])
     prf.add_item(2, "beta_norm", prevs=[1])
     prf.add_item(3, "theorem", args="plus_def_1")
     prf.add_item(4, "substitution", args={"n": nat.zero}, prevs=[3])
     prf.add_item(5, "implies_elim", prevs=[2, 4])
     prf.add_item(6, "assume", args=eq(nat.plus(n, nat.zero), n))
     prf.add_item(7, "theorem", args="plus_def_2")
     prf.add_item(8,
                  "substitution",
                  args={
                      "m": n,
                      "n": nat.zero
                  },
                  prevs=[7])
     prf.add_item(9, "arg_combination", args=nat.Suc, prevs=[6])
     prf.add_item(10, "transitive", prevs=[8, 9])
     prf.add_item(11,
                  "implies_intr",
                  args=eq(nat.plus(n, nat.zero), n),
                  prevs=[10])
     prf.add_item(12, "forall_intr", args=n, prevs=[11])
     prf.add_item(13, "implies_elim", prevs=[5, 12])
     th = Thm.mk_equals(nat.plus(n, nat.zero), n)
     self.assertEqual(thy.check_proof(prf), th)
Пример #8
0
    def testPrintUnicode(self):
        test_data = [
            (conj(A, B), "A ∧ B"),
            (disj(A, B), "A ∨ B"),
            (imp(A, B), "A ⟶ B"),
            (abs(a, P(a)), "λa. P a"),
            (all(a, P(a)), "∀a. P a"),
            (exists(a, P(a)), "∃a. P a"),
            (neg(A), "¬A"),
            (nat.plus(m, n), "m + n"),
            (nat.times(m, n), "m * n"),
        ]

        for t, s in test_data:
            self.assertEqual(printer.print_term(thy, t, unicode=True), s)
Пример #9
0
    def testPrintArithmetic(self):
        test_data = [
            (nat.plus(m, n), "m + n"),
            (nat.plus(nat.plus(m, n), p), "m + n + p"),
            (nat.plus(m, nat.plus(n, p)), "m + (n + p)"),
            (nat.times(m, n), "m * n"),
            (nat.times(nat.times(m, n), p), "m * n * p"),
            (nat.times(m, nat.times(n, p)), "m * (n * p)"),
            (nat.plus(m, nat.times(n, p)), "m + n * p"),
            (nat.times(m, nat.plus(n, p)), "m * (n + p)"),
            (nat.zero, "0"),
            (nat.plus(nat.zero, nat.zero), "0 + 0"),
            (nat.times(m, nat.zero), "m * 0"),
        ]

        for t, s in test_data:
            self.assertEqual(printer.print_term(thy, t), s)
Пример #10
0
 def plus(self, lhs, rhs):
     return nat.plus(lhs, rhs)
Пример #11
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"])
Пример #12
0
 def testPlus(self):
     self.assertEqual(nat.mk_plus(), zero)
     self.assertEqual(nat.mk_plus(zero), zero)
     self.assertEqual(nat.mk_plus(one), one)
     self.assertEqual(nat.mk_plus(zero, one), nat.plus(zero, one))
     self.assertEqual(nat.mk_plus(*([zero]*3)), nat.plus(nat.plus(zero, zero), zero))
Пример #13
0
natFunT = TFun(natT, natT)
Sem = hoare.Sem(natFunT)
Skip = hoare.Skip(natFunT)
Assign = hoare.Assign(natT, natT)
Seq = hoare.Seq(natFunT)
Cond = hoare.Cond(natFunT)
While = hoare.While(natFunT)
Valid = hoare.Valid(natFunT)
zero = nat.zero
one = nat.one

eq = Term.mk_equals
abs = Term.mk_abs
s = Var("s", natFunT)
assn_true = abs(s, logic.true)
incr_one = Assign(zero, abs(s, nat.plus(s(zero), one)))


def fun_upd_of_seq(*ns):
    return mk_fun_upd(mk_const_fun(natT, zero),
                      *[nat.to_binary(n) for n in ns])


class HoareTest(unittest.TestCase):
    def testEvalSem(self):
        com = Seq(Assign(zero, abs(s, one)),
                  Assign(one, abs(s, nat.to_binary(2))))
        st = mk_const_fun(natT, zero)
        st2 = fun_upd_of_seq(0, 1, 1, 2)
        goal = Sem(com, st, st2)
        prf = hoare.eval_Sem_macro().get_proof_term(thy, goal, []).export()
Пример #14
0
 def plus_expr(self, e1, e2):
     return nat.plus(e1, e2)