
    EdB                     |   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          ZLdCd5ZM G d6 d7e          ZN G d8 d9eN          ZO G d: d;eN          ZP G d< d=eN          ZQ G d> d?eN          ZR G d@ dAe          ZSdBS )D    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                   t    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dS )
BesselBasea  
    Abstract base class for Bessel-type functions.

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

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

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

    c                     | j         d         S )z( The order of the Bessel-type function. r   argsselfs    >lib/python3.11/site-packages/sympy/functions/special/bessel.pyorderzBesselBase.order4        y|    c                     | j         d         S )z+ The argument of the Bessel-type function.    r/   r1   s    r3   argumentzBesselBase.argument9   r5   r6   c                     d S N clsnuzs      r3   evalzBesselBase.eval>   s    r6      c                     |dk    rt          | |          | j        dz  |                     | j        dz
  | j                  z  | j        dz  |                     | j        dz   | j                  z  z
  S NrB   r8   )r
   _b	__class__r4   r9   _ar2   argindexs     r3   fdiffzBesselBase.fdiffB   sr    q= 	5$T8444	DNN4:>4=III	DNN4:>4=IIIJ 	Kr6   c                     | j         }|j        du r?|                     | j                                        |                                          S d S NF)r9   is_extended_negativerF   r4   	conjugater2   r@   s     r3   _eval_conjugatezBesselBase._eval_conjugateH   sP    M!U* 	I>>$*"6"6"8"8!++--HHH	I 	Ir6   c           	         | j         | j        }}|                    |          rdS |                    ||          sd S |                    ||          }|j        rOt          | 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    
DMA66!99 	5%%a++ 	4VVAq\\= 	1$'3R DEE 1RZ 1 0002:r~">??@@@r6   c                    | j         | j        | j        }}}|j        r|dz
  j        rh| j         | j        z   ||dz
  |                                          z  d| j        z  |dz
  z   ||dz
  |                                          z  |z  z   S |dz   j        rgd| j        z  |dz   z   ||dz   |                                          z  |z  | j        | j        z   ||dz   |                                          z  z
  S | S Nr8   rB   )	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}dnqA: 	JQ# J(261)G)G)I)II$'	26*11R!VQ<<+I+I+K+KKAMN Oq&% J$'	26*11R!VQ<<+I+I+K+KKAM"q&!(F(F(H(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66666z$r6   NrB   )__name__
__module____qualname____doc__propertyr4   r9   classmethodrA   rJ   rP   rS   rf   rn   r<   r6   r3   r-   r-   $   s            X   X   [K K K KI I I
A A A	 	 	         r6   r-   c                   v     e Zd ZdZej        Zej        Zed             Z	d Z
d Zd ZddZd	 Zd fd
	Z xZS )rW   a3  
    Bessel function of the first kind.

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

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

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

    with Laurent expansion

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

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

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

    Examples
    ========

    Create a Bessel function object:

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

    Differentiate it:

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

    Rewrite in terms of spherical Bessel functions:

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

    Access the parameter and argument:

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

    See Also
    ========

    bessely, besseli, besselk

    References
    ==========

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

    c                    |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 |                                r||z  | | z  z  t          ||           z  S |j        rm|                                r"t          j        | z  t          | |          z  S |                    t"                    }|rt"          |z  t%          ||          z  S |j        r&t'          |          }||k    rt          ||          S nS|                                \  }}|dk    r6t+          d|z  t,          z  |z  t"          z            t          ||          z  S t'          |          }||k    rt          ||          S d S NFTr   rB   )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   9 	z u- BJ%$7 BrFF<N vB# R]d-B (( uQ/00 	6M%%'' 	77QB2#;&wrA266= 	1**,, <}s+GRCOO;;--a00D 12wwr40000 = 	:a==Dqy )r4((() --//GD!Av :1Q3r6"9Q;''D(9(999nn9 	#3??"	# 	#r6   c                     t          t          t          z  |z  dz            t          |t	          t                     |z            z  S NrB   )r   r   r   rX   r#   r2   r?   r@   rm   s       r3   _eval_rewrite_as_besseliz besselj._eval_rewrite_as_besseli   s6    1R4719~~gb*aR..*:;;;;r6   c                     |j         du rRt          t          |z            t          | |          z  t	          t          |z            t          ||          z  z
  S d S rL   )rU   r   r   besselyr   r   s       r3   _eval_rewrite_as_besselyz besselj._eval_rewrite_as_bessely   sY    =E! 	Jr"u::grc1oo-BrE

72q>>0III	J 	J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||BrAF{DM::::r6   Nr   c                     | j         \  }}|                    |          }||j        v r||z  d|z  t          |dz             z  z  S |                     ||                    |d                    S NrB   r8   r   )r0   as_leading_termfree_symbolsr%   funcrT   )r2   r_   logxcdirr?   r@   args          r3   _eval_as_leading_termzbesselj._eval_as_leading_term   sr    	A""   	/7ArE%Q--/0099R1...r6   c                 >    | j         \  }}|j        r	|j        rdS d S d S NTr0   rU   is_extended_realr2   r?   r@   s      r3   _eval_is_extended_realzbesselj._eval_is_extended_real   :    	A= 	Q/ 	4	 	 	 	r6   c                 
   ddl m} | j        \  }}	 |                    |          \  }}	n# t          t
          f$ r | cY S w xY w|	j        rt          ||	z            }
 |||z  |          }|dz                      ||||          	                                }|t          j        u r|S t          |dz            |z   	                                }||z  t          |dz             z  }|g}t          d|
