CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/PhysicsTools/Utilities/interface/SimplifyPower.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_Utilities_SimplifyPower_h
00002 #define PhysicsTools_Utilities_SimplifyPower_h
00003 
00004 #include "PhysicsTools/Utilities/interface/Power.h"
00005 #include "PhysicsTools/Utilities/interface/Ratio.h"
00006 #include "PhysicsTools/Utilities/interface/Sum.h"
00007 #include "PhysicsTools/Utilities/interface/Sqrt.h"
00008 #include "PhysicsTools/Utilities/interface/Fraction.h"
00009 #include "PhysicsTools/Utilities/interface/DecomposePower.h"
00010 
00011 #include "PhysicsTools/Utilities/interface/Simplify_begin.h"
00012 
00013 namespace funct {
00014 
00015   // a ^ 1 = a
00016   POWER_RULE(TYPT1, A, NUM(1), A, _1);
00017 
00018   // a ^ -1 = 1 / a
00019   POWER_RULE(TYPT1, A, NUM(-1), RATIO(NUM(1), A), num<1>() / _1); 
00020   
00021   // a ^ 1/2 =  sqrt(a)
00022   POWER_RULE(TYPT1, A, FRACT_S(1, 2), SQRT(A), sqrt(_1));
00023   
00024   // a ^ 0 = 1
00025   POWER_RULE(TYPT1, A, NUM(0), NUM(1), num<1>());
00026 
00027   // (a * b)^ 0 = 1
00028   POWER_RULE(TYPT2, PROD_S(A, B), NUM(0), NUM(1), num<1>());
00029 
00030   // (a ^ b) ^ c = a ^ (b + c)
00031   POWER_RULE(TYPT3, POWER_S(A, B), C, POWER(A, SUM(B, C)), pow(_1._1, _1._2 + _2));
00032 
00033   // (a ^ b) ^ n = a ^ (b + n)
00034   POWER_RULE(TYPN1T2, POWER_S(A, B), NUM(n), POWER(A, SUM(B, NUM(n))),
00035              pow(_1._1, _1._2 + _2));
00036 
00037   // a ^ (-n) = 1 / a ^ n
00038   template<TYPN1T1, bool positive = (n>= 0)>
00039   struct SimplifySignedPower {
00040     typedef POWER_S(A, NUM(n)) type;
00041     COMBINE(A, NUM(n), type(_1, _2));
00042   };
00043 
00044   TEMPL(N1T1) struct SimplifySignedPower<n, A, false> {
00045     typedef RATIO(NUM(1), POWER(A, NUM(- n))) type;
00046     COMBINE(A, NUM(n), num<1>() / pow(_1, num<-n>()));
00047   };
00048 
00049   TEMPL(T1) struct SimplifySignedPower<0, A, true> {
00050     typedef NUM(1) type;
00051     COMBINE(A, NUM(0), num<1>());
00052   };
00053 
00054   TEMPL(N1T1) struct Power<A, NUM(n)> :
00055     public SimplifySignedPower<n, A> { };
00056   
00057 }
00058 
00059 #include "PhysicsTools/Utilities/interface/Simplify_end.h"
00060 
00061 #endif