o
    8Va7                     @   sN  d dl mZ d dlmZmZmZmZmZmZ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mZmZmZ d dlmZ d d	lmZ d d
lm Z m!Z! d dl"m#Z#m$Z$ d dlm%Z%m&Z& d dl'm(Z(m)Z) d dl*m+Z+ d dl,m-Z. G dd deZ/G dd de/Z0G dd de/Z1G dd de/Z2G dd de/Z3G dd de/Z4G dd de/Z5dd Z6G d d! d!e/Z7d"d# Z8d$d% Z9G d&d' d'e7Z:G d(d) d)e7Z;G d*d+ d+e7Z<G d,d- d-e<Z=G d.d/ d/e<Z>dAd2d3Z?G d4d5 d5eZ@G d6d7 d7e@ZAG d8d9 d9e@ZBG d:d; d;e@ZCG d<d= d=e@ZDG d>d? d?eZEd@S )B    wraps)AddSpiIRationalWildcacheitsympify)FunctionArgumentIndexError_mexpand)fuzzy_or	fuzzy_not)Pow)	factorial)sincoscsccot)ceiling)Abs)explog)sqrtroot)reim)gammadigamma)hyper)spherical_bessel_fnc                   @   s^   e Zd ZdZedd Zedd Zedd Zdd	d
Z	dd Z
dd Zdd Zdd ZdS )
BesselBasea  
    Abstract base class for Bessel-type functions.

    This class is meant to reduce code duplication.
    All Bessel-type functions can 1) be differentiated, with the derivatives
    expressed in terms of similar functions, and 2) be rewritten in terms
    of other Bessel-type functions.

    Here, Bessel-type functions are assumed to have one complex parameter.

    To use this base class, define class attributes ``_a`` and ``_b`` such that
    ``2*F_n' = -_a*F_{n+1} + b*F_{n-1}``.

    c                 C   
   | j d S )z( The order of the Bessel-type function. r   argsself r)   @/usr/lib/python3/dist-packages/sympy/functions/special/bessel.pyorder-      
zBesselBase.orderc                 C   r$   )z+ The argument of the Bessel-type function.    r%   r'   r)   r)   r*   argument2   r,   zBesselBase.argumentc                 C   s   d S Nr)   clsnuzr)   r)   r*   eval7   s   zBesselBase.eval   c                 C   sN   |dkr	t | || jd | | jd | j | jd | | jd | j  S Nr5   r-   )r   _b	__class__r+   r.   _ar(   argindexr)   r)   r*   fdiff;   s
   
zBesselBase.fdiffc                 C   s*   | j }|jdu r| | j | S d S NF)r.   is_extended_negativer8   r+   	conjugater(   r3   r)   r)   r*   _eval_conjugateA   s   
zBesselBase._eval_conjugatec                 C   sx   | j | j}}||rdS |||sd S |||}|jr2t| ttt	t
ttfs-|js2t|jS tt|j|jgS r=   )r+   r.   Zhas_eval_is_meromorphicsubs
is_integer
isinstancebesseljbesselihn1hn2jnynis_zeror   Zis_infiniter   )r(   xar2   r3   Zz0r)   r)   r*   rB   F   s   

zBesselBase._eval_is_meromorphicc                 K   s   | j | j| j}}}|jr_|d jr7| j | j ||d |  d| j |d  ||d |  |  S |d jr_d| j |d  ||d |  | | j| j ||d |   S | S )Nr-   r5   )	r+   r.   r8   Zis_realis_positiver9   r7   _eval_expand_funcis_negative)r(   hintsr2   r3   fr)   r)   r*   rP   S   s   
&
&zBesselBase._eval_expand_funcc                 K   s   ddl m} || S )Nr   )
besselsimp)Zsympy.simplify.simplifyrT   )r(   kwargsrT   r)   r)   r*   _eval_simplify^   s   zBesselBase._eval_simplifyNr5   )__name__
__module____qualname____doc__propertyr+   r.   classmethodr4   r<   rA   rB   rP   rV   r)   r)   r)   r*   r#      s    



r#   c                       d   e Zd ZdZejZejZedd Z	dd Z
dd Zdd	 ZdddZdd Zd fdd	Z  ZS )rF   a3  
    Bessel function of the first kind.

    Explanation
    ===========

    The Bessel $J$ function of order $\nu$ is defined to be the function
    satisfying Bessel's differential equation

    .. math ::
        z^2 \frac{\mathrm{d}^2 w}{\mathrm{d}z^2}
        + z \frac{\mathrm{d}w}{\mathrm{d}z} + (z^2 - \nu^2) w = 0,

    with Laurent expansion

    .. math ::
        J_\nu(z) = z^\nu \left(\frac{1}{\Gamma(\nu + 1) 2^\nu} + O(z^2) \right),

    if $\nu$ is not a negative integer. If $\nu=-n \in \mathbb{Z}_{<0}$
    *is* a negative integer, then the definition is

    .. math ::
        J_{-n}(z) = (-1)^n J_n(z).

    Examples
    ========

    Create a Bessel function object:

    >>> from sympy import besselj, jn
    >>> from sympy.abc import z, n
    >>> b = besselj(n, z)

    Differentiate it:

    >>> b.diff(z)
    besselj(n - 1, z)/2 - besselj(n + 1, z)/2

    Rewrite in terms of spherical Bessel functions:

    >>> b.rewrite(jn)
    sqrt(2)*sqrt(z)*jn(n - 1/2, z)/sqrt(pi)

    Access the parameter and argument:

    >>> b.order
    n
    >>> b.argument
    z

    See Also
    ========

    bessely, besseli, besselk

    References
    ==========

    .. [1] Abramowitz, Milton; Stegun, Irene A., eds. (1965), "Chapter 9",
           Handbook of Mathematical Functions with Formulas, Graphs, and
           Mathematical Tables
    .. [2] Luke, Y. L. (1969), The Special Functions and Their
           Approximations, Volume 1
    .. [3] https://en.wikipedia.org/wiki/Bessel_function
    .. [4] http://functions.wolfram.com/Bessel-TypeFunctions/BesselJ/

    c                 C   sb  |j r,|j r	tjS |jr|j du st|jrtjS t|jr&|jdur&tjS |j	r,tj
