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dgd'dҐdgd'dԐdgd,d֐dgd,dؐdgd'dڐdgd,dܐdgd,dސdgdfddgd,ddgd,ddgd'ddgdܐddgd,ddgd'ddgd,ddgd,ddgdܐddgd'ddgd,ddgd,ddgd'ddgdddgd,ddgd,d dgd,ddgdddgd'ddgd,dd	gd,d
dgd'ddgd'ddgd'ddgd,ddgd,ddgd,ddgd,ddgd,ddgdddgdddgddd gd!d"d#gdd$d%gdd&d'gd(d)d*gdd+d,gd-d.d/gdd0d1gd(d2d3gd-gZdS (6  a  
The function zetazero(n) computes the n-th nontrivial zero of zeta(s).

The general strategy is to locate a block of Gram intervals B where we
know exactly the number of zeros contained and which of those zeros
is that which we search.

If n <= 400 000 000  we know exactly the Rosser exceptions, contained
in a list in this file. Hence for n<=400 000 000 we simply
look at these list of exceptions. If our zero is implicated in one of
these exceptions we have our block B.  In other case we simply locate
the good Rosser block containing our zero.

For n > 400 000 000 we apply the method of Turing, as complemented by
Lehman, Brent and Trudgian  to find a suitable B.
   )defundefun_wrappedc                 C   s  t ttd D ]}td|  d }td|  d }||d kr|d |kr| |}| |}| j|}| j|}|| d }	|| }
td| d  }|	||g||g||gf  S q|d }t| |\}}}|g}|g}|dk r|d8 }t| |\}}}|d| |d| q|| d }	|d }t| |\}}}|| || |dk r|d7 }t| |\}}}|| || qR|	||g||fS )z;for n<400 000 000 determines a block were one find our zero       r   )	rangelen_ROSSER_EXCEPTIONS	grampoint_fpsiegelzcompute_triple_tvbinsertappend)ctxnkabt0t1v0v1my_zero_numberzero_number_blockpatterntvTVm r    j/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/mpmath/functions/zetazeros.pyfind_rosser_block_zero   s@    






r"   c                 C   s,   d}| dkrd}| dkrd}| dkr(d}|S )z(Precision needed to compute higher zeros5   i ?   l    h] F       @ k S   r    )r   wpr    r    r!   wpzeros7   s    r)   Nc                    s  |du r j }d}t|}||k rv||k rv|d }|d }	|g}
|	g}d}tdt|D ]}|| }|| }||	 dkr ||	 }|| | |d  }n|| d }|dk r؈ j|}t||k r |}n
 |}|	| dk r|d7 }|
| || || }|| dk r(|d7 }|
| || |}|}	q\|
}|}|d7 }|t	krl|dkrl|d |krld}d}d}tdt|D ]J}|| ||d   }||kr|}|}|}n||k r||kr|}q|d| krl fdd}||d  }|| } j
|||fd	d
d
d} |}	||k rl||k rl|	||  dk rl||| |||	 t|}q||krd}nd
}|||fS )z^Separate the zeros contained in the block T, limitloop
    determines how long one must searchNr   r   r   
      c                    s    j | ddS )Nr   Z
derivative)Zrs_zxr   r    r!   <lambda>y       z)separate_zeros_in_block.<locals>.<lambda>illinoisF)solververifyverboseT)infcount_variationsr   r   sqrtr
   r   absr   ITERATION_LIMITfindrootr   )r   r   r   r   	limitloopfp_toleranceZ
loopnumber
variationsr   r   ZnewTZnewVr   b2ualphar   wZdtMaxZdtSecZkMaxZk1dtfr   r   r   	separatedr    r/   r!   separate_zeros_in_blockB   s|    




"

&

rF   c                    sd  d}|d }t dt|D ]8}|| }	||	 dk rN|d7 }||krN|}
|}|	}|	}q||
 }||
d  }| _t| | }d | } jd g}d}|d d| kr|d7 }|d d d d|  g| }q|d |  _ j fdd||fdd	d
} d|}|dd D ]>}||  _| | j|dd  } d 	|}q 	|S )zPIf we know which zero of this block is mine,
    the function separates the zeror   r      r   r+   c                    s
     | S )Nr   r-   r/   r    r!   r0      r1   z"separate_my_zero.<locals>.<lambda>r2   F)r3   r5         ?Nr,   )
