
    g                        d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZmZmZ d dlmZmZ d dlmZmZmZ d d	lmZ d d
lmZmZmZ d dlmZ d dlmZ d dlm Z m!Z!m"Z"m#Z# d dl$m%Z% d dl&m'Z'm(Z( d dl)m*Z*m+Z+m,Z, d dl-m.Z.m/Z/m0Z0m1Z1m2Z2 d dl3m4Z4m5Z5m6Z6 d dl7m8Z8 d dl9m:Z: d dl;m<Z<m=Z=  G d d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>          ZC G d" d#e>          ZDd$ ZE G d% d&e>          ZFd' ZGd( ZH G d) d*eF          ZI G d+ d,eF          ZJ G d- d.eF          ZK G d/ d0eK          ZL G d1 d2eK          ZMdCd5ZN G d6 d7e          ZO G d8 d9eO          ZP G d: d;eO          ZQ G d< d=eO          ZR G d> d?eO          ZS G d@ dAe          ZTdBS )D    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                   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    Z/var/www/html/ai-engine/env/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.    r0   r2   s    r4   argumentzBesselBase.argument9   r6   r7   c                     d S N clsnuzs      r4   evalzBesselBase.eval>   s    r7      c                     |dk    rt          | |          | j        dz  |                     | j        dz
  | j                  z  | j        dz  |                     | j        dz   | j                  z  z
  S NrC   r9   )r
   _b	__class__r5   r:   _ar3   argindexs     r4   fdiffzBesselBase.fdiffB   so    q==$T8444	DNN4:>4=III	DNN4:>4=IIIJ 	Kr7   c                     | j         }|j        du r?|                     | j                                        |                                          S d S NF)r:   is_extended_negativerG   r5   	conjugater3   rA   s     r4   _eval_conjugatezBesselBase._eval_conjugateH   sI    M!U**>>$*"6"6"8"8!++--HHH +*r7   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 rM   )r5   r:   has_eval_is_meromorphicsubs
