25 static std::string str(
const X1& x1)
27 return "det(" + x1->str() +
")";
30 template<
typename X1,
typename X2>
31 static std::string str(
const X1& x1,
const X2& x2)
33 return "det(" + x1->str() +
"," + x2->str() +
")";
36 template<
typename X1,
typename X2,
typename X3>
37 static std::string str(
const X1& x1,
const X2& x2,
const X3& x3)
39 return "det(" + x1->str() +
"," + x2->str() +
"," + x3->str() +
")";
44 static std::pair<Index,Index> output_shape([[maybe_unused]]
const X1& s1) {
47 static Interval fwd(
const IntervalMatrix& x);
48 static ScalarType fwd_natural(
const MatrixType& x);
49 static ScalarType fwd_centered(
const MatrixType& x);
50 static void bwd(
const Interval& y, IntervalMatrix& x);
53 template<
typename X1,
typename X2>
54 static std::pair<Index,Index> output_shape([[maybe_unused]]
const X1& s1, [[maybe_unused]]
const X2& s2) {
57 static Interval fwd(
const IntervalVector& x1,
const IntervalVector& x2);
58 static ScalarType fwd_natural(
const VectorType& x1,
const VectorType& x2);
59 static ScalarType fwd_centered(
const VectorType& x1,
const VectorType& x2);
60 static void bwd(
const Interval& y, IntervalVector& x1, IntervalVector& x2);
63 template<
typename X1,
typename X2,
typename X3>
64 static std::pair<Index,Index> output_shape([[maybe_unused]]
const X1& s1, [[maybe_unused]]
const X2& s2, [[maybe_unused]]
const X3& s3) {
67 static Interval fwd(
const IntervalVector& x1,
const IntervalVector& x2,
const IntervalVector& x3);
68 static ScalarType fwd_natural(
const VectorType& x1,
const VectorType& x2,
const VectorType& x3);
69 static ScalarType fwd_centered(
const VectorType& x1,
const VectorType& x2,
const VectorType& x3);
70 static void bwd(
const Interval& y, IntervalVector& x1, IntervalVector& x2, IntervalVector& x3);
77 det(
const MatrixExpr& x1)
79 return { std::make_shared<AnalyticOperationExpr<DetOp,ScalarType,MatrixType>>(x1) };
83 det(
const VectorExpr& x1,
const VectorExpr& x2)
85 return { std::make_shared<AnalyticOperationExpr<DetOp,ScalarType,VectorType,VectorType>>(x1,x2) };
89 det(
const VectorExpr& x1,
const VectorExpr& x2,
const VectorExpr& x3)
91 return { std::make_shared<AnalyticOperationExpr<DetOp,ScalarType,VectorType,VectorType,VectorType>>(x1,x2,x3) };
96 inline Interval DetOp::fwd(
const IntervalMatrix& x)
98 assert_release(x.is_squared() &&
"can only compute determinants for a square matrix");
99 assert_release((x.rows() == 1 || x.rows() == 2) &&
"determinant not yet computable for n×n matrices, n>2");
104 else if(x.rows() == 2)
105 return x(0,0)*x(1,1)-x(0,1)*x(1,0);
111 inline ScalarType DetOp::fwd_natural(
const MatrixType& x)
119 inline ScalarType DetOp::fwd_centered(
const MatrixType& x)
121 if(centered_form_not_available_for_args(x))
122 return fwd_natural(x);
133 IntervalMatrix d(1, x.da.cols());
135 for (Index i=0; i < d.cols() ; i++) {
136 d(0,i) = x.da(0,i)*x.a(1,1) + x.da(3,i)*x.a(0,0)
137 - x.da(1,i)*x.a(0,1) - x.da(2,i)*x.a(1,0);
150 inline void DetOp::bwd(
const Interval& y, IntervalMatrix& x)
152 assert_release(x.is_squared() &&
"can only compute determinants for a square matrix");
153 assert_release((x.rows() == 1 || x.rows() == 2) &&
"determinant not yet computable for n×n matrices, n>2");
158 else if(x.rows() == 2)
160 Interval z1 = x(0,0)*x(1,1), z2 = x(1,0)*x(0,1);
161 SubOp::bwd(y, z1, z2);
162 MulOp::bwd(z1, x(0,0), x(1,1));
163 MulOp::bwd(z2, x(1,0), x(0,1));
172 inline Interval DetOp::fwd(
const IntervalVector& x1,
const IntervalVector& x2)
174 assert_release(x1.size() == 2 && x2.size() == 2 &&
"determinant only computable for pairs of 2d vectors");
175 IntervalMatrix m(2,2);
176 m.col(0) = x1; m.col(1) = x2;
177 return DetOp::fwd(m);
180 inline ScalarType DetOp::fwd_natural(
const VectorType& x1,
const VectorType& x2)
182 IntervalMatrix a(2,2);
183 a.col(0) = x1.a; a.col(1) = x2.a;
187 x1.def_domain && x2.def_domain
191 inline ScalarType DetOp::fwd_centered(
const VectorType& x1,
const VectorType& x2)
193 if(centered_form_not_available_for_args(x1,x2))
194 return fwd_natural(x1,x2);
196 IntervalMatrix m(2,2);
197 m.col(0) = x1.m; m.col(1) = x2.m;
198 IntervalMatrix a(2,2);
199 a.col(0) = x1.a; a.col(1) = x2.a;
201 assert(x1.da.cols() == x2.da.cols());
202 IntervalMatrix d(1, x1.da.cols());
203 for (Index i=0; i < d.cols() ; i++) {
204 d(0,i) = x1.da(0,i)*x2.a[1] + x1.a[0]*x2.da(1,i)
205 - x1.da(1,i)*x2.a[0] - x1.a[1]*x2.da(0,i);
212 x1.def_domain && x2.def_domain
216 inline void DetOp::bwd(
const Interval& y, IntervalVector& x1, IntervalVector& x2)
218 assert_release(x1.size() == 2 && x2.size() == 2 &&
"determinant only computable for pairs of 2d vectors");
219 IntervalMatrix m(2,2);
220 m.col(0) = x1; m.col(1) = x2;
226 inline Interval DetOp::fwd(
const IntervalVector& x1,
const IntervalVector& x2,
const IntervalVector& x3)
228 assert_release(x1.size() == 3 && x2.size() == 3 && x3.size() == 3 &&
"determinant only computable for triplet of 3d vectors");
229 IntervalMatrix m(3,3);
230 m.col(0) = x1; m.col(1) = x2; m.col(2) = x3;
231 return DetOp::fwd(m);
234 inline ScalarType DetOp::fwd_natural(
const VectorType& x1,
const VectorType& x2,
const VectorType& x3)
236 IntervalMatrix a(3,3);
237 a.col(0) = x1.a; a.col(1) = x2.a; a.col(2) = x3.a;
241 x1.def_domain && x2.def_domain && x3.def_domain
245 inline ScalarType DetOp::fwd_centered(
const VectorType& x1,
const VectorType& x2,
const VectorType& x3)
247 if(centered_form_not_available_for_args(x1,x2,x3))
248 return fwd_natural(x1,x2,x3);
250 IntervalMatrix m(3,3);
251 m.col(0) = x1.m; m.col(1) = x2.m; m.col(2) = x3.m;
252 IntervalMatrix a(3,3);
253 a.col(0) = x1.a; a.col(1) = x2.a; a.col(2) = x3.a;
259 x1.def_domain && x2.def_domain && x3.def_domain
263 inline void DetOp::bwd(
const Interval& y, IntervalVector& x1, IntervalVector& x2, IntervalVector& x3)
265 assert_release(x1.size() == 3 && x2.size() == 3 && x3.size() == 3 &&
"determinant only computable for triplet of 3d vectors");
267 IntervalMatrix m(3,3);
268 m.col(0) = x1; m.col(1) = x2; m.col(2) = x3;
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:62
static Interval empty()
Provides an empty interval.
Definition codac2_Interval_impl.h:535