Example #1
0
        def _repr_(self):
            r"""
            Return a string representation of ``self``.

            Supports printing in exponential coordinates of the first and
            second kinds, depending on the default coordinate system.

            EXAMPLES::

                sage: L = LieAlgebra(QQ, 2, step=2)
                sage: G = L.lie_group('H')
                sage: g = G.point([1, 2, 3]); g
                exp(X_1 + 2*X_2 + 3*X_12)
                sage: G.set_default_chart(G.chart_exp2())
                sage: g
                exp(4*X_12)exp(2*X_2)exp(X_1)
            """
            G = self.parent()
            chart = G.default_chart()
            if chart != G._Exp1:
                if chart != G.chart_exp2():
                    chart = G._Exp1

            x = self.coordinates(chart=chart)
            B = G.lie_algebra().basis()
            nonzero_pairs = [(Xk, xk) for Xk, xk in zip(B, x) if xk]

            if chart == G._Exp1:
                s = repr_lincomb(nonzero_pairs)
            else:
                s = ")exp(".join(repr_lincomb([(Xk, xk)])
                                 for Xk, xk in reversed(nonzero_pairs))
                if not s:
                    s = "0"
            return "exp(%s)" % s
Example #2
0
    def _repr_(self):
        r"""
        Return a string representation of ``self``.

        OUTPUT:

        - string.

        TESTS::

            sage: R.<x, y> = ZZ[]
            sage: S = Spec(R)
            sage: from sage.schemes.generic.divisor import Divisor_generic
            sage: from sage.schemes.generic.divisor_group import DivisorGroup
            sage: Div = DivisorGroup(S)
            sage: D = Divisor_generic([(4, x), (-5, y), (1, x+2*y)], Div)
            sage: D._repr_()
            'V(x + 2*y) + 4*V(x) - 5*V(y)'
        """
        # The default representation coming from formal sums does not look
        # very nice for divisors
        terms = list(self)
        # We sort the terms by variety. The order is "reversed" to keep it
        # straight - as the test above demonstrates, it results in the first
        # generator being in front of the second one
        terms.sort(key=lambda x: x[1], reverse=True)
        return repr_lincomb([("V(%s)" % v, c) for c, v in terms])
    def _repr_(self):
        """
        Return string representation of self.

        EXAMPLES::

            sage: A.<x,y,z> = FreeAlgebra(ZZ,3)
            sage: repr(-x+3*y*z)    # indirect doctest
            '-x + 3*y*z'

        Trac ticket :trac:`11068` enables the use of local variable names::

            sage: from sage.structure.parent_gens import localvars
            sage: with localvars(A, ['a','b','c']):
            ....:    print(-x+3*y*z)
            -a + 3*b*c

        """
        v = sorted(self._monomial_coefficients.items())
        P = self.parent()
        M = P.monoid()
        from sage.structure.parent_gens import localvars
        with localvars(M, P.variable_names(), normalize=False):
            x = repr_lincomb(v, strip_one=True)
        return x
Example #4
0
    def _latex_(self):
        r"""
        Return a LaTeX representation of ``self``.

        OUTPUT:

        - string.

        TESTS::

            sage: R.<x, y> = ZZ[]
            sage: S = Spec(R)
            sage: from sage.schemes.generic.divisor import Divisor_generic
            sage: from sage.schemes.generic.divisor_group import DivisorGroup
            sage: Div = DivisorGroup(S)
            sage: D = Divisor_generic([(4, x), (-5, y), (1, x+2*y)], Div)
            sage: D._latex_()
            '\\mathrm{V}\\left(x + 2 y\\right)
            + 4 \\mathrm{V}\\left(x\\right)
            - 5 \\mathrm{V}\\left(y\\right)'
        """
        # The code is copied from _repr_ with latex adjustments
        terms = list(self)
        # We sort the terms by variety. The order is "reversed" to keep it
        # straight - as the test above demonstrates, it results in the first
        # generator being in front of the second one
        terms.sort(key=lambda x: x[1], reverse=True)
        return repr_lincomb([(r"\mathrm{V}\left(%s\right)" % latex(v), c)
                             for c, v in terms],
                            is_latex=True)
