Example #1
0
    def testBetaConv(self):
        test_data = [
            (Comb(Abs("x", Ta, B0), c), c),
            (Comb(Abs("x", Ta, a), c), a),
        ]

        for t, res in test_data:
            self.assertEqual(t.beta_conv(), res)
Example #2
0
    def testCheckedGetTypeFail(self):
        test_data = [
            Comb(a, a),
            Comb(f, f),
            f(a, a),
            f(b),
            Comb(Abs("x", Ta, B0), b),
        ]

        for t in test_data:
            self.assertRaises(TypeCheckException, t.checked_get_type)
Example #3
0
    def testCheckProofMacro(self):
        """Proof checking with simple macro."""
        thy = Theory.EmptyTheory()
        thy.add_proof_macro("beta_conv_rhs", beta_conv_rhs_macro())
        
        t = Comb(Abs("x", Ta, Bound(0)), x)

        prf = Proof()
        prf.add_item(0, "reflexive", args=t)
        prf.add_item(1, "beta_conv_rhs", prevs=[0])
        th = Thm.mk_equals(t,x)

        # Check obtaining signature
        self.assertEqual(thy.get_proof_rule_sig("beta_conv_rhs"), Term)

        # Check proof without trusting beta_conv_rhs
        rpt = ProofReport()
        self.assertEqual(thy.check_proof(prf, rpt), th)
        self.assertEqual(rpt.steps_stat(), (0, 3, 0))
        self.assertEqual(rpt.macros_expand, {"beta_conv_rhs"})

        # Check proof while trusting beta_conv_rhs
        rpt = ProofReport()
        self.assertEqual(thy.check_proof(prf, rpt, check_level=1), th)
        self.assertEqual(rpt.steps_stat(), (0, 1, 1))
        self.assertEqual(rpt.macros_eval, {"beta_conv_rhs"})
Example #4
0
    def testCheckedExtend(self):
        """Checked extension: adding an axiom."""
        id_simps = Eq(Comb(Const("id", TFun(Ta,Ta)), x), x)
        exts = [extension.Theorem("id.simps", Thm([], id_simps))]

        ext_report = theory.thy.checked_extend(exts)
        self.assertEqual(theory.get_theorem("id.simps", svar=False), Thm([], id_simps))
        self.assertEqual(ext_report.get_axioms(), [("id.simps", Thm([], id_simps))])
Example #5
0
    def testCheckedExtend(self):
        """Checked extension: adding an axiom."""
        thy = Theory.EmptyTheory()
        thy_ext = TheoryExtension()

        id_simps = Term.mk_equals(Comb(Const("id", TFun(Ta,Ta)),x), x)
        thy_ext.add_extension(Theorem("id.simps", Thm([], id_simps)))

        ext_report = thy.checked_extend(thy_ext)
        self.assertEqual(thy.get_theorem("id.simps"), Thm([], id_simps))
        self.assertEqual(ext_report.get_axioms(), [("id.simps", Thm([], id_simps))])
Example #6
0
    def testCheckedGetType(self):
        test_data = [
            (a, Ta),
            (c, Ta),
            (f(a), Tb),
            (f2(a, a), Tb),
            (f(g(a)), Tb),
            (Comb(Abs("x", Ta, B0), a), Ta),
        ]

        for t, T in test_data:
            self.assertEqual(t.checked_get_type(), T)
Example #7
0
    def testCheckTermFail(self):
        test_data = [
            Const("random", Ta),
            Const("equals", TFun(Ta, Tb, BoolType)),
            Const("equals", TFun(Ta, Ta, Tb)),
            Const("implies", TFun(Ta, Ta, BoolType)),
            Comb(Const("random", Tab), x),
            f(Const("random", Ta)),
            Abs("x", Ta, Const("random", Ta)),
        ]

        for t in test_data:
            self.assertRaises(TheoryException, theory.thy.check_term, t)
Example #8
0
    def testSubstType(self):
        test_data = [
            (a, {
                "a": Tb
            }, Var("a", Tb)),
            (c, {
                "a": Tb
            }, Const("c", Tb)),
            (f(a), {
                "a": Tb
            }, Comb(Var("f", TFun(Tb, Tb)), Var("a", Tb))),
            (Abs("x", Ta, B0), {
                "a": Tb
            }, Abs("x", Tb, B0)),
            (Abs("x", Ta, a), {
                "a": Tb
            }, Abs("x", Tb, Var("a", Tb))),
        ]

        for t, tyinst, res in test_data:
            self.assertEqual(t.subst_type(tyinst), res)
Example #9
0
    def testCheckProofFail7(self):
        """Typing error: type-checking failed."""
        prf = Proof(Comb(Var("P", TFun(Tb, BoolType)), x))

        self.assertRaisesRegex(CheckProofException, "typing error", theory.check_proof, prf)
Example #10
0
 def comb(self, fun, arg):
     return Comb(fun, arg)
Example #11
0
 def testAbstractOverFail(self):
     self.assertRaises(TermException, Comb(f, a).abstract_over, Comb(f, a))
Example #12
0
 def testBetaConv(self):
     t = Comb(Abs("x", Ta, Bound(0)), x)
     self.assertEqual(Thm.beta_conv(t), Thm.mk_equals(t, x))