Skip to content

Commit 7f316a3

Browse files
committed
Support Legendre and Hermite
1 parent 4e13ae1 commit 7f316a3

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module ClassicalOrthogonalPolynomialsMutableArithmeticsExt
22
using ClassicalOrthogonalPolynomials, MutableArithmetics
3-
using ClassicalOrthogonalPolynomials: initiateforwardrecurrence, recurrencecoefficients, _p0
3+
import ClassicalOrthogonalPolynomials: initiateforwardrecurrence, recurrencecoefficients, _p0
44

55
Base.unsafe_getindex(P::OrthogonalPolynomial, x::AbstractMutable, n::Number) = initiateforwardrecurrence(n-1, recurrencecoefficients(P)..., x, _p0(P))[end]
66

7+
recurrencecoefficients(::Legendre{T}) where T<:AbstractMutable = recurrencecoefficients(Legendre())
78
end

src/classical/hermite.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ axes(::Hermite{T}) where T = (Inclusion{T}(ℝ), oneto(∞))
4646
computes the `n`-th Hermite polynomial, orthogonal with
4747
respec to `exp(-x^2)`, at `z`.
4848
"""
49-
hermiteh(n::Integer, z::Number) = Base.unsafe_getindex(Hermite{typeof(z)}(), z, n+1)
49+
hermiteh(n::Integer, z) = Base.unsafe_getindex(Hermite{typeof(z)}(), z, n+1)
5050

5151
broadcasted(::LazyQuasiArrayStyle{2}, ::typeof(*), ::HermiteWeight{T}, ::Hermite{V}) where {T,V} = Weighted(Hermite{promote_type(T,V)}())
5252

5353
# H_{n+1} = 2x H_n - 2n H_{n-1}
5454
# 1/2 * H_{n+1} + n H_{n-1} = x H_n
5555
# x*[H_0 H_1 H_2 …] = [H_0 H_1 H_2 …] * [0 1; 1/2 0 2; 1/2 0 3; …]
5656
jacobimatrix(H::Hermite{T}) where T = Tridiagonal(Fill(one(T)/2,∞), Zeros{T}(∞), one(T):∞)
57-
recurrencecoefficients(H::Hermite{T}) where T = Fill{T}(2,∞), Zeros{T}(∞), zero(T):2:
57+
recurrencecoefficients(H::Hermite) where T = Fill(2,∞), Zeros{Int}(∞), 0:2:
5858

5959
weightedgrammatrix(::Hermite{T}) where T = Diagonal(sqrt(convert(T,π)) .* convert(T,2) .^ (0:∞) .* gamma.(one(T):∞))
6060

src/classical/jacobi.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ basis_singularities(w::JacobiWeight) = Weighted(Jacobi(w.a, w.b))
119119
computes the `n`-th Jacobi polynomial, orthogonal with
120120
respec to `(1-x)^a*(1+x)^b`, at `z`.
121121
"""
122-
jacobip(n::Integer, a, b, z::Number) = Base.unsafe_getindex(Jacobi{promote_type(typeof(a), typeof(b), typeof(z))}(a,b), z, n+1)
123-
normalizedjacobip(n::Integer, a, b, z::Number) = Base.unsafe_getindex(Normalized(Jacobi{promote_type(typeof(a), typeof(b), typeof(z))}(a,b)), z, n+1)
122+
jacobip(n::Integer, a, b, z) = Base.unsafe_getindex(Jacobi{promote_type(typeof(a), typeof(b), typeof(z))}(a,b), z, n+1)
123+
normalizedjacobip(n::Integer, a, b, z) = Base.unsafe_getindex(Normalized(Jacobi{promote_type(typeof(a), typeof(b), typeof(z))}(a,b)), z, n+1)
124124

125125
OrthogonalPolynomial(w::JacobiWeight) = Jacobi(w.a, w.b)
126126
orthogonalityweight(P::Jacobi) = JacobiWeight(P.a, P.b)

src/classical/ultraspherical.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const WeightedUltraspherical{T} = WeightedBasis{T,<:UltrasphericalWeight,<:Ultra
5454

5555
orthogonalityweight(C::Ultraspherical) = UltrasphericalWeight(C.λ)
5656

57-
ultrasphericalc(n::Integer, λ, z::Number) = Base.unsafe_getindex(Ultraspherical{promote_type(typeof(λ),typeof(z))}(λ), z, n+1)
57+
ultrasphericalc(n::Integer, λ, z) = Base.unsafe_getindex(Ultraspherical{promote_type(typeof(λ),typeof(z))}(λ), z, n+1)
5858
ultraspherical(λ, d::AbstractInterval{T}) where T = Ultraspherical{float(promote_type(eltype(λ),T))}(λ)[affine(d,ChebyshevInterval{T}()), :]
5959

6060
==(a::Ultraspherical, b::Ultraspherical) = a.λ == b.λ

test/test_dynamicpolynomials.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ using DynamicPolynomials, ClassicalOrthogonalPolynomials, Test
66
@test chebyshevt(0,x) == 1
77
@test chebyshevt(1,x) == x
88
@test chebyshevt(5,x) == 5x - 20x^3 + 16x^5
9-
@test chebyshevu(5,x) == 6x - 32x^3 + 32x^5
10-
legendrep(5,x)
9+
@test chebyshevu(5,x) == ultrasphericalc(5,1,x) == 6x - 32x^3 + 32x^5
10+
@test legendrep(5,x) (15x - 70x^3 + 63x^5)/8
11+
@test hermiteh(5,x) == 120x - 160x^3 + 32x^5
1112
end

0 commit comments

Comments
 (0)