Example #5
0
    def _repr_(self):
        """
        EXAMPLES::

            sage: a = FormalSum([(1,2/3), (-3,4/5), (7,Mod(2,3))])
            sage: a   # random, since comparing Mod(2,3) and rationals ill-defined
            sage: a._repr_()    # random
            '2/3 - 3*4/5 + 7*2'
        """
        return repr_lincomb([t, c] for c, t in self)
Example #6
0
 def __repr__(self):
     from cutgeneratingfunctionology.spam.parametric_real_field_element import is_parametric_element
     # Following the Sage convention of returning a pretty-printed
     # expression in __repr__ (rather than __str__).
     if not(is_parametric_element(self._slope) or is_parametric_element(self._intercept)):
         # repr_lincomb tests for 0, don't do this for parametric elements.
         try:
             return '<FastLinearFunction ' + repr_lincomb([('x', self._slope), (1, self._intercept)], strip_one = True) + '>'
         except TypeError:
             pass
     return '<FastLinearFunction (%s)*x + (%s)>' % (self._slope, self._intercept)
Example #7
0
    def _latex_(self):
        r"""
        EXAMPLES::

            sage: latex(FormalSum([(1,2), (5, 8/9), (-3, 7)]))
            2 + 5\cdot \frac{8}{9} - 3\cdot 7
        """
        from sage.misc.latex import repr_lincomb
        symbols = [z[1] for z in self]
        coeffs = [z[0] for z in self]
        return repr_lincomb(symbols, coeffs)
Example #8
0
    def _repr_(self):
        """
        Return the string representation of ``self``.

        EXAMPLES::

            sage: ModularSymbols(Gamma0(11), 2).boundary_space()(Cusp(0))._repr_()
            '[0]'
            sage: (-6*ModularSymbols(Gamma0(11), 2).boundary_space()(Cusp(0)))._repr_()
            '-6*[0]'
        """
        return repr_lincomb([('[' + repr(self.parent()._known_gens[i]) + ']',
                              c) for i, c in sorted(self.__x.items())])
Example #9
0
    def _latex_(self):
        """
        EXAMPLES::

            sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)
            sage: ((2/3)*i - j)._latex_()
            '\\frac{2}{3} i - j'
        """
        Q = self.parent()
        M = Q.monoid()
        with localvars(M, Q.variable_names()):
            cffs = tuple(self.__vector)
            mons = Q.monomial_basis()
            return repr_lincomb(zip(mons, cffs), is_latex=True, strip_one=True)
Example #10
0
    def _repr_(self):
        """
        EXAMPLES::

            sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(ZZ)
            sage: i._repr_()
            'i'
        """
        Q = self.parent()
        M = Q.monoid()
        with localvars(M, Q.variable_names()):
            cffs = list(self.__vector)
            mons = Q.monomial_basis()
            return repr_lincomb(zip(mons, cffs), strip_one=True)
Example #11
0
    def _latex_(self):
        r"""
        A visual representation of this element.

        For a free generator `L`, the element `\frac{T^{j}}{j!}L` is
        denoted by ``T^(j)L``.

        EXAMPLES::

            sage: V = lie_conformal_algebras.Virasoro(QQ); V.inject_variables()
            Defining L, C
            sage: latex(L.T(2))
            2T^{(2)}L

            sage: R = lie_conformal_algebras.Affine(QQbar, 'A1', names=('e','h','f')); R.inject_variables()
            Defining e, h, f, K
            sage: latex(e.bracket(f))
            \left\{0 : h, 1 : K\right\}
            sage: latex(e.T(3))
            6T^{(3)}e

            sage: R = lie_conformal_algebras.Affine(QQbar, 'A1')
            sage: latex(R.0.bracket(R.2))
            \left\{0 : \alpha^\vee_{1}, 1 : \text{\texttt{K}}\right\}

            sage: R = lie_conformal_algebras.Affine(QQ, 'A1'); latex(R.0.T(3))
            6T^{(3)}\alpha_{1}
        """
        if self.is_zero():
            return "0"
        p = self.parent()
        try:
            names = p.latex_variable_names()
        except ValueError:
            names = None
        if names:
            terms = [("T^{{({0})}}{1}".format(k[1],
                        names[p._index_to_pos[k[0]]]),v) if k[1] > 1 \
                else("T{}".format(names[p._index_to_pos[k[0]]]),v)\
                if k[1] == 1\
                else ("{}".format(names[p._index_to_pos[k[0]]]),v)\
                        for k,v in self.monomial_coefficients().items()]
        else:
            terms = [("T^{{({0})}}{1}".format(k[1], latex(k[0])),v) if k[1] > 1 \
                      else("T{}".format(latex(k[0])),v) if k[1] == 1 \
                        else ("{}".format(latex(k[0])),v)\
                        for k,v in self.monomial_coefficients().items()]

        return repr_lincomb(terms, is_latex=True, strip_one=True)
    def _latex_(self):
        r"""
        Return latex representation of self.

        EXAMPLES::

            sage: A.<x,y,z>=FreeAlgebra(ZZ,3)
            sage: latex(-x+3*y^20*z)   # indirect doctest
            -x + 3 y^{20}z
            sage: alpha,beta,gamma=FreeAlgebra(ZZ,3,'alpha,beta,gamma').gens()
            sage: latex(alpha-beta)
            \alpha - \beta
        """
        v = sorted(self._monomial_coefficients.items())
        return repr_lincomb(v, strip_one=True, is_latex=True)
