CMS 3D CMS Logo

SimplifyTrigonometric.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_Utilities_SimplifyTrigonometric_h
2 #define PhysicsTools_Utilities_SimplifyTrigonometric_h
3 
13 #include <boost/mpl/if.hpp>
14 
16 
17 namespace funct {
18  // sin(-a) = - sin(a)
20 
21  // cos(-a) = cos(a)
23 
24  // tan(-a) = - tan(a)
26 
27  // sin(x) * x = x * sin(x)
28  PROD_RULE(TYPT1, SIN_S(A), A, PROD(A, SIN(A)), _2* _1);
29 
30  // cos(x) * x = x * cos(x)
31  PROD_RULE(TYPT1, COS_S(A), A, PROD(A, COS(A)), _2* _1);
32 
33  // tan(x) * x = x * tan(x)
34  PROD_RULE(TYPT1, TAN_S(A), A, PROD(A, TAN(A)), _2* _1);
35 
36  // sin(a) / cos(a) = tan(a)
38  struct SimplifySCRatio {
39  typedef RATIO_S(SIN(A), COS(A)) type;
40  COMBINE(SIN_S(A), COS_S(A), _1 / _2);
41  };
42 
43  TEMPL(T1) struct SimplifySCRatio<A, false> {
44  typedef TAN_S(A) type;
45  COMBINE(SIN_S(A), COS_S(A), type(_1._));
46  };
47 
48  TEMPL(T1) struct Ratio<SIN_S(A), COS_S(A)> : public SimplifySCRatio<A> {};
49 
50  // sin(a) / tan(a) = cos(a)
52  struct SimplifySTRatio {
53  typedef RATIO_S(SIN(A), TAN(A)) type;
54  COMBINE(SIN_S(A), TAN_S(A), _1 / _2);
55  };
56 
57  TEMPL(T1) struct SimplifySTRatio<A, false> {
58  typedef COS_S(A) type;
59  COMBINE(SIN_S(A), TAN_S(A), type(_1._));
60  };
61 
62  TEMPL(T1) struct Ratio<SIN_S(A), TAN_S(A)> : public SimplifySTRatio<A> {};
63 
64  // cos(a) * tan(a) = sin(a)
67  typedef PROD(COS(A), TAN(A)) type;
68  COMBINE(COS_S(A), TAN_S(A), _1* _2);
69  };
70 
71  TEMPL(T1) struct SimplifySTProduct<A, false> {
72  typedef SIN(A) type;
73  COMBINE(COS_S(A), TAN_S(A), sin(_1._));
74  };
75 
76  TEMPL(T1) struct Product<COS_S(A), TAN_S(A)> : public SimplifySTProduct<A> {};
77 
78  // cos(a) * sin(a) => sin(a) * cos(a)
79  TEMPL(T1) struct Product<COS_S(A), SIN_S(A)> {
80  typedef PROD(SIN(A), COS(A)) type;
81  COMBINE(COS_S(A), SIN_S(A), _2* _1);
82  };
83 
84  // cos(a)^b * tan(a)^b = sin(a)^b
87  typedef PROD(POWER(COS(A), B), POWER(TAN(A), B)) type;
88  COMBINE(POWER_S(COS_S(A), B), POWER_S(TAN_S(A), B), _1* _2);
89  };
90 
91  TEMPL(T2) struct SimplifySTnProduct<A, B, false> {
92  typedef POWER(SIN(A), B) type;
93  COMBINE(POWER_S(COS_S(A), B), POWER_S(TAN_S(A), B), pow(sin(_1._1._), _1._2));
94  };
95 
96  TEMPL(T2) struct Product<POWER_S(COS_S(A), B), POWER_S(TAN_S(A), B)> : public SimplifySTnProduct<A, B> {};
97 
98  TEMPL(N1T1)
99  struct Product<POWER_S(COS_S(A), NUM(n)), POWER_S(TAN_S(A), NUM(n))> : public SimplifySTnProduct<A, NUM(n)> {};
100 
101  // n cos(a)^2 + m sin(a)^2 = min(n, m) +
102  // (n - min(n, m)) cos(a)^2 + (m - min(n, m)) sin(a)^2
104  struct SimpifyS2C2Sum {
105  typedef SUM(PROD(NUM(n), SIN2(A)), PROD(NUM(m), COS2(A))) type;
106  COMBINE(PROD(NUM(n), SIN2(A)), PROD(NUM(m), COS2(A)), _1 + _2);
107  };
108 
109  TEMPL(N2T1) struct SimpifyS2C2Sum<n, m, A, false> {
110  static const int p = ::boost::mpl::if_c<(n < m), ::boost::mpl::int_<n>, ::boost::mpl::int_<m> >::type::value;
111  typedef SUM(SUM(PROD(NUM(n - p), SIN2(A)), PROD(NUM(m - p), COS2(A))), NUM(p)) type;
112  COMBINE(PROD(NUM(n), SIN2(A)), PROD(NUM(m), COS2(A)), (num<n - p>() * _1._2 + num<m - p>() * _2._2) + num<p>());
113  };
114 
115  TEMPL(T1) struct Sum<POWER_S(SIN_S(A), NUM(2)), POWER_S(COS_S(A), NUM(2))> : public SimpifyS2C2Sum<1, 1, A> {};
116 
117  TEMPL(T1) struct Sum<POWER_S(COS_S(A), NUM(2)), POWER_S(SIN_S(A), NUM(2))> {
118  typedef SUM(SIN2(A), COS2(A)) type;
119  inline static type combine(const COS2(A) & _1, const SIN2(A) & _2) {
120  return Sum<SIN2(A), COS2(A)>::combine(_2, _1);
121  }
122  };
123 
124  TEMPL(N2T1)
125  struct Sum<PROD_S(NUM(n), POWER_S(SIN_S(A), NUM(2))), PROD_S(NUM(m), POWER_S(COS_S(A), NUM(2)))>
126  : public SimpifyS2C2Sum<n, m, A> {};
127 
128  TEMPL(N2T1) struct Sum<PROD_S(NUM(m), POWER_S(COS_S(A), NUM(2))), PROD_S(NUM(n), POWER_S(SIN_S(A), NUM(2)))> {
129  typedef SUM(PROD(NUM(n), SIN2(A)), PROD(NUM(m), COS2(A))) type;
130  inline static type combine(const PROD(NUM(m), COS2(A)) & _1, const PROD(NUM(n), SIN2(A)) & _2) {
131  return Sum<PROD(NUM(n), SIN2(A)), PROD(NUM(m), COS2(A))>::combine(_2, _1);
132  }
133  };
134 
135 } // namespace funct
136 
138 
139 #endif
SUM
#define SUM(A, B)
Definition: Simplify_begin.h:52
TAN_S
#define TAN_S(A)
Definition: Simplify_begin.h:48
funct::Sum< ProductStruct< Numerical< m >, PowerStruct< CosStruct< A >, Numerical< 2 > > >, ProductStruct< Numerical< n >, PowerStruct< SinStruct< A >, Numerical< 2 > > > >::type
Sum< typename Product< Numerical< n >, typename Sin2< A >::type >::type, typename Product< Numerical< m >, typename Cos2< A >::type >::type >::type type
Definition: SimplifyTrigonometric.h:129
Product.h
SIN2
#define SIN2(A)
Definition: Simplify_begin.h:64
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
funct::Sum::combine
static type combine(const A &a, const B &b)
Definition: Sum.h:20
funct::SimplifySCRatio< A, false >::type
TanStruct< A > type
Definition: SimplifyTrigonometric.h:44
Ratio.h
COS_RULE
#define COS_RULE(TMPL, T, RES, COMB)
Definition: Simplify_begin.h:137
funct::SimplifySTRatio< A, false >::type
CosStruct< A > type
Definition: SimplifyTrigonometric.h:58
funct::SimplifySTnProduct::type
Product< typename Power< typename Cos< A >::type, B >::type, typename Power< typename Tan< A >::type, B >::type >::type type
Definition: SimplifyTrigonometric.h:87
funct::PROD_S
PROD_S(B, C)>
Definition: Factorize.h:114
SIN
#define SIN(A)
Definition: Simplify_begin.h:62
funct::B
TEMPL(T2) struct Divides B
Definition: Factorize.h:29
funct::SimplifySTnProduct
Definition: SimplifyTrigonometric.h:86
COS
#define COS(A)
Definition: Simplify_begin.h:63
funct::SimpifyS2C2Sum< n, m, A, false >::type
Sum< typename Sum< typename Product< Numerical< n - p >, typename Sin2< A >::type >::type, typename Product< Numerical< m - p >, typename Cos2< A >::type >::type >::type, Numerical< p > >::type type
Definition: SimplifyTrigonometric.h:111
RATIO_S
#define RATIO_S(A, B)
Definition: Simplify_begin.h:40
funct::SimplifySCRatio::type
RatioStruct< typename Sin< A >::type, typename Cos< A >::type > type
Definition: SimplifyTrigonometric.h:39
crabWrapper._
_
Definition: crabWrapper.py:19
COS_S
#define COS_S(A)
Definition: Simplify_begin.h:47
funct::Sum< ProductStruct< Numerical< m >, PowerStruct< CosStruct< A >, Numerical< 2 > > >, ProductStruct< Numerical< n >, PowerStruct< SinStruct< A >, Numerical< 2 > > > >::combine
static type combine(const typename Product< Numerical< m >, typename Cos2< A >::type >::type &_1, const typename Product< Numerical< n >, typename Sin2< A >::type >::type &_2)
Definition: SimplifyTrigonometric.h:130
funct::SimplifySTRatio
Definition: SimplifyTrigonometric.h:52
funct::Ratio
Definition: Ratio.h:18
funct::SimpifyS2C2Sum::type
Sum< typename Product< Numerical< n >, typename Sin2< A >::type >::type, typename Product< Numerical< m >, typename Cos2< A >::type >::type >::type type
Definition: SimplifyTrigonometric.h:105
TYPT1
#define TYPT1
Definition: Simplify_begin.h:6
Tan.h
funct::POWER
typedef POWER(A, NUM(n)) arg
MINUS
#define MINUS(A)
Definition: Simplify_begin.h:54
SIN_RULE
#define SIN_RULE(TMPL, T, RES, COMB)
Definition: Simplify_begin.h:130
TAN_RULE
#define TAN_RULE(TMPL, T, RES, COMB)
Definition: Simplify_begin.h:144
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
COS2
#define COS2(A)
Definition: Simplify_begin.h:65
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
funct::ProductStruct::_2
B _2
Definition: Product.h:14
funct::m
m
Definition: Factorize.h:50
Cos.h
funct::Product< CosStruct< A >, SinStruct< A > >::type
Product< typename Sin< A >::type, typename Cos< A >::type >::type type
Definition: SimplifyTrigonometric.h:80
Sum.h
funct::SimplifySTProduct
Definition: SimplifyTrigonometric.h:66
ParametricTrait.h
Sin.h
funct::SimplifySTnProduct< A, B, false >::type
Power< typename Sin< A >::type, B >::type type
Definition: SimplifyTrigonometric.h:92
funct::MINUS_S
typedef MINUS_S(A) arg
A
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
TAN
#define TAN(A)
Definition: Simplify_begin.h:66
PROD_RULE
#define PROD_RULE(TMPL, T1, T2, RES, COMB)
Definition: Simplify_begin.h:95
funct::TEMPL
TEMPL(T1) struct Divides0
Definition: Factorize.h:20
funct::p
static const int p
Definition: Factorize.h:53
funct::SimpifyS2C2Sum
Definition: SimplifyTrigonometric.h:104
Simplify_end.h
funct::Sum< PowerStruct< CosStruct< A >, Numerical< 2 > >, PowerStruct< SinStruct< A >, Numerical< 2 > > >::combine
static type combine(const typename Cos2< A >::type &_1, const typename Sin2< A >::type &_2)
Definition: SimplifyTrigonometric.h:119
relativeConstraints.value
value
Definition: relativeConstraints.py:53
funct::NUM
PROD_S(A, B)> NUM(n))
Definition: Factorize.h:87
funct::Product
Definition: Product.h:18
funct::Parametric
Definition: ParametricTrait.h:11
COMBINE
#define COMBINE(A, B, RES)
Definition: Simplify_begin.h:70
funct::SumStruct
Definition: Sum.h:7
funct::Sum
Definition: Sum.h:18
SIN_S
#define SIN_S(A)
Definition: Simplify_begin.h:46
funct::SimplifySTProduct< A, false >::type
Sin< A >::type type
Definition: SimplifyTrigonometric.h:72
Minus.h
funct::SimplifySTProduct::type
Product< typename Cos< A >::type, typename Tan< A >::type >::type type
Definition: SimplifyTrigonometric.h:67
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
Simplify_begin.h
funct::Sum< PowerStruct< CosStruct< A >, Numerical< 2 > >, PowerStruct< SinStruct< A >, Numerical< 2 > > >::type
Sum< typename Sin2< A >::type, typename Cos2< A >::type >::type type
Definition: SimplifyTrigonometric.h:118
funct::SimplifySCRatio
Definition: SimplifyTrigonometric.h:38
funct::SimplifySTRatio::type
RatioStruct< typename Sin< A >::type, typename Tan< A >::type > type
Definition: SimplifyTrigonometric.h:53
funct::PROD
typedef PROD(F, SUM(RATIO(A, F), RATIO(B, F))) type
funct
Definition: Abs.h:5
Sin2Cos2.h