
    ^Mh             
          d dl Zd dlZd dlZd dlmZ d dlmZmZ d dl m	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& ddl'm(Z(m)Z)m*Z*m+Z+ dd	l,m-Z- dd
lm.Z. ddl/m0Z0 ddl1m2Z2m3Z3 d dl4m5Z5 g dZ6dZ7dddddddddd	Z8ddddddd d!d"d	Z9d# Z:d$ Z;d% Z<d& Z=d' Z>d( Z?d) Z@dpd+ZAdpd,ZBdpd-ZCd. ZDdqd/ZEdqd0ZFdqd1ZGdqd2ZHdqd3ZIdqd4ZJd5 ZKd6 ZLd7 ZMd8 ZNd9 ZOd: ZPdrd<ZQeZRd= ZSd> ZTd? ZU e5e7V                    d@dA                    dB             ZW e5e7V                    dCdA                    dsdE            ZXdF ZYdG ZZdH Z[ e5e7V                    dIdJ                    dK             Z\dL Z]dM Z^dN Z_dO Z`dP ZadQ ZbdR ZcdS ZddT ZedU ZfdV ZgdW ZhdX ZidY ZjdZ Zkd[ Zld\ Zmd] Znd*d*d^d_Zodpd`ZpdqdaZqdqdbZrdc Zsdd Ztde Zudf Zvdg ZwdtdiZxdtdjZydtdkZzd*dldmZ{dudnZ|do Z}dS )v    N)defaultdict)heapifyheappop)piasarrayfloorisscalarsqrtwheresinplace
issubdtypeextractinexactnanzerossinc   )_ufuncs)	mathieu_a	mathieu_bivjvgammargammapsihankel1hankel2yvkvpochbinom_stirling2_inexact)_lqn_lqmn_rctj_rcty)_nonneg_int_or_fail)_specfun)	_comb_int)assoc_legendre_p_alllegendre_p_all)_deprecated)<ai_zerosassoc_laguerre	bei_zeros
beip_zeros	ber_zeros	bernoulli
berp_zerosbi_zerosclpmncombdigammadiric	erf_zeroseuler	factorial
factorial2
factorialkfresnel_zerosfresnelc_zerosfresnels_zerosh1vph2vpivpjn_zerosjnjnp_zeros	jnp_zeros
jnyn_zerosjvp	kei_zeros
keip_zeroskelvin_zeros	ker_zeros
kerp_zeroskvplmbdalpmnlpnlqmnlqnmathieu_even_coefmathieu_odd_coef
obl_cv_seqpbdn_seqpbdv_seqpbvv_seqperm	polygamma
pro_cv_seq
riccati_jn
riccati_ynr   softplus	stirling2y0_zerosy1_zeros	y1p_zerosyn_zeros	ynp_zerosyvpzetaz`scipy.special.{}` is deprecated as of SciPy 1.15.0 and will be removed in SciPy 1.17.0. Please use `scipy.special.{}` instead.   !   ,   6   A   J   T   ]   e   )	r                        	               %   +   /   3   8   c           
         t          |           t          |          }} t          || | z
  z             }t          | ||z
  z             } t          | j        t                    r| j        }nt          }t          | j        |          }t          j        |          j	        dk     rd}n"t          j        |          j	        dk     rd}nd}|dk    |t          |          k    z  }t          ||t                     | dz  } t          |           }d|z
  t          |          |k     z  }t          ||           }t          ||          }	|t           z  }
t          ||t#          d	t          j        |
          |	dz
  z                       d|z
  d|z
  z  }t          ||           }t          ||          }	t          ||          }t          ||t          |	|z            |	|z  z             |S )
a#  Periodic sinc function, also called the Dirichlet function.

    The Dirichlet function is defined as::

        diric(x, n) = sin(x * n/2) / (n * sin(x / 2)),

    where `n` is a positive integer.

    Parameters
    ----------
    x : array_like
        Input data
    n : int
        Integer defining the periodicity.

    Returns
    -------
    diric : ndarray

    Examples
    --------
    >>> import numpy as np
    >>> from scipy import special
    >>> import matplotlib.pyplot as plt

    >>> x = np.linspace(-8*np.pi, 8*np.pi, num=201)
    >>> plt.figure(figsize=(8, 8));
    >>> for idx, n in enumerate([2, 3, 4, 9]):
    ...     plt.subplot(2, 2, idx+1)
    ...     plt.plot(x, special.diric(x, n))
    ...     plt.title('diric, n={}'.format(n))
    >>> plt.show()

    The following example demonstrates that `diric` gives the magnitudes
    (modulo the sign and scaling) of the Fourier coefficients of a
    rectangular pulse.

    Suppress output of values that are effectively 0:

    >>> np.set_printoptions(suppress=True)

    Create a signal `x` of length `m` with `k` ones:

    >>> m = 8
    >>> k = 3
    >>> x = np.zeros(m)
    >>> x[:k] = 1

    Use the FFT to compute the Fourier transform of `x`, and
    inspect the magnitudes of the coefficients:

    >>> np.abs(np.fft.fft(x))
    array([ 3.        ,  2.41421356,  1.        ,  0.41421356,  1.        ,
            0.41421356,  1.        ,  2.41421356])

    Now find the same values (up to sign) using `diric`. We multiply
    by `k` to account for the different scaling conventions of
    `numpy.fft.fft` and `diric`:

    >>> theta = np.linspace(0, 2*np.pi, m, endpoint=False)
    >>> k * special.diric(theta, k)
    array([ 3.        ,  2.41421356,  1.        , -0.41421356, -1.        ,
           -0.41421356,  1.        ,  2.41421356])
    gC]r2<gdy=gV瞯<gHz>gMbP?r   rr   r   )r   r   dtyper   floatr   shapenpfinfoepsr   r   r   r   absr   r   powround)xnytypeyminvalmask1denommask2xsubnsubzsubmaskdsubs                T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/scipy/special/_basic.pyr9   r9   h   s   B 1::wqzzqAQqS	AQqS	A!'7## aguA 
xU""	%	u	$	$!VU1XX&E	!UC	AAFFEuWUf,-E5!D5!D"9D	!UCBHTNNDF344555eG% D4D4D4D	!T3tDy>>49-...H    c                    t          |           rt          |           | k    s| dk    rt          d          t          |           } t	          j        |           \  }}}}|d| dz            |d|          |d|          |d|          fS )a   Compute zeros of integer-order Bessel functions Jn and Jn'.

    Results are arranged in order of the magnitudes of the zeros.

    Parameters
    ----------
    nt : int
        Number (<=1200) of zeros to compute

    Returns
    -------
    zo[l-1] : ndarray
        Value of the lth zero of Jn(x) and Jn'(x). Of length `nt`.
    n[l-1] : ndarray
        Order of the Jn(x) or Jn'(x) associated with lth zero. Of length `nt`.
    m[l-1] : ndarray
        Serial number of the zeros of Jn(x) or Jn'(x) associated
        with lth zero. Of length `nt`.
    t[l-1] : ndarray
        0 if lth zero in zo is zero of Jn(x), 1 if it is a zero of Jn'(x). Of
        length `nt`.

    See Also
    --------
    jn_zeros, jnp_zeros : to get separated arrays of zeros.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996, chapter 5.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    i  zNumber must be integer <= 1200.r   N)r	   r   
