
    g'                     f   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 Zedd
            Zd ZddZd Zd Zd Zd Zedd            Zedd            Zd Zd Zedd            Zedd            Z d Z!edd            Z"d Z#edd            Z$d Z%d Z&ddZ'dS ) z: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           	      ~   | dk     r|j         gS |j         g||z    |d          z  |j         z   ||z
   |d          z  g}}t          d| dz             D ]g} ||          ||z   |z   z  ||z    |d          |z  z    |d          z
  z  }||z    |d          |z  z   |j         z
  ||z  ||z  z
  z   |d          |z  z  }||z    |d          |z  z   |j         z
  ||z    |d          |z  z    |d          z
  z  ||z    |d          |z  z   z   |d          |z  z  }	||z   |j         z
  ||z   |j         z
  z  ||z    |d          |z  z   z  |z  }
t          |||          }t          t          |d|          |	|          }t          ||
|          }|t	          t          |||          ||          }}i|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p2s                 R/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/polys/orthopolys.py
dup_jacobir$   	   s   1uuweW!QQqTTzAE)AaC1:6B1ac]] 8 8addAEAIA!Q1 56!eaadd1fnqu$1qs3qqttCx@!eaadd1fnqu$Q1a!!A$$)>?1q511Q44PQ6>RVWVWXYVZVZ[^V^_!eaema!eaem,a!eaadd1fn=CBA&&Jr1a00"a88BA&&WWRQ//Q77BI    NFc           	      :    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polyss        r#   jacobi_polyr)      s#    " aT+>Aq	5QQQr%   c                    | dk     r|j         gS |j         g |d          |z  |j        g}}t          d| dz             D ]}t          t	          |d|           |d          ||j         z
  z   ||          z   |d          z   |          }t          | |d          ||j         z
  z   ||          z  |j         z   |          }|t          |||          }}|S )z3Low-level implementation of Gegenbauer polynomials.r   r   r   zeror   r   r   r   )r   r   r   r   r   r   r!   r"   s           r#   dup_gegenbauerr-   ,   s    1uuweWqqttAvqv&B1ac]] ( (Jr1a00!!A$$!%.12E!2LaPPB!agqqtt 3ae ;Q??WRQ''BIr%   c                 8    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(   s       r#   gegenbauer_polyr/   7   s"     a/FAPUVVVr%   c                 j    | 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   s     r#   dup_chebyshevtr4   G   s=    1uuw2vv"1a(((1%%%r%   c                     |j         g|j         |j        g}}t          | dz
            D ]<}|t          t	          t          |d|           |d          |          ||          }}=|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   _s        r#   r2   r2   P   sq    2 eWquafoB1q5\\ S SW^Jr1a,@,@!!A$$JJBPQRRBIr%   c           
      
   |j         |j        g |d          |j        |j          g}}t          |           dd         D ]}t          t	          t          |||           |d          |          |j         d|          }|dk    r?|t          t	          t          ||           |d          |          |j         |          }}t          t	          t          ||           |d          |          |j         |          |}}|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   cs         r#   r3   r3   n   s    , eQV_qqttQVaeV4BVVABBZ Z ZB(:(:AAaDD!DDaeQPQRR#II~gb!nnaaddA'N'NPQPUWXYYBB#N72q>>11Q44$K$KQUTUVVXYBBIr%   c                     | dk     r|j         gS |j         g |d          |j        g}}t          d| dz             D ]<}|t          t	          t          |d|           |d          |          ||          }}=|S )zELow-level implementation of Chebyshev polynomials of the second kind.r   r   r6   r   r   r   r   r   s        r#   dup_chebyshevur?      s    1uuweWqqttQVnB1ac]] S SW^Jr1a,@,@!!A$$JJBPQRRBIr%   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   r4   r   r   r'   r(   s      r#   chebyshevt_polyrB      s(     a4qdEC C Cr%   c                 @    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   rA   s      r#   chebyshevu_polyrD      s(     a5tUD D Dr%   c           	      4   | dk     r|j         gS |j         g |d          |j        g}}t          d| dz             D ][}t          |d|          }t	          | ||dz
            |          }|t	          t          |||           |d          |          }}\|S )z0Low-level implementation of Hermite polynomials.r   r   r   r,   r   r   r   r   r   r   r   r   r   r   r   s          r#   dup_hermiterH      s    1uuweWqqttQVnB1ac]] ? ?r1a  2qq1vvq))^GAq!$4$4aaddA>>BIr%   c                     | dk     r|j         gS |j         g|j         |j        g}}t          d| dz             D ]C}t          |d|          }t	          | ||dz
            |          }|t          |||          }}D|S )z>Low-level implementation of probabilist's Hermite polynomials.r   r   rF   rG   s          r#   dup_hermite_probrJ      s    1uuweWquafoB1ac]] & &r1a  2qq1vvq))WQ1%%BIr%   c                 @    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   rH   r   rA   s      r#   hermite_polyrL      s     ab*>eLLLr%   c                 @    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   rJ   r   rA   s      r#   hermite_prob_polyrN      s&     a)2.e= = =r%   c                 <   | dk     r|j         gS |j         g|j         |j        g}}t          d| dz             D ]c}t          t	          |d|           |d|z  dz
  |          |          }t          | ||dz
  |          |          }|t          |||          }}d|S )z1Low-level implementation of Legendre polynomials.r   r   r+   rG   s          r#   dup_legendrerP      s    1uuweWquafoB1ac]] & &:b!Q//1Q3q5!a@@2qq1ayy!,,WQ1%%BIr%   c                 @    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   rP   r   rA   s      r#   legendre_polyrR      s     ar+@1$NNNr%   c           	      \   |j         g|j        g}}t          d| dz             D ]}t          ||j          ||          z  ||j        z
   ||          z   |d          z   g|          }t	          |||j        z
   ||          z  |j        z   |          }|t          |||          }}|S )z1Low-level implementation of Laguerre polynomials.r   r   )r,   r   r   r   r   r   )r   alphar   r   r   r   r   r   s           r#   dup_laguerrerU     s    fXwB1ac]] & &B!%!uQU{AAaDD&811Q44&?@!DD2aeQQqTT1AE91==WQ1%%BIr%   c                 8    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   rU   )r   r'   rT   r(   s       r#   laguerre_polyrW     s"     at-BQJPUVVVr%   c                 $   | dk     r|j         |j        gS |j         g|j         |j        g}}t          d| dz             D ]B}|t          t	          t          |d|           |d|z  dz
            |          ||          }}Ct          |d|          S )z%Low-level implementation of fn(n, x).r   r   r6   r>   s        r#   dup_spherical_bessel_fnrY     s    1uuqveWquafoB1ac]] W WW^Jr1a,@,@!!AaCE((ANNPRTUVVBb!Qr%   c                     |j         |j        g|j        g}}t          d| dz             D ]B}|t          t	          t          |d|           |dd|z  z
            |          ||          }}C|S )z&Low-level implementation of fn(-n, x).r   r   r9   r6   r>   s        r#   dup_spherical_bessel_fn_minusr[   (  sz    eQV_qvhB1ac]] W WW^Jr1a,@,@!!AacE((ANNPRTUVVBIr%   c           	          |t          d          }| dk     rt          nt          }t          t	          |           |t
          dt          d          |z  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[   rY   r   absr   r   )r   r'   r(   fs       r#   spherical_bessel_fnr`   /  sS    J 	y#JJ)*Q%%4KAc!ffaR"Q%%'U;;;r%   )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/   r4   r2   r3   r?   rB   rD   rH   rJ   rL   rN   rP   rR   rU   rW   rY   r[   r`    r%   r#   <module>rh      s   @ @ # # # # # #I I I I I I I I I I I I I I I I I I I I & & & & & & & & , , , , , , " " " " " "    R R R R$	 	 	W W W W & & &  <  >   C C C C D D D D	 	 		 	 	 M M M M = = = =	 	 	 O O O O   W W W W        (< (< (< (< (< (<r%   