Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:21

0001 #ifndef PhysicsTools_Utilities_SimplifyPower_h
0002 #define PhysicsTools_Utilities_SimplifyPower_h
0003 
0004 #include "PhysicsTools/Utilities/interface/Power.h"
0005 #include "PhysicsTools/Utilities/interface/Ratio.h"
0006 #include "PhysicsTools/Utilities/interface/Sum.h"
0007 #include "PhysicsTools/Utilities/interface/Sqrt.h"
0008 #include "PhysicsTools/Utilities/interface/Fraction.h"
0009 #include "PhysicsTools/Utilities/interface/DecomposePower.h"
0010 
0011 #include "PhysicsTools/Utilities/interface/Simplify_begin.h"
0012 
0013 namespace funct {
0014 
0015   // a ^ 1 = a
0016   POWER_RULE(TYPT1, A, NUM(1), A, _1);
0017 
0018   // a ^ -1 = 1 / a
0019   POWER_RULE(TYPT1, A, NUM(-1), RATIO(NUM(1), A), num<1>() / _1);
0020 
0021   // a ^ 1/2 =  sqrt(a)
0022   POWER_RULE(TYPT1, A, FRACT_S(1, 2), SQRT(A), sqrt(_1));
0023 
0024   // a ^ 0 = 1
0025   POWER_RULE(TYPT1, A, NUM(0), NUM(1), num<1>());
0026 
0027   // (a * b)^ 0 = 1
0028   POWER_RULE(TYPT2, PROD_S(A, B), NUM(0), NUM(1), num<1>());
0029 
0030   // (a ^ b) ^ c = a ^ (b + c)
0031   POWER_RULE(TYPT3, POWER_S(A, B), C, POWER(A, SUM(B, C)), pow(_1._1, _1._2 + _2));
0032 
0033   // (a ^ b) ^ n = a ^ (b + n)
0034   POWER_RULE(TYPN1T2, POWER_S(A, B), NUM(n), POWER(A, SUM(B, NUM(n))), pow(_1._1, _1._2 + _2));
0035 
0036   // a ^ (-n) = 1 / a ^ n
0037   template <TYPN1T1, bool positive = (n >= 0)>
0038   struct SimplifySignedPower {
0039     typedef POWER_S(A, NUM(n)) type;
0040     COMBINE(A, NUM(n), type(_1, _2));
0041   };
0042 
0043   TEMPL(N1T1) struct SimplifySignedPower<n, A, false> {
0044     typedef RATIO(NUM(1), POWER(A, NUM(-n))) type;
0045     COMBINE(A, NUM(n), num<1>() / pow(_1, num<-n>()));
0046   };
0047 
0048   TEMPL(T1) struct SimplifySignedPower<0, A, true> {
0049     typedef NUM(1) type;
0050     COMBINE(A, NUM(0), num<1>());
0051   };
0052 
0053   TEMPL(N1T1) struct Power<A, NUM(n)> : public SimplifySignedPower<n, A> {};
0054 
0055 }  // namespace funct
0056 
0057 #include "PhysicsTools/Utilities/interface/Simplify_end.h"
0058 
0059 #endif