r   r   precr)   logmagr;   mpczetaZim)r   r   r   r   r   rJ   r>   r   r   r   k0ZleftvZrightvr   r   wpzZguardZprecsindexrzZznewr    r/   r!   separate_my_zero   s:     
rT   c                 C   sj   |dk rdS |  |d }| j|}d|d  d|  }d|d  d|  }| t||}t|}|S )a  The number of good Rosser blocks needed to apply
    Turing method
    References:
    R. P. Brent, On the Zeros of the Riemann Zeta Function
    in the Critical Strip, Math. Comp. 33 (1979) 1361--1372
    T. Trudgian, Improvements to Turing Method, Math. Comp.i r   d   gHPx?g{Gz?ga+ei?g)\(?)r	   r
   lnceilminint)r   r   glgZbrentZtrudgianNr    r    r!   sure_number_block   s    r]   c                 C   sR   |  |}| j|}| t|| |d k r<| |}|d|  }|||fS )N-   )r	   r
   r   rL   r9   )r   r   r   r   r   r    r    r!   r      s    

r   rG   c           &      C   s$  t | |}d}|d }t| |\}}}|g}	|g}
|dk rh|d7 }t| |\}}}|	| |
| q2|g}|g}|g}|d| k r`|d7 }t| |\}}}|| || |dk r|d7 }t| |\}}}|| || q|| t|d }t| |||t|d\}}}|	  |	| |
  |
| |rN|d7 }nd}|g}|g}qzd}|d }t| |\}}}|	d| |
d| |dk r|d8 }t| |\}}}|	d| |
d| q|d| |g}|g}|d| k r|d8 }t| |\}}}|d| |d| |dk rf|d8 }t| |\}}}|d| |d| q(|d| t|d }t| |||t|d\}}}|  ||	 }	|  ||
 }
|r|d7 }nd}|g}|g}q|d|  }t|}||d|  d  }t| |\}}}|		|}t| |\}}}|		|}|	||d  }|
||d  }|| }t| |||t|d\}}}|r|| d ||g||fS || }t|}||| d  }t| |\}}} |		|}!t| |\}"}#}$|		|"}%|	|!|%d  }|
|!|%d  }|| d ||g||fS )zTo use for n>400 000 000r   r   r   r<   r=   )
r]   r   r   r   rF   r:   popextendr   rQ   )&r   r   r=   ZsbZnumber_goodblocksm2r   r   r   ZTfZVfZ
goodpointsr   r   ZznABrE   rR   r[   strZvrbrartsvsbsZas1qZtqZvqbqZaqttZvtZbtatr    r    r!   search_supergood_block   s    
















rq   c                 C   sD   d}| d }t dt| D ]$}| | }|| dk r:|d7 }|}q|S Nr   r   )r   r   )r   countvoldr   vnewr    r    r!   r7   2  s    r7   c                 C   s   d}|d }|d }t | |\}}}	d}
d}t|d |d D ]}t | |\}}}t|}|
|k rx||
 |krx|
d7 }
qZ|||
 }|| |d| t|}|d|  }|dkr|d }|
}|||  }}}	q>|d d }|S )N(r   r   z%sz)(r_   )r   r   r   r   r   r7   )r   blockr   r   r   r   r   r   r   Zb0r   rO   r   r   r   b1ZlgTLrs   r    r    r!   pattern_construct<  s,    

rz   FTc                 C   s  t |}|dk r | |  S |dkr0td| j}zt| |\}}|| _|dk rht| |\}}}	}
nt| ||\}}}	}
|d |d  }t| ||	|
| j	|d\}	}
}|rt
| ||	|
}t||}t| |||	|
|}| d|}W || _n|| _0 |r|
 }|r||||fS |S dS )a  
    Computes the `n`-th nontrivial zero of `\zeta(s)` on the critical line,
    i.e. returns an approximation of the `n`-th largest complex number
    `s = \frac{1}{2} + ti` for which `\zeta(s) = 0`. Equivalently, the
    imaginary part `t` is a zero of the Z-function (:func:`~mpmath.siegelz`).

    **Examples**

    The first few zeros::

        >>> from mpmath import *
        >>> mp.dps = 25; mp.pretty = True
        >>> zetazero(1)
        (0.5 + 14.13472514173469379045725j)
        >>> zetazero(2)
        (0.5 + 21.02203963877155499262848j)
        >>> zetazero(20)
        (0.5 + 77.14484006887480537268266j)

    Verifying that the values are zeros::

        >>> for n in range(1,5):
        ...     s = zetazero(n)
        ...     chop(zeta(s)), chop(siegelz(s.imag))
        ...
        (0.0, 0.0)
        (0.0, 0.0)
        (0.0, 0.0)
        (0.0, 0.0)

    Negative indices give the conjugate zeros (`n = 0` is undefined)::

        >>> zetazero(-1)
        (0.5 - 14.13472514173469379045725j)

    :func:`~mpmath.zetazero` supports arbitrarily large `n` and arbitrary precision::

        >>> mp.dps = 15
        >>> zetazero(1234567)
        (0.5 + 727690.906948208j)
        >>> mp.dps = 50
        >>> zetazero(1234567)
        (0.5 + 727690.9069482075392389420041147142092708393819935j)
        >>> chop(zeta(_)/_)
        0.0

    with *info=True*, :func:`~mpmath.zetazero` gives additional information::

        >>> mp.dps = 15
        >>> zetazero(542964976,info=True)
        ((0.5 + 209039046.578535j), [542964969, 542964978], 6, '(013111110)')

    This means that the zero is between Gram points 542964969 and 542964978;
    it is the 6-th zero between them. Finally (01311110) is the pattern
    of zeros in this interval. The numbers indicate the number of zeros
    in each Gram interval (Rosser blocks between parenthesis). In this case
    there is only one Rosser block of length nine.
    r   zn must be nonzero r   r`   rI   N)rY   zetazero	conjugate
