
    MZd                        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 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.m/Z/m0Z0m1Z1 d dl2m3Z3m4Z4m5Z5 d dl6m7Z7 d dl8m9Z9 d dl:m;Z;m<Z<  G d de      Z= G d de=      Z> G d de=      Z? G d de=      Z@ G d de=      ZA G d  d!e=      ZB G d" d#e=      ZCd$ ZD G d% d&e=      ZEd' ZFd( ZG G d) d*eE      ZH G d+ d,eE      ZI G d- d.eE      ZJ G d/ d0eJ      ZK G d1 d2eJ      ZLdAd3ZM G d4 d5e      ZN G d6 d7eN      ZO G d8 d9eN      ZP G d: d;eN      ZQ G d< d=eN      ZR G d> d?e      ZSy@)B    wraps)S)Add)cacheit)Expr)FunctionArgumentIndexError_mexpand)fuzzy_or	fuzzy_not)RationalpiI)Pow)Dummy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                   `    e Zd ZdZed        Zed        Zed        ZddZ	d Z
d Zd Zd	 Zy
)
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                      | j                   d   S )z( The order of the Bessel-type function. r   argsselfs    @/usr/lib/python3/dist-packages/sympy/functions/special/bessel.pyorderzBesselBase.order4        yy|    c                      | j                   d   S )z+ The argument of the Bessel-type function.    r/   r1   s    r3   argumentzBesselBase.argument9   r5   r6   c                      y N clsnuzs      r3   evalzBesselBase.eval>   s    r6   c                 
   |dk7  rt        | |      | j                  dz  | j                  | j                  dz
  | j                        z  | j
                  dz  | j                  | j                  dz   | j                        z  z
  S N   r8   )r
   _b	__class__r4   r9   _ar2   argindexs     r3   fdiffzBesselBase.fdiffB   sp    q=$T844	DNN4::>4==II	DNN4::>4==IIJ 	Kr6   c                     | j                   }|j                  du r8| j                  | j                  j	                         |j	                               S y NF)r9   is_extended_negativerF   r4   	conjugater2   r@   s     r3   _eval_conjugatezBesselBase._eval_conjugateH   sB    MM!!U*>>$**"6"6"8!++-HH +r6   c           	         | j                   | j                  }}|j                  |      ry|j                  ||      sy |j	                  ||      }|j
                  rKt        | t        t        t        t        t        t        f      s|j                  st        |j                        S t        t!        |j                  |j                  g            S rL   )r4   r9   has_eval_is_meromorphicsubs
is_integer
isinstancebesseljbesselihn1hn2jnynis_zeror   is_infiniter   )r2   xar?   r@   z0s         r3   rS   zBesselBase._eval_is_meromorphicM   s    

DMMA66!9%%a+VVAq\==$'3R DERZZ 002::r~~">?@@r6   c                 D   | j                   | j                  | j                  }}}|j                  r|dz
  j                  ri| j
                   | j                  z   ||dz
  |      j                         z  d| j
                  z  |dz
  z   ||dz
  |      j                         z  |z  z   S |dz   j                  rhd| j                  z  |dz   z   ||dz   |      j                         z  |z  | j
                  | j                  z   ||dz   |      j                         z  z
  S | S Nr8   rD   )	r4   r9   rF   is_realis_positiverG   rE   _eval_expand_funcis_negative)r2   hintsr?   r@   fs        r3   rf   zBesselBase._eval_expand_funcZ   s   ::t}}dnnqA::Q##(261)G)G)II$''	26*1R!VQ<+I+I+KKAMN Oq&%%$''	26*1R!VQ<+I+I+KKAM"q&!(F(F(HHI Jr6   c                     ddl m}  ||       S )Nr   )
besselsimp)sympy.simplify.simplifyrk   )r2   kwargsrk   s      r3   _eval_simplifyzBesselBase._eval_simplifye   s    6$r6   NrD   )__name__
__module____qualname____doc__propertyr4   r9   classmethodrA   rJ   rP   rS   rf   rn   r<   r6   r3   r-   r-   $   s_          KI
A	 r6   r-   c                        e Zd ZdZej
                  Zej
                  Zed        Z	d Z
d Zd Zd	 fd	Zd Zd
 fd	Z xZS )rW   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                    |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                  t        j                  fv rt        j                  S |j                         r||z  | | z  z  t        ||       z  S |j                  r_|j                         r"t        j                  | z  t        | |      z  S |j!                  t"              }|rt"        |z  t%        ||      z  S |j                  rt'        |      }||k7  rPt        ||      S |j)                         \  }}|dk7  r,t+        d|z  t,        z  |z  t"        z        t        ||      z  S t'        |      }||k7  rt        ||      S y )NFTr   rD   )r]   r   OnerU   r!   re   Zerorg   ComplexInfinityis_imaginaryNaNInfinityNegativeInfinitycould_extract_minus_signrW   NegativeOneextract_multiplicativelyr   rX   r$   extract_branch_factorr   r   r>   r?   r@   newznnnus         r3   rA   zbesselj.eval   s   99zzuu--BJJ%$7BrF<N<NvvB##R]]d-B(((uuQ//0066M%%'7QB2#;&wrA266==**,}}s+GRCO;;--a0D2wwr4000 ==a=Dqyr4((--/GD!Av1Q3r6"9Q;'D(999n93?" r6   c                 v    t        t        t        z  |z  dz        t        |t	        t               |z        z  S NrD   )r   r   r   rX   r#   r2   r?   r@   rm   s       r3   _eval_rewrite_as_besseliz besselj._eval_rewrite_as_besseli   s/    1R4719~gb*aR.*:;;;r6   c                     |j                   du r@t        t        |z        t        | |      z  t	        t        |z        t        ||      z  z
  S y rL   )rU   r   r   besselyr   r   s       r3   _eval_rewrite_as_besselyz besselj._eval_rewrite_as_bessely   sF    ==E!r"u:grc1o-BrE
72q>0III "r6   c                 |    t        d|z  t        z        t        |t        j                  z
  | j
                        z  S r   )r   r   r[   r   Halfr9   r   s       r3   _eval_rewrite_as_jnzbesselj._eval_rewrite_as_jn   s,    AaCF|BrAFF{DMM:::r6   c                    | j                   \  }}	 |j                  |      }|j                  |      \  }}|j                  r||z  d|z  t        |dz         z  z  S |j                  r\|dk(  rdn|}|||z  z  }	|	j                  s=t        d      t        |t        d|z  dz   z  dz  z
        z  t        t        |z        z  S | S t        t        | 3  |||      S # t        $ r | cY S w xY w)NrD   r8   r      )r0   as_leading_termNotImplementedErroras_coeff_exponentre   r%   rg   r   r   r   superrW   _eval_as_leading_termr2   r_   logxcdirr?   r@   argcesignrF   s             r3   r   zbesselj._eval_as_leading_term   s    		A	##A&C $$Q'1==7ArE%Q-/00]]	1tDT1W9D## Aws1r1R4!8}Q#677RT