ValueErrorintr)   jdzo)ntr   mtzos        r   rF   rF      s    D B<< <E"IIOOd:;;;	RB-##KAq!Ra1f:q"vq"vq"v--r   c                 4   t          |          rt          |           st          d          t          |           | k    st          |          |k    rt          d          |dk    rt          d          t          j        t          |           |          S )a	  Compute nt zeros of Bessel functions Jn(x), Jn'(x), Yn(x), and Yn'(x).

    Returns 4 arrays of length `nt`, corresponding to the first `nt`
    zeros of Jn(x), Jn'(x), Yn(x), and Yn'(x), respectively. The zeros
    are returned in ascending order.

    Parameters
    ----------
    n : int
        Order of the Bessel functions
    nt : int
        Number (<=1200) of zeros to compute

    Returns
    -------
    Jn : ndarray
        First `nt` zeros of Jn
    Jnp : ndarray
        First `nt` zeros of Jn'
    Yn : ndarray
        First `nt` zeros of Yn
    Ynp : ndarray
        First `nt` zeros of Yn'

    See Also
    --------
    jn_zeros, jnp_zeros, yn_zeros, ynp_zeros

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996, chapter 5.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    Examples
    --------
    Compute the first three roots of :math:`J_1`, :math:`J_1'`,
    :math:`Y_1` and :math:`Y_1'`.

    >>> from scipy.special import jnyn_zeros
    >>> jn_roots, jnp_roots, yn_roots, ynp_roots = jnyn_zeros(1, 3)
    >>> jn_roots, yn_roots
    (array([ 3.83170597,  7.01558667, 10.17346814]),
     array([2.19714133, 5.42968104, 8.59600587]))

    Plot :math:`J_1`, :math:`J_1'`, :math:`Y_1`, :math:`Y_1'` and their roots.

    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from scipy.special import jnyn_zeros, jvp, jn, yvp, yn
    >>> jn_roots, jnp_roots, yn_roots, ynp_roots = jnyn_zeros(1, 3)
    >>> fig, ax = plt.subplots()
    >>> xmax= 11
    >>> x = np.linspace(0, xmax)
    >>> x[0] += 1e-15
    >>> ax.plot(x, jn(1, x), label=r"$J_1$", c='r')
    >>> ax.plot(x, jvp(1, x, 1), label=r"$J_1'$", c='b')
    >>> ax.plot(x, yn(1, x), label=r"$Y_1$", c='y')
    >>> ax.plot(x, yvp(1, x, 1), label=r"$Y_1'$", c='c')
    >>> zeros = np.zeros((3, ))
    >>> ax.scatter(jn_roots, zeros, s=30, c='r', zorder=5,
    ...            label=r"$J_1$ roots")
    >>> ax.scatter(jnp_roots, zeros, s=30, c='b', zorder=5,
    ...            label=r"$J_1'$ roots")
    >>> ax.scatter(yn_roots, zeros, s=30, c='y', zorder=5,
    ...            label=r"$Y_1$ roots")
    >>> ax.scatter(ynp_roots, zeros, s=30, c='c', zorder=5,
    ...            label=r"$Y_1'$ roots")
    >>> ax.hlines(0, 0, xmax, color='k')
    >>> ax.set_ylim(-0.6, 0.6)
    >>> ax.set_xlim(0, xmax)
    >>> ax.legend(ncol=2, bbox_to_anchor=(1., 0.75))
    >>> plt.tight_layout()
    >>> plt.show()
    Arguments must be scalars.zArguments must be integers.r   znt > 0)r	   r   r   r)   jyzor   r   r   s     r   rH   rH      s    X RLL 7Xa[[ 75666aA599??6777
a"""=Q$$$r   c                 .    t          | |          d         S )a/  Compute zeros of integer-order Bessel functions Jn.

    Compute `nt` zeros of the Bessel functions :math:`J_n(x)` on the
    interval :math:`(0, \infty)`. The zeros are returned in ascending
    order. Note that this interval excludes the zero at :math:`x = 0`
    that exists for :math:`n > 0`.

    Parameters
    ----------
    n : int
        Order of Bessel function
    nt : int
        Number of zeros to return

    Returns
    -------
    ndarray
        First `nt` zeros of the Bessel function.

    See Also
    --------
    jv: Real-order Bessel functions of the first kind
    jnp_zeros: Zeros of :math:`Jn'`

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996, chapter 5.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    Examples
    --------
    Compute the first four positive roots of :math:`J_3`.

    >>> from scipy.special import jn_zeros
    >>> jn_zeros(3, 4)
    array([ 6.3801619 ,  9.76102313, 13.01520072, 16.22346616])

    Plot :math:`J_3` and its first four positive roots. Note
    that the root located at 0 is not returned by `jn_zeros`.

    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from scipy.special import jn, jn_zeros
    >>> j3_roots = jn_zeros(3, 4)
    >>> xmax = 18
    >>> xmin = -1
    >>> x = np.linspace(xmin, xmax, 500)
    >>> fig, ax = plt.subplots()
    >>> ax.plot(x, jn(3, x), label=r'$J_3$')
    >>> ax.scatter(j3_roots, np.zeros((4, )), s=30, c='r',
    ...            label=r"$J_3$_Zeros", zorder=5)
    >>> ax.scatter(0, 0, s=30, c='k',
    ...            label=r"Root at 0", zorder=5)
    >>> ax.hlines(0, 0, xmax, color='k')
    >>> ax.set_xlim(xmin, xmax)
    >>> plt.legend()
    >>> plt.show()
    r   rH   r   s     r   rE   rE   L      x aQr   c                 .    t          | |          d         S )a  Compute zeros of integer-order Bessel function derivatives Jn'.

    Compute `nt` zeros of the functions :math:`J_n'(x)` on the
    interval :math:`(0, \infty)`. The zeros are returned in ascending
    order. Note that this interval excludes the zero at :math:`x = 0`
    that exists for :math:`n > 1`.

    Parameters
    ----------
    n : int
        Order of Bessel function
    nt : int
        Number of zeros to return

    Returns
    -------
    ndarray
        First `nt` zeros of the Bessel function.

    See Also
    --------
    jvp: Derivatives of integer-order Bessel functions of the first kind
    jv: Float-order Bessel functions of the first kind

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996, chapter 5.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    Examples
    --------
    Compute the first four roots of :math:`J_2'`.

    >>> from scipy.special import jnp_zeros
    >>> jnp_zeros(2, 4)
    array([ 3.05423693,  6.70613319,  9.96946782, 13.17037086])

    As `jnp_zeros` yields the roots of :math:`J_n'`, it can be used to
    compute the locations of the peaks of :math:`J_n`. Plot
    :math:`J_2`, :math:`J_2'` and the locations of the roots of :math:`J_2'`.

    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from scipy.special import jn, jnp_zeros, jvp
    >>> j2_roots = jnp_zeros(2, 4)
    >>> xmax = 15
    >>> x = np.linspace(0, xmax, 500)
    >>> fig, ax = plt.subplots()
    >>> ax.plot(x, jn(2, x), label=r'$J_2$')
    >>> ax.plot(x, jvp(2, x, 1), label=r"$J_2'$")
    >>> ax.hlines(0, 0, xmax, color='k')
    >>> ax.scatter(j2_roots, np.zeros((4, )), s=30, c='r',
    ...            label=r"Roots of $J_2'$", zorder=5)
    >>> ax.set_ylim(-0.4, 0.8)
    >>> ax.set_xlim(0, xmax)
    >>> plt.legend()
    >>> plt.show()
    r   r   r   s     r   rG   rG     r   r   c                 .    t          | |          d         S )a7  Compute zeros of integer-order Bessel function Yn(x).

    Compute `nt` zeros of the functions :math:`Y_n(x)` on the interval
    :math:`(0, \infty)`. The zeros are returned in ascending order.

    Parameters
    ----------
    n : int
        Order of Bessel function
    nt : int
        Number of zeros to return

    Returns
    -------
    ndarray
        First `nt` zeros of the Bessel function.

    See Also
    --------
    yn: Bessel function of the second kind for integer order
    yv: Bessel function of the second kind for real order

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996, chapter 5.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    Examples
    --------
    Compute the first four roots of :math:`Y_2`.

    >>> from scipy.special import yn_zeros
    >>> yn_zeros(2, 4)
    array([ 3.38424177,  6.79380751, 10.02347798, 13.20998671])

    Plot :math:`Y_2` and its first four roots.

    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from scipy.special import yn, yn_zeros
    >>> xmin = 2
    >>> xmax = 15
    >>> x = np.linspace(xmin, xmax, 500)
    >>> fig, ax = plt.subplots()
    >>> ax.hlines(0, xmin, xmax, color='k')
    >>> ax.plot(x, yn(2, x), label=r'$Y_2$')
    >>> ax.scatter(yn_zeros(2, 4), np.zeros((4, )), s=30, c='r',
    ...            label='Roots', zorder=5)
    >>> ax.set_ylim(-0.4, 0.4)
    >>> ax.set_xlim(xmin, xmax)
    >>> plt.legend()
    >>> plt.show()
    rr   r   r   s     r   re   re     s    n aQr   c                 .    t          | |          d         S )a  Compute zeros of integer-order Bessel function derivatives Yn'(x).

    Compute `nt` zeros of the functions :math:`Y_n'(x)` on the
    interval :math:`(0, \infty)`. The zeros are returned in ascending
    order.

    Parameters
    ----------
    n : int
        Order of Bessel function
    nt : int
        Number of zeros to return

    Returns
    -------
    ndarray
        First `nt` zeros of the Bessel derivative function.


    See Also
    --------
    yvp

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996, chapter 5.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    Examples
    --------
    Compute the first four roots of the first derivative of the
    Bessel function of second kind for order 0 :math:`Y_0'`.

    >>> from scipy.special import ynp_zeros
    >>> ynp_zeros(0, 4)
    array([ 2.19714133,  5.42968104,  8.59600587, 11.74915483])

    Plot :math:`Y_0`, :math:`Y_0'` and confirm visually that the roots of
    :math:`Y_0'` are located at local extrema of :math:`Y_0`.

    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from scipy.special import yn, ynp_zeros, yvp
    >>> zeros = ynp_zeros(0, 4)
    >>> xmax = 13
    >>> x = np.linspace(0, xmax, 500)
    >>> fig, ax = plt.subplots()
    >>> ax.plot(x, yn(0, x), label=r'$Y_0$')
    >>> ax.plot(x, yvp(0, x, 1), label=r"$Y_0'$")
    >>> ax.scatter(zeros, np.zeros((4, )), s=30, c='r',
    ...            label=r"Roots of $Y_0'$", zorder=5)
    >>> for root in zeros:
    ...     y0_extremum =  yn(0, root)
    ...     lower = min(0, y0_extremum)
    ...     upper = max(0, y0_extremum)
    ...     ax.vlines(root, lower, upper, color='r')
    >>> ax.hlines(0, 0, xmax, color='k')
    >>> ax.set_ylim(-0.6, 0.6)
    >>> ax.set_xlim(0, xmax)
    >>> plt.legend()
    >>> plt.show()
    rs   r   r   s     r   rf   rf     s    @ aQr   Fc                     t          |           rt          |           | k    s| dk    rt          d          d}| }t          j        | ||          S )a	  Compute nt zeros of Bessel function Y0(z), and derivative at each zero.

    The derivatives are given by Y0'(z0) = -Y1(z0) at each zero z0.

    Parameters
    ----------
    nt : int
        Number of zeros to return
    complex : bool, default False
        Set to False to return only the real zeros; set to True to return only
        the complex zeros with negative real part and positive imaginary part.
        Note that the complex conjugates of the latter are also zeros of the
        function, but are not returned by this routine.

    Returns
    -------
    z0n : ndarray
        Location of nth zero of Y0(z)
    y0pz0n : ndarray
        Value of derivative Y0'(z0) for nth zero

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996, chapter 5.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    Examples
    --------
    Compute the first 4 real roots and the derivatives at the roots of
    :math:`Y_0`:

    >>> import numpy as np
    >>> from scipy.special import y0_zeros
    >>> zeros, grads = y0_zeros(4)
    >>> with np.printoptions(precision=5):
    ...     print(f"Roots: {zeros}")
    ...     print(f"Gradients: {grads}")
    Roots: [ 0.89358+0.j  3.95768+0.j  7.08605+0.j 10.22235+0.j]
    Gradients: [-0.87942+0.j  0.40254+0.j -0.3001 +0.j  0.2497 +0.j]

    Plot the real part of :math:`Y_0` and the first four computed roots.

    >>> import matplotlib.pyplot as plt
    >>> from scipy.special import y0
    >>> xmin = 0
    >>> xmax = 11
    >>> x = np.linspace(xmin, xmax, 500)
    >>> fig, ax = plt.subplots()
    >>> ax.hlines(0, xmin, xmax, color='k')
    >>> ax.plot(x, y0(x), label=r'$Y_0$')
    >>> zeros, grads = y0_zeros(4)
    >>> ax.scatter(zeros.real, np.zeros((4, )), s=30, c='r',
    ...            label=r'$Y_0$_zeros', zorder=5)
    >>> ax.set_ylim(-0.5, 0.6)
    >>> ax.set_xlim(xmin, xmax)
    >>> plt.legend(ncol=2)
    >>> plt.show()

    Compute the first 4 complex roots and the derivatives at the roots of
    :math:`Y_0` by setting ``complex=True``:

    >>> y0_zeros(4, True)
    (array([ -2.40301663+0.53988231j,  -5.5198767 +0.54718001j,
             -8.6536724 +0.54841207j, -11.79151203+0.54881912j]),
     array([ 0.10074769-0.88196771j, -0.02924642+0.5871695j ,
             0.01490806-0.46945875j, -0.00937368+0.40230454j]))
    r   *Arguments must be scalar positive integer.r	   r   r   r)   cyzor   complexkfkcs       r   rb   rb   G  sY    J B<< GE"IIOOqEFFF	
BB=R$$$r   c                     t          |           rt          |           | k    s| dk    rt          d          d}| }t          j        | ||          S )a	  Compute nt zeros of Bessel function Y1(z), and derivative at each zero.

    The derivatives are given by Y1'(z1) = Y0(z1) at each zero z1.

    Parameters
    ----------
    nt : int
        Number of zeros to return
    complex : bool, default False
        Set to False to return only the real zeros; set to True to return only
        the complex zeros with negative real part and positive imaginary part.
        Note that the complex conjugates of the latter are also zeros of the
        function, but are not returned by this routine.

    Returns
    -------
    z1n : ndarray
        Location of nth zero of Y1(z)
    y1pz1n : ndarray
        Value of derivative Y1'(z1) for nth zero

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996, chapter 5.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    Examples
    --------
    Compute the first 4 real roots and the derivatives at the roots of
    :math:`Y_1`:

    >>> import numpy as np
    >>> from scipy.special import y1_zeros
    >>> zeros, grads = y1_zeros(4)
    >>> with np.printoptions(precision=5):
    ...     print(f"Roots: {zeros}")
    ...     print(f"Gradients: {grads}")
    Roots: [ 2.19714+0.j  5.42968+0.j  8.59601+0.j 11.74915+0.j]
    Gradients: [ 0.52079+0.j -0.34032+0.j  0.27146+0.j -0.23246+0.j]

    Extract the real parts:

    >>> realzeros = zeros.real
    >>> realzeros
    array([ 2.19714133,  5.42968104,  8.59600587, 11.74915483])

    Plot :math:`Y_1` and the first four computed roots.

    >>> import matplotlib.pyplot as plt
    >>> from scipy.special import y1
    >>> xmin = 0
    >>> xmax = 13
    >>> x = np.linspace(xmin, xmax, 500)
    >>> zeros, grads = y1_zeros(4)
    >>> fig, ax = plt.subplots()
    >>> ax.hlines(0, xmin, xmax, color='k')
    >>> ax.plot(x, y1(x), label=r'$Y_1$')
    >>> ax.scatter(zeros.real, np.zeros((4, )), s=30, c='r',
    ...            label=r'$Y_1$_zeros', zorder=5)
    >>> ax.set_ylim(-0.5, 0.5)
    >>> ax.set_xlim(xmin, xmax)
    >>> plt.legend()
    >>> plt.show()

    Compute the first 4 complex roots and the derivatives at the roots of
    :math:`Y_1` by setting ``complex=True``:

    >>> y1_zeros(4, True)
    (array([ -0.50274327+0.78624371j,  -3.83353519+0.56235654j,
             -7.01590368+0.55339305j, -10.17357383+0.55127339j]),
     array([-0.45952768+1.31710194j,  0.04830191-0.69251288j,
            -0.02012695+0.51864253j,  0.011614  -0.43203296j]))
    r   r   r   r   r   s       r   rc   rc     sY    V B<< GE"IIOOqEFFF	
BB=R$$$r   c                     t          |           rt          |           | k    s| dk    rt          d          d}| }t          j        | ||          S )af	  Compute nt zeros of Bessel derivative Y1'(z), and value at each zero.

    The values are given by Y1(z1) at each z1 where Y1'(z1)=0.

    Parameters
    ----------
    nt : int
        Number of zeros to return
    complex : bool, default False
        Set to False to return only the real zeros; set to True to return only
        the complex zeros with negative real part and positive imaginary part.
        Note that the complex conjugates of the latter are also zeros of the
        function, but are not returned by this routine.

    Returns
    -------
    z1pn : ndarray
        Location of nth zero of Y1'(z)
    y1z1pn : ndarray
        Value of derivative Y1(z1) for nth zero

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996, chapter 5.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    Examples
    --------
    Compute the first four roots of :math:`Y_1'` and the values of
    :math:`Y_1` at these roots.

    >>> import numpy as np
    >>> from scipy.special import y1p_zeros
    >>> y1grad_roots, y1_values = y1p_zeros(4)
    >>> with np.printoptions(precision=5):
    ...     print(f"Y1' Roots: {y1grad_roots.real}")
    ...     print(f"Y1 values: {y1_values.real}")
    Y1' Roots: [ 3.68302  6.9415  10.1234  13.28576]
    Y1 values: [ 0.41673 -0.30317  0.25091 -0.21897]

    `y1p_zeros` can be used to calculate the extremal points of :math:`Y_1`
    directly. Here we plot :math:`Y_1` and the first four extrema.

    >>> import matplotlib.pyplot as plt
    >>> from scipy.special import y1, yvp
    >>> y1_roots, y1_values_at_roots = y1p_zeros(4)
    >>> real_roots = y1_roots.real
    >>> xmax = 15
    >>> x = np.linspace(0, xmax, 500)
    >>> x[0] += 1e-15
    >>> fig, ax = plt.subplots()
    >>> ax.plot(x, y1(x), label=r'$Y_1$')
    >>> ax.plot(x, yvp(1, x, 1), label=r"$Y_1'$")
    >>> ax.scatter(real_roots, np.zeros((4, )), s=30, c='r',
    ...            label=r"Roots of $Y_1'$", zorder=5)
    >>> ax.scatter(real_roots, y1_values_at_roots.real, s=30, c='k',
    ...            label=r"Extrema of $Y_1$", zorder=5)
    >>> ax.hlines(0, 0, xmax, color='k')
    >>> ax.set_ylim(-0.5, 0.5)
    >>> ax.set_xlim(0, xmax)
    >>> ax.legend(ncol=2, bbox_to_anchor=(1., 0.75))
    >>> plt.tight_layout()
    >>> plt.show()
    r   r   rr   r   r   s       r   rd   rd     sY    D B<< GE"IIOOqEFFF	
BB=R$$$r   c                     t          |           } d} || |z
  |          }t          d|dz             D ].}||||z
  dz   z  z  |z  }|| || |z
  |dz  z   |          z  z  }/|d|z  z  S )N      ?r   rr   g       @)r   range)vzr   Lphasepsis           r   _bessel_diff_formular   .  s    
 	

AA	!A#q		A1ac]]  Q!A#a%[!A%	Qqq1qsAA;r   c                 ~    t          |d          }|dk    rt          | |          S t          | ||t          d          S )a  Compute derivatives of Bessel functions of the first kind.

    Compute the nth derivative of the Bessel function `Jv` with
    respect to `z`.

    Parameters
    ----------
    v : array_like or float
        Order of Bessel function
    z : complex
        Argument at which to evaluate the derivative; can be real or
        complex.
    n : int, default 1
        Order of derivative. For 0 returns the Bessel function `jv` itself.

    Returns
    -------
    scalar or ndarray
        Values of the derivative of the Bessel function.

    Notes
    -----
    The derivative is computed using the relation DLFM 10.6.7 [2]_.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996, chapter 5.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    .. [2] NIST Digital Library of Mathematical Functions.
           https://dlmf.nist.gov/10.6.E7

    Examples
    --------

    Compute the Bessel function of the first kind of order 0 and
    its first two derivatives at 1.

    >>> from scipy.special import jvp
    >>> jvp(0, 1, 0), jvp(0, 1, 1), jvp(0, 1, 2)
    (0.7651976865579666, -0.44005058574493355, -0.3251471008130331)

    Compute the first derivative of the Bessel function of the first
    kind for several orders at 1 by providing an array for `v`.

    >>> jvp([0, 1, 2], 1, 1)
    array([-0.44005059,  0.3251471 ,  0.21024362])

    Compute the first derivative of the Bessel function of the first
    kind of order 0 at several points by providing an array for `z`.

    >>> import numpy as np
    >>> points = np.array([0., 1.5, 3.])
    >>> jvp(0, points, 1)
    array([-0.        , -0.55793651, -0.33905896])

    Plot the Bessel function of the first kind of order 1 and its
    first three derivatives.

    >>> import matplotlib.pyplot as plt
    >>> x = np.linspace(-10, 10, 1000)
    >>> fig, ax = plt.subplots()
    >>> ax.plot(x, jvp(1, x, 0), label=r"$J_1$")
    >>> ax.plot(x, jvp(1, x, 1), label=r"$J_1'$")
    >>> ax.plot(x, jvp(1, x, 2), label=r"$J_1''$")
    >>> ax.plot(x, jvp(1, x, 3), label=r"$J_1'''$")
    >>> plt.legend()
    >>> plt.show()
    r   r   r   )r(   r   r   r   r   r   s      r   rI   rI   <  s@    N 	As##AAvv!Qxx#Aq!R444r   c                 ~    t          |d          }|dk    rt          | |          S t          | ||t          d          S )a  Compute derivatives of Bessel functions of the second kind.

    Compute the nth derivative of the Bessel function `Yv` with
    respect to `z`.

    Parameters
    ----------
    v : array_like of float
        Order of Bessel function
    z : complex
        Argument at which to evaluate the derivative
    n : int, default 1
        Order of derivative. For 0 returns the BEssel function `yv`

    Returns
    -------
    scalar or ndarray
        nth derivative of the Bessel function.

    See Also
    --------
    yv : Bessel functions of the second kind

    Notes
    -----
    The derivative is computed using the relation DLFM 10.6.7 [2]_.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996, chapter 5.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    .. [2] NIST Digital Library of Mathematical Functions.
           https://dlmf.nist.gov/10.6.E7

    Examples
    --------
    Compute the Bessel function of the second kind of order 0 and
    its first two derivatives at 1.

    >>> from scipy.special import yvp
    >>> yvp(0, 1, 0), yvp(0, 1, 1), yvp(0, 1, 2)
    (0.088256964215677, 0.7812128213002889, -0.8694697855159659)

    Compute the first derivative of the Bessel function of the second
    kind for several orders at 1 by providing an array for `v`.

    >>> yvp([0, 1, 2], 1, 1)
    array([0.78121282, 0.86946979, 2.52015239])

    Compute the first derivative of the Bessel function of the
    second kind of order 0 at several points by providing an array for `z`.

    >>> import numpy as np
    >>> points = np.array([0.5, 1.5, 3.])
    >>> yvp(0, points, 1)
    array([ 1.47147239,  0.41230863, -0.32467442])

    Plot the Bessel function of the second kind of order 1 and its
    first three derivatives.

    >>> import matplotlib.pyplot as plt
    >>> x = np.linspace(0, 5, 1000)
    >>> x[0] += 1e-15
    >>> fig, ax = plt.subplots()
    >>> ax.plot(x, yvp(1, x, 0), label=r"$Y_1$")
    >>> ax.plot(x, yvp(1, x, 1), label=r"$Y_1'$")
    >>> ax.plot(x, yvp(1, x, 2), label=r"$Y_1''$")
    >>> ax.plot(x, yvp(1, x, 3), label=r"$Y_1'''$")
    >>> ax.set_ylim(-10, 10)
    >>> plt.legend()
    >>> plt.show()
    r   r   r   )r(   r   r   r   s      r   rg   rg     s@    V 	As##AAvv!Qxx#Aq!R444r   c                     t          |d          }|dk    rt          | |          S d|z  t          | ||t          d          z  S )a  Compute derivatives of real-order modified Bessel function Kv(z)

    Kv(z) is the modified Bessel function of the second kind.
    Derivative is calculated with respect to `z`.

    Parameters
    ----------
    v : array_like of float
        Order of Bessel function
    z : array_like of complex
        Argument at which to evaluate the derivative
    n : int, default 1
        Order of derivative. For 0 returns the Bessel function `kv` itself.

    Returns
    -------
    out : ndarray
        The results

    See Also
    --------
    kv

    Notes
    -----
    The derivative is computed using the relation DLFM 10.29.5 [2]_.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996, chapter 6.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    .. [2] NIST Digital Library of Mathematical Functions.
           https://dlmf.nist.gov/10.29.E5

    Examples
    --------
    Compute the modified bessel function of the second kind of order 0 and
    its first two derivatives at 1.

    >>> from scipy.special import kvp
    >>> kvp(0, 1, 0), kvp(0, 1, 1), kvp(0, 1, 2)
    (0.42102443824070834, -0.6019072301972346, 1.0229316684379428)

    Compute the first derivative of the modified Bessel function of the second
    kind for several orders at 1 by providing an array for `v`.

    >>> kvp([0, 1, 2], 1, 1)
    array([-0.60190723, -1.02293167, -3.85158503])

    Compute the first derivative of the modified Bessel function of the
    second kind of order 0 at several points by providing an array for `z`.

    >>> import numpy as np
    >>> points = np.array([0.5, 1.5, 3.])
    >>> kvp(0, points, 1)
    array([-1.65644112, -0.2773878 , -0.04015643])

    Plot the modified bessel function of the second kind and its
    first three derivatives.

    >>> import matplotlib.pyplot as plt
    >>> x = np.linspace(0, 5, 1000)
    >>> fig, ax = plt.subplots()
    >>> ax.plot(x, kvp(1, x, 0), label=r"$K_1$")
    >>> ax.plot(x, kvp(1, x, 1), label=r"$K_1'$")
    >>> ax.plot(x, kvp(1, x, 2), label=r"$K_1''$")
    >>> ax.plot(x, kvp(1, x, 3), label=r"$K_1'''$")
    >>> ax.set_ylim(-2.5, 2.5)
    >>> plt.legend()
    >>> plt.show()
    r   r   r   r   )r(   r    r   r   s      r   rO   rO     sJ    T 	As##AAvv!QxxQw-aAr1====r   c                 ~    t          |d          }|dk    rt          | |          S t          | ||t          d          S )a	  Compute derivatives of modified Bessel functions of the first kind.

    Compute the nth derivative of the modified Bessel function `Iv`
    with respect to `z`.

    Parameters
    ----------
    v : array_like or float
        Order of Bessel function
    z : array_like
        Argument at which to evaluate the derivative; can be real or
        complex.
    n : int, default 1
        Order of derivative. For 0, returns the Bessel function `iv` itself.

    Returns
    -------
    scalar or ndarray
        nth derivative of the modified Bessel function.

    See Also
    --------
    iv

    Notes
    -----
    The derivative is computed using the relation DLFM 10.29.5 [2]_.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996, chapter 6.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    .. [2] NIST Digital Library of Mathematical Functions.
           https://dlmf.nist.gov/10.29.E5

    Examples
    --------
    Compute the modified Bessel function of the first kind of order 0 and
    its first two derivatives at 1.

    >>> from scipy.special import ivp
    >>> ivp(0, 1, 0), ivp(0, 1, 1), ivp(0, 1, 2)
    (1.2660658777520084, 0.565159103992485, 0.7009067737595233)

    Compute the first derivative of the modified Bessel function of the first
    kind for several orders at 1 by providing an array for `v`.

    >>> ivp([0, 1, 2], 1, 1)
    array([0.5651591 , 0.70090677, 0.29366376])

    Compute the first derivative of the modified Bessel function of the
    first kind of order 0 at several points by providing an array for `z`.

    >>> import numpy as np
    >>> points = np.array([0., 1.5, 3.])
    >>> ivp(0, points, 1)
    array([0.        , 0.98166643, 3.95337022])

    Plot the modified Bessel function of the first kind of order 1 and its
    first three derivatives.

    >>> import matplotlib.pyplot as plt
    >>> x = np.linspace(-5, 5, 1000)
    >>> fig, ax = plt.subplots()
    >>> ax.plot(x, ivp(1, x, 0), label=r"$I_1$")
    >>> ax.plot(x, ivp(1, x, 1), label=r"$I_1'$")
    >>> ax.plot(x, ivp(1, x, 2), label=r"$I_1''$")
    >>> ax.plot(x, ivp(1, x, 3), label=r"$I_1'''$")
    >>> plt.legend()
    >>> plt.show()
    r   r   r   )r(   r   r   r   s      r   rD   rD   -  s@    T 	As##AAvv!Qxx#Aq!R333r   c                 ~    t          |d          }|dk    rt          | |          S t          | ||t          d          S )au  Compute derivatives of Hankel function H1v(z) with respect to `z`.

    Parameters
    ----------
    v : array_like
        Order of Hankel function
    z : array_like
        Argument at which to evaluate the derivative. Can be real or
        complex.
    n : int, default 1
        Order of derivative. For 0 returns the Hankel function `h1v` itself.

    Returns
    -------
    scalar or ndarray
        Values of the derivative of the Hankel function.

    See Also
    --------
    hankel1

    Notes
    -----
    The derivative is computed using the relation DLFM 10.6.7 [2]_.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996, chapter 5.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    .. [2] NIST Digital Library of Mathematical Functions.
           https://dlmf.nist.gov/10.6.E7

    Examples
    --------
    Compute the Hankel function of the first kind of order 0 and
    its first two derivatives at 1.

    >>> from scipy.special import h1vp
    >>> h1vp(0, 1, 0), h1vp(0, 1, 1), h1vp(0, 1, 2)
    ((0.7651976865579664+0.088256964215677j),
     (-0.44005058574493355+0.7812128213002889j),
     (-0.3251471008130329-0.8694697855159659j))

    Compute the first derivative of the Hankel function of the first kind
    for several orders at 1 by providing an array for `v`.

    >>> h1vp([0, 1, 2], 1, 1)
    array([-0.44005059+0.78121282j,  0.3251471 +0.86946979j,
           0.21024362+2.52015239j])

    Compute the first derivative of the Hankel function of the first kind
    of order 0 at several points by providing an array for `z`.

    >>> import numpy as np
    >>> points = np.array([0.5, 1.5, 3.])
    >>> h1vp(0, points, 1)
    array([-0.24226846+1.47147239j, -0.55793651+0.41230863j,
           -0.33905896-0.32467442j])
    r   r   r   )r(   r   r   r   s      r   rB   rB   ~  A    | 	As##AAvvq!}}#Aq!Wb999r   c                 ~    t          |d          }|dk    rt          | |          S t          | ||t          d          S )ax  Compute derivatives of Hankel function H2v(z) with respect to `z`.

    Parameters
    ----------
    v : array_like
        Order of Hankel function
    z : array_like
        Argument at which to evaluate the derivative. Can be real or
        complex.
    n : int, default 1
        Order of derivative. For 0 returns the Hankel function `h2v` itself.

    Returns
    -------
    scalar or ndarray
        Values of the derivative of the Hankel function.

    See Also
    --------
    hankel2

    Notes
    -----
    The derivative is computed using the relation DLFM 10.6.7 [2]_.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996, chapter 5.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    .. [2] NIST Digital Library of Mathematical Functions.
           https://dlmf.nist.gov/10.6.E7

    Examples
    --------
    Compute the Hankel function of the second kind of order 0 and
    its first two derivatives at 1.

    >>> from scipy.special import h2vp
    >>> h2vp(0, 1, 0), h2vp(0, 1, 1), h2vp(0, 1, 2)
    ((0.7651976865579664-0.088256964215677j),
     (-0.44005058574493355-0.7812128213002889j),
     (-0.3251471008130329+0.8694697855159659j))

    Compute the first derivative of the Hankel function of the second kind
    for several orders at 1 by providing an array for `v`.

    >>> h2vp([0, 1, 2], 1, 1)
    array([-0.44005059-0.78121282j,  0.3251471 -0.86946979j,
           0.21024362-2.52015239j])

    Compute the first derivative of the Hankel function of the second kind
    of order 0 at several points by providing an array for `z`.

    >>> import numpy as np
    >>> points = np.array([0.5, 1.5, 3.])
    >>> h2vp(0, points, 1)
    array([-0.24226846-1.47147239j, -0.55793651-0.41230863j,
           -0.33905896+0.32467442j])
    r   r   r   )r(   r   r   r   s      r   rC   rC     r   r   c                 `   t          |           rt          |          st          d          t          | dd          } | dk    rd}n| }t          j        |dz   ft          j                  }t          j        |          }t          |||f           |d	| dz            |d	| dz            fS )
a  Compute Ricatti-Bessel function of the first kind and its derivative.

    The Ricatti-Bessel function of the first kind is defined as :math:`x
    j_n(x)`, where :math:`j_n` is the spherical Bessel function of the first
    kind of order :math:`n`.

    This function computes the value and first derivative of the
    Ricatti-Bessel function for all orders up to and including `n`.

    Parameters
    ----------
    n : int
        Maximum order of function to compute
    x : float
        Argument at which to evaluate

    Returns
    -------
    jn : ndarray
        Value of j0(x), ..., jn(x)
    jnp : ndarray
        First derivative j0'(x), ..., jn'(x)

    Notes
    -----
    The computation is carried out via backward recurrence, using the
    relation DLMF 10.51.1 [2]_.

    Wrapper for a Fortran routine created by Shanjie Zhang and Jianming
    Jin [1]_.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
    .. [2] NIST Digital Library of Mathematical Functions.
           https://dlmf.nist.gov/10.51.E1

    arguments must be scalars.r   Fstrictr   r   r   outN)r	   r   r(   r   emptyfloat64
empty_liker&   )r   r   n1jnjnps        r   r^   r^     s    R QKK 7HQKK 75666As5111A	Q	26)2:	.	.	.B
-

C	!"cf!f:s6QqS6{""r   c                 `   t          |           rt          |          st          d          t          | dd          } | dk    rd}n| }t          j        |dz   ft          j                  }t          j        |          }t          |||f           |d	| dz            |d	| dz            fS )
a/  Compute Ricatti-Bessel function of the second kind and its derivative.

    The Ricatti-Bessel function of the second kind is defined here as :math:`+x
    y_n(x)`, where :math:`y_n` is the spherical Bessel function of the second
    kind of order :math:`n`. *Note that this is in contrast to a common convention
    that includes a minus sign in the definition.*

    This function computes the value and first derivative of the function for
    all orders up to and including `n`.

    Parameters
    ----------
    n : int
        Maximum order of function to compute
    x : float
        Argument at which to evaluate

    Returns
    -------
    yn : ndarray
        Value of y0(x), ..., yn(x)
    ynp : ndarray
        First derivative y0'(x), ..., yn'(x)

    Notes
    -----
    The computation is carried out via ascending recurrence, using the
    relation DLMF 10.51.1 [2]_.

    Wrapper for a Fortran routine created by Shanjie Zhang and Jianming
    Jin [1]_.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
    .. [2] NIST Digital Library of Mathematical Functions.
           https://dlmf.nist.gov/10.51.E1

    r   r   Fr   r   r   r   r   N)r	   r   r(   r   r   r   r   r'   )r   r   r   ynynps        r   r_   r_   @  s    T QKK 7HQKK 75666As5111A	Q	26)2:	.	.	.B
-

C	!"cf!f:s6QqS6{""r   c                     t          |           | k    s| dk    st          |           st          d          t          j        |           S )a  Compute the first nt zero in the first quadrant, ordered by absolute value.

    Zeros in the other quadrants can be obtained by using the symmetries
    erf(-z) = erf(z) and erf(conj(z)) = conj(erf(z)).


    Parameters
    ----------
    nt : int
        The number of zeros to compute

    Returns
    -------
    The locations of the zeros of erf : ndarray (complex)
        Complex values at which zeros of erf(z)

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    Examples
    --------
    >>> from scipy import special
    >>> special.erf_zeros(1)
    array([1.45061616+1.880943j])

    Check that erf is (close to) zero for the value returned by erf_zeros

    >>> special.erf(special.erf_zeros(1))
    array([4.95159469e-14-1.16407394e-16j])

    r   )Argument must be positive scalar integer.)r   r	   r   r)   cerzor   s    r   r:   r:   y  sE    F 	b		RR1WWXb\\WDEEE>"r   c                     t          |           | k    s| dk    st          |           st          d          t          j        d|           S )a  Compute nt complex zeros of cosine Fresnel integral C(z).

    Parameters
    ----------
    nt : int
        Number of zeros to compute

    Returns
    -------
    fresnelc_zeros: ndarray
        Zeros of the cosine Fresnel integral

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    r   r   r   r   r	   r   r)   fcszor   s    r   r@   r@     F    ( 	b		RR1WWXb\\WDEEE>!R   r   c                     t          |           | k    s| dk    st          |           st          d          t          j        d|           S )a  Compute nt complex zeros of sine Fresnel integral S(z).

    Parameters
    ----------
    nt : int
        Number of zeros to compute

    Returns
    -------
    fresnels_zeros: ndarray
        Zeros of the sine Fresnel integral

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    r   r   rr   r   r   s    r   rA   rA     r   r   c                     t          |           | k    s| dk    st          |           st          d          t          j        d|           t          j        d|           fS )a<  Compute nt complex zeros of sine and cosine Fresnel integrals S(z) and C(z).

    Parameters
    ----------
    nt : int
        Number of zeros to compute

    Returns
    -------
    zeros_sine: ndarray
        Zeros of the sine Fresnel integral
    zeros_cosine : ndarray
        Zeros of the cosine Fresnel integral

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    r   r   rr   r   r   r   s    r   r?   r?     sW    , 	b		RR1WWXb\\WDEEE>!R  (.B"7"777r           c                 .    t          j        |||           S )a  Compute the generalized (associated) Laguerre polynomial of degree n and order k.

    The polynomial :math:`L^{(k)}_n(x)` is orthogonal over ``[0, inf)``,
    with weighting function ``exp(-x) * x**k`` with ``k > -1``.

    Parameters
    ----------
    x : float or ndarray
        Points where to evaluate the Laguerre polynomial
    n : int
        Degree of the Laguerre polynomial
    k : int
        Order of the Laguerre polynomial

    Returns
    -------
    assoc_laguerre: float or ndarray
        Associated laguerre polynomial values

    Notes
    -----
    `assoc_laguerre` is a simple wrapper around `eval_genlaguerre`, with
    reversed argument order ``(x, n, k=0.0) --> (n, k, x)``.

    )r   eval_genlaguerre)r   r   ks      r   r/   r/     s    4 #Aq!,,,r   c                     t          |           t          |          }} d| dz   z  t          | dz             z  t          | dz   |          z  }t          | dk    t	          |          |          S )a.  Polygamma functions.

    Defined as :math:`\psi^{(n)}(x)` where :math:`\psi` is the
    `digamma` function. See [dlmf]_ for details.

    Parameters
    ----------
    n : array_like
        The order of the derivative of the digamma function; must be
        integral
    x : array_like
        Real valued input

    Returns
    -------
    ndarray
        Function results

    See Also
    --------
    digamma

    References
    ----------
    .. [dlmf] NIST, Digital Library of Mathematical Functions,
        https://dlmf.nist.gov/5.15

    Examples
    --------
    >>> from scipy import special
    >>> x = [2, 3, 25.5]
    >>> special.polygamma(1, x)
    array([ 0.64493407,  0.39493407,  0.03999467])
    >>> special.polygamma(0, x) == special.psi(x)
    array([ True,  True,  True], dtype=bool)

    g      r   r   r   )r   r   rh   r   r   )r   r   fac2s      r   r\   r\     sc    L 1::wqzzqAAaC=53<<'$qsA,,6DaQ&&&r   c                    t          |           rt          |          st          d          |dk     rt          d          | t          |           k    s| dk     rt          d          |dk    r2ddt          |          z  z   d|z  z
  d	t          |          z  |z  z   }n1d
dt          |          z  z   d|z  z
  dt          |          z  |z  z   }t	          |d| z  z             }|dk    rt          j        dt          d           d}t	          t          |                     } | dz  rd}t          | |          }t          j
        || ||          }|d|         S )a  Fourier coefficients for even Mathieu and modified Mathieu functions.

    The Fourier series of the even solutions of the Mathieu differential
    equation are of the form

    .. math:: \mathrm{ce}_{2n}(z, q) = \sum_{k=0}^{\infty} A_{(2n)}^{(2k)} \cos 2kz

    .. math:: \mathrm{ce}_{2n+1}(z, q) =
              \sum_{k=0}^{\infty} A_{(2n+1)}^{(2k+1)} \cos (2k+1)z

    This function returns the coefficients :math:`A_{(2n)}^{(2k)}` for even
    input m=2n, and the coefficients :math:`A_{(2n+1)}^{(2k+1)}` for odd input
    m=2n+1.

    Parameters
    ----------
    m : int
        Order of Mathieu functions.  Must be non-negative.
    q : float (>=0)
        Parameter of Mathieu functions.  Must be non-negative.

    Returns
    -------
    Ak : ndarray
        Even or odd Fourier coefficients, corresponding to even or odd m.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
    .. [2] NIST Digital Library of Mathematical Functions
           https://dlmf.nist.gov/28.4#i

    m and q must be scalars.r   q >=0zm must be an integer >=0.r         @L@fffff`@̬V@      1@@T㥛 ?笭_vOn?      ?    Too many predicted coefficients.rr   
stacklevelN)r	   r   r   r
   r   warningswarnRuntimeWarningr   r)   fcoef)r   qqmkmkdafcs          r   rU   rU   9  sb   H QKK 5HQKK 53444	A!!!	U1XX1q554555	Q4Q<%')DaLN:CQK$q&(5a=?:	R#a%ZB	Cxx8.UVWWWW	
BE!HHA1u !QA	Aq!	$	$Bcrc7Nr   c                    t          |           rt          |          st          d          |dk     rt          d          | t          |           k    s| dk    rt          d          |dk    r2ddt          |          z  z   d|z  z
  d	t          |          z  |z  z   }n1d
dt          |          z  z   d|z  z
  dt          |          z  |z  z   }t	          |d| z  z             }|dk    rt          j        dt          d           d}t	          t          |                     } | dz  rd}t          | |          }t          j
        || ||          }|d|         S )a]  Fourier coefficients for even Mathieu and modified Mathieu functions.

    The Fourier series of the odd solutions of the Mathieu differential
    equation are of the form

    .. math:: \mathrm{se}_{2n+1}(z, q) =
              \sum_{k=0}^{\infty} B_{(2n+1)}^{(2k+1)} \sin (2k+1)z

    .. math:: \mathrm{se}_{2n+2}(z, q) =
              \sum_{k=0}^{\infty} B_{(2n+2)}^{(2k+2)} \sin (2k+2)z

    This function returns the coefficients :math:`B_{(2n+2)}^{(2k+2)}` for even
    input m=2n+2, and the coefficients :math:`B_{(2n+1)}^{(2k+1)}` for odd
    input m=2n+1.

    Parameters
    ----------
    m : int
        Order of Mathieu functions.  Must be non-negative.
    q : float (>=0)
        Parameter of Mathieu functions.  Must be non-negative.

    Returns
    -------
    Bk : ndarray
        Even or odd Fourier coefficients, corresponding to even or odd m.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    r   r   r   zm must be an integer > 0r   r   r   r   r   r   r   r   r   r   r   r   rr   r   rt   rs   N)r	   r   r   r
   r   r   r   r   r   r)   r   )r   r   r  r  r  br  s          r   rV   rV   u  sb   F QKK 5HQKK 53444	A!!!	U1XX1663444	Q4Q<%')DaLN:CQK$q&(5a=?:	R#a%ZB	Cxx8.UVWWWW	
BE!HHA1u !QA	Aq!	$	$Bcrc7Nr   rQ   r+   c                    t          |dd          }t          |           |k    rt          d          t          j        |          rt          d          t          |           t          |          }} t          j        t          j        |          dk    dd          }t          |t          |           ||d	          \  }}t          j        |d
d          }t          j        |d
d          }| d
k    r|d| dz            }|d| dz            }nTt          j	        |d| dz
  d         d
|d
         d
          }t          j	        |d| dz
  d         d
|d
         d
          }||fS )a  Sequence of associated Legendre functions of the first kind.

    Computes the associated Legendre function of the first kind of order m and
    degree n, ``Pmn(z)`` = :math:`P_n^m(z)`, and its derivative, ``Pmn'(z)``.
    Returns two arrays of size ``(m+1, n+1)`` containing ``Pmn(z)`` and
    ``Pmn'(z)`` for all orders from ``0..m`` and degrees from ``0..n``.

    This function takes a real argument ``z``. For complex arguments ``z``
    use clpmn instead.

    .. deprecated:: 1.15.0
        This function is deprecated and will be removed in SciPy 1.17.0.
        Please `scipy.special.assoc_legendre_p_all` instead.

    Parameters
    ----------
    m : int
       ``|m| <= n``; the order of the Legendre function.
    n : int
       where ``n >= 0``; the degree of the Legendre function.  Often
       called ``l`` (lower case L) in descriptions of the associated
       Legendre function
    z : array_like
        Input value.

    Returns
    -------
    Pmn_z : (m+1, n+1) array
       Values for all orders 0..m and degrees 0..n
    Pmn_d_z : (m+1, n+1) array
       Derivatives for all orders 0..m and degrees 0..n

    See Also
    --------
    clpmn: associated Legendre functions of the first kind for complex z

    Notes
    -----
    In the interval (-1, 1), Ferrer's function of the first kind is
    returned. The phase convention used for the intervals (1, inf)
    and (-inf, -1) is such that the result is always real.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
    .. [2] NIST Digital Library of Mathematical Functions
           https://dlmf.nist.gov/14.3

    r   Fr   m must be <= n.z)Argument must be real. Use clpmn instead.r   rr   rs   
branch_cutdiff_nr   Nr   axis)
r(   r   r   r   iscomplexobjr   r   r+   swapaxesinsert)r   r   r   r  r   pds         r   rQ   rQ     s_   l 	As5111AA

*+++	q FDEEEq663q66qA"&))q.!Q//J CFFA*QOOOEAr
Aq!A	RA		B	QhAhK!a%\Ia!a%na1A666Yr+AE2+2a5q999b5Lr   r6   rs   c                    t          |           |k    rt          d          |dk    s|dk    st          d          t          |           t          |          }} t          j        |          st          j        |t                    }t          |t          |           ||d          \  }}t          j        |dd          }t          j        |dd          }| dk    r|d	| dz            }|d	| dz            }nTt          j	        |d	| dz
  d
         d|d         d          }t          j	        |d	| dz
  d
         d|d         d          }||fS )a  Associated Legendre function of the first kind for complex arguments.

    Computes the associated Legendre function of the first kind of order m and
    degree n, ``Pmn(z)`` = :math:`P_n^m(z)`, and its derivative, ``Pmn'(z)``.
    Returns two arrays of size ``(m+1, n+1)`` containing ``Pmn(z)`` and
    ``Pmn'(z)`` for all orders from ``0..m`` and degrees from ``0..n``.

    .. deprecated:: 1.15.0
        This function is deprecated and will be removed in SciPy 1.17.0.
        Please use `scipy.special.assoc_legendre_p_all` instead.

    Parameters
    ----------
    m : int
       ``|m| <= n``; the order of the Legendre function.
    n : int
       where ``n >= 0``; the degree of the Legendre function.  Often
       called ``l`` (lower case L) in descriptions of the associated
       Legendre function
    z : array_like, float or complex
        Input value.
    type : int, optional
       takes values 2 or 3
       2: cut on the real axis ``|x| > 1``
       3: cut on the real axis ``-1 < x < 1`` (default)

    Returns
    -------
    Pmn_z : (m+1, n+1) array
       Values for all orders ``0..m`` and degrees ``0..n``
    Pmn_d_z : (m+1, n+1) array
       Derivatives for all orders ``0..m`` and degrees ``0..n``

    See Also
    --------
    lpmn: associated Legendre functions of the first kind for real z

    Notes
    -----
    By default, i.e. for ``type=3``, phase conventions are chosen according
    to [1]_ such that the function is analytic. The cut lies on the interval
    (-1, 1). Approaching the cut from above or below in general yields a phase
    factor with respect to Ferrer's function of the first kind
    (cf. `lpmn`).

    For ``type=2`` a cut at ``|x| > 1`` is chosen. Approaching the real values
    on the interval (-1, 1) in the complex plane yields Ferrer's function
    of the first kind.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
    .. [2] NIST Digital Library of Mathematical Functions
           https://dlmf.nist.gov/14.21

    r	  rr   rs   ztype must be either 2 or 3.r   r   r
  r   Nr   r  )
r   r   r   r   r  r   r   r+   r  r  )r   r   r   typer   out_jacs         r   r6   r6      sT   z 	A

*+++AII6777q663q66qA?1 )Jq((('3q661aPPPLC
+c1a
 
 Ck'1a((G	Q(AE(m(AE(#iKa!eRK(!SV!<<<)GKa!eRK0!WQZaHHH<r   c           	         t          |           r| dk     rt          d          t          |          r|dk     rt          d          t          |           t          |          }} t          d|           }t          d|          }t	          j        |          }t	          j        |j        t          j                  s|	                    t          j
                  }t	          j        |          r1t	          j        |dz   |dz   f|j        z   t          j                  }n0t	          j        |dz   |dz   f|j        z   t          j
                  }t	          j        |          }|j        dk    rt#          |||f           n;t#          |t	          j        |dd          t	          j        |dd          f           |d	| dz   d	|dz   f         |d	| dz   d	|dz   f         fS )
am  Sequence of associated Legendre functions of the second kind.

    Computes the associated Legendre function of the second kind of order m and
    degree n, ``Qmn(z)`` = :math:`Q_n^m(z)`, and its derivative, ``Qmn'(z)``.
    Returns two arrays of size ``(m+1, n+1)`` containing ``Qmn(z)`` and
    ``Qmn'(z)`` for all orders from ``0..m`` and degrees from ``0..n``.

    Parameters
    ----------
    m : int
       ``|m| <= n``; the order of the Legendre function.
    n : int
       where ``n >= 0``; the degree of the Legendre function.  Often
       called ``l`` (lower case L) in descriptions of the associated
       Legendre function
    z : array_like, complex
        Input value.

    Returns
    -------
    Qmn_z : (m+1, n+1) array
       Values for all orders 0..m and degrees 0..n
    Qmn_d_z : (m+1, n+1) array
       Derivatives for all orders 0..m and degrees 0..n

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    r   z!m must be a non-negative integer.!n must be a non-negative integer.r   r   r   )r   r   )r   N)r	   r   r   maxr   r   r   r   r   astyper   r  r   r   
complex128r   ndimr%   moveaxis)r   r   r   mmnnr   qds          r   rS   rS   V  s   B A;; >1q55<===A;; >1q55<===q663q66qA	QB	QB

1AM!'2:.. !HHRZ  	q CHb1fb1f%/r}EEEHb1fb1f%/rzBBB	q		B	!aaW 	a;q&(33;r68446	7 	7 	7 	7 VqsVVqsV^b1Q31Q3000r   c                     t          |           r| dk     rt          d          t          |           } | dk     rd}n| }t          j        t          |                    d| dz            S )aD  Bernoulli numbers B0..Bn (inclusive).

    Parameters
    ----------
    n : int
        Indicated the number of terms in the Bernoulli series to generate.

    Returns
    -------
    ndarray
        The Bernoulli numbers ``[B(0), B(1), ..., B(n)]``.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
    .. [2] "Bernoulli number", Wikipedia, https://en.wikipedia.org/wiki/Bernoulli_number

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.special import bernoulli, zeta
    >>> bernoulli(4)
    array([ 1.        , -0.5       ,  0.16666667,  0.        , -0.03333333])

    The Wikipedia article ([2]_) points out the relationship between the
    Bernoulli numbers and the zeta function, ``B_n^+ = -n * zeta(1 - n)``
    for ``n > 0``:

    >>> n = np.arange(1, 5)
    >>> -n * zeta(1 - n)
    array([ 0.5       ,  0.16666667, -0.        , -0.03333333])

    Note that, in the notation used in the wikipedia article,
    `bernoulli` computes ``B_n^-`` (i.e. it used the convention that
    ``B_1`` is -1/2).  The relation given above is for ``B_n^+``, so the
    sign of 0.5 does not match the output of ``bernoulli(4)``.

    r   r  rr   Nr   )r	   r   r   r)   bernobr   r   s     r   r3   r3     sm    R A;; >1q55<===AA	A?3r77##FacF++r   c                     t          |           r| dk     rt          d          t          |           } | dk     rd}n| }t          j        |          d| dz            S )a  Euler numbers E(0), E(1), ..., E(n).

    The Euler numbers [1]_ are also known as the secant numbers.

    Because ``euler(n)`` returns floating point values, it does not give
    exact values for large `n`.  The first inexact value is E(22).

    Parameters
    ----------
    n : int
        The highest index of the Euler number to be returned.

    Returns
    -------
    ndarray
        The Euler numbers [E(0), E(1), ..., E(n)].
        The odd Euler numbers, which are all zero, are included.

    References
    ----------
    .. [1] Sequence A122045, The On-Line Encyclopedia of Integer Sequences,
           https://oeis.org/A122045
    .. [2] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.special import euler
    >>> euler(6)
    array([  1.,   0.,  -1.,   0.,   5.,   0., -61.])

    >>> euler(13).astype(np.int64)
    array([      1,       0,      -1,       0,       5,       0,     -61,
                 0,    1385,       0,  -50521,       0, 2702765,       0])

    >>> euler(22)[-1]  # Exact value of E(22) is -69348874393137901.
    -69348874393137976.0

    r   r  rr   Nr   )r	   r   r   r)   eulerbr#  s     r   r;   r;     sg    T A;; >1q55<===AA	A?2v1v&&r   rR   r,   c                 &    t          | |d          S )a  Legendre function of the first kind.

    Compute sequence of Legendre functions of the first kind (polynomials),
    Pn(z) and derivatives for all degrees from 0 to n (inclusive).

    See also special.legendre for polynomial class.

    .. deprecated:: 1.15.0
        This function is deprecated and will be removed in SciPy 1.17.0.
        Please use `scipy.special.legendre_p_all` instead.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
    r   )r  )r,   )r   r   s     r   rR   rR     s    ( !Qq))))r   c           	         t          | dd          } | dk     rd}n| }t          j        |          }t          j        |j        t          j                  s|                    t                    }t          j        |          r-t          j	        |dz   f|j
        z   t          j                  }n,t          j	        |dz   f|j
        z   t          j                  }t          j        |          }|j        dk    rt          |||f           n;t          |t          j        |dd          t          j        |dd          f           |d	| dz            |d	| dz            fS )
a  Legendre function of the second kind.

    Compute sequence of Legendre functions of the second kind, Qn(z) and
    derivatives for all degrees from 0 to n (inclusive).

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    r   Fr   r   r   r   r   r   N)r(   r   r   r   r   r   r  r   r  r   r   r  r   r   r  r$   r  )r   r   r   qnr   s        r   rT   rT     sV    	As5111A	A

1AM!'2:.. HHUOO	q =XrAvi!')???XrAvi!')<<<	r		B	!QRH 	Q+b!R((+b!R((*	+ 	+ 	+ 	+ f!f:r&AaC&z!!r   c                     d}t          |           rt          |           | k    s| dk    rt          d          t          j        | |          S )a  
    Compute `nt` zeros and values of the Airy function Ai and its derivative.

    Computes the first `nt` zeros, `a`, of the Airy function Ai(x);
    first `nt` zeros, `ap`, of the derivative of the Airy function Ai'(x);
    the corresponding values Ai(a');
    and the corresponding values Ai'(a).

    Parameters
    ----------
    nt : int
        Number of zeros to compute

    Returns
    -------
    a : ndarray
        First `nt` zeros of Ai(x)
    ap : ndarray
        First `nt` zeros of Ai'(x)
    ai : ndarray
        Values of Ai(x) evaluated at first `nt` zeros of Ai'(x)
    aip : ndarray
        Values of Ai'(x) evaluated at first `nt` zeros of Ai(x)

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    Examples
    --------
    >>> from scipy import special
    >>> a, ap, ai, aip = special.ai_zeros(3)
    >>> a
    array([-2.33810741, -4.08794944, -5.52055983])
    >>> ap
    array([-1.01879297, -3.24819758, -4.82009921])
    >>> ai
    array([ 0.53565666, -0.41901548,  0.38040647])
    >>> aip
    array([ 0.70121082, -0.80311137,  0.86520403])

    r   r   %nt must be a positive integer scalar.r	   r   r   r)   airyzor   r   s     r   r.   r.   :  P    Z 
BB<< BE"IIOOq@AAA?2r"""r   c                     d}t          |           rt          |           | k    s| dk    rt          d          t          j        | |          S )a  
    Compute `nt` zeros and values of the Airy function Bi and its derivative.

    Computes the first `nt` zeros, b, of the Airy function Bi(x);
    first `nt` zeros, b', of the derivative of the Airy function Bi'(x);
    the corresponding values Bi(b');
    and the corresponding values Bi'(b).

    Parameters
    ----------
    nt : int
        Number of zeros to compute

    Returns
    -------
    b : ndarray
        First `nt` zeros of Bi(x)
    bp : ndarray
        First `nt` zeros of Bi'(x)
    bi : ndarray
        Values of Bi(x) evaluated at first `nt` zeros of Bi'(x)
    bip : ndarray
        Values of Bi'(x) evaluated at first `nt` zeros of Bi(x)

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    Examples
    --------
    >>> from scipy import special
    >>> b, bp, bi, bip = special.bi_zeros(3)
    >>> b
    array([-1.17371322, -3.2710933 , -4.83073784])
    >>> bp
    array([-2.29443968, -4.07315509, -5.51239573])
    >>> bi
    array([-0.45494438,  0.39652284, -0.36796916])
    >>> bip
    array([ 0.60195789, -0.76031014,  0.83699101])

    rr   r   r*  r+  r-  s     r   r5   r5   m  r.  r   c                    t          |           rt          |          st          d          | dk     rt          d          t          |           }| |z
  }|dk     rd}n|}||z   }| t          |           k    rt	          j        ||          \  }}}nt	          j        ||          \  }}}|d|dz            |d|dz            fS )a  Jahnke-Emden Lambda function, Lambdav(x).

    This function is defined as [2]_,

    .. math:: \Lambda_v(x) = \Gamma(v+1) \frac{J_v(x)}{(x/2)^v},

    where :math:`\Gamma` is the gamma function and :math:`J_v` is the
    Bessel function of the first kind.

    Parameters
    ----------
    v : float
        Order of the Lambda function
    x : float
        Value at which to evaluate the function and derivatives

    Returns
    -------
    vl : ndarray
        Values of Lambda_vi(x), for vi=v-int(v), vi=1+v-int(v), ..., vi=v.
    dl : ndarray
        Derivatives Lambda_vi'(x), for vi=v-int(v), vi=1+v-int(v), ..., vi=v.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
    .. [2] Jahnke, E. and Emde, F. "Tables of Functions with Formulae and
           Curves" (4th ed.), Dover, 1945
    r   r   zargument must be > 0.r   N)r	   r   r   r   r)   lamvlamn)	r   r   r   v0r   v1vmvldls	            r   rP   rP     s    @ QKK 7HQKK 75666	A0111AA	
