Orthogonal polynomials¶
Chebyshev polynomials¶
The Chebyshev polynomial of the first kind arises as a solution to the differential equation
and those of the second kind as a solution to
The Chebyshev polynomials of the first kind are defined by the recurrence relation
The Chebyshev polynomials of the second kind are defined by the recurrence relation
For integers
and
They are named after Pafnuty Chebyshev (1821-1894, alternative transliterations: Tchebyshef or Tschebyscheff).
Hermite polynomials¶
The Hermite polynomials are defined either by
(the “probabilists’ Hermite polynomials”), or by
(the “physicists’ Hermite polynomials”). Sage (via Maxima) implements the latter flavor. These satisfy the orthogonality relation
They are named in honor of Charles Hermite (1822-1901), but were first introduced by Laplace in 1810 and also studied by Chebyshev in 1859.
Legendre polynomials¶
Each Legendre polynomial
These are solutions to Legendre’s differential equation:
and satisfy the orthogonality relation
The Legendre function of the second kind
The associated Legendre functions of the first kind
Assuming
where
The associated Legendre functions of the second kind
They are named after Adrien-Marie Legendre (1752-1833).
Laguerre polynomials¶
Laguerre polynomials may be defined by the Rodrigues formula
They are solutions of Laguerre’s equation:
and satisfy the orthogonality relation
The generalized Laguerre polynomials may be defined by the Rodrigues formula:
(These are also sometimes called the associated Laguerre
polynomials.) The simple Laguerre polynomials are recovered from
the generalized polynomials by setting
They are named after Edmond Laguerre (1834-1886).
Jacobi polynomials¶
Jacobi polynomials are a class of orthogonal polynomials. They are obtained from hypergeometric series in cases where the series is in fact finite:
where
They are named after Carl Gustav Jaboc Jacobi (1804-1851).
Gegenbauer polynomials¶
Ultraspherical or Gegenbauer polynomials are given in terms of
the Jacobi polynomials
They satisfy the orthogonality relation
for
where
They are named for Leopold Gegenbauer (1849-1903).
Krawtchouk polynomials¶
The Krawtchouk polynomials are discrete orthogonal polynomials that are given by the hypergeometric series
Since they are discrete orthogonal polynomials, they satisfy an orthogonality relation defined on a discrete (in this case finite) set of points:
where
where
They are named for Mykhailo Krawtchouk (1892-1942).
Meixner polynomials¶
The Meixner polynomials are discrete orthogonal polynomials that are given by the hypergeometric series
They satisfy an orthogonality relation:
where
where
They are named for Josef Meixner (1908-1994).
Hahn polynomials¶
The Hahn polynomials are discrete orthogonal polynomials that are given by the hypergeometric series
They satisfy an orthogonality relation:
where
They can also be described by the recurrence relation
where
They are named for Wolfgang Hahn (1911-1998), although they were first introduced by Chebyshev in 1875.
Pochhammer symbol¶
For completeness, the Pochhammer symbol, introduced by Leo August
Pochhammer,
On the other hand, the falling factorial or lower factorial is
in the notation of Ronald L. Graham, Donald E. Knuth and Oren Patashnik in their book Concrete Mathematics.
Todo
Implement Zernike polynomials. Wikipedia article Zernike_polynomials
REFERENCES:
Roelof Koekeok and René F. Swarttouw, arXiv math/9602214
AUTHORS:
David Joyner (2006-06)
Stefan Reiterer (2010-)
Ralf Stephan (2015-)
The original module wrapped some of the orthogonal/special functions in the Maxima package “orthopoly” and was written by Barton Willis of the University of Nebraska at Kearney.
- class sage.functions.orthogonal_polys.ChebyshevFunction(name, nargs=2, latex_name=None, conversions=None)[source]¶
Bases:
OrthogonalFunctionAbstract base class for Chebyshev polynomials of the first and second kind.
EXAMPLES:
sage: chebyshev_T(3, x) # needs sage.symbolic 4*x^3 - 3*x
- class sage.functions.orthogonal_polys.Func_assoc_legendre_P[source]¶
Bases:
BuiltinFunctionReturn the Ferrers function
of first kind for with general order and general degree .Ferrers functions of first kind are one of two linearly independent solutions of the associated Legendre differential equation
on the interval
and are usually denoted by .See also
The other linearly independent solution is called Ferrers function of second kind and denoted by
, seeFunc_assoc_legendre_Q.Warning
Ferrers functions must be carefully distinguished from associated Legendre functions which are defined on
and have not yet been implemented.EXAMPLES:
We give the first Ferrers functions for nonnegative integers
and in the interval :sage: for n in range(4): # needs sage.symbolic ....: for m in range(n+1): ....: print(f"P_{n}^{m}({x}) = {gen_legendre_P(n, m, x)}") P_0^0(x) = 1 P_1^0(x) = x P_1^1(x) = -sqrt(-x^2 + 1) P_2^0(x) = 3/2*x^2 - 1/2 P_2^1(x) = -3*sqrt(-x^2 + 1)*x P_2^2(x) = -3*x^2 + 3 P_3^0(x) = 5/2*x^3 - 3/2*x P_3^1(x) = -3/2*(5*x^2 - 1)*sqrt(-x^2 + 1) P_3^2(x) = -15*(x^2 - 1)*x P_3^3(x) = -15*(-x^2 + 1)^(3/2)
These expressions for nonnegative integers are computed by the Rodrigues-type given in
eval_gen_poly(). Negative values for are obtained by the following identity:For
being a nonnegative integer, negative values for are obtained bywhere
.Here are some specific values with negative integers:
sage: # needs sage.symbolic sage: gen_legendre_P(-2, -1, x) 1/2*sqrt(-x^2 + 1) sage: gen_legendre_P(2, -2, x) -1/8*x^2 + 1/8 sage: gen_legendre_P(3, -2, x) -1/8*(x^2 - 1)*x sage: gen_legendre_P(1, -2, x) 0
Here are some other random values with floating numbers:
sage: # needs sage.symbolic sage: m = var('m'); assume(m, 'integer') sage: gen_legendre_P(m, m, .2) 0.960000000000000^(1/2*m)*(-1)^m*factorial(2*m)/(2^m*factorial(m)) sage: gen_legendre_P(.2, m, 0) sqrt(pi)*2^m/(gamma(-1/2*m + 1.10000000000000)*gamma(-1/2*m + 0.400000000000000)) sage: gen_legendre_P(.2, .2, .2) 0.757714892929573
REFERENCES:
- eval_gen_poly(n, m, arg, **kwds)[source]¶
Return the Ferrers function of first kind
for integers given by the following Rodrigues-type formula:INPUT:
n– integer degreem– integer orderx– either an integer or a non-numerical symbolic expression
EXAMPLES:
sage: gen_legendre_P(7, 4, x) # needs sage.symbolic 3465/2*(13*x^3 - 3*x)*(x^2 - 1)^2 sage: gen_legendre_P(3, 1, sqrt(x)) # needs sage.symbolic -3/2*(5*x - 1)*sqrt(-x + 1)
REFERENCE:
[DLMF-Legendre], Section 14.7 eq. 10 (https://dlmf.nist.gov/14.7#E10)
- class sage.functions.orthogonal_polys.Func_assoc_legendre_Q[source]¶
Bases:
BuiltinFunctionEXAMPLES:
sage: loads(dumps(gen_legendre_Q)) gen_legendre_Q sage: maxima(gen_legendre_Q(2, 1, 3, hold=True))._sage_().simplify_full() # needs sage.symbolic 1/4*sqrt(2)*(36*pi - 36*I*log(2) + 25*I)
- eval_recursive(n, m, x, **kwds)[source]¶
Return the associated Legendre Q(n, m, arg) function for integers
.EXAMPLES:
sage: # needs sage.symbolic sage: gen_legendre_Q(3, 4, x) 48/(x^2 - 1)^2 sage: gen_legendre_Q(4, 5, x) -384/((x^2 - 1)^2*sqrt(-x^2 + 1)) sage: gen_legendre_Q(0, 1, x) -1/sqrt(-x^2 + 1) sage: gen_legendre_Q(0, 2, x) -1/2*((x + 1)^2 - (x - 1)^2)/(x^2 - 1) sage: gen_legendre_Q(2, 2, x).subs(x=2).expand() 9/2*I*pi - 9/2*log(3) + 14/3
- class sage.functions.orthogonal_polys.Func_chebyshev_T[source]¶
Bases:
ChebyshevFunctionChebyshev polynomials of the first kind.
REFERENCE:
[AS1964] 22.5.31 page 778 and 6.1.22 page 256.
EXAMPLES:
sage: chebyshev_T(5, x) # needs sage.symbolic 16*x^5 - 20*x^3 + 5*x sage: var('k') # needs sage.symbolic k sage: test = chebyshev_T(k, x); test # needs sage.symbolic chebyshev_T(k, x)
- eval_algebraic(n, x)[source]¶
Evaluate
chebyshev_Tas polynomial, using a recursive formula.INPUT:
n– integerx– a value to evaluate the polynomial at (this can be any ring element)
EXAMPLES:
sage: chebyshev_T.eval_algebraic(5, x) # needs sage.symbolic 2*(2*(2*x^2 - 1)*x - x)*(2*x^2 - 1) - x sage: chebyshev_T(-7, x) - chebyshev_T(7, x) # needs sage.symbolic 0 sage: R.<t> = ZZ[] sage: chebyshev_T.eval_algebraic(-1, t) t sage: chebyshev_T.eval_algebraic(0, t) 1 sage: chebyshev_T.eval_algebraic(1, t) t sage: chebyshev_T(7^100, 1/2) 1/2 sage: chebyshev_T(7^100, Mod(2,3)) 2 sage: n = 97; x = RIF(pi/2/n) # needs sage.symbolic sage: chebyshev_T(n, cos(x)).contains_zero() # needs sage.symbolic True sage: # needs sage.rings.padics sage: R.<t> = Zp(2, 8, 'capped-abs')[] sage: chebyshev_T(10^6 + 1, t) (2^7 + O(2^8))*t^5 + O(2^8)*t^4 + (2^6 + O(2^8))*t^3 + O(2^8)*t^2 + (1 + 2^6 + O(2^8))*t + O(2^8)
- eval_formula(n, x)[source]¶
Evaluate
chebyshev_Tusing an explicit formula. See [AS1964] 227 (p. 782) for details for the recursions. See also [Koe1999] for fast evaluation techniques.INPUT:
n– integerx– a value to evaluate the polynomial at (this can be any ring element)
EXAMPLES:
sage: # needs sage.symbolic sage: chebyshev_T.eval_formula(-1, x) x sage: chebyshev_T.eval_formula(0, x) 1 sage: chebyshev_T.eval_formula(1, x) x sage: chebyshev_T.eval_formula(10, x) 512*x^10 - 1280*x^8 + 1120*x^6 - 400*x^4 + 50*x^2 - 1 sage: chebyshev_T.eval_algebraic(10, x).expand() 512*x^10 - 1280*x^8 + 1120*x^6 - 400*x^4 + 50*x^2 - 1 sage: chebyshev_T.eval_formula(2, 0.1) == chebyshev_T._evalf_(2, 0.1) # needs sage.rings.complex_double True
- class sage.functions.orthogonal_polys.Func_chebyshev_U[source]¶
Bases:
ChebyshevFunctionClass for the Chebyshev polynomial of the second kind.
REFERENCE:
[AS1964] 22.8.3 page 783 and 6.1.22 page 256.
EXAMPLES:
sage: R.<t> = QQ[] sage: chebyshev_U(2, t) 4*t^2 - 1 sage: chebyshev_U(3, t) 8*t^3 - 4*t
- eval_algebraic(n, x)[source]¶
Evaluate
chebyshev_Uas polynomial, using a recursive formula.INPUT:
n– integerx– a value to evaluate the polynomial at (this can be any ring element)
EXAMPLES:
sage: chebyshev_U.eval_algebraic(5, x) # needs sage.symbolic -2*((2*x + 1)*(2*x - 1)*x - 4*(2*x^2 - 1)*x)*(2*x + 1)*(2*x - 1) sage: parent(chebyshev_U(3, Mod(8,9))) Ring of integers modulo 9 sage: parent(chebyshev_U(3, Mod(1,9))) Ring of integers modulo 9 sage: chebyshev_U(-3, x) + chebyshev_U(1, x) # needs sage.symbolic 0 sage: chebyshev_U(-1, Mod(5,8)) 0 sage: parent(chebyshev_U(-1, Mod(5,8))) Ring of integers modulo 8 sage: R.<t> = ZZ[] sage: chebyshev_U.eval_algebraic(-2, t) -1 sage: chebyshev_U.eval_algebraic(-1, t) 0 sage: chebyshev_U.eval_algebraic(0, t) 1 sage: chebyshev_U.eval_algebraic(1, t) 2*t sage: n = 97; x = RIF(pi/n) # needs sage.symbolic sage: chebyshev_U(n - 1, cos(x)).contains_zero() # needs sage.symbolic True sage: # needs sage.rings.padics sage: R.<t> = Zp(2, 6, 'capped-abs')[] sage: chebyshev_U(10^6 + 1, t) (2 + O(2^6))*t + O(2^6)
- eval_formula(n, x)[source]¶
Evaluate
chebyshev_Uusing an explicit formula.See [AS1964] 227 (p. 782) for details on the recursions. See also [Koe1999] for the recursion formulas.
INPUT:
n– integerx– a value to evaluate the polynomial at (this can be any ring element)
EXAMPLES:
sage: # needs sage.symbolic sage: chebyshev_U.eval_formula(10, x) 1024*x^10 - 2304*x^8 + 1792*x^6 - 560*x^4 + 60*x^2 - 1 sage: chebyshev_U.eval_formula(-2, x) -1 sage: chebyshev_U.eval_formula(-1, x) 0 sage: chebyshev_U.eval_formula(0, x) 1 sage: chebyshev_U.eval_formula(1, x) 2*x sage: chebyshev_U.eval_formula(2, 0.1) == chebyshev_U._evalf_(2, 0.1) True
- class sage.functions.orthogonal_polys.Func_gen_laguerre[source]¶
Bases:
OrthogonalFunctionREFERENCE:
[AS1964] 22.5.16, page 778 and page 789.
- class sage.functions.orthogonal_polys.Func_hahn[source]¶
Bases:
OrthogonalFunctionHahn polynomials
.INPUT:
k– the degreex– the independent variablea,b– the parameters ,n– the number of discrete points
EXAMPLES:
We verify the orthogonality for
:sage: # needs sage.symbolic sage: n = 2 sage: a, b = SR.var('a,b') sage: def rho(k, a, b, n): ....: return binomial(a + k, k) * binomial(b + n - k, n - k) sage: M = matrix([[sum(rho(k, a, b, n) ....: * hahn(i, k, a, b, n) * hahn(j, k, a, b, n) ....: for k in range(n + 1)).expand().factor() ....: for i in range(n+1)] for j in range(n+1)]) sage: M = M.factor() sage: P = rising_factorial sage: def diag(i, a, b, n): ....: return ((-1)^i * factorial(i) * P(b + 1, i) * P(i + a + b + 1, n + 1) ....: / (factorial(n) * (2*i + a + b + 1) * P(-n, i) * P(a + 1, i))) sage: all(M[i,i] == diag(i, a, b, n) for i in range(3)) True sage: all(M[i,j] == 0 for i in range(3) for j in range(3) if i != j) True
- eval_formula(k, x, a, b, n)[source]¶
Evaluate
selfusing an explicit formula.EXAMPLES:
sage: # needs sage.symbolic sage: k, x, a, b, n = var('k,x,a,b,n') sage: Q2 = hahn.eval_formula(2, x, a, b, n).simplify_full() sage: Q2.coefficient(x^2).factor() (a + b + 4)*(a + b + 3)/((a + 2)*(a + 1)*(n - 1)*n) sage: Q2.coefficient(x).factor() -(2*a*n - a + b + 4*n)*(a + b + 3)/((a + 2)*(a + 1)*(n - 1)*n) sage: Q2(x=0) 1
- eval_recursive(k, x, a, b, n, *args, **kwds)[source]¶
Return the Hahn polynomial
using the recursive formula.EXAMPLES:
sage: # needs sage.symbolic sage: x, a, b, n = var('x,a,b,n') sage: hahn.eval_recursive(0, x, a, b, n) 1 sage: hahn.eval_recursive(1, x, a, b, n) -(a + b + 2)*x/((a + 1)*n) + 1 sage: bool(hahn(2, x, a, b, n) == hahn.eval_recursive(2, x, a, b, n)) True sage: bool(hahn(3, x, a, b, n) == hahn.eval_recursive(3, x, a, b, n)) True sage: bool(hahn(4, x, a, b, n) == hahn.eval_recursive(4, x, a, b, n)) True sage: M = matrix([[-1/2, -1], [1, 0]]) # needs sage.modules sage: ret = hahn.eval_recursive(2, M, 1, 2, n).simplify_full().factor() # needs sage.modules sage: ret # needs sage.modules [1/4*(4*n^2 + 8*n - 19)/((n - 1)*n) 3/2*(4*n + 3)/((n - 1)*n)] [ -3/2*(4*n + 3)/((n - 1)*n) (n^2 - n - 7)/((n - 1)*n)]
- class sage.functions.orthogonal_polys.Func_hermite[source]¶
Bases:
GinacFunctionReturn the Hermite polynomial for integers
.REFERENCE:
[AS1964] 22.5.40 and 22.5.41, page 779.
EXAMPLES:
sage: # needs sage.symbolic sage: x = PolynomialRing(QQ, 'x').gen() sage: hermite(2, x) 4*x^2 - 2 sage: hermite(3, x) 8*x^3 - 12*x sage: hermite(3, 2) 40 sage: S.<y> = PolynomialRing(RR) sage: hermite(3, y) 8.00000000000000*y^3 - 12.0000000000000*y sage: R.<x,y> = QQ[] sage: hermite(3, y^2) 8*y^6 - 12*y^2 sage: w = var('w') sage: hermite(3, 2*w) 64*w^3 - 24*w sage: hermite(5, 3.1416) 5208.69733891963 sage: hermite(5, RealField(100)(pi)) 5208.6167627118104649470287166
Check that Issue #17192 is fixed:
sage: # needs sage.symbolic sage: x = PolynomialRing(QQ, 'x').gen() sage: hermite(0, x) 1 sage: hermite(-1, x) Traceback (most recent call last): ... RuntimeError: hermite_eval: The index n must be a nonnegative integer sage: hermite(-7, x) Traceback (most recent call last): ... RuntimeError: hermite_eval: The index n must be a nonnegative integer sage: m, x = SR.var('m,x') sage: hermite(m, x).diff(m) Traceback (most recent call last): ... RuntimeError: derivative w.r.t. to the index is not supported yet
- class sage.functions.orthogonal_polys.Func_jacobi_P[source]¶
Bases:
OrthogonalFunctionReturn the Jacobi polynomial
for integers and a and b symbolic or and .The Jacobi polynomials are actually defined for all
and . However, the Jacobi polynomial weight is not integrable for or .REFERENCE:
Table on page 789 in [AS1964].
EXAMPLES:
sage: x = PolynomialRing(QQ, 'x').gen() sage: jacobi_P(2, 0, 0, x) # needs sage.libs.flint sage.symbolic 3/2*x^2 - 1/2 sage: jacobi_P(2, 1, 2, 1.2) # needs sage.libs.flint 5.01000000000000
- class sage.functions.orthogonal_polys.Func_krawtchouk[source]¶
Bases:
OrthogonalFunctionKrawtchouk polynomials
.INPUT:
j– the degreex– the independent variablen– the number of discrete pointsp– the parameter
EXAMPLES:
We verify the orthogonality for
:sage: n = 4 sage: p = SR.var('p') # needs sage.symbolic sage: matrix([[sum(binomial(n,m) * p**m * (1-p)**(n-m) # needs sage.symbolic ....: * krawtchouk(i,m,n,p) * krawtchouk(j,m,n,p) ....: for m in range(n+1)).expand().factor() ....: for i in range(n+1)] for j in range(n+1)]) [ 1 0 0 0 0] [ 0 -4*(p - 1)*p 0 0 0] [ 0 0 6*(p - 1)^2*p^2 0 0] [ 0 0 0 -4*(p - 1)^3*p^3 0] [ 0 0 0 0 (p - 1)^4*p^4]
We verify the relationship between the Krawtchouk implementations:
sage: q = SR.var('q') # needs sage.symbolic sage: all(codes.bounds.krawtchouk(n, 1/q, j, x)*(-q)^j # needs sage.symbolic ....: == krawtchouk(j, x, n, 1-q) for j in range(n+1)) True
- eval_formula(k, x, n, p)[source]¶
Evaluate
selfusing an explicit formula.EXAMPLES:
sage: x, n, p = var('x,n,p') # needs sage.symbolic sage: krawtchouk.eval_formula(3, x, n, p).expand().collect(x) # needs sage.symbolic -1/6*n^3*p^3 + 1/2*n^2*p^3 - 1/3*n*p^3 - 1/2*(n*p - 2*p + 1)*x^2 + 1/6*x^3 + 1/6*(3*n^2*p^2 - 9*n*p^2 + 3*n*p + 6*p^2 - 6*p + 2)*x
- eval_recursive(j, x, n, p, *args, **kwds)[source]¶
Return the Krawtchouk polynomial
using the recursive formula.EXAMPLES:
sage: # needs sage.symbolic sage: x, n, p = var('x,n,p') sage: krawtchouk.eval_recursive(0, x, n, p) 1 sage: krawtchouk.eval_recursive(1, x, n, p) -n*p + x sage: krawtchouk.eval_recursive(2, x, n, p).collect(x) 1/2*n^2*p^2 + 1/2*n*(p - 1)*p - n*p^2 + 1/2*n*p - 1/2*(2*n*p - 2*p + 1)*x + 1/2*x^2 sage: bool(krawtchouk.eval_recursive(2, x, n, p) == krawtchouk(2, x, n, p)) True sage: bool(krawtchouk.eval_recursive(3, x, n, p) == krawtchouk(3, x, n, p)) True sage: bool(krawtchouk.eval_recursive(4, x, n, p) == krawtchouk(4, x, n, p)) True sage: M = matrix([[-1/2, -1], [1, 0]]) # needs sage.modules sage: krawtchouk.eval_recursive(2, M, 3, 1/2) # needs sage.modules [ 9/8 7/4] [-7/4 1/4]
- class sage.functions.orthogonal_polys.Func_laguerre[source]¶
Bases:
OrthogonalFunctionREFERENCE:
[AS1964] 22.5.16, page 778 and page 789.
- class sage.functions.orthogonal_polys.Func_legendre_P[source]¶
Bases:
GinacFunctionEXAMPLES:
sage: # needs sage.symbolic sage: legendre_P(4, 2.0) 55.3750000000000 sage: legendre_P(1, x) x sage: legendre_P(4, x + 1) 35/8*(x + 1)^4 - 15/4*(x + 1)^2 + 3/8 sage: legendre_P(1/2, I+1.) 1.05338240025858 + 0.359890322109665*I sage: legendre_P(0, SR(1)).parent() Symbolic Ring sage: legendre_P(0, 0) # needs sage.symbolic 1 sage: legendre_P(1, x) # needs sage.symbolic x sage: # needs sage.symbolic sage: legendre_P(4, 2.) 55.3750000000000 sage: legendre_P(5.5, 1.00001) 1.00017875754114 sage: legendre_P(1/2, I + 1).n() 1.05338240025858 + 0.359890322109665*I sage: legendre_P(1/2, I + 1).n(59) 1.0533824002585801 + 0.35989032210966539*I sage: legendre_P(42, RR(12345678)) 2.66314881466753e309 sage: legendre_P(42, Reals(20)(12345678)) 2.6632e309 sage: legendre_P(201/2, 0).n() 0.0561386178630179 sage: legendre_P(201/2, 0).n(100) 0.056138617863017877699963095883 sage: # needs sage.symbolic sage: R.<x> = QQ[] sage: legendre_P(4, x) 35/8*x^4 - 15/4*x^2 + 3/8 sage: legendre_P(10000, x).coefficient(x, 1) 0 sage: var('t,x') (t, x) sage: legendre_P(-5, t) 35/8*t^4 - 15/4*t^2 + 3/8 sage: legendre_P(4, x + 1) 35/8*(x + 1)^4 - 15/4*(x + 1)^2 + 3/8 sage: legendre_P(4, sqrt(2)) 83/8 sage: legendre_P(4, I*e) 35/8*e^4 + 15/4*e^2 + 3/8 sage: # needs sage.symbolic sage: n = var('n') sage: derivative(legendre_P(n,x), x) (n*x*legendre_P(n, x) - n*legendre_P(n - 1, x))/(x^2 - 1) sage: derivative(legendre_P(3,x), x) 15/2*x^2 - 3/2 sage: derivative(legendre_P(n,x), n) Traceback (most recent call last): ... RuntimeError: derivative w.r.t. to the index is not supported yet
- class sage.functions.orthogonal_polys.Func_legendre_Q[source]¶
Bases:
BuiltinFunctionEXAMPLES:
sage: loads(dumps(legendre_Q)) legendre_Q sage: maxima(legendre_Q(20, x, hold=True))._sage_().coefficient(x, 10) # needs sage.symbolic -29113619535/131072*log(-(x + 1)/(x - 1))
- eval_formula(n, arg, **kwds)[source]¶
Return expanded Legendre
Q(n, arg)function expression.REFERENCE:
Dunster, Legendre and Related Functions, https://dlmf.nist.gov/14.7#E2
EXAMPLES:
sage: # needs sage.symbolic sage: legendre_Q.eval_formula(1, x) 1/2*x*(log(x + 1) - log(-x + 1)) - 1 sage: legendre_Q.eval_formula(2, x).expand().collect(log(1+x)).collect(log(1-x)) 1/4*(3*x^2 - 1)*log(x + 1) - 1/4*(3*x^2 - 1)*log(-x + 1) - 3/2*x sage: legendre_Q.eval_formula(20, x).coefficient(x, 10) -29113619535/131072*log(x + 1) + 29113619535/131072*log(-x + 1) sage: legendre_Q(0, 2) -1/2*I*pi + 1/2*log(3) sage: legendre_Q(0, 2.) # needs mpmath 0.549306144334055 - 1.57079632679490*I
- eval_recursive(n, arg, **kwds)[source]¶
Return expanded Legendre Q(n, arg) function expression.
EXAMPLES:
sage: legendre_Q.eval_recursive(2, x) # needs sage.symbolic 3/4*x^2*(log(x + 1) - log(-x + 1)) - 3/2*x - 1/4*log(x + 1) + 1/4*log(-x + 1) sage: legendre_Q.eval_recursive(20, x).expand().coefficient(x, 10) # needs sage.symbolic -29113619535/131072*log(x + 1) + 29113619535/131072*log(-x + 1)
- class sage.functions.orthogonal_polys.Func_meixner[source]¶
Bases:
OrthogonalFunctionMeixner polynomials
.INPUT:
n– the degreex– the independent variableb,c– the parameters ,
- eval_formula(n, x, b, c)[source]¶
Evaluate
selfusing an explicit formula.EXAMPLES:
sage: x, b, c = var('x,b,c') # needs sage.symbolic sage: meixner.eval_formula(3, x, b, c).expand().collect(x) # needs sage.symbolic -x^3*(3/c - 3/c^2 + 1/c^3 - 1) + b^3 + 3*(b - 2*b/c + b/c^2 - 1/c - 1/c^2 + 1/c^3 + 1)*x^2 + 3*b^2 + (3*b^2 + 6*b - 3*b^2/c - 3*b/c - 3*b/c^2 - 2/c^3 + 2)*x + 2*b
- eval_recursive(n, x, b, c, *args, **kwds)[source]¶
Return the Meixner polynomial
using the recursive formula.EXAMPLES:
sage: # needs sage.symbolic sage: x, b, c = var('x,b,c') sage: meixner.eval_recursive(0, x, b, c) 1 sage: meixner.eval_recursive(1, x, b, c) -x*(1/c - 1) + b sage: meixner.eval_recursive(2, x, b, c).simplify_full().collect(x) -x^2*(2/c - 1/c^2 - 1) + b^2 + (2*b - 2*b/c - 1/c^2 + 1)*x + b sage: bool(meixner(2, x, b, c) == meixner.eval_recursive(2, x, b, c)) True sage: bool(meixner(3, x, b, c) == meixner.eval_recursive(3, x, b, c)) True sage: bool(meixner(4, x, b, c) == meixner.eval_recursive(4, x, b, c)) True sage: M = matrix([[-1/2, -1], [1, 0]]) sage: ret = meixner.eval_recursive(2, M, b, c).simplify_full().factor() sage: for i in range(2): # make the output polynomials in 1/c ....: for j in range(2): ....: ret[i, j] = ret[i, j].collect(c) sage: ret [b^2 + 1/2*(2*b + 3)/c - 1/4/c^2 - 5/4 -2*b + (2*b - 1)/c + 3/2/c^2 - 1/2] [ 2*b - (2*b - 1)/c - 3/2/c^2 + 1/2 b^2 + b + 2/c - 1/c^2 - 1]
- class sage.functions.orthogonal_polys.Func_ultraspherical[source]¶
Bases:
GinacFunctionReturn the ultraspherical (or Gegenbauer) polynomial
gegenbauer(n,a,x),When
is a nonnegative integer, this formula gives a polynomial in of degree , but all parameters are permitted to be complex numbers. When , the Gegenbauer polynomial reduces to a Legendre polynomial.Computed using Pynac.
For numerical evaluation, consider using the mpmath library, as it also allows complex numbers (and negative
as well); see the examples below.REFERENCE:
[AS1964] 22.5.27
EXAMPLES:
sage: # needs sage.symbolic sage: ultraspherical(8, 101/11, x) 795972057547264/214358881*x^8 - 62604543852032/19487171*x^6... sage: x = PolynomialRing(QQ, 'x').gen() sage: ultraspherical(2, 3/2, x) 15/2*x^2 - 3/2 sage: ultraspherical(1, 1, x) 2*x sage: t = PolynomialRing(RationalField(), "t").gen() sage: gegenbauer(3, 2, t) 32*t^3 - 12*t sage: x = SR.var('x') sage: n = ZZ.random_element(5, 5001) sage: a = QQ.random_element().abs() + 5 sage: s = ( (n + 1)*ultraspherical(n + 1, a, x) ....: - 2*x*(n + a)*ultraspherical(n, a, x) ....: + (n + 2*a - 1)*ultraspherical(n - 1, a, x) ) sage: s.expand().is_zero() True sage: ultraspherical(5, 9/10, 3.1416) 6949.55439044240 sage: ultraspherical(5, 9/10, RealField(100)(pi)) # needs sage.rings.real_mpfr 6949.4695419382702451843080687 sage: # needs sage.symbolic sage: a, n = SR.var('a,n') sage: gegenbauer(2, a, x) 2*(a + 1)*a*x^2 - a sage: gegenbauer(3, a, x) 4/3*(a + 2)*(a + 1)*a*x^3 - 2*(a + 1)*a*x sage: gegenbauer(3, a, x).expand() 4/3*a^3*x^3 + 4*a^2*x^3 + 8/3*a*x^3 - 2*a^2*x - 2*a*x sage: gegenbauer(10, a, x).expand().coefficient(x, 2) 1/12*a^6 + 5/4*a^5 + 85/12*a^4 + 75/4*a^3 + 137/6*a^2 + 10*a sage: ex = gegenbauer(100, a, x) sage: (ex.subs(a==55/98) - gegenbauer(100, 55/98, x)).is_trivial_zero() True sage: # needs sage.symbolic sage: gegenbauer(2, -3, x) 12*x^2 + 3 sage: gegenbauer(120, -99/2, 3) 1654502372608570682112687530178328494861923493372493824 sage: gegenbauer(5, 9/2, x) 21879/8*x^5 - 6435/4*x^3 + 1287/8*x sage: gegenbauer(15, 3/2, 5) 3903412392243800 sage: derivative(gegenbauer(n, a, x), x) # needs sage.symbolic 2*a*gegenbauer(n - 1, a + 1, x) sage: derivative(gegenbauer(3, a, x), x) # needs sage.symbolic 4*(a + 2)*(a + 1)*a*x^2 - 2*(a + 1)*a sage: derivative(gegenbauer(n, a, x), a) # needs sage.symbolic Traceback (most recent call last): ... RuntimeError: derivative w.r.t. to the second index is not supported yet
Numerical evaluation with the mpmath library:
sage: # needs mpmath sage: from mpmath import gegenbauer as gegenbauer_mp sage: from mpmath import mp sage: print(gegenbauer_mp(-7,0.5,0.3)) 0.1291811875 sage: with mp.workdps(25): ....: print(gegenbauer_mp(2+3j, -0.75, -1000j)) (-5038991.358609026523401901 + 9414549.285447104177860806j)
- class sage.functions.orthogonal_polys.OrthogonalFunction(name, nargs=2, latex_name=None, conversions=None)[source]¶
Bases:
BuiltinFunctionBase class for orthogonal polynomials.
This class is an abstract base class for all orthogonal polynomials since they share similar properties. The evaluation as a polynomial is either done via maxima, or with pynac.
Convention: The first argument is always the order of the polynomial, the others are other values or parameters where the polynomial is evaluated.
- eval_formula(*args)[source]¶
Evaluate this polynomial using an explicit formula.
EXAMPLES:
sage: from sage.functions.orthogonal_polys import OrthogonalFunction sage: P = OrthogonalFunction('testo_P') sage: P.eval_formula(1, 2.0) Traceback (most recent call last): ... NotImplementedError: no explicit calculation of values implemented