U
    ZÊ¹jè÷  ã                   @   s¢  d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZmZmZ d dlmZmZ d dlmZmZmZ d d	lmZ d d
lmZ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'm(Z( d dl)m*Z*m+Z+m,Z, d dl-m.Z.m/Z/m0Z0m1Z1m2Z2 d dl3m4Z4m5Z5m6Z6 d dl7m8Z8 d dl9m:Z: d dl;m<Z<m=Z= G dd„ deƒZ>G dd„ de>ƒZ?G dd„ de>ƒZ@G dd„ de>ƒZAG dd„ de>ƒZBG d d!„ d!e>ƒZCG d"d#„ d#e>ƒZDd$d%„ ZEG d&d'„ d'e>ƒZFd(d)„ ZGd*d+„ ZHG d,d-„ d-eFƒZIG d.d/„ d/eFƒZJG d0d1„ d1eFƒZKG d2d3„ d3eKƒZLG d4d5„ d5eKƒZMdGd8d9„ZNG d:d;„ d;eƒZOG d<d=„ d=eOƒZPG d>d?„ d?eOƒZQG d@dA„ dAeOƒZRG dBdC„ dCeOƒZSG dDdE„ dEeƒZTdFS )Hé    ©Úwraps)ÚS)ÚAdd)Úcacheit)ÚExpr)ÚFunctionÚArgumentIndexErrorÚ_mexpand)Úfuzzy_orÚ	fuzzy_not)ÚRationalÚpiÚI)ÚPow)ÚDummyÚuniquely_named_symbolÚWild)Úsympify)Ú	factorial)ÚsinÚcosÚcscÚcot)Úceiling)ÚexpÚlog)ÚcbrtÚsqrtÚroot)ÚAbsÚreÚimÚ
polar_liftÚ
unpolarify)ÚgammaÚdigammaÚ
uppergamma)Úhyper)Úspherical_bessel_fn)ÚmpÚworkprecc                   @   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   s
   | j d S )z( The order of the Bessel-type function. r   ©Úargs©Úself© r1   ú]/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sympy/functions/special/bessel.pyÚorder4   s    zBesselBase.orderc                 C   s
   | j d S )z+ The argument of the Bessel-type function. é   r-   r/   r1   r1   r2   Úargument9   s    zBesselBase.argumentc                 C   s   d S ©Nr1   ©ÚclsÚnuÚzr1   r1   r2   Úeval>   s    zBesselBase.evalé   c                 C   sN   |dkrt | |ƒ‚| jd |  | jd | j¡ | jd |  | jd | j¡  S ©Nr<   r4   )r	   Ú_bÚ	__class__r3   r5   Ú_a©r0   Úargindexr1   r1   r2   ÚfdiffB   s
    
ÿzBesselBase.fdiffc                 C   s*   | j }|jdkr&|  | j ¡ | ¡ ¡S d S ©NF)r5   Úis_extended_negativer?   r3   Ú	conjugate©r0   r:   r1   r1   r2   Ú_eval_conjugateH   s    
zBesselBase._eval_conjugatec                 C   sx   | j | j }}| |¡rdS | ||¡s,d S | ||¡}|jrdt| ttt	t
ttfƒsZ|jsdt|jƒS tt|j|jgƒƒS rD   )r3   r5   ÚhasÚ_eval_is_meromorphicÚsubsÚ
is_integerÚ
isinstanceÚbesseljÚbesseliÚhn1Úhn2ÚjnÚynÚis_zeror   Úis_infiniter   )r0   ÚxÚar9   r:   Zz0r1   r1   r2   rJ   M   s    

