
    "`;                        d Z ddlmZmZ ed        Zd Zed8d       Zed8d       Zed8d       Zed8d	       Z	ed8d
       Z
i ddgdgdgdgddfddgdgdgdgddfddgdgdgdgddfddgdgdgdgddfddgdgdgdgddfddgdgdgdgddfddgdgdgdgddfd ddgddgdgdgddfd!dgdgdgdgddfd"dgdgdgdgd#d$fd%dgdgdgdgddfd&ddgddgdgdgdd$fd'dd(dd)dd*dZed8d+       Zed9d,       Zd- Zd:d.Zd/ Zed0        Zed:d1       Zed;d2       Zed3        Zed4        Zed5        Zed6        Zed7        Zy)<aN  
Elliptic functions historically comprise the elliptic integrals
and their inverses, and originate from the problem of computing the
arc length of an ellipse. From a more modern point of view,
an elliptic function is defined as a doubly periodic function, i.e.
a function which satisfies

.. math ::

    f(z + 2 \omega_1) = f(z + 2 \omega_2) = f(z)

for some half-periods `\omega_1, \omega_2` with
`\mathrm{Im}[\omega_1 / \omega_2] > 0`. The canonical elliptic
functions are the Jacobi elliptic functions. More broadly, this section
includes  quasi-doubly periodic functions (such as the Jacobi theta
functions) and other functions useful in the study of elliptic functions.

Many different conventions for the arguments of
elliptic functions are in use. It is even standard to use
different parameterizations for different functions in the same
text or software (and mpmath is no exception).
The usual parameters are the elliptic nome `q`, which usually
must satisfy `|q| < 1`; the elliptic parameter `m` (an arbitrary
complex number); the elliptic modulus `k` (an arbitrary complex
number); and the half-period ratio `\tau`, which usually must
satisfy `\mathrm{Im}[\tau] > 0`.
These quantities can be expressed in terms of each other
using the following relations:

.. math ::

    m = k^2

.. math ::

    \tau = i \frac{K(1-m)}{K(m)}

.. math ::

    q = e^{i \pi \tau}

.. math ::

    k = \frac{\vartheta_2^2(q)}{\vartheta_3^2(q)}

In addition, an alternative definition is used for the nome in
number theory, which we here denote by q-bar:

.. math ::

    \bar{q} = q^2 = e^{2 i \pi \tau}

For convenience, mpmath provides functions to convert
between the various parameters (:func:`~mpmath.qfrom`, :func:`~mpmath.mfrom`,
:func:`~mpmath.kfrom`, :func:`~mpmath.taufrom`, :func:`~mpmath.qbarfrom`).

**References**

1. [AbramowitzStegun]_

2. [WhittakerWatson]_

   )defundefun_wrappedc                     | j                  |      dk  rt        d      | j                  |dz        }|| j                  |dz        z  S )aC  
    Returns the Dedekind eta function of tau in the upper half-plane.

        >>> from mpmath import *
        >>> mp.dps = 25; mp.pretty = True
        >>> eta(1j); gamma(0.25) / (2*pi**0.75)
        (0.7682254223260566590025942 + 0.0j)
        0.7682254223260566590025942
        >>> tau = sqrt(2) + sqrt(5)*1j
        >>> eta(-1/tau); sqrt(-1j*tau) * eta(tau)
        (0.9022859908439376463573294 + 0.07985093673948098408048575j)
        (0.9022859908439376463573295 + 0.07985093673948098408048575j)
        >>> eta(tau+1); exp(pi*1j/12) * eta(tau)
        (0.4493066139717553786223114 + 0.3290014793877986663915939j)
        (0.4493066139717553786223114 + 0.3290014793877986663915939j)
        >>> f = lambda z: diff(eta, z) / eta(z)
        >>> chop(36*diff(f,tau)**2 - 24*diff(f,tau,2)*f(tau) + diff(f,tau,3))
        0.0

    g        z+eta is only defined in the upper half-plane      )im
ValueErrorexpjpiqp)ctxtauqs      ;/usr/lib/python3/dist-packages/mpmath/functions/elliptic.pyetar   C   sI    , vvc{cFGG

3r6Asvvae}    c                    | j                  |      }|s|S || j                  k(  r|S | j                  |      r|S | j                  |      r1|| j                  k(  r t        |      d      S | j                  d      S | j                  | j                  |z
        }| j                  |      }| j                  | j                   |z  |z        }| j                  |      s@| j                  |      dk  r,| j                  |      r|j                  S |j                  dz   S |dk(  r| j                  d|j                        }|S )Nr   y                       )convertoneisnanisinfninftypempcellipkexppi_im_re_is_real_typerealimag)r   mabvs        r   nomer)   ^   s   AACGG|
yy|
yy|=472;772;

37719A

1A	!A771:#''!*q.Q66M66B;	
aGGAqvvHr   Nc                     || j                  |      S |t        | |      S |t        | | j                  |      dz        S || j                  |      S || j                  |      S y)a  
    Returns the elliptic nome `q`, given any of `q, m, k, \tau, \bar{q}`::

        >>> from mpmath import *
        >>> mp.dps = 25; mp.pretty = True
        >>> qfrom(q=0.25)
        0.25
        >>> qfrom(m=mfrom(q=0.25))
        0.25
        >>> qfrom(k=kfrom(q=0.25))
        0.25
        >>> qfrom(tau=taufrom(q=0.25))
        (0.25 + 0.0j)
        >>> qfrom(qbar=qbarfrom(q=0.25))
        0.25

    Nr   )r   r)   r
   sqrtr   r   r%   kr   qbars         r   qfromr/   w   ss    & 	}{{1~}C|}CQ*++
