
    Ed'                     L   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	 Zedd            Zd ZddZd Zedd            Zd Zedd            Z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)construct_domain)dup_muldup_mul_ground
dup_lshiftdup_subdup_add)ZZQQ)DMP)PolyPurePoly)publicc           
         |j         g||z    |d          z    |d          z  ||z
   |d          z  gg}t          d| dz             D ]} ||          ||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          |d         ||          }
t          t          |d         d|          ||          }t          |d         |	|          }|                    t          t          |
||          ||                     ||          S )z0Low-level implementation of Jacobi polynomials.       )oneranger   r   appendr   r	   )nabKseqidenf0f1f2p0p1p2s                6lib/python3.11/site-packages/sympy/polys/orthopolys.py
dup_jacobir&      s   E7a!eaaddlAAaDD(1q5!!A$$,7
8C1a!e__ 7 7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CGR++Js2w155r1==CGR++

772r1--r1556666q6M    NFc                 t   | dk     rt          d| z            t          ||gd          \  }}t          t          t	          |           |d         |d         |          |          }|t          j        ||          }n"t          j        |t          d                    }|r|n|	                                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polys           r%   jacobi_polyr3       s    ( 	1u OIAMNNNQF$///DAqz#a&&!A$!a00!44D .xa  |D%**--,44dllnn,r'   c                    |j         g |d          |z  |j        gg}t          d| dz             D ]} |d          ||z   |j         z
  z  |z  }| |d          |z  z    |d          z
  |z  }t          t	          |d         d|          ||          }t          |d         ||          }|                    t          |||                     ||          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$   s	            r%   dup_gegenbauerr7   B   s    E7QQqTT!VQV$
%C1a!e__ ' 'QqTTQUQU]#a'!!A$$q&j11Q441$Js2w155r1==CGR++

72r1%%&&&&q6Mr'   c                 V   | dk     rt          d| z            t          |d          \  }}t          t          t	          |           ||          |          }|t          j        ||          }n"t          j        |t          d                    }|r|n|	                                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   r7   r-   r   r.   r   r   r/   )r   r   r+   r0   r   r2   s         r%   gegenbauer_polyr9   P   s      	1u F@1DF F 	F AT***DAq~c!ffa++Q//D .xa  |D%**--,44dllnn,r'   c                    |j         g|j         |j        gg}t          d| dz             D ][}t          t	          |d         d|           |d          |          }|                    t          ||d         |                     \||          S )zCLow-level implementation of Chebyshev polynomials of the 1st kind. r   r   r   r   r5   r   r   r   r   r   s        r%   dup_chebyshevtr<   o   s    E7QUAFO
$C1a!e__ + +:c"gq!44aaddA>>

71c"gq))****q6Mr'   c                 @   | dk     rt          d| z            t          t          t          |           t                    t                    }|t          j        ||          }n"t          j        |t          d                    }|r|n|	                                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   r<   r-   r
   r   r.   r   r   r/   r   r+   r0   r2   s       r%   chebyshevt_polyr?   z        	1u NH1LN N 	N ~c!ffb))2..D .xa  |D%**--,44dllnn,r'   c                 $   |j         g |d          |j        gg}t          d| dz             D ][}t          t	          |d         d|           |d          |          }|                    t          ||d         |                     \||          S )zCLow-level implementation of Chebyshev polynomials of the 2nd kind. r   r   r   r   r5   r;   s        r%   dup_chebyshevurB      s    E7QQqTT16N
#C1a!e__ + +:c"gq!44aaddA>>

71c"gq))****q6Mr'   c                 @   | dk     rt          d| z            t          t          t          |           t                    t                    }|t          j        ||          }n"t          j        |t          d                    }|r|n|	                                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   rB   r-   r
   r   r.   r   r   r/   r>   s       r%   chebyshevu_polyrD      r@   r'   c                 b   |j         g |d          |j        gg}t          d| dz             D ]z}t          |d         d|          }t	          |d          ||dz
            |          }t	          t          |||           |d          |          }|                    |           {||          S )z1Low-level implementation of Hermite polynomials. r   r   r   r   )r   r6   r   r   r   r   r   )r   r   r   r   r   r   cs          r%   dup_hermiterG      s    E7QQqTT16N
#C1a!e__  s2w1%%3r7AAa!eHHa0071a++QQqTT155

