K idZddlmZddlmZmZddlmZddlm Z ddl m Z m Z m Z ddlmZddlmZdd lmZdd lmZdd lmZmZdd lmZdd lmZddlmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%e dZ&GddeZ'Gdde'Z(dZ)Gdde'Z*Gdde'Z+Gdde'Z,GddeZ-GddeZ.Gdd e'Z/Gd!d"eZ0Gd#d$e'Z1Gd%d&e'Z2Gd'd(e'Z3Gd)d*e'Z4y+),z This module mainly implements special orthogonal polynomials. See also functions.combinatorial.numbers which contains some combinatorial polynomials. )Rational)DefinedFunctionArgumentIndexError)S)Dummy)binomial factorialRisingFactorial)re)exp)floor)sqrt)cossec)gamma)hyper)chebyshevt_polychebyshevu_polygegenbauer_poly hermite_polyhermite_prob_poly jacobi_poly laguerre_poly legendre_polyxc&eZdZdZedZdZy)OrthogonalPolynomialz+Base class for orthogonal polynomials. c|jr9|dk\r3|jt|tj t|Syy)Nr) is_integer _ortho_polyint_xsubsclsnrs i/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/functions/special/polynomials.py_eval_at_orderz#OrthogonalPolynomial._eval_at_order s8 <>> from sympy import jacobi, S, conjugate, diff >>> from sympy.abc import a, b, n, x >>> jacobi(0, a, b, x) 1 >>> jacobi(1, a, b, x) a/2 - b/2 + x*(a/2 + b/2 + 1) >>> jacobi(2, a, b, x) a**2/8 - a*b/4 - a/8 + b**2/8 - b/8 + x**2*(a**2/8 + a*b/4 + 7*a/8 + b**2/8 + 7*b/8 + 3/2) + x*(a**2/4 + 3*a/4 - b**2/4 - 3*b/4) - 1/2 >>> jacobi(n, a, b, x) jacobi(n, a, b, x) >>> jacobi(n, a, a, x) RisingFactorial(a + 1, n)*gegenbauer(n, a + 1/2, x)/RisingFactorial(2*a + 1, n) >>> jacobi(n, 0, 0, x) legendre(n, x) >>> jacobi(n, S(1)/2, S(1)/2, x) RisingFactorial(3/2, n)*chebyshevu(n, x)/factorial(n + 1) >>> jacobi(n, -S(1)/2, -S(1)/2, x) RisingFactorial(1/2, n)*chebyshevt(n, x)/factorial(n) >>> jacobi(n, a, b, -x) (-1)**n*jacobi(n, b, a, x) >>> jacobi(n, a, b, 0) gamma(a + n + 1)*hyper((-n, -b - n), (a + 1,), -1)/(2**n*factorial(n)*gamma(a + 1)) >>> jacobi(n, a, b, 1) RisingFactorial(a + 1, n)/factorial(n) >>> conjugate(jacobi(n, a, b, x)) jacobi(n, conjugate(a), conjugate(b), conjugate(x)) >>> diff(jacobi(n,a,b,x), x) (a/2 + b/2 + n/2 + 1/2)*jacobi(n - 1, a + 1, b + 1, x) See Also ======== gegenbauer, chebyshevt_root, chebyshevu, chebyshevu_root, legendre, assoc_legendre, hermite, hermite_prob, laguerre, assoc_laguerre, sympy.polys.orthopolys.jacobi_poly, sympy.polys.orthopolys.gegenbauer_poly sympy.polys.orthopolys.chebyshevt_poly sympy.polys.orthopolys.chebyshevu_poly sympy.polys.orthopolys.hermite_poly sympy.polys.orthopolys.legendre_poly sympy.polys.orthopolys.laguerre_poly References ========== .. [1] https://en.wikipedia.org/wiki/Jacobi_polynomials .. [2] https://mathworld.wolfram.com/JacobiPolynomial.html .. [3] https://functions.wolfram.com/Polynomials/JacobiP/ c||k(r|tddk(r3ttj|t |z t ||zS|j r t||S|tjk(r9tdtjz|t |dzz t||zSt|dz|td|zdz|z t||tjz|zS|| k(rGt||zdzt|dzz d|z|dz zzd|z |dz zz t|| |zS|js|jr#tj|zt|||| zS|j rLd| zt||zdzzt|dzt |zz t!| |z | g|dzgdzS|tj"k(rt|dz|t |z S|tj$urS|j&rF||zd|zzj(r t+dt||z|zdz|tj$zSyyt-||||S)Nr+z,Error. a + b + 2*n should not be an integer.)rr rHalfr chebyshevtis_zerolegendre chebyshevu gegenbauerrassoc_legendre is_Numbercould_extract_minus_sign NegativeOner8rOneInfinity is_positiver ValueErrorr)r%r&abrs r'evalz jacobi.eval~sb 6HRO#&qvvq1IaL@:aQRCSSS1~%aff&qx3iA6FFTUWXIYYY&q1ua0?1Q37A3NNQ[\]_`cdcici_iklQmmm 1"WQ#eAEl2a!eqs^Cq1uPQRSPSnTWefgjkikmnWoo o{{))+}}a'&Aq1"*===yyQB%A "22eAElYq\6QRrAvrlQUGR89:AEEz&q1ua09Q<??ajj==A! //()WXX*1q519q=!v>>r)c|j\}}}}|j||j|j|jSr_r-r,r.)r/r&rKrLrs r'r0zjacobi._eval_conjugates:YY 1ayyAKKM1;;=!++-HHr)N)rR r1r2r3r4r5rMrWr]rar0r6r)r'r8r8-s3N`#+#+J587? Ir)r8ctd||zdzzt||zdzt||zdzzzd|z|z|zdzz t|t||z|zdzzz }t||||t |z S)a Jacobi polynomial $P_n^{\left(\alpha, \beta\right)}(x)$. Explanation =========== ``jacobi_normalized(n, alpha, beta, x)`` gives the $n$th Jacobi polynomial in $x$, $P_n^{\left(\alpha, \beta\right)}(x)$. The Jacobi polynomials are orthogonal on $[-1, 1]$ with respect to the weight $\left(1-x\right)^\alpha \left(1+x\right)^\beta$. This functions returns the polynomials normilzed: .. math:: \int_{-1}^{1} P_m^{\left(\alpha, \beta\right)}(x) P_n^{\left(\alpha, \beta\right)}(x) (1-x)^{\alpha} (1+x)^{\beta} \mathrm{d}x = \delta_{m,n} Examples ======== >>> from sympy import jacobi_normalized >>> from sympy.abc import n,a,b,x >>> jacobi_normalized(n, a, b, x) jacobi(n, a, b, x)/sqrt(2**(a + b + 1)*gamma(a + n + 1)*gamma(b + n + 1)/((a + b + 2*n + 1)*factorial(n)*gamma(a + b + n + 1))) Parameters ========== n : integer degree of polynomial a : alpha value b : beta value x : symbol See Also ======== gegenbauer, chebyshevt_root, chebyshevu, chebyshevu_root, legendre, assoc_legendre, hermite, hermite_prob, laguerre, assoc_laguerre, sympy.polys.orthopolys.jacobi_poly, sympy.polys.orthopolys.gegenbauer_poly sympy.polys.orthopolys.chebyshevt_poly sympy.polys.orthopolys.chebyshevu_poly sympy.polys.orthopolys.hermite_poly sympy.polys.orthopolys.legendre_poly sympy.polys.orthopolys.laguerre_poly References ========== .. [1] https://en.wikipedia.org/wiki/Jacobi_polynomials .. [2] https://mathworld.wolfram.com/JacobiPolynomial.html .. [3] https://functions.wolfram.com/Polynomials/JacobiP/ r;r+)rrr r8r)r&rKrLrnfactors r'jacobi_normalizedrgsFta!eai E!a%!)$4uQUQY7G$GHA#'A+/#&/lU1q519q=5I&IKG !Q1 W --r)c:eZdZdZedZddZdZdZdZ y) rBaN Gegenbauer polynomial $C_n^{\left(\alpha\right)}(x)$. Explanation =========== ``gegenbauer(n, alpha, x)`` gives the $n$th Gegenbauer polynomial in $x$, $C_n^{\left(\alpha\right)}(x)$. The Gegenbauer polynomials are orthogonal on $[-1, 1]$ with respect to the weight $\left(1-x^2\right)^{\alpha-\frac{1}{2}}$. Examples ======== >>> from sympy import gegenbauer, conjugate, diff >>> from sympy.abc import n,a,x >>> gegenbauer(0, a, x) 1 >>> gegenbauer(1, a, x) 2*a*x >>> gegenbauer(2, a, x) -a + x**2*(2*a**2 + 2*a) >>> gegenbauer(3, a, x) x**3*(4*a**3/3 + 4*a**2 + 8*a/3) + x*(-2*a**2 - 2*a) >>> gegenbauer(n, a, x) gegenbauer(n, a, x) >>> gegenbauer(n, a, -x) (-1)**n*gegenbauer(n, a, x) >>> gegenbauer(n, a, 0) 2**n*sqrt(pi)*gamma(a + n/2)/(gamma(a)*gamma(1/2 - n/2)*gamma(n + 1)) >>> gegenbauer(n, a, 1) gamma(2*a + n)/(gamma(2*a)*gamma(n + 1)) >>> conjugate(gegenbauer(n, a, x)) gegenbauer(n, conjugate(a), conjugate(x)) >>> diff(gegenbauer(n, a, x), x) 2*a*gegenbauer(n - 1, a + 1, x) See Also ======== jacobi, chebyshevt_root, chebyshevu, chebyshevu_root, legendre, assoc_legendre, hermite, hermite_prob, laguerre, assoc_laguerre, sympy.polys.orthopolys.jacobi_poly sympy.polys.orthopolys.gegenbauer_poly sympy.polys.orthopolys.chebyshevt_poly sympy.polys.orthopolys.chebyshevu_poly sympy.polys.orthopolys.hermite_poly sympy.polys.orthopolys.hermite_prob_poly sympy.polys.orthopolys.legendre_poly sympy.polys.orthopolys.laguerre_poly References ========== .. [1] https://en.wikipedia.org/wiki/Gegenbauer_polynomials .. [2] https://mathworld.wolfram.com/GegenbauerPolynomial.html .. [3] https://functions.wolfram.com/Polynomials/GegenbauerC3/ c|jrtjS|tjk(r t ||S|tj k(r t ||S|tjk(rtjS|js|tjk(rt|tjkDdk(rtjSttj||zzttj|zztd|z|zztd|zt|dzzz S|jr"tj|zt!||| zS|j"rld|zt%tjzt|tj|zzztd|z dz t|dzzt|zz S|tj k(r/td|z|ztd|zt|dzzz S|tj&ur*|j(rt+||tj&zSyyt-|||S)NTr;r+)rZrZeror=r@rGrArFrDr ComplexInfinityrPirrrErBr?rrHrIr r)r%r&rKrs r'rMzgegenbauer.evalgs ==66M ;Aq> ! !%%Za# # !-- 66M{{AMM!qEAFFNt+,,,ac Oc!$$q&k9E!A#a%LH!&qseAaCj!8:; ))+}}a'*QA2*>>>yy1tADDz)E!affQh,,??Aqy)E!a%L858CEGAEEzQqS1W~qseAEl)BCCajj==*1a01::==!! #1a+ +r)cddlm}|dk(r t|||dk(r|j\}}}t d}ddd||z zzz||zz||zd|zz||z zz }d|dzz|d|zzd|zd|zzdzzz d||zd|zzz z}|t |||z|t |||zz} || |d|dz fS|dk(r)|j\}}}d|zt |dz |dz|zSt||)NrrOr+r;rQr:r<)rSrPrr-rrB) r/rTrPr&rKrrQfactor1factor2r\s r'rWzgegenbauer.fdiffsG1 q=$T84 4 ]iiGAq!c A1a!e},-Q7A= s=#'(1u<./GQiA!G!ac A #>?QUQqS[!"G:aA..Aq!9L1LLDtaAE]+ + ]iiGAq!Q3z!a%Q22 2$T84 4r)c ddlm}td}d|zt|||z zd|z|d|zz zzt |t |d|zz zz }|||dt |dz fS)NrrOrQr:r;)rSrPrr r r )r/r&rKrr[rPrQr\s r'r]zgegenbauer._eval_rewrite_as_Sumsw1 #Ja/!QU33qsa!A#g6FF1 !ac' 2244!Qac +,,r)c ,|j|||fi|Sr_r`)r/r&rKrr[s r'raz&gegenbauer._eval_rewrite_as_polynomial )t((Aq;F;;r)c|j\}}}|j||j|jSr_rc)r/r&rKrs r'r0zgegenbauer._eval_conjugate0))1ayyAKKM1;;=99r)Nr<rdr6r)r'rBrB"s2BH&,&,P5,-< :r)rBcDeZdZdZeeZedZddZ dZ dZ y)r>a Chebyshev polynomial of the first kind, $T_n(x)$. Explanation =========== ``chebyshevt(n, x)`` gives the $n$th Chebyshev polynomial (of the first kind) in $x$, $T_n(x)$. The Chebyshev polynomials of the first kind are orthogonal on $[-1, 1]$ with respect to the weight $\frac{1}{\sqrt{1-x^2}}$. Examples ======== >>> from sympy import chebyshevt, diff >>> from sympy.abc import n,x >>> chebyshevt(0, x) 1 >>> chebyshevt(1, x) x >>> chebyshevt(2, x) 2*x**2 - 1 >>> chebyshevt(n, x) chebyshevt(n, x) >>> chebyshevt(n, -x) (-1)**n*chebyshevt(n, x) >>> chebyshevt(-n, x) chebyshevt(n, x) >>> chebyshevt(n, 0) cos(pi*n/2) >>> chebyshevt(n, -1) (-1)**n >>> diff(chebyshevt(n, x), x) n*chebyshevu(n - 1, x) See Also ======== jacobi, gegenbauer, chebyshevt_root, chebyshevu, chebyshevu_root, legendre, assoc_legendre, hermite, hermite_prob, laguerre, assoc_laguerre, sympy.polys.orthopolys.jacobi_poly sympy.polys.orthopolys.gegenbauer_poly sympy.polys.orthopolys.chebyshevt_poly sympy.polys.orthopolys.chebyshevu_poly sympy.polys.orthopolys.hermite_poly sympy.polys.orthopolys.hermite_prob_poly sympy.polys.orthopolys.legendre_poly sympy.polys.orthopolys.laguerre_poly References ========== .. [1] https://en.wikipedia.org/wiki/Chebyshev_polynomial .. [2] https://mathworld.wolfram.com/ChebyshevPolynomialoftheFirstKind.html .. [3] https://mathworld.wolfram.com/ChebyshevPolynomialoftheSecondKind.html .. [4] https://functions.wolfram.com/Polynomials/ChebyshevT/ .. [5] https://functions.wolfram.com/Polynomials/ChebyshevU/ c|js|jr!tj|zt || zS|jr t | |S|j r-t tjtjz|zS|tjk(rtjS|tjurtjSy|jr|j| |S|j||Sr_) rDrErrFr>r?rr=rlrGrHrZr(r$s r'rMzchebyshevt.evals{{))+}}a'*Q*;;;))+!1"a((yy166ADD=1,--AEEzuu ajjzz!!}}))1"a00))!Q//r)c|dk(r t|||dk(r!|j\}}|t|dz |zSt||Nr+r;)rr-rAr/rTr&rs r'rWzchebyshevt.fdiffsM q=$T84 4 ]99DAqz!a%++ +$T84 4r)c ddlm}td}t|d|z|dzdz |zz||d|zz zz}|||dt |dz fSNrrOrQr;r+)rSrPrrr r/r&rr[rPrQr\s r'r]zchebyshevt._eval_rewrite_as_Sum%s\1 #J1Q31a4!8a-/!a!A#g,>4!Qac +,,r)c *|j||fi|Sr_r`r/r&rr[s r'raz&chebyshevt._eval_rewrite_as_polynomial+)t((A888r)Nr;) r1r2r3r4 staticmethodrr r5rMrWr]rar6r)r'r>r>s6AF/K000 5- 9r)r>cDeZdZdZeeZedZddZ dZ dZ y)rAa Chebyshev polynomial of the second kind, $U_n(x)$. Explanation =========== ``chebyshevu(n, x)`` gives the $n$th Chebyshev polynomial of the second kind in x, $U_n(x)$. The Chebyshev polynomials of the second kind are orthogonal on $[-1, 1]$ with respect to the weight $\sqrt{1-x^2}$. Examples ======== >>> from sympy import chebyshevu, diff >>> from sympy.abc import n,x >>> chebyshevu(0, x) 1 >>> chebyshevu(1, x) 2*x >>> chebyshevu(2, x) 4*x**2 - 1 >>> chebyshevu(n, x) chebyshevu(n, x) >>> chebyshevu(n, -x) (-1)**n*chebyshevu(n, x) >>> chebyshevu(-n, x) -chebyshevu(n - 2, x) >>> chebyshevu(n, 0) cos(pi*n/2) >>> chebyshevu(n, 1) n + 1 >>> diff(chebyshevu(n, x), x) (-x*chebyshevu(n, x) + (n + 1)*chebyshevt(n + 1, x))/(x**2 - 1) See Also ======== jacobi, gegenbauer, chebyshevt, chebyshevt_root, chebyshevu_root, legendre, assoc_legendre, hermite, hermite_prob, laguerre, assoc_laguerre, sympy.polys.orthopolys.jacobi_poly sympy.polys.orthopolys.gegenbauer_poly sympy.polys.orthopolys.chebyshevt_poly sympy.polys.orthopolys.chebyshevu_poly sympy.polys.orthopolys.hermite_poly sympy.polys.orthopolys.hermite_prob_poly sympy.polys.orthopolys.legendre_poly sympy.polys.orthopolys.laguerre_poly References ========== .. [1] https://en.wikipedia.org/wiki/Chebyshev_polynomial .. [2] https://mathworld.wolfram.com/ChebyshevPolynomialoftheFirstKind.html .. [3] https://mathworld.wolfram.com/ChebyshevPolynomialoftheSecondKind.html .. [4] https://functions.wolfram.com/Polynomials/ChebyshevT/ .. [5] https://functions.wolfram.com/Polynomials/ChebyshevU/ c|js |jr!tj|zt || zS|jrH|tjk(rtj S| dz jst | dz | S|j r-ttjtjz|zS|tjk(rtj|zS|tjurtjSy|jr:|tjk(rtj S|j| dz | S|j||SNr;)rDrErrFrArjr?rr=rlrGrHrZr(r$s r'rMzchebyshevu.evalws {{))+}}a'*Q*;;;))+ %66M"q&::<&rAvq111yy166ADD=1,--AEEzuuqy ajjzz!!}} %66M..rAvq999))!Q//r)c|dk(r t|||dk(r=|j\}}|dzt|dz|z|t||zz |dzdz z St||ry)rr-r>rArzs r'rWzchebyshevu.fdiffsq q=$T84 4 ]99DAqUjQ22QAq9I5IIaQRdUVhW W$T84 4r)c ddlm}td}tj|zt ||z zd|z|d|zz zzt |t |d|zz zz }|||dt |dz fSNrrOrQr;rSrPrrrFr r r}s r'r]zchebyshevu._eval_rewrite_as_Sums1 #J}}a) E#cQ1W%&)21 !ac'8J)JL4!Qac +,,r)c *|j||fi|Sr_r`rs r'raz&chebyshevu._eval_rewrite_as_polynomialrr)Nr) r1r2r3r4rrr r5rMrWr]rar6r)r'rArA1s6AF/K00> 5-9r)rAc eZdZdZedZy)chebyshevt_roota ``chebyshev_root(n, k)`` returns the $k$th root (indexed from zero) of the $n$th Chebyshev polynomial of the first kind; that is, if $0 \le k < n$, ``chebyshevt(n, chebyshevt_root(n, k)) == 0``. Examples ======== >>> from sympy import chebyshevt, chebyshevt_root >>> chebyshevt_root(3, 2) -sqrt(3)/2 >>> chebyshevt(3, chebyshevt_root(3, 2)) 0 See Also ======== jacobi, gegenbauer, chebyshevt, chebyshevu, chebyshevu_root, legendre, assoc_legendre, hermite, hermite_prob, laguerre, assoc_laguerre, sympy.polys.orthopolys.jacobi_poly sympy.polys.orthopolys.gegenbauer_poly sympy.polys.orthopolys.chebyshevt_poly sympy.polys.orthopolys.chebyshevu_poly sympy.polys.orthopolys.hermite_poly sympy.polys.orthopolys.hermite_prob_poly sympy.polys.orthopolys.legendre_poly sympy.polys.orthopolys.laguerre_poly cd|kr||kstd|d|ttjd|zdzzd|zz S)Nrmust have 0 <= k < n, got k = and n = r;r+rJrrrlr%r&rQs r'rMzchebyshevt_root.evalsJaa!e+,a12 21441q>1Q3'((r)Nr1r2r3r4r5rMr6r)r'rrs@))r)rc eZdZdZedZy)chebyshevu_rootaw ``chebyshevu_root(n, k)`` returns the $k$th root (indexed from zero) of the $n$th Chebyshev polynomial of the second kind; that is, if $0 \le k < n$, ``chebyshevu(n, chebyshevu_root(n, k)) == 0``. Examples ======== >>> from sympy import chebyshevu, chebyshevu_root >>> chebyshevu_root(3, 2) -sqrt(2)/2 >>> chebyshevu(3, chebyshevu_root(3, 2)) 0 See Also ======== chebyshevt, chebyshevt_root, chebyshevu, legendre, assoc_legendre, hermite, hermite_prob, laguerre, assoc_laguerre, sympy.polys.orthopolys.jacobi_poly sympy.polys.orthopolys.gegenbauer_poly sympy.polys.orthopolys.chebyshevt_poly sympy.polys.orthopolys.chebyshevu_poly sympy.polys.orthopolys.hermite_poly sympy.polys.orthopolys.hermite_prob_poly sympy.polys.orthopolys.legendre_poly sympy.polys.orthopolys.laguerre_poly cd|kr||kstd|d|ttj|dzz|dzz S)Nrrrr+rrs r'rMzchebyshevu_root.evalsFaa!e+,a12 2144Q<Q'((r)Nrr6r)r'rrs@))r)rcDeZdZdZeeZedZddZ dZ dZ y)r@a ``legendre(n, x)`` gives the $n$th Legendre polynomial of $x$, $P_n(x)$ Explanation =========== The Legendre polynomials are orthogonal on $[-1, 1]$ with respect to the constant weight 1. They satisfy $P_n(1) = 1$ for all $n$; further, $P_n$ is odd for odd $n$ and even for even $n$. Examples ======== >>> from sympy import legendre, diff >>> from sympy.abc import x, n >>> legendre(0, x) 1 >>> legendre(1, x) x >>> legendre(2, x) 3*x**2/2 - 1/2 >>> legendre(n, x) legendre(n, x) >>> diff(legendre(n,x), x) n*(x*legendre(n, x) - legendre(n - 1, x))/(x**2 - 1) See Also ======== jacobi, gegenbauer, chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root, assoc_legendre, hermite, hermite_prob, laguerre, assoc_laguerre, sympy.polys.orthopolys.jacobi_poly sympy.polys.orthopolys.gegenbauer_poly sympy.polys.orthopolys.chebyshevt_poly sympy.polys.orthopolys.chebyshevu_poly sympy.polys.orthopolys.hermite_poly sympy.polys.orthopolys.hermite_prob_poly sympy.polys.orthopolys.legendre_poly sympy.polys.orthopolys.laguerre_poly References ========== .. [1] https://en.wikipedia.org/wiki/Legendre_polynomial .. [2] https://mathworld.wolfram.com/LegendrePolynomial.html .. [3] https://functions.wolfram.com/Polynomials/LegendreP/ .. [4] https://functions.wolfram.com/Polynomials/LegendreP2/ c|js|jr!tj|zt || zS|jr2| dz jst | tj z |S|j rYttjttj|dz z ttj |dz zzz S|tj k(rtj S|tjurtjSy|jr| tj z }|j||Sry)rDrErrFr@rGr?rrlrr=rHrZr(r$s r'rMz legendre.eval=s{{))+}}a'(1qb/99))+QBF3T3T3VQUU A..yyADDz5!A##6uQUUQqS[7I#IJJaeeuu ajjzz!! }}BJ%%a+ +r)c|dk(r t|||dk(r:|j\}}||dzdz z |t||zt|dz |z zSt||ry)rr-r@rzs r'rWzlegendre.fdiffUsk q=$T84 4 ]99DAqadQh<8Aq>!1HQUA4F!FG G$T84 4r)c ddlm}td}tj|zt ||dzzd|zdz ||z zzd|z dz |zz}|||d|fSr|)rSrPrrrFrr}s r'r]zlegendre._eval_rewrite_as_Summsh1 #J}}aA 11AE19A2FFQPQ TU~U4!Q##r)c *|j||fi|Sr_r`rs r'raz$legendre._eval_rewrite_as_polynomialsrr)Nr) r1r2r3r4rrr r5rMrWr]rar6r)r'r@r@s53j}-K,,.50$ 9r)r@cJeZdZdZedZedZd dZdZdZ dZ y) rCa ``assoc_legendre(n, m, x)`` gives $P_n^m(x)$, where $n$ and $m$ are the degree and order or an expression which is related to the nth order Legendre polynomial, $P_n(x)$ in the following manner: .. math:: P_n^m(x) = (-1)^m (1 - x^2)^{\frac{m}{2}} \frac{\mathrm{d}^m P_n(x)}{\mathrm{d} x^m} Explanation =========== Associated Legendre polynomials are orthogonal on $[-1, 1]$ with: - weight $= 1$ for the same $m$ and different $n$. - weight $= \frac{1}{1-x^2}$ for the same $n$ and different $m$. Examples ======== >>> from sympy import assoc_legendre >>> from sympy.abc import x, m, n >>> assoc_legendre(0,0, x) 1 >>> assoc_legendre(1,0, x) x >>> assoc_legendre(1,1, x) -sqrt(1 - x**2) >>> assoc_legendre(n,m,x) assoc_legendre(n, m, x) See Also ======== jacobi, gegenbauer, chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root, legendre, hermite, hermite_prob, laguerre, assoc_laguerre, sympy.polys.orthopolys.jacobi_poly sympy.polys.orthopolys.gegenbauer_poly sympy.polys.orthopolys.chebyshevt_poly sympy.polys.orthopolys.chebyshevu_poly sympy.polys.orthopolys.hermite_poly sympy.polys.orthopolys.hermite_prob_poly sympy.polys.orthopolys.legendre_poly sympy.polys.orthopolys.laguerre_poly References ========== .. [1] https://en.wikipedia.org/wiki/Associated_Legendre_polynomials .. [2] https://mathworld.wolfram.com/LegendrePolynomial.html .. [3] https://functions.wolfram.com/Polynomials/LegendreP/ .. [4] https://functions.wolfram.com/Polynomials/LegendreP2/ ct|tdjt|f}tj|zdtdzz t |dzz|j zS)NT)polysr+r;)rr"diffrrFras_expr)r%r&mPs r'r(zassoc_legendre._eval_at_ordersQ !Rt , 1 12q' :}}a1r1u9x1~"== KKr)c|jrAtj| zt||zt||z z zt || |zS|dk(r t ||S|dk(rId|zt tjztd|z |z dz td||z dz z zz S|jr|jr|jr|jr|jrt|d|dt||kDrt|d|d|d|jt|tt|j!t"|Syyyy)Nrr;r+z. : 1st index must be nonnegative integer (got )z0 : abs('2nd index') must be <= '1st index' (got z, )rErrFr rCr@rrlrrDrrZrJabsr(r!r#r")r%r&rrs r'rMzassoc_legendre.evals5 % % '==A2&)AE*:9QU;K*KL~^_bcacefOgg g 6Aq> ! 6a4QTT ?eQUQYM&:5a!eQY;O&OP P ;;1;;1<>> from sympy import hermite, diff >>> from sympy.abc import x, n >>> hermite(0, x) 1 >>> hermite(1, x) 2*x >>> hermite(2, x) 4*x**2 - 2 >>> hermite(n, x) hermite(n, x) >>> diff(hermite(n,x), x) 2*n*hermite(n - 1, x) >>> hermite(n, -x) (-1)**n*hermite(n, x) See Also ======== jacobi, gegenbauer, chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root, legendre, assoc_legendre, hermite_prob, laguerre, assoc_laguerre, sympy.polys.orthopolys.jacobi_poly sympy.polys.orthopolys.gegenbauer_poly sympy.polys.orthopolys.chebyshevt_poly sympy.polys.orthopolys.chebyshevu_poly sympy.polys.orthopolys.hermite_poly sympy.polys.orthopolys.hermite_prob_poly sympy.polys.orthopolys.legendre_poly sympy.polys.orthopolys.laguerre_poly References ========== .. [1] https://en.wikipedia.org/wiki/Hermite_polynomial .. [2] https://mathworld.wolfram.com/HermitePolynomial.html .. [3] https://functions.wolfram.com/Polynomials/HermiteH/ c|js|jr!tj|zt || zS|j r?d|zt tjzttj|z dz z S|tjurtjSy|jrtd|z|j||S)Nr;0The index n must be nonnegative integer (got %r))rDrErrFrr?rrlrrGrHrZrJr(r$s r'rMz hermite.eval&s{{))+}}a''!aR.88yy!td144j(5!%%!)Q+???ajjzz!!}} FJLL))!Q//r)c|dk(r t|||dk(r$|j\}}d|zt|dz |zSt||ry)rr-rrzs r'rWz hermite.fdiff:sQ q=$T84 4 ]99DAqQ3wq1ua(( ($T84 4r)c ddlm}td}tj|zt |t |d|zz zz d|z|d|zz zz}t ||||dt |dz fzSrrr}s r'r]zhermite._eval_rewrite_as_SumEsu1 #J}}a9Q< !ac'0B#BCqsaRSTURUgFVV|Cq!U1Q3Z&8999r)c *|j||fi|Sr_r`rs r'raz#hermite._eval_rewrite_as_polynomialKrr)c Ptd|zt||tdzzSr)r hermite_probrs r'_eval_rewrite_as_hermite_probz%hermite._eval_rewrite_as_hermite_probPs$AwzLAd1gI666r)Nr) r1r2r3r4rrr r5rMrWr]rarr6r)r'rrs:3j|,K00& 5: 9 7r)rcJeZdZdZeeZedZddZ dZ dZ dZ y) ra ``hermite_prob(n, x)`` gives the $n$th probabilist's Hermite polynomial in $x$, $He_n(x)$. Explanation =========== The probabilist's Hermite polynomials are orthogonal on $(-\infty, \infty)$ with respect to the weight $\exp\left(-\frac{x^2}{2}\right)$. They are monic polynomials, related to the plain Hermite polynomials (:py:class:`~.hermite`) by .. math :: He_n(x) = 2^{-n/2} H_n(x/\sqrt{2}) Examples ======== >>> from sympy import hermite_prob, diff, I >>> from sympy.abc import x, n >>> hermite_prob(1, x) x >>> hermite_prob(5, x) x**5 - 10*x**3 + 15*x >>> diff(hermite_prob(n,x), x) n*hermite_prob(n - 1, x) >>> hermite_prob(n, -x) (-1)**n*hermite_prob(n, x) The sum of absolute values of coefficients of $He_n(x)$ is the number of matchings in the complete graph $K_n$ or telephone number, A000085 in the OEIS: >>> [hermite_prob(n,I) / I**n for n in range(11)] [1, 1, 2, 4, 10, 26, 76, 232, 764, 2620, 9496] See Also ======== jacobi, gegenbauer, chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root, legendre, assoc_legendre, hermite, laguerre, assoc_laguerre, sympy.polys.orthopolys.jacobi_poly sympy.polys.orthopolys.gegenbauer_poly sympy.polys.orthopolys.chebyshevt_poly sympy.polys.orthopolys.chebyshevu_poly sympy.polys.orthopolys.hermite_poly sympy.polys.orthopolys.hermite_prob_poly sympy.polys.orthopolys.legendre_poly sympy.polys.orthopolys.laguerre_poly References ========== .. [1] https://en.wikipedia.org/wiki/Hermite_polynomial .. [2] https://mathworld.wolfram.com/HermitePolynomial.html c|js|jr!tj|zt || zS|j r9t tjttj|z dz z S|tjurtjSy|jrtd|zy|j||S)Nr;z'n must be a nonnegative integer, not %r)rDrErrFrr?rrlrrGrHrZrJr(r$s r'rMzhermite_prob.evals{{))+}}a',q1"*===yyADDzE1557a-$888ajjzz!!}}DqHI))!Q//r)cf|dk(r!|j\}}|t|dz |zSt||)Nr;r+)r-rrrzs r'rWzhermite_prob.fdiffs9 q=99DAq\!A#q)) )$T84 4r)c ddlm}td}tj |z||d|zz zzt |t |d|zz zz }t ||||dt |dz fzSr)rSrPrrr=r r r}s r'r]z!hermite_prob._eval_rewrite_as_Sumsn1 #J!|a!AaC%j(IaL9QqsU;K,KL|Cq!U1Q3Z&8999r)c *|j||fi|Sr_r`rs r'raz(hermite_prob._eval_rewrite_as_polynomialrr)c Rtd| zt||tdz zSr)rrrs r'_eval_rewrite_as_hermitez%hermite_prob._eval_rewrite_as_hermites&Aw!}wq!DG)444r)Nr) r1r2r3r4rrr r5rMrWr]rarr6r)r'rrTs;7r01K 0 05: 9 5r)rcDeZdZdZeeZedZddZ dZ dZ y)laguerreaL Returns the $n$th Laguerre polynomial in $x$, $L_n(x)$. Examples ======== >>> from sympy import laguerre, diff >>> from sympy.abc import x, n >>> laguerre(0, x) 1 >>> laguerre(1, x) 1 - x >>> laguerre(2, x) x**2/2 - 2*x + 1 >>> laguerre(3, x) -x**3/6 + 3*x**2/2 - 3*x + 1 >>> laguerre(n, x) laguerre(n, x) >>> diff(laguerre(n, x), x) -assoc_laguerre(n - 1, 1, x) Parameters ========== n : int Degree of Laguerre polynomial. Must be `n \ge 0`. See Also ======== jacobi, gegenbauer, chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root, legendre, assoc_legendre, hermite, hermite_prob, assoc_laguerre, sympy.polys.orthopolys.jacobi_poly sympy.polys.orthopolys.gegenbauer_poly sympy.polys.orthopolys.chebyshevt_poly sympy.polys.orthopolys.chebyshevu_poly sympy.polys.orthopolys.hermite_poly sympy.polys.orthopolys.hermite_prob_poly sympy.polys.orthopolys.legendre_poly sympy.polys.orthopolys.laguerre_poly References ========== .. [1] https://en.wikipedia.org/wiki/Laguerre_polynomial .. [2] https://mathworld.wolfram.com/LaguerrePolynomial.html .. [3] https://functions.wolfram.com/Polynomials/LaguerreL/ .. [4] https://functions.wolfram.com/Polynomials/LaguerreL3/ c.|jdur td|js|jr1| dz jst |t | dz | zS|j rtjS|tjurtjS|tjur$tj|ztjzSy|jrt |t | dz | zS|j||S)NFError: n should be an integer.r+)rrJrDrEr rr?rrGNegativeInfinityrHrFrZr(r$s r'rMz laguerre.evals <<5 => >{{))+QBF3T3T3V1vhrAvr222yyuu a(((zz!ajj}}a'!**44!}}1vhrAvr222))!Q//r)c|dk(r t|||dk(r |j\}}t|dz d| St||ry)rr-assoc_laguerrerzs r'rWzlaguerre.fdiff sM q=$T84 4 ]99DAq"1q5!Q// /$T84 4r)c ddlm}|jr%t||j| dz | fi|zS|j dur t dtd}t| |t|dzz ||zz}|||d|fS)NrrOr+FrrQr;) rSrPrZr r]rrJrr r r}s r'r]zlaguerre._eval_rewrite_as_Sums1 ==q65D55qb1fqbKFKK K <<5 => > #Jr1% ! a7!Q$>4!Q##r)c *|j||fi|Sr_r`rs r'raz$laguerre._eval_rewrite_as_polynomial"rr)Nr) r1r2r3r4rrr r5rMrWr]rar6r)r'rrs56p}-K00, 5 $9r)rc:eZdZdZedZddZdZdZdZ y) raj Returns the $n$th generalized Laguerre polynomial in $x$, $L_n(x)$. Examples ======== >>> from sympy import assoc_laguerre, diff >>> from sympy.abc import x, n, a >>> assoc_laguerre(0, a, x) 1 >>> assoc_laguerre(1, a, x) a - x + 1 >>> assoc_laguerre(2, a, x) a**2/2 + 3*a/2 + x**2/2 + x*(-a - 2) + 1 >>> assoc_laguerre(3, a, x) a**3/6 + a**2 + 11*a/6 - x**3/6 + x**2*(a/2 + 3/2) + x*(-a**2/2 - 5*a/2 - 3) + 1 >>> assoc_laguerre(n, a, 0) binomial(a + n, a) >>> assoc_laguerre(n, a, x) assoc_laguerre(n, a, x) >>> assoc_laguerre(n, 0, x) laguerre(n, x) >>> diff(assoc_laguerre(n, a, x), x) -assoc_laguerre(n - 1, a + 1, x) >>> diff(assoc_laguerre(n, a, x), a) Sum(assoc_laguerre(_k, a, x)/(-a + n), (_k, 0, n - 1)) Parameters ========== n : int Degree of Laguerre polynomial. Must be `n \ge 0`. alpha : Expr Arbitrary expression. For ``alpha=0`` regular Laguerre polynomials will be generated. See Also ======== jacobi, gegenbauer, chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root, legendre, assoc_legendre, hermite, hermite_prob, laguerre, sympy.polys.orthopolys.jacobi_poly sympy.polys.orthopolys.gegenbauer_poly sympy.polys.orthopolys.chebyshevt_poly sympy.polys.orthopolys.chebyshevu_poly sympy.polys.orthopolys.hermite_poly sympy.polys.orthopolys.hermite_prob_poly sympy.polys.orthopolys.legendre_poly sympy.polys.orthopolys.laguerre_poly References ========== .. [1] https://en.wikipedia.org/wiki/Laguerre_polynomial#Generalized_Laguerre_polynomials .. [2] https://mathworld.wolfram.com/AssociatedLaguerrePolynomial.html .. [3] https://functions.wolfram.com/Polynomials/LaguerreL/ .. [4] https://functions.wolfram.com/Polynomials/LaguerreL3/ c|jr t||S|js|jrt||z|S|tj ur)|dkDr$tj |ztj zS|tjur|dkDrtj Syy|jrtd|zt|||S)Nrr) r?rrDrrrHrFrrZrJr)r%r&alphars r'rMzassoc_laguerre.evalos ==Aq> !{{yyE 511ajjQU}}a'!**44a(((QUzz!.3(}} FJLL%Q511r)cddlm}|dk(r t|||dk(r;|j\}}}t d}|t |||||z z |d|dz fS|dk(r$|j\}}}t |dz |dz| St||)NrrOr+r;rQr<)rSrPrr-rr)r/rTrPr&rrrQs r'rWzassoc_laguerre.fdiffs1 q=$T84 4 ]))KAuac A~a2a%i@1aQ-P P ]))KAua"1q5%!)Q77 7$T84 4r)c $ddlm}|js|jdur t dt d}t | |t||zdzt|zz ||zz}t||zdzt|z |||d|fzS)NrrOFrYrQr+) rSrPrZrrJrr rr )r/r&rrr[rPrQr\s r'r]z#assoc_laguerre._eval_rewrite_as_Sums1 ==ALLE1IJ J #J BAIM*Yq\9;=>TBQY]#il2S1ay5IIIr)c ,|j|||fi|Sr_r`)r/r&rrr[s r'raz*assoc_laguerre._eval_rewrite_as_polynomials )t((E1???r)c|j\}}}|j||j|jSr_rc)r/r&rrs r'r0zassoc_laguerre._eval_conjugates1ii 5!yyEOO-q{{}==r)Nrurdr6r)r'rr(s3DL22*5"J@ >r)rN)5r4 sympy.corersympy.core.functionrrsympy.core.singletonrsympy.core.symbolr(sympy.functions.combinatorial.factorialsrr r $sympy.functions.elementary.complexesr &sympy.functions.elementary.exponentialr #sympy.functions.elementary.integersr (sympy.functions.elementary.miscellaneousr(sympy.functions.elementary.trigonometricrr'sympy.functions.special.gamma_functionsrsympy.functions.special.hyperrsympy.polys.orthopolysrrrrrrrrr"rr8rgrBr>rArrr@rCrrrrr6r)r'rs C"#YY3659=9/OOO 3Z A? A"dI !dINF.\R:%R:rs9%s9l{9%{9|&)o&)R&)o&)Zq9#q9hn:_n:jc7"c7L^5'^5Lk9#k9\>)>r)