zz#xx~ r   c                     || j                  |      S || j                  |      dz  S |t        | |      dz  S |!t        | | j                  |      dz        dz  S || j                  d|z        S y)a  
    Returns the number-theoretic nome `\bar q`, given any of
    `q, m, k, \tau, \bar{q}`::

        >>> from mpmath import *
        >>> mp.dps = 25; mp.pretty = True
        >>> qbarfrom(qbar=0.25)
        0.25
        >>> qbarfrom(q=qfrom(qbar=0.25))
        0.25
        >>> qbarfrom(m=extraprec(20)(mfrom)(qbar=0.25))  # ill-conditioned
        0.25
        >>> qbarfrom(k=extraprec(20)(kfrom)(qbar=0.25))  # ill-conditioned
        0.25
        >>> qbarfrom(tau=taufrom(qbar=0.25))
        (0.25 + 0.0j)

    Nr   )r   r)   r
   r,   s         r   qbarfromr1      s    ( {{4  }{{1~""}C|q  }CQ*+q00
zz!C%   r   c                 *   || j                  |      S |D| j                  |      }| j                  | j                  d|z
        z  | j                  |      z  S |J| j                  |      }| j                  | j                  d|dz  z
        z  | j                  |dz        z  S |+| j                  |      | j                  | j                  z  z  S |?| j                  |      }| j                  |      d| j                  z  | j                  z  z  S y)a  
    Returns the elliptic half-period ratio `\tau`, given any of
    `q, m, k, \tau, \bar{q}`::

        >>> from mpmath import *
        >>> mp.dps = 25; mp.pretty = True
        >>> taufrom(tau=0.5j)
        (0.0 + 0.5j)
        >>> taufrom(q=qfrom(tau=0.5j))
        (0.0 + 0.5j)
        >>> taufrom(m=mfrom(tau=0.5j))
        (0.0 + 0.5j)
        >>> taufrom(k=kfrom(tau=0.5j))
        (0.0 + 0.5j)
        >>> taufrom(qbar=qbarfrom(tau=0.5j))
        (0.0 + 0.5j)

    Nr   r   )r   jr   logr   r,   s         r   taufromr5      s    ( {{3}KKNuuSZZ!_$SZZ]22}KKNuuSZZ!Q$''

1a4(888}wwqzSVVCEE\**{{4 wwt}#&&// r   c                 *   || j                  |      S || j                  |      S || j                  |      }|| j                  |      }|dk(  r|S |dk(  r| j                  dd      S | j	                  dd|      | j	                  dd|      z  dz  S )a  
    Returns the elliptic modulus `k`, given any of
    `q, m, k, \tau, \bar{q}`::

        >>> from mpmath import *
        >>> mp.dps = 25; mp.pretty = True
        >>> kfrom(k=0.25)
        0.25
        >>> kfrom(m=mfrom(k=0.25))
        0.25
        >>> kfrom(q=qfrom(k=0.25))
        0.25
        >>> kfrom(tau=taufrom(k=0.25))
        (0.25 + 0.0j)
        >>> kfrom(qbar=qbarfrom(k=0.25))
        0.25

    As `q \to 1` and `q \to -1`, `k` rapidly approaches
    `1` and `i \infty` respectively::

        >>> kfrom(q=0.75)
        0.9999999999999899166471767
        >>> kfrom(q=-0.75)
        (0.0 + 7041781.096692038332790615j)
        >>> kfrom(q=1)
        1
        >>> kfrom(q=-1)
        (0.0 + +infj)
    r   r   r   infr      )r   r+   r
   r   jthetar,   s         r   kfromr:      s    > 	}{{1~}xx{
JJsOHHTNAvBwwwqJJq1cjj1Q//!33r   c                 T   ||S ||dz  S || j                  |      }|| j                  |      }|dk(  r| j                  |      S |dk(  r|| j                  z  S | j	                  dd|      | j	                  dd|      z  dz  }| j                  |      r|dk  r|j                  }|S )a  
    Returns the elliptic parameter `m`, given any of
    `q, m, k, \tau, \bar{q}`::

        >>> from mpmath import *
        >>> mp.dps = 25; mp.pretty = True
        >>> mfrom(m=0.25)
        0.25
        >>> mfrom(q=qfrom(m=0.25))
        0.25
        >>> mfrom(k=kfrom(m=0.25))
        0.25
        >>> mfrom(tau=taufrom(m=0.25))
        (0.25 + 0.0j)
        >>> mfrom(qbar=qbarfrom(m=0.25))
        0.25

    As `q \to 1` and `q \to -1`, `m` rapidly approaches
    `1` and `-\infty` respectively::

        >>> mfrom(q=0.75)
        0.9999999999999798332943533
        >>> mfrom(q=-0.75)
        -49586681013729.32611558353
        >>> mfrom(q=1)
        1.0
        >>> mfrom(q=-1)
        -inf

    The inverse nome as a function of `q` has an integer
    Taylor series expansion::

        >>> taylor(lambda q: mfrom(q), 0, 7)
        [0.0, 16.0, -128.0, 704.0, -3072.0, 11488.0, -38400.0, 117632.0]

    r   r   r   r   r8      )r
   r+   r   r7   r9   r"   r#   )r   r   r%   r-   r   r.   r(   s          r   mfromr=     s    L 	}}!t
JJsOHHTNAv{{1~Bwy	Aa	3::a!,	,q0A
AFFHr   snr8   r   r<   sintanhcncossechdn1nscsccothncseccoshndsctansinhsdcdcscotcschdcdsccssnnddc                     	 t            }| fd}|_        |S  j                  }		  xj                  dz  c_         j                  |      } j                  ||||      }| j                  d|z  |z  z   }
n/| j                  k(  r6|d   dk(  r j                  }
n t         |d         |      }
|
d|z  |z  z  }
n| j                  k(  r6|d   dk(  r j                  }
n t         |d         |      }
|
d|z  |z  z  }
n| j                  d	d|      d
z  z  } j                  }
|d   D ]  }|
 j                  |d|      z  }
 |d   D ]  }|
 j                  |d|      z  }
 |d
   D ]  }|
 j                  |||      z  }
 |d	   D ]  }|
 j                  |||      z  }
 |	 _        |