BBKWd9!T4HH # 	K	s   C C('C(c                 V    | j                   \  }}|j                  r|j                  ryy y NTr0   rU   is_extended_realr2   r?   r@   s      r3   _eval_is_extended_realzbesselj._eval_is_extended_real   (    		A==Q// 0=r6   c                    ddl m} | j                  \  }}	 |j                  |      \  }}	|	j                  rt        ||	z        }
 |||z  |      }|dz  j                  ||||      j                         }|t        j                  u r|S t        |dz        |z   j                         }||z  t        |dz         z  }|g}t        d|
dz   dz        D ]>  }|| |||z   z  z  z  }t        |      |z   j                         }|j                  |       @ t!        | |z   S t"        t$        | #  ||||      S # t        t
        f$ r | cY S w xY wNr   OrderrD   r8   )sympy.series.orderr   r0   leadterm
ValueErrorr   re   r   _eval_nseriesremoveOr   ry   r   r%   rangeappendr   r   rW   r2   r_   r   r   r   r   r?   r@   _r   newnorttermskrF   s                    r3   r   zbesselj._eval_nseries   sW    	-		A	ZZ]FAs ??1S5>DadAA1##Aq$5==?AAFF{!Q$!#,,.Ab5rAv&DA1tax!m, ArAvJ' *335 7Q;Wd1!QdCC' /0 	K	s   D5 5E	E	Nr   r   )rp   rq   rr   rs   r   rx   rG   rE   ru   rA   r   r   r   r   r   r   __classcell__rF   s   @r3   rW   rW   j   sX    BH 
B	
B!# !#F<J;I*
D Dr6   rW   c                        e Zd ZdZej
                  Zej
                  Zed        Z	d Z
d Zd Zd	 fd	Zd Zd
 fd	Z xZS )r   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                    |j                   rh|j                   rt        j                  S t        |      j                   du rt        j                  S t        |      j                   rt        j
                  S |t        j                  t        j                  fv rt        j                  S |t        t        j                  z  k(  r0t        t        t        z  |dz   z  dz        t        j                  z  S |t        t        j                  z  k(  r1t        t         t        z  |dz   z  dz        t        j                  z  S |j                  r3|j                         r"t        j                  | z  t        | |      z  S y y )NFr8   rD   )r]   r   r~   r!   rz   r|   r}   ry   r   r   r   rU   r   r   r   r=   s      r3   rA   zbessely.evalF  s   99zz)))B5((((BuuQ//0066M!**qtR!V}Q'!**44!$$$$r"ub1f~a'(1::55==**,}}s+GRCO;; - r6   c                     |j                   du r@t        t        |z        t        t        |z        t	        ||      z  t	        | |      z
  z  S y rL   )rU   r   r   r   rW   r   s       r3   _eval_rewrite_as_besseljz bessely._eval_rewrite_as_besseljZ  sF    ==E!r"u:s2b5z'"a.87B3?JKK "r6   c                 d     | j                   | j                   }|r|j                  t              S y r;   )r   r0   rewriterX   r2   r?   r@   rm   ajs        r3   r   z bessely._eval_rewrite_as_besseli^  /    *T**DII6::g&& r6   c                 |    t        d|z  t        z        t        |t        j                  z
  | j
                        z  S r   )r   r   r\   r   r   r9   r   s       r3   _eval_rewrite_as_ynzbessely._eval_rewrite_as_ync  s,    AaCF|baffdmm<<<r6   c                    | j                   \  }}	 |j                  |      }|j                  |      \  }}|j                  rdt
        z  t        |dz        z  t        ||      z  }	|j                  r |dz  | z   t        |dz
        z  t
        z  nt        j                  }
|dz  |z   t
        t        |      z  z  t        |dz         t        j                  z
  z  }t        |	|
|g j                  ||      }|S |j                  r|dk(  rdn|}|||z  z  }|j                  szt        d      t!        t
        |z  dz  |z
  t
        dz  z          dt#        t
        |z  dz  |z
  t
        dz  z         z  d|z  z  z   z  t        d|z        z  t        t
              z  S | S t$        t&        | S  |||      S # t        $ r | cY S w xY w)NrD   r8   r   r   r         )r0   r   r   r   re   r   r   rW   r   r   ry   r&   
EulerGammar   rg   r   r   r   r   r   r   )r2   r_   r   r   r?   r@   r   r   r   term_oneterm_two
term_threer   rF   s                r3   r   zbessely._eval_as_leading_termf  s   		A	##A&C $$Q'1==2s1Q3xA6H>@=M=M1}YrAv%66r9STSYSYHQ3)R	"%56Q!,,8VWJ(J78HHQUHVCJ]]	1tDT1W9D## AwRU1Wq[2a4%7!8 81SBq1rRStAS=T;TVWXYVY;Z Z[\`abcdad\eefjkmfnnnKWd9!T4HH' # 	K	s   F8 8GGc                 V    | j                   \  }}|j                  r|j                  ryy y r   r0   rU   re   r   s      r3   r   zbessely._eval_is_extended_real  &    		A==Q]] +=r6   c                 B   ddl m} | j                  \  }}	 |j                  |      \  }}	|	j                  r;|j                  r.t        ||	z        }
t        ||      }dt        z  t        |dz        z  |z  j                  ||||      }g g }} |||z  |      }|dz  j                  ||||      j                         }|t        j                  u r|S t!        |dz        |z   j                         }|t        j                  kD  r|| z  t#        |dz
        z  t        z  }|j%                  |       t'        d|      D ][  }||z
  |z  }|t        j                  k(  r	|||z  z  }n|||z  z  }t!        |      |z   j                         }|j%                  |       ] ||z  t        t#        |      z  z  }|t)        |dz         t        j*                  z
  z  }|j%                  |       t'        d|
