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))),
35  pow(_1._1, _1._2 + _2));
36 
37  // a ^ (-n) = 1 / a ^ n
38  template<TYPN1T1, bool positive = (n>= 0)>
40  typedef POWER_S(A, NUM(n)) type;
41  COMBINE(A, NUM(n), type(_1, _2));
42  };
43 
44  TEMPL(N1T1) struct SimplifySignedPower<n, A, false> {
45  typedef RATIO(NUM(1), POWER(A, NUM(- n))) type;
46  COMBINE(A, NUM(n), num<1>() / pow(_1, num<-n>()));
47  };
48 
49  TEMPL(T1) struct SimplifySignedPower<0, A, true> {
50  typedef NUM(1) type;
51  COMBINE(A, NUM(0), num<1>());
52  };
53 
54  TEMPL(N1T1) struct Power<A, NUM(n)> :
55  public SimplifySignedPower<n, A> { };
56 
57 }
58 
60 
61 #endif
const Numerical< n > & num()
Definition: Numerical.h:16
typedef POWER(A, NUM(n)) arg
Definition: Abs.h:5
#define TYPT2
Definition: Simplify_begin.h:7
PROD_S(A, B)>
Definition: Factorize.h:44
POWER_S(A, NUM(n))>
Definition: Factorize.h:48
Sqrt< T >::type sqrt(const T &t)
Definition: Sqrt.h:22
#define FRACT_S(N, M)
#define RATIO(A, B)
#define TYPN1T2
#define SUM(A, B)
TEMPL(T1) struct Divides0
Definition: Factorize.h:18
#define SQRT(A)
#define POWER_RULE(TMPL, T1, T2, RES, COMB)
#define TYPT3
Definition: Simplify_begin.h:8
#define COMBINE(A, B, RES)
NUM(n))
Definition: Factorize.h:92
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
#define TYPT1
Definition: Simplify_begin.h:6