codac 1.5.6
Loading...
Searching...
No Matches
codac2_atan.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include "codac2_Interval.h"
13#include "codac2_AnalyticType.h"
15
16namespace codac2
17{
18 struct AtanOp
19 {
20 static Interval fwd(const Interval& x1);
21 static ScalarType fwd_natural(const ScalarType& x1);
22 static ScalarType fwd_centered(const ScalarType& x1);
23 static void bwd(const Interval& y, Interval& x1);
24 };
25
26 // Analytic operator
27 // The following function can be used to build analytic expressions.
28
29 inline ScalarExpr
30 atan(const ScalarExpr& x1)
31 {
32 return { std::make_shared<AnalyticOperationExpr<AtanOp,ScalarType,ScalarType>>(x1) };
33 }
34
35 // Inline functions
36
37 inline Interval AtanOp::fwd(const Interval& x1)
38 {
39 return atan(x1);
40 }
41
42 inline ScalarType AtanOp::fwd_natural(const ScalarType& x1)
43 {
44 return {
45 fwd(x1.a),
46 x1.def_domain
47 };
48 }
49
50 inline ScalarType AtanOp::fwd_centered(const ScalarType& x1)
51 {
52 if(centered_form_not_available_for_args(x1))
53 return fwd_natural(x1);
54
55 IntervalMatrix d(1,x1.da.size());
56 for(Index i = 0 ; i < d.size() ; i++)
57 d(0,i) = x1.da(0,i)/(1.+sqr(x1.a));
58
59 return {
60 fwd(x1.m),
61 fwd(x1.a),
62 d,
63 x1.def_domain
64 };
65 }
66
67 inline void AtanOp::bwd(const Interval& y, Interval& x1)
68 {
69 // The content of this function comes from the IBEX library.
70 // See ibex::Interval (IBEX lib, main author: Gilles Chabert)
71 // https://ibex-lib.readthedocs.io
72
73 if(y.is_empty())
74 x1.set_empty();
75
76 else
77 {
78 // Note: if y.ub>pi/2 or y.lb<-pi/2, tan(y) gives (-oo,oo).
79 // so the implementation is not as simple as x1 &= tan(y).
80
81 Interval z = y;
82 double pi2l = (Interval::pi()/2).lb();
83 double pi2u = (Interval::pi()/2).ub();
84
85 if(z.ub() >= pi2l) // not pi2u. See comments below.
86 {
87 if(z.lb() >= pi2u)
88 x1.set_empty();
89
90 else
91 {
92 if(z.lb() > -pi2l)
93 {
94 // Note 1: tan(z^-) can give an interval (-oo,+oo) if
95 // z^- is close to -pi/2. Even in this case we keep the
96 // lower bound -oo.
97 //
98 // Note 2: if we had used z.lb()<-pi2u (with pi2u>pi/2)
99 // instead of z.lb()<-pi2l, it may be possible, in theory,
100 // that the calculated lower bound is a high value close to +oo, which would be incorrect.
101 //
102 // Note 3: if z.lb() is close to pi/2, the lower bound of tan(z.lb()) can be -oo. There
103 // is nothing we can do about it (the lower bound cannot be evaluated in this case)
104 //
105 // Note 4: tan(z.lb()) cannot be an empty set since z.lb() cannot be exactly pi/2.
106 x1 &= Interval(tan(Interval(z.lb())).lb(),oo);
107 }
108
109 // else do nothing
110 }
111 }
112
113 else
114 {
115 if(z.ub() <= -pi2u)
116 x1.set_empty();
117
118 else if(z.lb() < -pi2l)
119 // Same comments as above
120 x1 &= Interval(-oo,tan(Interval(z.ub())).ub());
121
122 else
123 x1 &= Interval(tan(Interval(z.lb())).lb(), tan(Interval(z.ub())).ub());
124 }
125 }
126 }
127}
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:62
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
double lb() const
Returns the lower bound of this.
Definition codac2_Interval_impl.h:102
Interval atan(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:133
Interval sqr(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:21
Interval tan(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:112