25 static std::string str(
const X1& x1)
27 return "-" + x1->str(!x1->is_str_leaf());
31 static std::pair<Index,Index> output_shape(
const X1& s1) {
32 return s1->output_shape();
35 static Interval fwd(
const Interval& x1);
36 static ScalarType fwd_natural(
const ScalarType& x1);
37 static ScalarType fwd_centered(
const ScalarType& x1);
38 static void bwd(
const Interval& y, Interval& x1);
40 static IntervalVector fwd(
const IntervalVector& x1);
41 static VectorType fwd_natural(
const VectorType& x1);
42 static VectorType fwd_centered(
const VectorType& x1);
43 static void bwd(
const IntervalVector& y, IntervalVector& x1);
45 static IntervalMatrix fwd(
const IntervalMatrix& x1);
46 static MatrixType fwd_natural(
const MatrixType& x1);
47 static MatrixType fwd_centered(
const MatrixType& x1);
48 static void bwd(
const IntervalMatrix& y, IntervalMatrix& x1);
52 template<
typename X1,
typename X2>
53 static std::string str(
const X1& x1,
const X2& x2)
55 return x1->str(!x1->is_str_leaf()) +
"-" + x2->str(!x2->is_str_leaf());
58 template<
typename X1,
typename X2>
59 static std::pair<Index,Index> output_shape(
const X1& s1,
const X2& s2) {
60 auto shape1=s1->output_shape();
61 auto shape2=s2->output_shape();
62 assert_release(shape1==shape2);
66 static Interval fwd(
const Interval& x1,
const Interval& x2);
67 static ScalarType fwd_natural(
const ScalarType& x1,
const ScalarType& x2);
68 static ScalarType fwd_centered(
const ScalarType& x1,
const ScalarType& x2);
69 static void bwd(
const Interval& y, Interval& x1, Interval& x2);
71 static IntervalVector fwd(
const IntervalVector& x1,
const IntervalVector& x2);
72 static VectorType fwd_natural(
const VectorType& x1,
const VectorType& x2);
73 static VectorType fwd_centered(
const VectorType& x1,
const VectorType& x2);
74 static void bwd(
const IntervalVector& y, IntervalVector& x1, IntervalVector& x2);
76 static IntervalMatrix fwd(
const IntervalMatrix& x1,
const IntervalMatrix& x2);
77 static MatrixType fwd_natural(
const MatrixType& x1,
const MatrixType& x2);
78 static MatrixType fwd_centered(
const MatrixType& x1,
const MatrixType& x2);
79 static void bwd(
const IntervalMatrix& y, IntervalMatrix& x1, IntervalMatrix& x2);
88 return { std::make_shared<AnalyticOperationExpr<SubOp,ScalarType,ScalarType>>(x1) };
94 return { std::make_shared<AnalyticOperationExpr<SubOp,VectorType,VectorType>>(x1) };
100 return { std::make_shared<AnalyticOperationExpr<SubOp,MatrixType,MatrixType>>(x1) };
107 operator-(
const ScalarExpr& x1,
const ScalarExpr& x2)
109 return { std::make_shared<AnalyticOperationExpr<SubOp,ScalarType,ScalarType,ScalarType>>(x1,x2) };
113 operator-(
const VectorExpr& x1,
const VectorExpr& x2)
115 return { std::make_shared<AnalyticOperationExpr<SubOp,VectorType,VectorType,VectorType>>(x1,x2) };
119 operator-(
const MatrixExpr& x1,
const MatrixExpr& x2)
121 return { std::make_shared<AnalyticOperationExpr<SubOp,MatrixType,MatrixType,MatrixType>>(x1,x2) };
131 inline ScalarType SubOp::fwd_natural(
const ScalarType& x1)
139 inline ScalarType SubOp::fwd_centered(
const ScalarType& x1)
152 SubOp::bwd(y, x2_, x1);
155 inline IntervalVector SubOp::fwd(
const IntervalVector& x1)
160 inline VectorType SubOp::fwd_natural(
const VectorType& x1)
168 inline VectorType SubOp::fwd_centered(
const VectorType& x1)
178 inline void SubOp::bwd(
const IntervalVector& y, IntervalVector& x1)
180 assert(y.size() == x1.size());
181 for(Index i = 0 ; i < y.size() ; i++)
185 inline IntervalMatrix SubOp::fwd(
const IntervalMatrix& x1)
190 inline MatrixType SubOp::fwd_natural(
const MatrixType& x1)
198 inline MatrixType SubOp::fwd_centered(
const MatrixType& x1)
208 inline void SubOp::bwd(
const IntervalMatrix& y, IntervalMatrix& x1)
210 assert(y.size() == x1.size());
211 for(Index i = 0 ; i < y.size() ; i++)
212 SubOp::bwd(*(y.data()+i), *(x1.data()+i));
220 inline ScalarType SubOp::fwd_natural(
const ScalarType& x1,
const ScalarType& x2)
224 x1.def_domain && x2.def_domain
228 inline ScalarType SubOp::fwd_centered(
const ScalarType& x1,
const ScalarType& x2)
230 if(centered_form_not_available_for_args(x1,x2))
231 return fwd_natural(x1,x2);
233 assert(x1.da.rows() == x2.da.rows() && x1.da.cols() == x2.da.cols());
238 x1.def_domain && x2.def_domain
244 if((x1 &= y+x2).is_empty())
247 else if((x2 &= x1-y).is_empty())
251 inline IntervalVector SubOp::fwd(
const IntervalVector& x1,
const IntervalVector& x2)
253 assert(x1.size() == x2.size());
257 inline VectorType SubOp::fwd_natural(
const VectorType& x1,
const VectorType& x2)
261 x1.def_domain && x2.def_domain
265 inline VectorType SubOp::fwd_centered(
const VectorType& x1,
const VectorType& x2)
267 if(centered_form_not_available_for_args(x1,x2))
268 return fwd_natural(x1,x2);
270 assert(x1.da.rows() == x2.da.rows() && x1.da.cols() == x2.da.cols());
275 x1.def_domain && x2.def_domain
279 inline void SubOp::bwd(
const IntervalVector& y, IntervalVector& x1, IntervalVector& x2)
281 assert(y.size() == x1.size() && y.size() == x2.size());
282 for(Index i = 0 ; i < y.size() ; i++)
283 SubOp::bwd(y[i], x1[i], x2[i]);
286 inline IntervalMatrix SubOp::fwd(
const IntervalMatrix& x1,
const IntervalMatrix& x2)
288 assert(x1.size() == x2.size());
292 inline MatrixType SubOp::fwd_natural(
const MatrixType& x1,
const MatrixType& x2)
294 assert(x1.a.cols() == x2.a.cols() && x1.a.rows() == x2.a.rows());
297 x1.def_domain && x2.def_domain
301 inline MatrixType SubOp::fwd_centered(
const MatrixType& x1,
const MatrixType& x2)
303 assert(x1.a.cols() == x2.a.cols() && x1.a.rows() == x2.a.rows());
308 x1.def_domain && x2.def_domain
312 inline void SubOp::bwd(
const IntervalMatrix& y, IntervalMatrix& x1, IntervalMatrix& x2)
314 assert(y.size() == x1.size() && y.size() == x2.size());
315 for(Index i = 0 ; i < y.size() ; i++)
316 SubOp::bwd(*(y.data()+i), *(x1.data()+i), *(x2.data()+i));
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:62
Interval operator-(const Interval &x, double y)
Returns with .
Definition codac2_Interval_impl.h:389