dz   dz        D ]a  }|| |||z   z  z  z  }t!        |      |z   j                         }|t)        ||z   dz         t)        |dz         z   z  }|j%                  |       c |t-        | z
  t-        | z
  S t.        t0        | 3  ||||      S # t        t
        f$ r | cY S w xY wr   )r   r   r0   r   r   r   re   rU   r   rW   r   r   r   r   r   ry   r   r   r   r   r&   r   r   r   r   r2   r_   r   r   r   r   r?   r@   r   r   r   bnr`   br   r   r   r   r   r   denomprF   s                         r3   r   zbessely._eval_nseries  s    	-		A	ZZ]FAs ??r}}1S5>DQBB$AaC#221atDArqAadAA1##Aq$5==?AAFF{!Q$!#,,.AAFF{B3x	"q& 11"4q" #A!VQJE!%$TNQ.779DHHTN# 2r)B-'(Agb1fo45DHHTN1tax!m, aRAF_$a[1_--/'!b&1*-A>?	
 sAw;a((Wd1!QdCCK /0 	K	s   J
 
JJr   r   )rp   rq   rr   rs   r   rx   rG   rE   ru   rA   r   r   r   r   r   r   r   r   s   @r3   r   r     sV    &P 
B	
B< <&L'
=I2
/D /Dr6   r   c                        e Zd ZdZej
                   Zej
                  Zed        Z	d Z
d Zd Zd Zd	 fd	Zd
 fd	Z xZS )rX   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                    |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                  t        j                  fv rt        j                  S |t        j                  u rt        j                  S |t        j                  u rd|z  t        j                  z  S |j                         r||z  | | z  z  t        ||       z  S |j                  rL|j                         rt        | |      S |j!                  t"              }|rt"        | z  t%        ||       z  S |j                  rt'        |      }||k7  rPt        ||      S |j)                         \  }}|dk7  r,t+        d|z  t,        z  |z  t"        z        t        ||      z  S t'        |      }||k7  rt        ||      S y )NFTr   rD   )r]   r   rx   rU   r!   re   ry   rg   rz   r{   r|   r"   r}   r~   r   rX   r   r   rW   r$   r   r   r   r   s         r3   rA   zbesseli.eval  s   99zzuu--BJJ%$7BrF<N<NvvB##R]]d-B(((uua5QZZ!3!34466M

?::"""8AJJ&&%%'7QB2#;&wrA266==**,sA&--a0DB3xTE 222 ==a=Dqyr4((--/GD!Av1Q3r6"9Q;'D(999n93?" r6   c                 v    t        t         t        z  |z  dz        t        |t	        t              |z        z  S r   )r   r   r   rW   r#   r   s       r3   r   z besseli._eval_rewrite_as_besselj	  s.    A2b58A:wr:a=?;;;r6   c                 d     | j                   | j                   }|r|j                  t              S y r;   r   r0   r   r   r   s        r3   r   z besseli._eval_rewrite_as_bessely  r   r6   c                 Z     | j                   | j                   j                  t              S r;   )r   r0   r   r[   r   s       r3   r   zbesseli._eval_rewrite_as_jn  s$    ,t,,dii8@@DDr6   c                 V    | j                   \  }}|j                  r|j                  ryy y r   r   r   s      r3   r   zbesseli._eval_is_extended_real  r   r6   c                    | j                   \  }}	 |j                  |      }|j                  |      \  }}|j                  r||z  d|z  t        |dz         z  z  S |j                  r@|dk(  rdn|}|||z  z  }	|	j                  s!t        |      t        dt        z  |z        z  S | S t        t        | 3  |||      S # t        $ r | cY S w xY wNrD   r8   r   )r0   r   r   r   re   r%   rg   r   r   r   r   rX   r   r   s             r3   r   zbesseli._eval_as_leading_term  s    		A	##A&C $$Q'1==7ArE%Q-/00]]	1tDT1W9D## 1vd1R46l**KWd9!T4HH # 	K	s   B> >CCc                    ddl m} | j                  \  }}	 |j                  |      \  }}	|	j                  rt        ||	z        }
 |||z  |      }|dz  j                  ||||      j                         }|t        j                  u r|S t        |dz        |z   j                         }||z  t        |dz         z  }|g}t        d|
dz   dz        D ]=  }|||||z   z  z  z  }t        |      |z   j                         }|j                  |       ? t!        | |z   S t"        t$        | #  ||||      S # t        t
        f$ r | cY S w xY wr   )r   r   r0   r   r   r   re   r   r   r   r   ry   r   r%   r   r   r   r   rX   r   s                    r3   r   zbesseli._eval_nseries.  sU    	-		A	ZZ]FAs ??1S5>DadAA1##Aq$5==?AAFF{!Q$!#,,.Ab5rAv&DA1tax!m, 1b1f:& *335 7Q;Wd1!QdCC' /0 	K	s   D4 4EEr   r   )rp   rq   rr   rs   r   rx   rG   rE   ru   rA   r   r   r   r   r   r   r   r   s   @r3   rX   rX     sY    %N %%B	
B%# %#N<'
E
I*D Dr6   rX   c                        e Zd ZdZej
                  Zej
                   Zed        Z	d Z
d Zd Zd Zd Zd
 fd	Zd fd		Z x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                    |j                   rh|j                   rt        j                  S t        |      j                   du rt        j                  S t        |      j                   rt        j
                  S |t        j                  t        t        j                  z  t        t        j                  z  fv rt        j                  S |j                  r|j                         rt        | |      S y y rL   )r]   r   r}   r!   rz   r|   r   r~   ry   rU   r   r   r=   s      r3   rA   zbesselk.evalw  s    99zzzz!B5((((BuuQqzz\1Q-?-?+?@@66M==**,sA& - r6   c                     |j                   du r7t        t        t        |z        z  t        | |      t        ||      z
  z  dz  S y )NFrD   )rU   r   r   rX   r   s       r3   r   z besselk._eval_rewrite_as_besseli  sB    ==E!c"R%j='2#q/GBN"BCAEE "r6   c                 d     | j                   | j                   }|r|j                  t              S y r;   )r   r0   r   rW   )r2   r?   r@   rm   ais        r3   r   z besselk._eval_rewrite_as_besselj  r   r6   c                 d     | j                   | j                   }|r|j                  t              S y r;   r   r   s        r3   r   z besselk._eval_rewrite_as_bessely  r   r6   c                 d     | j                   | j                   }|r|j                  t              S y r;   )r   r0   r   r\   )r2   r?   r@   rm   ays        r3   r   zbesselk._eval_rewrite_as_yn  s.    *T**DII6::b>! r6   c                 V    | j                   \  }}|j                  r|j                  ryy y r   r   r   s      r3   r   zbesselk._eval_is_extended_real  r   r6   c                    | j                   \  }}	 |j                  |      }|j                  |      \  }}|j                  rd|dz
  z  t        |dz        z  t        ||      z  }	|j                  r|dz  | z  t        |dz
        z  dz  nt        j                  }
d|z  |dz  |z  z  dt        |      z  z  t        |dz         t        j                  z
  z  }t        |	|
|g j                  ||      }|S |j                  r+t        t              t!        |       z  t        d|z        z  S t"        t$        | O  |||      S # t        $ r | cY S w xY w)Nr   r8   rD   r   )r0   r   r   r   re   r   rX   r   r   ry   r&   r   r   rg   r   r   r   r   r   r   )r2   r_   r   r   r?   r@   r   r   r   r   r   r   rF   s               r3   r   zbesselk._eval_as_leading_term  sT   		A	##A&C $$Q'1==r1uc!A#h.wr1~=H<>;K;K!s|Ib1f$55a7QRQWQWHr1Q3)+Qy}_=wrAvQRQ]Q]?]^J(J78HHQUHVCJ]] 8CG#D1I--Wd9!T4HH # 	K	s   E EEc                 :   ddl m} | j                  \  }}	 |j                  |      \  }}	|	j                  r7|j                  r*t        ||	z        }
t        ||      }d|dz
  z  t        |dz        z  |z  j                  ||||      }g g }} |||z  |      }|dz  j                  ||||      j                         }|t        j                  u r|S t        |dz        |z   j                         }|t        j                  kD  r|| z  t!        |dz
        z  dz  }|j#                  |       t%        d|      D ][  }||z
  |z  }|t        j                  k(  r	|||z  z  }n|||z  z  }t        |      |z   j                         }|j#                  |       ] ||z  d|z  z  dt!        |      z  z  }|t'        |dz         t        j(                  z
  z  }|j#                  |       t%        d|
dz   dz        D ]`  }|||||z   z  z  z  }t        |      |z   j                         }|t'        ||z   dz         t'        |dz         z   z  }|j#                  |       b |t+        | z   t+        | z   S t,        t.        | /  ||||      S # t        t
        f$ r | cY S w xY w)Nr   r   r   r8   rD   )r   r   r0   r   r   r   re   rU   r   rX   r   r   r   r   ry   r   r   r   r   r&   r   r   r   r   r   s                         r3   r   zbesselk._eval_nseries  s    	-		A	ZZ]FAs ??r}}1S5>DQBQAaC(+::1atLArqAadAA1##Aq$5==?AAFF{!Q$!#,,.AAFF{B3x	"q& 11!3q" #AVQJE!%$TNQ.779DHHTN# 2rBh)B-0Agb1fo45DHHTN1tax!m, Q1r6
^#a[1_--/'!b&1*-A>?	
 sAw;a((Wd1!QdCCK /0 	K	s   J JJr   r   )rp   rq   rr   rs   r   rx   rG   rE   ru   rA   r   r   r   r   r   r   r   r   r   s   @r3   r   r   N  s]    #J 
B
%%B' 'F'
'
"

I*/D /Dr6   r   c                   F    e Zd ZdZej
                  Zej
                  Zd Zy)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                     | j                   }|j                  du r2t        | j                  j	                         |j	                               S y rL   )r9   rM   hankel2r4   rN   rO   s     r3   rP   zhankel1._eval_conjugate  >    MM!!U*4:://11;;=AA +r6   N	rp   rq   rr   rs   r   rx   rG   rE   rP   r<   r6   r3   r   r     s"    "H 
