CMS 3D CMS Logo

SimplifyPower.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_Utilities_SimplifyPower_h
2 #define PhysicsTools_Utilities_SimplifyPower_h
3 
10 
12 
13 namespace funct {
14 
15  // a ^ 1 = a
16  POWER_RULE(TYPT1, A, NUM(1), A, _1);
17 
18  // a ^ -1 = 1 / a
19  POWER_RULE(TYPT1, A, NUM(-1), RATIO(NUM(1), A), num<1>() / _1);
20 
21  // a ^ 1/2 = sqrt(a)
22  POWER_RULE(TYPT1, A, FRACT_S(1, 2), SQRT(A), sqrt(_1));
23 
24  // a ^ 0 = 1
25  POWER_RULE(TYPT1, A, NUM(0), NUM(1), num<1>());
26 
27  // (a * b)^ 0 = 1
28  POWER_RULE(TYPT2, PROD_S(A, B), NUM(0), NUM(1), num<1>());
29 
30  // (a ^ b) ^ c = a ^ (b + c)
31  POWER_RULE(TYPT3, POWER_S(A, B), C, POWER(A, SUM(B, C)), pow(_1._1, _1._2 + _2));
32 
33  // (a ^ b) ^ n = a ^ (b + n)
34  POWER_RULE(TYPN1T2, POWER_S(A, B), NUM(n), POWER(A, SUM(B, NUM(n))), pow(_1._1, _1._2 + _2));
35 
36  // a ^ (-n) = 1 / a ^ n
37  template <TYPN1T1, bool positive = (n >= 0)>
39  typedef POWER_S(A, NUM(n)) type;
40  COMBINE(A, NUM(n), type(_1, _2));
41  };
42 
43  TEMPL(N1T1) struct SimplifySignedPower<n, A, false> {
44  typedef RATIO(NUM(1), POWER(A, NUM(-n))) type;
45  COMBINE(A, NUM(n), num<1>() / pow(_1, num<-n>()));
46  };
47 
48  TEMPL(T1) struct SimplifySignedPower<0, A, true> {
49  typedef NUM(1) type;
50  COMBINE(A, NUM(0), num<1>());
51  };
52 
53  TEMPL(N1T1) struct Power<A, NUM(n)> : public SimplifySignedPower<n, A> {};
54 
55 } // namespace funct
56 
58 
59 #endif
SUM
#define SUM(A, B)
Definition: Simplify_begin.h:52
POWER_RULE
#define POWER_RULE(TMPL, T1, T2, RES, COMB)
Definition: Simplify_begin.h:109
POWER_S
#define POWER_S(A, B)
Definition: Simplify_begin.h:41
funct::false
false
Definition: Factorize.h:34
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
Ratio.h
Fraction.h
funct::PROD_S
PROD_S(B, C)>
Definition: Factorize.h:114
FRACT_S
#define FRACT_S(N, M)
Definition: Simplify_begin.h:42
funct::B
TEMPL(T2) struct Divides B
Definition: Factorize.h:29
DecomposePower.h
Power.h
funct::C
C
Definition: Factorize.h:133
funct::SimplifySignedPower
Definition: SimplifyPower.h:38
TYPT1
#define TYPT1
Definition: Simplify_begin.h:6
Sqrt.h
funct::POWER
typedef POWER(A, NUM(n)) arg
TYPT2
#define TYPT2
Definition: Simplify_begin.h:7
RATIO
#define RATIO(A, B)
Definition: Simplify_begin.h:56
funct::num
const Numerical< n > & num()
Definition: Numerical.h:18
funct::sqrt
Sqrt< T >::type sqrt(const T &t)
Definition: Sqrt.h:22
SQRT
#define SQRT(A)
Definition: Simplify_begin.h:59
funct::Power
Definition: Power.h:19
Sum.h
funct::true
true
Definition: Factorize.h:173
funct::SimplifySignedPower::type
PowerStruct< A, Numerical< n > > type
Definition: SimplifyPower.h:39
A
funct::type
arg type
Definition: Factorize.h:37
funct::TEMPL
TEMPL(T1) struct Divides0
Definition: Factorize.h:20
TYPN1T2
#define TYPN1T2
Definition: Simplify_begin.h:17
Simplify_end.h
funct::NUM
PROD_S(A, B)> NUM(n))
Definition: Factorize.h:87
COMBINE
#define COMBINE(A, B, RES)
Definition: Simplify_begin.h:70
TYPT3
#define TYPT3
Definition: Simplify_begin.h:8
funct::SimplifySignedPower< n, A, false >::type
Ratio< Numerical< 1 >, typename Power< A, Numerical< -n > >::type >::type type
Definition: SimplifyPower.h:44
funct::Numerical
Definition: Numerical.h:7
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
Simplify_begin.h
funct
Definition: Abs.h:5