zBesselBase._eval_is_meromorphicc                 K   sÂ   | j | j| j  }}}|jr¾|d jrn| j | j ||d |ƒ ¡  d| j |d  ||d |ƒ ¡  |  S |d jr¾d| j |d  ||d |ƒ ¡  | | j| j ||d |ƒ ¡   S | S ©Nr4   r<   )	r3   r5   r?   Zis_realÚis_positiver@   r>   Ú_eval_expand_funcÚis_negative)r0   Úhintsr9   r:   Úfr1   r1   r2   rZ   Z   s    
&ÿ
&ÿzBesselBase._eval_expand_funcc                 K   s   ddl m} || ƒS )Nr   )Ú
besselsimp)Zsympy.simplify.simplifyr^   )r0   Úkwargsr^   r1   r1   r2   Ú_eval_simplifye   s    zBesselBase._eval_simplifyN)r<   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr3   r5   Úclassmethodr;   rC   rH   rJ   rZ   r`   r1   r1   r1   r2   r,   $   s   



r,   c                       sh   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‡ fdd„	Zdd„ Zd‡ fdd„	Z‡  ZS )rN   a4  
    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] https://functions.wolfram.com/Bessel-TypeFunctions/BesselJ/

    c                 C   sZ  |j rX|j rtjS |jr"|j dks,t|ƒjr2tjS t|ƒjrL|jdk	rLtjS |j	rXtj
S |tjtjfkrntjS | ¡ r–|| | |   t|| ƒ S |jrÜ| ¡ r¼tj|  t| |ƒ S | t¡}|rÜt| t||ƒ S |j�rt|ƒ}||k�r:t||ƒS n8| ¡ \}}|dk�r:td| t | t ƒt||ƒ S t|ƒ}||k�rVt||ƒS d S )NFTr   r<   )rT   r   ÚOnerL   r!   rY   ÚZeror[   ÚComplexInfinityÚis_imaginaryÚNaNÚInfinityÚNegativeInfinityÚcould_extract_minus_signrN   ÚNegativeOneÚextract_multiplicativelyr   rO   r$   Úextract_branch_factorr   r   ©r8   r9   r:   ZnewzÚnZnnur1   r1   r2   r;   ²   s:     


"
zbesselj.evalc                 K   s(   t tt | d ƒt|tt ƒ| ƒ S ©Nr<   )r   r   r   rO   r#   ©r0   r9   r:   r_   r1   r1   r2   Ú_eval_rewrite_as_besseliÖ   s    z besselj._eval_rewrite_as_besselic                 K   s<   |j dkr8tt| ƒt| |ƒ tt| ƒt||ƒ  S d S rD   )rL   r   r   Úbesselyr   ru   r1   r1   r2   Ú_eval_rewrite_as_besselyÙ   s    
z besselj._eval_rewrite_as_besselyc                 K   s"   t d| t ƒt|tj | jƒ S rt   )r   r   rR   r   ÚHalfr5   ru   r1   r1   r2   Ú_eval_rewrite_as_jnÝ   s    zbesselj._eval_rewrite_as_jnNr   c           
         sÒ   | j \}}z| |¡}W n tk
r0   |  Y S X | |¡\}}|jrb|| d| t|d ƒ  S |jr¾|dkrtdn|}|||  }	|	jsºtdƒt|t	d| d  d  ƒ tt	| ƒ S | S t
t| ƒ |||¡S )Nr<   r4   r   é   )r.   Úas_leading_termÚNotImplementedErrorÚas_coeff_exponentrY   r%   r[   r   r   r   ÚsuperrN   Ú_eval_as_leading_term©
r0   rV   ÚlogxÚcdirr9   r:   ÚargÚcÚeÚsign©r?   r1   r2   r€   à   s    

0zbesselj._eval_as_leading_termc                 C   s   | j \}}|jr|jrdS d S ©NT©r.   rL   Úis_extended_real©r0   r9   r:   r1   r1   r2   Ú_eval_is_extended_realõ   s    
zbesselj._eval_is_extended_realc              	      s&  ddl m} | j\}}z| |¡\}}	W n ttfk
rD   |  Y S X |	j�rt||	 ƒ}
||| |ƒ}|d  ||||¡ 	¡ }|t
jkrŽ|S t|d ƒ|  	¡ }|| t|d ƒ }|g}td|
d d ƒD ]4}|| |||   9 }t|ƒ|  	¡ }| |¡ qÎt|Ž | S tt| ƒ ||||¡S ©Nr   ©ÚOrderr<   r4   )Úsympy.series.orderr�   r.   ÚleadtermÚ
ValueErrorr}   rY   r   Ú_eval_nseriesÚremoveOr   rh   r
   r%   ÚrangeÚappendr   r   rN   ©r0   rV   rs   r‚   rƒ   r�   r9   r:   Ú_r   ÚnewnÚoÚrÚtÚtermÚsÚkrˆ   r1   r2   r”   ú   s*    


zbesselj._eval_nseries)Nr   )r   )ra   rb   rc   rd   r   rg   r@   r>   rf   r;   rv   rx   rz   r€   r�   r”   Ú__classcell__r1   r1   rˆ   r2   rN   j   s   D
#rN   c                       sh   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‡ fdd„	Zdd„ Zd‡ fdd„	Z‡  ZS )rw   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] https://functions.wolfram.com/Bessel-TypeFunctions/BesselY/

    c                 C   sÐ   |j r6|j rtjS t|ƒj dkr&tjS t|ƒj r6tjS |tjtjfkrLtjS |ttj krxt	tt
 |d  d ƒtj S |ttj kr¦t	t t
 |d  d ƒtj S |jrÌ| ¡ rÌtj|  t| |ƒ S d S )NFr4   r<   )rT   r   rm   r!   ri   rk   rl   rh   r   r   r   rL   rn   ro   rw   r7   r1   r1   r2   r;   F  s     
 zbessely.evalc                 K   s<   |j dkr8tt| ƒtt| ƒt||ƒ t| |ƒ  S d S rD   )rL   r   r   r   rN   ru   r1   r1   r2   Ú_eval_rewrite_as_besseljZ  s    
z bessely._eval_rewrite_as_besseljc                 K   s   | j | jŽ }|r| t¡S d S r6   )r¢   r.   ÚrewriterO   ©r0   r9   r:   r_   Zajr1   r1   r2   rv   ^  s    z bessely._eval_rewrite_as_besselic                 K   s"   t d| t ƒt|tj | jƒ S rt   )r   r   rS   r   ry   r5   ru   r1   r1   r2   Ú_eval_rewrite_as_ync  s    zbessely._eval_rewrite_as_ynNr   c                    s~  | j \}}z| |¡}W n tk
r0   |  Y S X | |¡\}}|jrØdt t|d ƒ t||ƒ }	|jrŠ|d |   t|d ƒ t nt	j
}
|d |  tt|ƒ  t|d ƒt	j  }t|	|
|gŽ j||d�}|S |j�rj|dkrìdn|}|||  }|j�sftdƒtt| d | td  ƒ dtt| d | td  ƒ d|    td| ƒ ttƒ S | S tt| ƒ |||¡S )Nr<   r4   ©r‚   r   r{   é   é   )r.   r|   r}   r~   rY   r   r   rN   r   r   rh   r&   Ú
EulerGammar   r[   r   r   r   r   rw   r€   )r0   rV   r‚   rƒ   r9   r:   r„   r…   r†   Úterm_oneÚterm_twoÚ
term_threer‡   rˆ   r1   r2   r€   f  s&    

,,bzbessely._eval_as_leading_termc                 C   s   | j \}}|jr|jrdS d S r‰   ©r.   rL   rY   rŒ   r1   r1   r2   r�     s    
zbessely._eval_is_extended_realc              	      s8  ddl m} | j\}}z| |¡\}}	W n ttfk
rD   |  Y S X |	j�r"|j�r"t||	 ƒ}
t	||ƒ}dt
 t|d ƒ |  ||||¡}g g  }}||| |ƒ}|d  ||||¡ ¡ }|tjkrÎ|S t|d ƒ|  ¡ }|tjk�rp||  t|d ƒ t
 }| |¡ td|ƒD ]R}|| | }|tjk�rF||| 9 }n||| 9 }t|ƒ|  ¡ }| |¡ �q|| t
t|ƒ  }|t|d ƒtj  }| |¡ td|
d d ƒD ]V}|| |||   9 }t|ƒ|  ¡ }|t|| d ƒt|d ƒ  }| |¡ �q¶|t|Ž  t|Ž  S tt| ƒ ||||¡S rŽ   )r‘   r�   r.   r’   r“   r}   rY   rL   r   rN   r   r   r”   r•   r   rh   r
   r   r—   r–   r&   r©   r   r   rw   ©r0   rV   rs   r‚   rƒ   r�   r9   r:   r™   r   rš   ZbnrW   Úbr…   r›   rœ   r�   rž   r    ÚdenomÚprˆ   r1   r2   r”   „  sH    


$



 zbessely._eval_nseries)Nr   )r   )ra   rb   rc   rd   r   rg   r@   r>   rf   r;   r¢   rv   r¥   r€   r�   r”   r¡   r1   r1   rˆ   r2   rw     s   (
rw   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‡ fdd„	Zd‡ fdd„	Z‡  ZS )rO   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] https://functions.wolfram.com/Bessel-TypeFunctions/BesselI/

    c                 C   s‚  |j rX|j rtjS |jr"|j dks,t|ƒjr2tjS t|ƒjrL|jdk	rLtjS |j	rXtj
S t|ƒtjtjfkrrtjS |tjkr‚tjS |tjkršd| tj S | ¡ rÂ|| | |   t|| ƒ S |j�r| ¡ rÞt| |ƒS | t¡}|�rt|  t|| ƒ S |j�r*t|ƒ}||k�rbt||ƒS n8| ¡ \}}|dk�rbtd| t | t ƒt||ƒ S t|ƒ}||k�r~t||ƒS d S )NFTéÿÿÿÿr   r<   )rT   r   rg   rL   r!   rY   rh   r[   ri   rj   rk   r"   rl   rm   rn   rO   rp   r   rN   r$   rq   r   r   rr   r1   r1   r2   r;   á  sB    

 


"
zbesseli.evalc                 K   s(   t t t | d ƒt|ttƒ| ƒ S rt   )r   r   r   rN   r#   ru   r1   r1   r2   r¢   	  s    z besseli._eval_rewrite_as_besseljc                 K   s   | j | jŽ }|r| t¡S d S r6   ©r¢   r.   r£   rw   r¤   r1   r1   r2   rx     s    z besseli._eval_rewrite_as_besselyc                 K   s   | j | jŽ  t¡S r6   )r¢   r.   r£   rR   ru   r1   r1   r2   rz     s    zbesseli._eval_rewrite_as_jnc                 C   s   | j \}}|jr|jrdS d S r‰   rŠ   rŒ   r1   r1   r2   r�     s    
zbesseli._eval_is_extended_realNr   c           
         sº   | j \}}z| |¡}W n tk
r0   |  Y S X | |¡\}}|jrb|| d| t|d ƒ  S |jr¦|dkrtdn|}|||  }	|	js¢t|ƒtdt	 | ƒ S | S t
t| ƒ |||¡S ©Nr<   r4   r   )r.   r|   r}   r~   rY   r%   r[   r   r   r   r   rO   r€   r�   rˆ   r1   r2   r€     s    

zbesseli._eval_as_leading_termc              	      s$  ddl m} | j\}}z| |¡\}}	W n ttfk
rD   |  Y S X |	j�rt||	 ƒ}
||| |ƒ}|d  ||||¡ 	¡ }|t
jkrŽ|S t|d ƒ|  	¡ }|| t|d ƒ }|g}td|
d d ƒD ]2}|||||   9 }t|ƒ|  	¡ }| |¡ qÎt|Ž | S tt| ƒ ||||¡S rŽ   )r‘   r�   r.   r’   r“   r}   rY   r   r”   r•   r   rh   r
   r%   r–   r—   r   r   rO   r˜   rˆ   r1   r2   r”   .  s*    


zbesseli._eval_nseries)Nr   )r   )ra   rb   rc   rd   r   rg   r@   r>   rf   r;   r¢   rx   rz   r�   r€   r”   r¡   r1   r1   rˆ   r2   rO   ¶  s   '
'rO   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‡ fdd„	Zd‡ fdd„	Z‡  Z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] https://functions.wolfram.com/Bessel-TypeFunctions/BesselK/

    c                 C   sv   |j r6|j rtjS t|ƒj dkr&tjS t|ƒj r6tjS |tjttj ttj fkrXtjS |j	rr| 
¡ rrt| |ƒS d S rD   )rT   r   rl   r!   ri   rk   r   rm   rh   rL   rn   rµ   r7   r1   r1   r2   r;   w  s    
zbesselk.evalc                 K   s8   |j dkr4ttt| ƒ t| |ƒt||ƒ  d S d S )NFr<   )rL   r   r   rO   ru   r1   r1   r2   rv   ‡  s    
z besselk._eval_rewrite_as_besselic                 K   s   | j | jŽ }|r| t¡S d S r6   )rv   r.   r£   rN   )r0   r9   r:   r_   Zair1   r1   r2   r¢   ‹  s    z besselk._eval_rewrite_as_besseljc                 K   s   | j | jŽ }|r| t¡S d S r6   r³   r¤   r1   r1   r2   rx   �  s    z besselk._eval_rewrite_as_besselyc                 K   s   | j | jŽ }|r| t¡S d S r6   )rx   r.   r£   rS   )r0   r9   r:   r_   Zayr1   r1   r2   r¥   •  s    zbesselk._eval_rewrite_as_ync                 C   s   | j \}}|jr|jrdS d S r‰   r­   rŒ   r1   r1   r2   r�   š  s    
zbesselk._eval_is_extended_realNr   c                    s  | j \}}z| |¡}W n tk
r0   |  Y S X | |¡\}}|jràd|d  t|d ƒ t||ƒ }	|jrŒ|d |  t|d ƒ d ntj	}
d| |d |  dt|ƒ  t
|d ƒtj  }t|	|
|gŽ j||d�}|S |j�rttƒt| ƒ td| ƒ S tt| ƒ |||¡S )Nr²   r4   r<   r¦   )r.   r|   r}   r~   rY   r   rO   r   r   rh   r&   r©   r   r[   r   r   r   r   rµ   r€   )r0   rV   r‚   rƒ   r9   r:   r„   r™   r†   rª   r«   r¬   rˆ   r1   r2   r€   Ÿ  s    

"*2zbesselk._eval_as_leading_termc              	      sB  ddl m} | j\}}z| |¡\}}	W n ttfk
rD   |  Y S X |	j�r,|j�r,t||	 ƒ}
t	||ƒ}d|d  t
|d ƒ |  ||||¡}g g  }}||| |ƒ}|d  ||||¡ ¡ }|tjkrÒ|S t|d ƒ|  ¡ }|tjk�rt||  t|d ƒ d }| |¡ td|ƒD ]R}|| | }|tjk�rJ||| 9 }n||| 9 }t|ƒ|  ¡ }| |¡ �q || d|  dt|ƒ  }|t|d ƒtj  }| |¡ td|
d d ƒD ]T}|||||   9 }t|ƒ|  ¡ }|t|| d ƒt|d ƒ  }| |¡ �qÂ|t|Ž  t|Ž  S tt| ƒ ||||¡S )Nr   r�   r²   r4   r<   )r‘   r�   r.   r’   r“   r}   rY   rL   r   rO   r   r”   r•   r   rh   r
   r   r—   r–   r&   r©   r   r   rµ   r®   rˆ   r1   r2   r”   ´  sH    


(



 zbesselk._eval_nseries)Nr   )r   )ra   rb   rc   rd   r   rg   r@   r>   rf   r;   rv   r¢   rx   r¥   r�   r€   r”   r¡   r1   r1   rˆ   r2   rµ   N  s   %
rµ   c                   @   s$   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] https://functions.wolfram.com/Bessel-TypeFunctions/HankelH1/

    c                 C   s(   | j }|jdkr$t| j ¡ | ¡ ƒS d S rD   )r5   rE   Úhankel2r3   rF   rG   r1   r1   r2   rH     s    
zhankel1._eval_conjugateN©	ra   rb   rc   rd   r   rg   r@   r>   rH   r1   r1   r1   r2   r¶   æ  s   $r¶   c                   @   s$   e Zd ZdZejZejZdd„ ZdS )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] https://functions.wolfram.com/Bessel-TypeFunctions/HankelH2/

    c                 C   s(   | j }|jdkr$t| j ¡ | ¡ ƒS d S rD   )r5   rE   r¶   r3   rF   rG   r1   r1   r2   rH   =  s    
zhankel2._eval_conjugateNr¸   r1   r1   r1   r2   r·     s   %r·   c                    s   t ˆ ƒ‡ fdd„ƒ}|S )Nc                    s   |j rˆ | ||ƒS d S r6   )rL   rŒ   ©Úfnr1   r2   ÚgD  s    zassume_integer_order.<locals>.gr   )rº   r»   r1   r¹   r2   Úassume_integer_orderC  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ƒ‚dS )z@ Expand self into a polynomial. Nu is guaranteed to be Integer. Z	expansionN©r}   ©r0   r\   r1   r1   r2   Ú_expandW  s    zSphericalBesselBase._expandc                 K   s   | j jr| jf |ŽS | S r6   )r3   Ú
is_IntegerrÀ   r¿   r1   r1   r2   rZ   [  s    z%SphericalBesselBase._eval_expand_funcr<   c                 C   s:   |dkrt | |ƒ‚|  | jd | j¡| | jd  | j  S r=   )r	   r?   r3   r5   rA   r1   r1   r2   rC   `  s
    
