Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
241720 views
�
�>Yc@s�dZddlZddlZddlZddlmZmZmZmZm	Z	m
Z
ddlmZm
Z
mZmZmZmZmZddlmZddlmZddlmZddlZej�ddlmZdd	lmZdd
l m!Z!ddl"m#Z#ddl$m%Z%dd
l&m'Z'dd
l m!Z!ddl(m)Z)ddl*Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1ed�Z2d�Z3d�Z4d�Z5d�Z6de7fd��YZ8de7fd��YZ9e9�Z:de7fd��YZ;de7fd��YZ<de7fd��YZ=d e;fd!��YZ>d"e;fd#��YZ?d$e;fd%��YZ@d&e@fd'��YZAd(e@fd)��YZBd*e;fd+��YZCd,e;fd-��YZDd.e;fd/��YZEd0eEfd1��YZFd2�ZGd3eEfd4��YZHd5e;fd6��YZId7�ZJd8d9�ZKd:e=fd;��YZLd<e=fd=��YZMd>e;fd?��YZNd@�ZOdA�ZPdS(Bs'
General L-series

AUTHOR:
    - William Stein

TODO:
    - Symmetric powers (and modular degree -- see trac 9758)
    - Triple product L-functions: Gross-Kudla, Zhang, etc -- see the code in triple_prod/triple.py
    - Support L-calc L-function
    - Make it so we use exactly one GP session for *all* of the Dokchitser L-functions
    - Tensor products
    - Genus 2 curves, via smalljac and genus2reduction
    - Fast L-series of elliptic curves over number fields (not just sqrt(5)), via smalljac
    - Inverse of number_of_coefficients function.