S |tju s6|tju r9tjS | rM|| | |   t||  S |jrp| r`tj|  t| | S |t}|rpt| t|| S ddlm} |jr||}||krt||S n| \}}|dkrtd| t | t t|| S ||}||krt||S d S NFTr   )
unpolarifyr5   )rL   r   OnerD   r   rO   ZerorQ   ComplexInfinityis_imaginaryNaNInfinityNegativeInfinitycould_extract_minus_signrF   NegativeOneextract_multiplicativelyr   rG   sympyr`   extract_branch_factorr   r   r1   r2   r3   Znewzr`   nZnnur)   r)   r*   r4      s@    

"
zbesselj.evalc                 K   s4   ddl m} ttt | d t||t |  S Nr   )
polar_liftr5   )rk   rp   r   r   r   rG   r(   r2   r3   rU   rp   r)   r)   r*   _eval_rewrite_as_besseli      (z besselj._eval_rewrite_as_besselic                 K   s<   |j du rtt| t| | tt| t||  S d S r=   )rD   r   r   besselyr   r(   r2   r3   rU   r)   r)   r*   _eval_rewrite_as_bessely      
.z besselj._eval_rewrite_as_besselyc                 K   "   t d| t t|tj | j S Nr5   )r   r   rJ   r   Halfr.   ru   r)   r)   r*   _eval_rewrite_as_jn      "zbesselj._eval_rewrite_as_jnNr   c                 C   sN   | j \}}||}||jv r|| d| t|d   S | |||dS Nr5   r-   r   )r&   as_leading_termfree_symbolsr   funcrC   )r(   rM   logxcdirr2   r3   argr)   r)   r*   _eval_as_leading_term   s
   


zbesselj._eval_as_leading_termc                 C   "   | j \}}|jr|jrdS d S d S NTr&   rD   is_extended_realr(   r2   r3   r)   r)   r*   _eval_is_extended_real      
zbesselj._eval_is_extended_realc              	      s"  ddl m} | j\}}z	||\}}	W n ttfy!   |  Y S w |	jrt||	 }
||| |}|d ||||	 }|t
ju rE|S t|d | 	 }|| t|d  }|g}td|
d d D ]}|| |||   9 }t|| 	 }|| qet| | S tt| ||||S Nr   )Orderr5   r-   )sympy.series.orderr   r&   leadterm
ValueErrorNotImplementedErrorrO   r   _eval_nseriesremoveOr   rb   r   r   rangeappendr   superrF   )r(   rM   rn   r   r   r   r2   r3   _r   newnorttermskr8   r)   r*   r      s,   

zbesselj._eval_nseriesNr   r   )rX   rY   rZ   r[   r   ra   r9   r7   r]   r4   rr   rv   r{   r   r   r   __classcell__r)   r)   r   r*   rF   c   s    D
$
rF   c                       r^   )rt   a_  
    Bessel function of the second kind.

    Explanation
    ===========

    The Bessel $Y$ function of order $\nu$ is defined as

    .. math ::
        Y_\nu(z) = \lim_{\mu \to \nu} \frac{J_\mu(z) \cos(\pi \mu)
                                            - J_{-\mu}(z)}{\sin(\pi \mu)},

    where $J_\mu(z)$ is the Bessel function of the first kind.

    It is a solution to Bessel's equation, and linearly independent from
    $J_\nu$.

    Examples
    ========

    >>> from sympy import bessely, yn
    >>> from sympy.abc import z, n
    >>> b = bessely(n, z)
    >>> b.diff(z)
    bessely(n - 1, z)/2 - bessely(n + 1, z)/2
    >>> b.rewrite(yn)
    sqrt(2)*sqrt(z)*yn(n - 1/2, z)/sqrt(pi)

    See Also
    ========

    besselj, besseli, besselk

    References
    ==========

    .. [1] http://functions.wolfram.com/Bessel-TypeFunctions/BesselY/

    c                 C   s~   |j r|j r	tjS t|j du rtjS t|j rtjS |tju s%|tju r(tjS |jr;|	 r=tj
|  t| | S d S d S r=   )rL   r   rg   r   rc   re   rf   rb   rD   rh   ri   rt   r0   r)   r)   r*   r4   2  s   
zbessely.evalc                 K   s<   |j du rtt| tt| t|| t| |  S d S r=   )rD   r   r   r   rF   ru   r)   r)   r*   _eval_rewrite_as_besseljB  rw   z bessely._eval_rewrite_as_besseljc                 K      | j | j }|r|tS d S r/   )r   r&   rewriterG   r(   r2   r3   rU   Zajr)   r)   r*   rr   F     
z bessely._eval_rewrite_as_besselic                 K   rx   ry   )r   r   rK   r   rz   r.   ru   r)   r)   r*   _eval_rewrite_as_ynK  r|   zbessely._eval_rewrite_as_ynNr   c           
      C   s   | j \}}dt t|d  t|| }|d jr(|d |  t|d  t ntj}|d | tt|  t|d tj	  }t
|||g |}	||	jv rQ|	S | |||d S r}   )r&   r   r   rF   rO   r   r   rb   r    
EulerGammar   r~   r   r   rC   Zcancel)
r(   rM   r   r   r2   r3   Zterm_oneZterm_twoZ
term_threer   r)   r)   r*   r   N  s   
.*
zbessely._eval_as_leading_termc                 C   r   r   r&   rD   rO   r   r)   r)   r*   r   Y  r   zbessely._eval_is_extended_realc              	      s  ddl m} | j\}}z	||\}}	W n ttfy!   |  Y S w |	jr|jrt||	 }
t	||}dt
 t|d  | ||||}g g }}||| |}|d |||| }|tju rf|S t|d |  }|tjkr||  t|d  t
 }|| td|d D ]}|||| d  | 9 }t||  }|| q|| t
t|  }|t|d tj  }|| td|
d d D ]*}|| |||   9 }t||  }|t|| d t|d   }|| q|t|  t|  S tt| ||||S r   )r   r   r&   r   r   r   rO   rD   r   rF   r   r   r   r   r   rb   r   ra   r   r   r   r    r   r   r   rt   )r(   rM   rn   r   r   r   r2   r3   r   r   r   ZbnrN   bcr   r   r   r   r   pr   r)   r*   r   ^  sD   

$




 zbessely._eval_nseriesr   r   )rX   rY   rZ   r[   r   ra   r9   r7   r]   r4   r   rr   r   r   r   r   r   r)   r)   r   r*   rt     s    (

rt   c                   @   sJ   e Zd ZdZej ZejZedd Z	dd Z
dd Zdd	 Zd
d ZdS )rG   a  
    Modified Bessel function of the first kind.

    Explanation
    ===========

    The Bessel $I$ function is a solution to the modified Bessel equation

    .. math ::
        z^2 \frac{\mathrm{d}^2 w}{\mathrm{d}z^2}
        + z \frac{\mathrm{d}w}{\mathrm{d}z} + (z^2 + \nu^2)^2 w = 0.

    It can be defined as

    .. math ::
        I_\nu(z) = i^{-\nu} J_\nu(iz),

    where $J_\nu(z)$ is the Bessel function of the first kind.

    Examples
    ========

    >>> from sympy import besseli
    >>> from sympy.abc import z, n
    >>> besseli(n, z).diff(z)
    besseli(n - 1, z)/2 + besseli(n + 1, z)/2

    See Also
    ========

    besselj, bessely, besselk

    References
    ==========

    .. [1] http://functions.wolfram.com/Bessel-TypeFunctions/BesselI/

    c                 C   sb  |j r,|j r	tjS |jr|j du st|jrtjS t|jr&|jdur&tjS |j	r,tj
S t|tju s:t|tju r=tjS | rQ|| | |   t||  S |jrp| r^t| |S |t}|rpt|  t||  S ddlm} |jr||}||krt||S n| \}}|dkrtd| t | t t|| S ||}||krt||S d S r_   )rL   r   ra   rD   r   rO   rb   rQ   rc   rd   re   r   rf   rg   rh   rG   rj   r   rF   rk   r`   rl   r   r   rm   r)   r)   r*   r4     s@    