dz   dz            D ]J}|| |||z   z  z  z  }t          |          |z   	                                }|                    |           Kt!          | |z   S t#          t$          |                               ||||          S Nr   )OrderrB   r8   )sympy.series.orderr   r0   leadterm
ValueErrorNotImplementedErrorre   r   _eval_nseriesremoveOr   rz   r   r%   rangeappendr   superrW   )r2   r_   r   r   r   r   r?   r@   _r   newnorttermskrF   s                    r3   r   zbesselj._eval_nseries   s   ,,,,,,	A	ZZ]]FAss/0 	 	 	KKK	 ? 	1S5>>DadAA1##Aq$55==??AAF{ !Q$!#,,..Ab5rAv&DA1tax!m,,  ArAvJ' *33557Q;Wd##11!QdCCC   , AANr   r   )rp   rq   rr   rs   r   ry   rG   rE   ru   rA   r   r   r   r   r   r   __classcell__rF   s   @r3   rW   rW   j   s        B BH 
B	
B!# !# [!#F< < <J J J; ; ;/ / / /  
D D D D D D D D D Dr6   rW   c                   v     e Zd ZdZej        Zej        Zed             Z	d Z
d Zd Zd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] http://functions.wolfram.com/Bessel-TypeFunctions/BesselY/

    c                    |j         rU|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 |j        r6|	                                r$t          j
        | z  t          | |          z  S d S d S rL   )r]   r   r   r!   r{   r}   r~   rz   rU   r   r   r   r=   s      r3   rA   zbessely.eval7  s    9 	z ))B5( ((B uQ/00 	6M= 	<**,, <}s+GRCOO;;	< 	<< <r6   c                     |j         du rRt          t          |z            t          t          |z            t	          ||          z  t	          | |          z
  z  S d S rL   )rU   r   r   r   rW   r   s       r3   _eval_rewrite_as_besseljz bessely._eval_rewrite_as_besseljG  sY    =E! 	Lr"u::s2b5zz'"a..87B3??JKK	L 	Lr6   c                 \     | j         | j         }|r|                    t                    S d S r;   )r   r0   rewriterX   r2   r?   r@   rm   ajs        r3   r   z bessely._eval_rewrite_as_besseliK  7    *T*DI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_ynP  s-    AaCF||bafdm<<<<r6   Nr   c                 F   | j         \  }}d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        v s	||	j        v r|	S |                     ||                    |d                                                    S )NrB   r8   )r   r   )r0   r   r   rW   re   r   r   rz   r&   
EulerGammar   r   r   r   rT   cancel)
r2   r_   r   r   r?   r@   term_oneterm_two
term_threer   s
             r3   r   zbessely._eval_as_leading_termS  s   	ArT3qs88OGBNN2:<9IUQqSRCL=26!2!22255qvsRiZIbMM!12GBFOOal4RS
Hh
34DDQTDRR!! 	8TS-=%= 	8J99R1!4!4!6!6777r6   c                 >    | j         \  }}|j        r	|j        rdS d S d S r   r0   rU   re   r   s      r3   r   zbessely._eval_is_extended_real^  9    	A= 	Q] 	4	 	 	 	r6   c                    ddl m} | j        \  }}	 |                    |          \  }}	n# t          t
          f$ r | cY S w xY w|	j        rs|j        rkt          ||	z            }
t          ||          }dt          z  t          |dz            z  |z                      ||||          }g g }} |||z  |          }|dz                      ||||                                          }|t          j        u r|S t!          |dz            |z                                   }|t          j        k    r|| z  t%          |dz
            z  t          z  }|                    |           t)          d|dz
            D ]L}||||z
  dz
  z  |z  z  }t!          |          |z                                   }|                    |           M||z  t          t%          |          z  z  }|t+          |dz             t          j        z
  z  }|                    |           t)          d|
