def _richcmp_(self, other, op): r""" Compare self and other (where the coercion model has already ensured that self and other have the same parent). Hecke operators on the same space compare as equal if and only if their matrices are equal, so we check if the indices are the same and if not we compute the matrices (which is potentially expensive). EXAMPLES:: sage: M = ModularSymbols(Gamma0(7), 4) sage: m = M.hecke_operator(3) sage: m == m True sage: m == 2*m False sage: m == M.hecke_operator(5) False These last two tests involve a coercion:: sage: m == m.matrix_form() True sage: m == m.matrix() False """ if not isinstance(other, HeckeOperator): if isinstance(other, HeckeAlgebraElement_matrix): return richcmp(self.matrix_form(), other, op) else: raise RuntimeError("Bug in coercion code") # can't get here if self.__n == other.__n: return rich_to_bool(op, 0) return richcmp(self.matrix(), other.matrix(), op)
def _richcmp_(self, other, op): r""" Compare this element with ``other`` for the comparison operator ``op``. TESTS:: sage: R.<t> = QQ[] sage: sigma = R.hom([t+1]) sage: der = R.derivation(1, twist=sigma) sage: S.<delta> = R['delta', der] sage: K = S.fraction_field() sage: P = K.random_element() sage: Q = K.random_element() sage: D = K.random_element() sage: (P*D) / (Q*D) == P/Q True """ if self.parent()._simplification: return richcmp((self._numerator, self._denominator), (other._numerator, other._denominator), op) if op == op_EQ or op == op_NE: _, U, V = self._denominator.left_xlcm(other._denominator) return richcmp(U * self._numerator, V * other._numerator, op) return NotImplemented
def __richcmp__(self, other, op): r""" Standard comparison function for Kodaira Symbols. EXAMPLES:: sage: from sage.schemes.elliptic_curves.kodaira_symbol import KodairaSymbol_class sage: KS1 = KodairaSymbol_class(15); KS1 I11 sage: KS2 = KodairaSymbol_class(-34); KS2 I30* sage: KS1 < KS2 True sage: KS2 < KS1 False :: sage: Klist = [KodairaSymbol_class(i) for i in [-10..10] if i!=0] sage: Klist.sort() sage: Klist [I0, I0*, I1, I1*, I2, I2*, I3, I3*, I4, I4*, I5, I5*, I6, I6*, II, II*, III, III*, IV, IV*] """ if isinstance(other, KodairaSymbol_class): if (self._n == "generic" and not other._n is None) or (other._n == "generic" and not self._n is None): return richcmp(self._starred, other._starred, op) return richcmp(self._str, other._str, op) else: return NotImplemented
def _richcmp_(self, other, op): r""" Compare this element with ``other``. TESTS:: sage: R = ZpLC(2) sage: x = R(1, 5) sage: y = R(128, 10) sage: z = x + y sage: x 1 + O(2^5) sage: z 1 + O(2^5) sage: x == z # Indirect doctest False sage: z - x 2^7 + O(2^10) """ if (self - other).is_zero(): return rich_to_bool(op, 0) else: return richcmp(QQ(self.lift()), QQ(other.lift()), op)
def __richcmp__(self, other, op): """ Intervals are sorted by lower bound, then upper bound OUTPUT: `-1`, `0`, or `+1` depending on how the intervals compare. EXAMPLES:: sage: I1 = RealSet.open_closed(1, 3)[0]; I1 (1, 3] sage: I2 = RealSet.open_closed(0, 5)[0]; I2 (0, 5] sage: I1 > I2 True sage: sorted([I1, I2]) [(0, 5], (1, 3]] TESTS: Check if a bug in sorting is fixed (:trac:`17714`):: sage: RealSet((0, 1),[1, 1],(1, 2)) (0, 2) """ x = (self._lower, not self._lower_closed, self._upper, self._upper_closed) y = (other._lower, not other._lower_closed, other._upper, other._upper_closed) return richcmp(x, y, op)
def __richcmp__(self, right, op): r""" Compare ``self`` and ``right``. If ``right`` is not a :class:`Set_object`, return ``NotImplemented``. If ``right`` is also a :class:`Set_object`, returns comparison on the underlying objects. .. NOTE:: If `X < Y` is true this does *not* necessarily mean that `X` is a subset of `Y`. Also, any two sets can be compared still, but the result need not be meaningful if they are not equal. EXAMPLES:: sage: Set(ZZ) == Set(QQ) False sage: Set(ZZ) < Set(QQ) True sage: Primes() == Set(QQ) False The following is random, illustrating that comparison of sets is not the subset relation, when they are not equal:: sage: Primes() < Set(QQ) # random True or False """ if not isinstance(right, Set_object): return NotImplemented return richcmp(self.__object, right.__object, op)
def __richcmp__(self, J, op): """ Compare the Jacobian self to `J`. If `J` is a Jacobian, then self and `J` are equal if and only if their curves are equal. EXAMPLES:: sage: from sage.schemes.jacobians.abstract_jacobian import Jacobian sage: P2.<x, y, z> = ProjectiveSpace(QQ, 2) sage: J1 = Jacobian(Curve(x^3 + y^3 + z^3)) sage: J1 == J1 True sage: J1 == P2 False sage: J1 != P2 True sage: J2 = Jacobian(Curve(x + y + z)) sage: J1 == J2 False sage: J1 != J2 True """ if not is_Jacobian(J): return NotImplemented return richcmp(self.curve(), J.curve(), op)
def __richcmp__(self, other, op): """ Compare ``self`` to ``other``. EXAMPLES:: sage: M = ModularSymbols(11) sage: s = M.2.modular_symbol_rep()[0][1] sage: t = M.0.modular_symbol_rep()[0][1] sage: s, t ({-1/9, 0}, {Infinity, 0}) sage: s < t True sage: t > s True sage: s == s True sage: t == t True """ if not isinstance(other, ModularSymbol): return NotImplemented return richcmp((self.__space, -self.__i, self.__alpha, self.__beta), (other.__space,-other.__i,other.__alpha,other.__beta), op)
def _richcmp_(self, other, op): """ Rich comparison of ``self`` to ``other``. EXAMPLES:: sage: F.<x,y> = FreeAlgebra(ZZ) sage: H = F.hochschild_complex(F) sage: a = H({0: x - y, ....: 1: H.module(1).basis().an_element(), ....: 2: H.module(2).basis().an_element()}) sage: a == 3*a False sage: a + a == 2*a True sage: a == H.zero() False sage: a != 3*a True sage: a + a != 2*a False sage: a != H.zero() True """ return richcmp(self._vec, other._vec, op)
def _richcmp_(left, right, op): """ Compare ``left`` and ``right``. INPUT: - ``right`` -- a :class:`FormalSum` with the same parent - ``op`` -- a comparison operator EXAMPLES:: sage: a = FormalSum([(1,3),(2,5)]); a 3 + 2*5 sage: b = FormalSum([(1,3),(2,7)]); b 3 + 2*7 sage: a != b True sage: a_QQ = FormalSum([(1,3),(2,5)],parent=FormalSums(QQ)) sage: a == a_QQ # a is coerced into FormalSums(QQ) True sage: a == 0 # 0 is coerced into a.parent()(0) False """ return richcmp(left._data, right._data, op)
def __richcmp__(self, other, op): """ Intervals are sorted by lower bound, then upper bound OUTPUT: `-1`, `0`, or `+1` depending on how the intervals compare. EXAMPLES:: sage: I1 = RealSet.open_closed(1, 3)[0]; I1 (1, 3] sage: I2 = RealSet.open_closed(0, 5)[0]; I2 (0, 5] sage: cmp(I1, I2) 1 sage: sorted([I1, I2]) [(0, 5], (1, 3]] TESTS: Check if a bug in sorting is fixed (:trac:`17714`):: sage: RealSet((0, 1),[1, 1],(1, 2)) (0, 2) """ x = (self._lower, not self._lower_closed, self._upper, self._upper_closed) y = (other._lower, not other._lower_closed, other._upper, other._upper_closed) return richcmp(x, y, op)
def _richcmp_(self, other, op): r""" Compare this morphism to ``other``. .. NOTE:: This implementation assumes that this morphism is defined by its domain and codomain. Morphisms for which this is not true must override this implementation. EXAMPLES:: sage: K.<x> = FunctionField(QQ); R.<y> = K[] sage: L.<y> = K.extension(y^2 - x*y + 4*x^3) sage: f = L.space_of_differentials().coerce_map_from(K.space_of_differentials()) sage: K.<x> = FunctionField(QQbar); R.<y> = K[] sage: L.<y> = K.extension(y^2 - x*y + 4*x^3) sage: g = L.space_of_differentials().coerce_map_from(K.space_of_differentials()) sage: f == g False sage: f == f True """ if type(self) != type(other): return NotImplemented from sage.structure.richcmp import richcmp return richcmp((self.domain(), self.codomain()), (other.domain(), other.codomain()), op)
def _richcmp_(self, other, op): """ Compare two linear expressions. INPUT: - ``other`` -- another linear expression (will be enforced by the coercion framework) EXAMPLES:: sage: from sage.geometry.linear_expression import LinearExpressionModule sage: L.<x> = LinearExpressionModule(QQ) sage: x == L([0, 1]) True sage: x == x + 1 False sage: M.<x> = LinearExpressionModule(ZZ) sage: L.gen(0) == M.gen(0) # because there is a conversion True sage: L.gen(0) == L(M.gen(0)) # this is the conversion True sage: x == 'test' False """ return richcmp((self._coeffs, self._const), (other._coeffs, other._const), op)
def _richcmp_(self, other, op): """ Compare two free monoid elements with the same parents. The ordering is first by increasing length, then lexicographically on the underlying word. EXAMPLES:: sage: S = FreeMonoid(3, 'a') sage: (x,y,z) = S.gens() sage: x * y < y * x True sage: a = FreeMonoid(5, 'a').gens() sage: x = a[0]*a[1]*a[4]**3 sage: x < x False sage: x == x True sage: x >= x*x False """ m = sum(i for x, i in self._element_list) n = sum(i for x, i in other._element_list) if m != n: return richcmp_not_equal(m, n, op) v = tuple([x for x, i in self._element_list for j in range(i)]) w = tuple([x for x, i in other._element_list for j in range(i)]) return richcmp(v, w, op)
def __richcmp__(self, other, op): """ Intervals are sorted by lower bound, then upper bound OUTPUT: `-1`, `0`, or `+1` depending on how the intervals compare. EXAMPLES:: sage: I1 = RealSet.open_closed(1, 3); I1 (1, 3] sage: I2 = RealSet.open_closed(0, 5); I2 (0, 5] sage: cmp(I1, I2) 1 sage: sorted([I1, I2]) [(0, 5], (1, 3]] sage: I1 == I1 True """ if not isinstance(other, RealSet): return NotImplemented # note that the interval representation is normalized into a # unique form return richcmp(self._intervals, other._intervals, op)
def __richcmp__(self, other, op): """ Intervals are sorted by lower bound, then upper bound OUTPUT: `-1`, `0`, or `+1` depending on how the intervals compare. EXAMPLES:: sage: I1 = RealSet.open_closed(1, 3); I1 (1, 3] sage: I2 = RealSet.open_closed(0, 5); I2 (0, 5] sage: I1 > I2 True sage: sorted([I1, I2]) [(0, 5], (1, 3]] sage: I1 == I1 True """ if not isinstance(other, RealSet): return NotImplemented # note that the interval representation is normalized into a # unique form return richcmp(self._intervals, other._intervals, op)
def __richcmp__(self, other, op): """ Compare ``self`` and ``other``. INPUT: - ``other`` -- anything. OUTPUT: Two faces test equal if and only if they are faces of the same (not just isomorphic) polyhedron and their generators have the same indices. EXAMPLES:: sage: square = polytopes.hypercube(2) sage: f = square.faces(1) sage: matrix(4,4, lambda i,j: ZZ(f[i] <= f[j])) [1 1 1 1] [0 1 1 1] [0 0 1 1] [0 0 0 1] sage: matrix(4,4, lambda i,j: ZZ(f[i] == f[j])) == 1 True """ if not isinstance(other, PolyhedronFace): return NotImplemented if self._polyhedron is not other._polyhedron: return NotImplemented return richcmp(self._ambient_Vrepresentation_indices, other._ambient_Vrepresentation_indices, op)
def _richcmp_(self, other, op): r""" Compare ``self`` to ``other``. Eta products are compared according to their rdicts. EXAMPLES:: sage: EtaProduct(2, {2:24,1:-24}) == 1 False sage: EtaProduct(6, {1:-24, 2:24}) == EtaProduct(6, {1:-24, 2:24}) True sage: EtaProduct(6, {1:-24, 2:24}) == EtaProduct(6, {1:24, 2:-24}) False sage: EtaProduct(6, {1:-24, 2:24}) < EtaProduct(6, {1:-24, 2:24, 3:24, 6:-24}) True sage: EtaProduct(6, {1:-24, 2:24, 3:24, 6:-24}) < EtaProduct(6, {1:-24, 2:24}) False """ if op in [op_EQ, op_NE]: test = (self._N == other._N and self._rdict == other._rdict) return test == (op == op_EQ) return richcmp((self._N, sorted(self._rdict.items())), (other._N, sorted(other._rdict.items())), op)
def __richcmp__(self, other, op): r""" Rich comparison for class functions. Compares groups and then the values of the class function on the conjugacy classes. EXAMPLES:: sage: G = PermutationGroup([[(1,2,3),(4,5)],[(3,4)]]) sage: chi = G.character([1, 1, 1, 1, 1, 1, 1]) sage: H = PermutationGroup([[(1,2,3),(4,5)]]) sage: xi = H.character([1, 1, 1, 1, 1, 1]) sage: chi == chi True sage: xi == xi True sage: xi == chi False sage: chi < xi False sage: xi < chi True """ if isinstance(other, ClassFunction_libgap): return richcmp((self._group, self.values()), (other._group, other.values()), op) else: return NotImplemented
def _richcmp_(self, right, op): """ Comparison of ``self`` and ``right``. EXAMPLES:: sage: V = span([[1/2,1,1],[3/2,2,1],[0,0,1]],ZZ) sage: W = V.span([2*V.0+4*V.1, 9*V.0+12*V.1, 4*V.2]) sage: Q = V/W sage: phi = Q.hom([Q.0,Q.0 + 2*Q.1]) sage: phi.im_gens() ((1, 0), (1, 2)) sage: phi.im_gens() is phi.im_gens() True sage: phi == phi True sage: psi = Q.hom([Q.0,Q.0 - 2*Q.1]) sage: phi == psi False sage: psi = Q.hom([Q.0,Q.0 - 2*Q.1]) sage: phi < psi True sage: psi >= phi True sage: psi = Q.hom([Q.0,Q.0 + 2*Q.1]) sage: phi == psi True """ a = (self.domain(), self.codomain()) b = (right.domain(), right.codomain()) if a != b: return (op == op_NE) return richcmp(self.im_gens(), right.im_gens(), op)
def __richcmp__(self, other, op): r""" Only quotients by the *same* ring and same ideal (with the same generators!!) are considered equal. EXAMPLES:: sage: R.<x,y> = PolynomialRing(QQ) sage: S = R.quotient_ring(x^2 + y^2) sage: S == R.quotient_ring(x^2 + y^2) True The ideals `(x^2 + y^2)` and `(-x^2-y^2)` are equal, but since the generators are different, the corresponding quotient rings are not equal:: sage: R.ideal(x^2+y^2) == R.ideal(-x^2 - y^2) True sage: R.quotient_ring(x^2 + y^2) == R.quotient_ring(-x^2 - y^2) False """ if not isinstance(other, QuotientRing_nc): return NotImplemented return richcmp((self.cover_ring(), self.defining_ideal().gens()), (other.cover_ring(), other.defining_ideal().gens()), op)
def __richcmp__(self, other, op) -> bool: """ EXAMPLES:: sage: a = CuspFamily(16, 4, "1"); a (c_{4,1}) sage: b = CuspFamily(16, 4, "2"); b (c_{4,2}) sage: c = CuspFamily(8, 8); c (0) sage: a == a True sage: a == b False sage: a != b True sage: a == c False sage: a < c False sage: a > c True sage: a != "foo" True """ if not isinstance(other, CuspFamily): return NotImplemented return richcmp(self.__tuple, other.__tuple, op)
def _richcmp_(self, other, op): """ Compare ``self`` and ``other``. TESTS:: sage: A = ArtinGroup(['B',3]) sage: x = A([1, 2, 1]) sage: y = A([2, 1, 2]) sage: x == y True sage: x < y^(-1) True sage: A([]) == A.one() True sage: x = A([2, 3, 2, 3]) sage: y = A([3, 2, 3, 2]) sage: x == y True sage: x < y^(-1) True """ if self.Tietze() == other.Tietze(): return rich_to_bool(op, 0) nfself = [i.Tietze() for i in self.left_normal_form()] nfother = [i.Tietze() for i in other.left_normal_form()] return richcmp(nfself, nfother, op)
def _richcmp_(self, other, op): """ Rich comparison. EXAMPLES:: sage: F = FreeAbelianMonoid(5, 'abcde') sage: F(1) 1 sage: a, b, c, d, e = F.gens() sage: x = a^2 * b^3 sage: F(1) < x True sage: x > b True sage: x <= a^4 True sage: x != a*b True sage: a*b == b*a True sage: x > a^3*b^2 False """ return richcmp(self._element_vector, other._element_vector, op)
def _richcmp_(self, other, op): r""" Compare this map to ``other``. .. NOTE:: This implementation assumes that this isomorphism is defined by its domain and codomain. Isomorphisms for which this is not true must override this implementation. EXAMPLES:: sage: K = QQ['x'].fraction_field() sage: L = K.function_field() sage: f = K.coerce_map_from(L) sage: K = QQbar['x'].fraction_field() sage: L = K.function_field() sage: g = K.coerce_map_from(L) sage: f == g False sage: f == f True """ if type(self) != type(other): return NotImplemented from sage.structure.richcmp import richcmp return richcmp((self.domain(), self.codomain()), (other.domain(), other.codomain()), op)
def __richcmp__(self, other, op): """ Compare torsion subgroups. INPUT: - ``other`` -- an object If other is a torsion subgroup, the abelian varieties are compared. Otherwise, the generic behavior for finite abelian variety subgroups is used. EXAMPLES:: sage: G = J0(11).rational_torsion_subgroup(); H = J0(13).rational_torsion_subgroup() sage: G == G True sage: G < H # since 11 < 13 True sage: G > H False """ if isinstance(other, RationalTorsionSubgroup): return richcmp(self.abelian_variety(), other.abelian_variety(), op) return FiniteSubgroup.__richcmp__(self, other, op)
def _richcmp_(self, other, op): """ Rich comparison for equal parents. 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 sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ) sage: dx,dy,dz = W.differentials() sage: dx != dy True sage: W.one() != 1 False """ return richcmp(self.__monomials, other.__monomials, op)
def __richcmp__(self, other, op): """ Standard comparison function. The ordering is just lexicographic on the tuple `(u,r,s,t)`. .. NOTE:: In a list of automorphisms, there is no guarantee that the identity will be first! EXAMPLES:: sage: from sage.schemes.elliptic_curves.weierstrass_morphism import baseWI sage: baseWI(1,2,3,4) == baseWI(1,2,3,4) True sage: baseWI(1,2,3,4) != baseWI(1,2,3,4) False sage: baseWI(1,2,3,4) < baseWI(1,2,3,5) True sage: baseWI(1,2,3,4) > baseWI(1,2,3,4) False It will never return equality if ``other`` is of another type:: sage: baseWI() == 1 False """ if not isinstance(other, baseWI): return (op == op_NE) return richcmp(self.tuple(), other.tuple(), op)
def __richcmp__(self, other, op): """ Rich comparison. EXAMPLES:: sage: ct1 = CartanType(['A',1],['B',2]) sage: ct2 = CartanType(['B',2],['A',1]) sage: ct3 = CartanType(['A',4]) sage: ct1 == ct1 True sage: ct1 == ct2 False sage: ct1 == ct3 False TESTS: Check that :trac:`20418` is fixed:: sage: ct = CartanType(["A2", "B2"]) sage: ct == (1, 2, 1) False """ if isinstance(other, CartanType_simple): return rich_to_bool(op, 1) if not isinstance(other, CartanType): return NotImplemented return richcmp(self._types, other._types, op)
def _richcmp_(self, other, op): r""" Comparison of self and other. EXAMPLES:: sage: p1 = HyperbolicPlane().UHP().get_point(1 + I) sage: p2 = HyperbolicPlane().UHP().get_point(2 + I) sage: p1 == p2 False sage: p1 == p1 True sage: p1 = HyperbolicPlane().PD().get_point(0) sage: p2 = HyperbolicPlane().PD().get_point(1/2 + 2*I/3) sage: p1 == p2 False sage: p1 == p1 True sage: p1 = HyperbolicPlane().KM().get_point((0,0)) sage: p2 = HyperbolicPlane().KM().get_point((0, 1/2)) sage: p1 == p2 False sage: p1 = HyperbolicPlane().HM().get_point((0,0,1)) sage: p2 = HyperbolicPlane().HM().get_point((0,0,1/1)) sage: p1 == p2 True """ if not(isinstance(other, HyperbolicPoint) or self.parent() is other.parent()): return op == op_NE # bool is required to convert symbolic (in)equalities return bool(richcmp(self._coordinates, other._coordinates, op))
def _richcmp_(self, other, op): """ Rich comparison of morphisms. EXAMPLES:: sage: V = ZZ^2 sage: phi = V.hom([3*V.0, 2*V.1]) sage: psi = V.hom([5*V.0, 5*V.1]) sage: id = V.hom([V.0, V.1]) sage: phi == phi True sage: phi == psi False sage: psi == End(V)(5) True sage: psi == 5 * id True sage: psi == 5 # no coercion False sage: id == End(V).identity() True """ if not isinstance(other, MatrixMorphism) or op not in (op_EQ, op_NE): # Generic comparison return sage.categories.morphism.Morphism._richcmp_(self, other, op) return richcmp(self.matrix(), other.matrix(), op)
def __richcmp__(self, other, op): """ Standard comparison function. The ordering is just lexicographic on the tuple `(u,r,s,t)`. .. NOTE:: In a list of automorphisms, there is no guarantee that the identity will be first! EXAMPLES:: sage: from sage.schemes.elliptic_curves.weierstrass_morphism import baseWI sage: baseWI(1,2,3,4) == baseWI(1,2,3,4) True sage: baseWI(1,2,3,4) < baseWI(1,2,3,5) True sage: baseWI(1,2,3,4) > baseWI(1,2,3,4) False It will never return equality if other is of another type:: sage: baseWI() == 1 False """ if not isinstance(other, baseWI): return (op == op_NE) return richcmp(self.tuple(), other.tuple(), op)
def _richcmp_(self, other, op): """ EXAMPLES:: sage: C = crystals.FastRankTwo(['A',2],shape=[2,1]) sage: D = crystals.FastRankTwo(['B',2],shape=[2,1]) sage: C(0) == C(0) True sage: C(1) == C(0) False sage: C(0) == D(0) False sage: C = crystals.FastRankTwo(['A',2],shape=[2,1]) sage: D = crystals.FastRankTwo(['B',2],shape=[2,1]) sage: C(0) != C(0) False sage: C(1) != C(0) True sage: C(0) != D(0) True sage: C = crystals.FastRankTwo(['A',2],shape=[2,1]) sage: C(1) < C(2) True sage: C(2) < C(1) False sage: C(2) > C(1) True sage: C(1) <= C(1) True """ return richcmp(self.value, other.value, op)
def _richcmp_(self, other, op): r""" Comparison of self and other. EXAMPLES:: sage: p1 = HyperbolicPlane().UHP().get_point(1 + I) sage: p2 = HyperbolicPlane().UHP().get_point(2 + I) sage: p1 == p2 False sage: p1 == p1 True sage: p1 = HyperbolicPlane().PD().get_point(0) sage: p2 = HyperbolicPlane().PD().get_point(1/2 + 2*I/3) sage: p1 == p2 False sage: p1 == p1 True sage: p1 = HyperbolicPlane().KM().get_point((0,0)) sage: p2 = HyperbolicPlane().KM().get_point((0, 1/2)) sage: p1 == p2 False sage: p1 = HyperbolicPlane().HM().get_point((0,0,1)) sage: p2 = HyperbolicPlane().HM().get_point((0,0,1/1)) sage: p1 == p2 True """ if not (isinstance(other, HyperbolicPoint) or self.parent() is other.parent()): return op == op_NE # bool is required to convert symbolic (in)equalities return bool(richcmp(self._coordinates, other._coordinates, op))
def __richcmp__(self, other, op): """ Compare ``self`` and ``other``. INPUT: - ``other`` -- anything. OUTPUT: Two faces test equal if and only if they are faces of the same (not just isomorphic) polyhedron and their generators have the same indices. EXAMPLES:: sage: square = polytopes.hypercube(2) sage: f = square.faces(1) sage: matrix(4,4, lambda i,j: ZZ(f[i] <= f[j])) [1 1 1 0] [0 1 0 0] [0 1 1 0] [1 1 1 1] sage: matrix(4,4, lambda i,j: ZZ(f[i] == f[j])) == 1 True """ if not isinstance(other, PolyhedronFace): return NotImplemented if self._polyhedron is not other._polyhedron: return NotImplemented return richcmp(self._ambient_Vrepresentation_indices, other._ambient_Vrepresentation_indices, op)
def __richcmp__(self, other, op): r""" Check whether ``self`` is equal to ``other``. .. TODO:: This overwrites the equality check of :class:`~sage.structure.list_clone.ClonableArray` in order to circumvent the coercion framework. Eventually this should be solved more elegantly. For now, two elements are compared by their defining lists. """ if isinstance(other, SuperPartition): return richcmp(list(self), list(other), op) else: return richcmp(list(self), other, op)
def _richcmp_(self, other, op): """ EXAMPLES: For == operator:: sage: A = crystals.KirillovReshetikhin(['C',2,1], 1,2).affinization() sage: S = A.subcrystal(max_depth=2) sage: sorted(S) [[[1, 1]](-1), [[1, 2]](-1), [](0), [[1, 1]](0), [[1, 2]](0), [[1, -2]](0), [[2, 2]](0), [](1), [[2, -1]](1), [[-2, -1]](1), [[-1, -1]](1), [[-1, -1]](2)] For != operator:: sage: ([(i,j) for i in range(len(S)) for j in range(len(S)) if S[i]!=S[j]] ....: == [(i,j) for i in range(len(S)) for j in range(len(S)) if ....: S[i].value!=S[j].value]) True For < operator:: sage: ([(i,j) for i in range(len(S)) for j in range(len(S)) if S[i]<S[j]] ....: == [(i,j) for i in range(len(S)) for j in range(len(S)) if ....: S[i].value<S[j].value]) True For <= operator:: sage: ([(i,j) for i in range(len(S)) for j in range(len(S)) if S[i]<=S[j]] ....: == [(i,j) for i in range(len(S)) for j in range(len(S)) if ....: S[i].value<=S[j].value]) True For > operator:: sage: ([(i,j) for i in range(len(S)) for j in range(len(S)) if S[i]>S[j]] ....: == [(i,j) for i in range(len(S)) for j in range(len(S)) if ....: S[i].value>S[j].value]) True For >= operator:: sage: ([(i,j) for i in range(len(S)) for j in range(len(S)) if S[i]>=S[j]] ....: == [(i,j) for i in range(len(S)) for j in range(len(S)) if ....: S[i].value>=S[j].value]) True """ return richcmp(self.value, other.value, op)
def _richcmp_(self, other, op): r""" Compare self and other. TESTS:: sage: x = QQ['x'].gen() sage: f = x^5 - x sage: H = HyperellipticCurve(f); H Hyperelliptic Curve over Rational Field defined by y^2 = x^5 - x sage: J = H.jacobian()(QQ); J Set of rational points of Jacobian of Hyperelliptic Curve over Rational Field defined by y^2 = x^5 - x The following point is 2-torsion:: sage: P = J(H.lift_x(-1)); P (x + 1, y) sage: 0 == 2 * P # indirect doctest True sage: P == P True :: sage: Q = J(H.lift_x(-1)) sage: Q == P True :: sage: 2 == Q False sage: P == False False Let's verify the same "points" on different schemes are not equal:: sage: x = QQ['x'].gen() sage: f = x^5 + x sage: H2 = HyperellipticCurve(f) sage: J2 = H2.jacobian()(QQ) :: sage: P1 = J(H.lift_x(0)); P1 (x, y) sage: P2 = J2(H2.lift_x(0)); P2 (x, y) sage: P1 == P2 False """ if self.scheme() != other.scheme(): return op == op_NE # since divisors are internally represented as Mumford divisors, # comparing polynomials is well-defined return richcmp(self.__polys, other.__polys, op)
def _richcmp_(self, right, op): r""" Compare two points in products of projective spaces. INPUT: - ``other`` -- another point OUTPUT: boolean EXAMPLES:: sage: T = ProductProjectiveSpaces([2, 2], ZZ, 'x') sage: P = T([1, 2, 3, 4, 5, 6]) sage: Q = T([2, 4, 6, 4, 5, 6]) sage: P == Q True EXAMPLES:: sage: T = ProductProjectiveSpaces([1, 1, 1], ZZ, 'x') sage: P = T([1, 2, 3, 4, 5, 6]) sage: Q = T([2, 4, 6, 4, 1, 0]) sage: P != Q True EXAMPLES:: sage: T = ProductProjectiveSpaces([1, 1, 1], GF(5), 'x') sage: P = T([3, 2, 3, 4, 1, 0]) sage: Q = T([1, 2, 3, 4, 3, 1]) sage: P > Q True :: sage: T = ProductProjectiveSpaces([1, 1, 1], GF(5), 'x') sage: P = T([1, 2, 3, 4, 1, 0]) sage: Q = T([1, 2, 3, 4, 3, 0]) sage: P == Q True :: sage: T = ProductProjectiveSpaces([1, 1, 1], GF(5), 'x') sage: P = T([1, 2, 3, 4, 1, 0]) sage: Q = T([1, 2, 3, 4, 3, 1]) sage: P < Q True """ #needed for Digraph if not isinstance(right, (ProductProjectiveSpaces_point_ring)): return NotImplemented else: return richcmp(self._points, right._points, op)
def _richcmp_(self, right, op): """ Compare the cusps ``self`` and ``right``. Comparison is as for rational numbers, except with the cusp oo greater than everything but itself. The ordering in comparison is only really meaningful for infinity or elements that coerce to the rationals. EXAMPLES:: sage: Cusp(2/3) == Cusp(oo) False sage: Cusp(2/3) < Cusp(oo) True sage: Cusp(2/3)> Cusp(oo) False sage: Cusp(2/3) > Cusp(5/2) False sage: Cusp(2/3) < Cusp(5/2) True sage: Cusp(2/3) == Cusp(5/2) False sage: Cusp(oo) == Cusp(oo) True sage: 19/3 < Cusp(oo) True sage: Cusp(oo) < 19/3 False sage: Cusp(2/3) < Cusp(11/7) True sage: Cusp(11/7) < Cusp(2/3) False sage: 2 < Cusp(3) True """ if not self.__b: s = Infinity else: s = self._rational_() if not right.__b: o = Infinity else: o = right._rational_() return richcmp(s, o, op)
def _richcmp_(self, right, op): """ Compare ``self`` with ``right``. EXAMPLES:: sage: F = GF(3).algebraic_closure() sage: F.gen(2) == F.gen(3) False """ x, y = self.parent()._to_common_subfield(self, right) return richcmp(x, y, op)