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 
14 
15 namespace funct {
16  // sin(-a) = - sin(a)
18 
19  // cos(-a) = cos(a)
21 
22  // tan(-a) = - tan(a)
24 
25  // sin(x) * x = x * sin(x)
26  PROD_RULE(TYPT1, SIN_S(A), A, PROD(A, SIN(A)), _2* _1);
27 
28  // cos(x) * x = x * cos(x)
29  PROD_RULE(TYPT1, COS_S(A), A, PROD(A, COS(A)), _2* _1);
30 
31  // tan(x) * x = x * tan(x)
32  PROD_RULE(TYPT1, TAN_S(A), A, PROD(A, TAN(A)), _2* _1);
33 
34  // sin(a) / cos(a) = tan(a)
36  struct SimplifySCRatio {
37  typedef RATIO_S(SIN(A), COS(A)) type;
38  COMBINE(SIN_S(A), COS_S(A), _1 / _2);
39  };
40 
41  TEMPL(T1) struct SimplifySCRatio<A, false> {
42  typedef TAN_S(A) type;
43  COMBINE(SIN_S(A), COS_S(A), type(_1._));
44  };
45 
46  TEMPL(T1) struct Ratio<SIN_S(A), COS_S(A)> : public SimplifySCRatio<A> {};
47 
48  // sin(a) / tan(a) = cos(a)
50  struct SimplifySTRatio {
51  typedef RATIO_S(SIN(A), TAN(A)) type;
52  COMBINE(SIN_S(A), TAN_S(A), _1 / _2);
53  };
54 
55  TEMPL(T1) struct SimplifySTRatio<A, false> {
56  typedef COS_S(A) type;
57  COMBINE(SIN_S(A), TAN_S(A), type(_1._));
58  };
59 
60  TEMPL(T1) struct Ratio<SIN_S(A), TAN_S(A)> : public SimplifySTRatio<A> {};
61 
62  // cos(a) * tan(a) = sin(a)
65  typedef PROD(COS(A), TAN(A)) type;
66  COMBINE(COS_S(A), TAN_S(A), _1* _2);
67  };
68 
69  TEMPL(T1) struct SimplifySTProduct<A, false> {
70  typedef SIN(A) type;
71  COMBINE(COS_S(A), TAN_S(A), sin(_1._));
72  };
73 
74  TEMPL(T1) struct Product<COS_S(A), TAN_S(A)> : public SimplifySTProduct<A> {};
75 
76  // cos(a) * sin(a) => sin(a) * cos(a)
77  TEMPL(T1) struct Product<COS_S(A), SIN_S(A)> {
78  typedef PROD(SIN(A), COS(A)) type;
79  COMBINE(COS_S(A), SIN_S(A), _2* _1);
80  };
81 
82  // cos(a)^b * tan(a)^b = sin(a)^b
85  typedef PROD(POWER(COS(A), B), POWER(TAN(A), B)) type;
86  COMBINE(POWER_S(COS_S(A), B), POWER_S(TAN_S(A), B), _1* _2);
87  };
88 
89  TEMPL(T2) struct SimplifySTnProduct<A, B, false> {
90  typedef POWER(SIN(A), B) type;
91  COMBINE(POWER_S(COS_S(A), B), POWER_S(TAN_S(A), B), pow(sin(_1._1._), _1._2));
92  };
93 
94  TEMPL(T2) struct Product<POWER_S(COS_S(A), B), POWER_S(TAN_S(A), B)> : public SimplifySTnProduct<A, B> {};
95 
96  TEMPL(N1T1)
97  struct Product<POWER_S(COS_S(A), NUM(n)), POWER_S(TAN_S(A), NUM(n))> : public SimplifySTnProduct<A, NUM(n)> {};
98 
99  // n cos(a)^2 + m sin(a)^2 = min(n, m) +
100  // (n - min(n, m)) cos(a)^2 + (m - min(n, m)) sin(a)^2
102  struct SimpifyS2C2Sum {
103  typedef SUM(PROD(NUM(n), SIN2(A)), PROD(NUM(m), COS2(A))) type;
104  COMBINE(PROD(NUM(n), SIN2(A)), PROD(NUM(m), COS2(A)), _1 + _2);
105  };
106 
107  TEMPL(N2T1) struct SimpifyS2C2Sum<n, m, A, false> {
108  static constexpr int p = n < m ? n : m;
109  typedef SUM(SUM(PROD(NUM(n - p), SIN2(A)), PROD(NUM(m - p), COS2(A))), NUM(p)) type;
110  COMBINE(PROD(NUM(n), SIN2(A)), PROD(NUM(m), COS2(A)), (num<n - p>() * _1._2 + num<m - p>() * _2._2) + num<p>());
111  };
112 
113  TEMPL(T1) struct Sum<POWER_S(SIN_S(A), NUM(2)), POWER_S(COS_S(A), NUM(2))> : public SimpifyS2C2Sum<1, 1, A> {};
114 
115  TEMPL(T1) struct Sum<POWER_S(COS_S(A), NUM(2)), POWER_S(SIN_S(A), NUM(2))> {
116  typedef SUM(SIN2(A), COS2(A)) type;
117  inline static type combine(const COS2(A) & _1, const SIN2(A) & _2) {
118  return Sum<SIN2(A), COS2(A)>::combine(_2, _1);
119  }
120  };
121 
122  TEMPL(N2T1)
123  struct Sum<PROD_S(NUM(n), POWER_S(SIN_S(A), NUM(2))), PROD_S(NUM(m), POWER_S(COS_S(A), NUM(2)))>
124  : public SimpifyS2C2Sum<n, m, A> {};
125 
126  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)))> {
127  typedef SUM(PROD(NUM(n), SIN2(A)), PROD(NUM(m), COS2(A))) type;
128  inline static type combine(const PROD(NUM(m), COS2(A)) & _1, const PROD(NUM(n), SIN2(A)) & _2) {
129  return Sum<PROD(NUM(n), SIN2(A)), PROD(NUM(m), COS2(A))>::combine(_2, _1);
130  }
131  };
132 
133 } // namespace funct
134 
136 
137 #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:127
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:29
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:42
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:56
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:85
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:24
funct::SimplifySTnProduct
Definition: SimplifyTrigonometric.h:84
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:109
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:37
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:128
funct::SimplifySTRatio
Definition: SimplifyTrigonometric.h:50
funct::Ratio
Definition: Ratio.h:17
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:103
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:13
funct::m
m
Definition: Factorize.h:45
Cos.h
funct::Product< CosStruct< A >, SinStruct< A > >::type
Product< typename Sin< A >::type, typename Cos< A >::type >::type type
Definition: SimplifyTrigonometric.h:78
Sum.h
funct::SimplifySTProduct
Definition: SimplifyTrigonometric.h:64
ParametricTrait.h
Sin.h
funct::SimplifySTnProduct< A, B, false >::type
Power< typename Sin< A >::type, B >::type type
Definition: SimplifyTrigonometric.h:90
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:15
funct::p
static const int p
Definition: Factorize.h:48
funct::SimpifyS2C2Sum
Definition: SimplifyTrigonometric.h:102
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:117
relativeConstraints.value
value
Definition: relativeConstraints.py:53
funct::NUM
PROD_S(A, B)> NUM(n))
Definition: Factorize.h:87
funct::Product
Definition: Product.h:17
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:70
Minus.h
funct::SimplifySTProduct::type
Product< typename Cos< A >::type, typename Tan< A >::type >::type type
Definition: SimplifyTrigonometric.h:65
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
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:116
funct::SimplifySCRatio
Definition: SimplifyTrigonometric.h:36
funct::SimplifySTRatio::type
RatioStruct< typename Sin< A >::type, typename Tan< A >::type > type
Definition: SimplifyTrigonometric.h:51
funct::PROD
typedef PROD(F, SUM(RATIO(A, F), RATIO(B, F))) type
funct
Definition: Abs.h:5
Sin2Cos2.h