Example #13
0
    def _repr_(self):
        r"""
        Return a string representation.

        OUTPUT:

        A string.

        EXAMPLES::

            sage: E = EllipticCurve([0, 0, 1, -1, 0])
            sage: E.divisor( E(0,0) )._repr_()
            '(x, y)'
        """
        return repr_lincomb([(tuple(I.gens()), c) for c, I in self])
Example #14
0
    def _repr_(self):
        r"""
        A visual representation of this element.

        For a free generator `L`, the element `\frac{T^{j}}{j!}L` is
        denoted by ``T^(j)L``.

        EXAMPLES::

            sage: V = lie_conformal_algebras.Virasoro(QQ); V.inject_variables()
            Defining L, C
            sage: v = L.T(5).nproduct(L,6); v
            -1440*L
            sage: L.T(2) + L + C
            2*T^(2)L + L + C
            sage: L.T(4)
            24*T^(4)L

            sage: R = lie_conformal_algebras.Affine(QQ, 'B3')
            sage: R.2.T()+3*R.3
            TB[alpha[1]] + 3*B[alpha[2] + alpha[3]]
        """
        if self.is_zero():
            return "0"
        p = self.parent()
        if p._names:
            terms = [("T^({0}){1}".format(k[1],
                        p._names[p._index_to_pos[k[0]]]),v) if k[1] > 1 \
                    else("T{}".format(p._names[p._index_to_pos[k[0]]]),v) \
                    if k[1] == 1 \
                    else ("{}".format(p._names[p._index_to_pos[k[0]]]),v)\
                        for k,v in self.monomial_coefficients().items()]
        else:
            terms = [("T^({0}){1}".format(k[1], p._repr_generator(k[0])),v)\
                      if k[1] > 1 else("T{}".format(p._repr_generator(k[0])),v)\
                      if k[1] == 1 else ("{}".format(p._repr_generator(k[0])),
                      v) for k,v in self.monomial_coefficients().items()]

        return repr_lincomb(terms, strip_one=True)
Example #15
0
    def _repr_(self):
        r"""
        String representation of self. The output will depend on the global
        modular symbols print mode setting controlled by the function
        ``set_modsym_print_mode``.

        EXAMPLES::

            sage: M = ModularSymbols(13, 4)
            sage: set_modsym_print_mode('manin'); M.0._repr_()
            '[X^2,(0,1)]'
            sage: set_modsym_print_mode('modular'); M.0._repr_()
            'X^2*{0, Infinity}'
            sage: set_modsym_print_mode('vector'); M.0._repr_()
            '(1, 0, 0, 0, 0, 0, 0, 0)'
            sage: set_modsym_print_mode()
        """
        if _print_mode == "vector":
            return str(self.element())
        elif _print_mode == "manin":
            m = self.manin_symbol_rep()
        elif _print_mode == "modular":
            m = self.modular_symbol_rep()
        return repr_lincomb([(t, c) for c, t in m])