o
    8Vap'                     @   s$  d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
 ddlmZmZ ddlmZ ddlmZmZ ddlmZ d	d
 Zed-ddZdd Zd-ddZdd Zed-ddZdd Zed-ddZdd Zed-ddZdd  Zed-d!d"Z d#d$ Z!ed.d%d&Z"d'd( Z#d)d* Z$d-d+d,Z%dS )/z;Efficient functions for generating orthogonal polynomials.     )Dummy)construct_domain)dup_muldup_mul_ground
dup_lshiftdup_subdup_add)ZZQQ)DMP)PolyPurePoly)publicc                 C   s  |j g|| |d |d || |d gg}td| d D ]}|||| |  || |d|  |d  }|| |d|  |j  || ||   |d|  }|| |d|  |j  || |d|  |d  || |d|   |d|  }|| |j  || |j   || |d|   | }	t|d ||}
tt|d d|||}t|d |	|}|tt|
|||| q||  S )z0Low-level implementation of Jacobi polynomials.       )oneranger   r   appendr   r   )nabKseqiZdenZf0f1f2Zp0p1p2 r    8/usr/lib/python3/dist-packages/sympy/polys/orthopolys.py
dup_jacobi   s   006V4r"   NFc                 C   s~   | dk r
t d|  t||gdd\}}ttt| |d |d ||}|dur/t||}nt|td}|r;|S |	 S )a  Generates Jacobi polynomial of degree `n` in `x`.

    Parameters
    ==========

    n : int
        `n` decides the degree of polynomial
    a
        Lower limit of minimal domain for the list of
        coefficients.
    b
        Upper limit of minimal domain for the list of
        coefficients.
    x : optional
    polys : bool, optional
        ``polys=True`` returns an expression, otherwise
        (default) returns an expression.
    r   z-can't generate Jacobi polynomial of degree %sTZfieldr   Nx)

ValueErrorr   r   r"   intr   newr   r   as_expr)r   r   r   r$   polysr   vpolyr    r    r!   jacobi_poly    s    r,   c           	      C   s   |j g|d| |jgg}td| d D ]:}|d|| |j   | }||d|  |d | }tt|d d|||}t|d ||}|t||| q||  S )z4Low-level implementation of Gegenbauer polynomials. r   r   r   r   r   zeror   r   r   r   r   )	r   r   r   r   r   r   r   r   r   r    r    r!   dup_gegenbauerB   s   r/   c                 C   sp   | dk r
t d|  t|dd\}}ttt| |||}|dur(t||}nt|td}|r4|S |	 S )ak  Generates Gegenbauer polynomial of degree `n` in `x`.

    Parameters
    ==========

    n : int
        `n` decides the degree of polynomial
    x : optional
    a
        Decides minimal domain for the list of
        coefficients.
    polys : bool, optional
        ``polys=True`` returns an expression, otherwise
        (default) returns an expression.
    r   z1can't generate Gegenbauer polynomial of degree %sTr#   Nr$   )
r%   r   r   r/   r&   r   r'   r   r   r(   )r   r   r$   r)   r   r+   r    r    r!   gegenbauer_polyP   s   r0   c                 C   sb   |j g|j |jgg}td| d D ]}tt|d d||d|}|t||d | q||  S )zCLow-level implementation of Chebyshev polynomials of the 1st kind. r   r   r   r   r-   r   r   r   r   r   r    r    r!   dup_chebyshevto   s
   r2   c                 C   ^   | dk r
t d|  ttt| tt}|durt||}nt|td}|r+|S |	 S )a1  Generates Chebyshev polynomial of the first kind of degree `n` in `x`.

    Parameters
    ==========

    n : int
        `n` decides the degree of polynomial
    x : optional
    polys : bool, optional
        ``polys=True`` returns an expression, otherwise
        (default) returns an expression.
    r   z9can't generate 1st kind Chebyshev polynomial of degree %sNr$   )
r%   r   r2   r&   r	   r   r'   r   r   r(   r   r$   r)   r+   r    r    r!   chebyshevt_polyz      r5   c                 C   sd   |j g|d|jgg}td| d D ]}tt|d d||d|}|t||d | q||  S )zCLow-level implementation of Chebyshev polynomials of the 2nd kind. r   r   r   r   r-   r1   r    r    r!   dup_chebyshevu   s
   r7   c                 C   r3   )a2  Generates Chebyshev polynomial of the second kind of degree `n` in `x`.

    Parameters
    ==========

    n : int
        `n` decides the degree of polynomial
    x : optional
    polys : bool, optional
        ``polys=True`` returns an expression, otherwise
        (default) returns an expression.
    r   z9can't generate 2nd kind Chebyshev polynomial of degree %sNr$   )
