コード例 #1
0
 def __init__(self, a_implies_b, not_b):
     if (
             isinstance(a_implies_b, Formulae.Formula)
             and isinstance(not_b, Formulae.Formula)
             ):
         self.input_formulae = [copy.deepcopy(a_implies_b),
                                copy.deepcopy(not_b)
                                ]
         if self.input_formulae[0].induction_method == Formulae.IMPLIES:
             implication_negated_consequent = Formulae.Formula(
                     [self.input_formulae[0].parent_formulae[1]],
                     Formulae.NOT
                     )
             if (
                     implication_negated_consequent.string
                     == self.input_formulae[1].string
                     ):
                 self.conclusion = Formulae.Formula(
                         [self.input_formulae[0].parent_formulae[0]],
                         Formulae.NOT
                         )
             else:
                 raise ValueError("""
                                  second formula must be negation of the
                                  consequent of the first: the ¬B of A->B"""
                                  )
         else:
             raise ValueError("""
                              first formula must be of method IMPLIES; so
                              of the form A-> B"""
                              )
     else:
         raise TypeError("pass two formulae")
コード例 #2
0
 def __init__(self, variable, term, formula_of_variable, formula_of_term):
     if not (
             isinstance(variable, Terms.Term)
             and variable.is_variable
             and isinstance(term, Terms.Term)
             and isinstance(formula_of_variable, Formulae.Formula)
             and isinstance(formula_of_term, Formulae.Formula)
             ):
         raise TypeError("""pass a variable, a term, a formula in the
                         variable, and that formula with the term instead"""
                         )
     formula_of_variable_copy = copy.deepcopy(formula_of_variable)
     formula_of_variable_copy.substitute(variable, term)
     if formula_of_variable_copy.string != formula_of_term.string:
         raise ValueError("""
                          the second formula must be the first, but with the
                          term substituted in place of the string"""
                          )
     self.input_formulae = [copy.deepcopy(variable),
                            copy.deepcopy(term),
                            copy.deepcopy(formula_of_variable),
                            copy.deepcopy(formula_of_term)]
     self.conclusion = Formulae.Formula(
                                        [
                                         self.input_formulae[0],
                                         self.input_formulae[2]
                                         ],
                                        Formulae.EXISTS
                                        )
コード例 #3
0
 def __init__(self, a_implies_b, b_implies_a):
     if (
             isinstance(a_implies_b, Formulae.Formula)
             and isinstance(b_implies_a, Formulae.Formula)
             ):
         a_implies_b_copy = copy.deepcopy(a_implies_b)
         b_implies_a_copy = copy.deepcopy(b_implies_a)
         first_antecedent = a_implies_b_copy.parent_formulae[0]
         first_consequent = a_implies_b_copy.parent_formulae[1]
         second_antecedent = b_implies_a_copy.parent_formulae[0]
         second_consequent = b_implies_a_copy.parent_formulae[1]
         if (
                 first_consequent.string == second_antecedent.string
                 and first_antecedent.string == second_consequent.string
                 ):
             self.input_formulae = [a_implies_b_copy, b_implies_a_copy]
             self.conclusion = Formulae.Formula(
                                                [
                                                 first_antecedent,
                                                 first_consequent
                                                 ],
                                                Formulae.IFF
                                                )
         else:
             raise ValueError("pass an implication and its converse")
     else:
         raise TypeError("Pass two formulae to be conjoined")
コード例 #4
0
 def __init__(self, a_iff_b):
     if isinstance(a_iff_b, Formulae.Formula):
         if a_iff_b.induction_method == Formulae.IFF:
             a_iff_b_copy = copy.deepcopy(a_iff_b)
             forward_implication = Formulae.Formula(
                     a_iff_b_copy.parent_formulae,
                     Formulae.IMPLIES
                     )
             backward_implication = Formulae.Formula(
                     a_iff_b_copy.parent_formulae[::-1],
                     Formulae.IMPLIES
                     )
             self.input_formulae = [a_iff_b_copy]
             self.conclusion = Formulae.Formula(
                                                [
                                                 forward_implication,
                                                 backward_implication
                                                 ],
                                                Formulae.AND)
         else:
             raise ValueError("pass an iff formula")
     else:
         raise TypeError("pass a formula")
コード例 #5
0
 def __init__(self, first_disjunct, second_disjunct):
     if (
             isinstance(first_disjunct, Formulae.Formula)
             and isinstance(second_disjunct, Formulae.Formula)
             ):
         self.input_formulae = [copy.deepcopy(first_disjunct),
                                copy.deepcopy(second_disjunct)
                                ]
         self.conclusion = Formulae.Formula(
                                            self.input_formulae,
                                            Formulae.OR
                                            )
     else:
         raise TypeError("Pass two formulae to be disjoined")
コード例 #6
0
 def __init__(self, free_variable, general_formula):
     if not (
             isinstance(general_formula, Formulae.Formula)
             and isinstance(free_variable, Terms.Term)
             and free_variable.is_variable
             ):
         raise TypeError("""
                         pass a free variable and a formula to be
                         generalised"""
                         )
     if free_variable.string not in general_formula.free_variables:
         raise ValueError("the variable must be free in the formula")
     self.input_formulae = [
                            copy.deepcopy(free_variable),
                            copy.deepcopy(general_formula)
                            ]
     self.conclusion = Formulae.Formula(self.input_formulae,
                                        Formulae.FORALL
                                        )
コード例 #7
0
 def __init__(self, a_implies_x, b_implies_y, a_or_b):
     if (
             isinstance(a_implies_x, Formulae.Formula)
             and isinstance(b_implies_y, Formulae.Formula)
             and isinstance(a_or_b, Formulae.Formula)
             ):
         if (
                 a_implies_x.induction_method == Formulae.IMPLIES
                 and b_implies_y.induction_method == Formulae.IMPLIES
                 and a_or_b.induction_method == Formulae.OR
                 ):
             a_implies_x_copy = copy.deepcopy(a_implies_x)
             b_implies_y_copy = copy.deepcopy(b_implies_y)
             a_or_b_copy = copy.deepcopy(a_or_b)
             first_antecedent = a_implies_x_copy.parent_formulae[0]
             second_antecedent = b_implies_y_copy.parent_formulae[0]
             first_disjunct = a_or_b_copy.parent_formulae[0]
             second_disjunct = a_or_b_copy.parent_formulae[1]
             first_consequent = a_implies_x_copy.parent_formulae[1]
             second_consequent = b_implies_y_copy.parent_formulae[1]
             if (
                     first_antecedent.string == first_disjunct.string
                     and second_antecedent.string == second_disjunct.string
                     ):
                 self.input_formulae = [a_implies_x_copy,
                                        b_implies_y_copy,
                                        a_or_b_copy
                                        ]
                 self.conclusion = Formulae.Formula(
                                                    [
                                                     first_consequent,
                                                     second_consequent
                                                     ],
                                                    Formulae.OR
                                                    )
             elif (
                     first_antecedent.string == second_disjunct.string
                     and second_antecedent.string == first_disjunct.string
                     ):
                 self.input_formulae = [b_implies_y_copy,
                                        a_implies_x_copy,
                                        a_or_b_copy
                                        ]
                 self.conclusion = Formulae.Formula(
                                                    [
                                                     second_consequent,
                                                     first_consequent
                                                     ],
                                                    Formulae.OR
                                                    )
             else:
                 raise ValueError("""
                                  the disjuncts in the third formula must be
                                  the antecedents of the implications"""
                                  )
         else:
             raise ValueError("""first two formulae must be implications,
                              third must be disjunction"""
                              )
     else:
         raise TypeError("pass three formulae")