예제 #1
0
    def conclude(self, assumptions):
        '''
        Try to automatically conclude this bi-directional implication by
        reducing its operands to true/false.
        '''
        from . import iff_t_t, iff_t_f, iff_f_t, iff_f_f, true_iff_true, false_iff_false
        if self in {true_iff_true, false_iff_false}:
            # should be proven via one of the imported theorems as a simple
            # special case
            try:
                self.evaluation(assumptions)
            except BaseException:
                return self.prove()
        try:
            # try to prove the bi-directional implication via evaluation reduction.
            # if that is possible, it is a relatively straightforward thing to
            # do.
            return Operation.conclude(assumptions)
        except BaseException:
            pass
        try:
            # Use a breadth-first search approach to find the shortest
            # path to get from one end-point to the other.
            return TransitiveRelation.conclude(self, assumptions)
        except BaseException:
            pass

        # the last attempt is to introduce the Iff via implications each way, an
        # essentially direct consequence of the definition.
        return self.conclude_by_definition(assumptions)
예제 #2
0
    def conclude(self, assumptions):
        '''
        Attempt to conclude the equivalence in various ways:
        simple reflexivity (A equiv A), via an evaluation (if one side
        is an irreducible), or via transitivity.
        IN PROGRESS. NOT YET CLEAR how this applies to the SetEquiv
        '''
        from proveit.logic import TRUE, FALSE, Implies, Iff
        if self.lhs == self.rhs:
            # Trivial A = A
            return self.concludeViaReflexivity(assumptions=assumptions)
    #     if self.lhs or self.rhs in (TRUE, FALSE):
    #         try:
    #             # Try to conclude as TRUE or FALSE.
    #             return self.concludeBooleanEquality(assumptions)
    #         except ProofFailure:
    #             pass
    #     if isIrreducibleValue(self.rhs):
    #         try:
    #             evaluation = self.lhs.evaluation(assumptions)
    #             if evaluation.rhs != self.rhs:
    #                 raise ProofFailure(self, assumptions, "Does not match with evaluation: %s"%str(evaluation))
    #             return evaluation
    #         except SimplificationError as e:
    #             raise ProofFailure(self, assumptions, "Evaluation error: %s"%e.message)
    #     elif isIrreducibleValue(self.lhs):
    #         try:
    #             evaluation = self.rhs.evaluation(assumptions)
    #             if evaluation.rhs != self.lhs:
    #                 raise ProofFailure(self, assumptions, "Does not match with evaluation: %s"%str(evaluation))
    #             return evaluation.deriveReversed()
    #         except SimplificationError as e:
    #             raise ProofFailure(self, assumptions, "Evaluation error: %s"%e.message)
    #     try:
    #         Implies(self.lhs, self.rhs).prove(assumptions, automation=False)
    #         Implies(self.rhs, self.lhs).prove(assumptions, automation=False)
    #         # lhs => rhs and rhs => lhs, so attempt to prove lhs = rhs via lhs <=> rhs
    #         # which works when they can both be proven to be Booleans.
    #         try:
    #             return Iff(self.lhs, self.rhs).deriveEquality(assumptions)
    #         except:
    #             from proveit.logic.boolean.implication._theorems_ import eqFromMutualImpl
    #             return eqFromMutualImpl.specialize({A:self.lhs, B:self.rhs}, assumptions=assumptions)
    #     except ProofFailure:
    #         pass

    #     """
    #     # Use concludeEquality if available
    #     if hasattr(self.lhs, 'concludeEquality'):
    #         return self.lhs.concludeEquality(assumptions)
    #     if hasattr(self.rhs, 'concludeEquality'):
    #         return self.rhs.concludeEquality(assumptions)
    #     """
    # Use a breadth-first search approach to find the shortest
    # path to get from one end-point to the other.
        return TransitiveRelation.conclude(self, assumptions)
예제 #3
0
 def conclude(self, assumptions):
     '''
     Try to automatically conclude this implication by reducing its operands
     to true/false, or by doing a "transitivity" search amongst known true implications
     whose assumptions are covered by the given assumptions.
     '''
     from ._axioms_ import untrueAntecedentImplication
     from ._theorems_ import trueImpliesTrue, falseImpliesTrue, falseImpliesFalse, falseAntecedentImplication
     from proveit.logic import TRUE, FALSE
     if self.antecedent == self.consequent:
         return self.concludeSelfImplication()
     if self in {trueImpliesTrue, falseImpliesTrue, falseImpliesFalse}:
         # should be proven via one of the imported theorems as a simple special case
         return self.prove()
     try:
         # Try evaluating the consequent.
         evaluation = self.consequent.evaluation(assumptions)
         if evaluation.rhs == TRUE:
             # If the consequent evaluates to true, we can prove trivially via hypothetical reasoning
             return self.consequent.prove(assumptions).asImplication(
                 self.antecedent)
         elif evaluation.rhs == FALSE:
             if self.antecedent.evaluation(assumptions).rhs == FALSE:
                 # Derive A => B given Not(A); it doesn't matter what B is if A is FALSE
                 return falseAntecedentImplication.specialize(
                     {
                         A: self.antecedent,
                         B: self.consequent
                     },
                     assumptions=assumptions)
             else:
                 # Derive A => B given (A != TRUE); it doesn't matter what B is if A is not TRUE
                 return untrueAntecedentImplication.specialize(
                     {
                         A: self.antecedent,
                         B: self.consequent
                     },
                     assumptions=assumptions)
     except:
         pass
     try:
         # Use a breadth-first search approach to find the shortest
         # path to get from one end-point to the other.
         return TransitiveRelation.conclude(self, assumptions)
     except:
         pass
     # try to prove the implication via hypothetical reasoning.
     return self.consequent.prove(assumptions +
                                  (self.antecedent, )).asImplication(
                                      self.antecedent)