dz   dz            D ]u}|| |||z   z  z  z  }t!          |          |z                                   }|t+          ||z   dz             t+          |dz             z   z  }|                    |           v|t/          | z
  t/          | z
  S t1          t2          |                               ||||          S r   )r   r   r0   r   r   r   re   rU   r   rW   r   r   r   r   r   rz   r   ry   r   r   r   r&   r   r   r   r   )r2   r_   r   r   r   r   r?   r@   r   r   r   bnr`   bcr   r   r   r   r   prF   s                        r3   r   zbessely._eval_nseriesc  s   ,,,,,,	A	ZZ]]FAss/0 	 	 	KKK	 ? 	)r} 	)1S5>>DQBB$AaC#221atDDArqAadAA1##Aq$55==??AAF{ !Q$!#,,..AAEz #B3x	"q& 1 11"4q"q&)) # #AArAvzN1,,D$TNNQ.7799DHHTNNNN2r)B--'(Agb1foo45DHHTNNN1tax!m,,  aRAF_$a[[1_--//'!b&1*--A>?sAw;a((Wd##11!QdCCCr   r   r   )rp   rq   rr   rs   r   ry   rG   rE   ru   rA   r   r   r   r   r   r   r   r   s   @r3   r   r     s        & &P 
B	
B< < [<L L L' ' '
= = =	8 	8 	8 	8  
)D )D )D )D )D )D )D )D )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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] http://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 |                                r||z  | | z  z  t          ||           z  S |j        r^|                                rt          | |          S |                    t"                    }|rt"          | z  t%          ||           z  S |j        r&t'          |          }||k    rt          ||          S nS|                                \  }}|dk    r6t+          d|z  t,          z  |z  t"          z            t          ||          z  S t'          |          }||k    rt          ||          S d S rx   )r]   r   ry   rU   r!   re   rz   rg   r{   r|   r}   r"   r~   r   r   rX   r   r   rW   r$   r   r   r   r   s         r3   rA   zbesseli.eval  s    9 	z u- BJ%$7 BrFF<N vB# R]d-B (( ua55QZ!344 	6M%%'' 	77QB2#;&wrA266= 	3**,, 'sA&--a00D 3B3xTE 2 222 = 	:a==Dqy )r4((() --//GD!Av :1Q3r6"9Q;''D(9(999nn9 	#3??"	# 	#r6   c                     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  s5    A2b58A:wr:a==?;;;;r6   c                 \     | j         | j         }|r|                    t                    S d S r;   r   r0   r   r   r   s        r3   r   z besseli._eval_rewrite_as_bessely  r   r6   c                 P     | j         | j                             t                    S r;   )r   r0   r   r[   r   s       r3   r   zbesseli._eval_rewrite_as_jn  s"    ,t,di8@@DDDr6   c                 >    | j         \  }}|j        r	|j        rdS d S d S r   r   r   s      r3   r   zbesseli._eval_is_extended_real  r   r6   N)rp   rq   rr   rs   r   ry   rG   rE   ru   rA   r   r   r   r   r<   r6   r3   rX   rX     s        % %N %B	
B!# !# [!#F< < <' ' '
E E E    r6   rX   c                   d    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S )	besselka  
    Modified Bessel function of the second kind.

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

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

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

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

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

    Examples
    ========

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

    See Also
    ========

    besselj, besseli, bessely

    References
    ==========

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

    c                    |j         rU|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%|
                                rt          | |          S d S d S rL   )r]   r   r~   r!   r{   r}   r   r   rz   rU   r   r   r=   s      r3   rA   zbesselk.eval  s    9 	z z!B5( ((B uQqz\1Q-?+?@@ 	6M= 	'**,, 'sA&	' 	'' 'r6   c                     |j         du rEt          t          t          |z            z  t          | |          t          ||          z
  z  dz  S d S )NFrB   )rU   r   r   rX   r   s       r3   r   z besselk._eval_rewrite_as_besseli(  sS    =E! 	Fc"R%jj='2#q//GBNN"BCAEE	F 	Fr6   c                 \     | j         | j         }|r|                    t                    S d S r;   )r   r0   r   rW   )r2   r?   r@   rm   ais        r3   r   z besselk._eval_rewrite_as_besselj,  r   r6   c                 \     | j         | j         }|r|                    t                    S d S r;   r   r   s        r3   r   z besselk._eval_rewrite_as_bessely1  r   r6   c                 \     | j         | j         }|r|                    t                    S d S r;   )r   r0   r   r\   )r2   r?   r@   rm   ays        r3   r   zbesselk._eval_rewrite_as_yn6  s5    *T*DI6 	"::b>>!	" 	"r6   c                 >    | j         \  }}|j        r	|j        rdS d S d S r   r   r   s      r3   r   zbesselk._eval_is_extended_real;  r   r6   N)rp   rq   rr   rs   r   ry   rG   rE   ru   rA   r   r   r   r   r   r<   r6   r3   r   r     s        # #J 
B
%B' ' ['F F F' ' '
' ' '
" " "
    r6   r   c                   4    e Zd ZdZej        Zej        Zd ZdS )hankel1a  
    Hankel function of the first kind.

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

    This function is defined as

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

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

    It is a solution to Bessel's equation.

    Examples
    ========

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

    See Also
    ========

    hankel2, besselj, bessely

    References
    ==========

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

    c                     | j         }|j        du r9t          | j                                        |                                          S d S rL   )r9   rM   hankel2r4   rN   rO   s     r3   rP   zhankel1._eval_conjugatei  L    M!U* 	B4://111;;==AAA	B 	Br6   N	rp   rq   rr   rs   r   ry   rG   rE   rP   r<   r6   r3   r   r   A  sC        " "H 
B	
BB B B B Br6   r   c                   4    e Zd ZdZej        Zej        Zd ZdS )r   a  
    Hankel function of the second kind.

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

    This function is defined as

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

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

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

    Examples
    ========

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

    See Also
    ========

    hankel1, besselj, bessely

    References
    ==========

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

    c                     | j         }|j        du r9t          | j                                        |                                          S d S rL   )r9   rM   r   r4   rN   rO   s     r3   rP   zhankel2._eval_conjugate  r   r6   Nr   r<   r6   r3   r   r   o  sC        # #J 
B	
BB B B B Br6   r   c                 <     t                      fd            }|S )Nc                 0    |j         r | ||          S d S r;   )rU   )r2   r?   r@   fns      r3   gzassume_integer_order.<locals>.g  s)    = 	#2dB??"	# 	#r6   r   )r   r   s   ` r3   assume_integer_orderr     s3    
2YY# # # # Y# Hr6   c                   &    e Zd ZdZd Zd ZddZdS )SphericalBesselBasea-  
    Base class for spherical Bessel functions.

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

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

    c                      t          d          )z@ Expand self into a polynomial. Nu is guaranteed to be Integer. 	expansionr   r2   rh   s     r3   _expandzSphericalBesselBase._expand  s    !+...r6   c                 8    | j         j        r | j        di |S | S Nr<   )r4   