QB	A	bB	U1XX]2q))
B]2q))
Bf!f:r&AaC&z!!r   c                    t          |           rt          |          st          d          t          |           }| |z
  }|dk     rd}n|}||z   }t          j        ||          \  }}}}	|d|dz            |d|dz            fS )a  Parabolic cylinder functions Dv(x) and derivatives.

    Parameters
    ----------
    v : float
        Order of the parabolic cylinder function
    x : float
        Value at which to evaluate the function and derivatives

    Returns
    -------
    dv : ndarray
        Values of D_vi(x), for vi=v-int(v), vi=1+v-int(v), ..., vi=v.
    dp : ndarray
        Derivatives D_vi'(x), for vi=v-int(v), vi=1+v-int(v), ..., vi=v.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996, chapter 13.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    r   r   N)r	   r   r   r)   pbdv
r   r   r   r3  r   r4  dvdppdfpdds
             r   rY   rY     s    0 QKK 7HQKK 75666AA	
1B	A	bB}R++BCer!te9b"Q$ir   c                    t          |           rt          |          st          d          t          |           }| |z
  }|dk    rd}n|}||z   }t          j        ||          \  }}}}	|d|dz            |d|dz            fS )a  Parabolic cylinder functions Vv(x) and derivatives.

    Parameters
    ----------
    v : float
        Order of the parabolic cylinder function
    x : float
        Value at which to evaluate the function and derivatives

    Returns
    -------
    dv : ndarray
        Values of V_vi(x), for vi=v-int(v), vi=1+v-int(v), ..., vi=v.
    dp : ndarray
        Derivatives V_vi'(x), for vi=v-int(v), vi=1+v-int(v), ..., vi=v.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996, chapter 13.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    r   r   N)r	   r   r   r)   pbvvr:  s
             r   rZ   rZ     s    0 QKK 7HQKK 75666AA	
