Skip to content

Commit 9d02cab

Browse files
authored
Support DynamicPolynomials.jl (#214)
* Support DynamicPolynomials.jl * Support Legendre and Hermite * Update hermite.jl
1 parent 50a37b4 commit 9d02cab

9 files changed

+42
-11
lines changed

Project.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ClassicalOrthogonalPolynomials"
22
uuid = "b30e2e7b-c4ee-47da-9d5f-2c5c27239acd"
33
authors = ["Sheehan Olver <solver@mac.com>"]
4-
version = "0.13.7"
4+
version = "0.13.8"
55

66
[deps]
77
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -26,13 +26,20 @@ RecurrenceRelationships = "807425ed-42ea-44d6-a357-6771516d7b2c"
2626
RecurrenceRelationshipArrays = "b889d2dc-af3c-4820-88a8-238fa91d3518"
2727
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
2828

29+
[weakdeps]
30+
MutableArithmetics = "d8a4904e-b15c-11e9-3269-09a3773c0cb0"
31+
32+
[extensions]
33+
ClassicalOrthogonalPolynomialsMutableArithmeticsExt = "MutableArithmetics"
34+
2935
[compat]
3036
ArrayLayouts = "1.3.1"
3137
BandedMatrices = "1"
3238
BlockArrays = "1"
3339
BlockBandedMatrices = "0.13"
3440
ContinuumArrays = "0.18.3"
3541
DomainSets = "0.6, 0.7"
42+
DynamicPolynomials = "0.6"
3643
FFTW = "1.1"
3744
FastGaussQuadrature = "1"
3845
FastTransforms = "0.16.6"
@@ -43,6 +50,7 @@ InfiniteLinearAlgebra = "0.8"
4350
IntervalSets = "0.7"
4451
LazyArrays = "2.2"
4552
LazyBandedMatrices = "0.10"
53+
MutableArithmetics = "1"
4654
QuasiArrays = "0.11"
4755
RecurrenceRelationships = "0.1"
4856
RecurrenceRelationshipArrays = "0.1"
@@ -51,11 +59,12 @@ julia = "1.10"
5159

5260
[extras]
5361
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
62+
DynamicPolynomials = "7c1d4256-1411-5781-91ec-d7bc3513ac07"
5463
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
5564
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
5665
SemiseparableMatrices = "f8ebbe35-cbfb-4060-bf7f-b10e4670cf57"
5766
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
5867
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
5968

6069
[targets]
61-
test = ["Base64", "Test", "ForwardDiff", "SemiseparableMatrices", "StaticArrays", "Random"]
70+
test = ["Base64", "Test", "ForwardDiff", "SemiseparableMatrices", "StaticArrays", "Random", "DynamicPolynomials"]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module ClassicalOrthogonalPolynomialsMutableArithmeticsExt
2+
using ClassicalOrthogonalPolynomials, MutableArithmetics
3+
import ClassicalOrthogonalPolynomials: initiateforwardrecurrence, recurrencecoefficients, _p0
4+
5+
Base.unsafe_getindex(P::OrthogonalPolynomial, x::AbstractMutable, n::Number) = initiateforwardrecurrence(n-1, recurrencecoefficients(P)..., x, _p0(P))[end]
6+
7+
recurrencecoefficients(::Legendre{T}) where T<:AbstractMutable = recurrencecoefficients(Legendre())
8+
end

src/classical/chebyshev.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ chebyshevu(S::AbstractQuasiMatrix) = chebyshevu(axes(S,1))
6161
6262
computes the `n`-th Chebyshev polynomial of the first kind at `z`.
6363
"""
64-
chebyshevt(n::Integer, z::Number) = Base.unsafe_getindex(ChebyshevT{typeof(z)}(), z, n+1)
64+
chebyshevt(n::Integer, z) = Base.unsafe_getindex(ChebyshevT{typeof(z)}(), z, n+1)
6565
"""
6666
chebyshevt(n, z)
6767
6868
computes the `n`-th Chebyshev polynomial of the second kind at `z`.
6969
"""
70-
chebyshevu(n::Integer, z::Number) = Base.unsafe_getindex(ChebyshevU{typeof(z)}(), z, n+1)
70+
chebyshevu(n::Integer, z) = Base.unsafe_getindex(ChebyshevU{typeof(z)}(), z, n+1)
7171

7272
chebysevtweight(d::AbstractInterval{T}) where T = ChebyshevTWeight{float(T)}[affine(d,ChebyshevInterval{T}())]
7373
chebysevuweight(d::AbstractInterval{T}) where T = ChebyshevUWeight{float(T)}[affine(d,ChebyshevInterval{T}())]

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) = 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/legendre.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ legendre(d::Inclusion) = legendre(d.domain)
6767
6868
computes the `n`-th Legendre polynomial at `z`.
6969
"""
70-
legendrep(n::Integer, z::Number) = Base.unsafe_getindex(Legendre{typeof(z)}(), z, n+1)
70+
legendrep(n::Integer, z) = Base.unsafe_getindex(Legendre{typeof(z)}(), z, n+1)
7171

7272

7373
show(io::IO, w::Legendre{Float64}) = summary(io, w)

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/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,6 @@ end
8585
@testset "Issue #179" begin
8686
@test startswith(sprint(show, MIME"text/plain"(), Chebyshev()[0.3, :]; context=(:compact=>true, :limit=>true)), "ℵ₀-element view(::ChebyshevT{Float64}, 0.3, :)")
8787
@test startswith(sprint(show, MIME"text/plain"(), Jacobi(0.2, 0.5)[-0.7, :]; context=(:compact=>true, :limit=>true)), "ℵ₀-element view(::Jacobi{Float64}, -0.7, :)")
88-
end
88+
end
89+
90+
include("test_dynamicpolynomials.jl")

test/test_dynamicpolynomials.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using DynamicPolynomials, ClassicalOrthogonalPolynomials, Test
2+
3+
@polyvar x
4+
5+
@testset "DynamicPolynomials" begin
6+
@test chebyshevt(0,x) == 1
7+
@test chebyshevt(1,x) == x
8+
@test chebyshevt(5,x) == 5x - 20x^3 + 16x^5
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
12+
end

0 commit comments

Comments
 (0)