ValueErrorrJ   comp_fp_tolerancer"   rq   rF   r6   rz   maxrT   rM   )r   r   inforound	wpinitialrP   r=   r   rw   r   r   r   rE   r   rJ   r   r   r    r    r!   r|   T  s:    <



r|   c                 C   s^   |dkrd|  |d }nd}| j}z,|  j|7  _t| || j }W || _n|| _0 |S )Nl     a$r+   r*   r   )rK   rJ   rY   siegelthetapi)r   r   r(   rJ   hr    r    r!   
gram_index  s    r   c                 C   s|   d}|d }|d }|d }d}||k rZ|| }	||	 dk rD|d7 }|	}|d7 }|| }q |  |}
|
| dk rx|d7 }|S rr   rH   )r   r   r   r   rs   rt   ZtoldZtnewr   ru   r   r    r    r!   count_to  s     

r   c                 C   s:   t || | }|dk r d}n|dkr.d}nd}||fS )Ni /hYgMb@?r&   g?rU   )r)   rK   )r   r   rP   r=   r    r    r!   r     s    r   c                 C   s8  |dk rdS t | |}t| |}| j}t| |\}}|| _| |}|dkr\|dk r\dS |dkrp|dkrpdS |d dk rt| |d }nt| |d |}|d \}	}
|
|	 dkr|d d }|| dkr|| _|d S || _|d S |\}}}}|
|	 }t| |||| j	|d\}}}t
| |||}|| _||	 d S )	a  
    Computes the number of zeros of the Riemann zeta function in
    `(0,1) \times (0,t]`, usually denoted by `N(t)`.

    **Examples**

    The first zero has imaginary part between 14 and 15::

        >>> from mpmath import *
        >>> mp.dps = 15; mp.pretty = True
        >>> nzeros(14)
        0
        >>> nzeros(15)
        1
        >>> zetazero(1)
        (0.5 + 14.1347251417347j)

    Some closely spaced zeros::

        >>> nzeros(10**7)
        21136125
        >>> zetazero(21136125)
        (0.5 + 9999999.32718175j)
        >>> zetazero(21136126)
        (0.5 + 10000000.2400236j)
        >>> nzeros(545439823.215)
        1500000001
        >>> zetazero(1500000001)
        (0.5 + 545439823.201985j)
        >>> zetazero(1500000002)
        (0.5 + 545439823.325697j)

    This confirms the data given by J. van de Lune,
    H. J. J. te Riele and D. T. Winter in 1986.
    g%fD,@r   r_   r   r   r{   r+   r`   )r   rY   floorrJ   r   r   r"   rq   rF   r6   r   )r   r   r.   r   r   rP   r=   r   ZRblockZn1Zn2r   r   rw   r   r   r   rE   r   r    r    r!   nzeros  sB    %

r   c                 C   s   |  |d | || j  S )aw  
    Computes the function
    `S(t) = \operatorname{arg} \zeta(\frac{1}{2} + it) / \pi`.

    See Titchmarsh Section 9.3 for details of the definition.

    **Examples**

        >>> from mpmath import *
        >>> mp.dps = 15; mp.pretty = True
        >>> backlunds(217.3)
        0.16302205431184

    Generally, the value is a small number. At Gram points it is an integer,
    frequently equal to 0::

        >>> chop(backlunds(grampoint(200)))
        0.0
        >>> backlunds(extraprec(10)(grampoint)(211))
        1.0
        >>> backlunds(extraprec(10)(grampoint)(232))
        -1.0

    The number of zeros of the Riemann zeta function up to height `t`
    satisfies `N(t) = \theta(t)/\pi + 1 + S(t)` (see :func:nzeros` and
    :func:`siegeltheta`)::

        >>> t = 1234.55
        >>> nzeros(t)
        842
        >>> siegeltheta(t)/pi+1+backlunds(t)
        842.0

    r   )r   r   r   )r   r   r    r    r!   	backlunds!  s    $r   i i z(00)3iaidiiz3(00)i=i=ioioiKiNi'i'iDiDi5i5i"i"i͜JiМJi+di.diOeiRei6٧i:٧z(00)40i(i(iR4yiU4yiýiýieieiii2 i5 i^RiaRi(i(iL=iO=iGi"Givi"viiiii	Ui	Ui_i_ieieihihi$.i'.i;i;iii~)i~)i<i
<i@i@iZDi]DipNisNibibi(i(iiivxiyxiiikini7/i:/i(7i(7ioEirEiOeIiReIipipi5i5iiiEŵiHŵi:i=i#i&i	i	i.	i1	i	iÁ	i&&	i)&	iĺ?	iǺ?	iϴB	iҴB	i_	i_	i_	i_	i&g	i&g	itqo	iwqo	i		i		ic	if	i=	i=	iv	iv	i	i	id	ig	iL
	iO
	i;
i;
i0
i0
iS'
iV'
i,
i,
i@
i@
i1T
i1T
i[
i[
i`
i`
i`c
i`c
if
if
i!y
i!y
iՊ
iՊ
i
i
i
i
iWC
iZC
i>h
iAh
i[b
i^b
i
i
z22(00)iǂ
iʂ
it4diw4dididififz(00)22iyiyiiiךiךi׬i׬isisiii
i
iZi]ititiii!i!i{i{i"i%iyiyi{i~iiiii=&i=&i|Ei|EiwLizLiYiYioYirYi]i]z3(010)i$`i'`ififiˁgi΁gib|ie|i`i`i3i6iii߀ii(>i+>iOiRiiiiÀiii
i
ie
ih
ijimi.Wi1Wi0`i3`i)T/i,T/i	SiSiXiXi]Yi`Yi<Ngi@Ngimimiii*i-iwiwi_ibi٤i٤iii=gi@gi#i#iii`~ic~ib
ie
i?iBi<i?i7(i7(z04(00)i//Ni2/Niz|Qi}|QiNciNcz(010)3i˾eiξeihihiDhiGhihʇikʇiiiiiiiiiliЦiЦiS;iV;i ii%i(iii-i0i'i*i55i55iZ7iZ7i"Mi"Mi`i`iSgiWgiti ti?iBiviviii"Ai%Aikiki#i&iiiii0i0i[i^iXi[iR%iR%iO'iR'iz7i}7iaI?idI?i!Wi$WiKYiNYihihi}li}lioqirqihrikriyiyiiiii(i(i$
i'
im(ip(i[i^iѓiԓiqxitxi@QiCQiSiSiCiFie,ih,iw)iz)iߥii8i;iiiiiiic!if!i'i'i(i(i:6i:6iJiJiOiOi]^i`^iqsitsiexihxi&|i)|i"i"ibibiiiiiAiDiiiaiaiiiii i i1!i1!iʺ*iκ*iP2iS2i.Ii.Ii;Mi;MiSiSididijnimniiiɭi̭iIiLiii !i!iڜiڜikiki*i*iiiiiiili'Di*Diii~ii)i,iFiIiK\iN\izB-i}B-i*Vi*VimimixixiPyiSyi׸iڸi$Îi'Îiĩiǩiϐiϐiiiiimipi5i5i%i%i>KiAKi{~i~~iViYiHiHiii*i*iiiii3i6iiiiiY#iY#i#i#i$i$iNgiQgidligliůiůipipi\i\i׊iڊiNiQiiiiiAiAi	.i.i2i2ipipiii i iii'*i**iZ35i^35i<7i<7i'=i*=iAiAiEiEiEiEiPUiPUi{Xi{Xi fifiiiniri1i1i @i@iii?i?iiiii*i-i$i$z04(010)i9i<i i iImiLmisisiІ4iԆ4iZ6i]6i;i;iBiBicici
vi
vidzidzi}i}i8i8i5i5ixi{iʯiʯiGSiJSiiiQNiTNipipiiizi~iii6i6i} i} iViVi/i/iMo%iPo%i*i*i-i-iA@iA@iNAiRAiGCiJCizXizXi'\i*\i\i\i'li'li1li4lifrifriTKxiWKxi|i|i꣗iiљiљiiiiiii2ji5jiۣii	]i]z032(00)i΄c,iӄc,z(010)40iӹ,iӹ,i9i9i%:i%:z(00)410iw;iw;it?it?z(00)230iqHivHi}Ji}JiQiQ)NN)FT)__doc__Z	functionsr   r   r"   r)   rF   rT   r]   r   r:   rq   r7   rz   r|   r   r   r   r   r   r   r    r    r    r!   <module>   s:  # 
F%
h
[

G
U   