def test_inv_right_conjunction(self):
        """|~ Predicate(alpha) and Predicate(beta)"""

        sequent = Sequent([], [Conjunction(self.alpha, self.beta)])
        decomp = sequent.decompose()[0]
        self.assertEqual(Sequent([], [self.alpha]), decomp[0])
        self.assertEqual(Sequent([], [self.beta]), decomp[1])
    def test_inv_left_conditional(self):
        """Predicate(alpha) implies Predicate(beta) |~ """

        sequent = Sequent([Conditional(self.alpha, self.beta)], [])
        decomp = sequent.decompose()[0]
        self.assertEqual(Sequent([], [self.alpha]), decomp[0])
        self.assertEqual(Sequent([self.beta], []), decomp[1])
 def test_complex_quantified_sequent(self):
     sequent = Sequent(
         [Existential(
             "alpha",
             Conjunction(
                 Universal(
                     "beta",
                     Atom("Predicate", ("alpha", "beta"))
                 ),
                 Atom("AnotherPredicate", ("alpha",))
             ))],
         [])
     with patch("json.load", lambda *args: self.names):
         decomp = sequent.decompose()
     self.assertEqual(
         Sequent(
             [
                 Conjunction(
                     Universal("beta", Atom("Predicate", ("Adrian", "beta"))),
                     Atom("AnotherPredicate", ("Adrian",))
                 )
             ],
             []
         ),
         decomp[0][0]
     )
    def test_inv_left_disjunction(self):
        """Predicate(alpha) or Predicate(beta) |~"""

        sequent = Sequent([Disjunction(self.alpha, self.beta)], [])
        decomp = sequent.decompose()[0]
        self.assertEqual(Sequent([self.alpha], []), decomp[0])
        self.assertEqual(Sequent([self.beta], []), decomp[1])
Example #5
0
 def test_non_invertible_one_parent_decomp(self):
     test_tree = Tree(mock.left_conjunction_sequent)
     test_tree.populate()
     self.assertEqual(Sequent([mock.atom], []), test_tree['0000aaaM'])
     self.assertEqual(Sequent([mock.atom], []), test_tree['0000aabM'])
     self.assertEqual(Sequent([mock.atom, mock.atom], []),
                      test_tree['0000aacM'])
Example #6
0
 def test_two_parent_sequents_invertible_decompose(self):
     sequent = mock.left_disjunction_sequent
     result = sequent.decompose()[0]
     result_pair = result
     left_parent = result_pair[0]
     right_parent = result_pair[1]
     self.assertEqual(Sequent([mock.atom], []), left_parent)
     self.assertEqual(Sequent([mock.atom], []), right_parent)
    def test_right_existential(self):
        """|~ exists(x)(Predicate(x)) """

        with patch("json.load", lambda *args: self.names):
            sequent = Sequent([], [Existential("alpha", self.alpha)])
            decomp = sequent.decompose()
        self.assertEqual(Sequent([], [Atom("Predicate", ("Adrian",))]), decomp[0][0])
        self.assertEqual(Sequent([], [Atom("Predicate", ("Eve",))]), decomp[1][0])
    def test_left_universal(self):
        """forall(x)(Predicate(x)) |~"""

        with patch("json.load", lambda *args: self.names):
            sequent = Sequent([Universal("alpha", self.alpha)], [])
            decomp = sequent.decompose()
        self.assertEqual(Sequent([Atom("Predicate", ("Adrian",))], []), decomp[0][0])
        self.assertEqual(Sequent([Atom("Predicate", ("Eve",))], []), decomp[1][0])
Example #9
0
 def test_non_invertible_two_parent_decomp(self):
     test_tree = Tree(Sequent([mock.atom], [mock.conjunction]))
     test_tree.populate()
     self.assertEqual(Sequent([mock.atom], [mock.atom]),
                      test_tree['0000aaaL'])
     self.assertEqual(Sequent([], [mock.atom]), test_tree['0000aaaR'])
     self.assertEqual(Sequent([], [mock.atom]), test_tree['0000aabL'])
     self.assertEqual(Sequent([mock.atom], [mock.atom]),
                      test_tree['0000aabR'])