is_Integerr   r   s     r3   rf   z%SphericalBesselBase._eval_expand_func  s,    :  	)4<((%(((r6   rB   c                     |dk    rt          | |          |                     | j        dz
  | j                  | | j        dz   z  | j        z  z
  S rD   )r
   rF   r4   r9   rH   s     r3   rJ   zSphericalBesselBase.fdiff  sV    q= 	5$T8444~~dj1ndm<<DJN#DM12 	2r6   Nro   )rp   rq   rr   rs   r   rf   rJ   r<   r6   r3   r   r     sP        	 	/ / /  
2 2 2 2 2 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     sU    1%%c!ff,MAE"#6rAvq#A#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    sS    MAE"%8!a%C%CCCFFJ1%%c!ff,- .r6   c                   F    e Zd ZdZed             Zd Zd Zd Zd Z	d Z
dS )	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] http://dlmf.nist.gov/10.47

    c                     |j         r9|j         rt          j        S |j        r|j        rt          j        S t          j        S |t          j        t          j        fv rt          j        S d S r;   )	r]   r   ry   rU   re   rz   r{   r   r~   r=   s      r3   rA   zjn.eval  si    9 	-z -u -> -6M,,#QZ00 	6M	 	r6   c                 r    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~~QVQ 7 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  s9    }b 4AaC>>1GRC!&L!4L4L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                 6    t          | j        | j                  S r;   )r   r4   r9   r   s     r3   r   z
jn._expand      4:t}---r6   c                 x    | j         j        r-|                     t                                        |          S d S r;   r4   r   r   rW   _eval_evalfr2   precs     r3   r  zjn._eval_evalf   9    :  	;<<((44T:::	; 	;r6   N)rp   rq   rr   rs   ru   rA   r   r   r   r   r  r<   r6   r3   r[   r[     s        8 8r 
 
 [
8 8 8M M M4 4 4. . .; ; ; ; ;r6   r[   c                   P    e Zd ZdZed             Zed             Zd Zd Zd Z	dS )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] http://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_besseljT  s=    }r!t$tB!H~~5afa8P8PPPr6   c                 r    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_besselyX  s+    B!H~~QVQ 7 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                 6    t          | j        | j                  S r;   )r  r4   r9   r   s     r3   r   z
yn._expand_  r	  r6   c                 x    | j         j        r-|                     t                                        |          S d S r;   )r4   r   r   r   r  r  s     r3   r  zyn._eval_evalfb  r  r6   N)
rp   rq   rr   rs   r   r   r   r   r   r  r<   r6   r3   r\   r\   %  s        - -\ Q Q Q 8 8 88 8 8. . .; ; ; ; ;r6   r\   c                   X    e Zd Zed             Zed             Zd Zd Zd Zd Z	d Z
dS )	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 rD   )_hankel_kind_signr   r   rW   r   r   r   r   r2   r?   r@   rm   hkss        r3   r   z,SphericalHankelBase._eval_rewrite_as_besselji  sp    
 $B!H~~wrAF{A66"1uQ]RT%::7B3<QR;S;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_besselyr  sh    
 $B!H~~q}b0"qvq1I1II"1uWR!&[!%<%<< = > 	>r6   c                     | j         }t          ||                              t                    |t          z  t          ||          z  z   S r;   )r  r[   r   r\   r   r  s        r3   r   z'SphericalHankelBase._eval_rewrite_as_yn{  s;    $"ayy  $$s1uRAYY66r6   c                     | j         }t          ||          |t          z  t          ||                              t                    z  z   S r;   )r  r[   r   r\   r   r  s        r3   r   z'SphericalHankelBase._eval_rewrite_as_jn  s<    $"ayy3q5B!2!22!6!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!99s1uRAYY..r6   c                     | j         }| j        }| j        }t          ||          |t          z  t          ||          z  z                                   S r;   )r4   r9   r  r   r   r  expand)r2   rh   r   r@   r  s        r3   r   zSphericalHankelBase._expand  sI    JM$ Aq		CE#a))O+33555r6   c                 x    | j         j        r-|                     t                                        |          S d S 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  g  s        U U U > > >7 7 77 7 7/ / /6 6 6; ; ; ; ;r6   r  c                   6    e Zd ZdZej        Zed             ZdS )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] http://dlmf.nist.gov/10.47

    c                 X    t          t          d|z  z            t          ||          z  S r   )r   r   r   r   s       r3   _eval_rewrite_as_hankel1zhn1._eval_rewrite_as_hankel1  #    B!H~~gb!nn,,r6   N)	rp   rq   rr   rs   r   ry   r  r   r%  r<   r6   r3   rY   rY     sC        . .` - - - - -r6   rY   c                   8    e Zd ZdZej         Zed             ZdS )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] http://dlmf.nist.gov/10.47

    c                 X    t          t          d|z  z            t          ||          z  S r   )r   r   r   r   s       r3   _eval_rewrite_as_hankel2zhn2._eval_rewrite_as_hankel2  r&  r6   N)	rp   rq   rr   rs   r   ry   r  r   r)  r<   r6   r3   rZ   rZ     sE        . .` - - - - -r6   rZ   sympy   c                     ddl m} dk    r8ddlm ddlm}  ||           fdt          d|dz             D             S dk    r0dd	lm 	 dd
l	m
  fd}n+# t          $ r ddl	m  fd}Y nw xY wt          d          fd} |z   } |||          }|g}	t          |dz
            D ]&}
 ||||z             }|	                    |           '|	S )a  
    Zeros of the spherical Bessel function of the first kind.

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

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

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

    Examples
    ========

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

    See Also
    ========

    jn, yn, besselj, besselk, bessely

    Parameters
    ==========

    n : integer
        order of Bessel function

    k : integer
        number of zeros to return


    r   )r   r*  )besseljzero)dps_to_precc           
          g | ]Q}t          j         t          d z                                           t	          |                              RS )g      ?)r   _from_mpmathr   
_to_mpmathint).0lr-  r   r  s     r3   
<listcomp>zjn_zeros.<locals>.<listcomp>C  sj     * * * !++aCjj.C.CD.I.I.1!ff#6 #67;= = * * *r6   r8   scipy)newton)spherical_jnc                      |           S r;   r<   )r_   r   r8  s    r3   <lambda>zjn_zeros.<locals>.<lambda>J  s    ,,q!,, r6   )sph_jnc                 4     |           d         d         S )Nr   r<   )r_   r   r;  s    r3   r:  zjn_zeros.<locals>.<lambda>M  s    &&A,,q/"- r6   Unknown method.c                 L    dk    r | |          }nt          d          |S )Nr6  r>  r   )ri   r_   r   methodr7  s      r3   solverzjn_zeros.<locals>.solverQ  s5    W 	96!Q<<DD%&7888r6   )mathr   mpmathr-  mpmath.libmp.libmpfr.  r   scipy.optimizer7  scipy.specialr8  ImportErrorr;  r   r   )r   r   r@  dpsmath_pir.  ri   rA  r   rootsir-  r7  r  r;  r8  s   ` `        @@@@@r3   jn_zerosrL    s   Z #""""" 5&&&&&&333333{3* * * * * *q!a%* * * 	* 
7	 	5))))))	.222222,,,,,AA 	. 	. 	.,,,,,,-----AAA	. ""3444      w;D6!T??DFE1q5\\  va((TLs   A& &A?>A?c                   .    e Zd ZdZd Zd ZddZddZdS )	AiryBasezg
    Abstract base class for Airy functions.

    This class is meant to reduce code duplication.

    c                 f    |                      | j        d                                                   S r   )r   r0   rN   r1   s    r3   rP   zAiryBase._eval_conjugatel  s&    yy1//11222r6   c                 &    | j         d         j        S r   )r0   r   r1   s    r3   r   zAiryBase._eval_is_extended_realo  s    y|,,r6   Tc                     | j         d         }|                                }| j        } ||           ||          z   dz  }t           ||           ||          z
  z  dz  }||fS )Nr   rB   )r0   rN   r   r   )r2   deeprh   r@   zcri   uvs           r3   as_real_imagzAiryBase.as_real_imagr  si    IaL[[]]IQqTT!!B%%ZNqquuQQqTTzN1!tr6   c                 J     | j         dd|i|\  }}||t          j        z  z   S )NrR  r<   )rV  r   ImaginaryUnit)r2   rR  rh   re_partim_parts        r3   _eval_expand_complexzAiryBase._eval_expand_complexz  s6    ,4,@@$@%@@000r6   N)T)rp   rq   rr   rs   rP   r   rV  r[  r<   r6   r3   rN  rN  d  sd         3 3 3- - -   1 1 1 1 1 1r6   rN  c                   v    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dS )airyaia  
    The Airy function $\operatorname{Ai}$ of the first kind.

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

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

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

    Equivalently, for real $z$

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

    Examples
    ========

    Create an Airy function object:

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

    >>> airyai(z)
    airyai(z)

    Several special values are known:

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

    The Airy function obeys the mirror symmetry:

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

    Differentiation with respect to $z$ is supported:

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

    Series expansion is also supported:

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

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

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

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

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

    See Also
    ========

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

    References
    ==========

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

    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>t          j        dt          dd          z  t          t          dd                    z  z  S |j        r>t          j        dt          dd          z  t          t          dd                    z  z  S d S )N   rB   )
	is_Numberr   r}   r~   rz   r   r]   ry   r   r%   r>   r   s     r3   rA   zairyai.eval  s    = 	Kae| Ku
" Kv** Kv Ku8Aq>> 1E(1a..4I4I IJJ; 	G5Ax1~~-hq!nn0E0EEFF	G 	Gr6   c                 b    |dk    rt          | j        d                   S t          | |          Nr8   r   )airyaiprimer0   r
   rH   s     r3   rJ   zairyai.fdiff  2    q= 	5ty|,,,$T8444r6   c           	          | dk     rt           j        S t          |          }t          |          dk    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_  rB      )r   rz   r   lenr   r   r   r   r   r%   ry   r   r_   previous_termsr   s       r3   taylor_termzairyai.taylor_term  s
    q5 
	76M

A>""Q& 7"2&aqb)47719A*>>s2qRSUVGWZbcdfgZhZhGhCi?j?jjktuvkwkwwacHQNN233458Qx1~~=MPXYZ\]P^P^=^9_5`5`ajklopkpaqaq5qrwxyz{x{  G  HI  KL  M  M  yM  sN  sN  6NO RSS T q(1a..034uagqtt^7L7LLsS[\]_`SaSabdSdfghihmfmSnOoOoo!!%(,Q	A~6 7r6   c                 $   t          dd          }t          dd          }t          | t          dd                    }t          |          j        r<|t	          |           z  t          | ||z            t          |||z            z   z  S d S Nr8   r_  rB   r   r   r!   rg   r   rW   r2   r@   rm   otttr`   s         r3   r   zairyai._eval_rewrite_as_besselj  s    a^^a^^HQNN##a55 	JdA2hh;'2#r!t"4"4wr2a47H7H"HII	J 	Jr6   c                    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 rm  r   r   r!   re   r   rX   ro  s         r3   r   zairyai._eval_rewrite_as_besseli  s    a^^a^^8Aq>>""a55 	Xd1gg:"bd!3!3gb"Q$6G6G!GHHs1bzz'2#r!t"4"44qQ}WRQSTUQUEVEV7V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_  rB   r8   	   rg  )r   ry   r   r%   r   r(   r2   r@   rm   pf1pf2s        r3   _eval_rewrite_as_hyperzairyai._eval_rewrite_as_hyper  s    eq(1a..(x1~~)>)>>?41::eHQNN3334U2A/Aa8883rHUVXYNNK[]^`a]abc]cAdAd;dddr6   c                    | j         d         }|j        }t          |          dk    r0|                                }t	          d|g          }t	          d|g          }t	          d|g          }t	          d|g          }|                    ||||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 d S d S d S 	Nr   r8   r   )excludedmr   r_  )r0   r   rh  popr   matchrU   r   r   ry   r]  r   airybir2   rh   r   symbsr@   r   r}  r~  r   Mpfnewargs               r3   rf   zairyai._eval_expand_func  s   il u::? 	h		AS1#&&&AS1#&&&AS1#&&&AS1#&&&A		!Qq!tVaK-((A 
haD aC# h!A!A!Aad(Q!Q$QqS/:BAXAaC0F6b15j&..%@BJPTUVPWPWCWX^_eXfXfCf%fgg#	h 	h
h 
hh hr6   Nr8   rp   rq   rr   rs   nargs
unbranchedru   rA   rJ   staticmethodr   rk  r   r   ry  rf   r<   r6   r3   r]  r]    s        V Vp EJG G [G5 5 5 5 7 7 W \7J J JX X Xe e e
h h h h hr6   r]  c                   v    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dS )r  a  
    The Airy function $\operatorname{Bi}$ of the second kind.

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

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

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

    Equivalently, for real $z$

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

    Examples
    ========

    Create an Airy function object:

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

    >>> airybi(z)
    airybi(z)

    Several special values are known:

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

    The Airy function obeys the mirror symmetry:

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

    Differentiation with respect to $z$ is supported:

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

    Series expansion is also supported:

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

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

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

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

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

    See Also
    ========

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

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Airy_function
    .. [2] http://dlmf.nist.gov/9
    .. [3] http://www.encyclopediaofmath.org/index.php/Airy_functions
    .. [4] http://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>t          j        dt          dd          z  t          t          dd                    z  z  S |j        r>t          j        dt          dd          z  t          t          dd                    z  z  S d S )Nr_  r8      rB   )
