ó
¡¼™\c           @  s  d  Z  d d l m Z m Z d d l m Z m Z m Z d d l m	 Z	 m
 Z
 d d l m Z d d l m Z d d l m Z d d l m Z m Z d d	 l m Z d d
 l m Z m Z d e	 f d „  ƒ  YZ d e	 f d „  ƒ  YZ d e	 f d „  ƒ  YZ d e	 f d „  ƒ  YZ d S(   s    Elliptic integrals. iÿÿÿÿ(   t   print_functiont   division(   t   St   pit   I(   t   Functiont   ArgumentIndexError(   t   sign(   t   atanh(   t   sqrt(   t   sint   tan(   t   gamma(   t   hypert   meijergt
   elliptic_kc           B  sV   e  Z d  Z e d „  ƒ Z d d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   s0  
    The complete elliptic integral of the first kind, defined by

    .. math:: K(m) = F\left(\tfrac{\pi}{2}\middle| m\right)

    where `F\left(z\middle| m\right)` is the Legendre incomplete
    elliptic integral of the first kind.

    The function `K(m)` is a single-valued function on the complex
    plane with branch cut along the interval `(1, \infty)`.

    Note that our notation defines the incomplete elliptic integral
    in terms of the parameter `m` instead of the elliptic modulus
    (eccentricity) `k`.
    In this case, the parameter `m` is defined as `m=k^2`.

    Examples
    ========

    >>> from sympy import elliptic_k, I, pi
    >>> from sympy.abc import m
    >>> elliptic_k(0)
    pi/2
    >>> elliptic_k(1.0 + I)
    1.50923695405127 + 0.625146415202697*I
    >>> elliptic_k(m).series(n=3)
    pi/2 + pi*m/8 + 9*pi*m**2/128 + O(m**3)

    See Also
    ========

    elliptic_f

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Elliptic_integrals
    .. [2] http://functions.wolfram.com/EllipticIntegrals/EllipticK

    c         C  sá   | t  j k r t d S| t  j k rU d t t  d ƒ d t t  d ƒ d ƒ d S| t  j k rk t  j S| t  j k r¤ t t  d ƒ d ƒ d d t d t ƒ S| t  j	 t  j
 t t  j	 t t  j
 t  j f k rÝ t  j Sd  S(   Ni   i   i   i   i   (   R   t   ZeroR   t   HalfR   t   Onet   ComplexInfinityt   NegativeOneR	   t   Infinityt   NegativeInfinityR   (   t   clst   m(    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyt   eval8   s    /*i   c         C  s9   |  j  d } t | ƒ d | t | ƒ d | d | S(   Ni    i   i   (   t   argst
   elliptic_eR   (   t   selft   argindexR   (    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyt   fdiffF   s    c         C  s@   |  j  d } | j o  | d j t k r< |  j | j ƒ  ƒ Sd  S(   Ni    i   (   R   t   is_realt   is_positivet   Falset   funct	   conjugate(   R   R   (    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyt   _eval_conjugateJ   s    c         C  s8   d d l  m } | |  j t ƒ j | d | d | ƒƒ S(   Niÿÿÿÿ(   t   hyperexpandt   nt   logx(   t   sympy.simplifyR%   t   rewriteR   t   _eval_nseries(   R   t   xR&   R'   R%   (    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyR*   O   s    c         K  s*   t  d t t j t j f t j f | ƒ S(   Ni   (   R   R   R   R   R   (   R   R   t   kwargs(    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyt   _eval_rewrite_as_hyperS   s    c         K  s9   t  t j t j f g  f t j f t j f f | ƒ d S(   Ni   (   R   R   R   R   (   R   R   R,   (    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyt   _eval_rewrite_as_meijergV   s    c         C  s)   d d  l  j } | j |  j d j ƒ  ƒ S(   Niÿÿÿÿi    (   t   sage.allt   allt   elliptic_kcR   t   _sage_(   R   t   sage(    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyR2   Y   s    (   t   __name__t
   __module__t   __doc__t   classmethodR   R   R$   R*   R-   R.   R2   (    (    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyR      s   (				t
   elliptic_fc           B  s2   e  Z d  Z e d „  ƒ Z d d „ Z d „  Z RS(   sÛ  
    The Legendre incomplete elliptic integral of the first
    kind, defined by

    .. math:: F\left(z\middle| m\right) =
              \int_0^z \frac{dt}{\sqrt{1 - m \sin^2 t}}

    This function reduces to a complete elliptic integral of
    the first kind, `K(m)`, when `z = \pi/2`.

    Note that our notation defines the incomplete elliptic integral
    in terms of the parameter `m` instead of the elliptic modulus
    (eccentricity) `k`.
    In this case, the parameter `m` is defined as `m=k^2`.

    Examples
    ========

    >>> from sympy import elliptic_f, I, O
    >>> from sympy.abc import z, m
    >>> elliptic_f(z, m).series(z)
    z + z**5*(3*m**2/40 - m/30) + m*z**3/6 + O(z**6)
    >>> elliptic_f(3.0 + I/2, 1.0 + I)
    2.909449841483 + 1.74720545502474*I

    See Also
    ========

    elliptic_k

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Elliptic_integrals
    .. [2] http://functions.wolfram.com/EllipticIntegrals/EllipticF

    c         C  s€   d | t  } | j r | S| j r+ t j S| j rB | t | ƒ S| t j t j f k ra t j S| j ƒ  r| t	 | | ƒ Sd  S(   Ni   (
   R   t   is_zeroR   R   t
   is_integerR   R   R   t   could_extract_minus_signR8   (   R   t   zR   t   k(    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyR   …   s    			i   c         C  s°   |  j  \ } } t d | t | ƒ d ƒ } | d k rA d | S| d k r t | | ƒ d | d | t | | ƒ d | t d | ƒ d d | | St |  | ƒ ‚ d  S(   Ni   i   i   (   R   R	   R
   R   R8   R   (   R   R   R<   R   t   fm(    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyR   “   s    1c         C  sK   |  j  \ } } | j o" | d j t k rG |  j | j ƒ  | j ƒ  ƒ Sd  S(   Ni   (   R   R   R    R!   R"   R#   (   R   R<   R   (    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyR$      s    (   R4   R5   R6   R7   R   R   R$   (    (    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyR8   ^   s   %
R   c           B  sP   e  Z d  Z e d d „ ƒ Z d d „ Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   s”  
    Called with two arguments `z` and `m`, evaluates the
    incomplete elliptic integral of the second kind, defined by

    .. math:: E\left(z\middle| m\right) = \int_0^z \sqrt{1 - m \sin^2 t} dt

    Called with a single argument `m`, evaluates the Legendre complete
    elliptic integral of the second kind

    .. math:: E(m) = E\left(\tfrac{\pi}{2}\middle| m\right)

    The function `E(m)` is a single-valued function on the complex
    plane with branch cut along the interval `(1, \infty)`.

    Note that our notation defines the incomplete elliptic integral
    in terms of the parameter `m` instead of the elliptic modulus
    (eccentricity) `k`.
    In this case, the parameter `m` is defined as `m=k^2`.

    Examples
    ========

    >>> from sympy import elliptic_e, I, pi, O
    >>> from sympy.abc import z, m
    >>> elliptic_e(z, m).series(z)
    z + z**5*(-m**2/40 + m/30) - m*z**3/6 + O(z**6)
    >>> elliptic_e(m).series(n=4)
    pi/2 - pi*m/8 - 3*pi*m**2/128 - 5*pi*m**3/512 + O(m**4)
    >>> elliptic_e(1 + I, 2 - I/2).n()
    1.55203744279187 + 0.290764986058437*I
    >>> elliptic_e(0)
    pi/2
    >>> elliptic_e(2.0 - I)
    0.991052601328069 + 0.81879421395609*I

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Elliptic_integrals
    .. [2] http://functions.wolfram.com/EllipticIntegrals/EllipticE2
    .. [3] http://functions.wolfram.com/EllipticIntegrals/EllipticE

    c         C  s	  | d  k	 r˜ | | } } d | t } | j r4 | S| j rD t j S| j r[ | t | ƒ S| t j t j f k rz t j	 S| j
 ƒ  rt | | ƒ Snm | j r© t d S| t j k r¿ t j S| t j k rÙ t t j S| t j k rï t j S| t j	 k rt j	 Sd  S(   Ni   (   t   NoneR   R9   R   R   R:   R   R   R   R   R;   R   R   (   R   R   R<   R=   (    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyR   Ð   s.    				i   c         C  sÅ   t  |  j ƒ d k r} |  j \ } } | d k rL t d | t | ƒ d ƒ S| d k r² t | | ƒ t | | ƒ d | Sn5 |  j d } | d k r² t | ƒ t | ƒ d | St |  | ƒ ‚ d  S(   Ni   i   i    (   t   lenR   R	   R
   R   R8   R   R   (   R   R   R<   R   (    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyR   ë   s    %c         C  sŸ   t  |  j ƒ d k r_ |  j \ } } | j o7 | d j t k r› |  j | j ƒ  | j ƒ  ƒ Sn< |  j d } | j o | d j t k r› |  j | j ƒ  ƒ Sd  S(   Ni   i   i    (   R@   R   R   R    R!   R"   R#   (   R   R<   R   (    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyR$   ø   s    c         C  so   d d l  m } t |  j ƒ d k rM | |  j t ƒ j | d | d | ƒƒ St t |  ƒ j | d | d | ƒS(   Niÿÿÿÿ(   R%   i   R&   R'   (	   R(   R%   R@   R   R)   R   R*   t   superR   (   R   R+   R&   R'   R%   (    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyR*     s    (c         O  sK   t  | ƒ d k rG | d } t d t t j t j f t j f | ƒ Sd  S(   Ni   i    i   (   R@   R   R   R   R   R   (   R   R   R,   R   (    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyR-     s    
c         O  sa   t  | ƒ d k r] | d } t t j t d ƒ d f g  f t j f t j f f | ƒ d Sd  S(   Ni   i    i   i   i   (   R@   R   R   R   R   (   R   R   R,   R   (    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyR.     s    
N(   R4   R5   R6   R7   R?   R   R   R$   R*   R-   R.   (    (    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyR   £   s   +	
		t   elliptic_pic           B  s5   e  Z d  Z e d d „ ƒ Z d „  Z d d „ Z RS(   s6  
    Called with three arguments `n`, `z` and `m`, evaluates the
    Legendre incomplete elliptic integral of the third kind, defined by

    .. math:: \Pi\left(n; z\middle| m\right) = \int_0^z \frac{dt}
              {\left(1 - n \sin^2 t\right) \sqrt{1 - m \sin^2 t}}

    Called with two arguments `n` and `m`, evaluates the complete
    elliptic integral of the third kind:

    .. math:: \Pi\left(n\middle| m\right) =
              \Pi\left(n; \tfrac{\pi}{2}\middle| m\right)

    Note that our notation defines the incomplete elliptic integral
    in terms of the parameter `m` instead of the elliptic modulus
    (eccentricity) `k`.
    In this case, the parameter `m` is defined as `m=k^2`.

    Examples
    ========

    >>> from sympy import elliptic_pi, I, pi, O, S
    >>> from sympy.abc import z, n, m
    >>> elliptic_pi(n, z, m).series(z, n=4)
    z + z**3*(m/6 + n/3) + O(z**4)
    >>> elliptic_pi(0.5 + I, 1.0 - I, 1.2)
    2.50232379629182 - 0.760939574180767*I
    >>> elliptic_pi(0, 0)
    pi/2
    >>> elliptic_pi(1.0 - I/3, 2.0 + I)
    3.29136443417283 + 0.32555634906645*I

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Elliptic_integrals
    .. [2] http://functions.wolfram.com/EllipticIntegrals/EllipticPi3
    .. [3] http://functions.wolfram.com/EllipticIntegrals/EllipticPi

    c         C  s}  | d  k	 r¤| | | } } } d | t } | t j k rJ t | | ƒ S| t j k r¡ t | | ƒ t d | t | ƒ d ƒ t | ƒ t	 | | ƒ d | S| j
 r» | t | | ƒ S| t j k rö t t | d ƒ t | ƒ ƒ t | d ƒ S| | k rEt | | ƒ t d | | ƒ t | ƒ t d | t | ƒ d ƒ S| t j t j f k rdt j S| t j t j f k rƒt j S| j ƒ  ryt | | | ƒ SnÕ | t j k r½t | ƒ S| t j k rÓt j S| t j k røt d t d | ƒ S| t j k rt j t | d ƒ S| | k r;t	 | ƒ d | S| t j t j f k rZt j S| t j t j f k ryt j Sd  S(   Ni   i   (   R?   R   R   R   R8   R   R	   R
   R   R   R:   RB   R   R   R   R;   R   R   R   (   R   R&   R   R<   R=   (    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyR   >  sH    %	,'
c         C  s¶   t  |  j ƒ d k r‡ |  j \ } } } | j o: | d j t k r² | j oV | d j t k r² |  j | j ƒ  | j ƒ  | j ƒ  ƒ Sn+ |  j \ } } |  j | j ƒ  | j ƒ  ƒ Sd  S(   Ni   i   (   R@   R   R   R    R!   R"   R#   (   R   R&   R<   R   (    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyR$   f  s    (i   c         C  s  t  |  j ƒ d k r\|  j \ } } } t d | t | ƒ d ƒ d | t | ƒ d } } | d k râ t | | ƒ | | t | | ƒ | | d | t | | | ƒ | | | t d | ƒ d | d | | | d S| d k rú d | | S| d k rÿt | | ƒ | d t | | | ƒ | t d | ƒ d | d | d | | Sn£ |  j \ } } | d k rÈt | ƒ | | t | ƒ | | d | t | | ƒ | d | | | d S| d k rÿt | ƒ | d t | | ƒ d | | St |  | ƒ ‚ d  S(   Ni   i   i   (	   R@   R   R	   R
   R   R8   RB   R   R   (   R   R   R&   R<   R   R>   t   fn(    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyR   p  s$    7E3$22+N(   R4   R5   R6   R7   R?   R   R$   R   (    (    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyRB     s
   ('	
N(   R6   t
   __future__R    R   t
   sympy.coreR   R   R   t   sympy.core.functionR   R   t$   sympy.functions.elementary.complexesR   t%   sympy.functions.elementary.hyperbolicR   t(   sympy.functions.elementary.miscellaneousR	   t(   sympy.functions.elementary.trigonometricR
   R   t'   sympy.functions.special.gamma_functionsR   t   sympy.functions.special.hyperR   R   R   R8   R   RB   (    (    (    sI   lib/python2.7/site-packages/sympy/functions/special/elliptic_integrals.pyt   <module>   s   PEq