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)
49 static Interval fwd(
const IntervalMatrix& x);
50 static ScalarType fwd_natural(
const MatrixType& x);
51 static ScalarType fwd_centered(
const MatrixType& x);
52 static void bwd(
const Interval& y, IntervalMatrix& x);
55 template<
typename X1,
typename X2>
56 static std::pair<Index,Index> output_shape([[maybe_unused]]
const X1& s1, [[maybe_unused]]
const X2& s2)
61 static Interval fwd(
const IntervalVector& x1,
const IntervalVector& x2);
62 static ScalarType fwd_natural(
const VectorType& x1,
const VectorType& x2);
63 static ScalarType fwd_centered(
const VectorType& x1,
const VectorType& x2);
64 static void bwd(
const Interval& y, IntervalVector& x1, IntervalVector& x2);
67 template<
typename X1,
typename X2,
typename X3>
68 static std::pair<Index,Index> output_shape([[maybe_unused]]
const X1& s1, [[maybe_unused]]
const X2& s2, [[maybe_unused]]
const X3& s3)
73 static Interval fwd(
const IntervalVector& x1,
const IntervalVector& x2,
const IntervalVector& x3);
74 static ScalarType fwd_natural(
const VectorType& x1,
const VectorType& x2,
const VectorType& x3);
75 static ScalarType fwd_centered(
const VectorType& x1,
const VectorType& x2,
const VectorType& x3);
76 static void bwd(
const Interval& y, IntervalVector& x1, IntervalVector& x2, IntervalVector& x3);
83 det(
const MatrixExpr& x1)
85 return { std::make_shared<AnalyticOperationExpr<DetOp,ScalarType,MatrixType>>(x1) };
89 det(
const VectorExpr& x1,
const VectorExpr& x2)
91 return { std::make_shared<AnalyticOperationExpr<DetOp,ScalarType,VectorType,VectorType>>(x1,x2) };
95 det(
const VectorExpr& x1,
const VectorExpr& x2,
const VectorExpr& x3)
97 return { std::make_shared<AnalyticOperationExpr<DetOp,ScalarType,VectorType,VectorType,VectorType>>(x1,x2,x3) };
102 inline Interval DetOp::fwd(
const IntervalMatrix& x)
104 assert_release(x.is_squared() &&
"can only compute determinants for a square matrix");
105 assert_release((x.rows() == 1 || x.rows() == 2) &&
"determinant not yet computable for n×n matrices, n>2");
110 else if(x.rows() == 2)
111 return x(0,0)*x(1,1)-x(0,1)*x(1,0);
117 inline ScalarType DetOp::fwd_natural(
const MatrixType& x)
125 inline ScalarType DetOp::fwd_centered(
const MatrixType& x)
127 if(centered_form_not_available_for_args(x))
128 return fwd_natural(x);
139 IntervalMatrix d(1, x.da.cols());
141 for (Index i=0; i < d.cols() ; i++) {
142 d(0,i) = x.da(0,i)*x.a(1,1) + x.da(3,i)*x.a(0,0)
143 - x.da(1,i)*x.a(0,1) - x.da(2,i)*x.a(1,0);
156 inline void DetOp::bwd(
const Interval& y, IntervalMatrix& x)
158 assert_release(x.is_squared() &&
"can only compute determinants for a square matrix");
159 assert_release((x.rows() == 1 || x.rows() == 2) &&
"determinant not yet computable for n×n matrices, n>2");
164 else if(x.rows() == 2)
166 Interval z1 = x(0,0)*x(1,1), z2 = x(1,0)*x(0,1);
167 SubOp::bwd(y, z1, z2);
168 MulOp::bwd(z1, x(0,0), x(1,1));
169 MulOp::bwd(z2, x(1,0), x(0,1));
178 inline Interval DetOp::fwd(
const IntervalVector& x1,
const IntervalVector& x2)
180 assert_release(x1.size() == 2 && x2.size() == 2 &&
"determinant only computable for pairs of 2d vectors");
181 IntervalMatrix m(2,2);
182 m.col(0) = x1; m.col(1) = x2;
183 return DetOp::fwd(m);
186 inline ScalarType DetOp::fwd_natural(
const VectorType& x1,
const VectorType& x2)
188 IntervalMatrix a(2,2);
189 a.col(0) = x1.a; a.col(1) = x2.a;
193 x1.def_domain && x2.def_domain
197 inline ScalarType DetOp::fwd_centered(
const VectorType& x1,
const VectorType& x2)
199 if(centered_form_not_available_for_args(x1,x2))
200 return fwd_natural(x1,x2);
202 IntervalMatrix m(2,2);
203 m.col(0) = x1.m; m.col(1) = x2.m;
204 IntervalMatrix a(2,2);
205 a.col(0) = x1.a; a.col(1) = x2.a;
207 assert(x1.da.cols() == x2.da.cols());
208 IntervalMatrix d(1, x1.da.cols());
209 for (Index i=0; i < d.cols() ; i++) {
210 d(0,i) = x1.da(0,i)*x2.a[1] + x1.a[0]*x2.da(1,i)
211 - x1.da(1,i)*x2.a[0] - x1.a[1]*x2.da(0,i);
218 x1.def_domain && x2.def_domain
222 inline void DetOp::bwd(
const Interval& y, IntervalVector& x1, IntervalVector& x2)
224 assert_release(x1.size() == 2 && x2.size() == 2 &&
"determinant only computable for pairs of 2d vectors");
225 IntervalMatrix m(2,2);
226 m.col(0) = x1; m.col(1) = x2;
232 inline Interval DetOp::fwd(
const IntervalVector& x1,
const IntervalVector& x2,
const IntervalVector& x3)
234 assert_release(x1.size() == 3 && x2.size() == 3 && x3.size() == 3 &&
"determinant only computable for triplet of 3d vectors");
235 IntervalMatrix m(3,3);
236 m.col(0) = x1; m.col(1) = x2; m.col(2) = x3;
237 return DetOp::fwd(m);
240 inline ScalarType DetOp::fwd_natural(
const VectorType& x1,
const VectorType& x2,
const VectorType& x3)
242 IntervalMatrix a(3,3);
243 a.col(0) = x1.a; a.col(1) = x2.a; a.col(2) = x3.a;
247 x1.def_domain && x2.def_domain && x3.def_domain
251 inline ScalarType DetOp::fwd_centered(
const VectorType& x1,
const VectorType& x2,
const VectorType& x3)
253 if(centered_form_not_available_for_args(x1,x2,x3))
254 return fwd_natural(x1,x2,x3);
256 IntervalMatrix m(3,3);
257 m.col(0) = x1.m; m.col(1) = x2.m; m.col(2) = x3.m;
258 IntervalMatrix a(3,3);
259 a.col(0) = x1.a; a.col(1) = x2.a; a.col(2) = x3.a;
265 x1.def_domain && x2.def_domain && x3.def_domain
269 inline void DetOp::bwd(
const Interval& y, IntervalVector& x1, IntervalVector& x2, IntervalVector& x3)
271 assert_release(x1.size() == 3 && x2.size() == 3 && x3.size() == 3 &&
"determinant only computable for triplet of 3d vectors");
273 IntervalMatrix m(3,3);
274 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:551