codac 1.5.6
Loading...
Searching...
No Matches
codac2_Interval_operations_impl.h
Go to the documentation of this file.
1
14
15#pragma once
16
17// Inline functions
18
19namespace codac2
20{
21 inline Interval sqr(const Interval& x)
22 {
23 return gaol::sqr(x);
24 }
25
26 inline Interval sqrt(const Interval& x)
27 {
28 Interval y = gaol::sqrt(x);
29 gaol::round_upward();
30 return y;
31 }
32
33 inline Interval pow(const Interval& x, int p)
34 {
35 Interval y = gaol::pow(x,p);
36 //gaol::round_upward(); // not necessary?
37 return y;
38 }
39
40 inline Interval pow(const Interval& x, double p)
41 {
42 if(p == -oo || p == oo)
43 return Interval::empty();
44
45 else
46 {
47 Interval y = gaol::pow(x,p);
48 gaol::round_upward();
49 return y;
50 }
51 }
52
53 inline Interval pow(const Interval& x, const Interval& p)
54 {
55 Interval y = gaol::pow(x,p);
56 gaol::round_upward();
57 return y;
58 }
59
60 inline Interval root(const Interval& x, int p)
61 {
62 // Get the root of the positive part (gaol does
63 // not consider negative values to be in the definition
64 // domain of the root function)
65
66 gaol::interval y = gaol::nth_root(x, p>=0 ? p : -p);
67
68 if(p%2 == 1 && x.lb() < 0)
69 y |= -gaol::nth_root(-x, p >= 0 ? p : -p);
70
71 if(p < 0)
72 y = 1.0/y;
73
74 gaol::round_upward();
75 return y;
76 }
77
78 inline Interval exp(const Interval& x)
79 {
80 Interval y = gaol::exp(x);
81 gaol::round_upward();
82 return y;
83 }
84
85 inline Interval log(const Interval& x)
86 {
87 if(x.ub() <= 0) // gaol returns (-oo,-DBL_MAX) if x.ub()==0, instead of empty set
88 return Interval::empty();
89
90 else
91 {
92 Interval y = gaol::log(x);
93 gaol::round_upward();
94 return y;
95 }
96 }
97
98 inline Interval cos(const Interval& x)
99 {
100 Interval y = gaol::cos(x);
101 gaol::round_upward();
102 return y;
103 }
104
105 inline Interval sin(const Interval& x)
106 {
107 Interval y = gaol::sin(x);
108 gaol::round_upward();
109 return y;
110 }
111
112 inline Interval tan(const Interval& x)
113 {
114 Interval y = gaol::tan(x);
115 gaol::round_upward();
116 return y;
117 }
118
119 inline Interval acos(const Interval& x)
120 {
121 Interval y = gaol::acos(x);
122 gaol::round_upward();
123 return y;
124 }
125
126 inline Interval asin(const Interval& x)
127 {
128 Interval y = gaol::asin(x);
129 gaol::round_upward();
130 return y;
131 }
132
133 inline Interval atan(const Interval& x)
134 {
135 Interval y = gaol::atan(x);
136 gaol::round_upward();
137 return y;
138 }
139
140 inline Interval atan2(const Interval& y, const Interval& x)
141 {
142 if(y.is_empty() || x.is_empty())
143 return Interval::empty();
144
145 // We handle the special case x=[0,0] separately
146 else if(x == Interval::zero())
147 {
148 if(y.lb() >= 0)
149 {
150 if(y.ub() == 0)
151 return Interval::empty(); // atan2(0,0) is undefined
152 else
153 return Interval::half_pi();
154 }
155
156 else if(y.ub() <= 0)
157 return -Interval::half_pi();
158
159 else
160 return Interval(-1,1)*Interval::half_pi();
161 }
162
163 else if(x.lb() >= 0)
164 return atan(y/x); // now, x.ub()>0 -> atan does not give an empty set
165
166 else if(x.ub() <= 0)
167 {
168 if(y.lb() >= 0)
169 return atan(y/x) + Interval::pi(); // x.lb()<0
170 else if(y.ub() < 0)
171 return atan(y/x) - Interval::pi();
172 else
173 return Interval(-1,1)*Interval::pi();
174 }
175
176 else
177 {
178 if(y.lb() >= 0)
179 return atan(y/x.ub()) | (atan(y/x.lb()) + Interval::pi());
180
181 else if(y.ub() <= 0)
182 {
183 if(x.lb() != -oo)
184 {
185 if(x.ub() != oo)
186 return (atan(y/x.lb())-Interval::pi()) | atan(y/x.ub());
187 else
188 return (atan(y/x.lb())-Interval::pi()) | Interval::zero();
189 }
190
191 else
192 {
193 if(x.ub() != oo)
194 return (-Interval::pi()) | atan(y/x.ub());
195 else
196 return -Interval::pi() | Interval::zero();
197 }
198 }
199
200 else
201 return Interval(-1,1)*Interval::pi();
202 }
203 }
204
205 inline Interval cosh(const Interval& x)
206 {
207 Interval y;
208 if(x.is_unbounded())
209 y = Interval(gaol::cosh(x).left(),oo);
210 else
211 y = gaol::cosh(x);
212 gaol::round_upward();
213 return y;
214 }
215
216 inline Interval sinh(const Interval& x)
217 {
218 Interval y = gaol::sinh(x);
219 gaol::round_upward();
220 return y;
221 }
222
223 inline Interval tanh(const Interval& x)
224 {
225 Interval y = gaol::tanh(x);
226 gaol::round_upward();
227 return y;
228 }
229
230 inline Interval acosh(const Interval& x)
231 {
232 Interval y = gaol::acosh(x);
233 gaol::round_upward();
234 return y;
235 }
236
237 inline Interval asinh(const Interval& x)
238 {
239 if(x.is_empty())
240 return Interval::empty();
241
242 else if(x.lb() >= 0)
243 return gaol::asinh(x);
244
245 else if(x.ub() <= 0)
246 return -gaol::asinh(-x);
247
248 else
249 return {
250 -gaol::asinh(gaol::interval(0,-x.lb())).right(),
251 gaol::asinh(gaol::interval(0,x.ub())).right()
252 };
253
254 // no round_upward?
255 }
256
257 inline Interval atanh(const Interval& x)
258 {
259 Interval y = gaol::atanh(x);
260 gaol::round_upward();
261 return y;
262 }
263
264 inline Interval abs(const Interval& x)
265 {
266 return gaol::abs(x);
267 }
268
269 inline Interval min(const Interval& x, const Interval& y)
270 {
271 return gaol::min(x,y);
272 }
273
274 inline Interval max(const Interval& x, const Interval& y)
275 {
276 return gaol::max(x,y);
277 }
278
279 inline Interval sign(const Interval& x)
280 {
281 return x.ub() < 0 ? -1. : x.lb() > 0 ? 1. : Interval(-1.,1.);
282 }
283
284 inline Interval integer(const Interval& x)
285 {
286 return gaol::integer(x);
287 }
288
289 inline Interval floor(const Interval& x)
290 {
291 return gaol::floor(x);
292 }
293
294 inline Interval ceil(const Interval& x)
295 {
296 return gaol::ceil(x);
297 }
298
299 inline Interval chi(const Interval& x, const Interval& y, const Interval& z)
300 {
301 if(x.ub() <= 0)
302 return y;
303
304 else if(x.lb() > 0)
305 return z;
306
307 else
308 return y | z;
309 }
310}
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:62
bool is_unbounded() const
Tests if one of the bounds of this is infinite.
Definition codac2_Interval_impl.h:202
bool is_empty() const
Tests if this is empty.
Definition codac2_Interval_impl.h:187
friend Interval chi(const Interval &, const Interval &, const Interval &)
Return if , if , else.
Definition codac2_Interval_operations_impl.h:299
double ub() const
Returns the upper bound of this.
Definition codac2_Interval_impl.h:107
static Interval pi()
Provides an interval for .
Definition codac2_Interval_impl.h:555
static Interval zero()
Provides an interval for .
Definition codac2_Interval_impl.h:540
friend Interval pow(const Interval &, double)
Returns , .
Definition codac2_Interval_operations_impl.h:40
Interval()
Creates an interval .
Definition codac2_Interval_impl.h:21
double lb() const
Returns the lower bound of this.
Definition codac2_Interval_impl.h:102
static Interval empty()
Provides an empty interval.
Definition codac2_Interval_impl.h:535
static Interval half_pi()
Provides an interval for .
Definition codac2_Interval_impl.h:550
Interval ceil(const Interval &x)
Returns ceil of .
Definition codac2_Interval_operations_impl.h:294
Interval atan(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:133
Interval max(const Interval &x, const Interval &y)
Returns .
Definition codac2_Interval_operations_impl.h:274
Interval asinh(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:237
Interval atanh(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:257
Interval pow(const Interval &x, int n)
Returns , .
Definition codac2_Interval_operations_impl.h:33
Interval sqrt(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:26
Interval cosh(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:205
Interval floor(const Interval &x)
Returns floor of .
Definition codac2_Interval_operations_impl.h:289
Interval sinh(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:216
Interval acos(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:119
Interval atan2(const Interval &y, const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:140
Interval log(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:85
Interval cos(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:98
Interval exp(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:78
Interval tanh(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:223
Interval sqr(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:21
Interval root(const Interval &x, int p)
Returns the p-th root: .
Definition codac2_Interval_operations_impl.h:60
Interval abs(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:264
Interval asin(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:126
Interval integer(const Interval &x)
Returns the largest integer interval included in .
Definition codac2_Interval_operations_impl.h:284
Interval min(const Interval &x, const Interval &y)
Returns .
Definition codac2_Interval_operations_impl.h:269
Interval acosh(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:230
Interval sign(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:279
Interval sin(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:105
Interval tan(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:112