
    Цi                        S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
JrJrJr  S SKJrJr  S SKJrJrJr  S S	KJr  S S
KJrJrJr  S SKJr  S SKJr  S SKJ r J!r!J"r"J#r#  S SK$J%r%  S SK&J'r'J(r(  S SK)J*r*J+r+J,r,  S SK-J.r.J/r/J0r0J1r1J2r2  S SK3J4r4J5r5J6r6  S SK7J8r8  S SK9J:r:  S SK;J<r<J=r=   " S S\5      r> " S S\>5      r? " S S\>5      r@ " S S\>5      rA " S S\>5      rB " S  S!\>5      rC " S" S#\>5      rDS$ rE " S% S&\>5      rFS' rGS( rH " S) S*\F5      rI " S+ S,\F5      rJ " S- S.\F5      rK " S/ S0\K5      rL " S1 S2\K5      rMSAS3 jrN " S4 S5\5      rO " S6 S7\O5      rP " S8 S9\O5      rQ " S: S;\O5      rR " S< S=\O5      rS " S> S?\5      rTg@)B    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                   j    \ rS rSrSr\S 5       r\S 5       r\S 5       r	SS jr
S rS rS	 rS
 rSrg)
BesselBase$   a  
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                      U R                   S   $ )z'The order of the Bessel-type function. r   argsselfs    ]/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/sympy/functions/special/bessel.pyorderBesselBase.order4        yy|    c                      U R                   S   $ )z*The argument of the Bessel-type function.    r1   r3   s    r5   argumentBesselBase.argument9   r8   r9   c                     g N clsnuzs      r5   evalBesselBase.eval>   s    r9   c                 
   US:w  a  [        X5      eU R                  S-  U R                  U R                  S-
  U R                  5      -  U R
                  S-  U R                  U R                  S-   U R                  5      -  -
  $ N   r;   )r
   _b	__class__r6   r<   _ar4   argindexs     r5   fdiffBesselBase.fdiffB   sn    q=$T44	DNN4::>4==II	DNN4::>4==IIJ 	Kr9   c                     U R                   nUR                  SL a8  U R                  U R                  R	                  5       UR	                  5       5      $ g NF)r<   is_extended_negativerK   r6   	conjugater4   rD   s     r5   _eval_conjugateBesselBase._eval_conjugateH   sB    MM!!U*>>$**"6"6"8!++-HH +r9   c           	         U R                   U R                  pCUR                  U5      (       a  gUR                  X5      (       d  g UR	                  X5      nUR
                  (       aU  [        U [        [        [        [        [        [        45      (       d  UR                  (       d  [        UR                  5      $ [        [!        UR                  UR                  /5      5      $ rR   )r6   r<   has_eval_is_meromorphicsubs
is_integer
isinstancebesseljbesselihn1hn2jnynis_zeror   is_infiniter   )r4   xarC   rD   z0s         r5   rZ   BesselBase._eval_is_meromorphicM   s    

DMMA66!99%%a++VVA\==$'3R DEERZZ 002::r~~">?@@r9   c                 `   U R                   U R                  U R                  pCnUR                  (       a  US-
  R                  (       ai  U R
                  * U R                  -  U" US-
  U5      R                  5       -  SU R
                  -  US-
  -  U" US-
  U5      R                  5       -  U-  -   $ US-   R                  (       ah  SU R                  -  US-   -  U" US-   U5      R                  5       -  U-  U R
                  U R                  -  U" US-   U5      R                  5       -  -
  $ U $ Nr;   rI   )	r6   r<   rK   is_realis_positiverL   rJ   _eval_expand_funcis_negative)r4   hintsrC   rD   fs        r5   rn   BesselBase._eval_expand_funcZ   s
   ::t}}dnnq::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r9   c                     SSK Jn  U" U 5      $ )Nr   )
besselsimp)sympy.simplify.simplifyrt   )r4   kwargsrt   s      r5   _eval_simplifyBesselBase._eval_simplifye   s    6$r9   r@   NrI   )__name__
__module____qualname____firstlineno____doc__propertyr6   r<   classmethodrE   rO   rV   rZ   rn   rw   __static_attributes__r@   r9   r5   r.   r.   $   s_          KI
A	 r9   r.   c                      ^  \ rS rSrSr\R                  r\R                  r\	S 5       r
S rS rS rSU 4S jjrS rSU 4S	 jjrS
rU =r$ )r^   j   a  
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                 |   UR                   (       a  UR                   (       a  [        R                  $ UR                  (       a  UR                   SL d  [	        U5      R
                  (       a  [        R                  $ [	        U5      R                  (       a  UR                  SLa  [        R                  $ UR                  (       a  [        R                  $ U[        R                  [        R                  4;   a  [        R                  $ UR                  5       (       a  X!-  U* U* -  -  [        X* 5      -  $ UR                  (       ah  UR                  5       (       a"  [        R                  U* -  [        U* U5      -  $ UR!                  ["        5      nU(       a  ["        U-  [%        X5      -  $ UR                  (       a  ['        U5      nX2:w  a  [        X5      $ OCUR)                  5       u  p4US:w  a+  [+        SU-  [,        -  U-  ["        -  5      [        X5      -  $ ['        U5      nX:w  a  [        XR5      $ g )NFTr   rI   )rd   r   Oner\   r"   rm   Zeroro   ComplexInfinityis_imaginaryNaNInfinityNegativeInfinitycould_extract_minus_signr^   NegativeOneextract_multiplicativelyr   r_   r%   extract_branch_factorr   r   rB   rC   rD   newznnnus         r5   rE   besselj.eval   s   99zzuu--BJJ%$7BrF<N<NvvB##R]]d-B(((uuQ//0066M%%''7QB2#;&wr266==**,,}}s+GRCO;;--a0D2wwr000 ==a=Dyr((  --/GDAv1Q3r6"9Q;'(999n93?" r9   c                 v    [        [        [        -  U-  S-  5      [        U[	        [        * 5      U-  5      -  $ NrI   )r   r   r   r_   r$   r4   rC   rD   rv   s       r5   _eval_rewrite_as_besseli besselj._eval_rewrite_as_besseli   s/    1R4719~gb*aR.*:;;;r9   c                     UR                   SL a?  [        [        U-  5      [        U* U5      -  [	        [        U-  5      [        X5      -  -
  $ g rR   )r\   r   r   besselyr   r   s       r5   _eval_rewrite_as_bessely besselj._eval_rewrite_as_bessely   sD    ==E!r"u:grc1o-BrE
72>0III "r9   c                 |    [        SU-  [        -  5      [        U[        R                  -
  U R
                  5      -  $ r   )r   r   rb   r   Halfr<   r   s       r5   _eval_rewrite_as_jnbesselj._eval_rewrite_as_jn   s,    AaCF|BrAFF{DMM:::r9   c                   > U R                   u  pE UR                  U5      nUR                  U5      u  pxUR                  (       a  Xd-  SU-  [        US-   5      -  -  $ UR                  (       aa  US:X  a  SOUnXsU-  -  n	U	R                  (       d=  [        S5      [        U[        SU-  S-   -  S-  -
  5      -  [        [        U-  5      -  $ U $ [        [        U ]3  XU5      $ ! [         a    U s $ f = f)NrI   r;   r      )r2   as_leading_termNotImplementedErroras_coeff_exponentrm   r&   ro   r   r   r   superr^   _eval_as_leading_termr4   rf   logxcdirrC   rD   argcesignrK   s             r5   r   besselj._eval_as_leading_term   s    			##A&C $$Q'==7ArE%Q-/00]]	1tD1W9D## Aws1r1R4!8}Q#677RT
BBKWd9!4HH # 	K	s   C% %C43C4c                 h    U R                   u  pUR                  (       a  UR                  (       a  gg g NTr2   r\   is_extended_realr4   rC   rD   s      r5   _eval_is_extended_realbesselj._eval_is_extended_real   &    		==Q// 0=r9   c                   > SSK Jn  U R                  u  pg UR                  U5      u  pU	R                  (       a  [        X)-  5      n
U" X-  U5      nUS-  R                  XX45      R                  5       nU[        R                  L a  U$ [        US-  5      U-   R                  5       nX-  [        US-   5      -  nU/n[        SU
S-   S-  5       H>  nX* UUU-   -  -  -  n[        U5      U-   R                  5       nUR                  U5        M@     [!        U6 U-   $ ["        [$        U ]#  XX45      $ ! [        [
        4 a    U s $ f = fNr   OrderrI   r;   )sympy.series.orderr   r2   leadterm
ValueErrorr   rm   r   _eval_nseriesremoveOr   r   r   r&   rangeappendr   r   r^   r4   rf   r   r   r   r   rC   rD   _r   newnorttermskrK   s                    r5   r   besselj._eval_nseries   s>    	-			ZZ]FA ??15>DadAA1##A$5==?AAFF{!Q$!#,,.A5rAv&DA1tax!m,ArAvJ' *335 - 7Q;Wd1!CC' /0 	K	s   D3 3EEr@   Nr   r   )rz   r{   r|   r}   r~   r   r   rL   rJ   r   rE   r   r   r   r   r   r   r   __classcell__rK   s   @r5   r^   r^   j   sX    BH 
B	
B!# !#F<J;I*
D Dr9   r^   c                      ^  \ rS rSrSr\R                  r\R                  r\	S 5       r
S rS rS rSU 4S jjrS rSU 4S	 jjrS
rU =r$ )r   i  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                 4   UR                   (       as  UR                   (       a  [        R                  $ [        U5      R                   SL a  [        R                  $ [        U5      R                   (       a  [        R
                  $ U[        R                  [        R                  4;   a  [        R                  $ U[        [        R                  -  :X  a0  [        [        [        -  US-   -  S-  5      [        R                  -  $ U[        [        R                  -  :X  a1  [        [        * [        -  US-   -  S-  5      [        R                  -  $ UR                  (       a8  UR                  5       (       a"  [        R                  U* -  [        U* U5      -  $ g g )NFr;   rI   )rd   r   r   r"   r   r   r   r   r   r   r   r\   r   r   r   rA   s      r5   rE   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;; - r9   c                     UR                   SL a?  [        [        U-  5      [        [        U-  5      [	        X5      -  [	        U* U5      -
  -  $ g rR   )r\   r   r   r   r^   r   s       r5   _eval_rewrite_as_besselj bessely._eval_rewrite_as_besseljZ  sD    ==E!r"u:s2b5z'".87B3?JKK "r9   c                 n    U R                   " U R                  6 nU(       a  UR                  [        5      $ g r?   )r   r2   rewriter_   r4   rC   rD   rv   ajs        r5   r    bessely._eval_rewrite_as_besseli^  -    **DII6::g&& r9   c                 |    [        SU-  [        -  5      [        U[        R                  -
  U R
                  5      -  $ r   )r   r   rc   r   r   r<   r   s       r5   _eval_rewrite_as_ynbessely._eval_rewrite_as_ync  s,    AaCF|baffdmm<<<r9   c                   > U R                   u  pE UR                  U5      nUR                  U5      u  pxUR                  (       a  S[
        -  [        US-  5      -  [        XE5      -  n	UR                  (       a   US-  U* -  * [        US-
  5      -  [
        -  O[        R                  n
US-  U-  * [
        [        U5      -  -  [        US-   5      [        R                  -
  -  n[        XU/6 R                  XS9nU$ UR                  (       a  US:X  a  SOUnXsU-  -  nUR                  (       dz  [        S5      [!        [
        U-  S-  U-
  [
        S-  -   5      * S[#        [
        U-  S-  U-
  [
        S-  -   5      -  SU-  -  -   -  [        SU-  5      -  [        [
        5      -  $ U $ [$        [&        U ]S  XU5      $ ! [         a    U s $ f = f)NrI   r;   r   r   r         )r2   r   r   r   rm   r   r   r^   r   r   r   r'   
EulerGammar   ro   r   r   r   r   r   r   )r4   rf   r   r   rC   rD   r   r   r   term_oneterm_two
term_threer   rK   s                r5   r   bessely._eval_as_leading_termf  s   			##A&C $$Q'==2s1Q3x6H>@=M=M1}YrAv%66r9STSYSYHQ3)R	"%56Q!,,8VWJJ78HHHVCJ]]	1tD1W9D## AwRU1Wq[2a4%7!8 81SBq1rRStAS=T;TVWXYVY;Z Z[\`abcdad\eefjkmfnnnKWd9!4HH' # 	K	s   G GGc                 h    U R                   u  pUR                  (       a  UR                  (       a  gg g r   r2   r\   rm   r   s      r5   r   bessely._eval_is_extended_real  $    		==Q]] +=r9   c                 N  > SSK Jn  U R                  u  pg UR                  U5      u  pU	R                  (       Ga?  UR                  (       Ga-  [        X)-  5      n
[        Xg5      nS[        -  [        US-  5      -  U-  R                  XX45      n/ / pU" X-  U5      nUS-  R                  XX45      R                  5       nU[        R                  L a  U$ [!        US-  5      U-   R                  5       nU[        R                  :  a  UU* -  [#        US-
  5      -  [        -  nUR%                  U5        ['        SU5       H]  nUU-
  U-  nU[        R                  :X  a	  UUU-  -  nOUUU-  -  n[!        U5      U-   R                  5       nUR%                  U5        M_     UU-  [        [#        U5      -  -  nU[)        US-   5      [        R*                  -
  -  nUR%                  U5        ['        SU
S-   S-  5       Hb  nUU* UUU-   -  -  -  n[!        U5      U-   R                  5       nU[)        UU-   S-   5      [)        US-   5      -   -  nUR%                  U5        Md     U[-        U6 -
  [-        U6 -
  $ [.        [0        U ]3  XX45      $ ! [        [
        4 a    U s $ f = fr   )r   r   r2   r   r   r   rm   r\   r   r^   r   r   r   r   r   r   r   r   r   r   r'   r   r   r   r   r4   rf   r   r   r   r   rC   rD   r   r   r   bnrg   br   r   r   r   r   r   denomprK   s                         r5   r   bessely._eval_nseries  sj    	-			ZZ]FA ???r}}}15>DBB$AaC#221DArqadAA1##A$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!CCK /0 	K	s   J J$#J$r@   r   r   )rz   r{   r|   r}   r~   r   r   rL   rJ   r   rE   r   r   r   r   r   r   r   r   r   s   @r5   r   r     sV    &P 
B	
B< <&L'
=I2
/D /Dr9   r   c                      ^  \ rS rSrSr\R                  * r\R                  r\	S 5       r
S rS rS rS rSU 4S jjrSU 4S	 jjrS
rU =r$ )r_   i  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                     UR                   (       a  UR                   (       a  [        R                  $ UR                  (       a  UR                   SL d  [	        U5      R
                  (       a  [        R                  $ [	        U5      R                  (       a  UR                  SLa  [        R                  $ UR                  (       a  [        R                  $ [        U5      [        R                  [        R                  4;   a  [        R                  $ U[        R                  L a  [        R                  $ U[        R                  L a  SU-  [        R                  -  $ UR                  5       (       a  X!-  U* U* -  -  [        X* 5      -  $ UR                  (       aU  UR                  5       (       a  [        U* U5      $ UR!                  ["        5      nU(       a  ["        U* -  [%        X* 5      -  $ UR                  (       a  ['        U5      nX2:w  a  [        X5      $ OCUR)                  5       u  p4US:w  a+  [+        SU-  [,        -  U-  ["        -  5      [        X5      -  $ ['        U5      nX:w  a  [        XR5      $ g )NFTr   rI   )rd   r   r   r\   r"   rm   r   ro   r   r   r   r#   r   r   r   r_   r   r   r^   r%   r   r   r   r   s         r5   rE   besseli.eval  s   99zzuu--BJJ%$7BrF<N<NvvB##R]]d-B(((uua5QZZ!3!34466M

?::"""8AJJ&&%%''7QB2#;&wr266==**,,sA&--a0DB3xE 222 ==a=Dyr((  --/GDAv1Q3r6"9Q;'(999n93?" r9   c                 v    [        [        * [        -  U-  S-  5      [        U[	        [        5      U-  5      -  $ r   )r   r   r   r^   r$   r   s       r5   r    besseli._eval_rewrite_as_besselj	  s.    A2b58A:wr:a=?;;;r9   c                 n    U R                   " U R                  6 nU(       a  UR                  [        5      $ g r?   r   r2   r   r   r   s        r5   r    besseli._eval_rewrite_as_bessely  r   r9   c                 Z    U R                   " U R                  6 R                  [        5      $ r?   )r   r2   r   rb   r   s       r5   r   besseli._eval_rewrite_as_jn  s"    ,,dii8@@DDr9   c                 h    U R                   u  pUR                  (       a  UR                  (       a  gg g r   r   r   s      r5   r   besseli._eval_is_extended_real  r   r9   c                   > U R                   u  pE UR                  U5      nUR                  U5      u  pxUR                  (       a  Xd-  SU-  [        US-   5      -  -  $ UR                  (       aE  US:X  a  SOUnXsU-  -  n	U	R                  (       d!  [        U5      [        S[        -  U-  5      -  $ U $ [        [        U ]3  XU5      $ ! [         a    U s $ f = fNrI   r;   r   )r2   r   r   r   rm   r&   ro   r   r   r   r   r_   r   r   s             r5   r   besseli._eval_as_leading_term  s    			##A&C $$Q'==7ArE%Q-/00]]	1tD1W9D## 1vd1R46l**KWd9!4HH # 	K	s   C	 	CCc                   > SSK Jn  U R                  u  pg UR                  U5      u  pU	R                  (       a  [        X)-  5      n
U" X-  U5      nUS-  R                  XX45      R                  5       nU[        R                  L a  U$ [        US-  5      U-   R                  5       nX-  [        US-   5      -  nU/n[        SU
S-   S-  5       H=  nXUUU-   -  -  -  n[        U5      U-   R                  5       nUR                  U5        M?     [!        U6 U-   $ ["        [$        U ]#  XX45      $ ! [        [
        4 a    U s $ f = fr   )r   r   r2   r   r   r   rm   r   r   r   r   r   r   r&   r   r   r   r   r_   r   s                    r5   r   besseli._eval_nseries.  s<    	-			ZZ]FA ??15>DadAA1##A$5==?AAFF{!Q$!#,,.A5rAv&DA1tax!m,1b1f:& *335 - 7Q;Wd1!CC' /0 	K	s   D2 2EEr@   r   r   )rz   r{   r|   r}   r~   r   r   rL   rJ   r   rE   r   r   r   r   r   r   r   r   r   s   @r5   r_   r_     sY    %N %%B	
B%# %#N<'
E
I*D Dr9   r_   c                      ^  \ rS rSrSr\R                  r\R                  * r\	S 5       r
S rS rS rS rS rSU 4S	 jjrSU 4S
 jjrSrU =r$ )besselkiN  a  
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                    UR                   (       as  UR                   (       a  [        R                  $ [        U5      R                   SL a  [        R                  $ [        U5      R                   (       a  [        R
                  $ U[        R                  [        [        R                  -  [        [        R                  -  4;   a  [        R                  $ UR                  (       a#  UR                  5       (       a  [        U* U5      $ g g rR   )rd   r   r   r"   r   r   r   r   r   r\   r   r  rA   s      r5   rE   besselk.evalw  s    99zzzz!B5((((BuuQqzz\1Q-?-?+?@@66M==**,,sA& - r9   c                     UR                   SL a6  [        [        [        U-  5      -  [        U* U5      [        X5      -
  -  S-  $ g )NFrI   )r\   r   r   r_   r   s       r5   r    besselk._eval_rewrite_as_besseli  s@    ==E!c"R%j='2#q/GBN"BCAEE "r9   c                 n    U R                   " U R                  6 nU(       a  UR                  [        5      $ g r?   )r   r2   r   r^   )r4   rC   rD   rv   ais        r5   r    besselk._eval_rewrite_as_besselj  r   r9   c                 n    U R                   " U R                  6 nU(       a  UR                  [        5      $ g r?   r   r   s        r5   r    besselk._eval_rewrite_as_bessely  r   r9   c                 n    U R                   " U R                  6 nU(       a  UR                  [        5      $ g r?   )r   r2   r   rc   )r4   rC   rD   rv   ays        r5   r   besselk._eval_rewrite_as_yn  s,    **DII6::b>! r9   c                 h    U R                   u  pUR                  (       a  UR                  (       a  gg g r   r   r   s      r5   r   besselk._eval_is_extended_real  r   r9   c                   > U R                   u  pE UR                  U5      nUR                  U5      u  pxUR                  (       a  SUS-
  -  [        US-  5      -  [        XE5      -  n	UR                  (       a  US-  U* -  [        US-
  5      -  S-  O[        R                  n
SU-  US-  U-  -  S[        U5      -  -  [        US-   5      [        R                  -
  -  n[        XU/6 R                  XS9nU$ UR                  (       a+  [        [        5      [!        U* 5      -  [        SU-  5      -  $ ["        [$        U ]O  XU5      $ ! [         a    U s $ f = f)Nr   r;   rI   r   )r2   r   r   r   rm   r   r_   r   r   r   r'   r   r   ro   r   r   r   r   r  r   )r4   rf   r   r   rC   rD   r   r   r   r   r   r   rK   s               r5   r   besselk._eval_as_leading_term  sG   			##A&C $$Q'==r1uc!A#h.wr~=H<>;K;K!s|Ib1f$55a7QRQWQWHr1Q3)+Qy}_=wrAvQRQ]Q]?]^JJ78HHHVCJ]] 8CG#D1I--Wd9!4HH # 	K	s   E EEc                 F  > SSK Jn  U R                  u  pg UR                  U5      u  pU	R                  (       Ga;  UR                  (       Ga)  [        X)-  5      n
[        Xg5      nSUS-
  -  [        US-  5      -  U-  R                  XX45      n/ / pU" X-  U5      nUS-  R                  XX45      R                  5       nU[        R                  L a  U$ [        US-  5      U-   R                  5       nU[        R                  :  a  UU* -  [!        US-
  5      -  S-  nUR#                  U5        [%        SU5       H]  nUU-
  U-  nU[        R                  :X  a	  UUU-  -  nOUUU-  -  n[        U5      U-   R                  5       nUR#                  U5        M_     UU-  SU-  -  S[!        U5      -  -  nU['        US-   5      [        R(                  -
  -  nUR#                  U5        [%        SU
S-   S-  5       Ha  nUUUUU-   -  -  -  n[        U5      U-   R                  5       nU['        UU-   S-   5      ['        US-   5      -   -  nUR#                  U5        Mc     U[+        U6 -   [+        U6 -   $ [,        [.        U ]/  XX45      $ ! [        [
        4 a    U s $ f = f)Nr   r   r   r;   rI   )r   r   r2   r   r   r   rm   r\   r   r_   r   r   r   r   r   r   r   r   r   r'   r   r   r   r  r   s                         r5   r   besselk._eval_nseries  st    	-			ZZ]FA ???r}}}15>DBQAaC(+::1LArqadAA1##A$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!CCK /0 	K	s   J J J r@   r   r   )rz   r{   r|   r}   r~   r   r   rL   rJ   r   rE   r   r   r   r   r   r   r   r   r   r   s   @r5   r  r  N  s]    #J 
B
%%B' 'F'
'
"

I*/D /Dr9   r  c                   N    \ rS rSrSr\R                  r\R                  rS r	Sr
g)hankel1i  aL  
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                     U R                   nUR                  SL a2  [        U R                  R	                  5       UR	                  5       5      $ g rR   )r<   rS   hankel2r6   rT   rU   s     r5   rV   hankel1._eval_conjugate  >    MM!!U*4:://11;;=AA +r9   r@   Nrz   r{   r|   r}   r~   r   r   rL   rJ   rV   r   r@   r9   r5   r  r    s"    "H 
B	
BBr9   r  c                   N    \ rS rSrSr\R                  r\R                  rS r	Sr
g)r  i  az  
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                     U R                   nUR                  SL a2  [        U R                  R	                  5       UR	                  5       5      $ g rR   )r<   rS   r  r6   rT   rU   s     r5   rV   hankel2._eval_conjugate=  r   r9   r@   Nr!  r@   r9   r5   r  r    s"    #J 
B	
BBr9   r  c                 0   ^  [        T 5      U 4S j5       nU$ )Nc                 :   > UR                   (       a	  T" XU5      $ g r?   )r\   )r4   rC   rD   fns      r5   gassume_integer_order.<locals>.gD  s    ==d?" r9   r   )r'  r(  s   ` r5   assume_integer_orderr*  C  s     
2Y# # Hr9   c                   .    \ rS rSrSrS rS rSS jrSrg)	SphericalBesselBaseiK  a  
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                     [        S5      e)z?Expand self into a polynomial. Nu is guaranteed to be Integer. 	expansionr   r4   rp   s     r5   _expandSphericalBesselBase._expandW  s    !+..r9   c                 `    U R                   R                  (       a  U R                  " S0 UD6$ U $ Nr@   )r6   
is_Integerr1  r0  s     r5   rn   %SphericalBesselBase._eval_expand_func[  s&    ::  <<(%((r9   c                     US:w  a  [        X5      eU R                  U R                  S-
  U R                  5      X R                  S-   -  U R                  -  -
  $ rH   )r
   rK   r6   r<   rM   s     r5   rO   SphericalBesselBase.fdiff`  sO    q=$T44~~djj1ndmm<JJN#DMM12 	2r9   r@   Nry   )	rz   r{   r|   r}   r~   r1  rn   rO   r   r@   r9   r5   r,  r,  K  s    	/
2r9   r,  c                     [        X5      [        U5      -  [        R                  U S-   -  [        U * S-
  U5      -  [	        U5      -  -   $ Nr;   )r*   r   r   r   r   r   rD   s     r5   _jnr<  g  sK    %c!f,MMAE"#6rAvq#AA#a&HI Jr9   c                     [         R                  U S-   -  [        U * S-
  U5      -  [        U5      -  [        X5      [	        U5      -  -
  $ r:  )r   r   r*   r   r   r;  s     r5   _ynr>  l  sI    MMAE"%8!a%CCCFJ%c!f,- .r9   c                   F    \ rS rSrSr\S 5       rS rS rS r	S r
S rS	rg
)rb   ir  aV  
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                 T   UR                   (       ac  UR                   (       a  [        R                  $ UR                  (       a1  UR                  (       a  [        R
                  $ [        R                  $ U[        R                  [        R                  4;   a  [        R
                  $ g r?   )	rd   r   r   r\   rm   r   r   r   r   rA   s      r5   rE   jn.eval  sa    99zzuu>>66M,,,##QZZ0066M 1r9   c                 h    [        [        SU-  -  5      [        U[        R                  -   U5      -  $ r   )r   r   r^   r   r   r   s       r5   r   jn._eval_rewrite_as_besselj  s(    B!H~QVVQ 777r9   c                     [         R                  U-  [        [        SU-  -  5      -  [	        U* [         R
                  -
  U5      -  $ r   )r   r   r   r   r   r   r   s       r5   r   jn._eval_rewrite_as_bessely  s8    }}b 4AaC>1GRC!&&L!4LLLr9   c                 J    [         R                  U-  [        U* S-
  U5      -  $ r:  )r   r   rc   r   s       r5   r   jn._eval_rewrite_as_yn  s"    }}r"Ra^33r9   c                 B    [        U R                  U R                  5      $ r?   )r<  r6   r<   r0  s     r5   r1  
jn._expand      4::t}}--r9   c                     U R                   R                  (       a$  U R                  [        5      R	                  U5      $ g r?   r6   r5  r   r^   _eval_evalfr4   precs     r5   rM  jn._eval_evalf  .    ::  <<(44T:: !r9   r@   N)rz   r{   r|   r}   r~   r   rE   r   r   r   r1  rM  r   r@   r9   r5   rb   rb   r  s6    8r 
 
8M4.;r9   rb   c                   J    \ rS rSrSr\S 5       r\S 5       rS rS r	S r
Srg	)
rc   i  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                     [         R                  US-   -  [        [        SU-  -  5      -  [	        U* [         R
                  -
  U5      -  $ rk   )r   r   r   r   r^   r   r   s       r5   r   yn._eval_rewrite_as_besselj  s<    }}r!t$tB!H~5affa8PPPr9   c                 h    [        [        SU-  -  5      [        U[        R                  -   U5      -  $ r   )r   r   r   r   r   r   s       r5   r   yn._eval_rewrite_as_bessely  s(    B!H~QVVQ 777r9   c                 P    [         R                  US-   -  [        U* S-
  U5      -  $ r:  )r   r   rb   r   s       r5   r   yn._eval_rewrite_as_jn  s&    }}rAv&RC!GQ77r9   c                 B    [        U R                  U R                  5      $ r?   )r>  r6   r<   r0  s     r5   r1  
yn._expand  rJ  r9   c                     U R                   R                  (       a$  U R                  [        5      R	                  U5      $ g r?   )r6   r5  r   r   rM  rN  s     r5   rM  yn._eval_evalf  rQ  r9   r@   N)rz   r{   r|   r}   r~   r*  r   r   r   r1  rM  r   r@   r9   r5   rc   rc     sA    -\ Q Q 8 88.;r9   rc   c                   R    \ rS rSr\S 5       r\S 5       rS rS rS r	S r
S rS	rg
)SphericalHankelBasei  c                     U R                   n[        [        SU-  -  5      [        U[        R
                  -   U5      U[        -  [        R                  US-   -  -  [        U* [        R
                  -
  U5      -  -   -  $ rH   )_hankel_kind_signr   r   r^   r   r   r   r   r4   rC   rD   rv   hkss        r5   r   ,SphericalHankelBase._eval_rewrite_as_besselj  sq    
 $$B!H~wrAFF{A6"1uQ]]RT%::7B3<QR;SS T U 	Ur9   c                     U R                   n[        [        SU-  -  5      [        R                  U-  [        U* [        R                  -
  U5      -  U[        -  [        U[        R                  -   U5      -  -   -  $ r   )r`  r   r   r   r   r   r   r   ra  s        r5   r   ,SphericalHankelBase._eval_rewrite_as_bessely  si    
 $$B!H~q}}b0"qvvq1II"1uWR!&&[!%<< = > 	>r9   c                     U R                   n[        X5      R                  [        5      U[        -  [        X5      -  -   $ r?   )r`  rb   r   rc   r   ra  s        r5   r   'SphericalHankelBase._eval_rewrite_as_yn   s3    $$"y  $s1uRY66r9   c                     U R                   n[        X5      U[        -  [        X5      R	                  [        5      -  -   $ r?   )r`  rb   r   rc   r   ra  s        r5   r   'SphericalHankelBase._eval_rewrite_as_jn$  s4    $$"y3q5B!2!22!6666r9   c                     U R                   R                  (       a  U R                  " S0 UD6$ U R                   nU R                  nU R                  n[        X#5      U[        -  [        X#5      -  -   $ r4  )r6   r5  r1  r<   r`  rb   r   rc   )r4   rp   rC   rD   rb  s        r5   rn   %SphericalHankelBase._eval_expand_func(  sY    ::  <<(%((BA((Cb9s1uRY..r9   c                     U R                   nU R                  nU R                  n[        X#5      U[        -  [        X#5      -  -   R                  5       $ r?   )r6   r<   r`  r<  r   r>  expand)r4   rp   r   rD   rb  s        r5   r1  SphericalHankelBase._expand1  sE    JJMM$$ A	CE#a)O+3355r9   c                     U R                   R                  (       a$  U R                  [        5      R	                  U5      $ g r?   rL  rN  s     r5   rM  SphericalHankelBase._eval_evalf@  rQ  r9   r@   N)rz   r{   r|   r}   r*  r   r   r   r   rn   r1  rM  r   r@   r9   r5   r^  r^    sC    U U > >77/6;r9   r^  c                   @    \ rS rSrSr\R                  r\S 5       r	Sr
g)r`   iE  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                 D    [        [        SU-  -  5      [        X5      -  $ r   )r   r   r  r   s       r5   _eval_rewrite_as_hankel1hn1._eval_rewrite_as_hankel1x      B!H~gbn,,r9   r@   N)rz   r{   r|   r}   r~   r   r   r`  r*  rs  r   r@   r9   r5   r`   r`   E  s&    .` - -r9   r`   c                   B    \ rS rSrSr\R                  * r\S 5       r	Sr
g)ra   i}  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                 D    [        [        SU-  -  5      [        X5      -  $ r   )r   r   r  r   s       r5   _eval_rewrite_as_hankel2hn2._eval_rewrite_as_hankel2  ru  r9   r@   N)rz   r{   r|   r}   r~   r   r   r`  r*  rx  r   r@   r9   r5   ra   ra   }  s(    .` - -r9   ra   c                 0  ^ ^^^^ SSK Jn  TS:X  at  SSKJn  SSKJn  U" U5      n[        SUS-   5       Vs/ s HE  n[        R                  " U" [        T S-   5      R                  U5      [        U5      5      U5      PMG     sn$ TS:X  a  SS	KJm   SS
KJm  U U4S jn	O[%        S5      eUU4S jn
T U-   nU
" X5      nU/n[        US-
  5       H  nU
" XU-   5      nUR'                  U5        M!     U$ s  snf ! [          a    SSKJm  U U4S jn	 Nhf = f)a1  
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_precr;   g      ?scipy)newton)spherical_jnc                    > T" TU 5      $ r?   r@   )rf   r   r  s    r5   <lambda>jn_zeros.<locals>.<lambda>  s    ,q!,r9   )sph_jnc                 "   > T" TU 5      S   S   $ )Nr   r   r@   )rf   r   r  s    r5   r  r    s    &A,q/"-r9   Unknown method.c                 :   > TS:X  a
  T" X5      nU$ [        S5      e)Nr~  r  r/  )rq   rf   r    methodr  s      r5   solverjn_zeros.<locals>.solver  s)    W!<D  &&788r9   )mathr   mpmathr|  mpmath.libmp.libmpfr}  r   r   _from_mpmathr   
_to_mpmathintscipy.optimizer  scipy.specialr  ImportErrorr  r   r   )r   r   r  dpsmath_pir|  r}  rO  lrq   r  r    rootsir  r  r  s   ` `           @@@r5   jn_zerosr    s   Z #&33 q!a%*(A !!+aCj.C.CD.I.1!f#67;=(* 	* 
7	)	.2,A
 ""344 w;D!?DFE1q5\a(T  L=*  	.,-A	.s   AC6C; ;DDc                   8    \ rS rSrSrS rS rS	S jrS	S jrSr	g)
AiryBasei	  z[
Abstract base class for Airy functions.

This class is meant to reduce code duplication.

c                 Z    U R                  U R                  S   R                  5       5      $ r   )funcr2   rT   r3   s    r5   rV   AiryBase._eval_conjugate  s"    yy1//122r9   c                 4    U R                   S   R                  $ r   )r2   r   r3   s    r5   r   AiryBase._eval_is_extended_real  s    yy|,,,r9   c                     U R                   S   nUR                  5       nU R                  nU" U5      U" U5      -   S-  n[        U" U5      U" U5      -
  -  S-  nXg4$ )Nr   rI   )r2   rT   r  r   )r4   deeprp   rD   zcrq   uvs           r5   as_real_imagAiryBase.as_real_imag  sY    IIaL[[]IIqT!B%ZNquQqTzN1tr9   c                 D    U R                   " SSU0UD6u  p4X4[        -  -   $ )Nr  r@   )r  r   )r4   r  rp   re_partim_parts        r5   _eval_expand_complexAiryBase._eval_expand_complex  s*    ,,@$@%@""r9   r@   N)T)
rz   r{   r|   r}   r~   rV   r   r  r  r   r@   r9   r5   r  r  	  s    3-#r9   r  c                   l    \ rS rSrSrSrSr\S 5       rSS jr	\
\S 5       5       rS rS	 rS
 rS rSrg)airyaii$  a  
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

r;   Tc                    UR                   (       a  U[        R                  L a  [        R                  $ U[        R                  L a  [        R                  $ U[        R
                  L a  [        R                  $ UR                  (       a6  [        R                  S[        SS5      -  [        [        SS5      5      -  -  $ UR                  (       a6  [        R                  S[        SS5      -  [        [        SS5      5      -  -  $ g )Nr   rI   )
	is_Numberr   r   r   r   r   rd   r   r   r&   rB   r   s     r5   rE   airyai.eval  s    ==aee|uu

"vv***vvuu8Aq> 1E(1a.4I IJJ;;55Ax1~-hq!n0EEFF r9   c                 T    US:X  a  [        U R                  S   5      $ [        X5      eNr;   r   )airyaiprimer2   r
   rM   s     r5   rO   airyai.fdiff  '    q=tyy|,,$T44r9   c           	      X   U S:  a  [         R                  $ [        U5      n[        U5      S:  a  US   n[	        S5      U-  U * -  [	        S5      U-  U S-   -  -  [        [        U [        SS5      -  [        SS5      -   -  5      -  [        U 5      -  [        U S-  [        SS5      -   5      -  [        [        U [        SS5      -  [        SS5      -   -  5      [        U S-   5      -  [        U S-  [        SS5      -   5      -  -  U-  $ [         R                  S[        SS5      -  [        -  -  [        U [         R                  -   [        S5      -  5      -  [        [        SS5      [        -  U [         R                  -   -  5      -  [        U 5      -  [	        S5      U-  U -  -  $ )Nr   r;   r   r   rI   r   )r   r   r   lenr   r   r   r   r   r&   r   r   rf   previous_termsr   s       r5   taylor_term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 7r9   c                     [        SS5      n[        SS5      n[        U* [        SS5      5      n[        U5      R                  (       a.  U[	        U* 5      -  [        U* XE-  5      [        X4U-  5      -   -  $ g Nr;   r   rI   r   r   r"   ro   r   r^   r4   rD   rv   otttrg   s         r5   r   airyai._eval_rewrite_as_besselj  sl    a^a^HQN#a5dA2h;'2#rt"4wra47H"HII r9   c                 f   [        SS5      n[        SS5      n[        U[        SS5      5      n[        U5      R                  (       a-  U[	        U5      -  [        U* XE-  5      [        X4U-  5      -
  -  $ U[        XS5      [        U* XE-  5      -  U[        XS* 5      -  [        X4U-  5      -  -
  -  $ r  r   r   r"   rm   r   r_   r  s         r5   r   airyai._eval_rewrite_as_besseli  s    a^a^8Aq>"a5d1g:"bd!3gbQ$6G!GHHs1z'2#rt"44qQ}WRTUQUEV7VVWWr9   c           	      >   [         R                  S[        SS5      -  [        [        SS5      5      -  -  nU[	        SS5      [        [        SS5      5      -  -  nU[        / [        SS5      /US-  S-  5      -  U[        / [        SS5      /US-  S-  5      -  -
  $ )Nr   rI   r;   	   r   )r   r   r   r&   r    r)   r4   rD   rv   pf1pf2s        r5   _eval_rewrite_as_hyper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dr9   c                 ^   U R                   S   nUR                  n[        U5      S:X  Ga  UR                  5       n[	        SU/S9n[	        SU/S9n[	        SU/S9n[	        SU/S9nUR                  XVXH-  -  U-  -  5      n	U	b  X   nSU-  R                  (       a  X   nX   nX   nXdU-  -  U-  Xg-  XGU-  -  -  -  n
XVU-  -  XGU-  -  -  n[        R                  U
[        R                  -   [        U5      -  U
[        R                  -
  [        S5      -  [        U5      -  -
  -  $ g g g 	Nr   r;   r   )excludedmr   r   )r2   free_symbolsr  popr   matchr\   r   r   r   r  r   airybir4   rp   r   symbsrD   r   r  r  r   Mpfnewargs               r5   rn   airyai._eval_expand_func  s<   iil  u:?		AS1#&AS1#&AS1#&AS1#&A		!qtVaK-(A}D aC##AAAd(Q!$qS/:BAXaC0F66b155j&.%@BJPTUVPWCWX^_eXfCf%fgg $	  r9   r@   Nr;   rz   r{   r|   r}   r~   nargs
unbranchedr   rE   rO   staticmethodr   r  r   r   r  rn   r   r@   r9   r5   r  r  $  sb    Vp EJG G5 7  7JXe
hr9   r  c                   l    \ rS rSrSrSrSr\S 5       rSS jr	\
\S 5       5       rS rS	 rS
 rS rSrg)r  i  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

r;   Tc                    UR                   (       a  U[        R                  L a  [        R                  $ U[        R                  L a  [        R                  $ U[        R                  L a  [        R
                  $ UR                  (       a6  [        R                  S[        SS5      -  [        [        SS5      5      -  -  $ UR                  (       a6  [        R                  S[        SS5      -  [        [        SS5      5      -  -  $ g )Nr   r;      rI   )
r  r   r   r   r   r   rd   r   r   r&   r  s     r5   rE   airybi.eval.  s    ==aee|uu

"zz!***vvuu8Aq> 1E(1a.4I IJJ;;55Ax1~-hq!n0EEFF r9   c                 T    US:X  a  [        U R                  S   5      $ [        X5      er  )airybiprimer2   r
   rM   s     r5   rO   airybi.fdiff=  r  r9   c           
      p   U S:  a  [         R                  $ [        U5      n[        U5      S:  a  US   n[	        S5      U-  [        [        [        SS5      [        -  U [         R                  -   -  5      5      -  [        U [         R                  -
  [        S5      -  5      -  U [         R                  -   [        [        [        SS5      [        -  U [         R                  -   -  5      5      -  [        U S-
  [        S5      -  5      -  -  U-  $ [         R                  [        SS5      [        -  -  [        U [         R                  -   [        S5      -  5      -  [        [        [        SS5      [        -  U [         R                  -   -  5      5      -  [        U 5      -  [	        S5      U-  U -  -  $ )Nr   r;   r   r   rI   r  )r   r   r   r  r   r!   r   r   r   r   r   r   r   r    r&   r  s       r5   r  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 7r9   c                     [        SS5      n[        SS5      n[        U* [        SS5      5      n[        U5      R                  (       a.  [	        U* S-  5      [        U* XE-  5      [        X4U-  5      -
  -  $ g r  r  r  s         r5   r   airybi._eval_rewrite_as_besseljR  sl    a^a^HQN#a51:"bd!3gbQ$6G!GHH r9   c                    [        SS5      n[        SS5      n[        U[        SS5      5      n[        U5      R                  (       a6  [	        U5      [	        S5      -  [        U* XE-  5      [        X4U-  5      -   -  $ [        XS5      n[        XS* 5      n[	        U5      U[        U* XE-  5      -  X-  [        X4U-  5      -  -   -  $ r  r  r4   rD   rv   r  r  rg   r   r   s           r5   r   airybi._eval_rewrite_as_besseliY  s    a^a^8Aq>"a5747?grc24&872!t;L&LMMA
AAsA8QwsBD11ACqD8I4IIJJr9   c           	      8   [         R                  [        SS5      [        [	        SS5      5      -  -  nU[        SS5      -  [        [	        SS5      5      -  nU[        / [	        SS5      /US-  S-  5      -  U[        / [	        SS5      /US-  S-  5      -  -   $ )Nr   r  rI   r;   r  r   )r   r   r    r&   r   r)   r  s        r5   r  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dr9   c                 ^   U R                   S   nUR                  n[        U5      S:X  Ga  UR                  5       n[	        SU/S9n[	        SU/S9n[	        SU/S9n[	        SU/S9nUR                  XVXH-  -  U-  -  5      n	U	b  X   nSU-  R                  (       a  X   nX   nX   nXdU-  -  U-  Xg-  XGU-  -  -  -  n
XVU-  -  XGU-  -  -  n[        R                  [        S5      [        R                  U
-
  -  [        U5      -  [        R                  U
-   [        U5      -  -   -  $ g g g r  )r2   r  r  r  r   r  r\   r   r   r   r   r  r  r  s               r5   rn   airybi._eval_expand_funci  s:   iil  u:?		AS1#&AS1#&AS1#&AS1#&A		!qtVaK-(A}D aC##AAAd(Q!$qS/:BAXaC0F66T!Waeebj%9&.%HAEETVJX^_eXfKf%fgg $	  r9   r@   Nr  r  r@   r9   r5   r  r    sb    Xt EJG G5 7  7I	Ke
hr9   r  c                   X    \ rS rSrSrSrSr\S 5       rSS jr	S r
S rS	 rS
 rS rSrg)r  i  aI  
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

r;   Tc                 @   UR                   (       aF  U[        R                  L a  [        R                  $ U[        R                  L a  [        R                  $ UR
                  (       a6  [        R                  S[        SS5      -  [        [        SS5      5      -  -  $ g )Nr   r;   )	r  r   r   r   r   rd   r   r   r&   r  s     r5   rE   airyaiprime.eval  sh    ==aee|uu

"vv;;==Ax1~$5hq!n8M$MNN r9   c                 t    US:X  a(  U R                   S   [        U R                   S   5      -  $ [        X5      er  )r2   r  r
   rM   s     r5   rO   airyaiprime.fdiff  4    q=99Q<tyy| 444$T44r9   c                     U R                   S   R                  U5      n[        U5         [        R                  " USS9nS S S 5        [
        R                  " WU5      $ ! , (       d  f       N%= fNr   r;   )
derivative)r2   r  r,   r+   r  r   r  r4   rO  rD   ress       r5   rM  airyaiprime._eval_evalf  Q    IIaL##D)d^))A!,C   d++ ^   A
A-c                     [        SS5      n[        U* [        SS5      5      n[        U5      R                  (       a$  US-  [	        U* X4-  5      [	        X3U-  5      -
  -  $ g NrI   r   )r   r   r"   ro   r^   r4   rD   rv   r  rg   s        r5   r   $airyaiprime._eval_rewrite_as_besselj  s[    a^HQN#a5Q3'2#rt,wra4/@@AA r9   c                    [        SS5      n[        SS5      nU[        U[        SS5      5      -  n[        U5      R                  (       a  US-  [	        XE5      [	        U* U5      -
  -  $ [        U[        SS5      5      n[        XT5      n[        XT* 5      nX1S-  U-  [	        XDU-  5      -  U[	        U* XE-  5      -  -
  -  $ r  )r   r   r"   rm   r_   r  s           r5   r   $airyaiprime._eval_rewrite_as_besseli  s    a^a^QA''a5Q3'".7B3?:;;Ax1~&AA
AAsAAaqD 11Agrc246H4HHIIr9   c           	      .   US-  SS[        SS5      -  -  [        [        SS5      5      -  -  nS[        SS5      [        [        SS5      5      -  -  nU[        / [        SS5      /US-  S-  5      -  U[        / [        SS5      /US-  S-  5      -  -
  $ )NrI   r   r;      r  )r   r&   r    r)   r  s        r5   r  "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dr9   c                 ^   U R                   S   nUR                  n[        U5      S:X  Ga  UR                  5       n[	        SU/S9n[	        SU/S9n[	        SU/S9n[	        SU/S9nUR                  XVXH-  -  U-  -  5      n	U	b  X   nSU-  R                  (       a  X   nX   nX   nXg-  XHU-  -  -  XdU-  -  U-  -  n
XVU-  -  XHU-  -  -  n[        R                  U
[        R                  -   [        U5      -  U
[        R                  -
  [        S5      -  [        U5      -  -   -  $ g g g r  )r2   r  r  r  r   r  r\   r   r   r   r  r   r  r  s               r5   rn   airyaiprime._eval_expand_func  s=   iil  u:?		AS1#&AS1#&AS1#&AS1#&A		!qtVaK-(A}D
 aC##AAA$qS/aQ$h]:BAXaC0F66b155j+f2E%EaeeUYZ[U\H\]hio]pHp%pqq $  r9   r@   Nr  rz   r{   r|   r}   r~   r  r  r   rE   rO   rM  r   r   r  rn   r   r@   r9   r5   r  r    sK    Ob EJO O5,B
Je
rr9   r  c                   X    \ rS rSrSrSrSr\S 5       rSS jr	S r
S rS	 rS
 rS rSrg)r  i  aR  
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

r;   Tc                    UR                   (       a  U[        R                  L a  [        R                  $ U[        R                  L a  [        R                  $ U[        R                  L a  [        R
                  $ UR                  (       a%  S[        SS5      -  [        [        SS5      5      -  $ UR                  (       a%  S[        SS5      -  [        [        SS5      5      -  $ g )Nr   r;   r  )	r  r   r   r   r   r   rd   r   r&   r  s     r5   rE   airybiprime.evalu  s    ==aee|uu

"zz!***vv(1a.(5!Q+@@@;;hq!n$uXa^'<<< r9   c                 t    US:X  a(  U R                   S   [        U R                   S   5      -  $ [        X5      er  )r2   r  r
   rM   s     r5   rO   airybiprime.fdiff  r  r9   c                     U R                   S   R                  U5      n[        U5         [        R                  " USS9nS S S 5        [
        R                  " WU5      $ ! , (       d  f       N%= fr  )r2   r  r,   r+   r  r   r  r  s       r5   rM  airybiprime._eval_evalf  r  r  c                     [        SS5      nU[        U* [        SS5      5      -  n[        U5      R                  (       a)  U* [	        S5      -  [        U* U5      [        X45      -   -  $ g r  r  r  s        r5   r   $airybiprime._eval_rewrite_as_besselj  s^    a^aR!Q((a52d1g:"a72>!ABB r9   c                    [        SS5      n[        SS5      nU[        U[        SS5      5      -  n[        U5      R                  (       a(  U[	        S5      -  [        U* U5      [        XE5      -   -  $ [        U[        SS5      5      n[        XT5      n[        XT* 5      n[	        U5      U[        U* XE-  5      -  US-  U-  [        XDU-  5      -  -   -  $ r  r  r  s           r5   r   $airybiprime._eval_rewrite_as_besseli  s    a^a^QA''a5T!W9Q'". @AAAx1~&AA
AAsA8q"bd!33ad1fWRA=N6NNOOr9   c           	      "   US-  S[        SS5      -  [        [        SS5      5      -  -  n[        SS5      [        [        SS5      5      -  nU[        / [        SS5      /US-  S-  5      -  U[        / [        SS5      /US-  S-  5      -  -   $ )NrI   r   r  r;   r
  r  )r    r&   r   r)   r  s        r5   r  "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dr9   c                 ^   U R                   S   nUR                  n[        U5      S:X  Ga  UR                  5       n[	        SU/S9n[	        SU/S9n[	        SU/S9n[	        SU/S9nUR                  XVXH-  -  U-  -  5      n	U	b  X   nSU-  R                  (       a  X   nX   nX   nXg-  XHU-  -  -  XdU-  -  U-  -  n
XVU-  -  XHU-  -  -  n[        R                  [        S5      U
[        R                  -
  -  [        U5      -  U
[        R                  -   [        U5      -  -   -  $ g g g r  )r2   r  r  r  r   r  r\   r   r   r   r   r  r  r  s               r5   rn   airybiprime._eval_expand_func  s?   iil  u:?		AS1#&AS1#&AS1#&AS1#&A		!qtVaK-(A}D
 aC##AAA$qS/aQ$h]:BAXaC0F66T!Wb155j%9+f:M%MQSVWV[V[Q[]hio]pPp%pqq $  r9   r@   Nr  r  r@   r9   r5   r  r    sI    Qf EJ= =5,C
Pe
rr9   r  c                   J    \ rS rSrSr\S 5       rSS jrS rS r	S r
S rS	rg
)marcumqi  a  
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                 R   U[         R                  L aa  U[         R                  L a#  U[         R                  L a  [         R                  $ [        XS-  [         R                  -  5      [	        U5      -  $ U[         R                  L a8  U[         R                  L a%  SS[        US-  [         R                  -  5      -  -
  $ X#:X  a  U[         R                  L a3  S[        US-  * 5      [        SUS-  5      -  -   [         R                  -  $ US:X  aa  [         R                  [         R                  [        US-  * 5      -  [        SUS-  5      -  -   [        US-  * 5      [        SUS-  5      -  -   $ UR                  (       a]  UR                  (       a!  UR                  (       a  [         R                  $ [        XS-  [         R                  -  5      [	        U5      -  $ UR                  (       a7  UR                  (       a%  SS[        US-  [         R                  -  5      -  -
  $ g g r  )	r   r   r(   r   r&   r   r   r_   rd   )rB   r  rg   r   s       r5   rE   marcumq.eval  s   ;AFF{qAFF{vvaA/%(::;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aAaff-a8899q3q!tAFF{++++ #9r9   c                     U R                   u  p#nUS:X  a   U[        X#U5      * [        SU-   X45      -   -  $ US:X  a8  XB-  * X2S-
  -  -  [        US-  US-  -   * S-  5      -  [        US-
  X4-  5      -  $ [	        X5      e)NrI   r;   r   )r2   r  r   r_   r
   )r4   rN   r  rg   r   s        r5   rO   marcumq.fdiff  s    ))aq=q))GAaC,>>??]TEA!H$adQTkN1,<(==!QS@QQQ$T44r9   c           	         SSK Jn  UR                  S[        [	        S5      R
                  5      5      nUSU-
  -  U" Xa-  [        US-  US-  -   * S-  5      -  [        US-
  X&-  5      -  Xc[        R                  /5      -  $ )Nr   )Integralrf   r;   rI   )
sympy.integrals.integralsr%  getr   r   namer   r_   r   r   )r4   r  rg   r   rv   r%  rf   s          r5   _eval_rewrite_as_Integral!marcumq._eval_rewrite_as_Integral  s    6JJsE"7"<"A"ABCQU|sQTAqD[>!#344wqsAC7HH1QRQ[Q[J\]^ 	^r9   c           	          SSK Jn  UR                  S[        S5      5      n[	        US-  US-  -   * S-  5      U" X#-  U-  [        XbU-  5      -  USU-
  [        R                  /5      -  $ )Nr   )Sumr   rI   r;   )sympy.concrete.summationsr,  r'  r   r   r_   r   r   )r4   r  rg   r   rv   r,  r   s          r5   _eval_rewrite_as_Summarcumq._eval_rewrite_as_Sum  sh    1JJsE#J'QTAqD[>A%&acAXQ3-G!QqSRSR\R\I])^^^r9   c                 d  ^ TU:X  a  US:X  a%  S[        TS-  * 5      [        STS-  5      -  -   S-  $ UR                  (       al  US:  ae  [        U4S j[	        SU5       5       5      n[
        R                  [        TS-  * 5      [        STS-  5      -  S-  -   [        TS-  * 5      U-  -   $ g g g )Nr;   rI   r   c              3   B   >#    U  H  n[        UTS -  5      v   M     g7f)rI   N)r_   ).0r  rg   s     r5   	<genexpr>3marcumq._eval_rewrite_as_besseli.<locals>.<genexpr>$  s     >+Q1a4((+s   )r   r_   r5  sumr   r   r   )r4   r  rg   r   rv   r   s     `   r5   r    marcumq._eval_rewrite_as_besseli  s    6AvCAJAqD)999Q>>||Q>%1+>>vvQTE
WQ1-= = AACAJQRNRR !'| r9   c                 H    [        S U R                   5       5      (       a  gg )Nc              3   8   #    U  H  oR                   v   M     g 7fr?   )rd   )r2  r   s     r5   r3  (marcumq._eval_is_zero.<locals>.<genexpr>(  s     0is{{is   T)allr2   r3   s    r5   _eval_is_zeromarcumq._eval_is_zero'  s    0dii000 1r9   r@   Nry   )rz   r{   r|   r}   r~   r   rE   rO   r)  r.  r   r;  r   r@   r9   r5   r  r    s8    .` , ,.5^_
Sr9   r  N)r{     )U	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   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*   r  r+   r,   r.   r^   r   r_   r  r  r  r*  r,  r<  r>  rb   rc   r^  r`   ra   r  r  r  r  r  r  r  r@   r9   r5   <module>rR     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r9   