Skip to content

Commit 36441f4

Browse files
authored
Support BigFloat in Hermite (#127)
* Support BigFloat in Hermite * revert axes type * allow powers of Hermite weight
1 parent 75ef962 commit 36441f4

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/classical/hermite.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,27 @@ is a quasi-vector representing `exp(-x^2)` on ℝ.
66
struct HermiteWeight{T} <: Weight{T} end
77

88
HermiteWeight() = HermiteWeight{Float64}()
9-
axes(::HermiteWeight{T}) where T = (Inclusion(ℝ),)
9+
axes(::HermiteWeight{T}) where T = (Inclusion{T}(ℝ),)
1010
function getindex(w::HermiteWeight, x::Number)
1111
x axes(w,1) || throw(BoundsError())
1212
exp(-x^2)
1313
end
1414

1515
sum(::HermiteWeight{T}) where T = sqrt(convert(T, π))
1616

17+
function broadcasted(::typeof(^), H::HermiteWeight, k::Number)
18+
x = axes(H,1)
19+
exp.((-k) .* x .^2)
20+
end
21+
22+
broadcasted(::typeof(sqrt), H::HermiteWeight{T}) where T = H .^ (one(T)/2)
23+
1724
struct Hermite{T} <: OrthogonalPolynomial{T} end
1825
Hermite() = Hermite{Float64}()
1926
orthogonalityweight(::Hermite{T}) where T = HermiteWeight{T}()
2027

2128
==(::Hermite, ::Hermite) = true
22-
axes(::Hermite{T}) where T = (Inclusion(ℝ), oneto(∞))
29+
axes(::Hermite{T}) where T = (Inclusion{T}(ℝ), oneto(∞))
2330

2431
"""
2532
hermiteh(n, z)

test/test_hermite.jl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ import DomainSets: ℝ
3131
end
3232

3333
@testset "OrthonormalWeighted" begin
34-
H = Hermite()
35-
Q = OrthonormalWeighted(H)
36-
37-
@test Q'Q == Eye(∞)
34+
@testset "orthogonality" begin
35+
H = Hermite()
36+
Q = OrthonormalWeighted(H)
37+
@test Q'Q == Eye(∞)
38+
end
3839

3940
@testset "evaluation" begin
41+
H = Hermite()
42+
Q = OrthonormalWeighted(H)
4043
x = 0.1
4144
@test Q[x,1] exp(-x^2/2)/π^(1/4)
4245
@test Q[x,2] 2x*exp(-x^2/2)/(sqrt(2^(1/4))
@@ -46,6 +49,8 @@ import DomainSets: ℝ
4649
end
4750

4851
@testset "Differentiation" begin
52+
H = Hermite()
53+
Q = OrthonormalWeighted(H)
4954
x = axes(Q,1)
5055
D = Derivative(x)
5156
= Q \ (D * Q)
@@ -54,5 +59,10 @@ import DomainSets: ℝ
5459
X = Q \ (x .* Q)
5560
@test (D² - X^2)[1:10,1:10] -Diagonal(1:2:19)
5661
end
62+
63+
@testset "BigFloat" begin
64+
Q = OrthonormalWeighted(Hermite{BigFloat}())
65+
@test Q[40.0, 1] exp(-big(40)^2/2) * big(π)^(-1/4)
66+
end
5767
end
5868
end

0 commit comments

Comments
 (0)