i����N(tprime_ranget
cached_methodtsqrttSRtvectortgcd(tZZtIntegertQQtOtComplexFieldtCDFtinfinity(tprimes(tis_RationalField(tis_EllipticCurve(textend_multiplicatively_generic(tprod(tis_ModularAbelianVariety(tis_DirichletCharacter(t
Dokchitser(tis_ModularSymbolsSpace(tis_NumberField(tNewform(t
Factorization(tcartesian_product_iteratorcCst|d�r|j�SdS(sX
    Return precision of s, if it has a precision attribute.  Otherwise
    return 53.  This is useful internally in this module.

    EXAMPLES::

        sage: from psage.lseries.eulerprod import prec
        sage: prec(ComplexField(100)(1))
        100
        sage: prec(RealField(125)(1))
        125
        sage: prec(1/3)
        53
    tpreci5(thasattrR(ts((spsage/eulerprod.pyRAs
cCs'y|j�SWntk
r"|SXdS(s�
    Return the norm of a, for a in either a number field or QQ.

    This is a function used internally in this module, mainly because
    elements of QQ and ZZ have no norm method.

    EXAMPLES::

        sage: from psage.lseries.eulerprod import norm
        sage: K.<a> = NumberField(x^2-x-1)
        sage: norm(a+5)
        29
        sage: (a+5).norm()
        29
        sage: norm(17)
        17
    N(tnormtAttributeError(ta((spsage/eulerprod.pyRTs
cCstddd|d�S(s�
    Return a number that we consider tiny to the given precision prec
    in bits.   This is used in various places as "zero" to the given
    precision for various checks, e.g., of correctness of the
    functional equation.
    g:�0�yE>g�?ii(tmax(R((spsage/eulerprod.pyttinykscCs-y|j�SWntk
r(t|�SXdS(s�
    Return the prime in ZZ below the prime P (or element of QQ).

    EXAMPLES::

        sage: from psage.lseries.eulerprod import prime_below
        sage: K.<a> = NumberField(x^2-x-1)
        sage: prime_below(K.prime_above(11))
        11
        sage: prime_below(K.prime_above(5))
        5
        sage: prime_below(K.prime_above(3))
        3
        sage: prime_below(7)
        7
    N(tsmallest_integerRR(tP((spsage/eulerprod.pytprime_belowts
tLSeriesDerivativecBs>eZdZd�Zd�Zd�Zd�Zdd�ZRS(s�
    The formal derivative of an L-series.

    EXAMPLES::

        sage: from psage.lseries.eulerprod import LSeries
        sage: L = LSeries('delta')
        sage: L.derivative()
        First derivative of L-function associated to Ramanujan's Delta (a weight 12 cusp form)
        sage: L.derivative()(11/2)
        0.125386233743526

    We directly create an instance of the class (users shouldn't need to do this)::

        sage: from psage.lseries.eulerprod import LSeriesDerivative
        sage: Ld = LSeriesDerivative(L, 2); Ld
        Second derivative of L-function associated to Ramanujan's Delta (a weight 12 cusp form)
        sage: type(Ld)
        <class 'psage.lseries.eulerprod.LSeriesDerivative'>
    cCs:t|�}|dkr$td�n||_||_dS(s�
        INPUT:
            - lseries -- any LSeries object (derives from LseriesAbstract)
            - k -- positive integer
        isk must be a positive integerN(Rt
ValueErrort_lseriest_k(tselftlseriestk((spsage/eulerprod.pyt__init__�s
	cCs%t|j|jf|j|jf�S(N(tcmpR'R((R)tright((spsage/eulerprod.pyt__cmp__�scCs%|jjt|��j||j�S(sH
        Return the value of this derivative at s, which must coerce to a
        complex number.  The computation is to the same precision as s,
        or to 53 bits of precision if s is exact.

        As usual, if s has large imaginary part, then there could be
        substantial precision loss (a warning is printed in that case).

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: L = LSeries(EllipticCurve('389a'))
            sage: L1 = L.derivative(1); L1(1)
            -1.94715429754927e-20
            sage: L1(2)
            0.436337613850735
            sage: L1(I)
            -19.8890471908356 + 31.2633280771869*I
            sage: L2 = L.derivative(2); L2(1)
            1.51863300057685
            sage: L2(I)
            134.536162459604 - 62.6542402272310*I
        (R't	_functionRt
derivativeR((R)R((spsage/eulerprod.pyt__call__�scCsc|j}|dkrd}n4|dkr3d}n|dkrHd}n
d|}d||jfS(	s�
        String representation of this derivative of an L-series.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: L = LSeries('delta')
            sage: L.derivative(1).__repr__()
            "First derivative of L-function associated to Ramanujan's Delta (a weight 12 cusp form)"
            sage: L.derivative(2).__repr__()
            "Second derivative of L-function associated to Ramanujan's Delta (a weight 12 cusp form)"
            sage: L.derivative(3).__repr__()
            "Third derivative of L-function associated to Ramanujan's Delta (a weight 12 cusp form)"
            sage: L.derivative(4).__repr__()
            "4-th derivative of L-function associated to Ramanujan's Delta (a weight 12 cusp form)"
            sage: L.derivative(2011).__repr__()
            "2011-th derivative of L-function associated to Ramanujan's Delta (a weight 12 cusp form)"
        itFirstitSeconditThirds%s-ths%s derivative of %s(R(R'(R)R+tkth((spsage/eulerprod.pyt__repr__�s				
icCs'|dkr|St|j|j|�S(s1
        Return the k-th derivative of this derivative object.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: f = Newforms(43,2,names='a')[1]; f
            q + a1*q^2 - a1*q^3 + (-a1 + 2)*q^5 + O(q^6)
            sage: L = LSeries(f); L1 = L.derivative()
            sage: L1(1)
            0.331674007376949
            sage: L(1)
            0.620539857407845
            sage: L = LSeries(f); L1 = L.derivative(); L1
            First derivative of L-series of a degree 2 newform of level 43 and weight 2
            sage: L1.derivative()
            Second derivative of L-series of a degree 2 newform of level 43 and weight 2
            sage: L1.derivative(3)
            4-th derivative of L-series of a degree 2 newform of level 43 and weight 2

        i(R%R'R((R)R+((spsage/eulerprod.pyR1�s(t__name__t
__module__t__doc__R,R/R2R7R1(((spsage/eulerprod.pyR%�s				tLSeriesParentClasscBs,eZd�Zd�Zd�Zd�ZRS(cCst|ttf�S(N(t
isinstancetLSeriesAbstracttLSeriesProduct(R)tx((spsage/eulerprod.pyt__contains__scCsbt|t�r|St|t�r&|S|dkr6|Syt|�SWntk
r]t�nXdS(s�
        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: L = LSeries('zeta')
            sage: P = L.parent(); P
            All L-series objects and their products
            sage: P(L) is L
            True

            sage: P(L^3)
            (Riemann Zeta function viewed as an L-series)^3
            sage: (L^3).parent()
            All L-series objects and their products

        You can make the L-series attached to an object by coercing
        that object into the parent::

            sage: P(EllipticCurve('11a'))
            L-series of Elliptic Curve defined by y^2 + y = x^3 - x^2 - 10*x - 20 over Rational Field

        We also allow coercing in 1, because this is very useful for
        formal factorizations and products::

            sage: P(1)
            1

        Other numbers do not coerce in, of course::

            sage: P(2)
            Traceback (most recent call last):
            ...
            TypeError
        iN(R<R=R>tLSeriestNotImplementedErrort	TypeError(R)R?((spsage/eulerprod.pyR2s#
cCsdS(s�
        Return string representation of this parent object.

            sage: from psage.lseries.eulerprod import LSeriesParent
            sage: LSeriesParent.__repr__()
            'All L-series objects and their products'
        s'All L-series objects and their products((R)((spsage/eulerprod.pyR74scCs,t|t�rdStt|�t|��S(s�
        Returns equality if right is an instance of
        LSeriesParentClass; otherwise compare memory locations.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeriesParent, LSeriesParentClass
            sage: cmp(LSeriesParent, LSeriesParentClass())
            0
            sage: cmp(LSeriesParent, 7) != 0
            True
            sage: cmp(7, LSeriesParent) == -cmp(LSeriesParent, 7)
            True
        i(R<R;R-tid(R)R.((spsage/eulerprod.pyR/>s(R8R9R@R2R7R/(((spsage/eulerprod.pyR;s		/	
R=cBs�eZdZedd�Zded�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd-d�Zd�Zd-d�Zd�Zed��Zd-d-dd�Zed-d��Zd-d�Zd�Zd�Zd�Zd�Zd�Zd-d�Zd�Z dd-d�Z!d�Z"d d!�Z#d-d"d#dd$�Z$d%dd&�Z%edd'd(��Z&d)�Z'dd'd*�Z(d'd+�Z)dd,�Z*RS(.s
    L-series defined by an Euler product.

    The parameters that define the 'shape' of the L-series are:

             conductor, hodge_numbers, weight, epsilon, poles, base_field

    Let gamma(s) = prod( Gamma((s+h)/2) for h in hodge_numbers ).
    Denote this L-series by L(s), and let `L^*(s) = A^s \gamma(s) L(s)`, where
    `A = \sqrt(N)/\pi^{d/2}`, where d = len(hodge_numbers) and N = conductor.
    Then the functional equation is

                  Lstar(s) = epsilon * Lstar(weight - s).

    To actually use this class we create a derived class that in
    addition implements a method _local_factor(P), that takes as input
    a prime ideal P of K=base_field, and returns a polynomial, which
    is typically the reversed characteristic polynomial of Frobenius
    at P of Gal(Kbar/K) acting on the maximal unramified quotient of
    some Galois representation.  This class automatically computes the
    Dirichlet series coefficients `a_n` from the local factors of the
    `L`-function.

    The derived class may optionally -- and purely as an optimization
    -- define a method self._precompute_local_factors(bound,
    prec=None), which is typically called before

        [_local_factor(P) for P with norm(P) < bound]

    is called in the course of various computations.
    i5c

	s�igd6|_||||||||f\|_|_|_|_|_|_|_|_	g�t
|t�r��jd�nt
|�dkr�t
|dt�r��jd�nt
|t�r��jd�nt
|�dkrt
|dt�r�jd�nt
|t�r+�jd�nt
��dkr�t}
x�tg�D]}t||�^qP�D]V�t��fd�tt
���D��}|jd|	d	t|�rlt}
PqlqlW|
s�td
dj���q�ndS(
sK
        INPUT:
            - ``conductor`` -- list or number (in a subset of the
              positive real numbers); if the conductor is a list, then
              each conductor is tried in order (to the precision prec
              below) until we find one that works.
            - ``hodge_numbers`` -- list of numbers (in a subring of the complex numbers)
            - ``weight`` -- number (in a subset of the positive real numbers)
            - ``epsilon`` -- number (in a subring of the complex numbers)
            - ``poles`` -- list of numbers (in subring of complex numbers); poles of the *completed* L-function
            - ``residues`` -- list of residues at each pole given in poles or string "automatic"
            - ``base_field`` -- QQ or a number field; local L-factors
              correspond to nonzero prime ideals of this field.
            - ``is_selfdual`` -- bool (default: True)
            - ``prec`` -- integer (default: 53); precision to use when trying to figure
              out parameters using the functional equation


        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeriesAbstract
            sage: L = LSeriesAbstract(conductor=1, hodge_numbers=[0], weight=1, epsilon=1, poles=[1], residues=[-1], base_field=QQ)
            sage: type(L)
            <class 'psage.lseries.eulerprod.LSeriesAbstract'>
            sage: L._conductor
            1
            sage: L._hodge_numbers
            [0]
            sage: L._weight
            1
            sage: L._epsilon
            1
            sage: L._poles
            [1]
            sage: L._residues
            [-1]
            sage: L._base_field
            Rational Field
            sage: L
            Euler Product L-series with conductor 1, Hodge numbers [0], weight 1, epsilon 1, poles [1], residues [-1] over Rational Field
        t
_conductorit_hodge_numberst_weightt_polest_epsilonc3s#|]}�|�|fVqdS(N((t.0ti(tXtv(spsage/eulerprod.pys	<genexpr>�sRtsaves no choice of values for %s workss, N(tNonet_anlistRERFRGRIRHt	_residuest_base_fieldt_is_selfdualR<tlisttappendtlentFalseRtgetattrtdicttranget_is_valid_parameterstTruetRuntimeErrortjoin(
R)t	conductort
hodge_numberstweighttepsilontpolestresiduest
base_fieldtis_selfdualRtfound_paramstattrtkwds((RLRMspsage/eulerprod.pyR,ts.3<%%/+cKs�t}z�g|j�D]}|t||�f^q}x*|j�D]\}}t|||�qDW|jj�|jd|�y|jd|�t}Wntk
r�nXWd|r�x$|D]\}}t|||�q�Wn|SX(NR(	RWtkeysRXt	iteritemstsetattrR0tclear_cacheR\R](R)RRNRitvalidR+toldRM((spsage/eulerprod.pyR[�s .


cCs�||krdSxNdddddgD]7}tt||��t||���}|r&|Sq&Wtt|�t|��}|j|�S(NitdegreeRaR_RbRe(R-RXttypet_cmp(R)R.Rtc((spsage/eulerprod.pyR/�s'cCs
t�dS(N(RC(R)R.((spsage/eulerprod.pyRr�scCstS(sa
        Return parent of this L-series, which is the collection of all
        L-series and their products.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: L = LSeries('delta');  P = L.parent(); P
            All L-series objects and their products
            sage: L in P
            True
        (t
LSeriesParent(R)((spsage/eulerprod.pytparent�s
cCst|t|�fg�S(s�
        Return the n-th power of this L-series, where n can be any integer.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: L = LSeries('delta');
            sage: L3 = L^3; L3
            (L-function associated to Ramanujan's Delta (a weight 12 cusp form))^3
            sage: L3(1)
            0.0000524870430366548
            sage: L(1)^3
            0.0000524870430366548
            sage: M = L^(-3); M(1)
            19052.3211471761
            sage: L(1)^(-3)
            19052.3211471761

        Higher precision::

            sage: M = L^(-3); M(RealField(100)(1))
            19052.321147176093380952680193
            sage: L(RealField(100)(1))^(-3)
            19052.321147176093380952680193

        Special case -- 0th power -- is not allowed::

            sage: L^0
            Traceback (most recent call last):
            ...
            ValueError: product must be nonempty

        (R>R(R)tn((spsage/eulerprod.pyt__pow__�s"cCsLt|t�r+t|df|dfg�St|t�rB||St�dS(s$
        Multiply two L-series, or an L-series times a formal product of L-series.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: d = LSeries('delta'); z = LSeries('zeta')
            sage: d * z
            (Riemann Zeta function viewed as an L-series) * (L-function associated to Ramanujan's Delta (a weight 12 cusp form))
            sage: d * (d * z)
            (Riemann Zeta function viewed as an L-series) * (L-function associated to Ramanujan's Delta (a weight 12 cusp form))^2
        iN(R<R=R>RC(R)R.((spsage/eulerprod.pyt__mul__"s

cCsdt|t�r+t|df|dfg�St|t�rZtt|dfg�|j�St�dS(s

        Divide two L-series or formal L-series products.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: d = LSeries('delta'); z = LSeries('zeta')
            sage: d / z
            (Riemann Zeta function viewed as an L-series)^-1 * (L-function associated to Ramanujan's Delta (a weight 12 cusp form))
            sage: d / (z^3)
            (Riemann Zeta function viewed as an L-series)^-3 * (L-function associated to Ramanujan's Delta (a weight 12 cusp form))
        ii����N(R<R=R>Rt_factorizationRC(R)R.((spsage/eulerprod.pyt__div__5s

 cCs|jS(s
        Return the conductor of this L-series.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: LSeries('zeta').conductor()
            1
            sage: LSeries('delta').conductor()
            1
            sage: LSeries(EllipticCurve('11a')).conductor()
            11
            sage: LSeries(Newforms(33)[0]).conductor()
            33
            sage: LSeries(DirichletGroup(37).0).conductor()
            37
            sage: LSeries(kronecker_character(7)).conductor()
            28
            sage: kronecker_character(7).conductor()
            28
            sage: L = LSeries(EllipticCurve('11a3').base_extend(QQ[sqrt(2)]), prec=5)
            sage: L.conductor().factor()
            2^6 * 11^2
        (RE(R)((spsage/eulerprod.pyR_HscCs
t|j�S(s�
        Return the Hodge numbers of this L-series.  These define the local Gamma factors.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: LSeries('zeta').hodge_numbers()
            [0]
            sage: LSeries('delta').hodge_numbers()
            [0, 1]
            sage: LSeries(EllipticCurve('11a')).hodge_numbers()
            [0, 1]
            sage: LSeries(Newforms(43,names='a')[1]).hodge_numbers()
            [0, 1]
            sage: LSeries(DirichletGroup(37).0).hodge_numbers()
            [1]
            sage: LSeries(EllipticCurve(QQ[sqrt(-1)],[1,2]), prec=5).hodge_numbers() # long time
            [0, 0, 1, 1]
        (RTRF(R)((spsage/eulerprod.pyR`cscCs|jS(s�
        Return the weight of this L-series.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: LSeries('zeta').weight()
            1
            sage: LSeries('delta').weight()
            12
            sage: LSeries(EllipticCurve('389a')).weight()
            2
            sage: LSeries(Newforms(43,names='a')[1]).weight()
            2
            sage: LSeries(Newforms(6,4)[0]).weight()
            4
            sage: LSeries(DirichletGroup(37).0).weight()
            1
            sage: L = LSeries(EllipticCurve('11a3').base_extend(QQ[sqrt(2)]),prec=5); L.weight()
            2
        (RG(R)((spsage/eulerprod.pyRayscCs
t|j�S(s�
        Poles of the *completed* L-function with the extra Gamma
        factors included.

        WARNING: These are not just the poles of self.

        OUTPUT:
             - list of numbers

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: LSeries('zeta').poles()
            [0, 1]
            sage: LSeries('delta').poles()
            []
        (RTRH(R)((spsage/eulerprod.pyRc�scCsw|jdkrf|dkr"|jSt|�}g|jd|�j�d�D]}||�^qMSn
t|j�SdS(sU
        Residues of the *completed* L-function at each pole.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: LSeries('zeta').residues()
            [9, 8]
            sage: LSeries('delta').residues()
            []
            sage: v = LSeries('zeta').residues()
            sage: v.append(10)
            sage: LSeries('zeta').residues()
            [9, 8]

        The residues of the Dedekind Zeta function of a field are dynamically computed::

            sage: K.<a> = NumberField(x^2 + 1)
            sage: L = LSeries(K); L
            Dedekind Zeta function of Number Field in a with defining polynomial x^2 + 1

        If you just call residues you get back that they are automatically computed::

            sage: L.residues()
            'automatic'

        But if you call with a specific precision, they are computed using that precision::

            sage: L.residues(prec=53)
            [-0.886226925452758]
            sage: L.residues(prec=200)
            [-0.88622692545275801364908374167057259139877472806119356410690]
        t	automaticRt	LresiduesN(RQROR
R0tgpRT(R)RtCR((spsage/eulerprod.pyRd�s"8cCs|jS(sN
        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: LSeries('zeta').base_field()
            Rational Field
            sage: L = LSeries(EllipticCurve('11a3').base_extend(QQ[sqrt(2)]), prec=5); L.base_field()
            Number Field in sqrt2 with defining polynomial x^2 - 2
        (RR(R)((spsage/eulerprod.pyRe�s
cCs�|jdksBt|jd�rF|dksB|jj�|krFdS|dk	r�t|�}t|jt�r�g|jD]}||�^qzS||j�S|jS(so
        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: LSeries('zeta').epsilon()
            1
            sage: LSeries('delta').epsilon()
            1
            sage: LSeries(EllipticCurve('389a')).epsilon()
            1
            sage: LSeries(EllipticCurve('37a')).epsilon()
            -1
            sage: LSeries(Newforms(389,names='a')[1]).epsilon()
            -1
            sage: LSeries(Newforms(6,4)[0]).epsilon()
            1
            sage: LSeries(DirichletGroup(7).0).epsilon()
            1/7*I*((((((e^(2/21*I*pi) + 1)*e^(2/21*I*pi) + 1)*e^(1/21*I*pi) - 1)*e^(1/21*I*pi) - 1)*e^(2/21*I*pi) - 1)*e^(1/21*I*pi) - 1)*sqrt(7)*e^(1/21*I*pi)
            sage: LSeries(DirichletGroup(7).0).epsilon(prec=53)
            0.386513572759156 + 0.922283718859307*I

        In this example, the epsilon factor is computed when the curve
        is created. The prec parameter determines the floating point precision
        used in computing the epsilon factor::

            sage: L = LSeries(EllipticCurve('11a3').base_extend(QQ[sqrt(2)]), prec=5); L.epsilon()
            -1

        Here is extra confirmation that the rank is really odd over the quadratic field::

            sage: EllipticCurve('11a').quadratic_twist(2).rank()
            1

        We can compute with the L-series too::

            sage: L(RealField(5)(2))
            0.53

        For L-functions of newforms with nontrivial character, the
        epsilon factor is harder to find (we don't have a good
        algorithm implemented to find it) and might not even be 1 or
        -1, so it is set to 'solve'.  In this case, the functional
        equation is used to determine the solution.::

            sage: f = Newforms(kronecker_character_upside_down(7),3)[0]; f
            q - 3*q^2 + 5*q^4 + O(q^6)
            sage: L = LSeries(f)
            sage: L.epsilon()
            'solve'
            sage: L(3/2)
            0.332981771482934
            sage: L.epsilon()
            1

        Here is an example with nontrivial character::

            sage: f = Newforms(DirichletGroup(7).0, 5, names='a')[0]; f
            q + a0*q^2 + ((zeta6 - 2)*a0 - zeta6 - 1)*q^3 + (-4*zeta6*a0 + 2*zeta6 - 2)*q^4 + ((4*zeta6 - 2)*a0 + 9*zeta6 - 18)*q^5 + O(q^6)
            sage: L = LSeries(f)

        First trying to evaluate with the default (53 bits) of
        precision fails, since for some reason (that I do not
        understand) the program is unable to find a valid epsilon
        factor::

            sage: L(0)
            Traceback (most recent call last):
            ...
            RuntimeError: unable to determine epsilon from functional equation working to precision 53, since we get epsilon=0.806362085925390 - 0.00491051026156292*I, which is not sufficiently close to 1

        However, when we evaluate to 100 bits of precision it works::

            sage: L(RealField(100)(0))
            0

        The epsilon factor is *not* known to infinite precision::

            sage: L.epsilon()
            'solve'

        But it is now known to 100 bits of precision, and here it is::

            sage: L.epsilon(100)
            0.42563106101692403875896879406 - 0.90489678963824790765479396740*I

        When we try to compute to higher precision, again Sage solves for the epsilon factor
        numerically::

            sage: L(RealField(150)(1))
            0.26128389551787271923496480408992971337929665 - 0.29870133769674001421149135036267324347896657*I

        And now it is known to 150 bits of precision.  Notice that
        this is consistent with the value found above, and has
        absolute value (very close to) 1.

            sage: L.epsilon(150)
            0.42563106101692403875896879406038776338921622 - 0.90489678963824790765479396740501409301704122*I
            sage: abs(L.epsilon(150))
            1.0000000000000000000000000000000000000000000
        tsolveRN(RIRRORR
R<RT(R)RR~R?((spsage/eulerprod.pyRb�se3 
cCs|jS(sA
        Return True if this L-series is self dual; otherwise, return False.

        EXAMPLES::

        Many L-series are self dual::

            sage: from psage.lseries.eulerprod import LSeries
            sage: LSeries('zeta').is_selfdual()
            True
            sage: LSeries('delta').is_selfdual()
            True
            sage: LSeries(Newforms(6,4)[0]).is_selfdual()
            True

        Nonquadratic characters have non-self dual L-series::

            sage: LSeries(DirichletGroup(7).0).is_selfdual()
            False
            sage: LSeries(kronecker_character(7)).is_selfdual()
            True

        Newforms with non-quadratic characters also have non-self dual L-seris::

            sage: L = LSeries(Newforms(DirichletGroup(7).0, 5, names='a')[0]); L.is_selfdual()
            False
        (RS(R)((spsage/eulerprod.pyRfKscCsHt|j��}|j�j�}||dks@td��||S(s�
        Return the degree of this L-function, which is by definition the number of Gamma
        factors (e.g., the number of Hodge numbers) divided by the degree of the base field.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: LSeries('zeta').degree()
            1
            sage: LSeries(DirichletGroup(5).0).degree()
            1
            sage: LSeries(EllipticCurve('11a')).degree()
            2

        The L-series attached to this modular symbols space of dimension 2 is a product
        of 2 degree 2 L-series, hence has degree 4::

            sage: M = ModularSymbols(43,2,sign=1).cuspidal_subspace()[1]; M.dimension()
            2
            sage: L = LSeries(M); L
            L-series attached to Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 4 for Gamma_0(43) of weight 2 with sign 1 over Rational Field
            sage: L.factor()
            (L-series of a degree 2 newform of level 43 and weight 2) * (L-series of a degree 2 newform of level 43 and weight 2)
            sage: L.degree()
            4

            sage: x = var('x'); K.<a> = NumberField(x^2-x-1); LSeries(EllipticCurve([0,-a,a,0,0])).degree()
            2
        is<degree of base field must divide the number of Hodge numbers(RVR`ReRptAssertionError(R)Rvtd((spsage/eulerprod.pyRpisc
Cs"t|d|d|d|d|�S(sS
        Return the quadratic twist of this L-series by the character chi, which
        must be a character of self.base_field().   Thus chi should take as input
        prime ideals (or primes) of the ring of integers of the base field, and
        output something that can be coerced to the complex numbers.

        INPUT:
            - `\chi` -- 1-dimensional character

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: E = EllipticCurve('11a')
            sage: L = LSeries(E); L
            L-series of Elliptic Curve defined by y^2 + y = x^3 - x^2 - 10*x - 20 over Rational Field
            sage: L3 = L.twist(DirichletGroup(3).0); L3
            Twist of L-series of Elliptic Curve defined by y^2 + y = x^3 - x^2 - 10*x - 20 over Rational Field by Dirichlet character modulo 3 of conductor 3 mapping 2 |--> -1
            sage: L3._chi
            Dirichlet character modulo 3 of conductor 3 mapping 2 |--> -1
            sage: L3._L
            L-series of Elliptic Curve defined by y^2 + y = x^3 - x^2 - 10*x - 20 over Rational Field
            sage: L3(1)
            1.68449633297548
            sage: F = E.quadratic_twist(-3)
            sage: L3.conductor()
            99
            sage: F.conductor()
            99
            sage: F.lseries()(1)
            1.68449633297548
            sage: L3.anlist(20)
            [0, 1, 2, 0, 2, -1, 0, -2, 0, 0, -2, -1, 0, 4, -4, 0, -4, 2, 0, 0, -2]
            sage: F.anlist(20)
            [0, 1, 2, 0, 2, -1, 0, -2, 0, 0, -2, -1, 0, 4, -4, 0, -4, 2, 0, 0, -2]
            sage: L3.anlist(1000) == F.anlist(1000)
            True
            sage: L3.local_factor(11)
            T + 1

        A higher degree twist::

            sage: L = LSeries(EllipticCurve('11a'))
            sage: L5 = L.twist(DirichletGroup(5).0); L5
            Twist of L-series of Elliptic Curve defined by y^2 + y = x^3 - x^2 - 10*x - 20 over Rational Field by Dirichlet character modulo 5 of conductor 5 mapping 2 |--> zeta4
            sage: L5(1)
            1.28009593569230 - 0.681843202124309*I
            sage: L5.epsilon()
            'solve'
            sage: L5.epsilon(53)
            0.989989082587826 + 0.141143956147310*I
            sage: L5.conductor()
            275
            sage: L5.taylor_series(center=1, degree=3)
            1.28009593569230 - 0.681843202124309*I + (-0.536450338806282 + 0.166075270978779*I)*z + (0.123743053129226 + 0.320802890011298*I)*z^2 + O(z^3)


        WARNING!! Twisting is not implemented in full generality when
        the conductors are not coprime.  One case where we run into
        trouble is when twisting lowers the level of a newform.  Below
        we take the form of level 11 and weight 2, twist it by the
        character chi of conductor 3 to get a form of level 99.  Then
        we take the L-series of the level 99 form, and twist that by
        chi, which should be the L-series attached to the form of
        level 11.  Unfortunately, our code for working out the local
        L-factors doesn't succeed in this case, hence the local factor
        is wrong, so the functional equation is not satisfied.

            sage: f = Newform('11a'); f
            q - 2*q^2 - q^3 + 2*q^4 + q^5 + O(q^6)
            sage: L = LSeries(f)
            sage: chi = DirichletGroup(3).0
            sage: Lc = L.twist(chi); Lc
            Twist of L-series of a degree 1 newform of level 11 and weight 2 by Dirichlet character modulo 3 of conductor 3 mapping 2 |--> -1
            sage: Lc.anlist(20)
            [0, 1, 2, 0, 2, -1, 0, -2, 0, 0, -2, -1, 0, 4, -4, 0, -4, 2, 0, 0, -2]
            sage: g = Newform('99d'); g
            q + 2*q^2 + 2*q^4 - q^5 + O(q^6)
            sage: list(g.qexp(20))
            [0, 1, 2, 0, 2, -1, 0, -2, 0, 0, -2, -1, 0, 4, -4, 0, -4, 2]
            sage: Lt = Lc.twist(chi, conductor=11)
            Traceback (most recent call last):
            ...
            RuntimeError: no choice of values for _epsilon works
            sage: Lt = Lc.twist(chi,conductor=11, epsilon=1)
            sage: Lt(1)
            Traceback (most recent call last):
            ...
            RuntimeError: invalid L-series parameters: functional equation not satisfied

        This is because the local factor is wrong::

            sage: Lt.local_factor(3)
            1
            sage: L.local_factor(3)
            3*T^2 + T + 1


        tchiR_RbR(tLSeriesTwist(R)R�R_RbR((spsage/eulerprod.pyttwist�sccCs|j|d|�S(s&
        Return the local factor of the L-function at the prime P of
        self._base_field.  The result is cached.

        INPUT:
            - a prime P of the ring of integers of the base_field
            - prec -- None or positive integer (bits of precision)

        OUTPUT:
            - a polynomial, e.g., something like "1-a*T+p*T^2".

        EXAMPLES:

        You must overload this in the derived class::

            sage: from psage.lseries.eulerprod import LSeriesAbstract
            sage: L = LSeriesAbstract(conductor=1, hodge_numbers=[0], weight=1, epsilon=1, poles=[1], residues=[-1], base_field=QQ)
            sage: L.local_factor(2)
            Traceback (most recent call last):
            ...
            NotImplementedError: must be implemented in the derived class
        R(t
_local_factor(R)R#R((spsage/eulerprod.pytlocal_factor�scCs
td�dS(s�
        Compute local factor at prime P.  This must be overwritten in the derived class.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeriesAbstract
            sage: L = LSeriesAbstract(conductor=1, hodge_numbers=[0], weight=1, epsilon=1, poles=[1], residues=[-1], base_field=QQ)
            sage: L.local_factor(2)
            Traceback (most recent call last):
            ...
            NotImplementedError: must be implemented in the derived class
        s(must be implemented in the derived classN(RB(R)R#R((spsage/eulerprod.pyR�s
cCs5d|j|j|j|j�|j|j|jfS(s�
        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeriesAbstract
            sage: L = LSeriesAbstract(conductor=1, hodge_numbers=[0], weight=1, epsilon=1, poles=[1], residues=[-1], base_field=QQ)
            sage: L.__repr__()
            'Euler Product L-series with conductor 1, Hodge numbers [0], weight 1, epsilon 1, poles [1], residues [-1] over Rational Field'
        spEuler Product L-series with conductor %s, Hodge numbers %s, weight %s, epsilon %s, poles %s, residues %s over %s(RERFRGRbRHRQRR(R)((spsage/eulerprod.pyR7s	cCsdS(sc
        Derived classes may use this as a 'hint' that _local_factors
        will soon get called for primes of norm less than the bound.

        In the base class, this is a no-op, and it is not necessary to
        overload this class.

        INPUT:
            - ``bound`` -- integer
            - ``prec`` -- integer

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeriesAbstract
            sage: L = LSeriesAbstract(conductor=1, hodge_numbers=[0], weight=1, epsilon=1, poles=[1], residues=[-1], base_field=QQ)
            sage: L._precompute_local_factors(100, 53)
        N((R)tboundR((spsage/eulerprod.pyt_precompute_local_factors'scCs-|j}t|�r|gS|j|�SdS(s
        Return the primes of the ring of integers of the base field above the integer p.

        INPUT:
            - p -- prime integer (no type checking necessarily done)

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeriesAbstract
            sage: L = LSeriesAbstract(conductor=1, hodge_numbers=[0], weight=1, epsilon=1, poles=[1], residues=[-1], base_field=QQ)
            sage: L._primes_above(3)
            [3]
            sage: L = LSeriesAbstract(conductor=1, hodge_numbers=[0], weight=1, epsilon=1, poles=[1], residues=[-1], base_field=QQ[sqrt(-1)])
            sage: L._primes_above(5)
            [Fractional ideal (I + 2), Fractional ideal (-I + 2)]
            sage: L._primes_above(3)
            [Fractional ideal (3)]
        N(RRRtprimes_above(R)tptK((spsage/eulerprod.pyt
_primes_above;s	cCs|j�j|�S(s
        Return the imaginary parts of the first n nontrivial zeros of
        this L-function on the critical line in the upper half plane,
        as 32-bit real numbers.

        INPUT:
             - n -- nonnegative integer

        EXAMPLES::

        (t_lcalctzeros(R)Rv((spsage/eulerprod.pyR�TscCs
t�dS(s
        Return Rubinstein Lcalc object attached to this L-series. This
        is useful both for evaluating the L-series, especially when
        the imaginary part is large, and for computing the zeros in
        the critical strip.

        EXAMPLES::
        N(RB(R)((spsage/eulerprod.pyR�bs
cCs	t|jd�|krk|dkr8|jd|d St|�}g|jdD]}||�^qRSn|dk	r
g|jj�D]2}|d|kr�t|d�|kr�|^q�}t|�dkr
t|�}g|dd|d D]}||�^q�Sn|j|dd|�t}g}x�t|d�D]�}	g}
xc|j|	�D]R}t	|�|kr]|j
||�}t|t�r�t
}n|
j|�q]q]W|j|	|
f�qAW|j|||�}
|st|
�d}
|
|j|<n|
S(s�
        Return list `v` of Dirichlet series coefficients `a_n`for `n` up to and including bound,
        where `v[n] = a_n`.  If at least one of the coefficients is ambiguous, e.g., the
        local_factor method returns a list of possibilities, then this function instead
        returns a generator over all possible `a_n` lists.

        In particular, we include v[0]=0 as a convenient place holder
        to avoid having `v[n-1] = a_n`.

        INPUT:
            - ``bound`` -- nonnegative integer

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries; L = LSeries('zeta')
            sage: L.anlist(30)
            [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
            sage: from psage.lseries.eulerprod import LSeries; L = LSeries(EllipticCurve('11a'))
            sage: L.anlist(30)
            [0, 1, -2, -1, 2, 1, 2, -2, 0, -2, -2, 1, -2, 4, 4, -1, -4, -2, 4, 0, 2, 2, -2, -1, 0, -4, -8, 5, -4, 0, 2]
            sage: K.<a> = NumberField(x^2-x-1); L = LSeries(EllipticCurve([0,-a,a,0,0]))
            sage: L.anlist(30)
            [0, 1, 0, 0, -2, -1, 0, 0, 0, -4, 0, 3, 0, 0, 0, 0, 0, 0, 0, 5, 2, 0, 0, 0, 0, -4, 0, 0, 0, 11, 0]
        iiRN(RVRPROR
RkR�RWRR�RR�R<RTR\RUt_compute_anlist(R)R�RR~Rtztttcompute_anlist_multipletLFR�tlfR#tFtcoefficients((spsage/eulerprod.pytanlistns6'H0	ccs�|j}ddgdg|d}xht|�D]Z\}\}}t|�dkr1t}	x�t|�D]�\}
}t|t�rht}	x]t|�D]L}tj|�}
||
|d|
<x"|j	|
||�D]}|Vq�Wq�WqhqhW|	r�dSt
|�}ttj
tj|�tj|���d}|j�j�}|t||�d}x,td|�D]}
||
|||
<qlWq1q1Wt|�t|�VdS(s&
        Iterator over possible anlists, given LF, bound, and prec.

        INPUT:
            - ``LF`` -- list of pairs (p, [local factors (or lists of them) at primes over p])
            - ``bound`` -- positive integer
            - ``prec`` -- positive integer (bits of precision)
        iiNi����(RRt	enumerateRVRWR<RTR\tcopytdeepcopyR�RtinttmathtfloortlogRutgenR	RZR(R)R�R�RR�R�RKR�RMt	some_listtjR�tftLF0R�t
accuracy_ptTtseries_p((spsage/eulerprod.pyR��s.		/
i
csK|jd��|j||��t��fd�td|d�D��S(s:
        Convert self into the symbolic ring as a truncated Dirichleter series, including
        terms up to `n^s` where n=bound.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: L = LSeries(EllipticCurve('37a'))
            sage: SR(L)
            -2/2^s - 3/3^s + 2/4^s - 2/5^s + 6/6^s - 1/7^s + 6/9^s + 4/10^s + 1
            sage: L._symbolic_(SR, 20)
            -2/2^s - 3/3^s + 2/4^s - 2/5^s + 6/6^s - 1/7^s + 6/9^s + 4/10^s - 5/11^s - 6/12^s - 2/13^s + 2/14^s + 6/15^s - 4/16^s - 12/18^s - 4/20^s + 1
        Rc3s!|]}�||�VqdS(N((RJRv(RR(spsage/eulerprod.pys	<genexpr>�si(tvarR�tsumRZ(R)tRR�R((RRspsage/eulerprod.pyt
_symbolic_�scCs8||jkrtd|�n|jt|��|�S(s�
        Return value of this L-function at s.  If s is a real or
        complex number to prec bits of precision, then the result is
        also computed to prec bits of precision.  If s has infinite or
        unknown precision, then the L-value is computed to 53 bits of
        precision.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: L = LSeries(EllipticCurve('37a'))
            sage: L(1)
            0
            sage: L(2)
            0.381575408260711
            sage: z = L(RealField(100)(2)); z
            0.38157540826071121129371040958
            sage: z.prec()
            100
            sage: L(RealField(150)(2))
            0.38157540826071121129371040958008663667709753

        WARNING: There will be precision loss (with a warning) if the imaginary
        part of the input is large::

            sage: L = LSeries('zeta')
            sage: L(1/2 + 40*I)
            verbose -1 (...: dokchitser.py, __call__) Warning: Loss of 14 decimal digits due to cancellation
            0.793046013671137 - 1.04127377821427*I
            sage: L(ComplexField(200)(1/2 + 40*I))
            verbose -1 (...: dokchitser.py, __call__) Warning: Loss of 14 decimal digits due to cancellation
            0.79304495256192867196489258889793696080572220439302833315881 - 1.0412746146510650200518905953910554313275550685861559488384*I

        An example with a pole::

            sage: L = LSeries('zeta')
            sage: L(2)  # good
            1.64493406684823
            sage: L(1)  # a pole!
            Traceback (most recent call last):
            ...
            ZeroDivisionError: pole at 1
        s
pole at %s(RHtZeroDivisionErrorR0R(R)R((spsage/eulerprod.pyR2�s,icCs|dkr|St||�S(s
        Return the k-th derivative of self.

        INPUT:
            - k -- (default: 1) nonnegative integer

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: L = LSeries('zeta')
            sage: L.derivative()
            First derivative of Riemann Zeta function viewed as an L-series

        We numerically approximate the derivative at two points and compare
        with evaluating the derivative object::

            sage: eps=1e-10;  (L(2+eps) - L(2))/eps
            -0.937547817159157
            sage: Lp = L.derivative(); Lp(2)
            -0.937548254315844
            sage: eps=1e-10;  (L(2+I+eps) - L(2+I))/eps
            0.0624900131640516 + 0.489033813444451*I
            sage: Lp(2+I)
            0.0624900021906470 + 0.489033591679899*I

        Higher derivatives::

            sage: L.derivative(2)
            Second derivative of Riemann Zeta function viewed as an L-series
            sage: L.derivative(2)(2)
            1.98928023429890
            sage: L.derivative(3)
            Third derivative of Riemann Zeta function viewed as an L-series
            sage: L.derivative(4)
            4-th derivative of Riemann Zeta function viewed as an L-series
            sage: L.derivative(5)
            5-th derivative of Riemann Zeta function viewed as an L-series

        Derivative of derivative::

            sage: L.derivative().derivative()
            Second derivative of Riemann Zeta function viewed as an L-series

        Using the derivative function in Sage works::

            sage: derivative(L)
            First derivative of Riemann Zeta function viewed as an L-series
            sage: derivative(L,2)
            Second derivative of Riemann Zeta function viewed as an L-series
        i(R%(R)R+((spsage/eulerprod.pyR1s3iR�cCsD|dkr(t|�|j�d}n|j|�j|||�S(sc
        Return the Taylor series expansion of self about the given
        center point to the given degree in the specified variable
        numerically computed to the precision prec in bits.  If the
        center is not specified it defaults to weight / 2.

        INPUT:
            - ``center`` -- None or number that coerces to the complex numbers
            - ``degree`` -- integer
            - ``variable`` -- string or symbolic variable
            - ``prec`` -- positive integer (floating point bits of precision)

        EXAMPLES:::

            sage: from psage.lseries.eulerprod import LSeries; L = LSeries('zeta')
            sage: L.taylor_series()
            -1.46035450880959 - 3.92264613920915*z - 8.00417850696433*z^2 - 16.0005515408865*z^3 - 31.9998883216853*z^4 - 64.0000050055172*z^5 + O(z^6)
            sage: RealField(53)(zeta(1/2))
            -1.46035450880959
            sage: L.taylor_series(center=2, degree=4, variable='t', prec=30)
            1.6449341 - 0.93754825*t + 0.99464012*t^2 - 1.0000243*t^3 + O(t^4)
            sage: RealField(30)(zeta(2))
            1.6449341

        iN(ROR
RGR0t
taylor_series(R)tcenterRptvariableR((spsage/eulerprod.pyR�Msg:�0�yE>cCs�t|�|j�d}d}xitr�|j||d|�}d}x4||kr|t||�|kro|S|d7}qIW|d7}q"WdS(NiiRii(R
RGR\R�tabs(R)R!RR�RpR�RK((spsage/eulerprod.pyt
analytic_rankks	g333333�?cCs%|j|�}|j||d|�S(s5
        Return Dokchitser object that allows for computation of this
        L-series computed to enough terms so that the functional
        equation checks out with the given value of T and precision.

        This is used behind the scenes for evaluation and computation
        of Taylor series.
        R�(Rbt_dokchitser(R)RR�teps((spsage/eulerprod.pyR0ws
cCsj|dkrd}n|}td|j�d|j�d|j�d|d|j�d|j�d	|�S(
NRRLR_tgammaVRaR�RcRdR(RR_R`RaRcRd(R)RRbR�((spsage/eulerprod.pyt_dokchitser_unitialized�s	*cCs"|j||j|��j|�S(su
        Return the number of Dirichlet series coefficients that will
        be needed in order to evaluate this L-series (near the real
        line) to prec bits of precision and have the functional
        equation test pass with the given value of T.

        INPUT:
            - prec -- integer

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: L = LSeries(DirichletGroup(5).0)
            sage: L.number_of_coefficients(20)
            8
            sage: L.number_of_coefficients()
            11
            sage: L.number_of_coefficients(1000)
            43
        (R�Rbt
num_coeffs(R)RR�((spsage/eulerprod.pytnumber_of_coefficients�sc
Cs�|j||�}|jd|�}|j||�}t|tj�rQ|}n	|g}t|�}xq|D]i}	ddjg|	dD]6}
t|
tt	t
f�r�t|
�n	|
j�^q��}|j
�r�|jdd|�n#t|_|j|�|jd�|dkr�d	}t|�|j|��}tt|�d�|krktd
||f�n|dkr�d|_q�|dkr�d|_q�||_n|j�}
t|
�|krm|	|j|<|SqmWtd�dS(
NR�sv=[%s]; a(k)=v[k];t,isa(k)tpari_precodes initLdata("a(k)",1,"conj(a(k))")Rs6sgneq = Vec(checkfeq()); sgn = -sgneq[2]/sgneq[1]; sgns�unable to determine epsilon from functional equation working to precision %s, since we get epsilon=%s, which is not sufficiently close to 1i����s>invalid L-series parameters: functional equation not satisfied(R�R�R�R<ttypest
GeneratorTypeR!R^R�tlongRtstrt_pari_init_Rftinit_coeffsR\t_Dokchitser__initt_gp_evalR
R�R]RItcheck_functional_equationRP(R)RRbR�tLRvRLtcoeff_liststtiny0tcoeffsR�Rtcmdtfe((spsage/eulerprod.pyR��s<		
T	


cCs|jd|�j|�S(NR(R0R�(R)R�R((spsage/eulerprod.pyR��sN(+R8R9R:R\R,R[R/RrRuRwRxRzR_R`RaRcRORdReRbRfRRpR�R�R�R7R�R�R�R�R�R�R�R2R1R�R�R0R�R�R�R�(((spsage/eulerprod.pyR=TsR	S					$						+	o	$e					>	(	07	
<tLSeriesProductEvaluatorcBseZd�Zd�ZRS(cCs||_||_dS(N(Ryt_prec(R)t
factorizationR((spsage/eulerprod.pyR,�s	cs{y
|j}WnQtk
r`g|jD]$\}}|j|j�|f^q'|_|j}nXt�fd�|D��S(Nc3s%|]\}}|��|VqdS(N((RJR�te(R(spsage/eulerprod.pys	<genexpr>�s(t
_functionsRRyR0R�R(R)RRMR�R�((Rspsage/eulerprod.pyR2�s

7
(R8R9R,R2(((spsage/eulerprod.pyR��s	R>cBs�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
dd�Zd
�Zd�Zd�Zdd�Zddddd�Zdd�Zd�Zedd��ZRS(s'
    A formal product of L-series.
    cCsVt|t�st|�}n|jt�t|�dkrItd�n||_dS(sv
        INPUT:
            - `F` -- list of pairs (L,e) where L is an L-function and e is a nonzero integer.
        isproduct must be nonemptyN(R<RtsortR-RVR&Ry(R)R�((spsage/eulerprod.pyR,�s
cCst|j|j�S(N(R-Ry(R)R.((spsage/eulerprod.pyR/scCsAtd�|jD��}t|�dkr/tSt|�dSdS(s�
        Return True if every factor of self is self dual; otherwise, return False.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: L1 = LSeries('zeta'); L1.is_selfdual()
            True
            sage: L2 = LSeries(DirichletGroup(9).0); L2.is_selfdual()
            False
            sage: (L1*L1).is_selfdual()
            True
            sage: (L1*L2).is_selfdual()
            False
            sage: (L2*L2).is_selfdual()
            False
        css!|]\}}|j�VqdS(N(Rf(RJR�R�((spsage/eulerprod.pys	<genexpr>siiN(tsetRyRVRWRT(R)Rf((spsage/eulerprod.pyRfscCstd�|jD��S(s�
        Return the conductor of this product, which we define to be
        the product with multiplicities of the conductors of the
        factors of self.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: J = J0(33); L = LSeries(J)
            sage: L.conductor()
            3993
            sage: L.conductor().factor()
            3 * 11^3
            sage: J.decomposition()
            [
            Simple abelian subvariety 11a(1,33) of dimension 1 of J0(33),
            Simple abelian subvariety 11a(3,33) of dimension 1 of J0(33),
            Simple abelian subvariety 33a(1,33) of dimension 1 of J0(33)
            ]

        Of course, the conductor as we have defined it need not be an integer::

            sage: L = LSeries(J[0])/LSeries(J[2])^2; L
            (L-series of a degree 1 newform of level 11 and weight 2) * (L-series of a degree 1 newform of level 33 and weight 2)^-2
            sage: L.conductor()
            1/99
        css%|]\}}|j�|VqdS(N(R_(RJR�R�((spsage/eulerprod.pys	<genexpr>9s(RRy(R)((spsage/eulerprod.pyR_scCst|jt|��S(s
        Return the n-th power of this formal L-series product, where n can be any integer.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: L = LSeries('zeta') * LSeries(DirichletGroup(9).0)
            sage: L(2)
            1.80817853715812 + 0.369298119218816*I
            sage: L = LSeries('zeta') * LSeries(DirichletGroup(9).0)
            sage: L3 = L^3; L3
            (Riemann Zeta function viewed as an L-series)^3 * (L-series attached to Dirichlet character modulo 9 of conductor 9 mapping 2 |--> zeta6)^3
            sage: L3(2)
            5.17205298762567 + 3.57190597873829*I
            sage: CC((zeta(2)*LSeries(DirichletGroup(9).0)(2))^3)
            5.17205298762567 + 3.57190597873829*I
            sage: L^(-1999)
            (Riemann Zeta function viewed as an L-series)^-1999 * (L-series attached to Dirichlet character modulo 9 of conductor 9 mapping 2 |--> zeta6)^-1999
            sage: (L^(-1999)) (2)
            8.90248311986228e-533 - 6.20123089437732e-533*I
        (R>RyR(R)Rv((spsage/eulerprod.pyRw;scCs\t|t�r/t|jt|dfg��St|t�rRt|j|j�St�dS(Ni(R<R=R>RyRRC(R)R.((spsage/eulerprod.pyRxSs
 cCs\t|t�r/t|jt|dfg��St|t�rRt|j|j�St�dS(Ni����(R<R=R>RyRRC(R)R.((spsage/eulerprod.pyRz[s
 cCstS(N(Rt(R)((spsage/eulerprod.pyRubscCs|jS(N(Ry(R)((spsage/eulerprod.pytfactorescCsdS(sG
        Return the Hodge numbers of this product of L-series.
        N((R)((spsage/eulerprod.pyR`hscCstd�|jD��S(Ncss%|]\}}||j�VqdS(N(Rp(RJR�R�((spsage/eulerprod.pys	<genexpr>ns(R�Ry(R)((spsage/eulerprod.pyRpmscs t��fd�|jD��S(Nc3s+|]!\}}|j���|VqdS(N(R�(RJR�R�(R#R(spsage/eulerprod.pys	<genexpr>qs(RRy(R)R#R((R#Rspsage/eulerprod.pyR�pscOs|jj||�S(N(Ryt__getitem__(R)targsRi((spsage/eulerprod.pyR�sscCs|j�j�S(N(R�R7(R)((spsage/eulerprod.pyR7vscCs|jt|��|�S(N(R0R(R)R((spsage/eulerprod.pyR2ysicCs
t�dS(N(RB(R)R+((spsage/eulerprod.pyR1|siR�i5cs&t����fd�|jD��S(sb
        EXAMPLE::

            sage: from psage.lseries.eulerprod import LSeries
            sage: L1 = LSeries('zeta'); L2 = LSeries('delta')
            sage: f = L1 * L2; f
            (Riemann Zeta function viewed as an L-series) * (L-function associated to Ramanujan's Delta (a weight 12 cusp form))
            sage: f.taylor_series(center=2, degree=4, variable='w', prec=30)
            0.24077647 + 0.10066485*w + 0.061553731*w^2 - 0.041923238*w^3 + O(w^4)
            sage: L1.taylor_series(2, 4, 'w', 30) * L2.taylor_series(2, 4, 'w', 30)
            0.24077647 + 0.10066485*w + 0.061553731*w^2 - 0.041923238*w^3 + O(w^4)
            sage: f = L1 / L2; f
            (Riemann Zeta function viewed as an L-series) * (L-function associated to Ramanujan's Delta (a weight 12 cusp form))^-1
            sage: f.taylor_series(center=2, degree=4, variable='w', prec=30)
            11.237843 - 17.508629*w + 21.688182*w^2 - 24.044641*w^3 + O(w^4)
            sage: L1.taylor_series(2, 4, 'w', 30) / L2.taylor_series(2, 4, 'w', 30)
            11.237843 - 17.508629*w + 21.688182*w^2 - 24.044641*w^3 + O(w^4)

        c3s1|]'\}}|j�����|VqdS(N(R�(RJR�R�(R�RpRR�(spsage/eulerprod.pys	<genexpr>�s(RRy(R)R�RpR�R((R�RpRR�spsage/eulerprod.pyR�scst�fd�|jD��S(s�
        Return sum of the order of vanishing counted with
        multiplicities of each factors at their center point.

        WARNING: The analytic rank is computed numerically, so is
        definitely not provably correct.

        EXAMPLES::

        We compute the analytic rank of the non-simple 32-dimensional modular abelian variety `J_0(389)`.

            sage: from psage.lseries.eulerprod import LSeries
            sage: M = ModularSymbols(389,sign=1).cuspidal_subspace()
            sage: L = LSeries(M); L
            L-series attached to Modular Symbols subspace of dimension 32 of Modular Symbols space of dimension 33 for Gamma_0(389) of weight 2 with sign 1 over Rational Field

        We first attempt computation of the analytic rank with the default of 53 bits precision::

            sage: L.analytic_rank()
            Traceback (most recent call last):
            ...
            RuntimeError: invalid L-series parameters: functional equation not satisfied

        The above failed because trying to compute one of the degree
        20 newforms resulting in some internal error when double
        checking the functional equation.  So we try with slightly more precision::

            sage: L.analytic_rank(70)
            13

        This works, since the factors have dimensions 1,2,3,6,20, and
        the one of degree 1 has rank 2, the ones of degree 2,3,6 have
        rank 2,3,6, respectively, and the one of degree 20 has rank 0::

            sage: 2*1 + 2 + 3 + 6
            13
        c3s+|]!\}}||jd��VqdS(RN(R�(RJR�R�(R(spsage/eulerprod.pys	<genexpr>�s(R�Ry(R)R((Rspsage/eulerprod.pyR��s&cCstd�|jD��S(s�
        Return the weight of this L-series, which is the sum of the weights
        of the factors counted with multiplicity.
        css%|]\}}||j�VqdS(N(Ra(RJR�R�((spsage/eulerprod.pys	<genexpr>�s(R�Ry(R)((spsage/eulerprod.pyRa�scCst|j|�S(s�
        Return Dokchitser object that allows for computation of this
        L-series.  This is used behind the scenes for evaluation and
        computation of Taylor series.
        (R�Ry(R)R((spsage/eulerprod.pyR0�sN(R8R9R:R,R/RfR_RwRxRzRuR�R`RpROR�R�R7R2R1R�R�RaRR0(((spsage/eulerprod.pyR>�s,														(	tLSeriesZetacBs2eZdZd�Zd�Zd�Zd�ZRS(s�
    EXAMPLES::

        sage: from psage.lseries.eulerprod import LSeries
        sage: L = LSeries('zeta'); L
        Riemann Zeta function viewed as an L-series
        sage: L(2)
        1.64493406684823
        sage: L(2.000000000000000000000000000000000000000000000000000)
        1.64493406684822643647241516664602518921894990120680
        sage: zeta(2.000000000000000000000000000000000000000000000000000)
        1.64493406684822643647241516664602518921894990120680
        sage: L.local_factor(3)
        -T + 1
        sage: L.local_factor(5)
        -T + 1
        sage: L.anlist(30)
        [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
    cCsgtj|ddddgdddddddgdd	d
gdt�tdj�}d||_dS(
NR_iR`iRaRbRcRdi	iReR�(R=R,RRR�t_lf(R)R�((spsage/eulerprod.pyR,�s'cCsdS(Ni((R)R.((spsage/eulerprod.pyRr�scCs|jS(N(R�(R)R#R((spsage/eulerprod.pyR��scCsdS(Ns+Riemann Zeta function viewed as an L-series((R)((spsage/eulerprod.pyR7�s(R8R9R:R,RrR�R7(((spsage/eulerprod.pyR��s
			tLSeriesDeltacBs>eZdZd�Zd�Zdd�Zd�Zd�ZRS(s�
    EXAMPLES::

        sage: from psage.lseries.eulerprod import LSeriesDelta; L = LSeriesDelta()
        sage: L.anlist(10)
        [0, 1, -24, 252, -1472, 4830, -6048, -16744, 84480, -113643, -115920]
        sage: list(delta_qexp(11))
        [0, 1, -24, 252, -1472, 4830, -6048, -16744, 84480, -113643, -115920]
        sage: L.anlist(10^4) == list(delta_qexp(10^4+1))
        True
    cCs]tj|dddddgdddddgd	gd
t�tdj�|_i|_dS(NR_iR`iRaiRbRcRdReR�(R=R,RRR�t_TR�(R)((spsage/eulerprod.pyR,�s*cCs?y|j|SWntk
r"nX|j|d�|j|S(s�
        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeriesDelta; L = LSeriesDelta()
            sage: L.local_factor(2)
            2048*T^2 + 24*T + 1
            sage: L._local_factor(11, None)   # really this is called
            285311670611*T^2 - 534612*T + 1

        The representation is reducible modulo 691::

            sage: L.local_factor(2).factor_mod(691)
            (666) * (T + 387) * (T + 690)
            sage: L.local_factor(3).factor_mod(691)
            (251) * (T + 234) * (T + 690)
            sage: L.local_factor(11).factor_mod(691)
            (468) * (T + 471) * (T + 690)

        ... because of the 691 here::

            sage: bernoulli(12)
            -691/2730
        i(R�tKeyErrorR�(R)R#R((spsage/eulerprod.pyR�s
cCs�ddlm}|j}|d}||�}xNt|�D]@}|jj|�s<d||||d||j|<q<q<WdS(s�
        Precompute local factors up to the given bound.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeriesDelta; L = LSeriesDelta()
            sage: L._lf
            {}
            sage: L._precompute_local_factors(10)
            sage: L._lf
            {2: 2048*T^2 + 24*T + 1, 3: 177147*T^2 - 252*T + 1, 5: 48828125*T^2 - 4830*T + 1, 7: 1977326743*T^2 + 16744*T + 1}
        i����(t
delta_qexpiiiN(tsage.modular.allR�R�RR�thas_key(R)R�RR�R�tT2R�R�((spsage/eulerprod.pyR�"s
	
cCsdS(NsBL-function associated to Ramanujan's Delta (a weight 12 cusp form)((R)((spsage/eulerprod.pyR77scCsdS(Ni((R)R.((spsage/eulerprod.pyRr:sN(	R8R9R:R,R�ROR�R7Rr(((spsage/eulerprod.pyR��s			tLSeriesEllipticCurvecBsMeZdd�Zd�Zd�Zd�Zd�Zd�Zdd�Z	RS(	i5cCs�|j�}||_|j�}|j�}i|_tdj�|_|j�|_	t
t|j	�|j��dkr�t
d�ntj|dt|j	�|j�dddg|dg|ddd	dd
gdgd|d
|�dS(s�
        EXAMPLES::
            sage: from psage.lseries.eulerprod import LSeriesEllipticCurve
            sage: L = LSeriesEllipticCurve(EllipticCurve('389a'))
            sage: L(2)
            0.360092863578881
        R�is{Computation of conductor only implemented when the discrimenant of the base field and the norm of the conductor are coprimeR_iR`iRaRbRcRdReRN(tglobal_minimal_modelt_EReRpR�RR�R�R_t_NRRtdiscriminantRBR=R,(R)tERR�R�((spsage/eulerprod.pyR,?s		$)$cCs|jS(N(R�(R)((spsage/eulerprod.pytelliptic_curveTscCst|j�|j��S(N(R-R�(R)R.((spsage/eulerprod.pyRrWscCsd|j�S(NsL-series of %s(R�(R)((spsage/eulerprod.pyR7Zsc	Cs�td}|j�}t|�}t|�}t|�j|�}|jj�}|j|�r�|j|j�r�|jj|�j	�}d|||S|d|jj
|�j�}d|||||d|SdS(NR�ii(RR�RR$tordR�tdividesR�t
local_datatbad_reduction_typet	reductiontcount_points(	R)R#R�R�tqR�R�tN1R((spsage/eulerprod.pyt_lf0]s
! cCs6|jj|�s+|j|�|j|<n|j|S(N(R�R�R�(R)R#R((spsage/eulerprod.pyR�kscCsxxqt|�D]c}xZ|j|�D]I}|j�|krAq#n|jj|�s#|j|�|j|<q#q#Wq
WdS(N(R
R�RR�R�R�(R)R�RR�R�((spsage/eulerprod.pyR�usN(
R8R9R,R�RrR7R�R�ROR�(((spsage/eulerprod.pyR�>s					
tLSeriesEllipticCurveQQcBs&eZd�Zd�Zdd�ZRS(cCs�|j�}||_|j�}|j�|_i|_tdj�|_t	j
|d|jdddgddd|j�d	gd
gdt�dS(NR�R_R`iiRaiRbRcRdRe(
R�R�ReR_R�R�RR�R�R=R,troot_numberR(R)R�R�((spsage/eulerprod.pyR,�s		cCs�|jj|�}|j}|j|dkrd|j||dkrU|j�d�Sd||Snd|||||SdS(Nii(R�tapR�R�Ru(R)R�RR�((spsage/eulerprod.pyR��s	cCsFx?t|�D]1}|jj|�s
|j|�|j|<q
q
WdS(N(R
R�R�R�(R)R�RR�((spsage/eulerprod.pyR��sN(R8R9R,R�ROR�(((spsage/eulerprod.pyR��s		tLSeriesEllipticCurveSqrt5cBs&eZdd�Zd�Zd�ZRS(cCsn|j}ddlm}m}||�}ddlm}|||�}tg|j�D]}	||	j��^qZ�}
t	d}|j
�}gtd�D]}
||
^q�}t|d�s�i|_
nx�t|�D]�\}
}|j�r�dnd}||
}||
kr+d|||}n.|j�}d|||||d|}||j
|<q�WdS(	Ni����(tprimes_of_bounded_normtPrime(taplistR�iR�ii(R�tpsage.number_fields.sqrt5.primeR�R�t#psage.ellcurve.lseries.aplist_sqrt5R�R�R�tprimeRR�RZRR�R�tis_inertR(R)R�RR�R�R�R
R�RMRt
bad_primesR#R�RKtTptinertial_degta_pR�R�((spsage/eulerprod.pyR��s&	1
#
"cCskddlm}m}t||�s4||�}n|jj|�rQ|j|Stj||j��SdS(Ni����(R�R�(	tnumber_fields.sqrt5.primeR�R�R<R�R�R�R�t
sage_ideal(R)R#RR�R�((spsage/eulerprod.pyR��scCsddlm}||�S(s�
        Return the primes above p.  This function returns a special
        optimized prime of the ring of integers of Q(sqrt(5)).
        i����(R�(R�R�(R)R�R�((spsage/eulerprod.pyR��sN(R8R9ROR�R�R�(((spsage/eulerprod.pyR��s%		tLSeriesDedekindZetacBs;eZdZd�Zd�Zd�Zd�Zd�ZRS(s�
    EXAMPLES::

        sage: from psage.lseries.eulerprod import LSeries
        sage: K.<a> = NumberField(x^3 - 2)
        sage: L = LSeries(K); L
        Dedekind Zeta function of Number Field in a with defining polynomial x^3 - 2
        sage: L(2)
        1.60266326190044
        sage: L.residues()
        'automatic'
        sage: L.residues(prec=53)
        [-4.77632833933856]
        sage: L.residues(prec=100)
        [-4.7763283393385594030639875094]
    cCs�|j�s!|jdd�}n||_|j�}|j�d}tj|dt|j��ddg||dg|ddddd	dgd
dd|d
t	�t
dj�|_dS(NtnamesRiR_R`iRaRbRcRdR{ReRfR�(
tis_absolutetabsolute_fieldt_KRpt	signatureR=R,R�R�R\RR�R�(R)R�R�tsigma((spsage/eulerprod.pyR,�s		cCst|j�|j��S(N(R-tnumber_field(R)R.((spsage/eulerprod.pyRr�scCs|jS(N(R(R)((spsage/eulerprod.pyR�scCsd|jS(NsDedekind Zeta function of %s(R(R)((spsage/eulerprod.pyR7�scCs|j}d||j�S(Ni(R�tresidue_class_degree(R)R#RR�((spsage/eulerprod.pyR�s	(R8R9R:R,RrRR7R�(((spsage/eulerprod.pyR��s				tLSeriesDirichletCharactercBsGeZdZd�Zd�Zd�Zd�Zdd�Zd�Z	RS(s�
    EXAMPLES::

        sage: from psage.lseries.eulerprod import LSeries;  L = LSeries(DirichletGroup(5).0)
        sage: L(3)
        0.988191681624057 + 0.0891051883457395*I
    cCs�|j�std�n|j�r0td�n|j�j�dkrTtd�n||_tj|d|j	�d|j
�r�dgndgddd	dd
gdgdtd
|j
�dk�tdj�|_dS(Nschi must be primitiveschi must be nontrivialis$base ring must have characteristic 0R_R`iRaRbRcRdReRfiR�(tis_primitiveRBt
is_trivialt	base_ringtcharacteristicR&t_chiR=R,R_tis_oddRORtorderRR�R�(R)R�((spsage/eulerprod.pyR,s 	cCst|j�|j��S(N(R-t	character(R)R.((spsage/eulerprod.pyRr scCsd|jS(s�
        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries;  L = LSeries(DirichletGroup(3).0)
            sage: L.__repr__()
            'L-series attached to Dirichlet character modulo 3 of conductor 3 mapping 2 |--> -1'
        sL-series attached to %s(R
(R)((spsage/eulerprod.pyR7#scCs|jS(N(R
(R)((spsage/eulerprod.pyR
-scCs�|j}|dkr?td�t|j��|j�j�St|�}||j��j�|jd|�}|j�r�||j	�9}nd|SdS(Ni����Ri(
R
RORRt	gauss_sumtmodulusR
tgauss_sum_numericalRR�(R)RR�R~R?((spsage/eulerprod.pyRb0s	*(cCs?|j|�}|dk	r0t|�|�}nd||jS(Ni(R
ROR
R�(R)R#RR((spsage/eulerprod.pyR�<sN(
R8R9R:R,RrR7R
RORbR�(((spsage/eulerprod.pyRs			
	tLSeriesModularSymbolsAbstractcBs>eZd�Zd�Zd�Zd�Zd�Zd�ZRS(cCst|j�|j��S(N(R-tmodular_symbols(R)R.((spsage/eulerprod.pyRrCscCs|jS(N(t_M(R)((spsage/eulerprod.pyRFscCs,d|jj�|jj�|jj�fS(s7
        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeries
            sage: f = Newforms(43,2,names='a')[1]; f
            q + a1*q^2 - a1*q^3 + (-a1 + 2)*q^5 + O(q^6)
            sage: LSeries(f).__repr__()
            'L-series of a degree 2 newform of level 43 and weight 2'
        s9L-series of a degree %s newform of level %s and weight %s(Rt	dimensiontlevelRa(R)((spsage/eulerprod.pyR7Is
cCs]gt|�D]6}|jj|�s=|j|d|kr
|^q
}|j||�dS(Ni(RR�R�t_do_precompute(R)R�RR�R
((spsage/eulerprod.pyR�UsIcCs�|jj|�\}}|dkr-t}nH|dksE|tkri|j�tkr`t}qut}nt|�}|j�j|�|j	}t
|g|D]}||�^q��}|j|�|}|dj�}	|	d}
|jj
�}|j�}x~tt|��D]j}
||
}||�}|dkrQ|||d9}nd||
|	||
}||f|j|<qWdS(Ni5R�iii(Rtcompact_system_of_eigenvaluesRROtooRRR
t
embeddingst
_conjugateRtchange_ringR�R
RaRZRVR�(R)R
RR�RMR~tphiRR�R�R�R�R+RKR�RR�((spsage/eulerprod.pyRYs,			(

cCss|dkrt}n|jj|�rM|j|d|krM|j|dS|j|g|�|j|dSdS(Nii(RORR�R�R(R)R#R((spsage/eulerprod.pyR�rs	)(R8R9RrRR7R�RR�(((spsage/eulerprod.pyRBs					t"LSeriesModularSymbolsNewformGamma0cBs#eZd�Zdedd�ZRS(cCs%t|j|jf|j|jf�S(N(R-RR(R)R.((spsage/eulerprod.pyRr|sic	Cs�|j�dkrtd�n|j�}|dksC|j�rOtd�n||_|j�}|r�|j�s�td�n|j�s�td�n|j	�s�td�q�n|j
�}|dkr|j|�j�}|dkr�td	�nd|d
|d}nt
|�}|dks=||j�krItd�n||_i|_tj|d|d
ddgd|d|dgdgdt�dS(s
        INPUT:
            - M -- a simple, new, cuspidal modular symbols space with
              sign 1
            - conjugate -- (default: 0), integer between 0 and dim(M)-1
            - check -- (default: True), if True, checks that M is
              simple, new, cuspidal, which can take a very long time,
              depending on how M was defined
            - epsilon -- (default: None), if not None, should be the sign
              in the functional equation, which is -1 or 1.  If this is
              None, then epsilon is computed by computing the sign of
              the main Atkin-Lehner operator on M.  If you have a faster
              way to determine epsilon, use it.

        EXAMPLES::

            sage: from psage.lseries.eulerprod import LSeriesModularSymbolsNewformGamma0
            sage: M = ModularSymbols(43,sign=1).cuspidal_subspace()[1]; M
            Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 4 for Gamma_0(43) of weight 2 with sign 1 over Rational Field
            sage: L0 = LSeriesModularSymbolsNewformGamma0(M,0,check=False,epsilon=1); L0
            L-series of a degree 2 newform of level 43 and weight 2
            sage: L0.taylor_series()
            0.620539857407845 + 0.331674007376949*z - 0.226392184536589*z^2 + 0.0960519649929789*z^3 - 0.00451826124421802*z^4 - 0.0203363026933833*z^5 + O(z^6)
            sage: L1 = LSeriesModularSymbolsNewformGamma0(M,1,check=False,epsilon=1); L1
            L-series of a degree 2 newform of level 43 and weight 2
            sage: L1(1)
            0.921328017272472
            sage: L1.taylor_series()
            0.921328017272472 + 0.492443075089339*z - 0.391019352704047*z^2 + 0.113271812405127*z^3 + 0.0213067052584679*z^4 - 0.0344198080536274*z^5 + O(z^6)
        is-modular symbols space must positive dimensions1modular symbols space must have trivial characters$modular symbols space must be simples!modular symbols space must be news&modular symbols space must be cuspidali����is>modular symbols space must have constant Atkin-Lehner operatoris<conjugate must a nonnegative integer less than the dimensionR_R`RaRbRcRdReN(i����i(ii(RR&R
RORRRt	is_simpletis_newtis_cuspidalRatatkin_lehner_operatortmatrixRRR�R=R,R(	R)tMt	conjugatetcheckRbR�tNR+tw((spsage/eulerprod.pyR,sB			N(R8R9RrR\ROR,(((spsage/eulerprod.pyR{s	cCs�t|�std�n|j�dkr6td�n|j�dkrTtd�n|j�sltd�n|j�s�td�n|j�s�td�ndS(Nsmust be a modular symbols spaceis-modular symbols space must positive dimensions4modular symbols space must have associated characters$modular symbols space must be simples!modular symbols space must be news&modular symbols space must be cuspidal(	RRCRR&R
RORRR (R#((spsage/eulerprod.pyt_is_valid_modsym_space�st%LSeriesModularSymbolsNewformCharactercBseZd�Zdd�ZRS(cCs%t|j|jf|j|jf�S(N(R-RR(R)R.((spsage/eulerprod.pyRr�sicCs�t|�|j�}||_|j�}d}|j�}t|�}|dksg||j�krstd�n||_t	j
|d|dddgd|d|d	gd
gdtd|j�d
k�i|_
dS(NRis<conjugate must a nonnegative integer less than the dimensionR_R`iRaRbRcRdReRfi(R(R
RRRaRRR&RR=R,RRR�(R)R#R$R�R&RbR+((spsage/eulerprod.pyR,�s(
		(R8R9RrR,(((spsage/eulerprod.pyR)�s	t LSeriesModularEllipticCurveSqrt5cBs5eZd�Zd�Zd�Zd�Zd�ZRS(cKs�||_|j�|_tdj�|_tj|dt|j�ddddddgddd	dd
gdgdgd
|j	�dt
|�dS(NR�R_iR`iiRaiRbi����RcRdReRf(R�R_R�RR�R�R=R,RReR\(R)R�Ri((spsage/eulerprod.pyR,�s	cCs|jS(N(R�(R)((spsage/eulerprod.pyR�	scCst|j�|j��S(N(R-R�(R)R.((spsage/eulerprod.pyRr		scCsd|jS(NsL-series attached to %s(R�(R)((spsage/eulerprod.pyR7	scCs�|j}|jj|�}|dkr7|j�d�S|dkri|j�}d||d||gS|jj|�}|j�}|j�}d|||||d|SdS(Nii(R�R�t	valuationRuRR�R�R(R)R#RR�RMR�RR�((spsage/eulerprod.pyR�	s	(R8R9R,R�RrR7R�(((spsage/eulerprod.pyR*�s
				cCs#|j�r|dfgSt�dS(s
    Returns a simple new modular symbols space N and an integer d such
    that M is isomorphic to `N^d` as a module over the anemic Hecke
    algebra.

    INPUT:
        - M -- a sign=1 modular simple space for the full Hecke
          algebra (including primes dividing the level) that can't be
          decomposed further by the Hecke operators.  None of the
          conditions on M are explicitly checked.

    OUTPUT:
        - N -- a simple new modular symbols space
        - d -- a positive integer
    iN(RRB(R#((spsage/eulerprod.pyt#_new_modsym_space_with_multiplicity!	s
icCsK|j�}|dkr!t�n&|j�r:t||�St||�SdS(N(R
RORBRRR)(R#RKR�((spsage/eulerprod.pytLSeriesModularSymbolsNewform5	s	
tLSeriesModularSymbolsMotivecBs)eZdZd�Zd�Zd�ZRS(sJ
    The product of L-series attached to the modular symbols space M.
    c
Cs�||_t|�s!td�n||_|j�}x|D]}t|�q=Wg}xv|D]n}xet|�D]W}|\}}|j�}x6t|j��D]"}	|j	t
||	�|f�q�WqqWq^Wtj||�dS(NsBX must be a modular symbols space or have a modular symbols method(
RRRCt
decompositionR(R,R
RZRRUR-R>R,(
R)R#tDtAR�RLR&R�R�RK((spsage/eulerprod.pyR,B	s		

(cCs|jS(N(R(R)((spsage/eulerprod.pyRS	scCsd|jS(NsL-series attached to %s(R(R)((spsage/eulerprod.pyR7V	s(R8R9R:R,RR7(((spsage/eulerprod.pyR.>	s		tLSeriesModularAbelianVarietycBs)eZdZd�Zd�Zd�ZRS(s�
    The product of L-series attached to the modular abelian variety A.

    EXAMPLES::

        sage: from psage.lseries.eulerprod import LSeries
        sage: L = LSeries(J0(54)); L
        L-series attached to Abelian variety J0(54) of dimension 4
        sage: L.factor()
        (L-series of a degree 1 newform of level 27 and weight 2)^2 * (L-series of a degree 1 newform of level 54 and weight 2) * (L-series of a degree 1 newform of level 54 and weight 2)
        sage: L(1)
        0.250717238804658
        sage: L.taylor_series(prec=20)
        0.25072 + 0.59559*z + 0.15099*z^2 - 0.35984*z^3 + 0.056934*z^4 + 0.17184*z^5 + O(z^6)

    Independent check of L(1)::

        sage: prod(EllipticCurve(lbl).lseries()(1) for lbl in ['54a', '54b', '27a', '27a'])
        0.250717238804658

    Different check that totally avoids using Dokchitser::

        sage: prod(EllipticCurve(lbl).lseries().at1()[0] for lbl in ['54a', '54b', '27a', '27a'])
        0.250848605530185
    cCs�||_|j�}d}x�|D]{}t|j�dd�}|jdd�}t|j�|j��}t|�|}|dkr�|}q"||9}q"W|dkr�t	d�nt
j||j��dS(NR�Rtsignis,abelian variety must have positive dimension(
t_AR/RORt
newform_labelRRRR.R&R>R,R�(R)R1R0R�R�R#R�R�((spsage/eulerprod.pyR,s	s	
	cCs|jS(N(R4(R)((spsage/eulerprod.pytabelian_variety�	scCsd|jS(NsL-series attached to %s(R4(R)((spsage/eulerprod.pyR7�	s(R8R9R:R,R6R7(((spsage/eulerprod.pyR2Y	s		R�cBsMeZdZdddd�Zd�Zd�Zd�Zd�Zd�Z	RS(	s.
    Twist of an L-series by a character.
    i5cCs||_||_|j�s*td�nt|j��}|j�}|dkr|j|�dkr�t|�}x,|j|�dkr�||j|�}qxW|||j�}	|	|dks�t	�gt
|	|�D]}
||
^q�}q|||j�}n|j�}|j�}|dkr�|j
�dkr�|j�dkr�|j|�dkr�|j
�||�}q�|j
�|j
�g}q�d}q�d}n|j�}
g}d}|j�}tj|||||||||
|�
dS(s!
        INPUT:
            - `L` -- an L-series
            - ``chi`` -- a character of the base field of L
            - ``conductor`` -- None, or a list of conductors to try
            - ``prec`` -- precision to use when trying conductors, if
              conductor is a list
        scharacter must be primitiveiiRiR{N(t_LR
RR&RR_RORRpR�tdivisorsR`RaRbRRfReR=R,(R)R�R�R_RbRR1tBtsmallesttbiggestR�R`RaRfRcRdRe((spsage/eulerprod.pyR,�	s>			*		cCsk|jj||�}|j}|j�j�}||�}|dk	r]t|�|�}n|||�S(N(R7R�R
RuR�ROR
(R)R#RtL0R�R�Rs((spsage/eulerprod.pyR��	s	cCsd|j|jfS(NsTwist of %s by %s(R7R
(R)((spsage/eulerprod.pyR7�	scCs%t|j|jf|j|jf�S(N(R-R7R
(R)R.((spsage/eulerprod.pyRr�	scCs|jS(N(R7(R)((spsage/eulerprod.pytuntwisted_lseries�	scCs|jS(N(R
(R)((spsage/eulerprod.pyttwist_character�	sN(
R8R9R:ROR,R�R7RrR=R>(((spsage/eulerprod.pyR��	s5					cOst|||�}||_|S(sL
    Return the L-series of X, where X can be any of the following:

        - elliptic curve over a number field (including QQ)
        - Dirichlet character
        - cuspidal newform
        - new cuspidal modular symbols space -- need not be simple
        - string: 'zeta' (Riemann Zeta function), 'delta'
        - modular elliptic curve attached to Hilbert modular forms space

    For convenience, if L is returned, then L._X is set to X.

    EXAMPLES::

    The Dedekind Zeta function of a number field::

        sage: from psage.lseries.eulerprod import LSeries
        sage: K.<a> = NumberField(x^2 + 1)
        sage: L = LSeries(K); L
        Dedekind Zeta function of Number Field in a with defining polynomial x^2 + 1
        sage: L(2)
        1.50670300992299

        sage: K.zeta_coefficients(100) == L.anlist(100)[1:]
        True

        sage: L = LSeries(ModularSymbols(43, weight=2,sign=1).cuspidal_subspace().decomposition()[1])
        sage: L(1)
        0.571720756464112
        sage: L.factor()[0][0](1)
        0.620539857407845
        sage: L.factor()[1][0](1)
        0.921328017272472
        sage: L._X
        Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 4 for Gamma_0(43) of weight 2 with sign 1 over Rational Field
        sage: L = LSeries(ModularSymbols(DirichletGroup(13).0^2, weight=2,sign=1).cuspidal_subspace())
        sage: L(1)
        0.298115272465799 - 0.0402203326076733*I

        sage: from psage.modform.hilbert.sqrt5.hmf import F, HilbertModularForms
        sage: D = HilbertModularForms(-13*F.0+5).elliptic_curve_factors()
        sage: D
        [
        Isogeny class of elliptic curves over QQ(sqrt(5)) attached to form number 0 in Hilbert modular forms of dimension 4, level -13*a+5 (of norm 209=11*19) over QQ(sqrt(5)),
        Isogeny class of elliptic curves over QQ(sqrt(5)) attached to form number 1 in Hilbert modular forms of dimension 4, level -13*a+5 (of norm 209=11*19) over QQ(sqrt(5)),
        Isogeny class of elliptic curves over QQ(sqrt(5)) attached to form number 2 in Hilbert modular forms of dimension 4, level -13*a+5 (of norm 209=11*19) over QQ(sqrt(5))
        ]
        sage: L = LSeries(D[0])
        sage: L(RealField(10)(1))
        0
        sage: L.epsilon()
        -1

    The L-series of a modular abelian variety with both new and old parts::

        sage: L = LSeries(J0(33)); L
        L-series attached to Abelian variety J0(33) of dimension 3
        sage: L.factor()
        (L-series of a degree 1 newform of level 11 and weight 2)^2 * (L-series of a degree 1 newform of level 33 and weight 2)
        sage: L.local_factor(2, prec=oo)
        8*T^6 + 12*T^5 + 12*T^4 + 8*T^3 + 6*T^2 + 3*T + 1
        sage: L(1)
        0.0481553138900504

    We check the above computation of L(1) via independent methods (and implementations)::

        sage: prod(EllipticCurve(lbl).lseries().at1()[0] for lbl in ['11a', '11a', '33a'])
        0.0481135342926321
        sage: prod(EllipticCurve(lbl).lseries()(1) for lbl in ['11a', '11a', '33a'])
        0.0481553138900504

    A nonsimple new modular symbols space of level 43::

        sage: L = LSeries(ModularSymbols(43,sign=1).cuspidal_subspace())
        sage: L
        L-series attached to Modular Symbols subspace of dimension 3 of Modular Symbols space of dimension 4 for Gamma_0(43) of weight 2 with sign 1 over Rational Field
        sage: L(1)
        0
        sage: L.taylor_series()
        0.196399786632435*z + 0.314922741074845*z^2 - 0.0797083673829092*z^3 - 0.161630566287135*z^4 + 0.123939472976207*z^5 + O(z^6)
        sage: L.factor()
        (L-series of a degree 1 newform of level 43 and weight 2) * (L-series of a degree 2 newform of level 43 and weight 2) * (L-series of a degree 2 newform of level 43 and weight 2)
        sage: L.analytic_rank()
        1
        sage: D = ModularSymbols(43,sign=1).cuspidal_subspace().decomposition()
        sage: L0 = LSeries(D[0]); L1 = LSeries(D[1])
        sage: L0.taylor_series() * L1.taylor_series()
        0.196399786632435*z + 0.314922741074845*z^2 - 0.0797083673829091*z^3 - 0.161630566287135*z^4 + 0.123939472976207*z^5 + O(z^6)
        sage: L0.factor()
        L-series of a degree 1 newform of level 43 and weight 2
        sage: L1.factor()
        (L-series of a degree 2 newform of level 43 and weight 2) * (L-series of a degree 2 newform of level 43 and weight 2)

    (R't_X(RLR�RiR�((spsage/eulerprod.pyRA�	s_	cOs�t|�rr|j�}t|�r4t|||�St|j��dddgkret|||�St|�Snt|�r�|j	�r�|j
�r�t||�St|||�Snt
|�r�t|||�St|tjjjj�r	t|jdd�||�St|�r@|j�dkr0t�nt|||�St|t�r�|j�}|dkrtt||�S|dkr�t||�Std|�nt|tjj j!j"j#�r�t$|||�St%|�r�t&|||�St�dS(s3
    Helper function used by LSeries function.
    i����iR3tzetatdeltasunknown L-series "%s"N('RRRR�RTtdefining_polynomialR�R�RRRR�RRR�R<tsagetmodulartmodformtelementRR-RRR3RBR.R�tlowerR�R&tpsagethilberttsqrt5thmftEllipticCurveFactorR*RR2(RLR�RiR�ty((spsage/eulerprod.pyR'F
s>!

	

(QR:R�R�R�tsage.allRRRRRRtsage.rings.allRRRR	R
RRRtsage.arith.allR
tsage.rings.rational_fieldRt(sage.schemes.elliptic_curves.ell_genericRt	pyximporttinstallthelperRt
sage.misc.allRtsage.modular.abvar.abvarRtsage.modular.dirichletRtsage.lfunctions.dokchitserRtsage.modular.modsym.spaceRt)sage.rings.number_field.number_field_baseRtsage.modular.modform.elementRCR�Rtsage.structure.factorizationRtsage.misc.mrangeRtIRRR!R$tobjectR%R;RtR=R�R>R�R�R�R�R�R�RRRR(R)R*R,R-R.R2R�RAR'(((spsage/eulerprod.pyt<module>sl$.4
					vQ	�����
�#MB70<9I	$*		6T	c