示例#1
0
    def test_closing_14(self):
        # (!A|B)->(A->B)
        expr = Impl(Or(Not(Atom("A")), Atom("B")), Impl(Atom("A"), Atom("B")))

        builder = IpcTableauxBuilder(false_exprs=[expr])
        builder.auto_resolve()

        self.assertTrue(builder.is_closed())
示例#2
0
    def test_not_closing_4(self):
        # A&B | !A&B
        expr = Or(And(Atom("A"), Atom("B")), And(Not(Atom("A")), Atom("B")))

        builder = IpcTableauxBuilder(false_exprs=[expr])
        builder.auto_resolve()

        self.assertFalse(builder.is_closed())
示例#3
0
    def test_not_closing_6(self):
        # !!A->A
        expr = Impl(Not(Not(Atom("A"))), Atom("A"))

        builder = IpcTableauxBuilder(false_exprs=[expr])
        builder.auto_resolve()

        self.assertFalse(builder.is_closed())
示例#4
0
    def test_not_closing_1(self):
        # A
        expr = Atom("A")

        builder = IpcTableauxBuilder(false_exprs=[expr])
        builder.auto_resolve()

        self.assertFalse(builder.is_closed())
示例#5
0
    def test_closing_3(self):
        # T A&B     F A
        expr_1 = And(Atom("A"), Atom("B"))
        expr_2 = Atom("A")

        builder = IpcTableauxBuilder(true_exprs=[expr_1], false_exprs=[expr_2])
        builder.auto_resolve()

        self.assertTrue(builder.is_closed())
示例#6
0
    def test_closing_8(self):
        # !(A|B) -> !A&!B
        expr = Impl(Not(Or(Atom("A"), Atom("B"))),
                    And(Not(Atom("A")), Not(Atom("B"))))

        builder = IpcTableauxBuilder(false_exprs=[expr])
        builder.auto_resolve()

        self.assertTrue(builder.is_closed())
示例#7
0
    def test_closing_11(self):
        # (A->!B) -> !(A&B)
        expr = Impl(Impl(Atom("A"), Not(Atom("B"))),
                    Not(And(Atom("A"), Atom("B"))))

        builder = IpcTableauxBuilder(false_exprs=[expr])
        builder.auto_resolve()

        self.assertTrue(builder.is_closed())
示例#8
0
    def get_drawing_calculator(self, true_exprs, false_exprs):
        painter_mock = MagicMock()
        tableaux_builder = IpcTableauxBuilder(
            true_exprs=[parse(e) for e in true_exprs],
            false_exprs=[parse(e) for e in false_exprs],
            visit_idx=len(true_exprs) + len(false_exprs))
        tableaux_builder.auto_resolve()

        return DrawingCalculator(tableaux_builder, painter_mock, False, True,
                                 10)
示例#9
0
    def test_not_closing_13(self):
        # (A->B)->(!A|B)
        expr = Impl(
            Impl(Atom("A"), Atom("B")),
            Or(Not(Atom("A")), Atom("B")),
        )

        builder = IpcTableauxBuilder(false_exprs=[expr])
        builder.auto_resolve()

        self.assertFalse(builder.is_closed())
示例#10
0
    def test_not_closing_10(self):
        # !(A->!B)->A&B
        expr = Impl(
            Not(Impl(Atom("A"), Not(Atom("B")))),
            And(Atom("A"), Atom("B")),
        )

        builder = IpcTableauxBuilder(false_exprs=[expr])
        builder.auto_resolve()

        self.assertFalse(builder.is_closed())
