21 template<
typename X1,
typename X2>
22 static std::string str(
const X1& x1,
const X2& x2)
24 return "(" + x1->str(!x1->is_str_leaf()) +
")^(" + x2->str(!x2->is_str_leaf()) +
")";
27 template<
typename X1,
typename X2>
28 static std::pair<Index,Index> output_shape([[maybe_unused]]
const X1& s1, [[maybe_unused]]
const X2& s2)
33 static Interval fwd(
const Interval& x1,
const Interval& x2);
34 static ScalarType fwd_natural(
const ScalarType& x1,
const ScalarType& x2);
35 static ScalarType fwd_centered(
const ScalarType& x1,
const ScalarType& x2);
36 static void bwd(
const Interval& y, Interval& x1,
int x2);
37 static void bwd(
const Interval& y, Interval& x1, Interval& x2);
44 pow(
const ScalarExpr& x1,
const ScalarExpr& x2)
46 auto x2_as_const_value = std::dynamic_pointer_cast<ConstValueExpr<ScalarType>>(x2->copy());
47 if(x2_as_const_value && x2_as_const_value->value() == 2.)
50 return { std::make_shared<AnalyticOperationExpr<SqrOp,ScalarType,ScalarType>>(x1) };
53 return { std::make_shared<AnalyticOperationExpr<PowOp,ScalarType,ScalarType,ScalarType>>(x1,x2) };
57 operator^(
const ScalarExpr& x1,
const ScalarExpr& x2)
60 <<
"Operator '^' is discouraged in Codac. Use pow(x,y), or sqr(x) instead."
72 inline ScalarType PowOp::fwd_natural(
const ScalarType& x1,
const ScalarType& x2)
74 bool x2isint = x2.a.is_integer();
75 bool x2positive = x2.a.lb()>=0.0;
78 x1.def_domain && x2.def_domain
79 && (x2isint || x1.a.lb()>=0.0)
80 && (x2positive || !x1.a.contains(0.0))
84 inline ScalarType PowOp::fwd_centered(
const ScalarType& x1,
const ScalarType& x2)
86 if(centered_form_not_available_for_args(x1,x2))
87 return fwd_natural(x1,x2);
89 bool x2isint = x2.a.is_integer();
90 bool x2positive = x2.a.lb()>=0.0;
93 if (x2.a.is_degenerated())
96 for(Index i = 0 ; i < d.size() ; i++)
97 d(0,i) = x2.a*x1.da(0,i)*
pow(x1.a,x2.a-1.);
102 for(Index i = 0 ; i < d.size() ; i++)
104 d(0,i) = x2.a*x1.da(0,i)*
pow(x1.a,x2.a-1.)
105 + x2.da(0,i)*
log(x1.a)*
pow(x1.a,x2.a);
114 x1.def_domain && x2.def_domain
115 && (x2isint || x1.a.lb()>=0.0)
116 && (x2positive || !x1.a.contains(0.0))
128 Interval proj =
root(y, x2);
129 Interval pos_proj = proj & x1;
130 Interval neg_proj = (-proj) & x1;
131 x1 = pos_proj | neg_proj;
140 assert_release(x2.is_degenerated() &&
"PowOp::bwd(y,x1,x2) (with x1 and x2 intervals) not implemented yet with Gaol");
141 assert_release(x2 == (
int)(x2.mid()) &&
"PowOp::bwd(y,x1,x2) (x2 not integer) not implemented yet with Gaol");
142 PowOp::bwd(y, x1, x2.mid());
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:49
Definition codac2_OctaSym.h:21
Interval pow(const Interval &x, int n)
Returns , .
Definition codac2_Interval_operations_impl.h:33
Interval log(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:85
Interval root(const Interval &x, int p)
Returns the p-th root: .
Definition codac2_Interval_operations_impl.h:60
Eigen::Matrix< Interval,-1,-1 > IntervalMatrix
Alias for a dynamic-size matrix of intervals.
Definition codac2_IntervalMatrix.h:25