23 template<
typename X1,
typename X2>
24 static std::string str(
const X1& x1,
const X2& x2)
26 return x1->str(!x1->is_str_leaf()) +
"/" + x2->str(!x2->is_str_leaf());
29 template<
typename X1,
typename X2>
30 static std::pair<Index,Index> output_shape(
const X1& s1,
const X2& s2)
32 auto shape1=s1->output_shape();
33 auto shape2=s2->output_shape();
34 assert_release(shape2.first == 1 && shape2.second == 1);
38 static Interval fwd(
const Interval& x1,
const Interval& x2);
39 static ScalarType fwd_natural(
const ScalarType& x1,
const ScalarType& x2);
40 static ScalarType fwd_centered(
const ScalarType& x1,
const ScalarType& x2);
41 static void bwd(
const Interval& y, Interval& x1, Interval& x2);
43 static IntervalVector fwd(
const IntervalVector& x1,
const Interval& x2);
44 static VectorType fwd_natural(
const VectorType& x1,
const ScalarType& x2);
45 static VectorType fwd_centered(
const VectorType& x1,
const ScalarType& x2);
46 static void bwd(
const IntervalVector& y, IntervalVector& x1, Interval& x2);
48 static IntervalMatrix fwd(
const IntervalMatrix& x1,
const Interval& x2);
49 static MatrixType fwd_natural(
const MatrixType& x1,
const ScalarType& x2);
50 static MatrixType fwd_centered(
const MatrixType& x1,
const ScalarType& x2);
51 static void bwd(
const IntervalMatrix& y, IntervalMatrix& x1, Interval& x2);
58 operator/(
const ScalarExpr& x1,
const ScalarExpr& x2)
60 return { std::make_shared<AnalyticOperationExpr<DivOp,ScalarType,ScalarType,ScalarType>>(x1,x2) };
64 operator/(
const VectorExpr& x1,
const ScalarExpr& x2)
66 return { std::make_shared<AnalyticOperationExpr<DivOp,VectorType,VectorType,ScalarType>>(x1,x2) };
70 operator/(
const MatrixExpr& x1,
const ScalarExpr& x2)
72 return { std::make_shared<AnalyticOperationExpr<DivOp,MatrixType,MatrixType,ScalarType>>(x1,x2) };
82 inline ScalarType DivOp::fwd_natural(
const ScalarType& x1,
const ScalarType& x2)
86 x1.def_domain && x2.def_domain && x2.a != 0.
90 inline ScalarType DivOp::fwd_centered(
const ScalarType& x1,
const ScalarType& x2)
92 if(centered_form_not_available_for_args(x1,x2))
93 return fwd_natural(x1,x2);
95 assert(x1.da.size() == x2.da.size());
97 IntervalMatrix d(1,x1.da.size());
98 for(Index i = 0 ; i < d.size() ; i++)
99 d(0,i) = (x1.da(0,i)*x2.a-x1.a*x2.da(0,i))/
sqr(x2.a);
105 x1.def_domain && x2.def_domain && x2.a != 0.
111 if((x1 &= y*x2).is_empty())
117 MulOp::bwd(x1, tmp, x2);
123 inline IntervalVector DivOp::fwd(
const IntervalVector& x1,
const Interval& x2)
128 inline VectorType DivOp::fwd_natural(
const VectorType& x1,
const ScalarType& x2)
132 x1.def_domain && x2.def_domain && x2.a != 0.
136 inline VectorType DivOp::fwd_centered(
const VectorType& x1,
const ScalarType& x2)
138 if(centered_form_not_available_for_args(x1,x2))
139 return fwd_natural(x1,x2);
141 assert(x2.da.rows() == 1);
142 assert(x1.da.cols() == x2.da.cols());
144 IntervalMatrix d(x1.da.rows(),x1.da.cols());
145 for(Index j = 0 ; j < d.cols() ; j++)
146 for(Index i = 0 ; i < d.rows() ; i++)
147 d(i,j) = x1.da(i,j)/x2.a - x1.a[i]*x2.da(0,j)/
sqr(x2.a);
153 x1.def_domain && x2.def_domain && x2.a != 0.
157 inline void DivOp::bwd(
const IntervalVector& y, IntervalVector& x1,
Interval& x2)
159 assert(x1.size() == y.size());
160 for(Index i = 0 ; i < x1.size() ; i++)
161 DivOp::bwd(y[i], x1[i], x2);
164 inline IntervalMatrix DivOp::fwd(
const IntervalMatrix& x1,
const Interval& x2)
169 inline MatrixType DivOp::fwd_natural(
const MatrixType& x1,
const ScalarType& x2)
173 x1.def_domain && x2.def_domain && x2.a != 0.
177 inline MatrixType DivOp::fwd_centered(
const MatrixType& x1,
const ScalarType& x2)
179 if(centered_form_not_available_for_args(x1,x2))
180 return fwd_natural(x1,x2);
182 assert(x2.da.rows() == 1);
183 assert(x1.da.cols() == x2.da.cols());
185 IntervalMatrix d(x1.da.rows(),x1.da.cols());
186 for(Index j = 0 ; j < d.cols() ; j++)
187 for(Index i = 0 ; i < d.rows() ; i++)
188 d(i,j) = x1.da(i,j)/x2.a -
189 x1.a.reshaped<Eigen::ColMajor>()[i]*x2.da(0,j)/
sqr(x2.a);
195 x1.def_domain && x2.def_domain && x2.a != 0.
199 inline void DivOp::bwd(
const IntervalMatrix& y, IntervalMatrix& x1,
Interval& x2)
201 assert(x1.cols() == y.cols() && x1.rows() == y.rows());
202 for(Index j = 0 ; j < x1.cols() ; j++)
203 for(Index i = 0 ; i < x1.rows() ; i++)
204 DivOp::bwd(y(i,j), x1(i,j), x2);
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:435
Interval sqr(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:21