is_integer
isinstancebesseljbesselihn1hn2jnynis_zeror   is_infiniter   )r3   xar@   rA   z0s         r4   rT   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~">??@@@r7   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 Nr9   rC   )	r5   r:   rG   is_realis_positiverH   rF   _eval_expand_funcis_negative)r3   hintsr@   rA   fs        r4   rg   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r7   c                 $    ddl m}  ||           S )Nr   )
besselsimp)sympy.simplify.simplifyrl   )r3   kwargsrl   s      r4   _eval_simplifyzBesselBase._eval_simplifye   s$    666666z$r7   NrC   )__name__
__module____qualname____doc__propertyr5   r:   classmethodrB   rK   rQ   rT   rg   ro   r=   r7   r4   r.   r.   $   s            X   X   [K K K KI I I
A A A	 	 	         r7   r.   c                   z     e Zd ZdZej        Zej        Zed             Z	d Z
d Zd Zd fd	Zd	 Zd fd
	Z xZS )rX   a4  
    Bessel function of the first kind.

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

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

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

    with Laurent expansion

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

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

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

    Examples
    ========

    Create a Bessel function object:

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

    Differentiate it:

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

    Rewrite in terms of spherical Bessel functions:

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

    Access the parameter and argument:

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

    See Also
    ========

    bessely, besseli, besselk

    References
    ==========

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

    c                    |j         r|j         rt          j        S |j        r	|j         du st	          |          j        rt          j        S t	          |          j        r|j        durt          j        S |j	        rt          j
        S |t          j        t          j        fv rt          j        S |                                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   rC   )r^   r   OnerV   r"   rf   Zerorh   ComplexInfinityis_imaginaryNaNInfinityNegativeInfinitycould_extract_minus_signrX   NegativeOneextract_multiplicativelyr   rY   r%   extract_branch_factorr   r   r?   r@   rA   newznnnus         r4   rB   zbesselj.eval   s   9 	z u- BJ%$7$7BrFF<N$7vB# R]d-B-B(( uQ/0006M%%'' 	77QB2#;&wrA266= 	1**,, <}s+GRCOO;;--a00D 12wwr40000 = 	:a==Dqyyr4(((  --//GD!Avv1Q3r6"9Q;''D(9(999nn993??" 9r7   c                     t          t          t          z  |z  dz            t          |t	          t                     |z            z  S NrC   )r   r   r   rY   r$   r3   r@   rA   rn   s       r4   _eval_rewrite_as_besseliz besselj._eval_rewrite_as_besseli   s6    1R4719~~gb*aR..*:;;;;r7   c                     |j         du rRt          t          |z            t          | |          z  t	          t          |z            t          ||          z  z
  S d S rM   )rV   r   r   besselyr   r   s       r4   _eval_rewrite_as_besselyz besselj._eval_rewrite_as_bessely   sR    =E!!r"u::grc1oo-BrE

72q>>0III "!r7   c                 |    t          d|z  t          z            t          |t          j        z
  | j                  z  S r   )r   r   r\   r   Halfr:   r   s       r4   _eval_rewrite_as_jnzbesselj._eval_rewrite_as_jn   s-    AaCF||BrAF{DM::::r7   Nr   c                    | j         \  }}	 |                    |          }n# t          $ r | cY S w xY w|                    |          \  }}|j        r||z  d|z  t          |dz             z  z  S |j        rf|dk    rdn|}|||z  z  }	|	j        sKt          d          t          |t          d|z  dz   z  dz  z
            z  t          t          |z            z  S | S t          t          |                               |||          S )NrC   r9   r      )r1   as_leading_termNotImplementedErroras_coeff_exponentrf   r&   rh   r   r   r   superrX   _eval_as_leading_termr3   r`   logxcdirr@   rA   argcesignrG   s             r4   r   zbesselj._eval_as_leading_term   s)   	A	##A&&CC" 	 	 	KKK	$$Q''1= 		7ArE%Q--/00] 			11tDT1W9D# C Awws1r1R4!8}Q#6777RT

BBKWd##99!T4HHH   # 22c                 >    | j         \  }}|j        r	|j        rdS d S d S NTr1   rV   is_extended_realr3   r@   rA   s      r4   _eval_is_extended_realzbesselj._eval_is_extended_real   :    	A= 	Q/ 	4	 	 	 	r7   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   OrderrC   r9   )sympy.series.orderr   r1   leadterm
ValueErrorr   rf   r   _eval_nseriesremoveOr   rz   r   r&   rangeappendr   r   rX   r3   r`   r   r   r   r   r@   rA   _r   newnorttermskrG   s                    r4   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   )rq   rr   rs   rt   r   ry   rH   rF   rv   rB   r   r   r   r   r   r   __classcell__rG   s   @r4   rX   rX   j   s        B BH 
B	
B!# !# [!#F< < <J J J; ; ;I I I I I I*  
D D D D D D D D D Dr7   rX   c                   z     e Zd ZdZej        Zej        Zed             Z	d Z
d Zd Zd fd	Zd	 Zd fd
	Z xZS )r   a`  
    Bessel function of the second kind.

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

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

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

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

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

    Examples
    ========

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

    See Also
    ========

    besselj, besseli, besselk

    References
    ==========

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

    c                    |j         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 |t          t          j        z  k    r2t          t          t          z  |dz   z  dz            t          j        z  S |t          t          j        z  k    r3t          t           t          z  |dz   z  dz            t          j        z  S |j        r6|                                r$t          j        | z  t          | |          z  S d S d S )NFr9   rC   )r^   r   r   r"   r{   r}   r~   rz   r   r   r   rV   r   r   r   r>   s      r4   rB   zbessely.evalF  s/   9 	z ))B5((((B uQ/0006M!*qtR!V}Q''!*44!$$$$r"ub1f~a'((1:55= 	<**,, <}s+GRCOO;;	< 	<< <r7   c                     |j         du rRt          t          |z            t          t          |z            t	          ||          z  t	          | |          z
  z  S d S rM   )rV   r   r   r   rX   r   s       r4   _eval_rewrite_as_besseljz bessely._eval_rewrite_as_besseljZ  sR    =E!!r"u::s2b5zz'"a..87B3??JKK "!r7   c                 \     | j         | j         }|r|                    t                    S d S r<   )r   r1   rewriterY   r3   r@   rA   rn   ajs        r4   r   z bessely._eval_rewrite_as_besseli^  7    *T*DI6 	'::g&&&	' 	'r7   c                 |    t          d|z  t          z            t          |t          j        z
  | j                  z  S r   )r   r   r]   r   r   r:   r   s       r4   _eval_rewrite_as_ynzbessely._eval_rewrite_as_ync  s-    AaCF||bafdm<<<<r7   Nr   c                    | j         \  }}	 |                    |          }n# t          $ r | cY S w xY w|                    |          \  }}|j        rdt
          z  t          |dz            z  t          ||          z  }	|j        r%|dz  | z   t          |dz
            z  t
          z  nt          j
        }
|dz  |z   t
          t          |          z  z  t          |dz             t          j        z
  z  }t          |	|
|g                     ||          }|S |j        r|dk    rdn|}|||z  z  }|j        st          d          t!          t
          |z  dz  |z
  t
          dz  z              dt#          t
          |z  dz  |z
  t
          dz  z             z  d|z  z  z   z  t          d|z            z  t          t
                    z  S | S t%          t&          |                               |||          S )NrC   r9   r   r   r         )r1   r   r   r   rf   r   r   rX   r   r   rz   r'   
EulerGammar   rh   r   r   r   r   r   r   )r3   r`   r   r   r@   rA   r   r   r   term_oneterm_two
term_threer   rG   s                r4   r   zbessely._eval_as_leading_termf  s   	A	##A&&CC" 	 	 	KKK	$$Q''1= 	2s1Q3xxA6H>@=MY1}YrAv%6%66r99STSYHQ3)R	"%56Q!,8VWJ(J78HHQUHVVCJ] 			11tDT1W9D# o AwwRU1Wq[2a4%7!8!8 81SBq1rRStAS=T=T;TVWXYVY;Z Z[\`abcdad\e\eefjkmfnfnnnKWd##99!T4HHHr   c                 >    | j         \  }}|j        r	|j        rdS d S d S r   r1   rV   rf   r   s      r4   r   zbessely._eval_is_extended_real  9    	A= 	Q] 	4	 	 	 	r7   c                     ddl m} | j        \  }}	 |                    |          \  }}	n# t          t
          f$ r | cY S w xY w|	j        r|j        rt          ||	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 ]d}||z
  |z  }|t          j        k    r	|||z  z  }n|||z  z  }t!          |          |z                                   }|                    |           e||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 t/          t0          |                               ||||          S r   )r   r   r1   r   r   r   rf   rV   r   rX   r   r   r   r   r   rz   r   r   r   r   r'   r   r   r   r   r3   r`   r   r   r   r   r@   rA   r   r   r   bnra   br   r   r   r   r   r   denomprG   s                         r4   r   zbessely._eval_nseries  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AF{{B3x	"q& 1 11"4q" # #A!VQJE!%$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   )rq   rr   rs   rt   r   ry   rH   rF   rv   rB   r   r   r   r   r   r   r   r   s   @r4   r   r     s        & &P 