S # t        $ r t        d      w xY w# |	 _        w xY w)NzYFirst argument must be a two-character string containing 's', 'c', 'd' or 'n', e.g.: 'sn'c                  0     j                   g| i |S N)ellipfun)argskwargsr   kinds     r   fzellipfun.<locals>.fU  s    3<<6t6v66r   
   )r%   r   r-   r   r   r<   rE      r8   r   r   )jacobi_specKeyErrorr	   __name__precr   r/   r   zerogetattrr9   )r   ra   ur%   r   r-   r   Srb   rh   r(   tr&   r'   cds   ``              r   r^   r^   M  s   ; 	y	7
88DBKKNIIQ!I-9!A#a%A#((]ts{A 2QqT 21 5A1QJA#''\ts{A 2QqT 21 5A1QJACJJq!Q'**AAqT31

1a 3313qT31

1a 3313qT31

1a 3313qT31

1a 33132IA  ; : ; 	;;> s   	F8 FG 8G	Gc                      | j                   dd|i|}| j                  dd|      }| j                  dd|      }| j                  dd|      }|dz  |dz  z   |dz  z   dz  }d||z  |z  dz  z  }||z  S )	a 
  
    Evaluates the Klein j-invariant, which is a modular function defined for
    `\tau` in the upper half-plane as

    .. math ::

        J(\tau) = \frac{g_2^3(\tau)}{g_2^3(\tau) - 27 g_3^2(\tau)}

    where `g_2` and `g_3` are the modular invariants of the Weierstrass
    elliptic function,

    .. math ::

        g_2(\tau) = 60 \sum_{(m,n) \in \mathbb{Z}^2 \setminus (0,0)} (m \tau+n)^{-4}

        g_3(\tau) = 140 \sum_{(m,n) \in \mathbb{Z}^2 \setminus (0,0)} (m \tau+n)^{-6}.

    An alternative, common notation is that of the j-function
    `j(\tau) = 1728 J(\tau)`.

    **Plots**

    .. literalinclude :: /plots/kleinj.py
    .. image :: /plots/kleinj.png
    .. literalinclude :: /plots/kleinj2.py
    .. image :: /plots/kleinj2.png

    **Examples**

    Verifying the functional equation `J(\tau) = J(\tau+1) = J(-\tau^{-1})`::

        >>> from mpmath import *
        >>> mp.dps = 25; mp.pretty = True
        >>> tau = 0.625+0.75*j
        >>> tau = 0.625+0.75*j
        >>> kleinj(tau)
        (-0.1507492166511182267125242 + 0.07595948379084571927228948j)
        >>> kleinj(tau+1)
        (-0.1507492166511182267125242 + 0.07595948379084571927228948j)
        >>> kleinj(-1/tau)
        (-0.1507492166511182267125242 + 0.07595948379084571927228946j)

    The j-function has a famous Laurent series expansion in terms of the nome
    `\bar{q}`, `j(\tau) = \bar{q}^{-1} + 744 + 196884\bar{q} + \ldots`::

        >>> mp.dps = 15
        >>> taylor(lambda q: 1728*q*kleinj(qbar=q), 0, 5, singular=True)
        [1.0, 744.0, 196884.0, 21493760.0, 864299970.0, 20245856256.0]

    The j-function admits exact evaluation at special algebraic points
    related to the Heegner numbers 1, 2, 3, 7, 11, 19, 43, 67, 163::

        >>> @extraprec(10)
        ... def h(n):
        ...     v = (1+sqrt(n)*j)
        ...     if n > 2:
        ...         v *= 0.5
        ...     return v
        ...
        >>> mp.dps = 25
        >>> for n in [1,2,3,7,11,19,43,67,163]:
        ...     n, chop(1728*kleinj(h(n)))
        ...
        (1, 1728.0)
        (2, 8000.0)
        (3, 0.0)
        (7, -3375.0)
        (11, -32768.0)
        (19, -884736.0)
        (43, -884736000.0)
        (67, -147197952000.0)
        (163, -262537412640768000.0)

    Also at other special points, the j-function assumes explicit
    algebraic values, e.g.::

        >>> chop(1728*kleinj(j*sqrt(5)))
        1264538.909475140509320227
        >>> identify(cbrt(_))      # note: not simplified
        '((100+sqrt(13520))/2)'
        >>> (50+26*sqrt(5))**3
        1264538.909475140509320227

    r   r   r   r8   r<      6    )r/   r9   )	r   r   r`   r   t2t3t4PQs	            r   kleinjry   s  s    l 			$c$V$A	Aa	B	Aa	B	Aa	B	QQQ	"A
BrE"Hq=AQ3Jr   c           	         ||k(  rt        | |||      S ||k(  rt        | |||      S ||k(  rt        | |||      S | j                  |      r"| j                  |      r| j                  |      sz| j                  |      s"| j                  |      s| j                  |      r||z  |z  S | j                  |      s"| j                  |      s| j                  |      r| j                  S |||}}}||z   |z   dz  x}}	| j                  d|z  d      t        t        ||z
        t        ||z
        t        ||z
              z  }
| j                  d      }| j                  }d}	 | j                  |      }| j                  |      }| j                  |      }||z  ||z  z   ||z  z   }|	|z   |z  }||z   |z  ||z   |z  ||z   |z  }}}||
z  t        |	      k  rn|}	|dz  }||z  }||	z  }||z
  |z  }||z
  |z  }| |z
  }||z  |dz  z
  }||z  |z  }| j                  |	d      dd	|z  z
  d
|dz  z  z   d|z  z   d|z  |z  z
  z  dz  S )Nr8         ?r   r   r         i$  i  i  i  iv  )RC_calcisnormalr   r   ri   rootmaxabsmpfr   r+   power)r   xyzrxmymzmA0Amrx   gpow4r%   xsyszslmAm1rm   XYZE2E3s                            r   RF_calcr     sk   Avgc1a++Avgc1a++Avgc1a++LLOQCLLO99Q<399Q<399Q<Q3q5L99Q<399Q<399Q<88O1"rBs1uaiB1bCBqD	#bd)C1I>>AA77D	A
XXb\XXb\XXb\URU]RU""uaieQYB	BrE19B!8c"g	Q	  	RA	AqA	AqA	
1A	
1QTB	
1QB99Rc"fSQY!6s2v!=c"fRi!GHMMr   c                    | j                  |      r| j                  |      sg| j                  |      s| j                  |      rd||z  z  S |dk(  r| j                  S |dk(  r!| j                  | j	                  |      z  dz  S t
        |rR| j                  |      dk(  r>| j                  |      dk  r*| j	                  |||z
  z        t        | ||z
  | |      z  S ||k(  rd| j	                  |      z  S dt        d| j                  ||z
         | j                  |      z         z  }| xj                  |z  c_        | j                  |      r| j                  |      r| j                  |      }| j                  |      }| j	                  ||z        }||k  r)| j	                  ||z
        }| j                  |      |z  }nz| j	                  ||z
        }| j                  |      |z  }nQ| j	                  |      }	| j	                  |      }
| j                  |	|
z        | j	                  d||z  z
        |
z  z  }| xj                  |z  c_        |S )Nr   r   r   )r   r   r7   r   r+   r	   r    r!   r~   r   magrh   r"   acosacosh)r   r   r   r   pv	extraprecr&   r'   r(   sxsys              r   r~   r~     s   LLOQ99Q<399Q<ac7N677N666CHHQK'!++	cggajAo#''!*q.xx1Q3 73!aR#;;;Av!}#a1cggaj011IHH	H
 1 1! 4GGAJGGAJHHQqSMq51AAA1A		!QAXXa[XXa[HHRUOSXXq1u.r12HH	HHr   c           
      4     j                        r3 j                        r" j                        r j                        s j                        s3 j                        s" j                        s j                        rz  z  S  j                        s3 j                        s" j                        s j                        r j                  S s j                  S   z    z   dkD  r j                  S  j                  }|dk\  rfj
                  dk\  xr1 j
                  dk\  xr  j
                  dk\  xr j
                  dkD  }|sk(  s
k(  sk(  rd}|sj                  dk7  sj
                  dk\  rj                  dk(  r%j
                  dk\  r j                        k(  rd}j                  dk(  r%j
                  dk\  r j                        k(  rd}j                  dk(  r%j
                  dk\  r j                        k(  rd}|r|dk(  rM j                  t        j
                  j
                  j
                  j
                               dz   }	t        d fD              r j                  }
nt        d fD              r j                   }
n]d}
fD ]C  }|j                  dk\  s|j
                  dkD  r"t        |
t        |j                        dz        }
E |
 j                  z  }
|	|
z  }	 fd}|dk(  r"d	 j                  |d|	 j                  g      z  S d	 j                  |d|	g      z  }|	z  |	z  |	z  |	z  f\  }}}}z   z   dz  z   d
z  x}}z
  z
  z  z
  z  } j                  d|z  d      t        t        |z
        t        |z
        t        |z
        t        |z
              z  }d} j!                  d      } j"                  }d}	  j%                  |      } j%                  |      } j%                  |      } j%                  |      }||z  ||z  z   ||z  z   }||z   |z  }||z   |z  }||z   |z  }||z   |z  }||z   |z  }||z   ||z   z  ||z   z  }| j'                  dd|z        z  |dz  z  } ||z  t        |      k  rn=t)          j"                   j"                  | z   |      |z  |z  }!||!z  }||z  }|dz  }|} j+                  dd|z        |z  }|z
  |z  }"|z
  |z  }#|z
  |z  }$|" |#z
  |$z
  dz  }%|"|#z  |"|$z  z   |#|$z  z   d|%dz  z  z
  }&|"|#z  |$z  d|&z  |%z  z   d|%dz  z  z   }'d|"z  |#z  |$z  |&|%z  z   d|%dz  z  z   |%z  }(|"|#z  |$z  |%dz  z  })dd|&z  z
  d|&dz  z  z   d|'z  z   d|&z  |'z  z
  d|(z  z
  d|)z  z   }%d}||z   j'                  |d      z  |%z  |z  }*d|z  }+||*z   |+z   S )a	  
    With integration == 0, computes RJ only using Carlson's algorithm
    (may be wrong for some values).
    With integration == 1, uses an initial integration to make sure
    Carlson's algorithm is correct.
    With integration == 2, uses only integration.
    r   r   Tr   c              3   \   K   | ]$  }|j                   d k\  xs |j                  d kD   & ywr   Nr$   r#   .0rm   s     r   	<genexpr>zRJ_calc.<locals>.<genexpr><  s(     E1AFFaK-166A:-E   *,c              3   \   K   | ]$  }|j                   d k  xs |j                  d kD   & ywr   r   r   s     r   r   zRJ_calc.<locals>.<genexpr>>  s(     FAaffqj.AFFQJ.Fr         ?c                     dj                  | z         j                  | z         z  j                  | z         z  | z   z  z  S )Nr   )r+   )rm   r   pr   r   r   s    r   <lambda>zRJ_calc.<locals>.<lambda>K  sC    !SXXac]388AaC=8!A#F!LM r   g      ?rd   r|   r{   r<   r8   i]  i  i	  i  i>  i  i
  g         )r   r   r   ri   r7   r#   r$   conjceilminallr3   r   quadr   r   r   r   r+   r   r~   ldexp),r   r   r   r   r   r   integrationinitial_integralokNmarginrm   Fr   r   r   pmr   r   deltarx   r%   r   r   rl   r   r   szspr   r   dmemTr   r   r   rw   r   r   E4E5v1v2s,   `````                                       r   RJ_calcr     sD    LLOQQCLLO99Q<399Q<399Q<399Q<Q3q5L99Q<399Q<399Q<399Q<88Owwa%E"Q&ww xxaffkHaffkHaffkHaffqjAva16vv{affkFFaKAFFaKCHHQK14DBFFaKAFFaKCHHQK14DBFFaKAFFaKCHHQK14DBkQ&#affaffaffaff==>BAEAq!EEF!Q1FF%% Q1 <Avv{affqj  QVVs):;F< #%%KAMAaSXXa!Q999"SXXa!Q%88FAAFAAFAAFAAa'KBr"R1uqy1Q3!!BqS1Q3K1Eas3r!t9SAYs2a4yRTKKA	AA77D	A