"
zbesseli.evalc                 K   s4   ddl m} tt t | d t||t|  S ro   )rk   rp   r   r   r   rF   rq   r)   r)   r*   r     rs   z besseli._eval_rewrite_as_besseljc                 K   r   r/   r   r&   r   rt   r   r)   r)   r*   rv     r   z besseli._eval_rewrite_as_besselyc                 K   s   | j | j tS r/   )r   r&   r   rJ   ru   r)   r)   r*   r{     s   zbesseli._eval_rewrite_as_jnc                 C   r   r   r   r   r)   r)   r*   r     r   zbesseli._eval_is_extended_realN)rX   rY   rZ   r[   r   ra   r9   r7   r]   r4   r   rv   r{   r   r)   r)   r)   r*   rG     s    '
$rG   c                   @   sR   e Zd ZdZejZej Zedd Z	dd Z
dd Zdd	 Zd
d Zdd ZdS )besselka  
    Modified Bessel function of the second kind.

    Explanation
    ===========

    The Bessel $K$ function of order $\nu$ is defined as

    .. math ::
        K_\nu(z) = \lim_{\mu \to \nu} \frac{\pi}{2}
                   \frac{I_{-\mu}(z) -I_\mu(z)}{\sin(\pi \mu)},

    where $I_\mu(z)$ is the modified Bessel function of the first kind.

    It is a solution of the modified Bessel equation, and linearly independent
    from $Y_\nu$.

    Examples
    ========

    >>> from sympy import besselk
    >>> from sympy.abc import z, n
    >>> besselk(n, z).diff(z)
    -besselk(n - 1, z)/2 - besselk(n + 1, z)/2

    See Also
    ========

    besselj, besseli, bessely

    References
    ==========

    .. [1] http://functions.wolfram.com/Bessel-TypeFunctions/BesselK/

    c                 C   sz   |j r|j r	tjS t|j du rtjS t|j rtjS |tjttj ttj fv r,tjS |j	r9|
 r;t| |S d S d S r=   )rL   r   rf   r   rc   re   r   rg   rb   rD   rh   r   r0   r)   r)   r*   r4     s   
zbesselk.evalc                 K   s8   |j du rttt|  t| |t||  d S d S )NFr5   )rD   r   r   rG   ru   r)   r)   r*   rr   %  s   
*z besselk._eval_rewrite_as_besselic                 K   r   r/   )rr   r&   r   rF   )r(   r2   r3   rU   Zair)   r)   r*   r   )  r   z besselk._eval_rewrite_as_besseljc                 K   r   r/   r   r   r)   r)   r*   rv   .  r   z besselk._eval_rewrite_as_besselyc                 K   r   r/   )rv   r&   r   rK   )r(   r2   r3   rU   Zayr)   r)   r*   r   3  r   zbesselk._eval_rewrite_as_ync                 C   r   r   r   r   r)   r)   r*   r   8  r   zbesselk._eval_is_extended_realN)rX   rY   rZ   r[   r   ra   r9   r7   r]   r4   rr   r   rv   r   r   r)   r)   r)   r*   r     s    %
r   c                   @   $   e Zd ZdZejZejZdd ZdS )hankel1a  
    Hankel function of the first kind.

    Explanation
    ===========

    This function is defined as

    .. math ::
        H_\nu^{(1)} = J_\nu(z) + iY_\nu(z),

    where $J_\nu(z)$ is the Bessel function of the first kind, and
    $Y_\nu(z)$ is the Bessel function of the second kind.

    It is a solution to Bessel's equation.

    Examples
    ========

    >>> from sympy import hankel1
    >>> from sympy.abc import z, n
    >>> hankel1(n, z).diff(z)
    hankel1(n - 1, z)/2 - hankel1(n + 1, z)/2

    See Also
    ========

    hankel2, besselj, bessely

    References
    ==========

    .. [1] http://functions.wolfram.com/Bessel-TypeFunctions/HankelH1/

    c                 C   (   | j }|jdu rt| j | S d S r=   )r.   r>   hankel2r+   r?   r@   r)   r)   r*   rA   f     
zhankel1._eval_conjugateN	rX   rY   rZ   r[   r   ra   r9   r7   rA   r)   r)   r)   r*   r   >  s
    $r   c                   @   r   )r   a  
    Hankel function of the second kind.

    Explanation
    ===========

    This function is defined as

    .. math ::
        H_\nu^{(2)} = J_\nu(z) - iY_\nu(z),

    where $J_\nu(z)$ is the Bessel function of the first kind, and
    $Y_\nu(z)$ is the Bessel function of the second kind.

    It is a solution to Bessel's equation, and linearly independent from
    $H_\nu^{(1)}$.

    Examples
    ========

    >>> from sympy import hankel2
    >>> from sympy.abc import z, n
    >>> hankel2(n, z).diff(z)
    hankel2(n - 1, z)/2 - hankel2(n + 1, z)/2

    See Also
    ========

    hankel1, besselj, bessely

    References
    ==========

    .. [1] http://functions.wolfram.com/Bessel-TypeFunctions/HankelH2/

    c                 C   r   r=   )r.   r>   r   r+   r?   r@   r)   r)   r*   rA     r   zhankel2._eval_conjugateNr   r)   r)   r)   r*   r   l  s
    %r   c                    s   t   fdd}|S )Nc                    s   |j r	 | ||S d S r/   )rD   r   fnr)   r*   g  s   zassume_integer_order.<locals>.gr   )r   r   r)   r   r*   assume_integer_order  s   r   c                   @   s*   e Zd ZdZdd Zdd Zd
ddZd	S )SphericalBesselBasea-  
    Base class for spherical Bessel functions.

    These are thin wrappers around ordinary Bessel functions,
    since spherical Bessel functions differ from the ordinary
    ones just by a slight change in order.

    To use this class, define the ``_eval_evalf()`` and ``_expand()`` methods.

    c                 K   s   t d)z@ Expand self into a polynomial. Nu is guaranteed to be Integer. Z	expansionr   r(   rR   r)   r)   r*   _expand  s   zSphericalBesselBase._expandc                 K   s   | j jr| jdi |S | S Nr)   )r+   
is_Integerr   r   r)   r)   r*   rP     s   z%SphericalBesselBase._eval_expand_funcr5   c                 C   s:   |dkr	t | || | jd | j| | jd  | j  S r6   )r   r8   r+   r.   r:   r)   r)   r*   r<     s
   
zSphericalBesselBase.fdiffNrW   )rX   rY   rZ   r[   r   rP   r<   r)   r)   r)   r*   r     s
    r   c                 C   s6   t | |t| d| d  t |  d | t|  S Nr-   r   r   r   rn   r3   r)   r)   r*   _jn  s   6r   c                 C   s6   d| d  t |  d | t| t | |t|  S r   r   r   r)   r)   r*   _yn  s   6r   c                   @   sD   e Zd ZdZedd Zdd Zdd Zdd	 Zd
d Z	dd Z
dS )rJ   a  
    Spherical Bessel function of the first kind.

    Explanation
    ===========

    This function is a solution to the spherical Bessel equation

    .. math ::
        z^2 \frac{\mathrm{d}^2 w}{\mathrm{d}z^2}
          + 2z \frac{\mathrm{d}w}{\mathrm{d}z} + (z^2 - \nu(\nu + 1)) w = 0.

    It can be defined as

    .. math ::
        j_\nu(z) = \sqrt{\frac{\pi}{2z}} J_{\nu + \frac{1}{2}}(z),

    where $J_\nu(z)$ is the Bessel function of the first kind.

    The spherical Bessel functions of integral order are
    calculated using the formula:

    .. math:: j_n(z) = f_n(z) \sin{z} + (-1)^{n+1} f_{-n-1}(z) \cos{z},

    where the coefficients $f_n(z)$ are available as
    :func:`sympy.polys.orthopolys.spherical_bessel_fn`.

    Examples
    ========

    >>> from sympy import Symbol, jn, sin, cos, expand_func, besselj, bessely
    >>> z = Symbol("z")
    >>> nu = Symbol("nu", integer=True)
    >>> print(expand_func(jn(0, z)))
    sin(z)/z
    >>> expand_func(jn(1, z)) == sin(z)/z**2 - cos(z)/z
    True
    >>> expand_func(jn(3, z))
    (-6/z**2 + 15/z**4)*sin(z) + (1/z - 15/z**3)*cos(z)
    >>> jn(nu, z).rewrite(besselj)
    sqrt(2)*sqrt(pi)*sqrt(1/z)*besselj(nu + 1/2, z)/2
    >>> jn(nu, z).rewrite(bessely)
    (-1)**nu*sqrt(2)*sqrt(pi)*sqrt(1/z)*bessely(-nu - 1/2, z)/2
    >>> jn(2, 5.2+0.3j).evalf(20)
    0.099419756723640344491 - 0.054525080242173562897*I

    See Also
    ========

    besselj, bessely, besselk, yn

    References
    ==========

    .. [1] http://dlmf.nist.gov/10.47

    c                 C   sD   |j r|j r	tjS |jr|jrtjS tjS |tjtjfv r tjS d S r/   )	rL   r   ra   rD   rO   rb   rc   rg   rf   r0   r)   r)   r*   r4     s   zjn.evalc                 K       t td|  t|tj | S ry   r   r   rF   r   rz   ru   r)   r)   r*   r     s    zjn._eval_rewrite_as_besseljc                 K   s*   d| t td|   t| tj | S )Nr   r5   r   r   rt   r   rz   ru   r)   r)   r*   rv     s   *zjn._eval_rewrite_as_besselyc                 K   s   d| t | d | S r   )rK   ru   r)   r)   r*   r     s   zjn._eval_rewrite_as_ync                 K      t | j| jS r/   )r   r+   r.   r   r)   r)   r*   r        z