1B	Q	bB}R++BCer!te9b"Q$ir   c                 4   t          |           rt          |          st          d          t          |           | k    rt          d          t          |           dk    rd}n| }t	          j        ||          \  }}|d|dz            |d|dz            fS )a  Parabolic cylinder functions Dn(z) and derivatives.

    Parameters
    ----------
    n : int
        Order of the parabolic cylinder function
    z : complex
        Value at which to evaluate the function and derivatives

    Returns
    -------
    dv : ndarray
        Values of D_i(z), for i=0, ..., i=n.
    dp : ndarray
        Derivatives D_i'(z), for i=0, ..., i=n.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996, chapter 13.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    r   zn must be an integer.r   N)r	   r   r   r   r)   cpbdn)r   r   r   cpbcpds        r   rX   rX   	  s    0 QKK 7HQKK 75666aA0111A!~b!$$HCu1u:s5BqD5z!!r   c                     t          |           rt          |           | k    s| dk    rt          d          t          j        | d          S )a  Compute nt zeros of the Kelvin function ber.

    Parameters
    ----------
    nt : int
        Number of zeros to compute. Must be positive.

    Returns
    -------
    ndarray
        First `nt` zeros of the Kelvin function.

    See Also
    --------
    ber

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    r   #nt must be positive integer scalar.r   r	   r   r   r)   klvnzor   s    r   r2   r2   @	  J    0 B<< @E"IIOOq>????2q!!!r   c                     t          |           rt          |           | k    s| dk    rt          d          t          j        | d          S )a  Compute nt zeros of the Kelvin function bei.

    Parameters
    ----------
    nt : int
        Number of zeros to compute. Must be positive.

    Returns
    -------
    ndarray
        First `nt` zeros of the Kelvin function.

    See Also
    --------
    bei

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    r   rF  rr   rG  r   s    r   r0   r0   ]	  rI  r   c                     t          |           rt          |           | k    s| dk    rt          d          t          j        | d          S )a  Compute nt zeros of the Kelvin function ker.

    Parameters
    ----------
    nt : int
        Number of zeros to compute. Must be positive.

    Returns
    -------
    ndarray
        First `nt` zeros of the Kelvin function.

    See Also
    --------
    ker

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    r   rF  rs   rG  r   s    r   rM   rM   z	  rI  r   c                     t          |           rt          |           | k    s| dk    rt          d          t          j        | d          S )a  Compute nt zeros of the Kelvin function kei.

    Parameters
    ----------
    nt : int
        Number of zeros to compute. Must be positive.

    Returns
    -------
    ndarray
        First `nt` zeros of the Kelvin function.

    See Also
    --------
    kei

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    r   rF  rt   rG  r   s    r   rJ   rJ   	  rI  r   c                     t          |           rt          |           | k    s| dk    rt          d          t          j        | d          S )a#  Compute nt zeros of the derivative of the Kelvin function ber.

    Parameters
    ----------
    nt : int
        Number of zeros to compute. Must be positive.

    Returns
    -------
    ndarray
        First `nt` zeros of the derivative of the Kelvin function.

    See Also
    --------
    ber, berp

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html


    Examples
    --------
    Compute the first 5 zeros of the derivative of the Kelvin function.

    >>> from scipy.special import berp_zeros
    >>> berp_zeros(5)
    array([ 6.03871081, 10.51364251, 14.96844542, 19.41757493, 23.86430432])

    r   rF  ru   rG  r   s    r   r4   r4   	  sK    B B<< @E"IIOOq>????2q!!!r   c                     t          |           rt          |           | k    s| dk    rt          d          t          j        | d          S )a.  Compute nt zeros of the derivative of the Kelvin function bei.

    Parameters
    ----------
    nt : int
        Number of zeros to compute. Must be positive.

    Returns
    -------
    ndarray
        First `nt` zeros of the derivative of the Kelvin function.

    See Also
    --------
    bei, beip

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    r   rF  rv   rG  r   s    r   r1   r1   	  rI  r   c                     t          |           rt          |           | k    s| dk    rt          d          t          j        | d          S )a.  Compute nt zeros of the derivative of the Kelvin function ker.

    Parameters
    ----------
    nt : int
        Number of zeros to compute. Must be positive.

    Returns
    -------
    ndarray
        First `nt` zeros of the derivative of the Kelvin function.

    See Also
    --------
    ker, kerp

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    r   rF  rw   rG  r   s    r   rN   rN   	  rI  r   c                     t          |           rt          |           | k    s| dk    rt          d          t          j        | d          S )a.  Compute nt zeros of the derivative of the Kelvin function kei.

    Parameters
    ----------
    nt : int
        Number of zeros to compute. Must be positive.

    Returns
    -------
    ndarray
        First `nt` zeros of the derivative of the Kelvin function.

    See Also
    --------
    kei, keip

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    r   rF  rx   rG  r   s    r   rK   rK   
  rI  r   c                    t          |           rt          |           | k    s| dk    rt          d          t          j        | d          t          j        | d          t          j        | d          t          j        | d          t          j        | d          t          j        | d          t          j        | d	          t          j        | d
          fS )a  Compute nt zeros of all Kelvin functions.

    Returned in a length-8 tuple of arrays of length nt.  The tuple contains
    the arrays of zeros of (ber, bei, ker, kei, ber', bei', ker', kei').

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    r   rF  r   rr   rs   rt   ru   rv   rw   rx   rG  r   s    r   rL   rL   1
  s     B<< @E"IIOOq>???OB""OB""OB""OB""OB""OB""OB""OB""$ $r   c                 n   t          |           rt          |          rt          |          st          d          |t          |          k    s| t          |           k    rt          d          || z
  dk    rt          d          || z
  dz   }t          j        | ||d          d         d|         S )a  Characteristic values for prolate spheroidal wave functions.

    Compute a sequence of characteristic values for the prolate
    spheroidal wave functions for mode m and n'=m..n and spheroidal
    parameter c.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    r   Modes must be integers.   (Difference between n and m is too large.r   Nr	   r   r   r)   segvr   r   cmaxLs       r   r]   r]   J
  s     QKK 7HQKK 7HQKK 75666	U1XX1a==2333	!c		CDDDQ3q5D=Aq!$$Q'..r   c                 n   t          |           rt          |          rt          |          st          d          |t          |          k    s| t          |           k    rt          d          || z
  dk    rt          d          || z
  dz   }t          j        | ||d          d         d|         S )a  Characteristic values for oblate spheroidal wave functions.

    Compute a sequence of characteristic values for the oblate
    spheroidal wave functions for mode m and n'=m..n and spheroidal
    parameter c.

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    r   rS  rT  rU  r   r   NrV  rX  s       r   rW   rW   b
  s     QKK 7HQKK 7HQKK 75666	U1XX1a==2333	!c		CDDDQ3q5D=Aq"%%a($//r   )exact
