def applyTransitivity(self, other, assumptions=USE_DEFAULTS): ''' Apply a transitivity rule to derive from this x>=y expression and something of the form y>z, y>=z, z<y, z<=y, or y=z to obtain x>z or x>=z as appropriate. In the special case of x>=y and y>=x (or x<=y), derive x=z. ''' from ._theorems_ import transitivityGreaterEqGreater, transitivityGreaterEqGreaterEq, symmetricGreaterEq from .less_than import Less, LessEq other = asExpression(other) if isinstance(other, Equals): return OrderingRelation.applyTransitivity(self, other, assumptions) # handles this special case if isinstance(other,Less) or isinstance(other,LessEq): other = other.deriveReversed(assumptions) if other.lhs == self.rhs and other.rhs == self.lhs: # x >= y and y >= x implies that x=y return symmetricGreaterEq.specialize({x:self.lhs, y:self.rhs}, assumptions=assumptions) elif other.lhs == self.rhs: if isinstance(other,Greater): return transitivityGreaterEqGreater.specialize({x:self.lhs, y:self.rhs, z:other.rhs}, assumptions=assumptions) elif isinstance(other,GreaterEq): return transitivityGreaterEqGreaterEq.specialize({x:self.lhs, y:self.rhs, z:other.rhs}, assumptions=assumptions) elif other.rhs == self.lhs: if isinstance(other,Greater): return transitivityGreaterEqGreater.specialize({x:self.lhs, y:self.rhs, z:other.lhs}, assumptions=assumptions) elif isinstance(other,GreaterEq): return transitivityGreaterEqGreaterEq.specialize({x:self.lhs, y:self.rhs, z:other.lhs}, assumptions=assumptions) else: raise ValueError("Cannot perform transitivity with %s and %s!"%(self, other))
def applyTransitivity(self, other, assumptions=USE_DEFAULTS): ''' Apply a transitivity rule to derive from this x<y expression and something of the form y<z, y<=z, z>y, z>=y, or y=z to obtain x<z. ''' from ._axioms_ import transitivityLessLess from ._theorems_ import transitivityLessLessEq from .greater_than import Greater, GreaterEq other = asExpression(other) if isinstance(other, Equals): return OrderingRelation.applyTransitivity(self, other, assumptions) # handles this special case if isinstance(other,Greater) or isinstance(other,GreaterEq): other = other.deriveReversed(assumptions) elif other.lhs == self.rhs: if isinstance(other,Less): return transitivityLessLess.specialize({x:self.lhs, y:self.rhs, z:other.rhs}, assumptions=assumptions) elif isinstance(other,LessEq): return transitivityLessLessEq.specialize({x:self.lhs, y:self.rhs, z:other.rhs}, assumptions=assumptions) elif other.rhs == self.lhs: if isinstance(other,Less): return transitivityLessLess.specialize({x:self.lhs, y:self.rhs, z:other.lhs}, assumptions=assumptions) elif isinstance(other,LessEq): return transitivityLessLessEq.specialize({x:self.lhs, y:self.rhs, z:other.lhs}, assumptions=assumptions) else: raise ValueError("Cannot perform transitivity with %s and %s!"%(self, other))
def applyTransitivity(self, other, assumptions=USE_DEFAULTS): ''' Apply a transitivity rule to derive from this A subset B expression and something of the form B subseteq C, B subset C, or B=C to obtain A subset C as appropriate. ''' from proveit.logic import ( Equals, ProperSubset, ProperSuperset, Subset, SubsetEq, Superset, SupersetEq) from ._theorems_ import ( transitivitySubsetSubset, transitivitySubsetSubsetEq) other = asExpression(other) if isinstance(other, Equals): return ContainmentRelation.applyTransitivity( self, other, assumptions=assumptions) if (isinstance(other, Superset) or isinstance(other, ProperSuperset) or isinstance(other,SupersetEq)): other = other.deriveReversed(assumptions=assumptions) other = asExpression(other) if other.lhs == self.rhs: if isinstance(other,Subset): result = transitivitySubsetSubset.specialize( {A:self.lhs, B:self.rhs, C:other.rhs}, assumptions=assumptions) return result elif isinstance(other,SubsetEq): result = transitivitySubsetSubsetEq.specialize( {A:self.lhs, B:self.rhs, C:other.rhs}, assumptions=assumptions) return result elif other.rhs == self.lhs: if isinstance(other,Subset): result = transitivitySubsetSubset.specialize( {A:self.lhs, B:self.rhs, C:other.lhs}, assumptions=assumptions) return result elif isinstance(other,SubsetEq): result = transitivitySubsetSubsetEq.specialize( {A:self.lhs, B:self.rhs, C:other.lhs}, assumptions=assumptions) return result else: raise ValueError( "Cannot perform transitivity with {0} and {1}!". format(self, other))
def applyTransitivity(self, other, assumptions=USE_DEFAULTS): ''' From A set_equiv B (self) and B set_equiv C (other) derive and return A set_equiv C. If "other" is not a SetEquiv, reverse roles and call 'applyTransitivity' from the "other" side. This method initially based on the applyTransitivity method from Equals class. ''' from ._theorems_ import setEquivTransitivity other = asExpression(other) if not isinstance(other, SetEquiv): # If the other relation is not "SetEquiv", # call from the "other" side. return other.applyTransitivity(self, assumptions) otherSetEquiv = other # We can assume that B set_equiv A will be a KnownTruth if # A set_equiv B is a KnownTruth because it is derived as a # side-effect. if self.rhs == otherSetEquiv.lhs: return setEquivTransitivity.specialize( { A: self.lhs, B: self.rhs, C: otherSetEquiv.rhs }, assumptions=assumptions) elif self.rhs == otherSetEquiv.rhs: return setEquivTransitivity.specialize( { A: self.lhs, B: self.rhs, C: otherSetEquiv.lhs }, assumptions=assumptions) elif self.lhs == otherSetEquiv.lhs: return setEquivTransitivity.specialize( { A: self.rhs, B: self.lhs, C: otherSetEquiv.rhs }, assumptions=assumptions) elif self.lhs == otherSetEquiv.rhs: return setEquivTransitivity.specialize( { A: self.rhs, B: self.lhs, C: otherSetEquiv.lhs }, assumptions=assumptions) else: raise TransitivityException( self, assumptions, 'Transitivity cannot be applied unless there is ' 'something in common in the set equivalences: ' '%s vs %s' % (str(self), str(other)))
def applyTransitivity(self, other, assumptions=USE_DEFAULTS): ''' Apply a transitivity rule to derive from this A superseteq B expression and something of the form B supseteq C, B supset C, or B=C to obtain A supset B or A supseteq B as appropriate. ''' from proveit.logic import Equals from ._theorems_ import transitivitySupsetEqSupset, transitivitySupsetEqSupsetEq from .superset import Subset, SubsetEq other = asExpression(other) if isinstance(other, Equals): return ContainmentRelation.applyTransitivity( other, assumptions) # handles this special case if isinstance(other, Subset) or isinstance(other, SubsetEq): other = other.deriveReversed(assumptions) elif other.lhs == self.rhs: if isinstance(other, Superset): result = transitivitySupsetEqSupset.specialize( { A: self.lhs, B: self.rhs, C: other.rhs }, assumptions=assumptions) return result.checked({self}) elif isinstance(other, SupersetEq): result = transitivitySupsetEqSupsetEq.specialize( { A: self.lhs, B: self.rhs, C: other.rhs }, assumptions=assumptions) return result elif other.rhs == self.lhs: if isinstance(other, Superset): result = transitivitySupsetEqSupset.specialize( { A: self.lhs, B: self.rhs, C: other.lhs }, assumptions=assumptions) return result elif isinstance(other, SupersetEq): result = transitivitySupsetEqSupsetEq.specialize( { A: self.lhs, B: self.rhs, C: other.lhs }, assumptions=assumptions) return result else: raise ValueError("Cannot perform transitivity with %s and %s!" % (self, other))
def applyTransitivity(self, other, assumptions=USE_DEFAULTS): ''' From x = y (self) and y = z (other) derive and return x = z. Also works more generally as long as there is a common side to the equations. If "other" is not an equality, reverse roles and call 'applyTransitivity' from the "other" side. ''' from ._axioms_ import equalsTransitivity other = asExpression(other) if not isinstance(other, Equals): # If the other relation is not "Equals", call from the "other" side. return other.applyTransitivity(self, assumptions) otherEquality = other # We can assume that y=x will be a KnownTruth if x=y is a KnownTruth because it is derived as a side-effect. if self.rhs == otherEquality.lhs: return equalsTransitivity.specialize( { x: self.lhs, y: self.rhs, z: otherEquality.rhs }, assumptions=assumptions) elif self.rhs == otherEquality.rhs: return equalsTransitivity.specialize( { x: self.lhs, y: self.rhs, z: otherEquality.lhs }, assumptions=assumptions) elif self.lhs == otherEquality.lhs: return equalsTransitivity.specialize( { x: self.rhs, y: self.lhs, z: otherEquality.rhs }, assumptions=assumptions) elif self.lhs == otherEquality.rhs: return equalsTransitivity.specialize( { x: self.rhs, y: self.lhs, z: otherEquality.lhs }, assumptions=assumptions) else: raise TransitivityException( self, assumptions, 'Transitivity cannot be applied unless there is something in common in the equalities: %s vs %s' % (str(self), str(other)))
def applyTransitivity(self, other, assumptions=USE_DEFAULTS): from ._theorems_ import transitivityGreaterGreater, transitivityGreaterGreaterEq from .less_than import Less, LessEq other = asExpression(other) if isinstance(other, Equals): return OrderingRelation.applyTransitivity( self, other, assumptions) # handles this special case if isinstance(other, Less) or isinstance(other, LessEq): other = other.deriveReversed(assumptions) if other.lhs == self.rhs: if isinstance(other, Greater): return transitivityGreaterGreater.specialize( { x: self.lhs, y: self.rhs, z: other.rhs }, assumptions=assumptions) elif isinstance(other, GreaterEq): return transitivityGreaterGreaterEq.specialize( { x: self.lhs, y: self.rhs, z: other.rhs }, assumptions=assumptions) elif other.rhs == self.lhs: if isinstance(other, Greater): return transitivityGreaterGreater.specialize( { x: self.lhs, y: self.rhs, z: other.lhs }, assumptions=assumptions) elif isinstance(other, GreaterEq): return transitivityGreaterGreaterEq.specialize( { x: self.lhs, y: self.rhs, z: other.lhs }, assumptions=assumptions) else: raise ValueError("Cannot perform transitivity with %s and %s!" % (self, other))
def applyTransitivity(self, other, assumptions=USE_DEFAULTS): ''' Apply a transitivity rule to derive from this Superset(A, B) expression and something of the form SupersetEq(B, C), ProperSuperset(B, C), ProperSubset(C, B), SubsetEq(C, B), or B=C to obtain ProperSuperset(A, C) or SupersetEq(A, C) as appropriate. For example, calling Superset(A,B).applyTransitivity(Equals(B,C), assumptions=[Superset(A,B), Equals(B,C)]) returns: {Superset(A,B), Equals(B,C)} |– Superset(A,C) ''' from proveit.logic import Equals, ProperSubset, Subset, SubsetEq from ._theorems_ import (transitivitySupsetSupset, transitivitySupsetSupsetEq) other = asExpression(other) if isinstance(other, Equals): return ContainmentRelation.applyTransitivity( self, other, assumptions=assumptions) if (isinstance(other, Subset) or isinstance(other, ProperSubset) or isinstance(other, SubsetEq)): other = other.deriveReversed(assumptions=assumptions) other = asExpression(other) if other.lhs == self.rhs: if isinstance(other, Superset) or isinstance( other, ProperSuperset): result = transitivitySupsetSupset.specialize( { A: self.lhs, B: self.rhs, C: other.rhs }, assumptions=assumptions) return result elif isinstance(other, SupersetEq): result = transitivitySupsetSupsetEq.specialize( { A: self.lhs, B: self.rhs, C: other.rhs }, assumptions=assumptions) return result elif other.rhs == self.lhs: if isinstance(other, Superset) or isinstance( other, ProperSuperset): result = transitivitySupsetSupset.specialize( { A: self.lhs, B: self.rhs, C: other.lhs }, assumptions=assumptions) return result elif isinstance(other, SupersetEq): result = transitivitySupsetSupsetEq.specialize( { A: self.lhs, B: self.rhs, C: other.lhs }, assumptions=assumptions) return result else: raise ValueError("Cannot perform transitivity with " "%s and %s!" % (self, other))