jn._expandc                 C      | j jr| t|S d S r/   r+   r   r   rF   _eval_evalfr(   precr)   r)   r*   r        zjn._eval_evalfN)rX   rY   rZ   r[   r]   r4   r   rv   r   r   r   r)   r)   r)   r*   rJ     s    9
rJ   c                   @   s@   e Zd ZdZedd Zedd Zdd Zdd	 Zd
d Z	dS )rK   a  
    Spherical Bessel function of the second kind.

    Explanation
    ===========

    This function is another solution to the spherical Bessel equation, and
    linearly independent from $j_n$. It can be defined as

    .. math ::
        y_\nu(z) = \sqrt{\frac{\pi}{2z}} Y_{\nu + \frac{1}{2}}(z),

    where $Y_\nu(z)$ is the Bessel function of the second kind.

    For integral orders $n$, $y_n$ is calculated using the formula:

    .. math:: y_n(z) = (-1)^{n+1} j_{-n-1}(z)

    Examples
    ========

    >>> from sympy import Symbol, yn, sin, cos, expand_func, besselj, bessely
    >>> z = Symbol("z")
    >>> nu = Symbol("nu", integer=True)
    >>> print(expand_func(yn(0, z)))
    -cos(z)/z
    >>> expand_func(yn(1, z)) == -cos(z)/z**2-sin(z)/z
    True
    >>> yn(nu, z).rewrite(besselj)
    (-1)**(nu + 1)*sqrt(2)*sqrt(pi)*sqrt(1/z)*besselj(-nu - 1/2, z)/2
    >>> yn(nu, z).rewrite(bessely)
    sqrt(2)*sqrt(pi)*sqrt(1/z)*bessely(nu + 1/2, z)/2
    >>> yn(2, 5.2+0.3j).evalf(20)
    0.18525034196069722536 + 0.014895573969924817587*I

    See Also
    ========

    besselj, bessely, besselk, jn

    References
    ==========

    .. [1] http://dlmf.nist.gov/10.47

    c                 K   s.   d|d  t td|   t| tj | S )Nr   r-   r5   r   ru   r)   r)   r*   r   O  s   .zyn._eval_rewrite_as_besseljc                 K   r   ry   r   ru   r)   r)   r*   rv   S  s    zyn._eval_rewrite_as_besselyc                 K   s   d|d  t | d | S r   )rJ   ru   r)   r)   r*   r{   W  s   zyn._eval_rewrite_as_jnc                 K   r   r/   )r   r+   r.   r   r)   r)   r*   r   Z  r   z
yn._expandc                 C   r   r/   )r+   r   r   rt   r   r   r)   r)   r*   r   ]  r   zyn._eval_evalfN)
rX   rY   rZ   r[   r   r   rv   r{   r   r   r)   r)   r)   r*   rK      s    .

rK   c                   @   sL   e Zd Zedd Zedd Zdd Zdd Zd	d
 Zdd Z	dd Z
dS )SphericalHankelBasec                 K   sL   | j }ttd|  t|tj ||t d|d   t| tj |   S )Nr5   r   r-   )_hankel_kind_signr   r   rF   r   rz   r   r(   r2   r3   rU   hksr)   r)   r*   r   d  s   $z,SphericalHankelBase._eval_rewrite_as_besseljc                 K   sH   | j }ttd|  d| t| tj | |t t|tj |   S )Nr5   r   )r   r   r   rt   r   rz   r   r   r)   r)   r*   rv   m  s   &z,SphericalHankelBase._eval_rewrite_as_besselyc                 K   s(   | j }t||t|t t||  S r/   )r   rJ   r   rK   r   r   r)   r)   r*   r   v     "z'SphericalHankelBase._eval_rewrite_as_ync                 K   s(   | j }t|||t t||t  S r/   )r   rJ   r   rK   r   r   r)   r)   r*   r{   z  r   z'SphericalHankelBase._eval_rewrite_as_jnc                 K   sF   | j jr| jdi |S | j }| j}| j}t|||t t||  S r   )r+   r   r   r.   r   rJ   r   rK   )r(   rR   r2   r3   r   r)   r)   r*   rP   ~  s   z%SphericalHankelBase._eval_expand_funcc                 K   s2   | j }| j}| j}t|||t t||   S r/   )r+   r.   r   r   r   r   expand)r(   rR   rn   r3   r   r)   r)   r*   r     s    
zSphericalHankelBase._expandc                 C   r   r/   r   r   r)   r)   r*   r     r   zSphericalHankelBase._eval_evalfN)rX   rY   rZ   r   r   rv   r   r{   rP   r   r   r)   r)   r)   r*   r   b  s    

	r   c                   @   s"   e Zd ZdZejZedd ZdS )rH   a  
    Spherical Hankel function of the first kind.

    Explanation
    ===========

    This function is defined as

    .. math:: h_\nu^(1)(z) = j_\nu(z) + i y_\nu(z),

    where $j_\nu(z)$ and $y_\nu(z)$ are the spherical
    Bessel function of the first and second kinds.

    For integral orders $n$, $h_n^(1)$ is calculated using the formula:

    .. math:: h_n^(1)(z) = j_{n}(z) + i (-1)^{n+1} j_{-n-1}(z)

    Examples
    ========

    >>> from sympy import Symbol, hn1, hankel1, expand_func, yn, jn
    >>> z = Symbol("z")
    >>> nu = Symbol("nu", integer=True)
    >>> print(expand_func(hn1(nu, z)))
    jn(nu, z) + I*yn(nu, z)
    >>> print(expand_func(hn1(0, z)))
    sin(z)/z - I*cos(z)/z
    >>> print(expand_func(hn1(1, z)))
    -I*sin(z)/z - cos(z)/z + sin(z)/z**2 - I*cos(z)/z**2
    >>> hn1(nu, z).rewrite(jn)
    (-1)**(nu + 1)*I*jn(-nu - 1, z) + jn(nu, z)
    >>> hn1(nu, z).rewrite(yn)
    (-1)**nu*yn(-nu - 1, z) + I*yn(nu, z)
    >>> hn1(nu, z).rewrite(hankel1)
    sqrt(2)*sqrt(pi)*sqrt(1/z)*hankel1(nu, z)/2

    See Also
    ========

    hn2, jn, yn, hankel1, hankel2

    References
    ==========

    .. [1] http://dlmf.nist.gov/10.47

    c                 K      t td|  t|| S ry   )r   r   r   ru   r)   r)   r*   _eval_rewrite_as_hankel1     zhn1._eval_rewrite_as_hankel1N)	rX   rY   rZ   r[   r   ra   r   r   r   r)   r)   r)   r*   rH     s
    0rH   c                   @   s$   e Zd ZdZej Zedd ZdS )rI   a  
    Spherical Hankel function of the second kind.

    Explanation
    ===========

    This function is defined as

    .. math:: h_\nu^(2)(z) = j_\nu(z) - i y_\nu(z),

    where $j_\nu(z)$ and $y_\nu(z)$ are the spherical
    Bessel function of the first and second kinds.

    For integral orders $n$, $h_n^(2)$ is calculated using the formula:

    .. math:: h_n^(2)(z) = j_{n} - i (-1)^{n+1} j_{-n-1}(z)

    Examples
    ========

    >>> from sympy import Symbol, hn2, hankel2, expand_func, jn, yn
    >>> z = Symbol("z")
    >>> nu = Symbol("nu", integer=True)
    >>> print(expand_func(hn2(nu, z)))
    jn(nu, z) - I*yn(nu, z)
    >>> print(expand_func(hn2(0, z)))
    sin(z)/z + I*cos(z)/z
    >>> print(expand_func(hn2(1, z)))
    I*sin(z)/z - cos(z)/z + sin(z)/z**2 + I*cos(z)/z**2
    >>> hn2(nu, z).rewrite(hankel2)
    sqrt(2)*sqrt(pi)*sqrt(1/z)*hankel2(nu, z)/2
    >>> hn2(nu, z).rewrite(jn)
    -(-1)**(nu + 1)*I*jn(-nu - 1, z) + jn(nu, z)
    >>> hn2(nu, z).rewrite(yn)
    (-1)**nu*yn(-nu - 1, z) - I*yn(nu, z)

    See Also
    ========

    hn1, jn, yn, hankel1, hankel2

    References
    ==========

    .. [1] http://dlmf.nist.gov/10.47

    c                 K   r   ry   )r   r   r   ru   r)   r)   r*   _eval_rewrite_as_hankel2  r   zhn2._eval_rewrite_as_hankel2N)	rX   rY   rZ   r[   r   ra   r   r   r   r)   r)   r)   r*   rI     s
    0rI   rk      c                    s  ddl m} dkr1ddlm ddlm} ddlm  || fddtd	|d	 D S d