XXb\XXb\XXb\XXb\URU]RU""uaieQYbeQYbeQYbeQYe2"R%(SYYq"Q$''"a%/!8c"gC#''"*a047"<	Q		Q! " 			!BqDBA	AqA	AqA	AqA
Aa
A	
1qsQqS1QT6	!B	
1Q2a!AqD&	 B
A#a%'BqD.1QT6
!1	$B	
1Qq!tBR$r1u*$tBw.b;d2gEROAA	
A		"d#	#a	'	)B	
1Bb 2%%r   c                    | j                  |      }| j                  |      }| j                  |      }| j                  }	 | xj                  dz  c_        | j                  dz  }t        | ||||      }|| _        |S # || _        w xY w)a  
    Evaluates the Carlson symmetric elliptic integral of the first kind

    .. math ::

        R_F(x,y,z) = \frac{1}{2}
            \int_0^{\infty} \frac{dt}{\sqrt{(t+x)(t+y)(t+z)}}

    which is defined for `x,y,z \notin (-\infty,0)`, and with
    at most one of `x,y,z` being zero.

    For real `x,y,z \ge 0`, the principal square root is taken in the integrand.
    For complex `x,y,z`, the principal square root is taken as `t \to \infty`
    and as `t \to 0` non-principal branches are chosen as necessary so as to
    make the integrand continuous.

    **Examples**

    Some basic values and limits::

        >>> from mpmath import *
        >>> mp.dps = 25; mp.pretty = True
        >>> elliprf(0,1,1); pi/2
        1.570796326794896619231322
        1.570796326794896619231322
        >>> elliprf(0,1,inf)
        0.0
        >>> elliprf(1,1,1)
        1.0
        >>> elliprf(2,2,2)**2
        0.5
        >>> elliprf(1,0,0); elliprf(0,0,1); elliprf(0,1,0); elliprf(0,0,0)
        +inf
        +inf
        +inf
        +inf

    Representing complete elliptic integrals in terms of `R_F`::

        >>> m = mpf(0.75)
        >>> ellipk(m); elliprf(0,1-m,1)
        2.156515647499643235438675
        2.156515647499643235438675
        >>> ellipe(m); elliprf(0,1-m,1)-m*elliprd(0,1-m,1)/3
        1.211056027568459524803563
        1.211056027568459524803563

    Some symmetries and argument transformations::

        >>> x,y,z = 2,3,4
        >>> elliprf(x,y,z); elliprf(y,x,z); elliprf(z,y,x)
        0.5840828416771517066928492
        0.5840828416771517066928492
        0.5840828416771517066928492
        >>> k = mpf(100000)
        >>> elliprf(k*x,k*y,k*z); k**(-0.5) * elliprf(x,y,z)
        0.001847032121923321253219284
        0.001847032121923321253219284
        >>> l = sqrt(x*y) + sqrt(y*z) + sqrt(z*x)
        >>> elliprf(x,y,z); 2*elliprf(x+l,y+l,z+l)
        0.5840828416771517066928492
        0.5840828416771517066928492
        >>> elliprf((x+l)/4,(y+l)/4,(z+l)/4)
        0.5840828416771517066928492

    Comparing with numerical integration::

        >>> x,y,z = 2,3,4
        >>> elliprf(x,y,z)
        0.5840828416771517066928492
        >>> f = lambda t: 0.5*((t+x)*(t+y)*(t+z))**(-0.5)
        >>> q = extradps(25)(quad)
        >>> q(f, [0,inf])
        0.5840828416771517066928492

    With the following arguments, the square root in the integrand becomes
    discontinuous at `t = 1/2` if the principal branch is used. To obtain
    the right value, `-\sqrt{r}` must be taken instead of `\sqrt{r}`
    on `t \in (0, 1/2)`::

        >>> x,y,z = j-1,j,0
        >>> elliprf(x,y,z)
        (0.7961258658423391329305694 - 1.213856669836495986430094j)
        >>> -q(f, [0,0.5]) + q(f, [0.5,inf])
        (0.7961258658423391329305694 - 1.213856669836495986430094j)

    The so-called *first lemniscate constant*, a transcendental number::

        >>> elliprf(0,1,2)
        1.31102877714605990523242
        >>> extradps(25)(quad)(lambda t: 1/sqrt(1-t**4), [0,1])
        1.31102877714605990523242
        >>> gamma('1/4')**2/(4*sqrt(2*pi))
        1.31102877714605990523242

    **References**

    1. [Carlson]_
    2. [DLMF]_ Chapter 19. Elliptic Integrals

          )r   rh   epsr   )r   r   r   r   rh   tolr(   s          r   elliprfr   x  s    N 	AAAAAA88DBggoCAq#&2I s   3A> >	Bc                     | j                  |      }| j                  |      }| j                  }	 | xj                  dz  c_        | j                  dz  }t        | ||||      }|| _        |S # || _        w xY w)a  
    Evaluates the degenerate Carlson symmetric elliptic integral
    of the first kind

    .. math ::

        R_C(x,y) = R_F(x,y,y) =
            \frac{1}{2} \int_0^{\infty} \frac{dt}{(t+y) \sqrt{(t+x)}}.

    If `y \in (-\infty,0)`, either a value defined by continuity,
    or with *pv=True* the Cauchy principal value, can be computed.

    If `x \ge 0, y > 0`, the value can be expressed in terms of
    elementary functions as

    .. math ::

        R_C(x,y) =
        \begin{cases}
          \dfrac{1}{\sqrt{y-x}}
            \cos^{-1}\left(\sqrt{\dfrac{x}{y}}\right),   & x < y \\
          \dfrac{1}{\sqrt{y}},                          & x = y \\
          \dfrac{1}{\sqrt{x-y}}
            \cosh^{-1}\left(\sqrt{\dfrac{x}{y}}\right),  & x > y \\
        \end{cases}.

    **Examples**

    Some special values and limits::

        >>> from mpmath import *
        >>> mp.dps = 25; mp.pretty = True
        >>> elliprc(1,2)*4; elliprc(0,1)*2; +pi
        3.141592653589793238462643
        3.141592653589793238462643
        3.141592653589793238462643
        >>> elliprc(1,0)
        +inf
        >>> elliprc(5,5)**2
        0.2
        >>> elliprc(1,inf); elliprc(inf,1); elliprc(inf,inf)
        0.0
        0.0
        0.0

    Comparing with the elementary closed-form solution::

        >>> elliprc('1/3', '1/5'); sqrt(7.5)*acosh(sqrt('5/3'))
        2.041630778983498390751238
        2.041630778983498390751238
        >>> elliprc('1/5', '1/3'); sqrt(7.5)*acos(sqrt('3/5'))
        1.875180765206547065111085
        1.875180765206547065111085

    Comparing with numerical integration::

        >>> q = extradps(25)(quad)
        >>> elliprc(2, -3, pv=True)
        0.3333969101113672670749334
        >>> elliprc(2, -3, pv=False)
        (0.3333969101113672670749334 + 0.7024814731040726393156375j)
        >>> 0.5*q(lambda t: 1/(sqrt(t+2)*(t-3)), [0,3-j,6,inf])
        (0.3333969101113672670749334 + 0.7024814731040726393156375j)

    r   r   )r   rh   r   r~   )r   r   r   r   rh   r   r(   s          r   elliprcr     sr    F 	AAAA88DBggoCAsB'2I s   3A- -	A6c           	      :   | j                  |      }| j                  |      }| j                  |      }| j                  |      }| j                  }	 | xj                  dz  c_        | j                  dz  }t        | ||||||      }|| _        |S # || _        w xY w)a  
    Evaluates the Carlson symmetric elliptic integral of the third kind

    .. math ::

        R_J(x,y,z,p) = \frac{3}{2}
            \int_0^{\infty} \frac{dt}{(t+p)\sqrt{(t+x)(t+y)(t+z)}}.

    Like :func:`~mpmath.elliprf`, the branch of the square root in the integrand
    is defined so as to be continuous along the path of integration for
    complex values of the arguments.

    **Examples**

    Some values and limits::

        >>> from mpmath import *
        >>> mp.dps = 25; mp.pretty = True
        >>> elliprj(1,1,1,1)
        1.0
        >>> elliprj(2,2,2,2); 1/(2*sqrt(2))
        0.3535533905932737622004222
        0.3535533905932737622004222
        >>> elliprj(0,1,2,2)
        1.067937989667395702268688
        >>> 3*(2*gamma('5/4')**2-pi**2/gamma('1/4')**2)/(sqrt(2*pi))
        1.067937989667395702268688
        >>> elliprj(0,1,1,2); 3*pi*(2-sqrt(2))/4
        1.380226776765915172432054
        1.380226776765915172432054
        >>> elliprj(1,3,2,0); elliprj(0,1,1,0); elliprj(0,0,0,0)
        +inf
        +inf
        +inf
        >>> elliprj(1,inf,1,0); elliprj(1,1,1,inf)
        0.0
        0.0
        >>> chop(elliprj(1+j, 1-j, 1, 1))
        0.8505007163686739432927844

    Scale transformation::

        >>> x,y,z,p = 2,3,4,5
        >>> k = mpf(100000)
        >>> elliprj(k*x,k*y,k*z,k*p); k**(-1.5)*elliprj(x,y,z,p)
        4.521291677592745527851168e-9
        4.521291677592745527851168e-9

    Comparing with numerical integration::

        >>> elliprj(1,2,3,4)
        0.2398480997495677621758617
        >>> f = lambda t: 1/((t+4)*sqrt((t+1)*(t+2)*(t+3)))
        >>> 1.5*quad(f, [0,inf])
        0.2398480997495677621758617
        >>> elliprj(1,2+1j,3,4-2j)
        (0.216888906014633498739952 + 0.04081912627366673332369512j)
        >>> f = lambda t: 1/((t+4-2j)*sqrt((t+1)*(t+2+1j)*(t+3)))
        >>> 1.5*quad(f, [0,inf])
        (0.216888906014633498739952 + 0.04081912627366673332369511j)

    r   r   )r   rh   r   r   )	r   r   r   r   r   r   rh   r   r(   s	            r   elliprjr   9  s    @ 	AAAAAAAA88DBggoCAq!S+62I s   5B 	Bc                 *    | j                  ||||      S )a  
    Evaluates the degenerate Carlson symmetric elliptic integral
    of the third kind or Carlson elliptic integral of the
    second kind `R_D(x,y,z) = R_J(x,y,z,z)`.

    See :func:`~mpmath.elliprj` for additional information.

    **Examples**

        >>> from mpmath import *
        >>> mp.dps = 25; mp.pretty = True
        >>> elliprd(1,2,3)
        0.2904602810289906442326534
        >>> elliprj(1,2,3,3)
        0.2904602810289906442326534

    The so-called *second lemniscate constant*, a transcendental number::

        >>> elliprd(0,2,1)/3
        0.5990701173677961037199612
        >>> extradps(25)(quad)(lambda t: t**2/sqrt(1-t**4), [0,1])
        0.5990701173677961037199612
        >>> gamma('3/4')**2/sqrt(2*pi)
        0.5990701173677961037199612

    )r   )r   r   r   r   s       r   elliprdr     s    8 ;;q1Qr   c                 z     j                         j                         j                          z    z   }|dk(  rz   z   dz  S |dk(  r@rd j                        z  S rd j                        z  S d j                        z  S |dk(  rsc fd} j                  |      S )aa  
    Evaluates the Carlson completely symmetric elliptic integral
    of the second kind

    .. math ::

        R_G(x,y,z) = \frac{1}{4} \int_0^{\infty}
            \frac{t}{\sqrt{(t+x)(t+y)(t+z)}}
            \left( \frac{x}{t+x} + \frac{y}{t+y} + \frac{z}{t+z}\right) dt.

    **Examples**

    Evaluation for real and complex arguments::

        >>> from mpmath import *
        >>> mp.dps = 25; mp.pretty = True
        >>> elliprg(0,1,1)*4; +pi
        3.141592653589793238462643
        3.141592653589793238462643
        >>> elliprg(0,0.5,1)
        0.6753219405238377512600874
        >>> chop(elliprg(1+j, 1-j, 2))
        1.172431327676416604532822

    A double integral that can be evaluated in terms of `R_G`::

        >>> x,y,z = 2,3,4
        >>> def f(t,u):
        ...     st = fp.sin(t); ct = fp.cos(t)
        ...     su = fp.sin(u); cu = fp.cos(u)
        ...     return (x*(st*cu)**2 + y*(st*su)**2 + z*ct**2)**0.5 * st
        ...
        >>> nprint(mpf(fp.quad(f, [0,fp.pi], [0,2*fp.pi])/(4*fp.pi)), 13)
        1.725503028069
        >>> nprint(elliprg(x,y,z), 13)
        1.725503028069

    r8   r   r   r   r   c                      dz  j                        z  } dz
  z  z
  z  j                        z  dz  }dj                        z  j                        z  j                        z  }| ||fS )Nr   r}   r8   )r   r   r+   )T1T2T3r   r   r   r   s      r   termszelliprg.<locals>.terms  s    U3;;q1%%1Q3Z1ckk!Aa002!_SXXa[(!4"Rxr   )r   r+   sum_accurately)r   r   r   r   zerosr   s   ````  r   elliprgr     s    P 	AAAAAAU1uQ'Ez!AqyzS!_$S!_$388A;zaDAq
 e$$r   c                 |   |}| j                  |      r| j                  |      s=|dk(  r||z   S |dk(  r||z  S || j                  k(  s|| j                  k(  r||z  S t        |j                  }| xj
                  t        d| j                  |            z  c_        | j                  }t        |      |dz  kD  }|dk(  r|r| j                  S |r4| j                  ||z        }|||z  z
  }d|z  | j                  |      z  }nd}| j                  |      \  }	}
