o
     ôjÅ'  ã                   @   s:  d 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 ddlmZmZ ddlmZ ddlmZ dd„ Zed3dd„ƒZdd„ Zd3dd„Zdd„ Zdd„ Zdd„ Zdd„ Zed3dd„ƒZed3dd„ƒZdd„ Zdd „ Zed3d!d"„ƒZed3d#d$„ƒZ d%d&„ Z!ed3d'd(„ƒZ"d)d*„ Z#ed4d+d,„ƒZ$d-d.„ Z%d/d0„ Z&d3d1d2„Z'd	S )5z:Efficient functions for generating orthogonal polynomials.é    )ÚDummy)Údup_mulÚdup_mul_groundÚ
dup_lshiftÚdup_subÚdup_addÚdup_sub_termÚdup_sub_groundÚdup_sqr)Ú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|||ƒ||ƒ}}q'|S )z/Low-level implementation of Jacobi polynomials.é   é   )ÚoneÚranger   r   r   r   )ÚnÚaÚbÚKÚm2Úm1ÚiÚdenÚf0Úf1Úf2Úp0Úp1Úp2© r!   úi/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/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 ]8}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   s,   | dk r|j gS | dk rt| |ƒS t| |ƒS )zDLow-level implementation of Chebyshev polynomials of the first kind.r   é@   )r   Ú_dup_chebyshevt_recÚ_dup_chebyshevt_prod)r   r   r!   r!   r"   Údup_chebyshevtG   s
   

r.   c                 C   sR   |j g|j |jg}}t| d ƒD ]}|ttt|d|ƒ|dƒ|ƒ||ƒ}}q|S )aò   Chebyshev polynomials of the first kind using recurrence.

    Explanation
    ===========

    Chebyshev polynomials of the first kind are defined by the recurrence
    relation:

    .. math::
        T_0(x) &= 1\\
        T_1(x) &= x\\
        T_n(x) &= 2xT_{n-1}(x) - T_{n-2}(x)

    This function calculates the Chebyshev polynomial of the first kind using
    the above recurrence relation.

    Parameters
    ==========

    n : int
        n is a nonnegative integer.
    K : domain

    r   r   ©r   r(   r   r   r   r   )r   r   r   r   Ú_r!   r!   r"   r,   P   s   (r,   c                 C   s¶   |j |jg|dƒ|j|j  g}}t| ƒdd… D ]?}ttt|||ƒ|dƒ|ƒ|j d|ƒ}|dkrE|ttt||ƒ|dƒ|ƒ|j |ƒ}}qttt||ƒ|dƒ|ƒ|j |ƒ|}}q|S )a§   Chebyshev polynomials of the first kind using recursive products.

    Explanation
    ===========

    Computes Chebyshev polynomials of the first kind using

    .. math::
        T_{2n}(x) &= 2T_n^2(x) - 1\\
        T_{2n+1}(x) &= 2T_{n+1}(x)T_n(x) - x

    This is faster than ``_dup_chebyshevt_rec`` for large ``n``.

    Parameters
    ==========

    n : int
        n is a nonnegative integer.
    K : domain

    r   é   Nr   Ú1)r   r(   Úbinr   r   r   r	   r
   )r   r   r   r   r   Úcr!   r!   r"   r-   n   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ƒ|ƒ||ƒ}}q|S )zELow-level implementation of Chebyshev polynomials of the second kind.r   r   r/   ©r   r   r   r   r   r!   r!   r"   Údup_chebyshevu�   s   (r6   c                 C   ó   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_poly–   ó   ÿr9   c                 C   r7   )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   r6   r   r8   r!   r!   r"   Úchebyshevu_poly¦   r:   r;   c                 C   s~   | dk r|j gS |j g|dƒ|jg}}td| d ƒD ]!}t|d|ƒ}t|||d ƒ|ƒ}|tt|||ƒ|dƒ|ƒ}}q|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_hermite¶   s    r>   c                 C   sp   | dk r|j gS |j g|j |jg}}td| d ƒD ]}t|d|ƒ}t|||d ƒ|ƒ}|t|||ƒ}}q|S )z>Low-level implementation of probabilist's Hermite polynomials.r   r   r<   r=   r!   r!   r"   Údup_hermite_probÁ   s   r?   c                 C   r7   )zóGenerates 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   r8   r!   r!   r"   Úhermite_polyÌ   ó   r@   c                 C   r7   )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   r?   r   r8   r!   r!   r"   Úhermite_prob_polyÛ   r:   rB   c                 C   sˆ   | dk r|j gS |j g|j |jg}}td| d ƒD ]'}tt|d|ƒ|d| d |ƒ|ƒ}t|||d |ƒ|ƒ}|t|||ƒ}}q|S )z1Low-level implementation of Legendre polynomials.r   r   r'   r=   r!   r!   r"   Údup_legendreë   s   "rC   c                 C   r7   )zôGenerates 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   rC   r   r8   r!   r!   r"   Úlegendre_polyö   rA   rD   c                 C   sŽ   |j g|jg}}td| d ƒD ]4}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 rF   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   rF   )r   r$   rE   r%   r!   r!   r"   Úlaguerre_poly  s   rG   c                 C   sx   | dk r
|j |jgS |j g|j |jg}}td| d ƒD ]}|ttt|d|ƒ|d| d ƒ|ƒ||ƒ}}qt|d|ƒS )z%Low-level implementation of fn(n, x).r   r   r/   r5   r!   r!   r"   Údup_spherical_bessel_fn  s   0rH   c              	   C   s\   |j |jg|jg}}td| d ƒD ]}|ttt|d|ƒ|dd|  ƒ|ƒ||ƒ}}q|S )z&Low-level implementation of fn(-n, x).r   r   r1   r/   r5   r!   r!   r"   Údup_spherical_bessel_fn_minus(  s   0rI   c                 C   s@   |du 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   rI   rH   r   Úabsr   r   )r   r$   r%   Úfr!   r!   r"   Úspherical_bessel_fn/  s   % rM   )NF)Nr   F)(Ú__doc__Úsympy.core.symbolr   Úsympy.polys.densearithr   r   r   r   r   r   r	   r
   Úsympy.polys.domainsr   r   Úsympy.polys.polytoolsr   Úsympy.utilitiesr   r#   r&   r)   r*   r.   r,   r-   r6   r9   r;   r>   r?   r@   rB   rC   rD   rF   rG   rH   rI   rM   r!   r!   r!   r"   Ú<module>   sD    (
				