kraddl	m
 zddlm fdd}W n ty`   ddlm fdd}Y nw tdfdd}| }|||}|g}	t|d	 D ]}
|||| }|	| q~|	S )a  
    Zeros of the spherical Bessel function of the first kind.

    Explanation
    ===========

    This returns an array of zeros of $jn$ up to the $k$-th zero.

    * method = "sympy": uses `mpmath.besseljzero
      <http://mpmath.org/doc/current/functions/bessel.html#mpmath.besseljzero>`_
    * method = "scipy": uses the
      `SciPy's sph_jn <http://docs.scipy.org/doc/scipy/reference/generated/scipy.special.jn_zeros.html>`_
      and
      `newton <http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.newton.html>`_
      to find all
      roots, which is faster than computing the zeros using a general
      numerical solver, but it requires SciPy and only works with low
      precision floating point numbers. (The function used with
      method="sympy" is a recent addition to mpmath; before that a general
      solver was used.)

    Examples
    ========

    >>> from sympy import jn_zeros
    >>> jn_zeros(2, 4, dps=5)
    [5.7635, 9.095, 12.323, 15.515]

    See Also
    ========

    jn, yn, besselj, besselk, bessely

    Parameters
    ==========

    n : integer
        order of Bessel function

    k : integer
        number of zeros to return


    r   )r   rk   )besseljzero)dps_to_precExprc                    s0   g | ]}  td  t|qS )g      ?)_from_mpmathr   
_to_mpmathint).0l)r   r   rn   r   r)   r*   
<listcomp>?  s    zjn_zeros.<locals>.<listcomp>r-   scipy)newton)spherical_jnc                    s
    | S r/   r)   rM   )rn   r   r)   r*   <lambda>F  s   
 zjn_zeros.<locals>.<lambda>)sph_jnc                    s    | d d S )Nr   r   r)   r   )rn   r   r)   r*   r   I  s    Unknown method.c                    s    dkr| |}|S t d)Nr   r   r   )rS   rM   r   )methodr   r)   r*   solverM  s   
zjn_zeros.<locals>.solver)Zmathr   mpmathr   Zmpmath.libmp.libmpfr   rk   r   r   Zscipy.optimizer   Zscipy.specialr   ImportErrorr   r   r   )rn   r   r   Zdpsr   r   rS   r   r   rootsir)   )r   r   r   rn   r   r   r   r   r*   jn_zeros  s6   -
r   c                   @   s4   e Zd ZdZdd Zdd ZdddZdd	d
ZdS )AiryBasezg
    Abstract base class for Airy functions.

    This class is meant to reduce code duplication.

    c                 C   s   |  | jd  S r   )r   r&   r?   r'   r)   r)   r*   rA   h  s   zAiryBase._eval_conjugatec                 C   s   | j d jS r   )r&   r   r'   r)   r)   r*   r   k  s   zAiryBase._eval_is_extended_realTc                 K   sL   | j d }| }| j}|||| d }t||||  d }||fS )Nr   r5   )r&   r?   r   r   )r(   deeprR   r3   ZzcrS   uvr)   r)   r*   as_real_imagn  s   
zAiryBase.as_real_imagc                 K   s&   | j dd|i|\}}||tj  S )Nr   r)   )r   r   ZImaginaryUnit)r(   r   rR   Zre_partZim_partr)   r)   r*   _eval_expand_complexv  s   zAiryBase._eval_expand_complexN)T)rX   rY   rZ   r[   rA   r   r   r   r)   r)   r)   r*   r   `  s    
r   c                   @   ^   e Zd ZdZdZdZedd ZdddZe	e
dd	 Zd
d Zdd Zdd Zdd ZdS )airyaia  
    The Airy function $\operatorname{Ai}$ of the first kind.

    Explanation
    ===========

    The Airy function $\operatorname{Ai}(z)$ is defined to be the function
    satisfying Airy's differential equation

    .. math::
        \frac{\mathrm{d}^2 w(z)}{\mathrm{d}z^2} - z w(z) = 0.

    Equivalently, for real $z$

    .. math::
        \operatorname{Ai}(z) := \frac{1}{\pi}
        \int_0^\infty \cos\left(\frac{t^3}{3} + z t\right) \mathrm{d}t.

    Examples
    ========

    Create an Airy function object:

    >>> from sympy import airyai
    >>> from sympy.abc import z

    >>> airyai(z)
    airyai(z)

    Several special values are known:

    >>> airyai(0)
    3**(1/3)/(3*gamma(2/3))
    >>> from sympy import oo
    >>> airyai(oo)
    0
    >>> airyai(-oo)
    0

    The Airy function obeys the mirror symmetry:

    >>> from sympy import conjugate
    >>> conjugate(airyai(z))
    airyai(conjugate(z))

    Differentiation with respect to $z$ is supported:

    >>> from sympy import diff
    >>> diff(airyai(z), z)
    airyaiprime(z)
    >>> diff(airyai(z), z, 2)
    z*airyai(z)

    Series expansion is also supported:

    >>> from sympy import series
    >>> series(airyai(z), z, 0, 3)
    3**(5/6)*gamma(1/3)/(6*pi) - 3**(1/6)*z*gamma(2/3)/(2*pi) + O(z**3)

    We can numerically evaluate the Airy function to arbitrary precision
    on the whole complex plane:

    >>> airyai(-2).evalf(50)
    0.22740742820168557599192443603787379946077222541710

    Rewrite $\operatorname{Ai}(z)$ in terms of hypergeometric functions:

    >>> from sympy import hyper
    >>> airyai(z).rewrite(hyper)
    -3**(2/3)*z*hyper((), (4/3,), z**3/9)/(3*gamma(1/3)) + 3**(1/3)*hyper((), (2/3,), z**3/9)/(3*gamma(2/3))

    See Also
    ========

    airybi: Airy function of the second kind.
    airyaiprime: Derivative of the Airy function of the first kind.
    airybiprime: Derivative of the Airy function of the second kind.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Airy_function
    .. [2] http://dlmf.nist.gov/9
    .. [3] http://www.encyclopediaofmath.org/index.php/Airy_functions
    .. [4] http://mathworld.wolfram.com/AiryFunctions.html

    r-   Tc                 C   s   |j r/|tju rtjS |tju rtjS |tju rtjS |jr/tjdtdd t	tdd  S |jrCtjdtdd t	tdd  S d S )N   r5   )
	is_Numberr   re   rf   rb   rg   rL   ra   r   r   r1   r   r)   r)   r*   r4     s   


""zairyai.evalc                 C       |dkrt | jd S t| |Nr-   r   )airyaiprimer&   r   r:   r)   r)   r*   r<        
zairyai.fdiffc                 G   sF  | dk rt jS t|}t|dkrp|d }dtdd | |   dtdd | | d   tt| tdd tdd   t|  t| d tdd  tt| tdd tdd  t| d  t| d tdd   | S t j	dtdd t  t| t j	 t d  tdt | t j	  t d  t|  t
dd| |   S )Nr   r-   r   r   r5      )r   rb   r   lenr   r   r   r   r   ra   r   rn   rM   Zprevious_termsr   r)   r)   r*   taylor_term  s"   X@Jzairyai.taylor_termc                 K   s`   t dd}t dd}t| t dd}t|jr.|t|  t| || t|||   S d S Nr-   r   r5   r   r   r   rQ   r   rF   r(   r3   rU   otttrN   r)   r)   r*   r        