B	
B< < [<&L L L' ' '
= = =I I I I I I2  
/D /D /D /D /D /D /D /D /D /Dr7   r   c                   |     e Zd ZdZej         Zej        Zed             Z	d Z
d Zd Zd Zd fd		Zd fd
	Z xZS )rY   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                 f   |j         r|j         rt          j        S |j        r	|j         du st	          |          j        rt          j        S t	          |          j        r|j        durt          j        S |j	        rt          j
        S t          |          t          j        t          j        fv rt          j        S |t          j        u rt          j        S |t          j        u rd|z  t          j        z  S |                                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 )NFTr   rC   )r^   r   ry   rV   r"   rf   rz   rh   r{   r|   r}   r#   r~   r   r   rY   r   r   rX   r%   r   r   r   r   s         r4   rB   zbesseli.eval  s   9 	z u- BJ%$7$7BrFF<N$7vB# R]d-B-B(( ua55QZ!34446M
??:"""8AJ&&%%'' 	77QB2#;&wrA266= 	3**,, 'sA&--a00D 3B3xTE 2 222 = 	:a==Dqyyr4(((  --//GD!Avv1Q3r6"9Q;''D(9(999nn993??" 9r7   c                     t          t           t          z  |z  dz            t          |t	          t                    |z            z  S r   )r   r   r   rX   r$   r   s       r4   r   z besseli._eval_rewrite_as_besselj	  s5    A2b58A:wr:a==?;;;;r7   c                 \     | j         | j         }|r|                    t                    S d S r<   r   r1   r   r   r   s        r4   r   z besseli._eval_rewrite_as_bessely  r   r7   c                 P     | j         | j                             t                    S r<   )r   r1   r   r\   r   s       r4   r   zbesseli._eval_rewrite_as_jn  s"    ,t,di8@@DDDr7   c                 >    | j         \  }}|j        r	|j        rdS d S d S r   r   r   s      r4   r   zbesseli._eval_is_extended_real  r   r7   Nr   c                    | j         \  }}	 |                    |          }n# t          $ r | cY S w xY w|                    |          \  }}|j        r||z  d|z  t          |dz             z  z  S |j        rE|dk    rdn|}|||z  z  }	|	j        s*t          |          t          dt          z  |z            z  S | S t          t          |                               |||          S NrC   r9   r   )r1   r   r   r   rf   r&   rh   r   r   r   r   rY   r   r   s             r4   r   zbesseli._eval_as_leading_term  s
   	A	##A&&CC" 	 	 	KKK	$$Q''1= 		7ArE%Q--/00] 			11tDT1W9D# + 1vvd1R46ll**KWd##99!T4HHHr   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 ]I}|||||z   z  z  z  }t          |          |z   	                                }|                    |           Jt!          | |z   S t#          t$          |                               ||||          S r   )r   r   r1   r   r   r   rf   r   r   r   r   rz   r   r&   r   r   r   r   rY   r   s                    r4   r   zbesseli._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,,  1b1f:& *33557Q;Wd##11!QdCCCr   r   r   )rq   rr   rs   rt   r   ry   rH   rF   rv   rB   r   r   r   r   r   r   r   r   s   @r4   rY   rY     s        % %N %B	
B%# %# [%#N< < <' ' '
E E E  
I I I I I I*D D D D D D D D D Dr7   rY   c                        e Zd ZdZej        Zej         Zed             Z	d Z
d Zd Zd Zd Zd fd
	Zd fd	Z xZS )besselka  
    Modified Bessel function of the second kind.

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

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

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

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

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

    Examples
    ========

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

    See Also
    ========

    besselj, besseli, bessely

    References
    ==========

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

    c                    |j         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 rM   )r^   r   r~   r"   r{   r}   r   r   rz   rV   r   r   r>   s      r4   rB   zbesselk.evalw  s    9 	z z!B5((((B uQqz\1Q-?+?@@@6M= 	'**,, 'sA&	' 	'' 'r7   c                     |j         du rEt          t          t          |z            z  t          | |          t          ||          z
  z  dz  S d S )NFrC   )rV   r   r   rY   r   s       r4   r   z besselk._eval_rewrite_as_besseli  sL    =E!!c"R%jj='2#q//GBNN"BCAEE "!r7   c                 \     | j         | j         }|r|                    t                    S d S r<   )r   r1   r   rX   )r3   r@   rA   rn   ais        r4   r   z besselk._eval_rewrite_as_besselj  r   r7   c                 \     | j         | j         }|r|                    t                    S d S r<   r   r   s        r4   r   z besselk._eval_rewrite_as_bessely  r   r7   c                 \     | j         | j         }|r|                    t                    S d S r<   )r   r1   r   r]   )r3   r@   rA   rn   ays        r4   r   zbesselk._eval_rewrite_as_yn  s5    *T*DI6 	"::b>>!	" 	"r7   c                 >    | j         \  }}|j        r	|j        rdS d S d S r   r   r   s      r4   r   zbesselk._eval_is_extended_real  r   r7   Nr   c                    | j         \  }}	 |                    |          }n# t          $ r | cY S w xY w|                    |          \  }}|j        rd|dz
  z  t          |dz            z  t          ||          z  }	|j        r|dz  | z  t          |dz
            z  dz  nt          j	        }
d|z  |dz  |z  z  dt          |          z  z  t          |dz             t          j        z
  z  }t          |	|
|g                     ||          }|S |j        r8t          t                    t!          |           z  t          d|z            z  S t#          t$          |                               |||          S )Nr   r9   rC   r   )r1   r   r   r   rf   r   rY   r   r   rz   r'   r   r   rh   r   r   r   r   r   r   )r3   r`   r   r   r@   rA   r   r   r   r   r   r   rG   s               r4   r   zbesselk._eval_as_leading_term  s   	A	##A&&CC" 	 	 	KKK	$$Q''1= 		.r1uc!A#hh.wr1~~=H<>;KW!s|Ib1f$5$55a77QRQWHr1Q3)+Qy}}_=wrAvQRQ]?]^J(J78HHQUHVVCJ] 	. 88CGG#D1II--Wd##99!T4HHHr   c                    ddl m} | j        \  }}	 |                    |          \  }}	n# t          t
          f$ r | cY S w xY w|	j        r|j        ryt          ||	z            }
t          ||          }d|dz
  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  dz  }|                    |           t%          d|          D ]d}||z
  |z  }|t          j        k    r	|||z  z  }n|||z  z  }t          |          |z                                   }|                    |           e||z  d|z  z  dt!          |          z  z  }|t'          |dz             t          j        z
  z  }|                    |           t%          d|
dz   dz            D ]t}|||||z   z  z  z  }t          |          |z                                   }|t'          ||z   dz             t'          |dz             z   z  }|                    |           u|t+          | z   t+          | z   S t-          t.          |                               ||||          S )Nr   r   r   r9   rC   )r   r   r1   r   r   r   rf   rV   r   rY   r   r   r   r   rz   r   r   r   r   r'   r   r   r   r   r   s                         r4   r   zbesselk._eval_nseries  s    	-,,,,,	A	ZZ]]FAss/0 	 	 	KKK	 ?  	)r}  	)1S5>>DQBQAaC(+::1atLLArqAadAA1##Aq$55==??AAF{{!Q$!#,,..AAF{{B3x	"q& 1 11!3q" # #AVQJE!%$TNNQ.7799DHHTNNNN2rBh)B--0Agb1foo45DHHTNNN1tax!m,,  Q1r6
^#a[[1_--//'!b&1*--A>?sAw;a((Wd##11!QdCCCr   r   r   )rq   rr   rs   rt   r   ry   rH   rF   rv   rB   r   r   r   r   r   r   r   r   r   s   @r4   r   r   N  s        # #J 
B
%B' ' ['F F F' ' '
' ' '
" " "
  
I I I I I I*/D /D /D /D /D /D /D /D /D /Dr7   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] https://functions.wolfram.com/Bessel-TypeFunctions/HankelH1/

    c                     | j         }|j        du r9t          | j                                        |                                          S d S rM   )r:   rN   hankel2r5   rO   rP   s     r4   rQ   zhankel1._eval_conjugate  E    M!U**4://111;;==AAA +*r7   N	rq   rr   rs   rt   r   ry   rH   rF   rQ   r=   r7   r4   r   r     sC        " "H 
B	
BB B B B Br7   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] https://functions.wolfram.com/Bessel-TypeFunctions/HankelH2/

    c                     | j         }|j        du r9t          | j                                        |                                          S d S rM   )r:   rN   r   r5   rO   rP   s     r4   rQ   zhankel2._eval_conjugate=  r   r7   Nr   r=   r7   r4   r   r     sC        # #J 
B	
BB B B B Br7   r   c                 <     t                      fd            }|S )Nc                 0    |j         r | ||          S d S r<   )rV   )r3   r@   rA   fns      r4   gzassume_integer_order.<locals>.gD  s)    = 	#2dB??"	# 	#r7   r   )r   r   s   ` r4   assume_integer_orderr   C  s3    
2YY# # # # Y# Hr7   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   r3   ri   s     r4   _expandzSphericalBesselBase._expandW  s    !+...r7   c                 8    | j         j        r | j        di |S | S Nr=   )r5   
is_Integerr  r  s     r4   rg   z%SphericalBesselBase._eval_expand_func[  s,    :  	)4<((%(((r7   rC   c                     |dk    rt          | |          |                     | j        dz
  | j                  | | j        dz   z  | j        z  z
  S rE   )r
   rG   r5   r:   rI   s     r4   rK   zSphericalBesselBase.fdiff`  sS    q==$T8444~~dj1ndm<<DJN#DM12 	2r7   Nrp   )rq   rr   rs   rt   r  rg   rK   r=   r7   r4   r  r  K  sP        	 	/ / /  
2 2 2 2 2 2r7   r  c                     t          | |          t          |          z  t          j        | dz   z  t          |  dz
  |          z  t	          |          z  z   S Nr9   )r*   r   r   r   r   r   rA   s     r4   _jnr  g  sU    1%%c!ff,MAE"#6rAvq#A#AA#a&&HI Jr7   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     r4   _ynr  l  sS    MAE"%8!a%C%CCCFFJ1%%c!ff,- .r7   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] https://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   rV   rf   rz   r{   r   r~   r>   s      r4   rB   zjn.eval  se    9 	-z -u -> -6M,,#QZ0006M 10r7   c                 r    t          t          d|z  z            t          |t          j        z   |          z  S r   )r   r   rX   r   r   r   s       r4   r   zjn._eval_rewrite_as_besselj  s+    B!H~~QVQ 7 777r7   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       r4   r   zjn._eval_rewrite_as_bessely  s9    }b 4AaC>>1GRC!&L!4L4LLLr7   c                 J    t           j        |z  t          | dz
  |          z  S r  )r   r   r]   r   s       r4   r   zjn._eval_rewrite_as_yn  s"    }r"Ra^^33r7   c                 6    t          | j        | j                  S r<   )r  r5   r:   r  s     r4   r  z
jn._expand      4:t}---r7   c                 x    | j         j        r-|                     t                                        |          S d S r<   r5   r
  r   rX   _eval_evalfr3   precs     r4   r  zjn._eval_evalf  9    :  	;<<((44T:::	; 	;r7   N)rq   rr   rs   rt   rv   rB   r   r   r   r  r  r=   r7   r4   r\   r\   r  s        8 8r 
 
 [
8 8 8M M M4 4 4. . .; ; ; ; ;r7   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] https://dlmf.nist.gov/10.47

    c                     t           j        |dz   z  t          t          d|z  z            z  t	          | t           j        z
  |          z  S rd   )r   r   r   r   rX   r   r   s       r4   r   zyn._eval_rewrite_as_besselj  s=    }r!t$tB!H~~5afa8P8PPPr7   c                 r    t          t          d|z  z            t          |t          j        z   |          z  S r   )r   r   r   r   r   r   s       r4   r   zyn._eval_rewrite_as_bessely  s+    B!H~~QVQ 7 777r7   c                 P    t           j        |dz   z  t          | dz
  |          z  S r  )r   r   r\   r   s       r4   r   zyn._eval_rewrite_as_jn  s&    }rAv&RC!GQ77r7   c                 6    t          | j        | j                  S r<   )r  r5   r:   r  s     r4   r  z
yn._expand  r  r7   c                 x    | j         j        r-|                     t                                        |          S d S r<   )r5   r
  r   r   r  r  s     r4   r  zyn._eval_evalf  r  r7   N)
rq   rr   rs   rt   r   r   r   r   r  r  r=   r7   r4   r]   r]     s        - -\ Q Q Q 8 8 88 8 8. . .; ; ; ; ;r7   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 rE   )_hankel_kind_signr   r   rX   r   r   r   r   r3   r@   rA   rn   hkss        r4   r   z,SphericalHankelBase._eval_rewrite_as_besselj  sp    
 $B!H~~wrAF{A66"1uQ]RT%::7B3<QR;S;SS T U 	Ur7   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        r4   r   z,SphericalHankelBase._eval_rewrite_as_bessely  sh    
 $B!H~~q}b0"qvq1I1II"1uWR!&[!%<%<< = > 	>r7   c                     | j         }t          ||                              t                    |t          z  t          ||          z  z   S r<   )r(  r\   r   r]   r   r)  s        r4   r   z'SphericalHankelBase._eval_rewrite_as_yn   s;    $"ayy  $$s1uRAYY66r7   c                     | j         }t          ||          |t          z  t          ||                              t                    z  z   S r<   )r(  r\   r   r]   r   r)  s        r4   r   z'SphericalHankelBase._eval_rewrite_as_jn$  s<    $"ayy3q5B!2!22!6!6666r7   c                     | j         j        r | j        di |S | j         }| j        }| j        }t          ||          |t          z  t          ||          z  z   S r	  )r5   r
  r  r:   r(  r\   r   r]   )r3   ri   r@   rA   r*  s        r4   rg   z%SphericalHankelBase._eval_expand_func(  s`    :  	/4<((%(((BA(Cb!99s1uRAYY..r7   c                     | j         }| j        }| j        }t          ||          |t          z  t          ||          z  z                                   S r<   )r5   r:   r(  r  r   r  expand)r3   ri   r   rA   r*  s        r4   r  zSphericalHankelBase._expand1  sI    JM$ Aq		CE#a))O+33555r7   c                 x    | j         j        r-|                     t                                        |          S d S r<   r  r  s     r4   r  zSphericalHankelBase._eval_evalf@  r  r7   N)rq   rr   rs   r   r   r   r   r   rg   r  r  r=   r7   r4   r&  r&    s        U U U > > >7 7 77 7 7/ / /6 6 6; ; ; ; ;r7   r&  c                   6    e Zd ZdZej        Zed             ZdS )rZ   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                 X    t          t          d|z  z            t          ||          z  S r   )r   r   r   r   s       r4   _eval_rewrite_as_hankel1zhn1._eval_rewrite_as_hankel1x  #    B!H~~gb!nn,,r7   N)	rq   rr   rs   rt   r   ry   r(  r   r4  r=   r7   r4   rZ   rZ   E  sC        . .` - - - - -r7   rZ   c                   8    e Zd ZdZej         Zed             ZdS )r[   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                 X    t          t          d|z  z            t          ||          z  S r   )r   r   r   r   s       r4   _eval_rewrite_as_hankel2zhn2._eval_rewrite_as_hankel2  r5  r7   N)	rq   rr   rs   rt   r   ry   r(  r   r8  r=   r7   r4   r[   r[   }  sE        . .` - - - - -r7   r[   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
      <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   r9  )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     r4   
<listcomp>zjn_zeros.<locals>.<listcomp>  sj     * * * !++aCjj.C.CD.I.I.1!ff#6 #67;= = * * *r7   r9   scipy)newton)spherical_jnc                      |           S r<   r=   )r`   r   rG  s    r4   <lambda>zjn_zeros.<locals>.<lambda>  s    ,,q!,, r7   )sph_jnc                 4     |           d         d         S )Nr   r   r=   )r`   r   rJ  s    r4   rI  zjn_zeros.<locals>.<lambda>  s    &&A,,q/"- r7   Unknown method.c                 L    dk    r | |          }nt          d          |S )NrE  rL  r  )rj   r`   r    methodrF  s      r4   solverzjn_zeros.<locals>.solver  s3    W6!Q<<DD%&7888r7   )mathr   mpmathr<  mpmath.libmp.libmpfr=  r   scipy.optimizerF  scipy.specialrG  ImportErrorrJ  r   r   )r   r   rN  dpsmath_pir=  rj   rO  r    rootsir<  rF  r  rJ  rG  s   ` `        @@@@@r4   jn_zerosrZ    s   Z #"""""&&&&&&333333{3* * * * * *q!a%* * * 	* 
7		))))))	.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   )funcr1   rO   r2   s    r4   rQ   zAiryBase._eval_conjugate  s&    yy1//11222r7   c                 &    | j         d         j        S r   )r1   r   r2   s    r4   r   zAiryBase._eval_is_extended_real  s    y|,,r7   Tc                     | j         d         }|                                }| j        } ||           ||          z   dz  }t           ||           ||          z
  z  dz  }||fS )Nr   rC   )r1   rO   r^  r   )r3   deepri   rA   zcrj   uvs           r4   as_real_imagzAiryBase.as_real_imag  si    IaL[[]]IQqTT!!B%%ZNqquuQQqTTzN1!tr7   c                 @     | j         dd|i|\  }}||t          z  z   S )Nra  r=   )re  r   )r3   ra  ri   re_partim_parts        r4   _eval_expand_complexzAiryBase._eval_expand_complex  s3    ,4,@@$@%@@""r7   N)T)rq   rr   rs   rt   rQ   r   re  ri  r=   r7   r4   r\  r\  	  sd         3 3 3- - -   # # # # # #r7   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 )airyaia  
    The Airy function $\operatorname{Ai}$ of the first kind.

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

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

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

    Equivalently, for real $z$

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

    Examples
    ========

    Create an Airy function object:

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

    >>> airyai(z)
    airyai(z)

    Several special values are known:

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

    The Airy function obeys the mirror symmetry:

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

    Differentiation with respect to $z$ is supported:

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

    Series expansion is also supported:

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

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

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

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

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

    See Also
    ========

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

    References
    ==========

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

    r9   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   rC   )
	is_Numberr   r}   r~   rz   r   r^   ry   r   r&   r?   r   s     r4   rB   zairyai.eval  s    = 	Kae||u