repetitionc                   |rt          | |z   dz
  ||          S |rdt          |           | k    r#t          |          |k    rt          | |          S d}t          j        |t
          d           t          | |          S t          |          t          |           } }|| k    | dk    z  |dk    z  }t          | |          }t          |t          j
                  rd|| <   n|st          j        d          }|S )as  The number of combinations of N things taken k at a time.

    This is often expressed as "N choose k".

    Parameters
    ----------
    N : int, ndarray
        Number of things.
    k : int, ndarray
        Number of elements taken.
    exact : bool, optional
        For integers, if `exact` is False, then floating point precision is
        used, otherwise the result is computed exactly.

        .. deprecated:: 1.14.0
            ``exact=True`` is deprecated for non-integer `N` and `k` and will raise an
            error in SciPy 1.16.0
    repetition : bool, optional
        If `repetition` is True, then the number of combinations with
        repetition is computed.

    Returns
    -------
    val : int, float, ndarray
        The total number of combinations.

    See Also
    --------
    binom : Binomial coefficient considered as a function of two real
            variables.

    Notes
    -----
    - Array arguments accepted only for exact=False case.
    - If N < 0, or k < 0, then 0 is returned.
    - If k > N and repetition=False, then 0 is returned.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.special import comb
    >>> k = np.array([3, 4])
    >>> n = np.array([10, 10])
    >>> comb(n, k, exact=False)
    array([ 120.,  210.])
    >>> comb(10, 3, exact=True)
    120
    >>> comb(10, 3, exact=True, repetition=True)
    220

    r   r\  z^`exact=True` is deprecated for non-integer `N` and `k` and will raise an error in SciPy 1.16.0rr   r   r   )r7   r   r*   r   r   DeprecationWarningr   r"   
