a
    RG5d'                     @   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d0ddZdd Zed1ddZdd  Zed2d!d"Z d#d$ Z!ed3d%d&Z"d'd( Z#d)d* Z$d4d+d,Z%dS )5z;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 ]F}|||| |  || |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#   R/var/www/html/django/DPS/env/lib/python3.9/site-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}|rv|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 ]t}|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rPt||}nt|td}|rh|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 ]6}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   s^   | dk rt d|  ttt| tt}|dur>t||}nt|td}|rV|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   s    r8   c                 C   sd   |j g|d|jgg}td| d D ]6}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
    r9   c                 C   s^   | dk rt d|  ttt| tt}|dur>t||}nt|td}|rV|S |	 S )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   r9   r*   r	   r   r+   r   r   r,   r7   r#   r#   r$   chebyshevu_poly   s    r:   c                 C   s|   |j g|d|jgg}td| d D ]N}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   s^   | dk rt d|  ttt| tt}|dur>t||}nt|td}|rV|S |	 S )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,   r7   r#   r#   r$   hermite_poly   s    r=   c                 C   s   |j g|j |jgg}td| d D ]V}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    &r>   c                 C   s^   | dk rt d|  ttt| tt}|dur>t||}nt|td}|rV|S |	 S )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   r>   r*   r
   r   r+   r   r   r,   r7   r#   r#   r$   legendre_poly   s    r?   c                 C   s   |j g|jgg}td| d D ]n}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$rA   c                 C   s   | dk rt d|  |dur.t|dd\}}nttd }}ttt| |||}|durht||}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   rA   r*   r   r+   r   r   r,   )r   r(   r@   r-   r   r/   r#   r#   r$   laguerre_poly  s    rB   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
    $rC   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
    $rE   c                 C   sp   | dk rt t|  t}ntt| t}t|t}|durLt|d| }nt|dtd }|rh|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(   )
rE   r*   r	   rC   r   r   r+   r   r   r,   )r   r(   r-   dupr/   r#   r#   r$   spherical_bessel_fnV  s    '
rG   )NF)NF)NF)NF)NF)NF)NNF)NF)&__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   r8   r9   r:   r<   r=   r>   r?   rA   rB   rC   rE   rG   r#   r#   r#   r$   <module>   s<   !
#