示例#1
0
def _multiple_of_constant(n, pos, const):
    """
    Function for internal use in formatting ticks on axes with
    nice-looking multiples of various symbolic constants, such
    as `\pi` or `e`.  Should only be used via keyword argument
    `tick_formatter` in :meth:`plot.show`.  See documentation
    for the matplotlib.ticker module for more details.

    EXAMPLES:

    Here is the intended use::

        sage: plot(sin(x), (x,0,2*pi), ticks=pi/3, tick_formatter=pi)
        Graphics object consisting of 1 graphics primitive

    Here is an unintended use, which yields unexpected (and probably
    undesired) results::

        sage: plot(x^2, (x, -2, 2), tick_formatter=pi)
        Graphics object consisting of 1 graphics primitive

    We can also use more unusual constant choices::

        sage: plot(ln(x), (x,0,10), ticks=e, tick_formatter=e)
        Graphics object consisting of 1 graphics primitive
        sage: plot(x^2, (x,0,10), ticks=[sqrt(2),8], tick_formatter=sqrt(2))
        Graphics object consisting of 1 graphics primitive
    """
    from sage.misc.latex import latex
    from sage.rings.arith import convergents
    c = [i for i in convergents(n / const.n()) if i.denominator() < 12]
    return '$%s$' % latex(c[-1] * const)
示例#2
0
def _multiple_of_constant(n,pos,const):
    """
    Function for internal use in formatting ticks on axes with
    nice-looking multiples of various symbolic constants, such
    as `\pi` or `e`.  Should only be used via keyword argument
    `tick_formatter` in :meth:`plot.show`.  See documentation
    for the matplotlib.ticker module for more details.

    EXAMPLES:

    Here is the intended use::

        sage: plot(sin(x), (x,0,2*pi), ticks=pi/3, tick_formatter=pi)
        Graphics object consisting of 1 graphics primitive

    Here is an unintended use, which yields unexpected (and probably
    undesired) results::

        sage: plot(x^2, (x, -2, 2), tick_formatter=pi)
        Graphics object consisting of 1 graphics primitive

    We can also use more unusual constant choices::

        sage: plot(ln(x), (x,0,10), ticks=e, tick_formatter=e)
        Graphics object consisting of 1 graphics primitive
        sage: plot(x^2, (x,0,10), ticks=[sqrt(2),8], tick_formatter=sqrt(2))
        Graphics object consisting of 1 graphics primitive
    """
    from sage.misc.latex import latex
    from sage.rings.arith import convergents
    c=[i for i in convergents(n/const.n()) if i.denominator()<12]
    return '$%s$'%latex(c[-1]*const)
示例#3
0
    def unimod_matrices_from_infty(self,r,s):
        """
        Returns a list of matrices whose associated unimodular paths connect r/s to infty.
        (This is Manin's continued fraction trick.)
        
        INPUT:
            r,s -- rational numbers
        
        OUTPUT:
            a list of SL_2(Z) matrices

        EXAMPLES:
        """        
        if s != 0:
            v = []
# the function contfrac_q in https://github.com/williamstein/psage/blob/master/psage/modform/rational/modular_symbol_map.pyx
# is very, very relevant to massively optimizing this.
            list = convergents(QQ(r)/s)  
            for j in range(0,len(list)-1):
                a = list[j].numerator()
                c = list[j].denominator()
                b = list[j+1].numerator()
                d = list[j+1].denominator()
                v = v + [self.flip(Matrix(ZZ,[[(-1)**(j+1)*a,b],[(-1)**(j+1)*c,d]]))]
            return [self.flip(Matrix(ZZ,[[1,list[0].numerator()],[0,list[0].denominator()]]))]+v
        else:
            return []
