/
constructors.jl
148 lines (116 loc) · 5.44 KB
/
constructors.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# constructors.jl
const tupleTMs = (:TaylorModel1, :RTaylorModel1)
const NumberNotSeries = TaylorSeries.NumberNotSeries
#=
Structs `TaylorModel1` and `RTaylorModel1` are essentially identical, except
the way the remainder is handled; the remainder for `TaylorModel1`
must contain 0.
=#
for TM in tupleTMs
@eval begin
struct $(TM){T,S} <: AbstractSeries{T}
pol :: Taylor1{T} # polynomial approx (of order `ord`)
rem :: Interval{S} # remainder
x0 :: Interval{S} # expansion point
dom :: Interval{S} # interval of interest
# Inner constructor
function $(TM){T,S}(pol::Taylor1{T}, rem::Interval{S},
x0::Interval{S}, dom::Interval{S}) where {T,S}
if $(TM) == TaylorModel1
@assert zero(S) ∈ rem && x0 ⊆ dom
else
@assert x0 ⊆ dom
end
return new{T,S}(pol, rem, x0, dom)
end
end
# Outer constructors
$(TM)(pol::Taylor1{T}, rem::Interval{S},
x0, dom::Interval{S}) where {T,S} = $(TM){T,S}(pol, rem, interval(x0), dom)
# Constructor just chainging the remainder
$(TM)(u::$(TM){T,S}, Δ::Interval{S}) where {T,S} = $(TM){T,S}(u.pol, Δ, u.x0, u.dom)
# Short-cut for independent variable
$(TM)(ord::Integer, x0, dom::Interval{T}) where {T} =
$(TM)(x0 + Taylor1(eltype(x0), ord), zero(dom), interval(x0), dom)
# Short-cut for a constructor expanding around midpoint by default
$(TM)(ord::Integer, dom::Interval{T}) where {T} =
$(TM)(ord, Interval(mid(dom)), dom)
# Short-cut for a constant TM
$(TM)(a::T, ord::Integer, x0::Interval{S}, dom::Interval{S}) where
{T,S} = $(TM)(Taylor1([a], ord), zero(dom), x0, dom)
# Functions to retrieve the order and remainder
@inline get_order(tm::$TM) = get_order(tm.pol)
@inline remainder(tm::$TM) = tm.rem
@inline polynomial(tm::$TM) = tm.pol
@inline domain(tm::$TM) = tm.dom
@inline expansion_point(tm::$TM) = tm.x0
end
end
@doc doc"""
TaylorModel1{T,S}
Absolute Taylor model in 1 variable, providing a rigurous polynomial approximation
given by a Taylor polynomial `pol` (around `x0`) and an absolute remainder
`rem` for a function `f(x)` in one variable, valid in the interval `dom`.
This corresponds to definition 2.1.3 of Mioara Joldes' thesis.
Fields:
- `pol`: polynomial approximation, represented as `TaylorSeries.Taylor1`
- `rem`: the interval bound
- `x0` : expansion point
- `dom`: domain, interval over which the Taylor model is defined / valid
The approximation ``f(x) = p(x) + \Delta`` is satisfied for all
``x\in \mathcal{D}`` (``0\in \Delta``); `n` is the order (degree)
of the polynomial ``p(x)=\sum_{i=0}^n p_i (x - x_0)^i``.
""" TaylorModel1
@doc doc"""
RTaylorModel1{T,S}
Relative Taylor model in 1 variable, providing a rigurous polynomial approximation
given by a Taylor polynomial `pol` (around `x0`) and a relative remainder
`rem` for a function `f(x)` in one variable, valid in the interval `dom`.
This corresponds to definition 2.3.2 of Mioara Joldes' thesis.
Fields:
- `pol`: polynomial approximation, represented as `TaylorSeries.Taylor1`
- `rem`: the interval bound
- `x0` : expansion point
- `dom`: domain, interval over which the Taylor model is defined / valid
The approximation ``f(x) = p(x) + \delta (x - x_0)^{n+1}`` is satisfied for all
``x\in \mathcal{D}``; `n` is the order (degree) of the polynomial
``p(x)=\sum_{i=0}^n p_i (x - x_0)^i``.
""" RTaylorModel1
# TaylorModelN's struct
"""
TaylorModelN{N,T,S}
Taylor Models with absolute remainder for `N` independent variables.
"""
struct TaylorModelN{N,T,S} <: AbstractSeries{T}
pol :: TaylorN{T} # polynomial approx (of order `ord`)
rem :: Interval{S} # remainder
x0 :: IntervalBox{N,S} # expansion point
dom :: IntervalBox{N,S} # interval of interest
# Inner constructor
function TaylorModelN{N,T,S}(pol::TaylorN{T}, rem::Interval{S},
x0::IntervalBox{N,S}, dom::IntervalBox{N,S}) where {N,T<:NumberNotSeries,S<:Real}
@assert N == get_numvars()
@assert zero(S) ∈ rem && x0 ⊆ dom
return new{N,T,S}(pol, rem, x0, dom)
end
end
# Outer constructors
TaylorModelN(pol::TaylorN{T}, rem::Interval{S}, x0::IntervalBox{N,S},
dom::IntervalBox{N,S}) where {N,T,S} = TaylorModelN{N,T,S}(pol, rem, x0, dom)
# Constructor for just changing the remainder
TaylorModelN(u::TaylorModelN{N,T,S}, Δ::Interval{S}) where {N,T,S} =
TaylorModelN{N,T,S}(u.pol, Δ, u.x0, u.dom)
# Short-cut for independent variable
TaylorModelN(nv::Integer, ord::Integer, x0::IntervalBox{N,T}, dom::IntervalBox{N,T}) where {N,T} =
TaylorModelN(x0[nv] + TaylorN(Interval{T}, nv, order=ord), zero(dom[1]), x0, dom)
# Short-cut for a constant
TaylorModelN(a::Interval{T}, ord::Integer, x0::IntervalBox{N,T}, dom::IntervalBox{N,T}) where {N,T} =
TaylorModelN(TaylorN(a, ord), zero(dom[1]), x0, dom)
TaylorModelN(a::T, ord::Integer, x0::IntervalBox{N,T}, dom::IntervalBox{N,T}) where {N,T} =
TaylorModelN(TaylorN(a, ord), zero(dom[1]), x0, dom)
# Functions to retrieve the order and remainder
@inline get_order(tm::TaylorModelN) = tm.pol.order
@inline remainder(tm::TaylorModelN) = tm.rem
@inline polynomial(tm::TaylorModelN) = tm.pol
@inline domain(tm::TaylorModelN) = tm.dom
@inline expansion_point(tm::TaylorModelN) = tm.x0