Пример #1
0
    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)
Пример #2
0
        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)
Пример #3
0
        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),
                 [[2, -1]](1),
                 [[-1, -1]](1),
                 [](1),
                 [[-2, -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)
Пример #4
0
        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),
                 [[2, -1]](1),
                 [[-1, -1]](1),
                 [](1),
                 [[-2, -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)
Пример #5
0
    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)
Пример #6
0
    def _richcmp_(self, other, op):
        """
        Elements of this crystal are compared using the comparison in
        the underlying classical crystal.

        Non elements of the crystal are not comparable with elements of the
        crystal, so we return ``NotImplemented``.

        EXAMPLES::

            sage: K = crystals.KirillovReshetikhin(['A',2,1],1,1)
            sage: b = K(rows=[[1]])
            sage: c = K(rows=[[2]])

            sage: b == c
            False
            sage: b == b
            True

            sage: b != c
            True
            sage: b != b
            False

            sage: c < b
            False
            sage: b < b
            False
            sage: b < c
            True

            sage: b > c
            False
            sage: b > b
            False
            sage: c > b
            True

            sage: b <= c
            True
            sage: b <= b
            True
            sage: c <= b
            False

            sage: c >= b
            True
            sage: b >= b
            True
            sage: b >= c
            False
        """
        return richcmp(self.value, other.value, op)
Пример #7
0
    def _richcmp_(left, right, op):
        """
        Compare two free algebra elements with the same parents.

        The ordering is the one on the underlying sorted list of
        (monomial,coefficients) pairs.

        EXAMPLES::

            sage: R.<x,y> = FreeAlgebra(QQ,2)
            sage: x < y
            True
            sage: x * y < y * x
            True
            sage: y * x < x * y
            False
        """
        v = sorted(left._monomial_coefficients.items())
        w = sorted(right._monomial_coefficients.items())
        return richcmp(v, w, op)
Пример #8
0
    def _richcmp_(self, right, op):
        """
        Compare the cusps ``self`` and ``right``.

        Comparison is as for elements in the number field, except with
        the cusp oo which is greater than everything but itself.

        The ordering in comparison is only really meaningful for infinity.

        EXAMPLES::

            sage: k.<a> = NumberField(x^3 + x + 1)
            sage: kCusps = NFCusps(k)

        Comparing with infinity::

            sage: c = kCusps((a,2))
            sage: d = kCusps(oo)
            sage: c < d
            True
            sage: kCusps(oo) < d
            False

        Comparison as elements of the number field::

            sage: kCusps(2/3) < kCusps(5/2)
            False
            sage: k(2/3) < k(5/2)
            False
        """
        if self.__b.is_zero():
            if right.__b.is_zero():
                return rich_to_bool(op, 0)
            else:
                return rich_to_bool(op, 1)
        else:
            if right.__b.is_zero():
                return rich_to_bool(op, -1)
            else:
                return richcmp(self._number_field_element_(),
                               right._number_field_element_(), op)
Пример #9
0
    def _richcmp_(self, right, op):
        """
        Compare self and right.

        EXAMPLES::

            sage: V = span([[1/2,1,1],[3/2,2,1],[0,0,1]],ZZ); W = V.span([2*V.0+4*V.1, 9*V.0+12*V.1, 4*V.2])
            sage: Q = V/W; Q
            Finitely generated module V/W over Integer Ring with invariants (4, 12)
            sage: x = Q.0; x
            (1, 0)
            sage: y = Q.1; y
            (0, 1)
            sage: x == y
            False
            sage: x == x
            True
            sage: x + x == 2*x
            True
        """
        return richcmp(self.vector(), right.vector(), op)
Пример #10
0
        def _richcmp_(self, other, op):
            """
            Comparison.

            TESTS::

                sage: A = crystals.KirillovReshetikhin(['A',2,1], 2, 2).affinization()
                sage: mg = A.module_generators[0]
                sage: mg == mg
                True
                sage: mg == mg.f(2).e(2)
                True
                sage: KT = crystals.TensorProductOfKirillovReshetikhinTableaux(['C',2,1], [[1,2],[2,1]])
                sage: A = crystals.AffinizationOf(KT)
                sage: A(KT.module_generators[3], 1).f(0) == A.module_generators[0]
                True

                sage: A = crystals.KirillovReshetikhin(['A',2,1], 2, 2).affinization()
                sage: mg = A.module_generators[0]
                sage: mg != mg.f(2)
                True
                sage: mg != mg.f(2).e(2)
                False


                sage: A = crystals.KirillovReshetikhin(['A',2,1], 2, 2).affinization()
                sage: S = A.subcrystal(max_depth=2)
                sage: sorted(S)
                [[[1, 1], [2, 2]](0),
                 [[1, 1], [2, 3]](0),
                 [[1, 2], [2, 3]](0),
                 [[1, 1], [3, 3]](0),
                 [[1, 1], [2, 3]](1),
                 [[1, 2], [2, 3]](1),
                 [[1, 2], [3, 3]](1),
                 [[2, 2], [3, 3]](2)]
            """
            return richcmp((self._m, self._b), (other._m, other._b), op)
