Package: orthopy
All about orthogonal polynomials.orthopy provides various orthogonal polynomial classes forlines,triangles,disks,spheres,n-cubes,the nD space with weight function exp(-r2)and more.
All computations are done using numerically stable recurrence schemes. Furthermore, all
functions are fully vectorized and can return results inexact arithmetic.InstallationInstall orthopyfrom PyPIwithpip install orthopyHow to get a licenseLicenses for personal and academic use can be purchasedhere.
You'll receive a confirmation email with a license key.
Install the key withplm add <your-license-key>on your machine and you're good to go.For commercial use, please contactsupport@mondaytech.com.Basic usageThe main function of all submodules is the iteratorEvalwhich evaluates the series of
orthogonal polynomials with increasing degree at given points using a recurrence
relation, e.g.,importorthopyx=0.5evaluator=orthopy.c1.legendre.Eval(x,"classical")for_inrange(5):print(next(evaluator))1.0# P_0(0.5)0.5# P_1(0.5)-0.125# P_2(0.5)-0.4375# P_3(0.5)-0.2890625# P_4(0.5)Other ways of getting the firstnitems areevaluator=Eval(x,"normal")vals=[next(evaluator)for_inrange(n)]importitertoolsvals=list(itertools.islice(Eval(x,"normal"),n))Instead of evaluating at only one point, you can provide any array forx; the
polynomials will then be evaluated for all points at once. You can also use sympy for
symbolic computation:importitertoolsimportorthopyimportsympyx=sympy.Symbol("x")evaluator=orthopy.c1.legendre.Eval(x,"classical")forvalinitertools.islice(evaluator,5):print(sympy.expand(val))1
x
3*x**2/2 - 1/2
5*x**3/2 - 3*x/2
35*x**4/8 - 15*x**2/4 + 3/8AllEvalmethods have ascalingargument which can have three values:"monic": The leading coefficient is 1."classical": The maximum value is 1 (or (n+alpha over n))."normal": The integral of the squared function over the domain is 1.For univariate ("one-dimensional") integrals, every new iteration contains one function.
For bivariate ("two-dimensional") domains, every level will contain one function more
than the previous, and similarly for multivariate families. See the tree plots below.Line segment (-1, +1) with weight function (1-x)α(1+x)βLegendreChebyshev 1Chebyshev 2Jacobi, Gegenbauer (α=β), Chebyshev 1 (α=β=-1/2), Chebyshev 2 (α=β=1/2), Legendre
(α=β=0) polynomials.importorthopyorthopy.c1.legendre.Eval(x,"normal")orthopy.c1.chebyshev1.Eval(x,"normal")orthopy.c1.chebyshev2.Eval(x,"normal")orthopy.c1.gegenbauer.Eval(x,"normal",lmbda)orthopy.c1.jacobi.Eval(x,"normal",alpha,beta)The plots above are generated withimportorthopyorthopy.c1.jacobi.show(5,"normal",0.0,0.0)# plot, savefig also existRecurrence coefficients can be explicitly retrieved byimportorthopyrc=orthopy.c1.jacobi.RecurrenceCoefficients("monic",# or "classical", "normal"alpha=0,beta=0,symbolic=True)print(rc.p0)forkinrange(5):print(rc[k])1
(1, 0, None)
(1, 0, 1/3)
(1, 0, 4/15)
(1, 0, 9/35)
(1, 0, 16/63)1D half-space with weight function xαexp(-r)(Generalized) Laguerre polynomials.evaluator=orthopy.e1r.Eval(x,alpha=0,scaling="normal")1D space with weight function exp(-r2)Hermite polynomials come in two standardizations:"physicists"(against the weight functionexp(-x ** 2)"probabilists"(against the weight function1 / sqrt(2 * pi) * exp(-x ** 2 / 2)evaluator=orthopy.e1r2.Eval(x,"probabilists",# or "physicists""normal")Associated Legendre "polynomials"Not all of those are polynomials, so they should really be called associated Legendrefunctions. Thekth iteration contains2k+1functions, indexed from-ktok. (See the color grouping in the above plot.)evaluator=orthopy.c1.associated_legendre.Eval(x,phi=None,standardization="natural",with_condon_shortley_phase=True)Triangle (T2)orthopy's triangle orthogonal polynomials are evaluated in terms ofbarycentric
coordinates, so theX.shape[0]has to be 3.importorthopybary=[0.1,0.7,0.2]evaluator=orthopy.t2.Eval(bary,"normal")Disk (S2)XuZernikeZernike 2orthopy contains several families of orthogonal polynomials on the unit disk: AfterXu,Zernike, and a simplified version
of Zernike polynomials.importorthopyx=[0.1,-0.3]evaluator=orthopy.s2.xu.Eval(x,"normal")# evaluator = orthopy.s2.zernike.Eval(x, "normal")# evaluator = orthopy.s2.zernike2.Eval(x, "normal")Sphere (U3)Complex-valuedspherical harmonics,(black=zero, green=real positive,
pink=real negative, blue=imaginary positive, yellow=imaginary negative). The
functions in the middle are real-valued. The complex angle takesnturns on
thenth level.evaluator=orthopy.u3.EvalCartesian(x,scaling="quantum mechanic"# or "acoustic", "geodetic", "schmidt")evaluator=orthopy.u3.EvalSpherical(theta_phi,# polar, azimuthal anglesscaling="quantum mechanic"# or "acoustic", "geodetic", "schmidt")n-Cube (Cn)C1(Legendre)C2C3Jacobi product polynomials.
All polynomials are normalized on the n-dimensional cube. The dimensionality is
determined byX.shape[0].evaluator=orthopy.cn.Eval(X,alpha=0,beta=0)values,degrees=next(evaluator)nD space with weight function exp(-r2) (Enr2)E1r2E2r2E3r2Hermite product polynomials.
All polynomials are normalized over the measure. The dimensionality is determined byX.shape[0].evaluator=orthopy.enr2.Eval(x,standardization="probabilists"# or "physicists")values,degrees=next(evaluator)Other toolsGenerating recurrence coefficients for 1D domains withStieltjes,Golub-Welsch,Chebyshev, andmodified
Chebyshev.The the sanity of recurrence coefficients with test 3 fromGautschi's article:
computing the weighted sum of orthogonal polynomials:orthopy.tools.gautschi_test_3(moments,alpha,beta)Clenshaw algorithmfor
computing the weighted sum of orthogonal polynomials:vals=orthopy.c1.clenshaw(a,alpha,beta,t)Relevant publicationsRobert C. Kirby, Singularity-free evaluation of collapsed-coordinate orthogonal polynomials, ACM Transactions on Mathematical Software (TOMS), Volume 37, Issue 1, January 2010Abedallah Rababah, Recurrence Relations for Orthogonal Polynomials on Triangular Domains, MDPI Mathematics 2016, 4(2)Yuan Xu, Orthogonal polynomials of several variables, arxiv.org, January 2017