codac 1.5.6
Loading...
Searching...
No Matches
codac2_pow.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include "codac2_Interval.h"
13#include "codac2_AnalyticType.h"
15
16namespace codac2
17{
18 struct PowOp
19 {
20 static Interval fwd(const Interval& x1, const Interval& x2);
21 static ScalarType fwd_natural(const ScalarType& x1, const ScalarType& x2);
22 static ScalarType fwd_centered(const ScalarType& x1, const ScalarType& x2);
23 static void bwd(const Interval& y, Interval& x1, int x2);
24 static void bwd(const Interval& y, Interval& x1, Interval& x2);
25 };
26
27 // Analytic operator
28 // The following function can be used to build analytic expressions.
29
30 inline ScalarExpr
31 pow(const ScalarExpr& x1, const ScalarExpr& x2)
32 {
33 return { std::make_shared<AnalyticOperationExpr<PowOp,ScalarType,ScalarType,ScalarType>>(x1,x2) };
34 }
35
36 inline ScalarExpr
37 operator^(const ScalarExpr& x1, const ScalarExpr& x2)
38 {
39 return { std::make_shared<AnalyticOperationExpr<PowOp,ScalarType,ScalarType,ScalarType>>(x1,x2) };
40 }
41
42 // Inline functions
43
44 inline Interval PowOp::fwd(const Interval& x1, const Interval& x2)
45 {
46 return pow(x1,x2);
47 }
48
49 inline ScalarType PowOp::fwd_natural(const ScalarType& x1, const ScalarType& x2)
50 {
51 return {
52 fwd(x1.a, x2.a),
53 x1.def_domain && x2.def_domain
54 };
55 }
56
57 inline ScalarType PowOp::fwd_centered(const ScalarType& x1, const ScalarType& x2)
58 {
59 if(centered_form_not_available_for_args(x1,x2))
60 return fwd_natural(x1,x2);
61
62 IntervalMatrix d(1,x1.da.size());
63 for(Index i = 0 ; i < d.size() ; i++)
64 d(0,i) = x2.a*x1.da(0,i)*pow(x1.a,x2.a-1.);
65
66 return {
67 fwd(x1.m, x2.m),
68 fwd(x1.a, x2.a),
69 d,
70 x1.def_domain && x2.def_domain
71 };
72 }
73
74 inline void PowOp::bwd(const Interval& y, Interval& x1, int x2)
75 {
76 // The content of this function comes from the IBEX library.
77 // See ibex::Interval (IBEX lib, main author: Gilles Chabert)
78 // https://ibex-lib.readthedocs.io
79
80 if(x2 % 2 == 0)
81 {
82 Interval proj = root(y, x2);
83 Interval pos_proj = proj & x1;
84 Interval neg_proj = (-proj) & x1;
85 x1 = pos_proj | neg_proj;
86 }
87
88 else
89 x1 &= root(y, x2);
90 }
91
92 inline void PowOp::bwd(const Interval& y, Interval& x1, Interval& x2)
93 {
94 assert_release(x2.is_degenerated() && "PowOp::bwd(y,x1,x2) (with x1 and x2 intervals) not implemented yet with Gaol");
95 assert_release(x2 == (int)(x2.mid()) && "PowOp::bwd(y,x1,x2) (x2 not integer) not implemented yet with Gaol");
96 PowOp::bwd(y, x1, x2.mid());
97 }
98}
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:62
Interval pow(const Interval &x, int n)
Returns , .
Definition codac2_Interval_operations_impl.h:33
Interval root(const Interval &x, int p)
Returns the p-th root: .
Definition codac2_Interval_operations_impl.h:60