isinstancer   ndarrayr   )Nr   r\  r]  msgcondvalss          r   r7   r7   z
  s   h  /AEAIq.... q66Q;;3q66Q;;Q??"*c-!<<<<Aqzzqzz71::1Q16"a1f-Q{{dBJ'' 	!D$KK 	!:a==Dr   c                    |rt          j        |           d         } t          j        |          d         }t          |           rt          |          st          d          t	          |           t	          |          }}|| k    o||k     }|| k    s| dk     s|dk     r"|rd}t          j        |t          d           dS |rt          d          d}t          ||z
  dz   |dz             D ]}||z  }|S t          |          t          |           } }|| k    | dk    z  |dk    z  }	t          | |z
  dz   |          }
t          |
t           j                  rd|
|	 <   n|	st          j        d          }
|
S )	a  Permutations of N things taken k at a time, i.e., k-permutations of N.

    It's also known as "partial permutations".

    Parameters
    ----------
    N : int, ndarray
        Number of things.
    k : int, ndarray
        Number of elements taken.
    exact : bool, optional
        If ``True``, calculate the answer exactly using long integer arithmetic (`N`
        and `k` must be scalar integers). If ``False``, a floating point approximation
        is calculated (more rapidly) using `poch`. Default is ``False``.

    Returns
    -------
    val : int, ndarray
        The number of k-permutations of N.

    Notes
    -----
    - Array arguments accepted only for exact=False case.
    - If k > N, N < 0, or k < 0, then a 0 is returned.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.special import perm
    >>> k = np.array([3, 4])
    >>> n = np.array([10, 10])
    >>> perm(n, k)
    array([  720.,  5040.])
    >>> perm(10, 3, exact=True)
    720

     z6`N` and `k` must scalar integers be with `exact=True`.r   z`Non-integer `N` and `k` with `exact=True` is deprecated and will raise an error in SciPy 1.16.0.rr   r   z;Non-integer `N` and `k` with `exact=True` is not supported.r   )r   squeezer	   r   r   r   r   r`  r   r   r!   ra  rb  r   )rc  r   r\  floor_Nfloor_knon_integralrd  valr   re  rf  s              r   r[   r[   
  s   L  JqMM"JqMM" 	W 	WUVVVq663q66#qL9W\:EEq1uu!a%% E>c#5!DDDD1 	+ * + + +w(1,gk:: 	 	A1HCC
qzz71::1Q16"a1f-AEAIq!!dBJ'' 	!D$KK 	!:a==Dr   c                     | dk    r|dk    rt          j        |          S | |z   |k     r?|| z   dz  }|dk    r|||z
  |z  z
  }t          | ||          t          ||z   ||          z  S | |z   |k    r| |z  S |S )a  
    Product of a range of numbers spaced k apart (from hi).

    For k=1, this returns the product of
    lo * (lo+1) * (lo+2) * ... * (hi-2) * (hi-1) * hi
    = hi! / (lo-1)!

    For k>1, it correspond to taking only every k'th number when
    counting down from hi - e.g. 18!!!! = _range_prod(1, 18, 4).

    Breaks into smaller products first for speed:
    _range_prod(2, 9) = ((2*3)*(4*5))*((6*7)*(8*9))
    r   rr   )mathr<   _range_prod)lohir   mids       r   rp  rp    s     