""v***v Ku8Aq>> 1E(1a..4I4I IJJ; 	G5Ax1~~-hq!nn0E0EEFF	G 	Gr7   c                 b    |dk    rt          | j        d                   S t          | |          Nr9   r   )airyaiprimer1   r
   rI   s     r4   rK   zairyai.fdiff  /    q==ty|,,,$T8444r7   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   r9   r   r   rC   r   )r   rz   r   lenr   r   r   r   r   r&   ry   r   r`   previous_termsr   s       r4   taylor_termzairyai.taylor_term  s    q556M

A>""Q&&"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 7r7   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 Nr9   r   rC   r   r   r"   rh   r   rX   r3   rA   rn   otttra   s         r4   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r7   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 ry  r   r   r"   rf   r   rY   r{  s         r4   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Wr7   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   rC   r9   	   r   )r   ry   r   r&   r    r)   r3   rA   rn   pf1pf2s        r4   _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dr7   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   r9   r   )excludedmr   r   )r1   free_symbolsrt  popr   matchrV   r   r   ry   rk  r   airybir3   ri   r   symbsrA   r   r  r  r   Mpfnewargs               r4   rg   zairyai._eval_expand_func  s~   il u::??		AS1#&&&AS1#&&&AS1#&&&AS1#&&&A		!Qq!tVaK-((A}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r7   Nr9   rq   rr   rs   rt   nargs
unbranchedrv   rB   rK   staticmethodr   rw  r   r   r  rg   r=   r7   r4   rk  rk  $  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r7   rk  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] https://dlmf.nist.gov/9
    .. [3] https://encyclopediaofmath.org/wiki/Airy_functions
    .. [4] https://mathworld.wolfram.com/AiryFunctions.html

    r9   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   r9      rC   )
rm  r   r}   r~   r   rz   r^   ry   r   r&   rn  s     r4   rB   zairybi.eval.  s    = 	Kae||u
""z!***v Ku8Aq>> 1E(1a..4I4I IJJ; 	G5Ax1~~-hq!nn0E0EEFF	G 	Gr7   c                 b    |dk    rt          | j        d                   S t          | |          rp  )airybiprimer1   r
   rI   s     r4   rK   zairybi.fdiff=  rr  r7   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   r9   r   r   rC   r  )r   rz   r   rt  r   r!   r   r   r   ry   r   r   r   r    r&   ru  s       r4   rw  zairybi.taylor_termC  s    q556M

A>""Q&&"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 7r7   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 ry  rz  r{  s         r4   r   zairybi._eval_rewrite_as_besseljR  s    a^^a^^HQNN##a55 	I1::"bd!3!3gb"Q$6G6G!GHH	I 	Ir7   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 ry  r  r3   rA   rn   r|  r}  ra   r   r   s           r4   r   zairybi._eval_rewrite_as_besseliY  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Jr7   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  rC   r9   r  r   )r   ry   r    r&   r   r)   r  s        r4   r  zairybi._eval_rewrite_as_hyperd  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dr7   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  )r1   r  rt  r  r   r  rV   r   r   r   ry   rk  r  r  s               r4   rg   zairybi._eval_expand_funci  s{   il u::??		AS1#&&&AS1#&&&AS1#&&&AS1#&&&A		!Qq!tVaK-((A}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r7   Nr  r  r=   r7   r4   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r7   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 )rq  a%  
    The derivative $\operatorname{Ai}^\prime$ of the Airy function of the first
    kind.

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

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

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

    Examples
    ========

    Create an Airy function object:

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

    >>> airyaiprime(z)
    airyaiprime(z)

    Several special values are known:

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

    The Airy function obeys the mirror symmetry:

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

    Differentiation with respect to $z$ is supported:

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

    Series expansion is also supported:

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

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

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

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

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

    See Also
    ========

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

    References
    ==========

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

    r9   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   r9   )	rm  r   r}   r~   rz   r^   r   r   r&   rn  s     r4   rB   zairyaiprime.eval  sx    = 	ae||u
""v; 	O=Ax1~~$5hq!nn8M8M$MNN	O 	Or7   c                 ~    |dk    r(| j         d         t          | j         d                   z  S t          | |          rp  )r1   rk  r
   rI   s     r4   rK   zairyaiprime.fdiff  :    q==9Q<ty| 4 444$T8444r7   c                     | j         d                             |          }t          |          5  t          j        |d          }d d d            n# 1 swxY w Y   t          j        ||          S Nr   r9   )
derivative)r1   r@  r,   r+   rk  r   r?  r3   r  rA   ress       r4   r  zairyaiprime._eval_evalf      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 NrC   r   )r   r   r"   rh   rX   r3   rA   rn   r}  ra   s        r4   r   z$airyaiprime._eval_rewrite_as_besselj  sx    a^^HQNN##a55 	BQ3'2#r!t,,wr2a4/@/@@AA	B 	Br7   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 ry  )r   r   r"   rf   rY   r  s           r4   r   z$airyaiprime._eval_rewrite_as_besseli  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Ir7   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 )NrC   r   r9      r  )r   r&   r    r)   r  s        r4   r  z"airyaiprime._eval_rewrite_as_hyper  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dr7   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  )r1   r  rt  r  r   r  rV   r   r   ry   rq  r   r  r  s               r4   rg   zairyaiprime._eval_expand_func  s   il u::??		AS1#&&&AS1#&&&AS1#&&&AS1#&&&A		!Qq!tVaK-((A}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r7   Nr  rq   rr   rs   rt   r  r  rv   rB   rK   r  r   r   r  rg   r=   r7   r4   rq  rq    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r7   rq  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  a6  
    The derivative $\operatorname{Bi}^\prime$ of the Airy function of the first
    kind.

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

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

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

    Examples
    ========

    Create an Airy function object:

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

    >>> airybiprime(z)
    airybiprime(z)

    Several special values are known:

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

    The Airy function obeys the mirror symmetry:

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

    Differentiation with respect to $z$ is supported:

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

    Series expansion is also supported:

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

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

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

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

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

    See Also
    ========

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

    References
    ==========

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

    r9   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   r9   r  )	rm  r   r}   r~   r   rz   r^   r   r&   rn  s     r4   rB   zairybiprime.evalu  s    = 	Aae||u
""z!***v A(1a..(5!Q+@+@@@; 	=hq!nn$uXa^^'<'<<<	= 	=r7   c                 ~    |dk    r(| j         d         t          | j         d                   z  S t          | |          rp  )r1   r  r
   rI   s     r4   rK   zairybiprime.fdiff  r  r7   c                     | j         d                             |          }t          |          5  t          j        |d          }d d d            n# 1 swxY w Y   t          j        ||          S r  )r1   r@  r,   r+   r  r   r?  r  s       r4   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  rz  r  s        r4   r   z$airybiprime._eval_rewrite_as_besselj  sy    a^^aR!Q(((a55 	C2d1gg:"a72q>>!ABB	C 	Cr7   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 ry  r  r  s           r4   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Or7   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 )NrC   r   r  r9   r  r  )r    r&   r   r)   r  s        r4   r  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dr7   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  )r1   r  rt  r  r   r  rV   r   r   r   ry   rq  r  r  s               r4   rg   zairybiprime._eval_expand_func  s   il u::??		AS1#&&&AS1#&&&AS1#&&&AS1#&&&A		!Qq!tVaK-((A}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r7   Nr  r  r=   r7   r4   r  r    s        Q Qf EJ= = [=5 5 5 5, , ,C C C
P 
P 
Pe e e
r r r r rr7   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] https://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   rY   r^   )r?   r  ra   r   s       r4   rB   zmarcumq.eval  s   ;;AF{{qAF{{vaA//%((::;;1;;q3q!taf}-----66AEzzCAJJAqD)9)99916AAAvv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{+++++	, 	, 	, 	,r7   rC   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	          | |          )NrC   r9   r   )r1   r  r   rY   r
   )r3   rJ   r  ra   r   s        r4   rK   zmarcumq.fdiff  s    )1aq==Aq)))GAaCA,>,>>??]]TEA!H$adQTkN1,<(=(==!QqS@Q@QQQ$T8444r7   c           	      *   ddl m} |                    dt          t	          d          j                            }|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`   r9   rC   )