r`  r   r}   r~   r   rz   r]   ry   r   r%   ra  s     r3   rA   zairybi.eval  s    = 	Kae| Ku
" Kz!** Kv Ku8Aq>> 1E(1a..4I4I IJJ; 	G5Ax1~~-hq!nn0E0EEFF	G 	Gr6   c                 b    |dk    rt          | j        d                   S t          | |          rc  )airybiprimer0   r
   rH   s     r3   rJ   zairybi.fdiff  re  r6   c           
         | dk     rt           j        S t          |          }t          |          dk    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_  rB   r  )r   rz   r   rh  r   r    r   r   r   ry   r   r   r   r   r%   ri  s       r3   rk  zairybi.taylor_term  s    q5 
	76M

A>""Q& 7"2&Q	CHQNN2,=q15y,I(J(J$K$KKiYZ]^]bYbdefgdhdhXhNiNiiae)s3x1~~b/@!af*/M+N+N'O'OOR[]^ab]bdefgdhdh\hRiRiikmno p tAqzz"}-q15y!A$$6F0G0GG#cRZ[\^_R`R`acRcefijinenRoNpNpJqJqq!!%(,Q	A~6 7r6   c                 $   t          dd          }t          dd          }t          | t          dd                    }t          |          j        r<t	          | dz            t          | ||z            t          |||z            z
  z  S d S rm  rn  ro  s         r3   r   zairybi._eval_rewrite_as_besselj  s    a^^a^^HQNN##a55 	I1::"bd!3!3gb"Q$6G6G!GHH	I 	Ir6   c                    t          dd          }t          dd          }t          |t          dd                    }t          |          j        rHt	          |          t	          d          z  t          | ||z            t          |||z            z   z  S t          ||          }t          ||           }t	          |          |t          | ||z            z  ||z  t          |||z            z  z   z  S rm  rs  r2   r@   rm   rp  rq  r`   r   r   s           r3   r   zairybi._eval_rewrite_as_besseli  s    a^^a^^8Aq>>""a55 	K77477?grc2a4&8&872r!t;L;L&LMMAr

