def knownRelationsFromLeft(RelationClass, expr, assumptionsSet): ''' Yield (KnownTruth, right-hand-side) pairs for this transitive relationship (or equality) that involve the given expression on the left side and are known to be true under the given assumptions. The strongest known relationships should be yielded first, starting with equalities (for inequalities, next is < followed by <=). ''' from proveit.logic import Equals # equality relationships are strongest and should come first. for (knownTruth, otherExpr) in Equals.knownRelationsFromLeft(expr, assumptionsSet): if expr != otherExpr: # exclude reflexive equations -- they don't count yield (knownTruth, otherExpr) if RelationClass is not Equals: # stronger then weaker relations for Relation in (RelationClass._checkedStrongRelationClass(), RelationClass._checkedWeakRelationClass()): for knownTruth in list(Relation.knownLeftSides.get(expr, [])): if knownTruth.isSufficient(assumptionsSet): yield (knownTruth, knownTruth.rhs)
def conclude(self, assumptions=USE_DEFAULTS): ''' Try to deduce that the given element is in the number set under the given assumptions. ''' element = self.element # See if the element is known to be equal with something # that is known to be in the number set. assumptions_set = set(defaults.checkedAssumptions(assumptions)) for eq, equiv_elem in Equals.knownRelationsFromLeft( element, assumptions_set): try: equiv_elem_in_set = InSet(equiv_elem, self.number_set) equiv_elem_in_set.prove(assumptions, automation=False) return eq.subLeftSideInto(equiv_elem_in_set, assumptions) except ProofFailure: pass ''' # Maybe let's not simplify first. If # See if we can simplify the element first. if hasattr(element, 'simplification'): simplification = element.simplification(assumptions=assumptions) element = simplification.rhs if element != self.element: # Prove membersip for the simplified element elem_in_set = InSet(element, self.number_set).prove(assumptions) # Substitute into the original. return simplification.subLeftSideInto(elem_in_set, assumptions) ''' # Try the 'deduceInNumberSet' method. if hasattr(element, 'deduceInNumberSet'): return element.deduceInNumberSet(self.number_set, assumptions=assumptions) else: msg = str(element) + " has no 'deduceInNumberSet' method." raise ProofFailure(InSet(self.element, self.number_set), assumptions, msg)