def __eq__(self,other): """ TESTS:: sage: P = Poset([["a","b"],["d"],["c"],["d"],[]], facade = False) sage: Q = Poset([["a","b"],["d"],["c"],[],[]], facade = False) sage: P(0).__eq__(P(4)) False sage: from sage.combinat.posets.elements import PosetElement sage: PosetElement(P,0,"c") == PosetElement(P,0,"c") True sage: PosetElement(P,0,"c") == PosetElement(Q,0,"c") False sage: PosetElement(P,0,"b") == PosetElement(P,0,"c") False .. warning:: as an optimization, this only compares the parent and vertex, using the invariant that, in a proper poset element, ``self.element == other.element`` if and only ``self.vertex == other.vertex``:: sage: PosetElement(P,1,"c") == PosetElement(P,0,"c") True Test that :trac:`12351` is fixed:: sage: P(0) == int(0) False """ # This should instead exploit unique representation, using # self is other, or best inherit __eq__ from there. But there # are issues around pickling and rich comparison functions. return have_same_parent(self, other) \ and self.vertex == other.vertex
def __eq__(self, other): """ Check equality. TESTS:: sage: R.<x,y,z> = QQ[] sage: W = DifferentialWeylAlgebra(R) sage: dx,dy,dz = W.differentials() sage: dy*(x^3-y*z)*dx == -z*dx + x^3*dx*dy - y*z*dx*dy True sage: W.zero() == 0 True sage: W.one() == 1 True sage: x == 1 False sage: x + 1 == 1 False sage: W(x^3 - y*z) == x^3 - y*z True """ if have_same_parent(self, other): return self.__monomials == other.__monomials try: return get_coercion_model().bin_op(self, other, operator.eq) except TypeError: return False
def __mul__(self, right): r""" Product of two elements INPUT:: - ``self``, ``right`` -- two elements This calls the `_mul_` method of ``self``, if it is available and the two elements have the same parent. Otherwise, the job is delegated to the coercion model. Do not override; instead implement a ``_mul_`` method in the element class or a ``product`` method in the parent class. EXAMPLES:: sage: S = Semigroups().example("free") sage: x = S('a'); y = S('b') sage: x * y 'ab' """ if have_same_parent(self, right) and hasattr(self, "_mul_"): return self._mul_(right) from sage.structure.element import get_coercion_model import operator return get_coercion_model().bin_op(self, right, operator.mul)
def __mul__(self, right): r""" Product of two elements INPUT:: - ``self``, ``right`` -- two elements This calls the `_mul_` method of ``self``, if it is available and the two elements have the same parent. Otherwise, the job is delegated to the coercion model. Do not override; instead implement a ``_mul_`` method in the element class or a ``product`` method in the parent class. EXAMPLES:: sage: S = Semigroups().example("free") sage: x = S('a'); y = S('b') sage: x * y 'ab' """ if have_same_parent(self, right) and hasattr(self, "_mul_"): return self._mul_(right) from sage.structure.element import get_coercion_model import operator return get_coercion_model().bin_op(self, right, operator.mul)
def __eq__(self, other): """ Check equality. TESTS:: sage: R.<x,y,z> = QQ[] sage: W = DifferentialWeylAlgebra(R) sage: dx,dy,dz = W.differentials() sage: dy*(x^3-y*z)*dx == -z*dx + x^3*dx*dy - y*z*dx*dy True sage: W.zero() == 0 True sage: W.one() == 1 True sage: x == 1 False sage: x + 1 == 1 False sage: W(x^3 - y*z) == x^3 - y*z True """ if have_same_parent(self, other): return self.__monomials == other.__monomials try: return get_coercion_model().bin_op(self, other, operator.eq) except TypeError: return False
def __eq__(self, other): """ EXAMPLES:: sage: F = GF(3); MS = MatrixSpace(F,2) sage: gens = [MS([1,0, 0,1]), MS([1,1, 0,1])] sage: G = MatrixGroup(gens) sage: H = MatrixGroup(gens) sage: g = G([1,1, 0,1]) sage: h = H([1,1, 0,1]) sage: g == h True """ return have_same_parent(self, other) and self.__mat == other.__mat
def __eq__(self, other): """ EXAMPLES:: sage: F = GF(3); MS = MatrixSpace(F,2) sage: gens = [MS([1,0, 0,1]), MS([1,1, 0,1])] sage: G = MatrixGroup(gens) sage: H = MatrixGroup(gens) sage: g = G([1,1, 0,1]) sage: h = H([1,1, 0,1]) sage: g == h True """ return have_same_parent(self, other) and self.__mat == other.__mat
def __mul__(self, right): """ EXAMPLES:: sage: s = SFASchur(QQ) sage: a = s([2]) sage: a._mul_(a) #indirect doctest s[2, 2] + s[3, 1] + s[4] Todo: use AlgebrasWithBasis(QQ).example() """ if have_same_parent(self, right) and hasattr(self, "_mul_"): return self._mul_(right) from sage.structure.element import get_coercion_model import operator return get_coercion_model().bin_op(self, right, operator.mul)
def __mul__(self, right): """ EXAMPLES:: sage: s = SFASchur(QQ) sage: a = s([2]) sage: a._mul_(a) #indirect doctest s[2, 2] + s[3, 1] + s[4] Todo: use AlgebrasWithBasis(QQ).example() """ if have_same_parent(self, right) and hasattr(self, "_mul_"): return self._mul_(right) from sage.structure.element import get_coercion_model import operator return get_coercion_model().bin_op(self, right, operator.mul)
def __radd__(self, left): r""" Handles the sum of two elements, when the left hand side needs to be coerced first. EXAMPLES:: sage: F = CommutativeAdditiveSemigroups().example() sage: (a,b,c,d) = F.additive_semigroup_generators() sage: a.__radd__(b) a + b """ if have_same_parent(left, self) and hasattr(left, "_add_"): return left._add_(self) from sage.structure.element import get_coercion_model import operator return get_coercion_model().bin_op(left, self, operator.add)
def __radd__(self, left): r""" Handles the sum of two elements, when the left hand side needs to be coerced first. EXAMPLES:: sage: F = CommutativeAdditiveSemigroups().example() sage: (a,b,c,d) = F.additive_semigroup_generators() sage: a.__radd__(b) a + b """ if have_same_parent(left, self) and hasattr(left, "_add_"): return left._add_(self) from sage.structure.element import get_coercion_model import operator return get_coercion_model().bin_op(left, self, operator.add)
def __sub__(left, right): """ Top-level subtraction operator See extensive documentation at the top of element.pyx. EXAMPLES:: sage: F = CombinatorialFreeModule(QQ, ['a','b']) sage: a,b = F.basis() sage: a - b B['a'] - B['b'] """ if have_same_parent(left, right) and hasattr(left, "_sub_"): return left._sub_(right) from sage.structure.element import get_coercion_model import operator return get_coercion_model().bin_op(left, right, operator.sub)
def __sub__(left, right): """ Return the difference between ``left`` and ``right``, if it exists. This top-level implementation delegates the work to the ``_sub_`` method or to coercion. See the extensive documentation at the top of :ref:`sage.structure.element`. EXAMPLES:: sage: F = CombinatorialFreeModule(QQ, ['a','b']) sage: a,b = F.basis() sage: a - b B['a'] - B['b'] """ if have_same_parent(left, right) and hasattr(left, "_sub_"): return left._sub_(right) from sage.structure.element import get_coercion_model import operator return get_coercion_model().bin_op(left, right, operator.sub)
def __add__(self, right): r""" Sum of two elements This calls the `_add_` method of ``self``, if it is available and the two elements have the same parent. Otherwise, the job is delegated to the coercion model. Do not override; instead implement an ``_add_`` method in the element class or a ``summation`` method in the parent class. EXAMPLES:: sage: F = CommutativeAdditiveSemigroups().example() sage: (a,b,c,d) = F.additive_semigroup_generators() sage: a + b a + b """ if have_same_parent(self, right) and hasattr(self, "_add_"): return self._add_(right) from sage.structure.element import get_coercion_model import operator return get_coercion_model().bin_op(self, right, operator.add)
def __add__(self, right): r""" Sum of two elements This calls the `_add_` method of ``self``, if it is available and the two elements have the same parent. Otherwise, the job is delegated to the coercion model. Do not override; instead implement an ``_add_`` method in the element class or a ``summation`` method in the parent class. EXAMPLES:: sage: F = CommutativeAdditiveSemigroups().example() sage: (a,b,c,d) = F.additive_semigroup_generators() sage: a + b a + b """ if have_same_parent(self, right) and hasattr(self, "_add_"): return self._add_(right) from sage.structure.element import get_coercion_model import operator return get_coercion_model().bin_op(self, right, operator.add)