ÿzSphericalBesselBase.fdiffN)r<   )ra   rb   rc   rd   rÀ   rZ   rC   r1   r1   r1   r2   r½   K  s   r½   c                 C   s8   t | |ƒt|ƒ tj| d  t |  d |ƒ t|ƒ  S ©Nr4   )r)   r   r   ro   r   ©rs   r:   r1   r1   r2   Ú_jng  s    $ÿrÄ   c                 C   s8   t j| d  t|  d |ƒ t|ƒ t| |ƒt|ƒ  S rÂ   )r   ro   r)   r   r   rÃ   r1   r1   r2   Ú_ynl  s    $ÿ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 )rR   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] https://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kr@tjS d S r6   )	rT   r   rg   rL   rY   rh   ri   rm   rl   r7   r1   r1   r2   r;   ¬  s    zjn.evalc                 K   s    t td|  ƒt|tj |ƒ S rt   )r   r   rN   r   ry   ru   r1   r1   r2   r¢   ¹  s    zjn._eval_rewrite_as_besseljc                 K   s,   t j| ttd|  ƒ t| t j |ƒ S rt   )r   ro   r   r   rw   ry   ru   r1   r1   r2   rx   ¼  s    zjn._eval_rewrite_as_besselyc                 K   s   t j| t| d |ƒ S rÂ   )r   ro   rS   ru   r1   r1   r2   r¥   ¿  s    zjn._eval_rewrite_as_ync                 K   s   t | j| jƒS r6   )rÄ   r3   r5   r¿   r1   r1   r2   rÀ   Â  s    z
jn._expandc                 C   s   | j jr|  t¡ |¡S d S r6   ©r3   rÁ   r£   rN   Ú_eval_evalf©r0   Úprecr1   r1   r2   rÇ   Å  s    zjn._eval_evalfN)ra   rb   rc   rd   rf   r;   r¢   rx   r¥   rÀ   rÇ   r1   r1   r1   r2   rR   r  s   9
rR   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 )rS   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] https://dlmf.nist.gov/10.47

    c                 K   s0   t j|d  ttd|  ƒ t| t j |ƒ S rX   )r   ro   r   r   rN   ry   ru   r1   r1   r2   r¢   ù  s    zyn._eval_rewrite_as_besseljc                 K   s    t td|  ƒt|tj |ƒ S rt   )r   r   rw   r   ry   ru   r1   r1   r2   rx   ý  s    zyn._eval_rewrite_as_besselyc                 K   s   t j|d  t| d |ƒ S rÂ   )r   ro   rR   ru   r1   r1   r2   rz     s    zyn._eval_rewrite_as_jnc                 K   s   t | j| jƒS r6   )rÅ   r3   r5   r¿   r1   r1   r2   rÀ     s    z