Qww166~b!!!	Av{{Bw1nq55#(a(C2sA&&S1Wb!)D)DDD	a2Bw	r   c           	         t          j        |           }|t          j        |                    }t          j        |                                           rt          }nz|t
                                          v rX|d         t
          |         k    rt          }n@|d         t          |         k    rt           j	        }nt          j
        d          }nt          }t          j        | |          }||dk             }d|| dk     <   d|| dk     <   t          d|          D ]}|dk    r|||z  |k             n|}|j        rt          dt          |d                   |          }||| |d         k    <   t          t!          |          dz
            D ]P}||         }	||dz            }
|t          t          |	dz             t          |
          |          z  }||| |
k    <   Qt          j        |                                           r@|                    t           j                  }t           j        |t          j        |           <   |S )a  
    Exact computation of factorial for an array.

    The factorials are computed in incremental fashion, by taking
    the sorted unique values of n and multiplying the intervening
    numbers between the different unique values.

    In other words, the factorial for the largest input is only
    computed once, with each other result computed in the process.

    k > 1 corresponds to the multifactorial.
    r   longr   r   rr   r   r   )r   uniqueisnananyr   _FACTORIALK_LIMITS_64BITSkeysobject_FACTORIALK_LIMITS_32BITSint64r   r   r   sizerp  r   lenr  r   r   )r   r   undtr   laneulrm  r   prevcurrents              r   _factorialx_array_exactr  )  s!    
1B 
RXb\\M	B 
x{{ 	
',,..	.	.b6-a000BBV/222BB&!!BB 
-
$
$
$C 
BFBCAJCAJ
 a ( (%&UURaD !!7 	( aRUq111C!CRU
O3r77Q;'' 	( 	( !uQU) {3tax==#g,,!DDDD$'AL!!	x{{ "jj$$6BHQKKJr   c           	      &   |dk    rt          | ||          S t          | j                  }t          |t	          j        |           t          j                   | dk    }t          ||           }t          ||t          |||                     |S )z
    Calculate approximation to multifactorial for array n and integer k.

    Ensure that values aren't calculated unnecessarily.
    r   r   extendr   )_factorialx_approx_corer   r   r   r   rx  r   r   )r   r   r  resultre  n_to_computes         r   _factorialx_array_approxr  n  s     &qAf==== 17^^F	&"(1++rv&&&FD4##L	&$/&QQQRRRMr   c                    t          | dz             }t          |t          j                  r)t	          | j        d          st          j        || dk    <   n.t          j        |          r| dk    rt          j        d          }|S )zO
    returns gamma(n+1), though with NaN at -1 instead of inf, c.f. #21827
    r   rY  r   r   )	r   ra  r   rb  _is_subdtyper   r   isinfr   )rf  ress     r   _gamma1pr    sy     q//C #rz""  DJ,, 	% fC
O	#  42::jJr   c           
         |dk    r?t          |           }t          | t          j                  rt          j        |          }|S |dk    rt          t          |          d          s|dk     rt          nd}t          j	                    5  t          j
        dt                     t          j        || |z  |          t          | |z            z  }|t          d|z  dz             t          j        |d|z  |          z  z  }ddd           n# 1 swxY w Y   t          | t          j                  rt          j        |          }|S | |z  }t          | t          j                  sXt          j        || |z
  |z            t          | |z  dz             z  t          ||z  dz             z  t          |d          z  S t          j        || |z            t          | |z  dz             z  }d }t          j        |          D ]4}|dk    r	|||k    xx          ||t#          |                    z  cc<   5|S )	zI
    Core approximation to multifactorial for array n and integer k.
    r   r   rY  r   Nignorer   c                 f    t          j        | | | z            t          || z  dz             z  |z  S )Nr   )r   powerr   )r   rs     r   corrz%_factorialx_approx_core.<locals>.corr  s3    28ArAv..q1uqy1A1AAAEEr   )r  ra  r   rb  arrayr  r  r   r   catch_warningssimplefilterr   r  r   r   r  rw  r   )r   r   r  r  p_dtypen_mod_kr  r  s           r   r  r    s    	Avv !a$$ 	&Xf%%F*477C88LAEE''$&& 	L 	L!(N;;;XaQg666!a%HFfQUQY''"(1a!e7*K*K*KKKF	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L a$$ 	&Xf%%F !eG a$$ 
HQW)**AEAI!&w{Q!7!78'1oo	
 XaQ%A	"2"22F FEEYw 0 066w!|QA/Ms   A;DDDc                      t          |t                    r|n|g}t          j        t          j        t          j        t          j        dfd|D             }t           fd|D                       S )a  
    Shorthand for calculating whether dtype is subtype of some dtypes.

    Also allows specifying a list instead of just a single dtype.

    Additionaly, the most important supertypes from
        https://numpy.org/doc/stable/reference/arrays.scalars.html
    can optionally be specified using abbreviations as follows:
        "i": np.integer
        "f": np.floating
        "c": np.complexfloating
        "n": np.number (contains the other three)
    )r   frY  r   c                 <    g | ]}                     ||          S rh  )get).0r   mappings     r   
<listcomp>z _is_subdtype.<locals>.<listcomp>  s'    000Agkk!Q000r   c              3   B   K   | ]}t          j        |          V  d S )N)r   r   )r  r  r   s     r   	<genexpr>z_is_subdtype.<locals>.<genexpr>  s/      99Br}UB''999999r   )ra  listr   integerfloatingcomplexfloatingnumberry  )r   dtypesr  s   ` @r   r  r    s     "&$//=VVfXF Z[Y	 G 1000000F9999&999999r   c           	         |dvrt          d|           |r|dk    rt          d          d}| dk    r|dz  }n|dz  }d	}d
}| dk    r|dz  }n| dk    r|dz  }t          t          |          g d          s2t          |                    d| t          |                              t          t          |          ddg          r|dk    rt          |          |dk    r|dk     rd| }t          |          |dk    rt          d          | dk    rdnddg}	t	          j        |          dk    rt          |t          j                  st          t          |          dddt          d          g          s2t          |                    d| t          |                              t          t          |          |	          r|dk    rt          |          |t	          j        |          rM|dk    ot          t          |          d          }
|
rt	          j	        d          nt	          j
        d          S |dk    r|dk     r|rdnt	          j
        d          S |dv r|rdnt	          j
        d          S |r/t          t          |          d          rt          d||          S |r0t          |                    t          |                               t          |||!          S t          |          }t          |j        g d          s*t          |                    d| |j                            t          |j        |	          r|dk    rt          |          |r>t          |j        dg          r(t          |                    |j                             |j        dk    r|S |rt!          ||          S t#          |||!          S )"zG
    Shared implementation for factorial, factorial2 & factorialk.
    )zeror   z@argument `extend` must be either 'zero' or 'complex', received: r   z9Incompatible options: `exact=True` and `extend='complex'`z6Unsupported data type for {vname} in {fname}: {dtype}
r<   zxPermitted data types are integers and floating point numbers, as well as complex numbers if `extend='complex' is passed.zxPermitted data types are integers, as well as floating point numbers and complex numbers if `extend='complex' is passed.zA`exact=True` only supports integers, cannot use data type {dtype}zIn order to use non-integer arguments, you must opt into this by passing `extend='complex'`. Note that this changes the result for all negative arguments (which by default return 0).r=   zm Additionally, it will rescale the values of the double factorial at even integers by a factor of sqrt(2/pi).r>   z^ Additionally, it will perturb the values of the multifactorial at most positive integers `n`.)r   r  rY  z`k`)vnamefnamer   r  rY  r  r   z=For `extend='zero'`, k must be a positive integer, received: r   zParameter k cannot be zero!r   Nz`n`znan+nanjr   >   r   r   rv  r   r  )r   r  r  formatr   r  ra  rb  rx  r  r   rp  r  r   r   r  r  r  )r  r   r   r\  r  	msg_unsupmsg_exact_not_possiblemsg_needs_complexrd  types_requiring_complex
complexifys              r   _factorialx_wrapperr    sx    (((WvWW
 
 	
  V9$$TUUU 	B  I	
		
 	J	
	
 	L 	1   W 	X	,		 O 	P DGG___55 	0Y--EdSTgg-VVWWW$q''C:.. 	06Y3F3F.///VAURSUUCS//!!VV:;;; &+k%9%9ccSz 
wqzzQz!RZ88DGGc3T$ZZ%@AA 	KY--EdSTgg-VVWWW$q''#:;; 	K)@S@S.///Y"(1++Y I-M<Q3M3MJ0:Q2=,,,
5@Q@QQv!a%%0112:a==0&[[0112:a==0 	K|DGGS11 	Kq!q)))) 	K3::a:IIJJJ&qAf==== 	

A11 G))U!')RRSSS	ag6	7	7 GFi<O<O*+++	 G<#// G/66QW6EEFFFv{{	 /&qA....#A6::::r   r  c                 *    t          d| d||          S )aX  
    The factorial of a number or array of numbers.

    The factorial of non-negative integer `n` is the product of all
    positive integers less than or equal to `n`::

        n! = n * (n - 1) * (n - 2) * ... * 1

    Parameters
    ----------
    n : int or float or complex (or array_like thereof)
        Input values for ``n!``. Complex values require ``extend='complex'``.
        By default, the return value for ``n < 0`` is 0.
    exact : bool, optional
        If ``exact`` is set to True, calculate the answer exactly using
        integer arithmetic, otherwise approximate using the gamma function
        (faster, but yields floats instead of integers).
        Default is False.
    extend : string, optional
        One of ``'zero'`` or ``'complex'``; this determines how values ``n<0``
        are handled - by default they are 0, but it is possible to opt into the
        complex extension of the factorial (see below).

    Returns
    -------
    nf : int or float or complex or ndarray
        Factorial of ``n``, as integer, float or complex (depending on ``exact``
        and ``extend``). Array inputs are returned as arrays.

    Notes
    -----
    For arrays with ``exact=True``, the factorial is computed only once, for
    the largest input, with each other result computed in the process.
    The output dtype is increased to ``int64`` or ``object`` if necessary.

    With ``exact=False`` the factorial is approximated using the gamma
    function (which is also the definition of the complex extension):

    .. math:: n! = \Gamma(n+1)

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.special import factorial
    >>> arr = np.array([3, 4, 5])
    >>> factorial(arr, exact=False)
    array([   6.,   24.,  120.])
    >>> factorial(arr, exact=True)
    array([  6,  24, 120])
    >>> factorial(5, exact=True)
    120

    r<   r   r   r\  r  r  r   r\  r  s      r   r<   r<   @  s    l {A%OOOOr   c                 *    t          d| d||          S )a  Double factorial.

    This is the factorial with every second value skipped.  E.g., ``7!! = 7 * 5
    * 3 * 1``.  It can be approximated numerically as::

      n!! = 2 ** (n / 2) * gamma(n / 2 + 1) * sqrt(2 / pi)  n odd
          = 2 ** (n / 2) * gamma(n / 2 + 1)                 n even
          = 2 ** (n / 2) * (n / 2)!                         n even

    The formula for odd ``n`` is the basis for the complex extension.

    Parameters
    ----------
    n : int or float or complex (or array_like thereof)
        Input values for ``n!!``. Non-integer values require ``extend='complex'``.
        By default, the return value for ``n < 0`` is 0.
    exact : bool, optional
        If ``exact`` is set to True, calculate the answer exactly using
        integer arithmetic, otherwise use above approximation (faster,
        but yields floats instead of integers).
        Default is False.
    extend : string, optional
        One of ``'zero'`` or ``'complex'``; this determines how values ``n<0``
        are handled - by default they are 0, but it is possible to opt into the
        complex extension of the double factorial. This also enables passing
        complex values to ``n``.

        .. warning::

           Using the ``'complex'`` extension also changes the values of the
           double factorial for even integers, reducing them by a factor of
           ``sqrt(2/pi) ~= 0.79``, see [1].

    Returns
    -------
    nf : int or float or complex or ndarray
        Double factorial of ``n``, as integer, float or complex (depending on
        ``exact`` and ``extend``). Array inputs are returned as arrays.

    Examples
    --------
    >>> from scipy.special import factorial2
    >>> factorial2(7, exact=False)
    array(105.00000000000001)
    >>> factorial2(7, exact=True)
    105

    References
    ----------
    .. [1] Complex extension to double factorial
            https://en.wikipedia.org/wiki/Double_factorial#Complex_arguments
    r=   rr   r  r  r  s      r   r=   r=   y  s    j |Q!5PPPPr   c                 *    t          d| |||          S )a  Multifactorial of n of order k, n(!!...!).

    This is the multifactorial of n skipping k values.  For example,

      factorialk(17, 4) = 17!!!! = 17 * 13 * 9 * 5 * 1

    In particular, for any integer ``n``, we have

      factorialk(n, 1) = factorial(n)

      factorialk(n, 2) = factorial2(n)

    Parameters
    ----------
    n : int or float or complex (or array_like thereof)
        Input values for multifactorial. Non-integer values require
        ``extend='complex'``. By default, the return value for ``n < 0`` is 0.
    n : int or float or complex (or array_like thereof)
        Order of multifactorial. Non-integer values require ``extend='complex'``.
    exact : bool, optional
        If ``exact`` is set to True, calculate the answer exactly using
        integer arithmetic, otherwise use an approximation (faster,
        but yields floats instead of integers)
        Default is False.
    extend : string, optional
        One of ``'zero'`` or ``'complex'``; this determines how values ``n<0`` are
        handled - by default they are 0, but it is possible to opt into the complex
        extension of the multifactorial. This enables passing complex values,
        not only to ``n`` but also to ``k``.

        .. warning::

           Using the ``'complex'`` extension also changes the values of the
           multifactorial at integers ``n != 1 (mod k)`` by a factor depending
           on both ``k`` and ``n % k``, see below or [1].

    Returns
    -------
    nf : int or float or complex or ndarray
        Multifactorial (order ``k``) of ``n``, as integer, float or complex (depending
        on ``exact`` and ``extend``). Array inputs are returned as arrays.

    Examples
    --------
    >>> from scipy.special import factorialk
    >>> factorialk(5, k=1, exact=True)
    120
    >>> factorialk(5, k=3, exact=True)
    10
    >>> factorialk([5, 7, 9], k=3, exact=True)
    array([ 10,  28, 162])
    >>> factorialk([5, 7, 9], k=3, exact=False)
    array([ 10.,  28., 162.])

    Notes
    -----
    While less straight-forward than for the double-factorial, it's possible to
    calculate a general approximation formula of n!(k) by studying ``n`` for a given
    remainder ``r < k`` (thus ``n = m * k + r``, resp. ``r = n % k``), which can be
    put together into something valid for all integer values ``n >= 0`` & ``k > 0``::

      n!(k) = k ** ((n - r)/k) * gamma(n/k + 1) / gamma(r/k + 1) * max(r, 1)

    This is the basis of the approximation when ``exact=False``.

    In principle, any fixed choice of ``r`` (ignoring its relation ``r = n%k``
    to ``n``) would provide a suitable analytic continuation from integer ``n``
    to complex ``z`` (not only satisfying the functional equation but also
    being logarithmically convex, c.f. Bohr-Mollerup theorem) -- in fact, the
    choice of ``r`` above only changes the function by a constant factor. The
    final constraint that determines the canonical continuation is ``f(1) = 1``,
    which forces ``r = 1`` (see also [1]).::

      z!(k) = k ** ((z - 1)/k) * gamma(z/k + 1) / gamma(1/k + 1)

    References
    ----------
    .. [1] Complex extension to multifactorial
            https://en.wikipedia.org/wiki/Double_factorial#Alternative_extension_of_the_multifactorial
    r>   r  r  )r   r   r\  r  s       r   r>   r>     s    b |Q!5PPPPr   r_  c          	         t          j        |           ot          j        |          }t          |           t          |          }} t          j        | j        t           j                  st          d          t          j        |j        t           j                  st          d          |s@t          |                     t                    |                    t                              S t          t          d t          j        | |gdg          D                                 }t          |           t          t                    }dD ]}d||<   dg d}}|rt!          |          \  }	}
