U
    9%eN!                     @   s  d 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 dd Zed/ddZdd Zd0ddZdd Zdd Zed1ddZed2ddZdd Zdd Zed3ddZed4dd Zd!d" Zed5d#d$Zd%d& Zed6d'd(Zd)d* Z d+d, Z!d7d-d.Z"d	S )8z:Efficient functions for generating orthogonal polynomials.    )Dummy)dup_muldup_mul_ground
dup_lshiftdup_subdup_add)ZZQQ)
named_poly)publicc                 C   s  | dk r|j gS |j g|| |d |j  || |d g }}td| d D ]:}|||| |  || |d|  |d  }|| |d|  |j  || ||   |d|  }|| |d|  |j  || |d|  |d  || |d|   |d|  }	|| |j  || |j   || |d|   | }
t|||}tt|d||	|}t||
|}|tt||||| }}qN|S )z/Low-level implementation of Jacobi polynomials.      )oneranger   r   r   r   )nabKm2m1iZdenZf0f1f2p0p1p2 r   U/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/sympy/polys/orthopolys.py
dup_jacobi	   s    006V4r   NFc                 C   s   t | tdd|||f|S )a  Generates the Jacobi polynomial `P_n^{(a,b)}(x)`.

    Parameters
    ==========

    n : int
        Degree of the 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
        If True, return a Poly, otherwise (default) return an expression.
    NzJacobi polynomial)r
   r   )r   r   r   xpolysr   r   r   jacobi_poly   s    r!   c                 C   s   | dk r|j gS |j g|d| |jg }}td| d D ]p}tt|d||d||j   || |d |}t||d||j   || |j  |}|t||| }}q:|S )z3Low-level implementation of Gegenbauer polynomials.r   r   r   zeror   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   dup_gegenbauer,   s    2(r$   c                 C   s   t | tdd||f|S )a?  Generates the Gegenbauer polynomial `C_n^{(a)}(x)`.

    Parameters
    ==========

    n : int
        Degree of the polynomial.
    x : optional
    a
        Decides minimal domain for the list of coefficients.
    polys : bool, optional
        If True, return a Poly, otherwise (default) return an expression.
    NzGegenbauer polynomial)r
   r$   )r   r   r   r    r   r   r   gegenbauer_poly7   s    r%   c                 C   sd   | dk r|j gS |j g|j |jg }}td| d D ]*}|ttt|d||d||| }}q4|S )zDLow-level implementation of Chebyshev polynomials of the first kind.r   r   r   r#   r   r   r   r   r   r   r   r   r   r   r   r   dup_chebyshevtG   s    (r(   c                 C   sf   | dk r|j gS |j g|d|jg }}td| d D ]*}|ttt|d||d||| }}q6|S )zELow-level implementation of Chebyshev polynomials of the second kind.r   r   r&   r'   r   r   r   dup_chebyshevuP   s    (r)   c                 C   s   t | ttd|f|S )a  Generates the Chebyshev polynomial of the first kind `T_n(x)`.

    Parameters
    ==========

    n : int
        Degree of the polynomial.
    x : optional
    polys : bool, optional
        If True, return a Poly, otherwise (default) return an expression.
    z&Chebyshev polynomial of the first kind)r
   r(   r   r   r   r    r   r   r   chebyshevt_polyY   s
      r+   c                 C   s   t | ttd|f|S )a  Generates the Chebyshev polynomial of the second kind `U_n(x)`.

    Parameters
    ==========

    n : int
        Degree of the polynomial.
    x : optional
    polys : bool, optional
        If True, return a Poly, otherwise (default) return an expression.
    z'Chebyshev polynomial of the second kind)r
   r)   r   r*   r   r   r   chebyshevu_polyi   s
      r,   c                 C   s~   | dk r|j gS |j g|d|jg }}td| d D ]B}t|d|}t|||d |}|tt||||d| }}q6|S )z0Low-level implementation of Hermite polynomials.r   r   r   r#   r   r   r   r   r   r   r   r   r   r   r   r   r   r   dup_hermitey   s     r/   c                 C   sp   | dk r|j gS |j g|j |jg }}td| d D ]6}t|d|}t|||d |}|t||| }}q4|S )z>Low-level implementation of probabilist's Hermite polynomials.r   r   r-   r.   r   r   r   dup_hermite_prob   s    r0   c                 C   s   t | ttd|f|S )zGenerates the Hermite polynomial `H_n(x)`.

    Parameters
    ==========

    n : int
        Degree of the polynomial.
    x : optional
    polys : bool, optional
        If True, return a Poly, otherwise (default) return an expression.
    zHermite polynomial)r
   r/   r   r*   r   r   r   hermite_poly   s    r1   c                 C   s   t | ttd|f|S )a  Generates the probabilist's Hermite polynomial `He_n(x)`.

    Parameters
    ==========

    n : int
        Degree of the polynomial.
    x : optional
    polys : bool, optional
        If True, return a Poly, otherwise (default) return an expression.
    z probabilist's Hermite polynomial)r
   r0   r   r*   r   r   r   hermite_prob_poly   s
      r2   c                 C   s   | dk r|j gS |j g|j |jg }}td| d D ]N}tt|d||d| d ||}t|||d ||}|t||| }}q4|S )z1Low-level implementation of Legendre polynomials.r   r   r"   r.   r   r   r   dup_legendre   s    "r3   c                 C   s   t | ttd|f|S )zGenerates the Legendre polynomial `P_n(x)`.

    Parameters
    ==========

    n : int
        Degree of the polynomial.
    x : optional
    polys : bool, optional
        If True, return a Poly, otherwise (default) return an expression.
    zLegendre polynomial)r
   r3   r	   r*   r   r   r   legendre_poly   s    r4   c                 C   s   |j g|jg }}td| d D ]h}t||j || ||j || |d g|}t|||j || |j |}|t||| }}q |S )z1Low-level implementation of Laguerre polynomials.r   r   )r#   r   r   r   r   r   )r   alphar   r   r   r   r   r   r   r   r   dup_laguerre   s    2 r6   c                 C   s   t | tdd||f|S )aQ  Generates the Laguerre polynomial `L_n^{(\alpha)}(x)`.

    Parameters
    ==========

    n : int
        Degree of the polynomial.
    x : optional
    alpha : optional
        Decides minimal domain for the list of coefficients.
    polys : bool, optional
        If True, return a Poly, otherwise (default) return an expression.
    NzLaguerre polynomial)r
   r6   )r   r   r5   r    r   r   r   laguerre_poly   s    r7   c                 C   sx   | dk r|j |jgS |j g|j |jg }}td| d D ]2}|ttt|d||d| d ||| }}q8t|d|S )z%Low-level implementation of fn(n, x).r   r   r&   r'   r   r   r   dup_spherical_bessel_fn   s    0r8   c              	   C   s\   |j |jg|jg }}td| d D ]2}|ttt|d||dd|  ||| }}q$|S )z&Low-level implementation of fn(-n, x).r   r      r&   r'   r   r   r   dup_spherical_bessel_fn_minus   s    0r:   c                 C   s@   |dkrt d}| dk rtnt}tt| |tdtd| f|S )a  
    Coefficients for the spherical Bessel functions.

    These 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
        Degree of the polynomial.
    x : optional
    polys : bool, optional
        If True, return a Poly, otherwise (default) return 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

    Nr   r    r   )r   r:   r8   r
   absr   r	   )r   r   r    fr   r   r   spherical_bessel_fn   s    %r>   )NF)NF)NF)NF)NF)NF)NF)Nr   F)NF)#__doc__Zsympy.core.symbolr   Zsympy.polys.densearithr   r   r   r   r   Zsympy.polys.domainsr   r	   Zsympy.polys.polytoolsr
   Zsympy.utilitiesr   r   r!   r$   r%   r(   r)   r+   r,   r/   r0   r1   r2   r3   r4   r6   r7   r8   r:   r>   r   r   r   r   <module>   s>   
				