Example #10
0
 def test_two_parent_sequents_non_invertible_decompose(self):
     sequent = mock.reflexive_disjunction_sequent
     result = sequent.decompose()
     x_result = result[0]
     x_left = x_result[0]
     x_right = x_result[1]
     y_result = result[1]
     y_left = y_result[0]
     y_right = y_result[1]
     self.assertEqual(Sequent([mock.atom], [mock.disjunction]), x_left)
     self.assertEqual(Sequent([mock.atom], []), x_right)
     self.assertEqual(Sequent([mock.atom], []), y_left)
     self.assertEqual(Sequent([mock.atom], [mock.disjunction]), y_right)
 def test_string_to_sequent(self):
     string = "Predicate(alpha), (Relation(alpha; beta) and Relation(beta; delta)) " \
              "|~ (Relation(beta; gamma) implies Predicate(delta)), Predicate(delta) or Predicate(zeta)"
     sequent = String(string).to_sequent()
     self.assertEqual(
         Sequent(
             [
                 Atom("Predicate", ("alpha",)),
                 Conjunction(
                     Atom("Relation", ("alpha", "beta")),
                     Atom("Relation", ("beta", "delta"))
                 )
             ],
             [
                 Conditional(
                     Atom("Relation", ("beta", "gamma")),
                     Atom("Predicate", ("delta",))
                 ),
                 Disjunction(
                     Atom("Predicate", ("delta",)),
                     Atom("Predicate", ("zeta",))
                 )
             ]
         ),
         sequent
     )
 def test_sequent_left_universal_principal(self):
     universal = Universal("x", Atom("Proposition", ("x",)))
     sequent = Sequent([universal], [])
     principal = sequent.principal
     self.assertEqual("ant", principal.side)
     self.assertEqual(0, principal.index)
     self.assertEqual(LeftUniversal("x", Atom("Proposition", ("x",))), principal.proposition)
 def test_nested_quantified_sequents(self):
     """forall(x)(exists(y)(Predicate(x; y)) |~"""
     sequent = Sequent([
         Universal(
             "alpha",
             Existential("beta", Atom("Predicate", ("alpha", "beta"))))
     ], [])
     with patch("json.load", lambda *args: self.names):
         decomp = sequent.decompose()
     self.assertEqual(
         Sequent(
             [Existential("beta", Atom("Predicate", ("Adrian", "beta")))],
             []), decomp[0][0])
     self.assertEqual(
         Sequent([Existential("beta", Atom("Predicate", ("Eve", "beta")))],
                 []), decomp[1][0])
Example #14
0
 def to_sequent(self) -> Sequent:
     """Returns a sequent from the input."""
     try:
         assert ' |~ ' in self.data
         sides = self.data.split(' |~ ')
         ant_list = sides[0].split(', ')
         con_list = sides[1].split(', ')
         antecedent = [ant for ant in _convert_list(ant_list)]
         consequent = [con for con in _convert_list(con_list)]
         return Sequent(antecedent, consequent)
     except AssertionError:
         raise ValueError(f"{self.data} must be a sequent.")
Example #15
0
 def _decompose(self, key: str, sequent: Sequent) -> dict:
     """Returns the results of decomposing a sequent as a dictionary
     with keys matching their locations in the tree. If reflexivity
     is off, deletes reflexive results and marks the tree as having
     been truncated."""
     new_items = {}
     children: tuple = sequent.decompose()
     if sequent.principal.proposition.is_invertible:
         new_items.update(_invertible_decomp(children, key))
     else:
         new_items.update(_non_invertible_decomp(children, key))
     if not Settings()['Reflexivity']:
         for new_key, new_sequent in new_items.items():
             if new_sequent.is_reflexive:
                 del new_items[new_key]
                 if not self.has_been_truncated:
                     self.has_been_truncated = True
     return new_items
disjunction = Disjunction(atom, atom)

