def test_merge_9(self): expr_t = parse('(A)x (P(x)|T(x))') expr_f = parse('P(A)&F(B)') l_expr = [ parse('P(A)|T(A)'), ] r_expr = [] tableau = FoplTableauxBuilder(true_exprs=[expr_t], false_exprs=[expr_f], constants=['A', 'B']) manual_tableau = BaseManualTableau(LogicType.FOPL, tableau) manual_tableau.merge((expr_t, None, None), [l_expr], [r_expr], [[]], ['A']) sequent = tableau.sequent self.assertEqual(1, len(sequent[BaseTableauxBuilder.true_exprs])) self.assertIn(parse('P(A)|T(A)'), sequent[BaseTableauxBuilder.true_exprs]) self.assertEqual(1, len(sequent[BaseTableauxBuilder.false_exprs])) self.assertIn(parse('P(A)&F(B)'), 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])) self.assertEqual( 0, len(sequent[ BaseTableauxBuilder.processed_false_quantor_expressions])) self.assertEqual( 1, len(sequent[ BaseTableauxBuilder.processed_true_quantor_expressions])) self.assertIn( parse('(A)x (P(x)|T(x))'), sequent[BaseTableauxBuilder.processed_true_quantor_expressions]) self.assertEqual( 1, len(sequent[BaseTableauxBuilder.processed_true_quantor_expressions] [parse('(A)x (P(x)|T(x))')])) self.assertIn( 'A', sequent[BaseTableauxBuilder.processed_true_quantor_expressions][ parse('(A)x (P(x)|T(x))')]) self.assertEqual( 2, len(sequent[BaseTableauxBuilder.established_constants])) self.assertIn('A', sequent[BaseTableauxBuilder.established_constants]) self.assertIn('B', sequent[BaseTableauxBuilder.established_constants]) self.assertEqual(0, len(tableau.children))
def get_drawing_calculator(self, true_exprs, false_exprs): painter_mock = MagicMock() tableaux_builder = FoplTableauxBuilder( 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, False, 10)
def test_incorrect_1(self): expr = parse('(P()->T())&(T()->Q())->(P()->Q())') l_expr = [ parse('(P()->T())&(T()->Q())'), parse('(P()->Q())'), ] tableau = FoplTableauxBuilder(false_exprs=[expr]) manual_tableau = BaseManualTableau(LogicType.FOPL, tableau) success = manual_tableau.merge((None, expr, None), [l_expr], [[]], [[]], []) self.assertFalse(success)
def test_correct_3(self): expr_t = parse('!!P()') expr_f = parse('(P()->T())&(T()->Q())->(P()->Q())') l_expr = [parse('(P()->T())&(T()->Q())')] r_expr = [parse('(P()->Q())')] tableau = FoplTableauxBuilder(true_exprs=[expr_t], false_exprs=[expr_f]) manual_tableau = BaseManualTableau(LogicType.FOPL, tableau) success = manual_tableau.merge((None, expr_f, None), [l_expr], [r_expr], [[]], []) self.assertTrue(success)
def test_correct_10(self): expr_t = [ parse('P()&T()&Q()'), parse('K()->R()'), parse('R()->S()'), ] expr_f = [parse('!S()->!F()')] l_expr = [parse('P()&T()'), parse('Q()')] r_expr = [] tableau = FoplTableauxBuilder(true_exprs=expr_t, false_exprs=expr_f) manual_tableau = BaseManualTableau(LogicType.FOPL, tableau) success = manual_tableau.merge((expr_t[0], None, None), [l_expr], [r_expr], [[]], []) self.assertTrue(success)
def test_incorrect_13(self): expr_t = parse('(A)x P(x)') expr_f = parse('P(A)|T(B)') l_expr = [ parse('P(A)&T(B)'), ] r_expr = [] tableau = FoplTableauxBuilder(true_exprs=[expr_t], false_exprs=[expr_f], constants=['A', 'B']) manual_tableau = BaseManualTableau(LogicType.FOPL, tableau) success = manual_tableau.merge((expr_t, None, None), [l_expr], [r_expr], [[]], ['A', 'B']) self.assertFalse(success)
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