B	
BBr6   r   c                   F    e Zd ZdZej
                  Zej
                  Zd Zy)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                     | j                   }|j                  du r2t        | j                  j	                         |j	                               S y rL   )r9   rM   r   r4   rN   rO   s     r3   rP   zhankel2._eval_conjugate=  r   r6   Nr   r<   r6   r3   r   r     s"    #J 
B	
BBr6   r   c                 .     t                fd       }|S )Nc                 2    |j                   r
 | ||      S y r;   )rU   )r2   r?   r@   fns      r3   gzassume_integer_order.<locals>.gD  s    ==dB?" r6   r   )r   r   s   ` r3   assume_integer_orderr   C  s     
2Y# # Hr6   c                   $    e Zd ZdZd Zd ZddZy)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                     t        d      )z@ Expand self into a polynomial. Nu is guaranteed to be Integer. 	expansionr   r2   rh   s     r3   _expandzSphericalBesselBase._expandW  s    !+..r6   c                 V    | j                   j                  r | j                  di |S | S Nr<   )r4   
is_Integerr  r  s     r3   rf   z%SphericalBesselBase._eval_expand_func[  s(    ::  4<<(%((r6   c                     |dk7  rt        | |      | j                  | j                  dz
  | j                        | | j                  dz   z  | j                  z  z
  S rC   )r
   rF   r4   r9   rH   s     r3   rJ   zSphericalBesselBase.fdiff`  sS    q=$T844~~djj1ndmm<DJJN#DMM12 	2r6   Nro   )rp   rq   rr   rs   r  rf   rJ   r<   r6   r3   r   r   K  s    	/
2r6   r   c                     t        | |      t        |      z  t        j                  | dz   z  t        |  dz
  |      z  t	        |      z  z   S Nr8   )r)   r   r   r   r   r   r@   s     r3   _jnr  g  sM    1%c!f,MMAE"#6rAvq#AA#a&HI Jr6   c                     t         j                  | dz   z  t        |  dz
  |      z  t        |      z  t        | |      t	        |      z  z
  S r
  )r   r   r)   r   r   r  s     r3   _ynr  l  sK    MMAE"%8!a%CCCFJ1%c!f,- .r6   c                   >    e Zd ZdZed        Zd Zd Zd Zd Z	d Z
y)	r[   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                 (   |j                   rT|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 y r;   )	r]   r   rx   rU   re   ry   rz   r~   r}   r=   s      r3   rA   zjn.eval  sa    99zzuu>>66M,,,##QZZ0066M 1r6   c                 h    t        t        d|z  z        t        |t        j                  z   |      z  S r   )r   r   rW   r   r   r   s       r3   r   zjn._eval_rewrite_as_besselj  s(    B!H~QVVQ 777r6   c                     t         j                  |z  t        t        d|z  z        z  t	        | t         j
                  z
  |      z  S r   )r   r   r   r   r   r   r   s       r3   r   zjn._eval_rewrite_as_bessely  s8    }}b 4AaC>1GRC!&&L!4LLLr6   c                 J    t         j                  |z  t        | dz
  |      z  S r
  )r   r   r\   r   s       r3   r   zjn._eval_rewrite_as_yn  s"    }}r"Ra^33r6   c                 B    t        | j                  | j                        S r;   )r  r4   r9   r  s     r3   r  z
jn._expand      4::t}}--r6   c                 x    | j                   j                  r$| j                  t              j	                  |      S y r;   r4   r  r   rW   _eval_evalfr2   precs     r3   r  zjn._eval_evalf  .    ::  <<(44T:: !r6   N)rp   rq   rr   rs   ru   rA   r   r   r   r  r  r<   r6   r3   r[   r[   r  s6    8r 
 
8M4.;r6   r[   c                   B    e Zd ZdZed        Zed        Zd Zd Zd Z	y)r\   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                     t         j                  |dz   z  t        t        d|z  z        z  t	        | t         j
                  z
  |      z  S rc   )r   r   r   r   rW   r   r   s       r3   r   zyn._eval_rewrite_as_besselj  s<    }}r!t$tB!H~5affa8PPPr6   c                 h    t        t        d|z  z        t        |t        j                  z   |      z  S r   )r   r   r   r   r   r   s       r3   r   zyn._eval_rewrite_as_bessely  s(    B!H~QVVQ 777r6   c                 P    t         j                  |dz   z  t        | dz
  |      z  S r
  )r   r   r[   r   s       r3   r   zyn._eval_rewrite_as_jn  s&    }}rAv&RC!GQ77r6   c                 B    t        | j                  | j                        S r;   )r  r4   r9   r  s     r3   r  z
yn._expand  r  r6   c                 x    | j                   j                  r$| j                  t              j	                  |      S y r;   )r4   r  r   r   r  r  s     r3   r  zyn._eval_evalf  r  r6   N)
rp   rq   rr   rs   r   r   r   r   r  r  r<   r6   r3   r\   r\     sA    -\ Q Q 8 88.;r6   r\   c                   J    e Zd Zed        Zed        Zd Zd Zd Zd Z	d Z
y)	SphericalHankelBasec                     | j                   }t        t        d|z  z        t        |t        j
                  z   |      |t        z  t        j                  |dz   z  z  t        | t        j
                  z
  |      z  z   z  S rC   )_hankel_kind_signr   r   rW   r   r   r   r   r2   r?   r@   rm   hkss        r3   r   z,SphericalHankelBase._eval_rewrite_as_besselj  sq    
 $$B!H~wrAFF{A6"1uQ]]RT%::7B3<QR;SS T U 	Ur6   c                     | j                   }t        t        d|z  z        t        j                  |z  t        | t        j                  z
  |      z  |t        z  t        |t        j                  z   |      z  z   z  S r   )r%  r   r   r   r   r   r   r   r&  s        r3   r   z,SphericalHankelBase._eval_rewrite_as_bessely  si    
 $$B!H~q}}b0"qvvq1II"1uWR!&&[!%<< = > 	>r6   c                     | j                   }t        ||      j                  t              |t        z  t        ||      z  z   S r;   )r%  r[   r   r\   r   r&  s        r3   r   z'SphericalHankelBase._eval_rewrite_as_yn   s7    $$"ay  $s1uRAY66r6   c                     | j                   }t        ||      |t        z  t        ||      j	                  t              z  z   S r;   )r%  r[   r   r\   r   r&  s        r3   r   z'SphericalHankelBase._eval_rewrite_as_jn$  s8    $$"ay3q5B!2!22!6666r6   c                     | j                   j                  r | j                  di |S | j                   }| j                  }| j                  }t        ||      |t        z  t        ||      z  z   S r  )r4   r  r  r9   r%  r[   r   r\   )r2   rh   r?   r@   r'  s        r3   rf   z%SphericalHankelBase._eval_expand_func(  s_    ::  4<<(%((BA((Cb!9s1uRAY..r6   c                     | j                   }| j                  }| j                  }t        ||      |t        z  t        ||      z  z   j                         S r;   )r4   r9   r%  r  r   r  expand)r2   rh   r   r@   r'  s        r3   r  zSphericalHankelBase._expand1  sI    JJMM$$ Aq	CE#a)O+3355r6   c                 x    | j                   j                  r$| j                  t              j	                  |      S y r;   r  r  s     r3   r  zSphericalHankelBase._eval_evalf@  r  r6   N)rp   rq   rr   r   r   r   r   r   rf   r  r  r<   r6   r3   r#  r#    sC    U U > >77/6;r6   r#  c                   8    e Zd ZdZej
                  Zed        Zy)rY   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                 F    t        t        d|z  z        t        ||      z  S r   )r   r   r   r   s       r3   _eval_rewrite_as_hankel1zhn1._eval_rewrite_as_hankel1x      B!H~gb!n,,r6   N)	rp   rq   rr   rs   r   rx   r%  r   r1  r<   r6   r3   rY   rY   E  s&    .` - -r6   rY   c                   :    e Zd ZdZej
                   Zed        Zy)rZ   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                 F    t        t        d|z  z        t        ||      z  S r   )r   r   r   r   s       r3   _eval_rewrite_as_hankel2zhn2._eval_rewrite_as_hankel2  r2  r6   N)	rp   rq   rr   rs   r   rx   r%  r   r5  r<   r6   r3   rZ   rZ   }  s(    .` - -r6   rZ   c                     ddl m} dk(  rpddlm} ddlm}  ||      }t        d|dz         D cg c]C  }t        j                   |t         dz         j                  |      t        |            |      E c}S dk(  rdd	lm 	 dd
lm  fd}	nt%        d      fd}
 |z   } |
|	|      }|g}t        |dz
        D ]  } |
|	||z         }|j'                  |       ! |S c c}w # t         $ r ddlm  fd}	Y ew xY w)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   sympy)besseljzero)dps_to_precr8   g      ?scipy)newton)spherical_jnc                      |       S r;   r<   )r_   r   r<  s    r3   <lambda>zjn_zeros.<locals>.<lambda>  s    ,q!, r6   )sph_jnc                 "     |       d   d   S )Nr   r   r<   )r_   r   r?  s    r3   r>  zjn_zeros.<locals>.<lambda>  s    &A,q/"- r6   Unknown method.c                 :    dk(  r | |      }|S t        d      )Nr:  rA  r  )ri   r_   r   methodr;  s      r3   solverzjn_zeros.<locals>.solver  s+    W!Q<D  &&788r6   )mathr   mpmathr8  mpmath.libmp.libmpfr9  r   r   _from_mpmathr   
_to_mpmathintscipy.optimizer;  scipy.specialr<  ImportErrorr?  r   r   )r   r   rC  dpsmath_pir8  r9  r  lri   rD  r   rootsir;  r?  r<  s   ` `           @@@r3   jn_zerosrS    s   Z #&33 q!a%* !!+aCj.C.CD.I.1!f#67;= * 	* 
7	)	.2,A
 ""344 w;D!T?DFE1q5\ a(T L=*  	.,-A	.s   AC.C3 3D
Dc                   ,    e Zd ZdZd Zd ZddZddZy)AiryBasezg
    Abstract base class for Airy functions.

    This class is meant to reduce code duplication.

    c                 Z    | j                  | j                  d   j                               S r   )funcr0   rN   r1   s    r3   rP   zAiryBase._eval_conjugate  s"    yy1//122r6   c                 4    | j                   d   j                  S r   )r0   r   r1   s    r3   r   zAiryBase._eval_is_extended_real  s    yy|,,,r6   c                     | j                   d   }|j                         }| j                  } ||       ||      z   dz  }t         ||       ||      z
  z  dz  }||fS )Nr   rD   )r0   rN   rW  r   )r2   deeprh   r@   zcri   uvs           r3   as_real_imagzAiryBase.as_real_imag  s[    IIaL[[]IIqT!B%ZNquQqTzN1!tr6   c                 H     | j                   dd|i|\  }}||t        z  z   S )NrZ  r<   )r^  r   )r2   rZ  rh   re_partim_parts        r3   _eval_expand_complexzAiryBase._eval_expand_complex  s0    ,4,,@$@%@""r6   N)T)rp   rq   rr   rs   rP   r   r^  rb  r<   r6   r3   rU  rU  	  s    3-#r6   rU  c                   b    e Zd ZdZdZdZed        ZddZe	e
d               Zd Zd Zd	 Zd
 Zy)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

    r8   Tc                    |j                   r|t        j                  u rt        j                  S |t        j                  u rt        j                  S |t        j
                  u rt        j                  S |j                  r6t        j                  dt        dd      z  t        t        dd            z  z  S |j                  r6t        j                  dt        dd      z  t        t        dd            z  z  S y )Nr   rD   )
	is_Numberr   r|   r}   ry   r~   r]   rx   r   r%   r>   r   s     r3   rA   zairyai.eval  s    ==aee|uu

"vv***vvuu8Aq> 1E(1a.4I IJJ;;55Ax1~-hq!n0EEFF r6   c                 T    |dk(  rt        | j                  d         S t        | |      Nr8   r   )airyaiprimer0   r
   rH   s     r3   rJ   zairyai.fdiff  )    q=tyy|,,$T844r6   c           	      T   | dk  rt         j                  S t        |      }t        |      dkD  r|d   }t	        d      |z  |  z  t	        d      |z  | dz   z  z  t        t        | t        dd      z  t        dd      z   z        z  t        |       z  t        | dz  t        dd      z         z  t        t        | t        dd      z  t        dd      z   z        t        | dz         z  t        | dz  t        dd      z         z  z  |z  S t         j                  dt        dd      z  t        z  z  t        | t         j                  z   t        d      z        z  t        t        dd      t        z  | t         j                  z   z        z  t        |       z  t	        d      |z  | z  z  S )Nr   r8   r   r   rD   r   )r   ry   r   lenr   r   r   r   r   r%   rx   r   r_   previous_termsr   s       r3   taylor_termzairyai.taylor_term  s    q566M
A>"Q&"2&aqb)4719A*>>s2qRSUVGWZbcdfgZhGhCi?jjktuvkwwacHQN23458Qx1~=MPXYZ\]P^=^9_5`ajklopkpaq5qrwxyz{x{  G  HI  KL  M  yM  sN  6NO RSS T q(1a.034uagqt^7LLsS[\]_`SabdSdfghihmhmfmSnOoo!!%(,Q	A~6 7r6   c                     t        dd      }t        dd      }t        | t        dd            }t        |      j                  r0|t	        |       z  t        | ||z        t        |||z        z   z  S y Nr8   r   rD   r   r   r!   rg   r   rW   r2   r@   rm   otttr`   s         r3   r   zairyai._eval_rewrite_as_besselj  sp    a^a^HQN#a5dA2h;'2#r!t"4wr2a47H"HII r6   c                 h   t        dd      }t        dd      }t        |t        dd            }t        |      j                  r/|t	        |      z  t        | ||z        t        |||z        z
  z  S |t        ||      t        | ||z        z  |t        ||       z  t        |||z        z  z
  z  S rr  r   r   r!   re   r   rX   rt  s         r3   r   zairyai._eval_rewrite_as_besseli  s    a^a^8Aq>"a5d1g:"bd!3gb"Q$6G!GHHs1bz'2#r!t"44qQ}WRQSTUQUEV7VVWWr6   c           	      >   t         j                  dt        dd      z  t        t        dd            z  z  }|t	        dd      t        t        dd            z  z  }|t        g t        dd      g|dz  dz        z  |t        g t        dd      g|dz  dz        z  z
  S )Nr   rD   r8   	   r   )r   rx   r   r%   r   r(   r2   r@   rm   pf1pf2s        r3   _eval_rewrite_as_hyperzairyai._eval_rewrite_as_hyper  s    eeq(1a.(x1~)>>?41:eHQN334U2A/Aa883rHUVXYNK[]^`a]abc]cAd;dddr6   c                 ~   | j                   d   }|j                  }t        |      dk(  r|j                         }t	        d|g      }t	        d|g      }t	        d|g      }t	        d|g      }|j                  ||||z  z  |z  z        }	|	|	|   }d|z  j                  r|	|   }|	|   }|	|   }|||z  z  |z  ||z  |||z  z  z  z  }
|||z  z  |||z  z  z  }t        j                  |
t        j                  z   t        |      z  |
t        j                  z
  t        d      z  t        |      z  z
  z  S y y y 	Nr   r8   r   )excludedmr   r   )r0   free_symbolsrm  popr   matchrU   r   r   rx   rd  r   airybir2   rh   r   symbsr@   r   r  r  r   Mpfnewargs               r3   rf   zairyai._eval_expand_func  sR   iil  u:?		AS1#&AS1#&AS1#&AS1#&A		!Qq!tVaK-(A}aD aC##!A!A!Aad(Q!Q$QqS/:BAXAaC0F66b155j&.%@BJPTUVPWCWX^_eXfCf%fgg $	  r6   Nr8   rp   rq   rr   rs   nargs
unbranchedru   rA   rJ   staticmethodr   rp  r   r   r~  rf   r<   r6   r3   rd  rd  $  sb    Vp EJG G5 7  7JXe
hr6   rd  c                   b    e Zd ZdZdZdZed        ZddZe	e
d               Zd Zd Zd	 Zd
 Zy)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

    r8   Tc                    |j                   r|t        j                  u rt        j                  S |t        j                  u rt        j                  S |t        j                  u rt        j
                  S |j                  r6t        j                  dt        dd      z  t        t        dd            z  z  S |j                  r6t        j                  dt        dd      z  t        t        dd            z  z  S y )Nr   r8      rD   )
rf  r   r|   r}   r~   ry   r]   rx   r   r%   rg  s     r3   rA   zairybi.eval.  s    ==aee|uu

"zz!***vvuu8Aq> 1E(1a.4I IJJ;;55Ax1~-hq!n0EEFF r6   c                 T    |dk(  rt        | j                  d         S t        | |      ri  )airybiprimer0   r
   rH   s     r3   rJ   zairybi.fdiff=  rk  r6   c           
      l   | dk  rt         j                  S t        |      }t        |      dkD  r|d   }t	        d      |z  t        t        t        dd      t        z  | t         j                  z   z              z  t        | t         j                  z
  t        d      z        z  | t         j                  z   t        t        t        dd      t        z  | t         j                  z   z              z  t        | dz
  t        d      z        z  z  |z  S t         j                  t        dd      t        z  z  t        | t         j                  z   t        d      z        z  t        t        t        dd      t        z  | t         j                  z   z              z  t        |       z  t	        d      |z  | z  z  S )Nr   r8   r   r   rD   r  )r   ry   r   rm  r   r    r   r   r   rx   r   r   r   r   r%   rn  s       r3   rp  zairybi.taylor_termC  sw    q566M
A>"Q&"2&Q	CHQN2,=q155y,I(J$KKiYZ]^]b]bYbdefgdhXhNiiaee)s3x1~b/@!aff*/M+N'OOR[]^ab]bdefgdh\hRiikmno p tAqz"}-q155y!A$6F0GG#cRZ[\^_R`acRcefijininenRoNpJqq!!%(,Q	A~6 7r6   c                     t        dd      }t        dd      }t        | t        dd            }t        |      j                  r0t	        | dz        t        | ||z        t        |||z        z
  z  S y rr  rs  rt  s         r3   r   zairybi._eval_rewrite_as_besseljR  sp    a^a^HQN#a51:"bd!3gb"Q$6G!GHH r6   c                    t        dd      }t        dd      }t        |t        dd            }t        |      j                  r8t	        |      t	        d      z  t        | ||z        t        |||z        z   z  S t        ||      }t        ||       }t	        |      |t        | ||z        z  ||z  t        |||z        z  z   z  S rr  rx  r2   r@   rm   ru  rv  r`   r   r   s           r3   r   zairybi._eval_rewrite_as_besseliY  s    a^a^8Aq>"a5747?grc2a4&872r!t;L&LMMAr