예제 #4
0
 def conclude(self, assumptions):
     '''
     Attempt to conclude the equality various ways:
     simple reflexivity (x=x), via an evaluation (if one side is an irreducible),
     or via transitivity.
     '''
     from proveit.logic import TRUE, FALSE, Implies, Iff
     if self.lhs == self.rhs:
         # Trivial x=x
         return self.concludeViaReflexivity()
     if self.lhs or self.rhs in (TRUE, FALSE):
         try:
             # Try to conclude as TRUE or FALSE.
             return self.concludeBooleanEquality(assumptions)
         except ProofFailure:
             pass
     if isIrreducibleValue(self.rhs):
         return self.lhs.evaluation()
     elif isIrreducibleValue(self.lhs):
         return self.rhs.evaluation().deriveReversed()
     try:
         Implies(self.lhs, self.rhs).prove(assumptions, automation=False)
         Implies(self.rhs, self.lhs).prove(assumptions, automation=False)
         # lhs => rhs and rhs => lhs, so attempt to prove lhs = rhs via lhs <=> rhs
         # which works when they can both be proven to be Booleans.
         try:
             return Iff(self.lhs, self.rhs).deriveEquality(assumptions)
         except:
             from proveit.logic.boolean.implication._theorems_ import eqFromMutualImpl
             return eqFromMutualImpl.specialize({
                 A: self.lhs,
                 B: self.rhs
             },
                                                assumptions=assumptions)
     except ProofFailure:
         pass
     """
     # Use concludeEquality if available
     if hasattr(self.lhs, 'concludeEquality'):
         return self.lhs.concludeEquality(assumptions)
     if hasattr(self.rhs, 'concludeEquality'):
         return self.rhs.concludeEquality(assumptions)
     """
     # Use a breadth-first search approach to find the shortest
     # path to get from one end-point to the other.
     return TransitiveRelation.conclude(self, assumptions)
예제 #5
0
    def conclude(self, **defaults_config):
        '''
        Attempt to conclude the equivalence in various ways:
        simple reflexivity (A equiv A), via an evaluation (if one side
        is an irreducible), or via transitivity.
        IN PROGRESS
        '''
        if self.lhs == self.rhs:
            try:
                # Trivial A = A
                return self.conclude_via_reflexivity()
            except BaseException:
                pass  # e.g., reflexivity theorem may not be usable
        try:
            return self.conclude_as_folded()
        except ProofFailure:
            raise ProofFailure(
                self, defaults.assumptions,
                "Unable to automatically conclude by "
                "standard means.  To try to prove this via "
                "transitive implication relations, try "
                "'conclude_via_transitivity'.")

    #     if self.lhs or self.rhs in (TRUE, FALSE):
    #         try:
    #             # Try to conclude as TRUE or FALSE.
    #             return self.conclude_boolean_equality(assumptions)
    #         except ProofFailure:
    #             pass
    #     if is_irreducible_value(self.rhs):
    #         try:
    #             evaluation = self.lhs.evaluation(assumptions)
    #             if evaluation.rhs != self.rhs:
    #                 raise ProofFailure(self, assumptions, "Does not match with evaluation: %s"%str(evaluation))
    #             return evaluation
    #         except SimplificationError as e:
    #             raise ProofFailure(self, assumptions, "Evaluation error: %s"%e.message)
    #     elif is_irreducible_value(self.lhs):
    #         try:
    #             evaluation = self.rhs.evaluation(assumptions)
    #             if evaluation.rhs != self.lhs:
    #                 raise ProofFailure(self, assumptions, "Does not match with evaluation: %s"%str(evaluation))
    #             return evaluation.derive_reversed()
    #         except SimplificationError as e:
    #             raise ProofFailure(self, assumptions, "Evaluation error: %s"%e.message)
    #     try:
    #         Implies(self.lhs, self.rhs).prove(assumptions, automation=False)
    #         Implies(self.rhs, self.lhs).prove(assumptions, automation=False)
    #         # lhs => rhs and rhs => lhs, so attempt to prove lhs = rhs via lhs <=> rhs
    #         # which works when they can both be proven to be Boolean.
    #         try:
    #             return Iff(self.lhs, self.rhs).derive_equality(assumptions)
    #         except:
    #             from proveit.logic.booleans.implication import eq_from_mutual_impl
    #             return eq_from_mutual_impl.instantiate({A:self.lhs, B:self.rhs}, assumptions=assumptions)
    #     except ProofFailure:
    #         pass

    #     """
    #     # Use conclude_equality if available
    #     if hasattr(self.lhs, 'conclude_equality'):
    #         return self.lhs.conclude_equality(assumptions)
    #     if hasattr(self.rhs, 'conclude_equality'):
    #         return self.rhs.conclude_equality(assumptions)
    #     """
    # Use a breadth-first search approach to find the shortest
    # path to get from one end-point to the other.
        return TransitiveRelation.conclude(self)