AAsA88QwsBqD111AaCBqD8I8I4IIJJr6   c           	         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  rB   r8   ru  rg  )r   ry   r   r%   r   r(   rv  s        r3   ry  zairybi._eval_rewrite_as_hyper  s    etAqzz%A"7"778Q

lU8Aq>>222U2A/Aa8883rHUVXYNNK[]^`a]abc]cAdAd;dddr6   c                    | j         d         }|j        }t          |          dk    r0|                                }t	          d|g          }t	          d|g          }t	          d|g          }t	          d|g          }|                    ||||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 d S d S d S r{  )r0   r   rh  r  r   r  rU   r   r   r   ry   r]  r  r  s               r3   rf   zairybi._eval_expand_func  s   il u::? 	h		AS1#&&&AS1#&&&AS1#&&&AS1#&&&A		!Qq!tVaK-((A 
haD aC# h!A!A!Aad(Q!Q$QqS/:BAXAaC0F6T!WWaebj%9&..%HAETVJX^_eXfXfKf%fgg#	h 	h
h 
hh hr6   Nr  r  r<   r6   r3   r  r  +  s        X Xt EJG G [G5 5 5 5 7 7 W \7I I I	K 	K 	Ke e e
h h h h hr6   r  c                   V    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dS )rd  a+  
    The derivative $\operatorname{Ai}^\prime$ of the Airy function of the first
    kind.

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

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

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

    Examples
    ========

    Create an Airy function object:

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

    >>> airyaiprime(z)
    airyaiprime(z)

    Several special values are known:

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

    The Airy function obeys the mirror symmetry:

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

    Differentiation with respect to $z$ is supported:

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

    Series expansion is also supported:

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

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

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

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

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

    See Also
    ========

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

    References
    ==========

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

    r8   Tc                    |j         r4|t          j        u rt          j        S |t          j        u rt          j        S |j        r>t          j        dt          dd          z  t          t          dd                    z  z  S d S )Nr_  r8   )	r`  r   r}   r~   rz   r]   r   r   r%   ra  s     r3   rA   zairyaiprime.eval1  s}    = 	ae| u