yn._expandc                 C   s   | j jr|  t¡ |¡S d S r6   )r3   rÁ   r£   rw   rÇ   rÈ   r1   r1   r2   rÇ     s    zyn._eval_evalfN)
ra   rb   rc   rd   r¼   r¢   rx   rz   rÀ   rÇ   r1   r1   r1   r2   rS   Ê  s   .

rS   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   sN   | j }ttd|  ƒt|tj |ƒ|t tj|d   t| tj |ƒ   S r=   )Ú_hankel_kind_signr   r   rN   r   ry   r   ro   ©r0   r9   r:   r_   Úhksr1   r1   r2   r¢     s    &ÿz,SphericalHankelBase._eval_rewrite_as_besseljc                 K   sJ   | j }ttd|  ƒtj| t| tj |ƒ |t t|tj |ƒ   S rt   )rË   r   r   r   ro   rw   ry   r   rÌ   r1   r1   r2   rx     s    (ÿz,SphericalHankelBase._eval_rewrite_as_besselyc                 K   s(   | j }t||ƒ t¡|t t||ƒ  S r6   )rË   rR   r£   rS   r   rÌ   r1   r1   r2   r¥      s    z'SphericalHankelBase._eval_rewrite_as_ync                 K   s(   | j }t||ƒ|t t||ƒ t¡  S r6   )rË   rR   r   rS   r£   rÌ   r1   r1   r2   rz   $  s    z'SphericalHankelBase._eval_rewrite_as_jnc                 K   sF   | j jr| jf |ŽS | j }| j}| j}t||ƒ|t t||ƒ  S d S r6   )r3   rÁ   rÀ   r5   rË   rR   r   rS   )r0   r\   r9   r:   rÍ   r1   r1   r2   rZ   (  s    z%SphericalHankelBase._eval_expand_funcc                 K   s2   | j }| j}| j}t||ƒ|t t||ƒ   ¡ S r6   )r3   r5   rË   rÄ   r   rÅ   Úexpand)r0   r\   rs   r:   rÍ   r1   r1   r2   rÀ   1  s    
zSphericalHankelBase._expandc                 C   s   | j jr|  t¡ |¡S d S r6   rÆ   rÈ   r1   r1   r2   rÇ   @  s    zSphericalHankelBase._eval_evalfN)ra   rb   rc   r¼   r¢   rx   r¥   rz   rZ   rÀ   rÇ   r1   r1   r1   r2   rÊ     s   

	rÊ   c                   @   s"   e Zd ZdZejZedd„ ƒZdS )rP   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] https://dlmf.nist.gov/10.47

    c                 K   s   t td|  ƒt||ƒ S rt   )r   r   r¶   ru   r1   r1   r2   Ú_eval_rewrite_as_hankel1x  s    zhn1._eval_rewrite_as_hankel1N)	ra   rb   rc   rd   r   rg   rË   r¼   rÏ   r1   r1   r1   r2   rP   E  s   0rP   c                   @   s$   e Zd ZdZej Zedd„ ƒZdS )rQ   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] https://dlmf.nist.gov/10.47

    c                 K   s   t td|  ƒt||ƒ S rt   )r   r   r·   ru   r1   r1   r2   Ú_eval_rewrite_as_hankel2°  s    zhn2._eval_rewrite_as_hankel2N)	ra   rb   rc   rd   r   rg   rË   r¼   rÐ   r1   r1   r1   r2   rQ   }  s   0rQ   Úsympyé   c                    s  ddl m} ˆdkrTddlm‰  ddlm} ||ƒ‰‡ ‡‡fdd„td|d ƒD ƒS ˆd	kr¸dd