sympy.integrals.integralsr  getr   r   namer   rY   r   r~   )r3   r  ra   r   rn   r  r`   s          r4   _eval_rewrite_as_Integralz!marcumq._eval_rewrite_as_Integral  s    666666JJsE"7"<"<"ABBCCQU|x1sQTAqD[>!#3444wqsAaC7H7HH1aQRQ[J\]]^ 	^r7   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   rC   r9   )sympy.concrete.summationsr  r  r   r   rY   r   r~   )r3   r  ra   r   rn   r  r   s          r4   _eval_rewrite_as_Sumzmarcumq._eval_rewrite_as_Sum  s    111111JJsE#JJ''QTAqD[>A%&&acAX1Q3-G!QqSRSR\I])^)^^^r7   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 )Nr9   rC   r   c              3   >   K   | ]}t          |d z            V  dS )rC   N)rY   )rB  rY  ra   s     r4   	<genexpr>z3marcumq._eval_rewrite_as_besseli.<locals>.<genexpr>$  s1      >>Q1a4((>>>>>>r7   )r   rY   r
  sumr   r   r   )r3   r  ra   r   rn   r   s     `   r4   r   z marcumq._eval_rewrite_as_besseli  s    66AvvCAJJAqD)9)999Q>>| SQ>>>>%1++>>>>>vQTE

WQ1-=-= = AACAJJQRNRR 6S Sr7   c                 F    t          d | j        D                       rdS d S )Nc              3   $   K   | ]}|j         V  d S r<   )r^   )rB  r   s     r4   r  z(marcumq._eval_is_zero.<locals>.<genexpr>(  s$      00ss{000000r7   T)allr1   r2   s    r4   _eval_is_zerozmarcumq._eval_is_zero'  s2    00di00000 	4	 	r7   Nrp   )rq   rr   rs   rt   rv   rB   rK   r  r  r   r  r=   r7   r4   r  r    s        . .` , , [,.5 5 5 5^ ^ ^_ _ _
S S S    r7   r  N)r9  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*   rQ  r+   r,   r.   rX   r   rY   r   r   r   r   r  r  r  r\   r]   r&  rZ   r[   rZ  r\  rk  r  rq  r  r  r=   r7   r4   <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mD mD mD mD mDj mD mD mD`YD YD YD YD YDj YD YD YDxUD UD UD UD UDj UD UD UDpUD UD UD UD UDj UD UD UDp+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# # # # #x # # #6i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r7   