" v; 	O=Ax1~~$5hq!nn8M8M$MNN	O 	Or6   c                 ~    |dk    r(| j         d         t          | j         d                   z  S t          | |          rc  )r0   r]  r
   rH   s     r3   rJ   zairyaiprime.fdiff<  =    q= 	59Q<ty| 4 444$T8444r6   c                     | j         d                             |          }t          |          5  t          j        |d          }d d d            n# 1 swxY w Y   t          j        ||          S Nr   r8   )
derivative)r0   r1  r+   r*   r]  r   r0  r2   r  r@   ress       r3   r  zairyaiprime._eval_evalfB      IaL##D))d^^ 	- 	-)A!,,,C	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- d+++   AAAc                     t          dd          }t          | t          dd                    }t          |          j        r.|dz  t	          | ||z            t	          |||z            z
  z  S d S NrB   r_  )r   r   r!   rg   rW   r2   r@   rm   rq  r`   s        r3   r   z$airyaiprime._eval_rewrite_as_besseljH  sx    a^^HQNN##a55 	BQ3'2#r!t,,wr2a4/@/@@AA	B 	B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 rm  )r   r   r!   re   rX   r  s           r3   r   z$airyaiprime._eval_rewrite_as_besseliN  s    a^^a^^QA'''a55 	JQ3'"a..7B3??:;;Ax1~~&&AAr

AAsAAaBqD 1 11Agrc2a46H6H4H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 )NrB   r_  r8      ru  )r   r%   r   r(   rv  s        r3   ry  z"airyaiprime._eval_rewrite_as_hyperZ  s    da8Aq>>))%A*?*??@41::eHQNN3334U2A/Aa8883rHUVXYNNK[]^`a]abc]cAdAd;dddr6   c                    | j         d         }|j        }t          |          dk    r0|                                }t	          d|g          }t	          d|g          }t	          d|g          }t	          d|g          }|                    ||||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 d S d S d S r{  )r0   r   rh  r  r   r  rU   r   r   ry   rd  r   r  r  s               r3   rf   zairyaiprime._eval_expand_func_  s   il u::? 	r		AS1#&&&AS1#&&&AS1#&&&AS1#&&&A		!Qq!tVaK-((A raD
 aC# r!A!A!AQ$QqS/a!Q$h]:BAXAaC0F6b15j+f2E2E%EaeUYZ[U\U\H\]hio]p]pHp%pqq'	r 	rr rr rr6   Nr  rp   rq   rr   rs   r  r  ru   rA   rJ   r  r   r   ry  rf   r<   r6   r3   rd  rd    s        O Ob EJO O [O5 5 5 5, , ,B B B
J 
J 
Je e e
r r r r rr6   rd  c                   V    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dS )r  a<  
    The derivative $\operatorname{Bi}^\prime$ of the Airy function of the first
    kind.

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

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

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

    Examples
    ========

    Create an Airy function object:

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

    >>> airybiprime(z)
    airybiprime(z)

    Several special values are known:

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

    The Airy function obeys the mirror symmetry:

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

    Differentiation with respect to $z$ is supported:

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

    Series expansion is also supported:

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

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

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

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

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

    See Also
    ========

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

    References
    ==========

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

    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        r1dt          dd          z  t          t          dd                    z  S |j        r1dt          dd          z  t          t          dd                    z  S d S )Nr_  r8   r  )	r`  r   r}   r~   r   rz   r]   r   r%   ra  s     r3   rA   zairybiprime.eval  s    = 	Aae| Au
" Az!** Av A(1a..(5!Q+@+@@@; 	=hq!nn$uXa^^'<'<<<	= 	=r6   c                 ~    |dk    r(| j         d         t          | j         d                   z  S t          | |          rc  )r0   r  r
   rH   s     r3   rJ   zairybiprime.fdiff  r  r6   c                     | j         d                             |          }t          |          5  t          j        |d          }d d d            n# 1 swxY w Y   t          j        ||          S r  )r0   r1  r+   r*   r  r   r0  r  s       r3   r  zairybiprime._eval_evalf  r  r  c                     t          dd          }|t          | t          dd                    z  }t          |          j        r6| t	          d          z  t          | |          t          ||          z   z  S d S r  rn  r  s        r3   r   z$airybiprime._eval_rewrite_as_besselj  sy    a^^aR!Q(((a55 	C2d1gg:"a72q>>!ABB	C 	Cr6   c                    t          dd          }t          dd          }|t          |t          dd                    z  }t          |          j        r5|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 rm  rs  r  s           r3   r   z$airybiprime._eval_rewrite_as_besseli  s    a^^a^^QA'''a55 	PT!WW9Q'"a.. @AAAx1~~&&AAr

AAsA88q"bd!3!33ad1fWRA=N=N6NNOOr6   c           	      r   |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 )NrB   r_  r  r8   r  ru  )r   r%   r   r(   rv  s        r3   ry  z"airybiprime._eval_rewrite_as_hyper  s    daQ

l5!Q#8#8891ajj5!Q000U2A/Aa8883rHUVXYNNK[]^`a]abc]cAdAd;dddr6   c                    | j         d         }|j        }t          |          dk    r0|                                }t	          d|g          }t	          d|g          }t	          d|g          }t	          d|g          }|                    ||||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 d S d S d S r{  )r0   r   rh  r  r   r  rU   r   r   r   ry   rd  r  r  s               r3   rf   zairybiprime._eval_expand_func  s   il u::? 	r		AS1#&&&AS1#&&&AS1#&&&AS1#&&&A		!Qq!tVaK-((A raD
 aC# r!A!A!AQ$QqS/a!Q$h]:BAXAaC0F6T!WWb15j%9+f:M:M%MQSVWV[Q[]hio]p]pPp%pqq'	r 	rr rr rr6   Nr  r  r<   r6   r3   r  r  y  s        Q Qf EJ= = [=5 5 5 5, , ,C C C
