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
const Numerical< n > & num()
Definition: Numerical.h:18
typedef POWER(A, NUM(n)) arg
Definition: Abs.h:5
#define TYPT2
Definition: Simplify_begin.h:7
PROD_S(B, C)>
Definition: Factorize.h:114
TEMPL(T2) struct Divides B
Definition: Factorize.h:24
Sqrt< T >::type sqrt(const T &t)
Definition: Sqrt.h:22
#define FRACT_S(N, M)
#define RATIO(A, B)
#define TYPN1T2
PowerStruct< A, Numerical< n > > type
Definition: SimplifyPower.h:39
#define SUM(A, B)
TEMPL(T1) struct Divides0
Definition: Factorize.h:15
#define SQRT(A)
Ratio< Numerical< 1 >, typename Power< A, Numerical< -n > >::type >::type type
Definition: SimplifyPower.h:44
arg type
Definition: Factorize.h:32
#define POWER_RULE(TMPL, T1, T2, RES, COMB)
#define TYPT3
Definition: Simplify_begin.h:8
#define COMBINE(A, B, RES)
PROD_S(A, B)> NUM(n))
Definition: Factorize.h:87
#define POWER_S(A, B)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
#define TYPT1
Definition: Simplify_begin.h:6