propositions_list = [atom, negation, conditional, conjunction, disjunction]

# Proposition Strings
atom_str = 'Proposition'
neg_str = '(not Proposition)'
cond_str = '(Proposition implies Proposition)'
conj_str = '(Proposition and Proposition)'
disj_str = '(Proposition or Proposition)'

proposition_strings_list = [atom_str, neg_str, cond_str, conj_str, disj_str]

# Reflexive Sequents
# Note: do not attempt to decompose universal sequents non-invertibly.
empty_sequent = Sequent([], [])
reflexive_atomic_sequent = Sequent([atom], [atom])
reflexive_negation_sequent = Sequent([negation], [negation])
reflexive_conditional_sequent = Sequent([conditional], [conditional])
reflexive_conjunction_sequent = Sequent([conjunction], [conjunction])
reflexive_disjunction_sequent = Sequent([disjunction], [disjunction])
reflexive_universal_sequent = Sequent(propositions_list, propositions_list)

reflexive_sequents_list = [
    empty_sequent, reflexive_atomic_sequent, reflexive_negation_sequent,
    reflexive_conditional_sequent, reflexive_conjunction_sequent,
    reflexive_disjunction_sequent, reflexive_universal_sequent
]

# Reflexive Sequent Strings
ref_empty_sequent_str = ' |~ '
    def test_inv_left_negation(self):
        """not Predicate(alpha) |~"""

        sequent = Sequent([Negation(self.alpha)], [])
        decomp = sequent.decompose()[0][0]
        self.assertEqual(Sequent([], [self.alpha]), decomp)
Example #18
0
 def test_one_parent_sequents_invertible_decompose(self):
     sequent = mock.reflexive_negation_sequent
     result = sequent.decompose()[0]
     self.assertEqual(Sequent([], [mock.atom, mock.negation]), result[0])
Example #19
0
 def test_invertible_one_parent_decomp(self):
     test_tree = Tree(mock.right_disjunction_sequent)
     test_tree.populate()
     self.assertEqual(Sequent([], [mock.atom, mock.atom]),
                      test_tree['0000000M'])
    def test_inv_right_disjunction(self):
        """|~ Predicate(alpha) or Predicate(beta)"""

        sequent = Sequent([], [Disjunction(self.alpha, self.beta)])
        decomp = sequent.decompose()[0][0]
        self.assertEqual(Sequent([], [self.alpha, self.beta]), decomp)
Example #21
0
 def test_invertible_two_parent_decomp(self):
     test_tree = Tree(mock.left_conditional_sequent)
     test_tree.populate()
     self.assertEqual(Sequent([], [mock.atom]), test_tree['0000000L'])
     self.assertEqual(Sequent([mock.atom], []), test_tree['0000000R'])
    def test_inv_left_conjunction(self):
        """Predicate(alpha) and Predicate(beta) |~"""

        sequent = Sequent([Conjunction(self.alpha, self.beta)], [])
        decomp = sequent.decompose()[0][0]
        self.assertEqual(Sequent([self.alpha, self.beta], []), decomp)
    def test_inv_right_conditional(self):
        """|~ Predicate(alpha) implies Predicate(beta)"""

        sequent = Sequent([], [Conditional(self.alpha, self.beta)])
        decomp = sequent.decompose()[0][0]
        self.assertEqual(Sequent([self.alpha], [self.beta]), decomp)
Example #24
0
 def test_one_parent_sequents_non_invertible_decompose(self):
     sequent = mock.right_conditional_sequent
     result = sequent.decompose()
     self.assertEqual(Sequent([mock.atom], []), result[0][0])
     self.assertEqual(Sequent([], [mock.atom]), result[1][0])
     self.assertEqual(Sequent([mock.atom], [mock.atom]), result[2][0])
    def test_inv_right_negation(self):
        """|~ not Predicate(alpha)"""

        sequent = Sequent([], [Negation(self.alpha)])
        decomp = sequent.decompose()[0][0]
        self.assertEqual(Sequent([self.alpha], []), decomp)