codac 1.5.6
Loading...
Searching...
No Matches
codac2_chi.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 // chi([x1],[x2],[x3]) = [x2] if (x1^+)<=0, [x3] if (x1^-)>0, hull([x2],[x3]) else
19 struct ChiOp
20 {
21 static Interval fwd(const Interval& x1, const Interval& x2, const Interval& x3);
22 static ScalarType fwd_natural(const ScalarType& x1, const ScalarType& x2, const ScalarType& x3);
23 static ScalarType fwd_centered(const ScalarType& x1, const ScalarType& x2, const ScalarType& x3);
24 static void bwd(const Interval& y, Interval& x1, Interval& x2, Interval& x3);
25 };
26
27 // Analytic operator
28 // The following function can be used to build analytic expressions.
29
30 inline ScalarExpr
31 chi(const ScalarExpr& x1, const ScalarExpr& x2, const ScalarExpr& x3)
32 {
33 return { std::make_shared<AnalyticOperationExpr<ChiOp,ScalarType,ScalarType,ScalarType,ScalarType>>(x1,x2,x3) };
34 }
35
36 // Inline functions
37
38 inline Interval ChiOp::fwd(const Interval& x1, const Interval& x2, const Interval& x3)
39 {
40 return chi(x1,x2,x3);
41 }
42
43 inline ScalarType ChiOp::fwd_natural(const ScalarType& x1, const ScalarType& x2, const ScalarType& x3)
44 {
45 return {
46 fwd(x1.a,x2.a,x3.a),
47 x1.def_domain && x2.def_domain && x3.def_domain
48 };
49 }
50
51 inline ScalarType ChiOp::fwd_centered(const ScalarType& x1, const ScalarType& x2, const ScalarType& x3)
52 {
53 return {
54 fwd(x1.m,x2.m,x3.m),
55 fwd(x1.a,x2.a,x3.a),
56 IntervalMatrix(0,0), // not supported yet for auto diff
57 x1.def_domain && x2.def_domain && x3.def_domain
58 };
59 }
60
61 inline void ChiOp::bwd(const Interval& y, Interval& x1, Interval& x2, Interval& x3)
62 {
63 // The content of this function comes from the IBEX library.
64 // See ibex::Interval (IBEX lib, main author: Gilles Chabert)
65 // https://ibex-lib.readthedocs.io
66
67 if(x1.ub() <= 0)
68 {
69 if((x2 &= y).is_empty())
70 {
71 x1.set_empty();
72 x3.set_empty();
73 }
74 }
75
76 else if(x1.lb() > 0)
77 {
78 if((x3 &= y).is_empty())
79 {
80 x1.set_empty();
81 x2.set_empty();
82 }
83 }
84
85 if(y.is_disjoint(x2))
86 {
87 if((x1 &= Interval(0,oo)).is_empty())
88 {
89 x2.set_empty();
90 x3.set_empty();
91 }
92
93 if((x3 &= y).is_empty())
94 {
95 x1.set_empty();
96 x2.set_empty();
97 }
98 }
99
100 if(y.is_disjoint(x3))
101 {
102 if((x1 &= Interval(-oo,0)).is_empty())
103 {
104 x2.set_empty();
105 x3.set_empty();
106 }
107
108 if((x2 &= y).is_empty())
109 {
110 x1.set_empty();
111 x3.set_empty();
112 }
113 }
114 }
115}
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:62
Interval chi(const Interval &x, const Interval &y, const Interval &z)
Return if , if , else.
Definition codac2_Interval_operations_impl.h:299