,zairyai._eval_rewrite_as_besseljc                 K   s   t dd}t dd}t|t dd}t|jr,|t| t| || t|||   S |t||t| ||  |t||  t|||    S r  r   r   r   rO   r   rG   r	  r)   r)   r*   rr     s   


*<zairyai._eval_rewrite_as_besselic                 K   s~   t jdtdd ttdd  }|tddttdd  }|tg tddg|d d  |tg tddg|d d   S )Nr   r5   r-   	   r  )r   ra   r   r   r   r!   r(   r3   rU   Zpf1Zpf2r)   r)   r*   _eval_rewrite_as_hyper
  s   "@zairyai._eval_rewrite_as_hyperc                 K   s"  | j d }|j}t|dkr| }td|gd}td|gd}td|gd}td|gd}|||||  |  }	|	d ur|	| }d| jr|	| }|	| }|	| }|||  | || |||    }
|||  |||   }tj|
tj	 t
| |
tj	 td t|   S d S d S d S 	Nr   r-   r   )Zexcludedmrn   r   )r&   r   r  popr	   matchrD   r   rz   ra   r   r   airybir(   rR   r   Zsymbsr3   r   r  r  rn   MZpfZnewargr)   r)   r*   rP     *   

$2zairyai._eval_expand_funcNr-   rX   rY   rZ   r[   nargs
unbranchedr]   r4   r<   staticmethodr
   r  r   rr   r  rP   r)   r)   r)   r*   r   {  s    X

	r   c                   @   r   )r  a  
    The Airy function $\operatorname{Bi}$ of the second kind.

    Explanation
    ===========

    The Airy function $\operatorname{Bi}(z)$ is defined to be the function
    satisfying Airy's differential equation

    .. math::
        \frac{\mathrm{d}^2 w(z)}{\mathrm{d}z^2} - z w(z) = 0.

    Equivalently, for real $z$

    .. math::
        \operatorname{Bi}(z) := \frac{1}{\pi}
                 \int_0^\infty
                   \exp\left(-\frac{t^3}{3} + z t\right)
                   + \sin\left(\frac{t^3}{3} + z t\right) \mathrm{d}t.

    Examples
    ========

    Create an Airy function object:

    >>> from sympy import airybi
    >>> from sympy.abc import z

    >>> airybi(z)
    airybi(z)

    Several special values are known:

    >>> airybi(0)
    3**(5/6)/(3*gamma(2/3))
    >>> from sympy import oo
    >>> airybi(oo)
    oo
    >>> airybi(-oo)
    0

    The Airy function obeys the mirror symmetry:

    >>> from sympy import conjugate
    >>> conjugate(airybi(z))
    airybi(conjugate(z))

    Differentiation with respect to $z$ is supported:

    >>> from sympy import diff
    >>> diff(airybi(z), z)
    airybiprime(z)
    >>> diff(airybi(z), z, 2)
    z*airybi(z)

    Series expansion is also supported:

    >>> from sympy import series
    >>> series(airybi(z), z, 0, 3)
    3**(1/3)*gamma(1/3)/(2*pi) + 3**(2/3)*z*gamma(2/3)/(2*pi) + O(z**3)

    We can numerically evaluate the Airy function to arbitrary precision
    on the whole complex plane:

    >>> airybi(-2).evalf(50)
    -0.41230258795639848808323405461146104203453483447240

    Rewrite $\operatorname{Bi}(z)$ in terms of hypergeometric functions:

    >>> from sympy import hyper
    >>> airybi(z).rewrite(hyper)
    3**(1/6)*z*hyper((), (4/3,), z**3/9)/gamma(1/3) + 3**(5/6)*hyper((), (2/3,), z**3/9)/(3*gamma(2/3))

    See Also
    ========

    airyai: Airy function of the first kind.
    airyaiprime: Derivative of the Airy function of the first kind.
    airybiprime: Derivative of the Airy function of the second kind.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Airy_function
    .. [2] http://dlmf.nist.gov/9
    .. [3] http://www.encyclopediaofmath.org/index.php/Airy_functions
    .. [4] http://mathworld.wolfram.com/AiryFunctions.html

    r-   Tc                 C   s   |j r/|tju rtjS |tju rtjS |tju rtjS |jr/tjdtdd t	tdd  S |jrCtjdtdd t	tdd  S d S )Nr   r-      r5   )
r   r   re   rf   rg   rb   rL   ra   r   r   r   r)   r)   r*   r4     s   