|	dk     s|
|	k    s|
d	k    r'|
|	k    s|
dk    rd||	|
f<   ;|	|k    rw|	|z
  }|d	k    r^|                    d           t%          t'          |          dz
  dd
          D ]}||         |z  ||dz
           z   ||<   |dz  }|d	k    ^||
         ||	|
f<   n||
         ||	|
f<   |	|}}||rt(          t(          t(          gnt          t          t          g}t          j        | |dgddgdgdgddgg|          }|5  |j        sN|t          |d	                   t          |d                   f         |d<   |                                 |j        N|j        d         }|r|                    d	          }ddd           n# 1 swxY w Y   |S )a	  Generate Stirling number(s) of the second kind.

    Stirling numbers of the second kind count the number of ways to
    partition a set with N elements into K non-empty subsets.

    The values this function returns are calculated using a dynamic
    program which avoids redundant computation across the subproblems
    in the solution. For array-like input, this implementation also
    avoids redundant computation across the different Stirling number
    calculations.

    The numbers are sometimes denoted

    .. math::

        {N \brace{K}}

    see [1]_ for details. This is often expressed-verbally-as
    "N subset K".

    Parameters
    ----------
    N : int, ndarray
        Number of things.
    K : int, ndarray
        Number of non-empty subsets taken.
    exact : bool, optional
        Uses dynamic programming (DP) with floating point
        numbers for smaller arrays and uses a second order approximation due to
        Temme for larger entries  of `N` and `K` that allows trading speed for
        accuracy. See [2]_ for a description. Temme approximation is used for
        values ``n>50``. The max error from the DP has max relative error
        ``4.5*10^-16`` for ``n<=50`` and the max error from the Temme approximation
        has max relative error ``5*10^-5`` for ``51 <= n < 70`` and
        ``9*10^-6`` for ``70 <= n < 101``. Note that these max relative errors will
        decrease further as `n` increases.

    Returns
    -------
    val : int, float, ndarray
        The number of partitions.

    See Also
    --------
    comb : The number of combinations of N things taken k at a time.

    Notes
    -----
    - If N < 0, or K < 0, then 0 is returned.
    - If K > N, then 0 is returned.

    The output type will always be `int` or ndarray of `object`.
    The input must contain either numpy or python integers otherwise a
    TypeError is raised.

    References
    ----------
    .. [1] R. L. Graham, D. E. Knuth and O. Patashnik, "Concrete
        Mathematics: A Foundation for Computer Science," Addison-Wesley
        Publishing Company, Boston, 1989. Chapter 6, page 258.

    .. [2] Temme, Nico M. "Asymptotic estimates of Stirling numbers."
        Studies in Applied Mathematics 89.3 (1993): 233-243.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.special import stirling2
    >>> k = np.array([3, -1, 3])
    >>> n = np.array([10, 10, 9])
    >>> stirling2(n, k)
    array([9330.0, 0.0, 3025.0])

    z'Argument `N` must contain only integersz'Argument `K` must contain only integersc                 h    g | ]/\  }}|                     d           |                     d           f0S )r   )take)r  r   r   s      r   r  zstirling2.<locals>.<listcomp>]  sE     9 9 9A ffQii# 9 9 9r   refs_ok))r   r   )r   r   )rr   r   )rr   rr   r   rr   )r   r   r   r   r   Nbufferedreadonly	writeonlyallocate)	op_dtypes)r   r	   r   r   r   r  	TypeErrorr#   r  r   r  setnditerr   r   r   r   appendr   r  r|  finishediternextoperandsr  )rc  Kr\  output_is_scalarnk_pairs	snsk_valspairn_oldn_rowr   r   	num_itersj	out_typesitoutputs                   r   ra   ra     s   V {1~~8"+a..1::wqzzqA="*-- CABBB="*-- CABBB D "!((5//188E??CCC 9 9Aq6I;779 9 9 	: 	: H HC  I0  	$iii5E
  x  1q55AEEQ!VV!VVqAvv !Iq!f%ZZE	Ia--Qs5zz!|Q33 7 7A$QxzE!A#J6E!HHQ	 a-- !&aIq!f %aIq!f%u%   & -2L((ue7LI		
At	Y

|k:%>?	
 
 
B 
 $ $+ 	s2a5zz3r!u::67BqEKKMMM + 	 Q 	$[[^^F$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ Ms   9A:K??LLc                 \    |t          j        | |          S t          j        | ||          S )a  
    Riemann or Hurwitz zeta function.

    Parameters
    ----------
    x : array_like of float or complex.
        Input data
    q : array_like of float, optional
        Input data, must be real.  Defaults to Riemann zeta. When `q` is
        ``None``, complex inputs `x` are supported. If `q` is not ``None``,
        then currently only real inputs `x` with ``x >= 1`` are supported,
        even when ``q = 1.0`` (corresponding to the Riemann zeta function).

    out : ndarray, optional
        Output array for the computed values.

    Returns
    -------
    out : array_like
        Values of zeta(x).

    See Also
    --------
    zetac

    Notes
    -----
    The two-argument version is the Hurwitz zeta function

    .. math::

        \zeta(x, q) = \sum_{k=0}^{\infty} \frac{1}{(k + q)^x};

    see [dlmf]_ for details. The Riemann zeta function corresponds to
    the case when ``q = 1``.

    For complex inputs with ``q = None``, points with
    ``abs(z.imag) > 1e9`` and ``0 <= abs(z.real) < 2.5`` are currently not
    supported due to slow convergence causing excessive runtime.

    References
    ----------
    .. [dlmf] NIST, Digital Library of Mathematical Functions,
        https://dlmf.nist.gov/25.11#i

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.special import zeta, polygamma, factorial

    Some specific values:

    >>> zeta(2), np.pi**2/6
    (1.6449340668482266, 1.6449340668482264)

    >>> zeta(4), np.pi**4/90
    (1.0823232337111381, 1.082323233711138)

    First nontrivial zero:

    >>> zeta(0.5 + 14.134725141734695j)
    0 + 0j

    Relation to the `polygamma` function:

    >>> m = 3
    >>> x = 1.25
    >>> polygamma(m, x)
    array(2.782144009188397)
    >>> (-1)**(m+1) * factorial(m) * zeta(m+1, x)
    2.7821440091883969

    )r   _riemann_zeta_zeta)r   r   r   s      r   rh   rh     s1    T 	y$Q,,,}Q3'''r   c                 (    t          j        d| fi |S )a  
    Compute the softplus function element-wise.

    The softplus function is defined as: ``softplus(x) = log(1 + exp(x))``.
    It is a smooth approximation of the rectifier function (ReLU).

    Parameters
    ----------
    x : array_like
        Input value.
    **kwargs
        For other keyword-only arguments, see the
        `ufunc docs <https://numpy.org/doc/stable/reference/ufuncs.html>`_.

    Returns
    -------
    softplus : ndarray
        Logarithm of ``exp(0) + exp(x)``.

    Examples
    --------
    >>> from scipy import special

    >>> special.softplus(0)
    0.6931471805599453

    >>> special.softplus([-1, 0, 1])
    array([0.31326169, 0.69314718, 1.31326169])
    r   )r   	logaddexp)r   kwargss     r   r`   r`     s    < <1'''''r   )F)r   )r   )rs   )Fr  )NN)~numpyr   ro  r   collectionsr   heapqr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r    r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   _gufuncsr$   r%   r&   r'   _input_validationr(   r)   _combr*   _multiufuncsr+   r,   scipy._lib.deprecationr-   __all____DEPRECATION_MSG_1_15rz  r}  r9   rF   rH   rE   rG   re   rf   rb   rc   rd   r   rI   rg   rO   rD   rB   rC   r^   r_   r:   r@   rA   r?   r/   r8   r\   rU   rV   r  rQ   r6   rS   r3   r;   rR   rT   r.   r5   rP   rY   rZ   rX   r2   r0   rM   rJ   r4   r1   rN   rK   rL   r]   rW   r7   r[   rp  r  r  r  r  r  r  r<   r=   r>   ra   rh   r`   rh  r   r   <module>r     s-  
       # # # # # # " " " " " " " "O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 0 / / / / / / / / / / / 2 2 2 2 2 2            + + + + + + + + . . . . . .= = =BF  !#rbRB "rbS: :  !#rbRB "rbR9 9 c c cL&. &. &.RR% R% R%j<  <  < ~<  <  < ~7  7  7 t@  @  @ FI% I% I% I%XO% O% O% O%dF% F% F% F%R  K5 K5 K5 K5\O5 O5 O5 O5dN> N> N> N>bN4 N4 N4 N4bB: B: B: B:JB: B: B: B:J5# 5# 5#p6# 6# 6#r% % %P! ! !2! ! !28 8 86- - - -: (' (' ('V9 9 9x8 8 8v #**63IJJKKL L LKL^ #**74JKKLLR R R MLRj<1 <1 <1~0, 0, 0,f1' 1' 1'h #**52BCCDD* * ED*,$" $" $"N0# 0# 0#f0# 0# 0#f/" /" /"d"  "  " J"  "  " J!" !" !"H" " ":" " ":" " ":" " ":#" #" #"L" " ":" " ":" " ":$ $ $2/ / /00 0 00 % H H H H HVC C C CN   :B B B BJ  (  0 0 0f: : :4_; _; _;D6P 6P 6P 6Pr5Q 5Q 5Q 5QpQQ QQ QQ QQh # E E E E EPM( M( M( M(`( ( ( ( (r   