|
| j                  |	dz  d||
dz  z  z
  d      z  |z   S )aB
  
    Evaluates the Legendre incomplete elliptic integral of the first kind

     .. math ::

        F(\phi,m) = \int_0^{\phi} \frac{dt}{\sqrt{1-m \sin^2 t}}

    or equivalently

    .. math ::

        F(\phi,m) = \int_0^{\sin \phi}
        \frac{dt}{\left(\sqrt{1-t^2}\right)\left(\sqrt{1-mt^2}\right)}.

    The function reduces to a complete elliptic integral of the first kind
    (see :func:`~mpmath.ellipk`) when `\phi = \frac{\pi}{2}`; that is,

    .. math ::

        F\left(\frac{\pi}{2}, m\right) = K(m).

    In the defining integral, it is assumed that the principal branch
    of the square root is taken and that the path of integration avoids
    crossing any branch cuts. Outside `-\pi/2 \le \Re(\phi) \le \pi/2`,
    the function extends quasi-periodically as

    .. math ::

        F(\phi + n \pi, m) = 2 n K(m) + F(\phi,m), n \in \mathbb{Z}.

    **Plots**

    .. literalinclude :: /plots/ellipf.py
    .. image :: /plots/ellipf.png

    **Examples**

    Basic values and limits::

        >>> from mpmath import *
        >>> mp.dps = 25; mp.pretty = True
        >>> ellipf(0,1)
        0.0
        >>> ellipf(0,0)
        0.0
        >>> ellipf(1,0); ellipf(2+3j,0)
        1.0
        (2.0 + 3.0j)
        >>> ellipf(1,1); log(sec(1)+tan(1))
        1.226191170883517070813061
        1.226191170883517070813061
        >>> ellipf(pi/2, -0.5); ellipk(-0.5)
        1.415737208425956198892166
        1.415737208425956198892166
        >>> ellipf(pi/2+eps, 1); ellipf(-pi/2-eps, 1)
        +inf
        +inf
        >>> ellipf(1.5, 1)
        3.340677542798311003320813

    Comparing with numerical integration::

        >>> z,m = 0.5, 1.25
        >>> ellipf(z,m)
        0.5287219202206327872978255
        >>> quad(lambda t: (1-m*sin(t)**2)**(-0.5), [0,z])
        0.5287219202206327872978255

    The arguments may be complex numbers::

        >>> ellipf(3j, 0.5)
        (0.0 + 1.713602407841590234804143j)
        >>> ellipf(3+4j, 5-6j)
        (1.269131241950351323305741 - 0.3561052815014558335412538j)
        >>> z,m = 2+3j, 1.25
        >>> k = 1011
        >>> ellipf(z+pi*k,m); ellipf(z,m) + 2*k*ellipk(m)
        (4086.184383622179764082821 - 3003.003538923749396546871j)
        (4086.184383622179764082821 - 3003.003538923749396546871j)

    For `|\Re(z)| < \pi/2`, the function can be expressed as a
    hypergeometric series of two variables
    (see :func:`~mpmath.appellf1`)::

        >>> z,m = 0.5, 0.25
        >>> ellipf(z,m)
        0.5050887275786480788831083
        >>> sin(z)*appellf1(0.5,0.5,0.5,1.5,sin(z)**2,m*sin(z)**2)
        0.5050887275786480788831083

    r   r   r   )r   r7   r   r	   r#   rh   r   r   r   r   nintr   cos_sinr   )r   phir%   r   r   r   awayro   rw   rn   ss              r   ellipfr     s1   z 	ALLOQ6q5L6q5L<1=1*	AHHAswwqz""H
