Sequences
A Sequence
is a structure representing a sequence in a prescribed VectorSpace
. More precisely, a Sequence
is comprised of the two fields space::VectorSpace
and coefficients::AbstractVector
with matching dimension and length.
julia> a = Sequence(Taylor(1), [1, 2])
Sequence in Taylor(1) with coefficients Vector{Int64}: 1 2
The two fields space
and coefficients
are accessible via the respective functions of the same name.
julia> space(a)
Taylor(1)
julia> coefficients(a)
2-element Vector{Int64}: 1 2
For convenience, the methods zeros
, ones
, fill
and fill!
are available:
julia> s = Taylor(1)
Taylor(1)
julia> zeros(s)
Sequence in Taylor(1) with coefficients Vector{Float64}: 0.0 0.0
julia> ones(s)
Sequence in Taylor(1) with coefficients Vector{Float64}: 1.0 1.0
julia> fill(2, s)
Sequence in Taylor(1) with coefficients Vector{Int64}: 2 2
julia> fill!(zeros(s), 2)
Sequence in Taylor(1) with coefficients Vector{Float64}: 2.0 2.0
The coefficients of a Sequence
are indexed according to the indices of the space (as given by indices
).
julia> a[0:1] # indices(space(a))
2-element Vector{Int64}: 1 2
When the space of a Sequence
is a CartesianSpace
, its coefficients are given as the concatenation of the coefficients associated with each space. The function component
extracts a Sequence
composing the cartesian space.
julia> b = Sequence(ParameterSpace() × Taylor(1)^2, [1, 2, 3, 4, 5])
Sequence in 𝕂 × Taylor(1)² with coefficients Vector{Int64}: 1 2 3 4 5
julia> b[1:5] # indices(space(b))
5-element Vector{Int64}: 1 2 3 4 5
julia> component(b, 1) # extract the sequence associated with the space ParameterSpace()
Sequence in 𝕂 with coefficients SubArray{Int64, 1, Vector{Int64}, Tuple{UnitRange{Int64}}, true}: 1
julia> component(b, 2) # extract the sequence associated with the space Taylor(1)^2
Sequence in Taylor(1)² with coefficients SubArray{Int64, 1, Vector{Int64}, Tuple{UnitRange{Int64}}, true}: 2 3 4 5
julia> component(component(b, 2), 1)
Sequence in Taylor(1) with coefficients SubArray{Int64, 1, Vector{Int64}, Tuple{UnitRange{Int64}}, true}: 2 3
julia> component(component(b, 2), 2)
Sequence in Taylor(1) with coefficients SubArray{Int64, 1, Vector{Int64}, Tuple{UnitRange{Int64}}, true}: 4 5
Similarly, the function eachcomponent
returns a Generator
whose iterates yield each Sequence
composing the cartesian space.
Arithmetic
The addition and subtraction operations are implemented as the +
and -
functions respectively.
julia> c = Sequence(Taylor(1), [0, 1])
Sequence in Taylor(1) with coefficients Vector{Int64}: 0 1
julia> d = Sequence(Taylor(2), [1, 2, 1])
Sequence in Taylor(2) with coefficients Vector{Int64}: 1 2 1
julia> c + d
Sequence in Taylor(2) with coefficients Vector{Int64}: 1 3 1
julia> c - d
Sequence in Taylor(2) with coefficients Vector{Int64}: -1 -1 -1
The discrete convolution between sequences whose spaces are a SequenceSpace
is implemented as the *(::Sequence{<:SequenceSpace}, ::Sequence{<:SequenceSpace})
, mul!(::Sequence{<:SequenceSpace}, ::Sequence{<:SequenceSpace}, ::Sequence{<:SequenceSpace}, ::Number, ::Number)
and ^(::Sequence{<:SequenceSpace}, ::Int)
functions. Their bar counterparts mul_bar
(unicode alias *\bar<tab>
) and pow_bar
(unicode alias ^\bar<tab>
) give the result projected in the smallest compatible space between the operands; in general, mul_bar
is not associative.
julia> c * d
Sequence in Taylor(3) with coefficients Vector{Int64}: 0 1 2 1
julia> c ^ 3
Sequence in Taylor(3) with coefficients Vector{Int64}: 0 0 0 1
julia> mul_bar(c, d) # project(c * d, Taylor(1))
Sequence in Taylor(1) with coefficients Vector{Int64}: 0 1
julia> pow_bar(c, 3) # project(c ^ 3, Taylor(1))
Sequence in Taylor(1) with coefficients Vector{Int64}: 0 0
To improve performance, the FFT algorithm may be used to compute discrete convolutions via the Convolution Theorem. However, the performance gain is tempered with the loss of accuracy which may stop the decay of the coefficients. To circumvent machine precision limitations, the banach_rounding!
method enclose rigorously each term of the convolution beyond a prescribed order.[1]
julia> x = Sequence(Taylor(3), interval.([inv(10_000.0 ^ i) for i ∈ 0:3]))
Sequence in Taylor(3) with coefficients Vector{Interval{Float64}}: Interval{Float64}(1.0, 1.0, com, true) Interval{Float64}(0.0001, 0.0001, com, true) Interval{Float64}(1.0e-8, 1.0e-8, com, true) Interval{Float64}(1.0e-12, 1.0e-12, com, true)
julia> RadiiPolynomial.set_conv_algorithm(:fft)
:fft
julia> x³ = x ^ 3
Sequence in Taylor(9) with coefficients Vector{Interval{Float64}}: Interval{Float64}(0.9999999999999988, 1.0000000000000013, com, false) Interval{Float64}(0.00029999999999913776, 0.0003000000000009015, com, false) Interval{Float64}(5.999999926209087e-8, 6.000000089712177e-8, com, false) Interval{Float64}(9.999147625819226e-12, 1.000107365363463e-11, com, false) Interval{Float64}(5.767225544805468e-16, 1.9773326896552844e-15, com, false) Interval{Float64}(-6.400000000000008e-19, 6.400000000000008e-19, com, true) Interval{Float64}(-6.400000000000003e-23, 6.400000000000003e-23, com, true) Interval{Float64}(-6.399999999999998e-27, 6.399999999999998e-27, com, true) Interval{Float64}(-6.3999999999999925e-31, 6.3999999999999925e-31, com, true) Interval{Float64}(-6.399999999999987e-35, 6.399999999999987e-35, com, true)
julia> RadiiPolynomial.set_conv_algorithm(:sum) # default algorithm
:sum
julia> x³ = x ^ 3 # only rounding error
Sequence in Taylor(9) with coefficients Vector{Interval{Float64}}: Interval{Float64}(1.0, 1.0, com, true) Interval{Float64}(0.0003, 0.00030000000000000003, com, true) Interval{Float64}(6.0e-8, 6.000000000000001e-8, com, true) Interval{Float64}(1.0e-11, 1.0000000000000003e-11, com, true) Interval{Float64}(1.1999999999999998e-15, 1.2000000000000006e-15, com, true) Interval{Float64}(1.1999999999999996e-19, 1.2000000000000004e-19, com, true) Interval{Float64}(9.999999999999997e-24, 1.0000000000000004e-23, com, true) Interval{Float64}(5.999999999999999e-28, 6.000000000000002e-28, com, true) Interval{Float64}(2.9999999999999995e-32, 3.0000000000000006e-32, com, true) Interval{Float64}(9.999999999999998e-37, 1.0000000000000001e-36, com, true)
API
- 1J.-P. Lessard, Computing discrete convolutions with verified accuracy via Banach algebras and the FFT, Applications of Mathematics, 63 (2018), 219-235.