P 
P 
Pe e e
r r r r rr6   r  c                   H    e Zd ZdZed             Zd
dZd Zd Zd Z	d Z
d	S )marcumqa  
    The Marcum Q-function.

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

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

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

    Examples
    ========

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

    Special values:

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

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

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

    References
    ==========

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

    c                    |t           j        u rX|t           j        u r|t           j        u rt           j        S t          ||dz  t           j        z            t	          |          z  S |t           j        u r3|t           j        u r%ddt          |dz  t           j        z            z  z
  S ||k    r|t           j        u r7dt          |dz             t          d|dz            z  z   t           j        z  S |dk    rit           j        t           j        t          |dz             z  t          d|dz            z  z   t          |dz             t          d|dz            z  z   S |j        rJ|j        r|j        rt           j        S t          ||dz  t           j        z            t	          |          z  S |j        r,|j        r'ddt          |dz  t           j        z            z  z
  S d S d S r   )	r   rz   r'   r   r%   r   ry   rX   r]   )r>   r~  r`   r   s       r3   rA   zmarcumq.evalN  s   ; 	;AF{ qAF{ vaA//%((::; 	.1; 	.q3q!taf}-----6 	gAEz BCAJJAqD)9)99916AAAv gvadU 3gaA6F6F FFaQRdUV]^_abdeaeVfVfIfff9 	9y QY vaAaf--a889 	, 	,q3q!tAF{+++++	, 	, 	, 	,r6   rB   c                 *   | j         \  }}}|dk    r*|t          |||           t          d|z   ||          z   z  S |dk    rC||z   ||dz
  z  z  t          |dz  |dz  z    dz            z  t          |dz
  ||z            z  S t	          | |          )NrB   r8   r_  )r0   r  r   rX   r
   )r2   rI   r~  r`   r   s        r3   rJ   zmarcumq.fdifff  s    )1aq= 	5Aq)))GAaCA,>,>>??] 	5TEA!H$adQTkN1,<(=(==!QqS@Q@QQQ$T8444r6   c           	         ddl m} |                    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   rB   )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_Integralo  s    666666JJsE#JJ''QU|x1sQTAqD[>!#3444wqsAaC7H7HH1aQRQ[J\]]^ 	^r6   c           	          ddl m} |                    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   rB   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_Sumu  s    111111JJsE#JJ''QTAqD[>A%&&acAX1Q3-G!QqSRSR\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    r{t          fdt	          d|          D                       }t
          j        t          dz             t          ddz            z  dz  z   t          dz             |z  z   S d S d S d S )Nr8   rB   r   c                 6    g | ]}t          |d z            S ro   )rX   )r3  rK  r`   s     r3   r5  z4marcumq._eval_rewrite_as_besseli.<locals>.<listcomp>  s'    ???aAqD))???r6   )r   rX   r   sumr   r   r   )r2   r~  r`   r   rm   r   s     `   r3   r   z marcumq._eval_rewrite_as_besseliz  s    6 	SAv ?CAJJAqD)9)999Q>>| SQ S????5A;;???@@vQTE

WQ1-=-= = AACAJJQRNRR	S 	SS S S Sr6   c                 F    t          d | j        D                       rdS d S )Nc              3   $   K   | ]}|j         V  d S r;   )r]   )r3  r   s     r3   	<genexpr>z(marcumq._eval_is_zero.<locals>.<genexpr>  s$      00ss{000000r6   T)allr0   r1   s    r3   _eval_is_zerozmarcumq._eval_is_zero  s2    00di00000 	4	 	r6   Nro   )rp   rq   rr   rs   ru   rA   rJ   r  r  r   r  r<   r6   r3   r  r    s        . .` , , [,.5 5 5 5^ ^ ^_ _ _
S S S    r6   r  N)r*  r+  )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)   rC  r*   r+   r-   rW   r   rX   r   r   r   r   r   r   r  r[   r\   r  rY   rZ   rL  rN  r]  r  rd  r  r  r<   r6   r3   <module>r     s                     $ $ $ $ $ $             F F F F F F F F F F 0 0 0 0 0 0 0 0 . . . . . . . . . .             ) ) ) ) ) ) ) ) & & & & & & > > > > > > G G G G G G G G G G G G 7 7 7 7 7 7 ; ; ; ; ; ; ; ; E E E E E E E E E E V V V V V V V V V V V V V V N N N N N N N N N N / / / / / / 6 6 6 6 6 6        C  C  C  C  C  C  C  C L^D ^D ^D ^D ^Dj ^D ^D ^DBAD AD AD AD ADj AD AD ADH] ] ] ] ]j ] ] ]@O O O O Oj O O Od+B +B +B +B +Bj +B +B +B\,B ,B ,B ,B ,Bj ,B ,B ,B^  2 2 2 2 2* 2 2 28J J J
. . .U; U; U; U; U;	 U; U; U;p?; ?; ?; ?; ?;	 ?; ?; ?;D6; 6; 6; 6; 6;- 6; 6; 6;r5- 5- 5- 5- 5-
 5- 5- 5-p5- 5- 5- 5- 5-
 5- 5- 5-pQ Q Q Qh1 1 1 1 1x 1 1 16ih ih ih ih ihX ih ih ihXnh nh nh nh nhX nh nh nhbZr Zr Zr Zr Zr( Zr Zr Zrzar ar ar ar ar( ar ar arHg g g g gh g g g g gr6   