示例#4
0
def unimod_matrices_to_infty(r, s):
    r"""
    Return
    a list of matrices whose associated unimodular paths connect `0` to ``r/s``.

    INPUT:

    - ``r``, ``s`` -- rational numbers

    OUTPUT:

    - a list of matrices in `SL_2(\ZZ)`

    EXAMPLES::

        sage: v = sage.modular.pollack_stevens.manin_map.unimod_matrices_to_infty(19,23); v
        [
        [1 0]  [ 0  1]  [1 4]  [-4  5]  [ 5 19]
        [0 1], [-1  1], [1 5], [-5  6], [ 6 23]
        ]
        sage: [a.det() for a in v]
        [1, 1, 1, 1, 1]

        sage: sage.modular.pollack_stevens.manin_map.unimod_matrices_to_infty(11,25)
        [
        [1 0]  [ 0  1]  [1 3]  [-3  4]  [ 4 11]
        [0 1], [-1  2], [2 7], [-7  9], [ 9 25]
        ]

    ALGORITHM:

    This is Manin's continued fraction trick, which gives an expression
    `{0,r/s} = {0,\infty} + ... + {a,b} + ... + {*,r/s}`, where each `{a,b}` is
    the image of `{0,\infty}` under a matrix in `SL_2(\ZZ)`.

    """
    if s == 0:
        return []
    # the function contfrac_q in
    # https://github.com/williamstein/psage/blob/master/psage/modform/rational/modular_symbol_map.pyx
    # is very, very relevant to massively optimizing this.
    L = convergents(r / s)
    # Computes the continued fraction convergents of r/s
    v = [M2Z([1, L[0].numerator(), 0, L[0].denominator()])]
    # Initializes the list of matrices
    for j in range(0, len(L)-1):
        a = L[j].numerator()
        c = L[j].denominator()
        b = L[j + 1].numerator()
        d = L[j + 1].denominator()
        v.append(M2Z([(-1)**(j + 1) * a, b, (-1)**(j + 1) * c, d]))
        # The matrix connecting two consecutive convergents is added on
    return v
示例#5
0
def unimod_matrices_to_infty(r, s):
    r"""
    Return a list of matrices whose associated unimodular paths connect `0` to ``r/s``.

    INPUT:

    - ``r``, ``s`` -- rational numbers

    OUTPUT:

    - a list of matrices in `SL_2(\ZZ)`

    EXAMPLES::

        sage: v = sage.modular.pollack_stevens.manin_map.unimod_matrices_to_infty(19,23); v
        [
        [1 0]  [ 0  1]  [1 4]  [-4  5]  [ 5 19]
        [0 1], [-1  1], [1 5], [-5  6], [ 6 23]
        ]
        sage: [a.det() for a in v]
        [1, 1, 1, 1, 1]

        sage: sage.modular.pollack_stevens.manin_map.unimod_matrices_to_infty(11,25)
        [
        [1 0]  [ 0  1]  [1 3]  [-3  4]  [ 4 11]
        [0 1], [-1  2], [2 7], [-7  9], [ 9 25]
        ]


    ALGORITHM:

    This is Manin's continued fraction trick, which gives an expression
    `{0,r/s} = {0,\infty} + ... + {a,b} + ... + {*,r/s}`, where each `{a,b}` is
    the image of `{0,\infty}` under a matrix in `SL_2(\ZZ)`.

    """
    if s == 0:
        return []
    # the function contfrac_q in
    # https://github.com/williamstein/psage/blob/master/psage/modform/rational/modular_symbol_map.pyx
    # is very, very relevant to massively optimizing this.
    L = convergents(r / s)
    # Computes the continued fraction convergents of r/s
    v = [M2Z([1, L[0].numerator(), 0, L[0].denominator()])]
    # Initializes the list of matrices
    for j in range(0, len(L)-1):
        a = L[j].numerator()
        c = L[j].denominator()
        b = L[j + 1].numerator()
        d = L[j + 1].denominator()
        v.append(M2Z([(-1)**(j + 1) * a, b, (-1)**(j + 1) * c, d]))
        # The matrix connecting two consecutive convergents is added on
    return v