AAsA8QwsBqD11AaCBqD8I4IIJJr6   c           	      8   t         j                  t        dd      t        t	        dd            z  z  }|t        dd      z  t        t	        dd            z  }|t        g t	        dd      g|dz  dz        z  |t        g t	        dd      g|dz  dz        z  z   S )Nr   r  rD   r8   rz  r   )r   rx   r   r%   r   r(   r{  s        r3   r~  zairybi._eval_rewrite_as_hyperd  s    eetAqz%A"778Q
lU8Aq>22U2A/Aa883rHUVXYNK[]^`a]abc]cAd;dddr6   c                 ~   | j                   d   }|j                  }t        |      dk(  r|j                         }t	        d|g      }t	        d|g      }t	        d|g      }t	        d|g      }|j                  ||||z  z  |z  z        }	|	|	|   }d|z  j                  r|	|   }|	|   }|	|   }|||z  z  |z  ||z  |||z  z  z  z  }
|||z  z  |||z  z  z  }t        j                  t        d      t        j                  |
z
  z  t        |      z  t        j                  |
z   t        |      z  z   z  S y y y r  )r0   r  rm  r  r   r  rU   r   r   r   rx   rd  r  r  s               r3   rf   zairybi._eval_expand_funci  sP   iil  u:?		AS1#&AS1#&AS1#&AS1#&A		!Qq!tVaK-(A}aD aC##!A!A!Aad(Q!Q$QqS/:BAXAaC0F66T!Waeebj%9&.%HAEETVJX^_eXfKf%fgg $	  r6   Nr  r  r<   r6   r3   r  r    sb    Xt EJG G5 7  7I	Ke
hr6   r  c                   N    e Zd ZdZdZdZed        ZddZd Z	d Z
d Zd	 Zd
 Zy)rj  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

    r8   Tc                 (   |j                   rD|t        j                  u rt        j                  S |t        j                  u rt        j                  S |j
                  r6t        j                  dt        dd      z  t        t        dd            z  z  S y )Nr   r8   )	rf  r   r|   r}   ry   r]   r   r   r%   rg  s     r3   rA   zairyaiprime.eval  sh    ==aee|uu

"vv;;==Ax1~$5hq!n8M$MNN r6   c                 t    |dk(  r(| j                   d   t        | j                   d         z  S t        | |      ri  )r0   rd  r
   rH   s     r3   rJ   zairyaiprime.fdiff  6    q=99Q<tyy| 444$T844r6   c                     | j                   d   j                  |      }t        |      5  t        j                  |d      }d d d        t        j                  |      S # 1 sw Y   xY wNr   r8   )
derivative)r0   rI  r+   r*   rd  r   rH  r2   r  r@   ress       r3   r  zairyaiprime._eval_evalf  Y    IIaL##D)d^ 	-))A!,C	-  d++	- 	-   A  A)c                     t        dd      }t        | t        dd            }t        |      j                  r&|dz  t	        | ||z        t	        |||z        z
  z  S y NrD   r   )r   r   r!   rg   rW   r2   r@   rm   rv  r`   s        r3   r   z$airyaiprime._eval_rewrite_as_besselj  s_    a^HQN#a5Q3'2#r!t,wr2a4/@@AA r6   c                    t        dd      }t        dd      }|t        |t        dd            z  }t        |      j                  r |dz  t	        ||      t	        | |      z
  z  S t        |t        dd            }t        ||      }t        ||       }||dz  |z  t	        |||z        z  |t	        | ||z        z  z
  z  S rr  )r   r   r!   re   rX   r  s           r3   r   z$airyaiprime._eval_rewrite_as_besseli  s    a^a^QA''a5Q3'"a.7B3?:;;Ax1~&AAr
