K i':dZddlmZddlmZmZmZmZmZm Z m Z m Z ddl m Z mZddlmZddlmZdZedd Zd Zdd Zd Zd ZdZdZeddZeddZdZdZeddZeddZ dZ!eddZ"dZ#eddZ$dZ%dZ&ddZ'y)z:Efficient functions for generating orthogonal polynomials.)Dummy)dup_muldup_mul_ground dup_lshiftdup_subdup_add dup_sub_termdup_sub_grounddup_sqr)ZZQQ) named_poly)publicc @|dkr |jgS|jg||z|dz |jz||z |dz g}}td|dzD]B}||||z|zz||z|d|zz|dz z}||z|d|zz|jz ||z||zz z|d|zz }||z|d|zz|jz ||z|d|zz|dz z||z|d|zzz|d|zz } ||z|jz ||z|jz z||z|d|zzz|z } t|||} tt|d|| |} t|| |} |t t | | || |}}E|S)z/Low-level implementation of Jacobi polynomials.)onerangerrrr)nabKm2m1idenf0f1f2p0p1p2s \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/polys/orthopolys.py dup_jacobir$ s1uweeW!QqTzAEE)AaC1:6B 1ac]8dAEAIA!Q1 56!ead1fnquu$1qs 3qtCx @!ead1fnquu$Q1a!A$)> ?1q51Q4PQ6> RVWXYVZ[^V^ _!eaeema!eaeem ,a!ead1fn = C BA & Jr1a0"a 8 BA &WWRQ/Q7B8 INc 0t|tdd|||f|S)aGenerates 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. NzJacobi polynomial)rr$)rrrxpolyss r# jacobi_polyr)s " aT+>Aq 5 QQr%c|dkr |jgS|jg|d|z|jg}}td|dzD]}tt |d||d||jz z||z |dz|}t||d||jz z||z |jz|}|t |||}}|S)z3Low-level implementation of Gegenbauer polynomials.rrrzerorrrr)rrrrrrr!r"s r#dup_gegenbauerr-,s1uweeWqtAvqvv&B 1ac]( Jr1a0!A$!%%.12E!2La P B!agqt 3aee ;Q ?WRQ'B( Ir%c.t|tdd||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. NzGegenbauer polynomial)rr-)rrr'r(s r#gegenbauer_polyr/7s a/FAPU VVr%c`|dkr |jgS|dkr t||St||S)zDLow-level implementation of Chebyshev polynomials of the first kind.r@)r_dup_chebyshevt_rec_dup_chebyshevt_prod)rrs r#dup_chebyshevtr4Gs51uw2v"1a(( 1 %%r%c |jg|j|jg}}t|dz D]-}|tt 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 rrrr,rrrr)rrrr_s r#r2r2Psf2eeWquuaffoB 1q5\SW^Jr1a,@!A$JBPQRBS Ir%c |j|jg|d|j|j g}}t|ddD]}tt t ||||d||jd|}|dk(r5|t t t|||d||j|}}qt 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 rNr1)rr,binr rrr r )rrrrrcs r#r3r3ns,eeQVV_qtQVVaeeV4B VABZZ B(:AaD!DaeeQPQ R #I~gb!nadA'NPQPUPUWXYB#N72q>1Q4$KQUUTUVXYB Z Ir%c |dkr |jgS|jg|d|jg}}td|dzD]-}|tt t |d||d|||}}/|S)zELow-level implementation of Chebyshev polynomials of the second kind.rrr6rrrrrs r#dup_chebyshevur?sx1uweeWqtQVVnB 1ac]SW^Jr1a,@!A$JBPQRBS Ir%c4t|ttd|f|S)aGenerates 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)rr4r rr'r(s r#chebyshevt_polyrBs" a 4qdE CCr%c4t|ttd|f|S)aGenerates 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)rr?r rAs r#chebyshevu_polyrDs" a 5tU DDr%c |dkr |jgS|jg|d|jg}}td|dzD]E}t|d|}t |||dz |}|t t ||||d|}}G|S)z0Low-level implementation of Hermite polynomials.rrrr,rrrrrrrrrrrs r# dup_hermiterHs1uweeWqtQVVnB 1ac]? r1a  2q1vq )^GAq!$4adA>B? Ir%c|dkr |jgS|jg|j|jg}}td|dzD]4}t|d|}t |||dz |}|t |||}}6|S)z>Low-level implementation of probabilist's Hermite polynomials.rrrFrGs r#dup_hermite_probrJs1uweeWquuaffoB 1ac]& r1a  2q1vq )WQ1%B& Ir%c4t|ttd|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. zHermite polynomial)rrHr rAs r# hermite_polyrLs ab*>e LLr%c4t|ttd|f|S)aGenerates 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)rrJr rAs r#hermite_prob_polyrNs! a)2 .e ==r%c2|dkr |jgS|jg|j|jg}}td|dzD]M}tt |d||d|zdz ||}t|||dz ||}|t |||}}O|S)z1Low-level implementation of Legendre polynomials.rrr+rGs r# dup_legendrerPs1uweeWquuaffoB 1ac]& :b!Q/1Q3q5!a @ 2q1ay! ,WQ1%B& Ir%c4t|ttd|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. zLegendre polynomial)rrPr rAs r# legendre_polyrRs ar+@1$ NNr%c d|jg|jg}}td|dzD]}t||j ||z ||jz ||z |dzg|}t |||jz ||z |jz|}|t |||}}|S)z1Low-level implementation of Laguerre polynomials.rr)r,rrrrr)ralpharrrrrrs r# dup_laguerrerUsffXwB 1ac]& B!%%!uQUU{AaD&81Q4&?@! D 2aee QqT1AEE91 =WQ1%B& Ir%c.t|tdd||f|S)aQGenerates 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. NzLaguerre polynomial)rrU)rr'rTr(s r# laguerre_polyrWs at-BQJPU VVr%c *|dkr|j|jgS|jg|j|jg}}td|dzD]3}|tt t |d||d|zdz |||}}5t |d|S)z%Low-level implementation of fn(n, x).rrr6r>s r#dup_spherical_bessel_fnrYs1uqvveeWquuaffoB 1ac]WW^Jr1a,@!AaCE(ANPRTUVBW b!Q r%c |j|jg|jg}}td|dzD]3}|tt t |d||dd|zz |||}}5|S)z&Low-level implementation of fn(-n, x).rrr9r6r>s r#dup_spherical_bessel_fn_minusr[(soeeQVV_qvvhB 1ac]WW^Jr1a,@!AacE(ANPRTUVBW Ir%c | td}|dkrtnt}tt ||t dt 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'rr)rr[rYrabsr r )rr'r(fs r#spherical_bessel_fnr`/sEJ y #J)*Q%4KA c!faR"Q%'U ;;r%)NF)NrF)(__doc__sympy.core.symbolrsympy.polys.densearithrrrrrr r r sympy.polys.domainsr r sympy.polys.polytoolsrsympy.utilitiesrr$r)r-r/r4r2r3r?rBrDrHrJrLrNrPrRrUrWrYr[r`r%r#rhs@#III&," RR$ W &<> C C D D   M M = =  O OWW  (