@@ -33,49 +33,16 @@ summary(io::IO, w::JacobiWeight) = print(io, "(1-x)^$(w.a) * (1+x)^$(w.b) on -1.
33
33
34
34
sum (P:: JacobiWeight ) = jacobimoment (P. a, P. b)
35
35
36
- struct LegendreWeight{T} <: AbstractJacobiWeight{T} end
37
- LegendreWeight () = LegendreWeight {Float64} ()
38
- legendreweight (d:: AbstractInterval{T} ) where T = LegendreWeight {float(T)} ()[affine (d,ChebyshevInterval {T} ())]
39
-
40
- function getindex (w:: LegendreWeight{T} , x:: Number ) where T
41
- x ∈ axes (w,1 ) || throw (BoundsError ())
42
- one (T)
43
- end
44
-
45
- getproperty (w:: LegendreWeight{T} , :: Symbol ) where T = zero (T)
46
-
47
- sum (:: LegendreWeight{T} ) where T = 2 one (T)
48
-
49
- _weighted (:: LegendreWeight , P) = P
50
- _weighted (:: SubQuasiArray{<:Any,1,<:LegendreWeight} , P) = P
51
-
52
- broadcasted (:: LazyQuasiArrayStyle{1} , :: typeof (* ), :: LegendreWeight{T} , :: LegendreWeight{V} ) where {T,V} =
53
- LegendreWeight {promote_type(T,V)} ()
54
-
55
- broadcasted (:: LazyQuasiArrayStyle{1} , :: typeof (sqrt), w:: LegendreWeight{T} ) where T = w
56
-
57
- broadcasted (:: LazyQuasiArrayStyle{1} , :: typeof (Base. literal_pow), :: Base.RefValue{typeof(^)} , w:: LegendreWeight , :: Base.RefValue{Val{k}} ) where k = w
58
36
59
37
# support auto-basis determination
60
38
61
39
singularities (a:: AbstractAffineQuasiVector ) = singularities (a. x)
62
- singularitiesbroadcast (_, L:: LegendreWeight ) = L # Assume we stay smooth
63
- singularitiesbroadcast (:: typeof (exp), L:: LegendreWeight ) = L
64
- singularitiesbroadcast (:: typeof (Base. literal_pow), :: typeof (^ ), L:: LegendreWeight , :: Val ) = L
65
40
66
41
67
42
for op in (:+ , :* )
68
43
@eval singularitiesbroadcast (:: typeof ($ op), A, B, C, D... ) = singularitiesbroadcast (* , singularitiesbroadcast (* , A, B), C, D... )
69
44
end
70
- for op in (:+ , :- , :* )
71
- @eval begin
72
- singularitiesbroadcast (:: typeof ($ op), A:: LegendreWeight , B:: LegendreWeight ) = LegendreWeight {promote_type(eltype(A), eltype(B))} ()
73
- singularitiesbroadcast (:: typeof ($ op), L:: LegendreWeight , :: NoSingularities ) = L
74
- singularitiesbroadcast (:: typeof ($ op), :: NoSingularities , L:: LegendreWeight ) = L
75
- end
76
- end
77
- singularitiesbroadcast (:: typeof (^ ), L:: LegendreWeight , :: NoSingularities ) = L
78
- singularitiesbroadcast (:: typeof (/ ), :: NoSingularities , L:: LegendreWeight ) = L # can't find roots
45
+
79
46
80
47
_parent (:: NoSingularities ) = NoSingularities ()
81
48
_parent (a) = parent (a)
@@ -87,38 +54,13 @@ singularitiesbroadcast(F, V::Union{NoSingularities,SubQuasiArray}...) = singular
87
54
singularitiesbroadcast (:: typeof (* ), V:: Union{NoSingularities,SubQuasiArray} ...) = singularitiesbroadcast (* , map (_parent,V)... )[_parentindices (V... )... ]
88
55
89
56
90
- singularitiesbroadcast (:: typeof (* ), :: LegendreWeight , b:: AbstractJacobiWeight ) = b
91
- singularitiesbroadcast (:: typeof (* ), a:: AbstractJacobiWeight , :: LegendreWeight ) = a
92
-
93
57
abstract type AbstractJacobi{T} <: OrthogonalPolynomial{T} end
94
58
95
- singularities (:: AbstractJacobi{T} ) where T = LegendreWeight {T} ()
96
- singularities (:: Inclusion{T,<:AbstractInterval} ) where T = LegendreWeight {T} ()
97
- singularities (d:: Inclusion{T,<:Interval} ) where T = LegendreWeight {T} ()[affine (d,ChebyshevInterval {T} ())]
98
-
99
- struct Legendre{T} <: AbstractJacobi{T} end
100
- Legendre () = Legendre {Float64} ()
101
-
102
- legendre () = Legendre ()
103
- legendre (d:: AbstractInterval{T} ) where T = Legendre {float(T)} ()[affine (d,ChebyshevInterval {T} ()), :]
104
-
105
- """
106
- legendrep(n, z)
107
-
108
- computes the `n`-th Legendre polynomial at `z`.
109
- """
110
- legendrep (n:: Integer , z:: Number ) = Base. unsafe_getindex (Legendre {typeof(z)} (), z, n+ 1 )
59
+ include (" legendre.jl" )
111
60
61
+ singularitiesbroadcast (:: typeof (* ), :: LegendreWeight , b:: AbstractJacobiWeight ) = b
62
+ singularitiesbroadcast (:: typeof (* ), a:: AbstractJacobiWeight , :: LegendreWeight ) = a
112
63
113
- == (:: Legendre , :: Legendre ) = true
114
-
115
- OrthogonalPolynomial (w:: LegendreWeight{T} ) where {T} = Legendre {T} ()
116
- orthogonalityweight (:: Legendre{T} ) where T = LegendreWeight {T} ()
117
-
118
- function qr (P:: Legendre )
119
- Q = Normalized (P)
120
- QuasiQR (Q, Diagonal (Q. scaling))
121
- end
122
64
123
65
struct Jacobi{T} <: AbstractJacobi{T}
124
66
a:: T
@@ -221,12 +163,8 @@ function plotgrid(Pn::SubQuasiArray{T,2,<:AbstractJacobi,<:Tuple{Inclusion,Any}}
221
163
ChebyshevGrid {2,T} (40 maximum (jr))
222
164
end
223
165
224
-
225
- function ldiv (:: Legendre{V} , f:: AbstractQuasiVector ) where V
226
- T = ChebyshevT {V} ()
227
- [cheb2leg (paddeddata (T \ f)); zeros (V,∞)]
228
- end
229
-
166
+ ldiv (P:: Jacobi{V} , f:: Inclusion{T} ) where {T,V} = _op_ldiv (P, f)
167
+ ldiv (P:: Jacobi{V} , f:: AbstractQuasiFill{T,1} ) where {T,V} = _op_ldiv (P, f)
230
168
function ldiv (P:: Jacobi{V} , f:: AbstractQuasiVector ) where V
231
169
T = ChebyshevT {V} ()
232
170
[cheb2jac (paddeddata (T \ f), P. a, P. b); zeros (V,∞)]
237
175
# Mass Matrix
238
176
# ########
239
177
240
- # massmatrix(P) = Weighted(P)'P
241
- massmatrix (P:: Legendre{T} ) where T = Diagonal (convert (T,2 ) ./ (2 (0 : ∞) .+ 1 ))
242
-
243
-
244
-
245
- """
246
- legendre_massmatrix
247
-
248
- computes the massmatrix by first re-expanding in Legendre
249
- """
250
- function legendre_massmatrix (Ac, B)
251
- A = parent (Ac)
252
- P = Legendre {eltype(B)} ()
253
- (P\ A)' * massmatrix (P)* (P\ B)
254
- end
255
178
256
- @simplify * (Ac:: QuasiAdjoint{<:Any,<:Legendre} , B:: Legendre ) = massmatrix (Legendre {promote_type(eltype(Ac), eltype(B))} ())
257
179
@simplify * (Ac:: QuasiAdjoint{<:Any,<:AbstractJacobi} , B:: AbstractJacobi ) = legendre_massmatrix (Ac,B)
258
180
@simplify * (Ac:: QuasiAdjoint{<:Any,<:AbstractJacobi} , B:: Weighted{<:Any,<:AbstractJacobi} ) = legendre_massmatrix (Ac,B)
259
181
287
209
# Jacobi Matrix
288
210
# #######
289
211
290
- jacobimatrix (:: Legendre{T} ) where T = Tridiagonal ((one (T): ∞). / (1 : 2 : ∞), Zeros {T} (∞), (one (T): ∞). / (3 : 2 : ∞))
291
-
292
- # These return vectors A[k], B[k], C[k] are from DLMF. Cause of MikaelSlevinsky we need an extra entry in C ... for now.
293
- function recurrencecoefficients (:: Legendre{T} ) where T
294
- n = zero (T): ∞
295
- ((2 n .+ 1 ) ./ (n .+ 1 ), Zeros {T} (∞), n ./ (n .+ 1 ))
296
- end
297
-
298
212
function jacobimatrix (J:: Jacobi )
299
213
b,a = J. b,J. a
300
214
n = 0 : ∞
@@ -316,19 +230,6 @@ function recurrencecoefficients(P::Jacobi)
316
230
(A,B,C)
317
231
end
318
232
319
- # explicit special case for normalized Legendre
320
- # todo: do we want these explicit constructors for normalized Legendre?
321
- # function jacobimatrix(::Normalized{<:Any,<:Legendre{T}}) where T
322
- # b = (one(T):∞) ./sqrt.(4 .*(one(T):∞).^2 .-1)
323
- # Symmetric(_BandedMatrix(Vcat(zeros(∞)', (b)'), ∞, 1, 0), :L)
324
- # end
325
- # function recurrencecoefficients(::Normalized{<:Any,<:Legendre{T}}) where T
326
- # n = zero(T):∞
327
- # nn = one(T):∞
328
- # ((2n .+ 1) ./ (n .+ 1) ./ sqrt.(1 .-2 ./(3 .+2n)), Zeros{T}(∞), Vcat(zero(T),nn ./ (nn .+ 1) ./ sqrt.(1 .-4 ./(3 .+2nn))))
329
- # end
330
-
331
- @simplify * (X:: Identity , P:: Legendre ) = ApplyQuasiMatrix (* , P, P\ (X* P))
332
233
333
234
334
235
@@ -519,25 +420,11 @@ end
519
420
end
520
421
521
422
522
- # ##
523
- # Splines
524
- # ##
525
-
526
- function \ (A:: Legendre , B:: HeavisideSpline )
527
- @assert B. points == - 1 : 2 : 1
528
- Vcat (1 , Zeros (∞,1 ))
529
- end
530
423
531
424
# ##
532
425
# sum
533
426
# ##
534
427
535
- function _sum (P:: Legendre{T} , dims) where T
536
- @assert dims == 1
537
- Hcat (convert (T, 2 ), Zeros {T} (1 ,∞))
538
- end
539
-
540
- _sum (p:: SubQuasiArray{T,1,Legendre{T},<:Tuple{Inclusion,Int}} , :: Colon ) where T = parentindices (p)[2 ] == 1 ? convert (T, 2 ) : zero (T)
541
428
_sum (P:: AbstractJacobi{T} , dims) where T = 2 * (Legendre {T} () \ P)[1 : 1 ,:]
542
429
543
430
0 commit comments