&&Bq6BqD=DAv77NHHQrTNbdFaC

1;;q>DAqs{{1a41QT61--11r   c                 |   	
 t        |      dk(  r j                  |d         S |\  }	|
 j                  
      r j                  	      sD	dk(  r
	z   S 
dk(  r
	z  S 	 j                  k(  s	 j                  k(  r j                  S t
        
j                  } xj                  t        d j                  |            z  c_         j                  }t        |      |dz  kD  }|r4 j                  ||z        }
||z  z
  
d|z   j                  	      z  }nd} 	
fd} j                  |      |z   S )aP  
    Called with a single argument `m`, evaluates the Legendre complete
    elliptic integral of the second kind, `E(m)`, defined by

        .. math :: E(m) = \int_0^{\pi/2} \sqrt{1-m \sin^2 t} \, dt \,=\,
            \frac{\pi}{2}
            \,_2F_1\left(\frac{1}{2}, -\frac{1}{2}, 1, m\right).

    Called with two arguments `\phi, m`, evaluates the incomplete elliptic
    integral of the second kind

     .. math ::

        E(\phi,m) = \int_0^{\phi} \sqrt{1-m \sin^2 t} \, dt =
                    \int_0^{\sin z}
                    \frac{\sqrt{1-mt^2}}{\sqrt{1-t^2}} \, dt.

    The incomplete integral reduces to a complete integral when
    `\phi = \frac{\pi}{2}`; that is,

    .. math ::

        E\left(\frac{\pi}{2}, m\right) = E(m).

    In the defining integral, it is assumed that the principal branch
    of the square root is taken and that the path of integration avoids
    crossing any branch cuts. Outside `-\pi/2 \le \Re(z) \le \pi/2`,
    the function extends quasi-periodically as

    .. math ::

        E(\phi + n \pi, m) = 2 n E(m) + E(\phi,m), n \in \mathbb{Z}.

    **Plots**

    .. literalinclude :: /plots/ellipe.py
    .. image :: /plots/ellipe.png

    **Examples for the complete integral**

    Basic values and limits::

        >>> from mpmath import *
        >>> mp.dps = 25; mp.pretty = True
        >>> ellipe(0)
        1.570796326794896619231322
        >>> ellipe(1)
        1.0
        >>> ellipe(-1)
        1.910098894513856008952381
        >>> ellipe(2)
        (0.5990701173677961037199612 + 0.5990701173677961037199612j)
        >>> ellipe(inf)
        (0.0 + +infj)
        >>> ellipe(-inf)
        +inf

    Verifying the defining integral and hypergeometric
    representation::

        >>> ellipe(0.5)
        1.350643881047675502520175
        >>> quad(lambda t: sqrt(1-0.5*sin(t)**2), [0, pi/2])
        1.350643881047675502520175
        >>> pi/2*hyp2f1(0.5,-0.5,1,0.5)
        1.350643881047675502520175

    Evaluation is supported for arbitrary complex `m`::

        >>> ellipe(0.5+0.25j)
        (1.360868682163129682716687 - 0.1238733442561786843557315j)
        >>> ellipe(3+4j)
        (1.499553520933346954333612 - 1.577879007912758274533309j)

    A definite integral::

        >>> quad(ellipe, [0,1])
        1.333333333333333333333333

    **Examples for the incomplete integral**

    Basic values and limits::

        >>> ellipe(0,1)
        0.0
        >>> ellipe(0,0)
        0.0
        >>> ellipe(1,0)
        1.0
        >>> ellipe(2+3j,0)
        (2.0 + 3.0j)
        >>> ellipe(1,1); sin(1)
        0.8414709848078965066525023
        0.8414709848078965066525023
        >>> ellipe(pi/2, -0.5); ellipe(-0.5)
        1.751771275694817862026502
        1.751771275694817862026502
        >>> ellipe(pi/2, 1); ellipe(-pi/2, 1)
        1.0
        -1.0
        >>> ellipe(1.5, 1)
        0.9974949866040544309417234

    Comparing with numerical integration::

        >>> z,m = 0.5, 1.25
        >>> ellipe(z,m)
        0.4740152182652628394264449
        >>> quad(lambda t: sqrt(1-m*sin(t)**2), [0,z])
        0.4740152182652628394264449

    The arguments may be complex numbers::

        >>> ellipe(3j, 0.5)
        (0.0 + 7.551991234890371873502105j)
        >>> ellipe(3+4j, 5-6j)
        (24.15299022574220502424466 + 75.2503670480325997418156j)
        >>> k = 35
        >>> z,m = 2+3j, 1.25
        >>> ellipe(z+pi*k,m); ellipe(z,m) + 2*k*ellipe(m)
        (48.30138799412005235090766 + 17.47255216721987688224357j)
        (48.30138799412005235090766 + 17.47255216721987688224357j)

    For `|\Re(z)| < \pi/2`, the function can be expressed as a
    hypergeometric series of two variables
    (see :func:`~mpmath.appellf1`)::

        >>> z,m = 0.5, 0.25
        >>> ellipe(z,m)
        0.4950017030164151928870375
        >>> sin(z)*appellf1(0.5,0.5,-0.5,1.5,sin(z)**2,m*sin(z)**2)
        0.4950017030164151928870376

    r   r   r   c                      j                        \  } }| dz  }d|dz  z  z
  }j                  ||d      }j                  ||d      }||z   |dz  z  |z  dz  fS Nr   r   r8   )r   r   r   )	rn   r   r   r   RFRDr   r%   r   s	         r   r   zellipe.<locals>.terms  ss    {{1~1qDa1fH[[Aq![[Aq!taR1WRZ\!!r   )len_elliper   r7   r   r	   r#   rh   r   r   r   r   r   elliper   )r   r_   r   r   r   r   ro   rw   r   r%   r   s   `        @@r   r   r   V  s&   P 4yA~{{47##QALLOQ6q5L6q5L<1=77N	AHHAswwqz""H
&&Bq6BqD=DHHQrTNbdFaC

1" e$q((r   c                 J   	
 t        |      dk(  r|\  
d	 j                  dz  x}n
|\  }
d	| j                        r# j                        r j                  
      s3 j                        s" j                        s j                  
      rt        	r~
dk(  r5dk(  r j
                  S  j                  d j                  dz
        z  z  S dk(  r j                  
      S  j                        s j                  
      rM j                  S dk(  rS  j                        r j                  S  j                  
      r j                  S  j                        s" j                        s j                  
      rt        	r;
dk(  r3dk(  r j
                  S  j
                    j                  dz
        z  S d}nXj                  } xj                  t        d j                  |            z  c_         j                  }t        |      |dz  kD  }|rQ j!                  z        }||z  z
  d|z   j#                  
      z  } j                  |      r j
                  S d}	 
fd} j%                  |      |z   S )a  
    Called with three arguments `n, \phi, m`, evaluates the Legendre
    incomplete elliptic integral of the third kind

    .. math ::

        \Pi(n; \phi, m) = \int_0^{\phi}
            \frac{dt}{(1-n \sin^2 t) \sqrt{1-m \sin^2 t}} =
            \int_0^{\sin \phi}
            \frac{dt}{(1-nt^2) \sqrt{1-t^2} \sqrt{1-mt^2}}.

    Called with two arguments `n, m`, evaluates the complete
    elliptic integral of the third kind
    `\Pi(n,m) = \Pi(n; \frac{\pi}{2},m)`.

    In the defining integral, it is assumed that the principal branch
    of the square root is taken and that the path of integration avoids
    crossing any branch cuts. Outside `-\pi/2 \le \Re(\phi) \le \pi/2`,
    the function extends quasi-periodically as

    .. math ::

        \Pi(n,\phi+k\pi,m) = 2k\Pi(n,m) + \Pi(n,\phi,m), k \in \mathbb{Z}.

    **Plots**

    .. literalinclude :: /plots/ellippi.py
    .. image :: /plots/ellippi.png

    **Examples for the complete integral**

    Some basic values and limits::

        >>> from mpmath import *
        >>> mp.dps = 25; mp.pretty = True
        >>> ellippi(0,-5); ellipk(-5)
        0.9555039270640439337379334
        0.9555039270640439337379334
        >>> ellippi(inf,2)
        0.0
        >>> ellippi(2,inf)
        0.0
        >>> abs(ellippi(1,5))
        +inf
        >>> abs(ellippi(0.25,1))
        +inf

    Evaluation in terms of simpler functions::

        >>> ellippi(0.25,0.25); ellipe(0.25)/(1-0.25)
        1.956616279119236207279727
        1.956616279119236207279727
        >>> ellippi(3,0); pi/(2*sqrt(-2))
        (0.0 - 1.11072073453959156175397j)
        (0.0 - 1.11072073453959156175397j)
        >>> ellippi(-3,0); pi/(2*sqrt(4))
        0.7853981633974483096156609
        0.7853981633974483096156609

    **Examples for the incomplete integral**

    Basic values and limits::

        >>> ellippi(0.25,-0.5); ellippi(0.25,pi/2,-0.5)
        1.622944760954741603710555
        1.622944760954741603710555
        >>> ellippi(1,0,1)
        0.0
        >>> ellippi(inf,0,1)
        0.0
        >>> ellippi(0,0.25,0.5); ellipf(0.25,0.5)
        0.2513040086544925794134591
        0.2513040086544925794134591
        >>> ellippi(1,1,1); (log(sec(1)+tan(1))+sec(1)*tan(1))/2
        2.054332933256248668692452
        2.054332933256248668692452
        >>> ellippi(0.25, 53*pi/2, 0.75); 53*ellippi(0.25,0.75)
        135.240868757890840755058
        135.240868757890840755058
        >>> ellippi(0.5,pi/4,0.5); 2*ellipe(pi/4,0.5)-1/sqrt(3)
        0.9190227391656969903987269
        0.9190227391656969903987269

    Complex arguments are supported::

        >>> ellippi(0.5, 5+6j-2*pi, -7-8j)
        (-0.3612856620076747660410167 + 0.5217735339984807829755815j)

    Some degenerate cases::

        >>> ellippi(1,1)
        +inf
        >>> ellippi(1,0)
        +inf
        >>> ellippi(1,2,0)
        +inf
        >>> ellippi(1,2,1)
        +inf
        >>> ellippi(1,0,1)
        0.0

    r   TFr   r   c            	         rj                   j                  }} nj                  
      \  } }| dz  }d|dz  z  z
  }j                  ||d      }j	                  ||dd	|dz  z  z
        }||z  	|dz  z  |z  dz  fS r   )ri   r   r   r   r   )rn   r   r   r   r   RJcompleter   r%   nr   s         r   r   zellippi.<locals>.terms  s    88SWWqA;;q>DAqqDa1fH[[Aq![[Aq!AadF(+tQq!tVBYq[  r   )r   r   r   r   r	   r7   r+   r   r   ri   signr#   rh   r   r   r   r   ellippir   )r   r_   r   r   r   r   ro   rw   r   r   r%   r   r   s   `        @@@@r   r   r     s=   P 4yA~1&&(C	3LLOQCLLO99Q<399Q<399Q<Av677Nvvq!A#//Avcjjm+yy|syy|CHH_Avaxyy|CHH_yy|CHH_99Q<399Q<399Q<6AvwwGG8CHHQqSM))FFC3771:&&ffW1v1}HHQrTNbdFaCAa  99Q<77N	! 	! e$q((r   )NNNNNr]   )T)r   )__doc__	functionsr   r   r   r)   r/   r1   r5   r:   r=   re   r^   ry   r   r~   r   r   r   r   r   r   r   r   r   rs   r   r   <module>r      sG  >@ , 42  : ! !< 0 0B *4 *4X 4 4l1#qc1#qc5&	)1#qc1#qc5&	) 1#qc1#qc3	' 1#qc1#qc5&	)	
 1#qc1#qc5&	) 1#qc1#qc3	' 1#qc1#qc5&	) 1Q%1qc1#uf	- 1#qc1#qc5#	& 1#qc1#qc5&	) 1#qc1#qc5#	& 1Q%1qc1#uf	-     !& # #J [ [|!NFB`&D p pd K KZ J JX    : 9% 9%x r2 r2h e) e)N \) \)r   