r%   r   r7   r&   r	   r   r'   r   r   r(   r4   r    r    r!   chebyshevu_poly   r6   r8   c                 C   s|   |j g|d|jgg}td| d D ]'}t|d d|}t|d ||d |}tt||||d|}|| q||  S )z1Low-level implementation of Hermite polynomials. r   r   r   r   )r   r.   r   r   r   r   r   )r   r   r   r   r   r   cr    r    r!   dup_hermite   s   r:   c                 C   r3   )a  Generates Hermite polynomial of degree `n` in `x`.

    Parameters
    ==========

    n : int
        `n` decides the degree of polynomial
    x : optional
    polys : bool, optional
        ``polys=True`` returns an expression, otherwise
        (default) returns an expression.
    r   z.can't generate Hermite polynomial of degree %sNr$   )
r%   r   r:   r&   r	   r   r'   r   r   r(   r4   r    r    r!   hermite_poly      r;   c                 C   s   |j g|j |jgg}td| d D ]+}tt|d d||d| d ||}t|d ||d ||}|t||| q||  S )z2Low-level implementation of Legendre polynomials. r   r   r   r   r-   )r   r   r   r   r   r   r    r    r!   dup_legendre   s   &r=   c                 C   r3   )a  Generates Legendre polynomial of degree `n` in `x`.

    Parameters
    ==========

    n : int
        `n` decides the degree of polynomial
    x : optional
    polys : bool, optional
        ``polys=True`` returns an expression, otherwise
        (default) returns an expression.
    r   z/can't generate Legendre polynomial of degree %sNr$   )
r%   r   r=   r&   r
   r   r'   r   r   r(   r4   r    r    r!   legendre_poly   r<   r>   c                 C   s   |j g|jgg}td| d D ]7}t|d |j | || |d| d |  g|}t|d || ||d |  |}|t||| q|d S )z2Low-level implementation of Laguerre polynomials. r   r   r   r   )r.   r   r   r   r   r   r   )r   alphar   r   r   r   r   r    r    r!   dup_laguerre  s   4$r@   c                 C   s   | dk r
t d|  |durt|dd\}}nttd}}ttt| |||}|dur4t||}nt|t	d}|r@|S |
 S )am  Generates Laguerre polynomial of degree `n` in `x`.

    Parameters
    ==========

    n : int
        `n` decides the degree of polynomial
    x : optional
    alpha
        Decides minimal domain for the list
        of coefficients.
    polys : bool, optional
        ``polys=True`` returns an expression, otherwise
        (default) returns an expression.
    r   z/can't generate Laguerre polynomial of degree %sNTr#   r$   )r%   r   r
   r   r@   r&   r   r'   r   r   r(   )r   r$   r?   r)   r   r+   r    r    r!   laguerre_poly  s   rA   c                 C   sr   |j g|j |jgg}td| d D ]}tt|d d||d| d |}|t||d | qt||  d|S )z& Low-level implementation of fn(n, x) r   r   r   r   r-   r1   r    r    r!   dup_spherical_bessel_fn@  s
   $rB   c                 C   sj   |j |jg|jgg}td| d D ]}tt|d d||dd|  |}|t||d | q||  S )z' Low-level implementation of fn(-n, x) r   r   r      r   r-   r1   r    r    r!   dup_spherical_bessel_fn_minusK  s
   $rD   c                 C   sp   | dk rt t|  t}ntt| t}t|t}|dur&t|d| }n
t|dtd }|r4|S |	 S )a
  
    Coefficients for the spherical Bessel functions.

    Those are only needed in the jn() function.

    The coefficients are calculated from:

    fn(0, z) = 1/z
    fn(1, z) = 1/z**2
    fn(n-1, z) + fn(n+1, z) == (2*n+1)/z * fn(n, z)

    Parameters
    ==========

    n : int
        `n` decides the degree of polynomial
    x : optional
    polys : bool, optional
        ``polys=True`` returns an expression, otherwise
        (default) returns an expression.

    Examples
    ========

    >>> from sympy.polys.orthopolys import spherical_bessel_fn as fn
    >>> from sympy import Symbol
    >>> z = Symbol("z")
    >>> fn(1, z)
    z**(-2)
    >>> fn(2, z)
    -1/z + 3/z**3
    >>> fn(3, z)
    -6/z**2 + 15/z**4
    >>> fn(4, z)
    1/z - 45/z**3 + 105/z**5

    r   Nr   r$   )
rD   r&   r	   rB   r   r   r'   r   r   r(   )r   r$   r)   dupr+   r    r    r!   spherical_bessel_fnV  s   '
rF   )NF)NNF)&__doc__Zsympyr   Zsympy.polys.constructorr   Zsympy.polys.densearithr   r   r   r   r   Zsympy.polys.domainsr	   r
   Zsympy.polys.polyclassesr   Zsympy.polys.polytoolsr   r   Zsympy.utilitiesr   r"   r,   r/   r0   r2   r5   r7   r8   r:   r;   r=   r>   r@   rA   rB   rD   rF   r    r    r    r!   <module>   s>    !
#