Пример #11
0
        def _richcmp_(self, other, op):
            """
            Comparison.

            TESTS::

                sage: A = crystals.KirillovReshetikhin(['A',2,1], 2, 2).affinization()
                sage: mg = A.module_generators[0]
                sage: mg == mg
                True
                sage: mg == mg.f(2).e(2)
                True
                sage: KT = crystals.TensorProductOfKirillovReshetikhinTableaux(['C',2,1], [[1,2],[2,1]])
                sage: A = crystals.AffinizationOf(KT)
                sage: A(KT.module_generators[3], 1).f(0) == A.module_generators[0]
                True

                sage: A = crystals.KirillovReshetikhin(['A',2,1], 2, 2).affinization()
                sage: mg = A.module_generators[0]
                sage: mg != mg.f(2)
                True
                sage: mg != mg.f(2).e(2)
                False


                sage: A = crystals.KirillovReshetikhin(['A',2,1], 2, 2).affinization()
                sage: S = A.subcrystal(max_depth=2)
                sage: sorted(S)
                [[[1, 1], [2, 2]](0),
                 [[1, 1], [2, 3]](0),
                 [[1, 2], [2, 3]](0),
                 [[1, 1], [3, 3]](0),
                 [[1, 1], [2, 3]](1),
                 [[1, 2], [2, 3]](1),
                 [[1, 2], [3, 3]](1),
                 [[2, 2], [3, 3]](2)]
            """
            return richcmp((self._m, self._b), (other._m, other._b), op)
Пример #12
0
    def _richcmp_(self, other, op):
        r"""
        Comparisons

        TESTS::

            sage: F = FreeMonoid(index_set=ZZ)
            sage: a,b,c,d,e = [F.gen(i) for i in range(5)]
            sage: a == a
            True
            sage: a*e == a*e
            True
            sage: a*b*c^3*b*d == (a*b*c)*(c^2*b*d)
            True
            sage: a != b
            True
            sage: a*b != b*a
            True
            sage: a*b*c^3*b*d != (a*b*c)*(c^2*b*d)
            False

            sage: F = FreeMonoid(index_set=ZZ)
            sage: a,b,c,d,e = [F.gen(i) for i in range(5)]
            sage: a < b
            True
            sage: a*b < b*a
            True
            sage: a*b < a*a
            False
            sage: a^2*b < a*b*b
            True
            sage: b > a
            True
            sage: a*b > b*a
            False
            sage: a*b > a*a
            True
            sage: a*b <= b*a
            True
            sage: a*b <= b*a
            True

            sage: FA = FreeAbelianMonoid(index_set=ZZ)
            sage: a,b,c,d,e = [FA.gen(i) for i in range(5)]
            sage: a == a
            True
            sage: a*e == e*a
            True
            sage: a*b*c^3*b*d == a*d*(b^2*c^2)*c
            True
            sage: a != b
            True
            sage: a*b != a*a
            True
            sage: a*b*c^3*b*d != a*d*(b^2*c^2)*c
            False
        """
        if self._monomial == other._monomial:
            # Equal
            return rich_to_bool(op, 0)
        if op == op_EQ or op == op_NE:
            # Not equal
            return rich_to_bool(op, 1)
        return richcmp(self.to_word_list(), other.to_word_list(), op)
Пример #13
0
    def _richcmp_(self, other, op):
        r"""
        Comparisons

        TESTS::

            sage: F = FreeMonoid(index_set=ZZ)
            sage: a,b,c,d,e = [F.gen(i) for i in range(5)]
            sage: a == a
            True
            sage: a*e == a*e
            True
            sage: a*b*c^3*b*d == (a*b*c)*(c^2*b*d)
            True
            sage: a != b
            True
            sage: a*b != b*a
            True
            sage: a*b*c^3*b*d != (a*b*c)*(c^2*b*d)
            False

            sage: F = FreeMonoid(index_set=ZZ)
            sage: a,b,c,d,e = [F.gen(i) for i in range(5)]
            sage: a < b
            True
            sage: a*b < b*a
            True
            sage: a*b < a*a
            False
            sage: a^2*b < a*b*b
            True
            sage: b > a
            True
            sage: a*b > b*a
            False
            sage: a*b > a*a
            True
            sage: a*b <= b*a
            True
            sage: a*b <= b*a
            True

            sage: FA = FreeAbelianMonoid(index_set=ZZ)
            sage: a,b,c,d,e = [FA.gen(i) for i in range(5)]
            sage: a == a
            True
            sage: a*e == e*a
            True
            sage: a*b*c^3*b*d == a*d*(b^2*c^2)*c
            True
            sage: a != b
            True
            sage: a*b != a*a
            True
            sage: a*b*c^3*b*d != a*d*(b^2*c^2)*c
            False
        """
        if self._monomial == other._monomial:
            # Equal
            return rich_to_bool(op, 0)
        if op == op_EQ or op == op_NE:
            # Not equal
            return rich_to_bool(op, 1)
        return richcmp(self.to_word_list(), other.to_word_list(), op)