26 static std::string str(
const X1& x1)
28 return "det(" + x1->str() +
")";
31 template<
typename X1,
typename X2>
32 static std::string str(
const X1& x1,
const X2& x2)
34 return "det(" + x1->str() +
"," + x2->str() +
")";
37 template<
typename X1,
typename X2,
typename X3>
38 static std::string str(
const X1& x1,
const X2& x2,
const X3& x3)
40 return "det(" + x1->str() +
"," + x2->str() +
"," + x3->str() +
")";
45 static std::pair<Index,Index> output_shape([[maybe_unused]]
const X1& s1)
51 static ScalarType fwd_natural(
const MatrixType& x);
52 static ScalarType fwd_centered(
const MatrixType& x);
56 template<
typename X1,
typename X2>
57 static std::pair<Index,Index> output_shape([[maybe_unused]]
const X1& s1, [[maybe_unused]]
const X2& s2)
63 static ScalarType fwd_natural(
const VectorType& x1,
const VectorType& x2);
64 static ScalarType fwd_centered(
const VectorType& x1,
const VectorType& x2);
68 template<
typename X1,
typename X2,
typename X3>
69 static std::pair<Index,Index> output_shape([[maybe_unused]]
const X1& s1, [[maybe_unused]]
const X2& s2, [[maybe_unused]]
const X3& s3)
75 static ScalarType fwd_natural(
const VectorType& x1,
const VectorType& x2,
const VectorType& x3);
76 static ScalarType fwd_centered(
const VectorType& x1,
const VectorType& x2,
const VectorType& x3);
84 det(
const MatrixExpr& x1)
86 return { std::make_shared<AnalyticOperationExpr<DetOp,ScalarType,MatrixType>>(x1) };
90 det(
const VectorExpr& x1,
const VectorExpr& x2)
92 return { std::make_shared<AnalyticOperationExpr<DetOp,ScalarType,VectorType,VectorType>>(x1,x2) };
96 det(
const VectorExpr& x1,
const VectorExpr& x2,
const VectorExpr& x3)
98 return { std::make_shared<AnalyticOperationExpr<DetOp,ScalarType,VectorType,VectorType,VectorType>>(x1,x2,x3) };
105 assert_release(x.is_squared() &&
"can only compute determinants for a square matrix");
111 else if(x.rows() == 2)
112 return x(0,0)*x(1,1)-x(0,1)*x(1,0);
120 inline ScalarType DetOp::fwd_natural(
const MatrixType& x)
128 inline ScalarType DetOp::fwd_centered(
const MatrixType& x)
130 if(centered_form_not_available_for_args(x))
131 return fwd_natural(x);
144 for (Index i=0; i < d.cols() ; i++) {
145 d(0,i) = x.da(0,i)*x.a(1,1) + x.da(3,i)*x.a(0,0)
146 - x.da(1,i)*x.a(0,1) - x.da(2,i)*x.a(1,0);
157 for (Index i=0; i < d.cols() ; i++)
158 d(0,i) = ret1.first.reshaped<Eigen::ColMajor>().dot(x.da.col(i));
171 assert_release(x.is_squared() &&
"can only compute determinants for a square matrix");
177 else if(x.rows() == 2)
179 Interval z1 = x(0,0)*x(1,1), z2 = x(1,0)*x(0,1);
180 SubOp::bwd(y, z1, z2);
181 MulOp::bwd(z1, x(0,0), x(1,1));
182 MulOp::bwd(z2, x(1,0), x(0,1));
188 if (ret.second.is_disjoint(y)) x.set_empty();
195 assert_release(x1.size() == 2 && x2.size() == 2 &&
"determinant only computable for pairs of 2d vectors");
197 m.col(0) = x1; m.col(1) = x2;
198 return DetOp::fwd(m);
201 inline ScalarType DetOp::fwd_natural(
const VectorType& x1,
const VectorType& x2)
204 a.col(0) = x1.a; a.col(1) = x2.a;
208 x1.def_domain && x2.def_domain
212 inline ScalarType DetOp::fwd_centered(
const VectorType& x1,
const VectorType& x2)
214 if(centered_form_not_available_for_args(x1,x2))
215 return fwd_natural(x1,x2);
218 m.col(0) = x1.m; m.col(1) = x2.m;
220 a.col(0) = x1.a; a.col(1) = x2.a;
222 assert(x1.da.cols() == x2.da.cols());
224 for (Index i=0; i < d.cols() ; i++) {
225 d(0,i) = x1.da(0,i)*x2.a[1] + x1.a[0]*x2.da(1,i)
226 - x1.da(1,i)*x2.a[0] - x1.a[1]*x2.da(0,i);
233 x1.def_domain && x2.def_domain
239 assert_release(x1.size() == 2 && x2.size() == 2 &&
"determinant only computable for pairs of 2d vectors");
241 m.col(0) = x1; m.col(1) = x2;
249 assert_release(x1.size() == 3 && x2.size() == 3 && x3.size() == 3 &&
"determinant only computable for triplet of 3d vectors");
251 m.col(0) = x1; m.col(1) = x2; m.col(2) = x3;
252 return DetOp::fwd(m);
255 inline ScalarType DetOp::fwd_natural(
const VectorType& x1,
const VectorType& x2,
const VectorType& x3)
258 a.col(0) = x1.a; a.col(1) = x2.a; a.col(2) = x3.a;
262 x1.def_domain && x2.def_domain && x3.def_domain
266 inline ScalarType DetOp::fwd_centered(
const VectorType& x1,
const VectorType& x2,
const VectorType& x3)
268 if(centered_form_not_available_for_args(x1,x2,x3))
269 return fwd_natural(x1,x2,x3);
272 m.col(0) = x1.m; m.col(1) = x2.m; m.col(2) = x3.m;
274 a.col(0) = x1.a; a.col(1) = x2.a; a.col(2) = x3.a;
276 assert(x1.da.cols() == x2.da.cols());
277 assert(x1.da.cols() == x3.da.cols());
280 for (Index i=0; i < d.cols() ; i++) {
281 d(0,i) = ret1.first.col(0).dot(x1.da.col(i));
282 d(0,i) += ret1.first.col(1).dot(x2.da.col(i));
283 d(0,i) += ret1.first.col(2).dot(x3.da.col(i));
289 x1.def_domain && x2.def_domain && x3.def_domain
295 assert_release(x1.size() == 3 && x2.size() == 3 && x3.size() == 3 &&
"determinant only computable for triplet of 3d vectors");
298 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:50
Definition codac2_OctaSym.h:21
std::pair< IntervalMatrix, Interval > cofactor_matrix_enclosure(const Eigen::MatrixBase< OtherDerived > &A)
compute the interval cofactor matrix, as well as the determinant, of a square matrix
Definition codac2_inversion.h:130
Eigen::Matrix< Interval,-1, 1 > IntervalVector
Alias for a dynamic-size column vector of intervals.
Definition codac2_IntervalVector.h:25
Eigen::Matrix< Interval,-1,-1 > IntervalMatrix
Alias for a dynamic-size matrix of intervals.
Definition codac2_IntervalMatrix.h:25