
    MZdN!                     "   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 Zedd	       Zd
 Zd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"y)z:Efficient functions for generating orthogonal polynomials.    )Dummy)dup_muldup_mul_ground
dup_lshiftdup_subdup_add)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 ]B  } ||      ||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        |||      ||      }}E |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                 8/usr/lib/python3/dist-packages/sympy/polys/orthopolys.py
dup_jacobir!   	   s   1uweeW!QqTzAEE)AaC1:6B1ac] 8dAEAIA!Q1 56!ead1fnquu$1qs3qtCx@!ead1fnquu$Q1a!A$)>?1q51Q4PQ6>RVWXYVZ[^V^_!eaeema!eaeem,a!ead1fn=CBA&Jr1a0"a8BA&WWRQ/Q7B8 I    Nc           	      0    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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    1uweeWqtAvqvv&B1ac] (Jr1a0!A$!%%.12E!2LaPB!agqt 3aee ;Q?WRQ'B( Ir"   c                 .    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Vr"   c                     | dk  r|j                   gS |j                   g|j                   |j                  g}}t        d| dz         D ]-  }|t        t	        t        |d|       |d      |      ||      }}/ |S )zDLow-level implementation of Chebyshev polynomials of the first kind.r   r   r   r)   r   r   r   r   r   r   r   r   r   s        r    dup_chebyshevtr0   G   sx    1uweeWquuaffoB1ac] SW^Jr1a,@!A$JBPQRBS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   r.   r/   s        r    dup_chebyshevur2   P   sx    1uweeWqtQVVnB1ac] SW^Jr1a,@!A$JBPQRBSIr"   c                 4    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   r0   r	   r   r$   r%   s      r    chebyshevt_polyr5   Y   s"     a4qdEC Cr"   c                 4    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   r2   r	   r4   s      r    chebyshevu_polyr7   i   s"     a5tUD Dr"   c           	         | dk  r|j                   gS |j                   g |d      |j                  g}}t        d| dz         D ]E  }t        |d|      }t	        | ||dz
        |      }|t	        t        |||       |d      |      }}G |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_hermiter;   y   s    1uweeWqtQVVnB1ac] ?r1a 2q1vq)^GAq!$4adA>B? Ir"   c                     | dk  r|j                   gS |j                   g|j                   |j                  g}}t        d| dz         D ]4  }t        |d|      }t	        | ||dz
        |      }|t        |||      }}6 |S )z>Low-level implementation of probabilist's Hermite polynomials.r   r   r9   r:   s          r    dup_hermite_probr=      s    1uweeWquuaffoB1ac] &r1a 2q1vq)WQ1%B& Ir"   c                 4    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	   r4   s      r    hermite_polyr?      s     ab*>eLLr"   c                 4    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   r=   r	   r4   s      r    hermite_prob_polyrA      s!     a)2.e= =r"   c                 2   | dk  r|j                   gS |j                   g|j                   |j                  g}}t        d| dz         D ]M  }t        t	        |d|       |d|z  dz
  |      |      }t        | ||dz
  |      |      }|t        |||      }}O |S )z1Low-level implementation of Legendre polynomials.r   r   r(   r:   s          r    dup_legendrerC      s    1uweeWquuaffoB1ac] &:b!Q/1Q3q5!a@2q1ay!,WQ1%B& Ir"   c                 4    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   rC   r
   r4   s      r    legendre_polyrE      s     ar+@1$NNr"   c           	      d   |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_laguerrerH      s    ffXwB1ac] &B!%%!uQUU{AaD&81Q4&?@!D2aeeQqT1AEE91=WQ1%B& Ir"   c                 .    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   rH   )r   r$   rG   r%   s       r    laguerre_polyrJ      s     at-BQJPUVVr"   c                 *   | dk  r|j                   |j                  gS |j                   g|j                   |j                  g}}t        d| dz         D ]3  }|t        t	        t        |d|       |d|z  dz
        |      ||      }}5 t        |d|      S )z%Low-level implementation of fn(n, x).r   r   r.   r/   s        r    dup_spherical_bessel_fnrL      s    1uqvveeWquuaffoB1ac] WW^Jr1a,@!AaCE(ANPRTUVBWb!Qr"   c                     |j                   |j                  g|j                  g}}t        d| dz         D ]3  }|t        t	        t        |d|       |dd|z  z
        |      ||      }}5 |S )z&Low-level implementation of fn(-n, x).r   r      r.   r/   s        r    dup_spherical_bessel_fn_minusrO      so    eeQVV_qvvhB1ac] WW^Jr1a,@!AacE(ANPRTUVBW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

    r$   r    r   )r   rO   rL   r   absr	   r
   )r   r$   r%   fs       r    spherical_bessel_fnrT      sE    J 	y#J)*Q%4KAc!faR"Q%'U;;r"   )NF)Nr   F)#__doc__sympy.core.symbolr   sympy.polys.densearithr   r   r   r   r   sympy.polys.domainsr	   r
   sympy.polys.polytoolsr   sympy.utilitiesr   r!   r&   r*   r,   r0   r2   r5   r7   r;   r=   r?   rA   rC   rE   rH   rJ   rL   rO   rT    r"   r    <module>r\      s    @ #" " & , "  R R$	W  C C D D		 M M = =	 O O W W  (<r"   