示例#6
0
def unimod_matrices_from_infty(r, s):
    r"""
    Return a list of matrices whose associated unimodular paths connect `\infty` to ``r/s``.

    INPUT:

    - ``r``, ``s`` -- rational numbers

    OUTPUT:

    - a list of `SL_2(\ZZ)` matrices

    EXAMPLES::

        sage: v = sage.modular.pollack_stevens.manin_map.unimod_matrices_from_infty(19,23); v
        [
        [ 0  1]  [-1  0]  [-4  1]  [-5 -4]  [-19   5]
        [-1  0], [-1 -1], [-5  1], [-6 -5], [-23   6]
        ]
        sage: [a.det() for a in v]
        [1, 1, 1, 1, 1]
        
        sage: sage.modular.pollack_stevens.manin_map.unimod_matrices_from_infty(11,25)
        [
        [ 0  1]  [-1  0]  [-3  1]  [-4 -3]  [-11   4]
        [-1  0], [-2 -1], [-7  2], [-9 -7], [-25   9]
        ]

        
    ALGORITHM:
        
    This is Manin's continued fraction trick, which gives an expression
    `{\infty,r/s} = {\infty,0} + ... + {a,b} + ... + {*,r/s}`, where each
    `{a,b}` is the image of `{0,\infty}` under a matrix in `SL_2(\ZZ)`.
        
    """
    if s != 0:
        L = convergents(r / s)
        # Computes the continued fraction convergents of r/s
        v = [M2Z([-L[0].numerator(), 1, -L[0].denominator(), 0])]
        # Initializes the list of matrices
        # the function contfrac_q in https://github.com/williamstein/psage/blob/master/psage/modform/rational/modular_symbol_map.pyx
        # is very, very relevant to massively optimizing this.
        for j in range(0, len(L) - 1):
            a = L[j].numerator()
            c = L[j].denominator()
            b = L[j + 1].numerator()
            d = L[j + 1].denominator()
            v.append(M2Z([-b, (-1)**(j + 1) * a, -d, (-1)**(j + 1) * c]))
            # The matrix connecting two consecutive convergents is added on
        return v
    else:
        return []
示例#7
0
    def __manin_symbol_rep(self, alpha):
        """
        Return Manin symbol representation of X^i*Y^(k-2-i){0,alpha}.

        EXAMPLES::

            sage: s = ModularSymbols(11,2).1.modular_symbol_rep()[0][1]; s
            {-1/8, 0}
            sage: s.manin_symbol_rep()          # indirect doctest
            -(-8,1) - (1,1)
            sage: M = ModularSymbols(11,2)
            sage: s = M( (1,9) ); s
            (1,9)
            sage: t = s.modular_symbol_rep()[0][1].manin_symbol_rep(); t
            -(-9,1) - (1,1)
            sage: M(t)
            (1,9)
        """
        space = self.__space
        i = self.__i
        k = space.weight()
        v = [(0, 1), (1, 0)]
        if not alpha.is_infinity():
            v += [(x.numerator(), x.denominator())
                  for x in arith.convergents(alpha._rational_())]
        sign = 1
        apply = sage.modular.modsym.manin_symbols.apply_to_monomial
        mansym = sage.modular.modsym.manin_symbols.ManinSymbol
        z = formal_sum.FormalSum(0)
        for j in range(1, len(v)):
            c = sign * v[j][1]
            d = v[j - 1][1]
            coeffs = apply(i, k - 2, sign * v[j][0], v[j - 1][0],
                           sign * v[j][1], v[j - 1][1])
            w = [(coeffs[j], mansym(space, (j, c, d))) \
                       for j in range(k-1) if coeffs[j] != 0]
            z += formal_sum.FormalSum(w)
            sign *= -1
        return z
示例#8
0
    def __manin_symbol_rep(self, alpha):
        """
        Return Manin symbol representation of X^i*Y^(k-2-i){0,alpha}.

        EXAMPLES::

            sage: s = ModularSymbols(11,2).1.modular_symbol_rep()[0][1]; s
            {-1/8, 0}
            sage: s.manin_symbol_rep()          # indirect doctest
            -(-8,1) - (1,1)
            sage: M = ModularSymbols(11,2)
            sage: s = M( (1,9) ); s 
            (1,9)
            sage: t = s.modular_symbol_rep()[0][1].manin_symbol_rep(); t
            -(-9,1) - (1,1)
            sage: M(t)
            (1,9)
        """
        space = self.__space
        i = self.__i
        k = space.weight()
        v = [(0,1), (1,0)]
        if not alpha.is_infinity():
            v += [(x.numerator(), x.denominator()) for x in arith.convergents(alpha._rational_())]
        sign = 1
        apply = sage.modular.modsym.manin_symbols.apply_to_monomial
        mansym = sage.modular.modsym.manin_symbols.ManinSymbol
        z = formal_sum.FormalSum(0)
        for j in range(1,len(v)):
            c = sign*v[j][1]
            d = v[j-1][1]
            coeffs = apply(i, k-2, sign*v[j][0], v[j-1][0], sign*v[j][1], v[j-1][1])
            w = [(coeffs[j], mansym(space, (j, c, d))) \
                       for j in range(k-1) if coeffs[j] != 0]
            z += formal_sum.FormalSum(w)
            sign *= -1
        return z