示例#11
0
    def test_closing_18(self):
        # (A&B)<->((A->B)<->A)
        expr = Eq(And(Atom("A"), Atom("B")),
                  Eq(
                      Impl(Atom("A"), Atom("B")),
                      Atom("A"),
                  ))

        builder = IpcTableauxBuilder(false_exprs=[expr])
        builder.auto_resolve()

        self.assertTrue(builder.is_closed())
    def test_correct_15(self):
        expr_t = [
            parse('a&b&c'),
            parse('q->r'),
            parse('r->s'),
        ]
        expr_f = [
            parse('!s->!p')
        ]
        expr_cf = [
            parse('a<->b')
        ]

        l_expr = [[]]
        r_expr = [[]]
        cf_expr = [[
            parse('(a->b)&(b->a)')
        ]]

        tableau = IpcTableauxBuilder(true_exprs=expr_t,
                                     false_exprs=expr_f,
                                     cf_exprs=expr_cf)
        manual_tableau = BaseManualTableau(LogicType.IPROPOSITIONAL, tableau)

        success = manual_tableau.merge((None, None, expr_cf[0]), l_expr, r_expr, cf_expr, [])

        self.assertTrue(success)
    def test_merge_true_impl(self):
        expr_t = [
            parse('q->r'),
            parse('a&b&c'),
            parse('r->s'),
        ]
        expr_f = [
            parse('!s->!p')
        ]

        l_expr = [
            [], [parse('r')],
        ]

        r_expr = [
            [parse('q')], [],
        ]

        tableau = IpcTableauxBuilder(true_exprs=expr_t, false_exprs=expr_f)
        manual_tableau = BaseManualTableau(LogicType.IPROPOSITIONAL, tableau)

        manual_tableau.merge((expr_t[0], None, None), l_expr, r_expr, [[],[]], [])

        sequent = tableau.sequent

        self.assertEqual(2, len(tableau.children))

        self.assertEqual(2, len(sequent[BaseTableauxBuilder.true_exprs]))
        self.assertIn(parse('r->s'), sequent[BaseTableauxBuilder.true_exprs])
        self.assertIn(parse('a&b&c'), sequent[BaseTableauxBuilder.true_exprs])
        self.assertEqual(0, len(sequent[BaseTableauxBuilder.false_atoms]))
        self.assertEqual(0, len(sequent[BaseTableauxBuilder.true_atoms]))
        self.assertEqual(0, len(sequent[BaseTableauxBuilder.false_processed]))
        self.assertEqual(1, len(sequent[BaseTableauxBuilder.true_processed]))
        self.assertIn(parse('q->r'), sequent[BaseTableauxBuilder.true_processed])

        c_s_1 = tableau.children[0].sequent
        c_s_2 = tableau.children[1].sequent

        self.assertEqual(2, len(c_s_1[BaseTableauxBuilder.true_exprs]))
        self.assertIn(parse('r->s'), c_s_1[BaseTableauxBuilder.true_exprs])
        self.assertIn(parse('a&b&c'), c_s_1[BaseTableauxBuilder.true_exprs])
        self.assertEqual(1, len(c_s_1[BaseTableauxBuilder.false_atoms]))
        self.assertIn(parse('q'), c_s_1[BaseTableauxBuilder.false_atoms])
        self.assertEqual(0, len(c_s_1[BaseTableauxBuilder.true_atoms]))
        self.assertEqual(0, len(c_s_1[BaseTableauxBuilder.false_processed]))
        self.assertEqual(1, len(c_s_1[BaseTableauxBuilder.true_processed]))
        self.assertIn(parse('q->r'), c_s_1[BaseTableauxBuilder.true_processed])

        self.assertEqual(2, len(c_s_2[BaseTableauxBuilder.true_exprs]))
        self.assertIn(parse('r->s'), c_s_2[BaseTableauxBuilder.true_exprs])
        self.assertIn(parse('a&b&c'), c_s_2[BaseTableauxBuilder.true_exprs])
        self.assertEqual(1, len(c_s_2[BaseTableauxBuilder.true_atoms]))
        self.assertIn(parse('r'), c_s_2[BaseTableauxBuilder.true_atoms])
        self.assertEqual(0, len(c_s_2[BaseTableauxBuilder.false_atoms]))
        self.assertEqual(0, len(c_s_2[BaseTableauxBuilder.false_processed]))
        self.assertEqual(1, len(c_s_2[BaseTableauxBuilder.true_processed]))
        self.assertIn(parse('q->r'), c_s_2[BaseTableauxBuilder.true_processed])
    def test_merge_true_not(self):
        expr_t = [
            parse('!s'),
            parse('a&b&c'),
            parse('q->r'),
            parse('r->s'),
        ]
        expr_f = [
            parse('!s->!p'),
            parse('t&f')
        ]
        expr_cf = [
            parse('!s')
        ]

        l_expr = [[]]
        r_expr = [[]]
        cf_expr = [[
            parse('s')
        ]]

        tableau = IpcTableauxBuilder(true_exprs=expr_t,
                                     false_exprs=expr_f,
                                     cf_exprs = expr_cf)
        manual_tableau = BaseManualTableau(LogicType.IPROPOSITIONAL, tableau)

        manual_tableau.merge((expr_t[0], None, None), l_expr, r_expr, cf_expr, [])

        self.assertEqual(0, len(tableau.children))
        sequent = tableau.sequent

        self.assertEqual(3, len(sequent[BaseTableauxBuilder.true_exprs]))
        self.assertIn(parse('q->r'), sequent[BaseTableauxBuilder.true_exprs])
        self.assertIn(parse('r->s'), sequent[BaseTableauxBuilder.true_exprs])
        self.assertIn(parse('a&b&c'), sequent[BaseTableauxBuilder.true_exprs])
        self.assertEqual(0, len(sequent[BaseTableauxBuilder.true_atoms]))

        self.assertEqual(2, len(sequent[BaseTableauxBuilder.false_exprs]))
        self.assertIn(parse('!s->!p'), sequent[BaseTableauxBuilder.false_exprs])
        self.assertIn(parse('t&f'), sequent[BaseTableauxBuilder.false_exprs])
        self.assertEqual(0, len(sequent[BaseTableauxBuilder.false_atoms]))

        self.assertEqual(1, len(sequent[BaseTableauxBuilder.certain_falsehood_exprs]))
        self.assertIn(parse('!s'), sequent[BaseTableauxBuilder.certain_falsehood_exprs])
        self.assertEqual(1, len(sequent[BaseTableauxBuilder.certain_falsehood_atoms]))
        self.assertIn(parse('s'), sequent[BaseTableauxBuilder.certain_falsehood_atoms])

        self.assertEqual(1, len(sequent[BaseTableauxBuilder.true_processed]))
        self.assertIn(parse('!s'), sequent[BaseTableauxBuilder.true_processed])
        self.assertEqual(0, len(sequent[BaseTableauxBuilder.false_processed]))
        self.assertEqual(0, len(sequent[BaseTableauxBuilder.certain_falsehood_processed]))
    def test_incorrect_1(self):
        expr = parse('(a->b)&(b->c)->(a->c)')

        l_expr = [
            parse('(a->b)&(b->c)'),
            parse('(a->c)'),
        ]

        tableau = IpcTableauxBuilder(false_exprs=[expr])
        manual_tableau = BaseManualTableau(LogicType.IPROPOSITIONAL, tableau)

        success = manual_tableau.merge((None, expr, None), [l_expr], [[]], [[]], [])

        self.assertFalse(success)
    def test_incorrect_5(self):
        expr_t = parse('!!a')
        expr_f = parse('a|b')

        l_expr = []

        r_expr = [
            parse('a'),
        ]

        tableau = IpcTableauxBuilder(true_exprs=[expr_t], false_exprs=[expr_f])
        manual_tableau = BaseManualTableau(LogicType.IPROPOSITIONAL, tableau)

        success = manual_tableau.merge((None, expr_f, None), [l_expr], [r_expr], [[]], [])

        self.assertFalse(success)
    def test_incorrect_4(self):
        expr_t = parse('(a->b)&(b->c)->(a->c)')
        expr_f = parse('(a->b)&(b->c)->(a->c)')

        l_expr = [
            parse('(a->b)&(b->c)'),
        ]

        r_expr = [
            parse('(a->c)'),
        ]

        tableau = IpcTableauxBuilder(true_exprs=[expr_t], false_exprs=[expr_f])
        manual_tableau = BaseManualTableau(LogicType.IPROPOSITIONAL, tableau)

        success = manual_tableau.merge((expr_t, None, None), [l_expr], [r_expr], [[]], [])

        self.assertFalse(success)
    def test_merge_false_impl(self):
        expr_t = [
            parse('a&b&c'),
            parse('q->r'),
            parse('r->s'),
        ]
        expr_f = [
            parse('!s->!p'),
            parse('t&f')
        ]

        l_expr = [
            parse('!s')
        ]

        r_expr = [
            parse('!p')
        ]

        tableau = IpcTableauxBuilder(true_exprs=expr_t, false_exprs=expr_f)
        manual_tableau = BaseManualTableau(LogicType.IPROPOSITIONAL, tableau)

        manual_tableau.merge((None, expr_f[0], None), [l_expr], [r_expr], [[]], [])

        self.assertEqual(1, len(tableau.children))
        sequent = tableau.children[0].sequent

        self.assertEqual(4, len(sequent[BaseTableauxBuilder.true_exprs]))
        self.assertIn(parse('q->r'), sequent[BaseTableauxBuilder.true_exprs])
        self.assertIn(parse('r->s'), sequent[BaseTableauxBuilder.true_exprs])
        self.assertIn(parse('!s'), sequent[BaseTableauxBuilder.true_exprs])
        self.assertIn(parse('a&b&c'), sequent[BaseTableauxBuilder.true_exprs])

        self.assertEqual(1, len(sequent[BaseTableauxBuilder.false_exprs]))
        self.assertIn(parse('!p'), sequent[BaseTableauxBuilder.false_exprs])

        self.assertEqual(0, len(sequent[BaseTableauxBuilder.false_atoms]))
        self.assertEqual(0, len(sequent[BaseTableauxBuilder.true_atoms]))
        self.assertEqual(0, len(sequent[BaseTableauxBuilder.true_processed]))
        self.assertEqual(0, len(sequent[BaseTableauxBuilder.false_processed]))
    def test_correct_10(self):
        expr_t = [
            parse('a&b&c'),
            parse('q->r'),
            parse('r->s'),
        ]
        expr_f = [
            parse('!s->!p')
        ]

        l_expr = [
            parse('a&b'),
            parse('c')
        ]

        r_expr = []

        tableau = IpcTableauxBuilder(true_exprs=expr_t, false_exprs=expr_f)
        manual_tableau = BaseManualTableau(LogicType.IPROPOSITIONAL, tableau)

        success = manual_tableau.merge((expr_t[0], None, None), [l_expr], [r_expr], [[]], [])

        self.assertTrue(success)