""zairybi.evalc                 C   r   r   )airybiprimer&   r   r:   r)   r)   r*   r<     r  zairybi.fdiffc                 G   s  | dk rt jS t|}t|dkr\|d }dtdd | ttdt | t j  t d  t	| t j t d  | t j tt
dt | t j  t d  t	| d t d   | S t jtddt  t| t j t d  ttdt | t j  t d  t	|  tdd| |   S )Nr   r-   r   r   r5   r  )r   rb   r   r  r   r   r   r   ra   r   r   rz   r   r   r  r)   r)   r*   r    s   H>Jzairybi.taylor_termc                 K   s`   t dd}t dd}t| t dd}t|jr.t| d t| || t|||   S d S r  r  r	  r)   r)   r*   r     r  zairybi._eval_rewrite_as_besseljc                 K   s   t dd}t dd}t|t dd}t|jr.t|td t| || t|||   S t||}t|| }t||t| ||  || t|||    S r  r  r(   r3   rU   r
  r  rN   r   r   r)   r)   r*   rr     s   


.
2zairybi._eval_rewrite_as_besselic                 K   sz   t jtddttdd  }|tdd ttdd }|tg tddg|d d  |tg tddg|d d   S )Nr   r  r5   r-   r  r  )r   ra   r   r   r   r!   r  r)   r)   r*   r    s   @zairybi._eval_rewrite_as_hyperc                 K   s"  | j d }|j}t|dkr| }td|gd}td|gd}td|gd}td|gd}|||||  |  }	|	d ur|	| }d| jr|	| }|	| }|	| }|||  | || |||    }
|||  |||   }tjt	dtj
|
  t| tj
|
 t|   S d S d S d S r  )r&   r   r  r  r	   r  rD   r   rz   r   ra   r   r  r  r)   r)   r*   rP     r  zairybi._eval_expand_funcNr  r  r)   r)   r)   r*   r  '  s    Z

r  c                   @   V   e Zd ZdZdZdZedd ZdddZdd	 Z	d
d Z
dd Zdd Zdd ZdS )r  a+  
    The derivative $\operatorname{Ai}^\prime$ of the Airy function of the first
    kind.

    Explanation
    ===========

    The Airy function $\operatorname{Ai}^\prime(z)$ is defined to be the
    function

    .. math::
        \operatorname{Ai}^\prime(z) := \frac{\mathrm{d} \operatorname{Ai}(z)}{\mathrm{d} z}.

    Examples
    ========

    Create an Airy function object:

    >>> from sympy import airyaiprime
    >>> from sympy.abc import z

    >>> airyaiprime(z)
    airyaiprime(z)

    Several special values are known:

    >>> airyaiprime(0)
    -3**(2/3)/(3*gamma(1/3))
    >>> from sympy import oo
    >>> airyaiprime(oo)
    0

    The Airy function obeys the mirror symmetry:

    >>> from sympy import conjugate
    >>> conjugate(airyaiprime(z))
    airyaiprime(conjugate(z))

    Differentiation with respect to $z$ is supported:

    >>> from sympy import diff
    >>> diff(airyaiprime(z), z)
    z*airyai(z)
    >>> diff(airyaiprime(z), z, 2)
    z*airyaiprime(z) + airyai(z)

    Series expansion is also supported:

    >>> from sympy import series
    >>> series(airyaiprime(z), z, 0, 3)
    -3**(2/3)/(3*gamma(1/3)) + 3**(1/3)*z**2/(6*gamma(2/3)) + O(z**3)

    We can numerically evaluate the Airy function to arbitrary precision
    on the whole complex plane:

    >>> airyaiprime(-2).evalf(50)
    0.61825902074169104140626429133247528291577794512415

    Rewrite $\operatorname{Ai}^\prime(z)$ in terms of hypergeometric functions:

    >>> from sympy import hyper
    >>> airyaiprime(z).rewrite(hyper)
    3**(1/3)*z**2*hyper((), (5/3,), z**3/9)/(6*gamma(2/3)) - 3**(2/3)*hyper((), (1/3,), z**3/9)/(3*gamma(1/3))

    See Also
    ========

    airyai: Airy function of the first kind.
    airybi: Airy function of the second kind.
    airybiprime: Derivative of the Airy function of the second kind.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Airy_function
    .. [2] http://dlmf.nist.gov/9
    .. [3] http://www.encyclopediaofmath.org/index.php/Airy_functions
    .. [4] http://mathworld.wolfram.com/AiryFunctions.html

    r-   Tc                 C   sR   |j r|tju rtjS |tju rtjS |jr'tjdtdd ttdd  S d S )Nr   r-   )	r   r   re   rf   rb   rL   ri   r   r   r   r)   r)   r*   r4   -  s   

"zairyaiprime.evalc                 C   *   |dkr| j d t| j d  S t| |r   )r&   r   r   r:   r)   r)   r*   r<   8     
zairyaiprime.fdiffc                 C   n   ddl m}m} ddlm} | jd |}|| |j|dd}W d    n1 s,w   Y  |||S Nr   )mpworkprecr   r-   )Z
derivative)	r   r'  r(  rk   r   r&   r   r   r   r(   r   r'  r(  r   r3   resr)   r)   r*   r   >     
zairyaiprime._eval_evalfc                 K   sP   t dd}t| t dd}t|jr&|d t| || t|||   S d S Nr5   r   )r   r   r   rQ   rF   r(   r3   rU   r  rN   r)   r)   r*   r   F  s
   

&z$airyaiprime._eval_rewrite_as_besseljc                 K   s   t dd}t dd}|t|t dd }t|jr(|d t||t| |  S t|t dd}t||}t|| }||d | t|||  |t| ||    S r  )r   r   r   rO   rG   r!  r)   r)   r*   rr   L  s   



2z$airyaiprime._eval_rewrite_as_besselic                 K   s   |d ddt dd  tt dd  }dtddtt dd  }|tg t ddg|d d  |tg t ddg|d d   S )Nr5   r   r-      r  )r   r   r   r!   r  r)   r)   r*   r  X  s   (@z"airyaiprime._eval_rewrite_as_hyperc                 K   s"  | j d }|j}t|dkr| }td|gd}td|gd}td|gd}td|gd}|||||  |  }	|	d ur|	| }d| jr|	| }|	| }|	| }|| |||   |||  |  }
|||  |||   }tj|
tj	 t
| |
tj	 td t|   S d S d S d S r  )r&   r   r  r  r	   r  rD   r   rz   ra   r  r   r   r  r)   r)   r*   rP   ]  *   

$2zairyaiprime._eval_expand_funcNr  rX   rY   rZ   r[   r  r  r]   r4   r<   r   r   rr   r  rP   r)   r)   r)   r*   r    s    Q


r  c                   @   r"  )r   a<  
    The derivative $\operatorname{Bi}^\prime$ of the Airy function of the first
    kind.

    Explanation
    ===========

    The Airy function $\operatorname{Bi}^\prime(z)$ is defined to be the
    function

    .. math::
        \operatorname{Bi}^\prime(z) := \frac{\mathrm{d} \operatorname{Bi}(z)}{\mathrm{d} z}.

    Examples
    ========

    Create an Airy function object:

    >>> from sympy import airybiprime
    >>> from sympy.abc import z

    >>> airybiprime(z)
    airybiprime(z)

    Several special values are known:

    >>> airybiprime(0)
    3**(1/6)/gamma(1/3)
    >>> from sympy import oo
    >>> airybiprime(oo)
    oo
    >>> airybiprime(-oo)
    0

    The Airy function obeys the mirror symmetry:

    >>> from sympy import conjugate
    >>> conjugate(airybiprime(z))
    airybiprime(conjugate(z))

    Differentiation with respect to $z$ is supported:

    >>> from sympy import diff
    >>> diff(airybiprime(z), z)
    z*airybi(z)
    >>> diff(airybiprime(z), z, 2)
    z*airybiprime(z) + airybi(z)

    Series expansion is also supported:

    >>> from sympy import series
    >>> series(airybiprime(z), z, 0, 3)
    3**(1/6)/gamma(1/3) + 3**(5/6)*z**2/(6*gamma(2/3)) + O(z**3)

    We can numerically evaluate the Airy function to arbitrary precision
    on the whole complex plane:

    >>> airybiprime(-2).evalf(50)
    0.27879516692116952268509756941098324140300059345163

    Rewrite $\operatorname{Bi}^\prime(z)$ in terms of hypergeometric functions:

    >>> from sympy import hyper
    >>> airybiprime(z).rewrite(hyper)
    3**(5/6)*z**2*hyper((), (5/3,), z**3/9)/(6*gamma(2/3)) + 3**(1/6)*hyper((), (1/3,), z**3/9)/gamma(1/3)

    See Also
    ========

    airyai: Airy function of the first kind.
    airybi: Airy function of the second kind.
    airyaiprime: Derivative of the Airy function of the first kind.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Airy_function
    .. [2] http://dlmf.nist.gov/9
    .. [3] http://www.encyclopediaofmath.org/index.php/Airy_functions
    .. [4] http://mathworld.wolfram.com/AiryFunctions.html

    r-   Tc                 C   s~   |j r,|tju rtjS |tju rtjS |tju rtjS |jr,dtdd ttdd S |jr=dtdd ttdd S d S )Nr   r-   r  )	r   r   re   rf   rg   rb   rL   r   r   r   r)   r)   r*   r4     s   


zairybiprime.evalc                 C   r#  r   )r&   r  r   r:   r)   r)   r*   r<     r$  zairybiprime.fdiffc                 C   r%  r&  )	r   r'  r(  rk   r   r&   r   r  r   r)  r)   r)   r*   r     r+  zairybiprime._eval_evalfc                 K   sR   t dd}|t| t dd }t|jr'| td t| |t||  S d S r,  r  r-  r)   r)   r*   r     s
   

$z$airybiprime._eval_rewrite_as_besseljc                 K   s   t dd}t dd}|t|t dd }t|jr*|td t| |t||  S t|t dd}t||}t|| }t||t| ||  |d | t|||    S r  r  r!  r)   r)   r*   rr     s   


"
6z$airybiprime._eval_rewrite_as_besselic                 K   s|   |d dt dd ttdd  }t ddttdd }|tg tddg|d d  |tg tddg|d d   S )Nr5   r   r  r-   r.  r  )r   r   r   r!   r  r)   r)   r*   r    s   $@z"airybiprime._eval_rewrite_as_hyperc                 K   s"  | j d }|j}t|dkr| }td|gd}td|gd}td|gd}td|gd}|||||  |  }	|	d ur|	| }d| jr|	| }|	| }|	| }|| |||   |||  |  }
|||  |||   }tjt	d|
tj
  t| |
tj
 t|   S d S d S d S r  )r&   r   r  r  r	   r  rD   r   rz   r   ra   r  r   r  r)   r)   r*   rP     r/  zairybiprime._eval_expand_funcNr  r0  r)   r)   r)   r*   r   w  s    S

r   c                   @   sF   e Zd ZdZedd ZdddZdd Zd	d
 Zdd Z	dd Z
dS )marcumqa  
    The Marcum Q-function.

    Explanation
    ===========

    The Marcum Q-function is defined by the meromorphic continuation of

    .. math::
        Q_m(a, b) = a^{- m + 1} \int_{b}^{\infty} x^{m} e^{- \frac{a^{2}}{2} - \frac{x^{2}}{2}} I_{m - 1}\left(a x\right)\, dx

    Examples
    ========

    >>> from sympy import marcumq
    >>> from sympy.abc import m, a, b
    >>> marcumq(m, a, b)
    marcumq(m, a, b)

    Special values:

    >>> marcumq(m, 0, b)
    uppergamma(m, b**2/2)/gamma(m)
    >>> marcumq(0, 0, 0)
    0
    >>> marcumq(0, a, 0)
    1 - exp(-a**2/2)
    >>> marcumq(1, a, a)
    1/2 + exp(-a**2)*besseli(0, a**2)/2
    >>> marcumq(2, a, a)
    1/2 + exp(-a**2)*besseli(0, a**2)/2 + exp(-a**2)*besseli(1, a**2)

    Differentiation with respect to $a$ and $b$ is supported:

    >>> from sympy import diff
    >>> diff(marcumq(m, a, b), a)
    a*(-marcumq(m, a, b) + marcumq(m + 1, a, b))
    >>> diff(marcumq(m, a, b), b)
    -a**(1 - m)*b**m*exp(-a**2/2 - b**2/2)*besseli(m - 1, a*b)

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Marcum_Q-function
    .. [2] http://mathworld.wolfram.com/MarcumQ-Function.html

    c                 C   sd  ddl m}m} |tju r(|tju r|tju rtjS |||d tj t| S |tju r?|tju r?dd||d tj   S ||kr|tju r[d||d  td|d   tj S |dkrtjtj||d   td|d   ||d  td|d   S |j	r|j	r|j	rtjS |||d tj t| S |j	r|j	rdd||d tj   S d S d S )Nr   )r   
uppergammar5   r-   )
rk   r   r2  r   rb   rz   r   ra   rG   rL   )r1   r  rN   r   r   r2  r)   r)   r*   r4   N  s&   

&Dzmarcumq.evalr5   c                 C   s   ddl m} | j\}}}|dkr!|t||| td| ||  S |dkrF||  ||d   ||d |d   d  t|d ||  S t| |)Nr   r   r5   r-   r   )rk   r   r&   r1  rG   r   )r(   r;   r   r  rN   r   r)   r)   r*   r<   g  s   "B
zmarcumq.fdiffc           
      K   st   ddl m}m}m}m} |d|d}	|d|  ||	| ||	d |d   d  t|d ||	  |	||g S )Nr   )Integralr   DummyoorM   r-   r5   )rk   r4  r   r5  r6  getrG   )
r(   r  rN   r   rU   r4  r   r5  r6  rM   r)   r)   r*   _eval_rewrite_as_Integralq  s
   
>z!marcumq._eval_rewrite_as_Integralc           
      K   sl   ddl m}m}m}m} |d|d}	||d |d   d ||| |	 t|	||  |	d| |g S )Nr   )Sumr   r5  r6  r   r5   r-   )rk   r9  r   r5  r6  r7  rG   )
r(   r  rN   r   rU   r9  r   r5  r6  r   r)   r)   r*   _eval_rewrite_as_Sumw  s   Dzmarcumq._eval_rewrite_as_Sumc                    s    |krQddl m} |dkr d| d  td d   d S |jrS|dkrUt fddtd|D }tj| d  td d  d  | d  |  S d S d S d S )Nr   r3  r-   r5   c                    s   g | ]	}t | d  qS rW   )rG   )r   r   rN   r)   r*   r     s    z4marcumq._eval_rewrite_as_besseli.<locals>.<listcomp>)rk   r   rG   r   sumr   r   rz   )r(   r  rN   r   rU   r   r   r)   r;  r*   rr   |  s   $8z marcumq._eval_rewrite_as_besselic                 C   s   t dd | jD rdS d S )Nc                 s   s    | ]}|j V  qd S r/   )rL   )r   r   r)   r)   r*   	<genexpr>  s    z(marcumq._eval_is_zero.<locals>.<genexpr>T)allr&   r'   r)   r)   r*   _eval_is_zero  s   zmarcumq._eval_is_zeroNrW   )rX   rY   rZ   r[   r]   r4   r<   r8  r:  rr   r?  r)   r)   r)   r*   r1    s    0


	r1  N)rk   r   )F	functoolsr   rk   r   r   r   r   r   r	   r
   r   Zsympy.core.functionr   r   r   Zsympy.core.logicr   r   Zsympy.core.powerr   Z(sympy.functions.combinatorial.factorialsr   Z(sympy.functions.elementary.trigonometricr   r   r   r   Z#sympy.functions.elementary.integersr   Z$sympy.functions.elementary.complexesr   Z&sympy.functions.elementary.exponentialr   r   Z(sympy.functions.elementary.miscellaneousr   r   r   r   Z'sympy.functions.special.gamma_functionsr   r    Zsympy.functions.special.hyperr!   Zsympy.polys.orthopolysr"   r   r#   rF   rt   rG   r   r   r   r   r   r   r   rJ   rK   r   rH   rI   r   r   r   r  r  r   r1  r)   r)   r)   r*   <module>   sX    (F $ bR./XB98
8U - 2   '