lm‰ zddl	m
‰ ‡‡fdd„}W qÀ tk
r´   ddl	m‰ ‡‡fdd„}Y qÀX n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
      <https://mpmath.org/doc/current/functions/bessel.html#mpmath.besseljzero>`_
    * method = "scipy": uses the
      `SciPy's sph_jn <https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.jn_zeros.html>`_
      and
      `newton <https://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   rÑ   )Úbesseljzero)Údps_to_precc                    s0   g | ](}t  ˆ tˆd  ƒ ˆ¡t|ƒƒˆ¡‘qS )g      à?)r   Ú_from_mpmathr   Ú
_to_mpmathÚint)Ú.0Úl)rÓ   rs   rÉ   r1   r2   Ú
<listcomp>è  s   þÿÿzjn_zeros.<locals>.<listcomp>r4   Úscipy)Únewton)Úspherical_jnc                    s
   ˆˆ | ƒS r6   r1   ©rV   )rs   rÝ   r1   r2   Ú<lambda>ï  ó    zjn_zeros.<locals>.<lambda>)Úsph_jnc                    s   ˆˆ | ƒd d S )Nr   r²   r1   rÞ   )rs   rá   r1   r2   rß   ò  rà   úUnknown method.c                    s    ˆ dkrˆ| |ƒ}nt dƒ‚|S )NrÛ   râ   r¾   )r]   rV   r   )ÚmethodrÜ   r1   r2   Úsolverö  s    zjn_zeros.<locals>.solver)Úmathr   ÚmpmathrÓ   Zmpmath.libmp.libmpfrÔ   r–   Zscipy.optimizerÜ   Zscipy.specialrÝ   ÚImportErrorrá   r}   r—   )rs   r    rã   ZdpsZmath_pirÔ   r]   rä   r   ÚrootsÚir1   )rÓ   rã   rs   rÜ   rÉ   rá   rÝ   r2   Újn_zerosµ  s2    -þ
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 ©Nr   )Úfuncr.   rF   r/   r1   r1   r2   rH     s    zAiryBase._eval_conjugatec                 C   s   | j d jS rì   )r.   r‹   r/   r1   r1   r2   r�     s    zAiryBase._eval_is_extended_realTc                 K   sL   | j d }| ¡ }| j}||ƒ||ƒ d }t||ƒ||ƒ  d }||fS )Nr   r<   )r.   rF   rí   r   )r0   Údeepr\   r:   Zzcr]   ÚuÚvr1   r1   r2   Úas_real_imag  s    
zAiryBase.as_real_imagc                 K   s$   | j f d|i|—Ž\}}||t  S )Nrî   )rñ   r   )r0   rî   r\   Zre_partZim_partr1   r1   r2   Ú_eval_expand_complex  s    zAiryBase._eval_expand_complexN)T)T)ra   rb   rc   rd   rH   r�   rñ   rò   r1   r1   r1   r2   rë   	  s
   
rë   c                   @   s^   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] https://dlmf.nist.gov/9
    .. [3] https://encyclopediaofmath.org/wiki/Airy_functions
    .. [4] https://mathworld.wolfram.com/AiryFunctions.html

    r4   Tc                 C   sŠ   |j r^|tjkrtjS |tjkr&tjS |tjkr6tjS |jr^tjdtddƒ t	tddƒƒ  S |jr†tjdtddƒ t	tddƒƒ  S d S )Nr§   r<   )
Ú	is_Numberr   rk   rl   rh   rm   rT   rg   r   r%   ©r8   r„   r1   r1   r2   r;   €  s    


"zairyai.evalc                 C   s$   |dkrt | jd ƒS t| |ƒ‚d S ©Nr4   r   )Úairyaiprimer.   r	   rA   r1   r1   r2   rC   Ž  s    zairyai.fdiffc                 G   s:  | dk rt jS t|ƒ}t|ƒdkrÔ|d }tdƒ| |   t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tddƒt | t j
  ƒ t| ƒ tdƒ| |   S d S )Nr   r4   r²   r§   r<   r{   )r   rh   r   Úlenr   r   r   r   r   r%   rg   ©rs   rV   Zprevious_termsr±   r1   r1   r2   Útaylor_term”  s"    Lÿ@ÿÿHÿÿ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 ©Nr4   r§   r<   ©r   r   r!   r[   r   rN   ©r0   r:   r_   ÚotÚttrW   r1   r1   r2   r¢   £  s
    


zairyai._eval_rewrite_as_besseljc                 K   s˜   t ddƒ}t ddƒ}t|t ddƒƒ}t|ƒjrX|t|ƒ t| || ƒt||| ƒ  S |t||ƒt| || ƒ |t|| ƒ t||| ƒ   S d S rû   ©r   r   r!   rY   r   rO   rý   r1   r1   r2   rv   ª  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§   r<   r4   é	   r{   )r   rg   r   r%   r   r(   ©r0   r:   r_   Zpf1Zpf2r1   r1   r2   Ú_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 k	�r|	| }d| j�r|	| }|	| }|	| }|||  | || |||    }
|||  |||   }tj|
tj	 t
|ƒ |
tj	 tdƒ t|ƒ   S d S ©	Nr   r4   r…   )ÚexcludeÚdÚmrs   r§   )r.   Úfree_symbolsrø   Úpopr   ÚmatchrL   r   ry   rg   ró   r   Úairybi©r0   r\   r„   Zsymbsr:   r…   r  r  rs   ÚMÚpfZnewargr1   r1   r2   rZ   ¸  s$    

$zairyai._eval_expand_funcN)r4   ©ra   rb   rc   rd   ÚnargsÚ
unbranchedrf   r;   rC   Ústaticmethodr   rú   r¢   rv   r  rZ   r1   r1   r1   r2   ró   $  s   X

	ró   c                   @   s^   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 )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] https://dlmf.nist.gov/9
    .. [3] https://encyclopediaofmath.org/wiki/Airy_functions
    .. [4] https://mathworld.wolfram.com/AiryFunctions.html

    r4   Tc                 C   sŠ   |j r^|tjkrtjS |tjkr&tjS |tjkr6tjS |jr^tjdtddƒ t	tddƒƒ  S |jr†tjdtddƒ t	tddƒƒ  S d S )Nr§   r4   é   r<   )
rô   r   rk   rl   rm   rh   rT   rg   r   r%   rõ   r1   r1   r2   r;   .  s    


"zairybi.evalc                 C   s$   |dkrt | jd ƒS t| |ƒ‚d S rö   )Úairybiprimer.   r	   rA   r1   r1   r2   rC   =  s    zairybi.fdiffc                 G   s  | dk rt jS t|ƒ}t|ƒdkr®|d }tdƒ| tttddƒt | t j	  ƒƒ t
| t j	 t dƒ ƒ | t j	 tttddƒt | t j  ƒƒ t
| d t dƒ ƒ  | S t j	tddƒt  t| t j	 t dƒ ƒ tttddƒt | t j	  ƒƒ t
| ƒ tdƒ| |   S d S )Nr   r4   r²   r§   r<   r  )r   rh   r   rø   r   r    r   r   r   rg   r   r   ry   r   r%   rù   r1   r1   r2   rú   C  s    @<ÿÿHÿÿ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ý   r1   r1   r2   r¢   R  s
    


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 d S rû   r   ©r0   r:   r_   rþ   rÿ   rW   r¯   r…   r1   r1   r2   rv   Y  s    


.
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  r<   r4   r  r{   )r   rg   r   r%   r   r(   r  r1   r1   r2   r  d  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 k	�r|	| }d| j�r|	| }|	| }|	| }|||  | || |||    }
|||  |||   }tjt	dƒtj
|
  t|ƒ tj
|
 t|ƒ   S d S r  )r.   r  rø   r	  r   r
  rL   r   ry   r   rg   ró   r  r  r1   r1   r2   rZ   i  s$    

$zairybi._eval_expand_funcN)r4   r  r1   r1   r1   r2   r  Ð  s   Z

r  c                   @   sV   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] https://dlmf.nist.gov/9
    .. [3] https://encyclopediaofmath.org/wiki/Airy_functions
    .. [4] https://mathworld.wolfram.com/AiryFunctions.html

    r4   Tc                 C   sR   |j r&|tjkrtjS |tjkr&tjS |jrNtjdtddƒ ttddƒƒ  S d S )Nr§   r4   )	rô   r   rk   rl   rh   rT   ro   r   r%   rõ   r1   r1   r2   r;   Ö  s    

zairyaiprime.evalc                 C   s.   |dkr | j d t| j d ƒ S t| |ƒ‚d S rö   )r.   ró   r	   rA   r1   r1   r2   rC   á  s    zairyaiprime.fdiffc              	   C   s>   | j d  |¡}t|ƒ� tj|dd�}W 5 Q R X t ||¡S ©Nr   r4   )Z
derivative)r.   rÖ   r+   r*   ró   r   rÕ   ©r0   rÉ   r:   Úresr1   r1   r2   rÇ   ç  s    
zairyaiprime._eval_evalfc                 K   sP   t ddƒ}t| t ddƒƒ}t|ƒjrL|d t| || ƒt||| ƒ  S d S ©Nr<   r§   )r   r   r!   r[   rN   ©r0   r:   r_   rÿ   rW   r1   r1   r2   r¢   í  s    

z$airyaiprime._eval_rewrite_as_besseljc                 K   s¬   t ddƒ}t ddƒ}|t|t ddƒƒ }t|ƒjrP|d t||ƒt| |ƒ  S t|t ddƒƒ}t||ƒ}t|| ƒ}||d | t||| ƒ |t| || ƒ   S d S rû   )r   r   r!   rY   rO   r  r1   r1   r2   rv   ó  s    



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 )Nr<   r§   r4   é   r  )r   r%   r   r(   r  r1   r1   r2   r  ÿ  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 k	�r|	| }d| j�r|	| }|	| }|	| }|| |||   |||  |  }
|||  |||   }tj|
tj	 t
|ƒ |
tj	 tdƒ t|ƒ   S d S r  )r.   r  rø   r	  r   r
  rL   r   ry   rg   r÷   r   r  r  r1   r1   r2   rZ     s$    

$zairyaiprime._eval_expand_funcN)r4   ©ra   rb   rc   rd   r  r  rf   r;   rC   rÇ   r¢   rv   r  rZ   r1   r1   r1   r2   r÷   �  s   Q


r÷   c                   @   sV   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  a6  
    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] https://dlmf.nist.gov/9
    .. [3] https://encyclopediaofmath.org/wiki/Airy_functions
    .. [4] https://mathworld.wolfram.com/AiryFunctions.html

    r4   Tc                 C   s~   |j rX|tjkrtjS |tjkr&tjS |tjkr6tjS |jrXdtddƒ ttddƒƒ S |jrzdtddƒ ttddƒƒ S d S )Nr§   r4   r  )	rô   r   rk   rl   rm   rh   rT   r   r%   rõ   r1   r1   r2   r;   u  s    


zairybiprime.evalc                 C   s.   |dkr | j d t| j d ƒ S t| |ƒ‚d S rö   )r.   r  r	   rA   r1   r1   r2   rC   …  s    zairybiprime.fdiffc              	   C   s>   | j d  |¡}t|ƒ� tj|dd�}W 5 Q R X t ||¡S r  )r.   rÖ   r+   r*   r  r   rÕ   r  r1   r1   r2   rÇ   ‹  s    
zairybiprime._eval_evalfc                 K   sR   t ddƒ}|t| t ddƒƒ }t|ƒjrN| tdƒ t| |ƒt||ƒ  S d S r  rü   r  r1   r1   r2   r¢   ‘  s    

z$airybiprime._eval_rewrite_as_besseljc                 K   s´   t ddƒ}t ddƒ}|t|t ddƒƒ }t|ƒjrT|tdƒ t| |ƒt||ƒ  S t|t ddƒƒ}t||ƒ}t|| ƒ}t|ƒ|t| || ƒ |d | t||| ƒ   S d S rû   r   r  r1   r1   r2   rv   —  s    


"
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 )Nr<   r§   r  r4   r  r  )r   r%   r   r(   r  r1   r1   r2   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 k	�r|	| }d| j�r|	| }|	| }|	| }|| |||   |||  |  }
|||  |||   }tjt	dƒ|
tj
  t|ƒ |
tj
 t|ƒ   S d S r  )r.   r  rø   r	  r   r
  rL   r   ry   r   rg   r÷   r  r  r1   r1   r2   rZ   ¨  s$    

$zairybiprime._eval_expand_funcN)r4   r  r1   r1   r1   r2   r    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] https://mathworld.wolfram.com/MarcumQ-Function.html

    c                 C   sZ  |t jkr@|t jkr$|t jkr$t jS t||d t j ƒt|ƒ S |t jkrn|t jkrnddt|d t j ƒ  S ||krò|t jkr¦dt|d  ƒtd|d ƒ  t j S |dkròt jt jt|d  ƒ td|d ƒ  t|d  ƒtd|d ƒ  S |j�r,|j�r|j�rt jS t||d t j ƒt|ƒ S |j�rV|j�rVddt|d t j ƒ  S d S r´   )	r   rh   r'   ry   r%   r   rg   rO   rT   )r8   r  rW   r¯   r1   r1   r2   r;   ó  s"    

&Dzmarcumq.evalr<   c                 C   sŽ   | j \}}}|dkr6|t|||ƒ td| ||ƒ  S |dkr€||  ||d   t|d |d   d ƒ t|d || ƒ S t| |ƒ‚d S )Nr<   r4   r§   )r.   r  r   rO   r	   )r0   rB   r  rW   r¯   r1   r1   r2   rC     s    "Bzmarcumq.fdiffc                 K   sp   ddl m} | dttdƒjƒ¡}|d|  ||| t|d |d   d ƒ t|d || ƒ ||tj	gƒ S )Nr   )ÚIntegralrV   r4   r<   )
Zsympy.integrals.integralsr  Úgetr   r   Únamer   rO   r   rl   )r0   r  rW   r¯   r_   r  rV   r1   r1   r2   Ú_eval_rewrite_as_Integral  s
    
@ÿz!marcumq._eval_rewrite_as_Integralc                 K   sb   ddl m} | dtdƒ¡}t|d |d   d ƒ||| | t||| ƒ |d| tjgƒ S )Nr   )ÚSumr    r<   r4   )Zsympy.concrete.summationsr"  r  r   r   rO   r   rl   )r0   r  rW   r¯   r_   r"  r    r1   r1   r2   Ú_eval_rewrite_as_Sum  s    zmarcumq._eval_rewrite_as_Sumc                    sš   ˆ |kr–|dkr4dt ˆ d  ƒtdˆ d ƒ  d S |jr–|dkr–t‡ fdd„td|ƒD ƒƒ}tjt ˆ d  ƒtdˆ d ƒ d  t ˆ d  ƒ|  S d S )Nr4   r<   r   c                 3   s   | ]}t |ˆ d  ƒV  qdS )r<   N)rO   )rØ   ré   ©rW   r1   r2   Ú	<genexpr>$  s     z3marcumq._eval_rewrite_as_besseli.<locals>.<genexpr>)r   rO   rÁ   Úsumr–   r   ry   )r0   r  rW   r¯   r_   rŸ   r1   r$  r2   rv     s    $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 r6   )rT   )rØ   r„   r1   r1   r2   r%  (  s     z(marcumq._eval_is_zero.<locals>.<genexpr>T)Úallr.   r/   r1   r1   r2   Ú_eval_is_zero'  s    zmarcumq._eval_is_zeroN)r<   )ra   rb   rc   rd   rf   r;   rC   r!  r#  rv   r(  r1   r1   r1   r2   r  Â  s   0

	r  N)rÑ   rÒ   )UÚ	functoolsr   Z
sympy.corer   Zsympy.core.addr   Zsympy.core.cacher   Zsympy.core.exprr   Zsympy.core.functionr   r	   r
   Zsympy.core.logicr   r   Zsympy.core.numbersr   r   r   Zsympy.core.powerr   Zsympy.core.symbolr   r   r   Zsympy.core.sympifyr   Z(sympy.functions.combinatorial.factorialsr   Z(sympy.functions.elementary.trigonometricr   r   r   r   Z#sympy.functions.elementary.integersr   Z&sympy.functions.elementary.exponentialr   r   Z(sympy.functions.elementary.miscellaneousr   r   r   Z$sympy.functions.elementary.complexesr    r!   r"   r#   r$   Z'sympy.functions.special.gamma_functionsr%   r&   r'   Zsympy.functions.special.hyperr(   Zsympy.polys.orthopolysr)   ræ   r*   r+   r,   rN   rw   rO   rµ   r¶   r·   r¼   r½   rÄ   rÅ   rR   rS   rÊ   rP   rQ   rê   rë   ró   r  r÷   r  r  r1   r1   r1   r2   Ú<module>   sf   F 1   ./XB988
T - 2  %