AAsAAaBqD 11Agrc2a46H4HHIIr6   c           	      .   |dz  ddt        dd      z  z  t        t        dd            z  z  }dt        dd      t        t        dd            z  z  }|t        g t        dd      g|dz  dz        z  |t        g t        dd      g|dz  dz        z  z
  S )NrD   r   r8      rz  )r   r%   r   r(   r{  s        r3   r~  z"airyaiprime._eval_rewrite_as_hyper  s    da8Aq>))%A*??@41:eHQN334U2A/Aa883rHUVXYNK[]^`a]abc]cAd;dddr6   c                 ~   | j                   d   }|j                  }t        |      dk(  r|j                         }t	        d|g      }t	        d|g      }t	        d|g      }t	        d|g      }|j                  ||||z  z  |z  z        }	|	|	|   }d|z  j                  r|	|   }|	|   }|	|   }||z  |||z  z  z  |||z  z  |z  z  }
|||z  z  |||z  z  z  }t        j                  |
t        j                  z   t        |      z  |
t        j                  z
  t        d      z  t        |      z  z   z  S y y y r  )r0   r  rm  r  r   r  rU   r   r   rx   rj  r   r  r  s               r3   rf   zairyaiprime._eval_expand_func  sS   iil  u:?		AS1#&AS1#&AS1#&AS1#&A		!Qq!tVaK-(A}aD
 aC##!A!A!AQ$QqS/a!Q$h]:BAXAaC0F66b155j+f2E%EaeeUYZ[U\H\]hio]pHp%pqq $  r6   Nr  rp   rq   rr   rs   r  r  ru   rA   rJ   r  r   r   r~  rf   r<   r6   r3   rj  rj    sK    Ob EJO O5,B