示例#20
0
def create_tableau_builder(logic_type: int, left_exprs: list,
                          right_exprs: list, visit_idx:int=0,
                          cf: list=None, constants=[], functions=[]):
    if logic_type == LogicType.PROPOSITIONAL:
        tableau_builder = PropositionalTableauxBuilder(
            true_exprs=left_exprs,
            false_exprs=right_exprs,
            visit_idx=visit_idx,
        )
        return tableau_builder
    if logic_type == LogicType.FOPL:
        tableau_builder = FoplTableauxBuilder(
            true_exprs=left_exprs,
            false_exprs=right_exprs,
            constants=constants,
            functions=functions,
            visit_idx=visit_idx,
        )
        return tableau_builder
    if logic_type == LogicType.IPROPOSITIONAL:
        tableau_builder = IpcTableauxBuilder(
            true_exprs=left_exprs,
            false_exprs=right_exprs,
            visit_idx=visit_idx,
            cf_exprs=cf if cf is not None else [],
        )
        return tableau_builder
    if logic_type == LogicType.IFOPL:
        tableau_builder = IfoplTableauxBuilder(
            true_exprs=left_exprs,
            false_exprs=right_exprs,
            constants = constants,
            functions=functions,
            visit_idx=visit_idx,
            cf_exprs=cf if cf is not None else [],
        )
        return tableau_builder