o
    *ήc'                     @   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idenf0f1f2p0p1p2 r#   =/tmp/pip-target-vg8gfxp4/lib/python/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.Cannot generate Jacobi polynomial of degree %sTfieldr   Nx)

ValueErrorr   r   r%   intr   newr   r   as_expr)r   r   r   r(   polysr   vpolyr#   r#   r$   jacobi_poly    s    r0   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   r3   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   z2Cannot generate Gegenbauer polynomial of degree %sTr&   Nr(   )
r)   r   r   r3   r*   r   r+   r   r   r,   )r   r   r(   r-   r   r/   r#   r#   r$   gegenbauer_polyP   s   r4   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   r1   r   r   r   r   r   r#   r#   r$   dup_chebyshevto   s
   r6   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   z:Cannot generate 1st kind Chebyshev polynomial of degree %sNr(   )
r)   r   r6   r*   r	   r   r+   r   r   r,   r   r(   r-   r/   r#   r#   r$   chebyshevt_polyz      r9   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   r1   r5   r#   r#   r$   dup_chebyshevu   s
   r;   c                 C   r7   )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   z:Cannot generate 2nd kind Chebyshev polynomial of degree %sNr(   )
r)   r   r;   r*   r	   r   r+   r   r   r,   r8   r#   r#   r$   chebyshevu_poly   r:   r<   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   r2   r   r   r   r   r   )r   r   r   r   r   r   cr#   r#   r$   dup_hermite   s   r>   c                 C   r7   )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/Cannot generate Hermite polynomial of degree %sNr(   )
r)   r   r>   r*   r	   r   r+   r   r   r,   r8   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   r1   )r   r   r   r   r   r   r#   r#   r$   dup_legendre   s   &rA   c                 C   r7   )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   z0Cannot generate Legendre polynomial of degree %sNr(   )
r)   r   rA   r*   r
   r   r+   r   r   r,   r8   r#   r#   r$   legendre_poly   r@   rB   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   )r2   r   r   r   r   r   r   )r   alphar   r   r   r   r   r#   r#   r$   dup_laguerre  s   4$rD   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   z0Cannot generate Laguerre polynomial of degree %sNTr&   r(   )r)   r   r
   r   rD   r*   r   r+   r   r   r,   )r   r(   rC   r-   r   r/   r#   r#   r$   laguerre_poly  s   rE   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   r1   r5   r#   r#   r$   dup_spherical_bessel_fn@  s
   $rF   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   r1   r5   r#   r#   r$   dup_spherical_bessel_fn_minusK  s
   $rH   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(   )
rH   r*   r	   rF   r   r   r+   r   r   r,   )r   r(   r-   dupr/   r#   r#   r$   spherical_bessel_fnV  s   '
rJ   )NF)NNF)&__doc__sympy.core.symbolr   sympy.polys.constructorr   sympy.polys.densearithr   r   r   r   r   sympy.polys.domainsr	   r
   sympy.polys.polyclassesr   sympy.polys.polytoolsr   r   sympy.utilitiesr   r%   r0   r3   r4   r6   r9   r;   r<   r>   r?   rA   rB   rD   rE   rF   rH   rJ   r#   r#   r#   r$   <module>   s>    !
#