Je
rr6   rj  c                   N    e Zd ZdZdZdZed        ZddZd Z	d Z
d Zd	 Zd
 Zy)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

    r8   Tc                    |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      z  t        t        dd            z  S |j                  r%dt        dd      z  t        t        dd            z  S y )Nr   r8   r  )	rf  r   r|   r}   r~   ry   r]   r   r%   rg  s     r3   rA   zairybiprime.evalu  s    ==aee|uu

"zz!***vv(1a.(5!Q+@@@;;hq!n$uXa^'<<< r6   c                 t    |dk(  r(| j                   d   t        | j                   d         z  S t        | |      ri  )r0   r  r
   rH   s     r3   rJ   zairybiprime.fdiff  r  r6   c                     | j                   d   j                  |      }t        |      5  t        j                  |d      }d d d        t        j                  |      S # 1 sw Y   xY wr  )r0   rI  r+   r*   r  r   rH  r  s       r3   r  zairybiprime._eval_evalf  r  r  c                     t        dd      }|t        | t        dd            z  }t        |      j                  r*| t	        d      z  t        | |      t        ||      z   z  S y r  rs  r  s        r3   r   z$airybiprime._eval_rewrite_as_besselj  s`    a^aR!Q((a52d1g:"a72q>!ABB r6   c                    t        dd      }t        dd      }|t        |t        dd            z  }t        |      j                  r)|t	        d      z  t        | |      t        ||      z   z  S t        |t        dd            }t        ||      }t        ||       }t	        |      |t        | ||z        z  |dz  |z  t        |||z        z  z   z  S rr  rx  r  s           r3   r   z$airybiprime._eval_rewrite_as_besseli  s    a^a^QA''a5T!W9Q'"a. @AAAx1~&AAr