1q6Mr'   c                 @   | dk     rt          d| z            t          t          t          |           t                    t                    }|t          j        ||          }n"t          j        |t          d                    }|r|n|	                                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   rG   r-   r
   r   r.   r   r   r/   r>   s       r%   hermite_polyrI      s     	1u PJQNOOO{3q662&&++D .xa  |D%**--,44dllnn,r'   c                 f   |j         g|j         |j        gg}t          d| dz             D ]}t          t	          |d         d|           |d|z  dz
  |          |          }t          |d          ||dz
  |          |          }|                    t          |||                     ||          S )z2Low-level implementation of Legendre polynomials. r   r   r   r   r5   )r   r   r   r   r   r   s         r%   dup_legendrerK      s    E7QUAFO
$C1a!e__ % %:c"gq!44aa!ammQGG3r7AAa!eQKK33

71a##$$$$q6Mr'   c                 @   | dk     rt          d| z            t          t          t          |           t                    t                    }|t          j        ||          }n"t          j        |t          d                    }|r|n|	                                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   rK   r-   r   r   r.   r   r   r/   r>   s       r%   legendre_polyrM      s     	1u QKaOPPP|CFFB'',,D .xa  |D%**--,44dllnn,r'   c           
      r   |j         g|j        gg}t          d| dz             D ]}t          |d         |j         |z  ||z   |d|z  dz
            |z  z   g|          }t	          |d         ||z   ||dz
            |z  z   |          }|                    t          |||                     |d         S )z2Low-level implementation of Laguerre polynomials. r   r   r   r   )r6   r   r   r   r   r   r   )r   alphar   r   r   r   r   s          r%   dup_laguerrerP     s    F8aeW
C1a!e__ % %CGqufQha!!AaC!G**Q,(>?CC3r7E!GaaAhhqj$8!<<

71a##$$$$r7Nr'   c                    | dk     rt          d| z            |t          |d          \  }}nt          t          d          }}t          t	          t          |           ||          |          }|t          j        ||          }n"t          j        |t          d                    }|r|n|
                                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   rP   r-   r   r.   r   r   r/   )r   r+   rO   r0   r   r2   s         r%   laguerre_polyrR     s    " 	1u QKaOPPP #  55 r!uu5|CFFE1--q11D .xa  |D%**--,44dllnn,r'   c                 F   |j         g|j         |j        gg}t          d| dz             D ]a}t          t	          |d         d|           |d|z  dz
            |          }|                    t          ||d         |                     bt	          ||          d|          S )z& Low-level implementation of fn(n, x) r   r   r   r   r5   r;   s        r%   dup_spherical_bessel_fnrT   @  s    E7QUAFO
$C1a!e__ + +:c"gq!44aa!ajj!DD

71c"gq))****c!fa###r'   c           	      (   |j         |j        g|j        gg}t          d| dz             D ]a}t          t	          |d         d|           |dd|z  z
            |          }|                    t          ||d         |                     b||          S )z' Low-level implementation of fn(-n, x) r   r   r      r   r5   r;   s        r%   dup_spherical_bessel_fn_minusrW   K  s    E16?QVH
%C1a!e__ + +:c"gq!44aaAaCjj!DD

71c"gq))****q6Mr'   c                 t   | dk     r$t          t          |            t                    }n"t          t          |           t                    }t	          |t                    }|t          j        |d|z            }n%t          j        |dt          d          z            }|r|n|	                                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+   )
rW   r-   r
   rT   r   r   r.   r   r   r/   )r   r+   r0   dupr2   s        r%   spherical_bessel_fnrZ   V  s    N 	1u 2+SVVGR88%c!ffb11sB<<D 0xac""|D!E#JJ,//,44dllnn,r'   )NF)NNF)&__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&   r3   r7   r9   r<   r?   rB   rD   rG   rI   rK   rM   rP   rR   rT   rW   rZ    r'   r%   <module>rd      sH   A A $ # # # # # 4 4 4 4 4 4              ' & & & & & & & ' ' ' ' ' ' 0 0 0 0 0 0 0 0 " " " " " "  " - - - -B  - - - ->   - - - -6   - - - -6   - - - -4
 
 
 - - - -4
 
 
  -  -  -  -F$ $ $  3- 3- 3- 3- 3- 3-r'   