AAsA8q"bd!33ad1fWRA=N6NNOOr6   c           	      "   |dz  dt        dd      z  t        t        dd            z  z  }t        dd      t        t        dd            z  }|t        g t        dd      g|dz  dz        z  |t        g t        dd      g|dz  dz        z  z   S )NrD   r   r  r8   r  rz  )r   r%   r   r(   r{  s        r3   r~  z"airybiprime._eval_rewrite_as_hyper  s    daQ
l5!Q#8891aj5!Q00U2A/Aa883rHUVXYNK[]^`a]abc]cAd;dddr6   c                 ~   | j                   d   }|j                  }t        |      dk(  r|j                         }t	        d|g      }t	        d|g      }t	        d|g      }t	        d|g      }|j                  ||||z  z  |z  z        }	|	|	|   }d|z  j                  r|	|   }|	|   }|	|   }||z  |||z  z  z  |||z  z  |z  z  }
|||z  z  |||z  z  z  }t        j                  t        d      |
t        j                  z
  z  t        |      z  |
t        j                  z   t        |      z  z   z  S y y y r  )r0   r  rm  r  r   r  rU   r   r   r   rx   rj  r  r  s               r3   rf   zairybiprime._eval_expand_func  sU   iil  u:?		AS1#&AS1#&AS1#&AS1#&A		!Qq!tVaK-(A}aD
 aC##!A!A!AQ$QqS/a!Q$h]:BAXAaC0F66T!Wb155j%9+f:M%MQSVWV[V[Q[]hio]pPp%pqq $  r6   Nr  r  r<   r6   r3   r  r    sI    Qf EJ= =5,C
Pe
rr6   r  c                   @    e Zd ZdZed        Zd	dZd Zd Zd Z	d Z
y)
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                    |t         j                  u r`|t         j                  u r"|t         j                  u rt         j                  S t        ||dz  t         j                  z        t	        |      z  S |t         j                  u r7|t         j                  u r%ddt        |dz  t         j                  z        z  z
  S ||k(  r|t         j                  u r3dt        |dz         t        d|dz        z  z   t         j                  z  S |dk(  rat         j                  t         j                  t        |dz         z  t        d|dz        z  z   t        |dz         t        d|dz        z  z   S |j                  rT|j                  r|j                  rt         j                  S t        ||dz  t         j                  z        t	        |      z  S |j                  r2|j                  r%ddt        |dz  t         j                  z        z  z
  S y y r   )	r   ry   r'   r   r%   r   rx   rX   r]   )r>   r  r`   r   s       r3   rA   zmarcumq.eval  s   ;AFF{qAFF{vvaA/%(::;1;q3q!taff}----6AEEzCAJAqD)999166AAAvvvadU 3gaA6F FFaQRdUV]^_abdeaeVfIfff99yyQYYvvaAaff-a8899q3q!tAFF{++++ #9r6   c                    | j                   \  }}}|dk(  r"|t        |||       t        d|z   ||      z   z  S |dk(  r;||z   ||dz
  z  z  t        |dz  |dz  z    dz        z  t        |dz
  ||z        z  S t	        | |      )NrD   r8   r   )r0   r  r   rX   r
   )r2   rI   r  r`   r   s        r3   rJ   zmarcumq.fdiff  s    ))1aq=Aq))GAaCA,>>??]TEA!H$adQTkN1,<(==!QqS@QQQ$T844r6   c           	          ddl m} |j                  dt        d            }|d|z
  z   |||z  t	        |dz  |dz  z    dz        z  t        |dz
  ||z        z  ||t        j                  g      z  S )Nr   )Integralr_   r8   rD   )sympy.integrals.integralsr  getr   r   rX   r   r}   )r2   r  r`   r   rm   r  r_   s          r3   _eval_rewrite_as_Integralz!marcumq._eval_rewrite_as_Integral  s}    6JJsE#J'QU|1sQTAqD[>!#344wqsAaC7HH1aQRQ[Q[J\]^ 	^r6   c           	          ddl m} |j                  dt        d            }t	        |dz  |dz  z    dz         |||z  |z  t        |||z        z  |d|z
  t        j                  g      z  S )Nr   )Sumr   rD   r8   )sympy.concrete.summationsr  r  r   r   rX   r   r}   )r2   r  r`   r   rm   r  r   s          r3   _eval_rewrite_as_Sumzmarcumq._eval_rewrite_as_Sum  sl    1JJsE#J'QTAqD[>A%&acAX1Q3-G!QqSRSR\R\I])^^^r6   c           
      ~   ||k(  r|dk(  r%dt        |dz         t        d|dz        z  z   dz  S |j                  r||dk\  rvt        t	        d|      D cg c]  }t        ||dz         c}      }t
        j                  t        |dz         t        d|dz        z  dz  z   t        |dz         |z  z   S y y y c c}w )Nr8   rD   r   )r   rX   r  sumr   r   r   )r2   r  r`   r   rm   rR  r   s          r3   r   z marcumq._eval_rewrite_as_besseli  s    6AvCAJAqD)999Q>>||Q5A;?aAqD)?@vvQTE
WQ1-= = AACAJQRNRR !'|  @s   B:c                 >    t        d | j                  D              ryy )Nc              3   4   K   | ]  }|j                     y wr;   )r]   ).0r   s     r3   	<genexpr>z(marcumq._eval_is_zero.<locals>.<genexpr>(  s     0ss{{0s   T)allr0   r1   s    r3   _eval_is_zerozmarcumq._eval_is_zero'  s    0dii00 1r6   Nro   )rp   rq   rr   rs   ru   rA   rJ   r  r  r   r  r<   r6   r3   r  r    s8    .` , ,.5^_
Sr6   r  N)r7     )T	functoolsr   
sympy.corer   sympy.core.addr   sympy.core.cacher   sympy.core.exprr   sympy.core.functionr	   r
   r   sympy.core.logicr   r   sympy.core.numbersr   r   r   sympy.core.powerr   sympy.core.symbolr   r   sympy.core.sympifyr   (sympy.functions.combinatorial.factorialsr   (sympy.functions.elementary.trigonometricr   r   r   r   #sympy.functions.elementary.integersr   &sympy.functions.elementary.exponentialr   r   (sympy.functions.elementary.miscellaneousr   r   r   $sympy.functions.elementary.complexesr    r!   r"   r#   r$   'sympy.functions.special.gamma_functionsr%   r&   r'   sympy.functions.special.hyperr(   sympy.polys.orthopolysr)   rF  r*   r+   r-   rW   r   rX   r   r   r   r   r   r  r  r[   r\   r#  rY   rZ   rS  rU  rd  r  rj  r  r  r<   r6   r3   <module>r     s      $   F F 0 . .   ) & > G G 7 ; E E V V N N / 6 C  C LmDj mD`YDj YDxUDj UDpUDj UDp+Bj +B\,Bj ,B^2* 28J
.U;	 U;p?;	 ?;D6;- 6;r5-
 5-p5-
 5-pQh#x #6ihX ihXnhX nhbZr( Zrzar( arHgh gr6   