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) {
130  }
131  };
132 
133 } // namespace funct
134 
136 
137 #endif
#define TAN_RULE(TMPL, T, RES, COMB)
Product< typename Power< typename Cos< A >::type, B >::type, typename Power< typename Tan< A >::type, B >::type >::type type
typedef POWER(A, NUM(n)) arg
Definition: Abs.h:5
#define COS(A)
Sum< typename Product< Numerical< n >, typename Sin2< A >::type >::type, typename Product< Numerical< m >, typename Cos2< A >::type >::type >::type type
static type combine(const typename Cos2< A >::type &_1, const typename Sin2< A >::type &_2)
#define MINUS(A)
#define COS2(A)
PROD_S(B, C)>
Definition: Factorize.h:114
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Sum< typename Product< Numerical< n >, typename Sin2< A >::type >::type, typename Product< Numerical< m >, typename Cos2< A >::type >::type >::type type
typedef MINUS_S(A) arg
#define SIN_RULE(TMPL, T, RES, COMB)
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)
Product< typename Cos< A >::type, typename Tan< A >::type >::type type
#define RATIO_S(A, B)
TEMPL(T2) struct Divides B
Definition: Factorize.h:24
RatioStruct< typename Sin< A >::type, typename Tan< A >::type > type
#define TAN(A)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
#define COS_S(A)
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
#define SIN2(A)
#define PROD_RULE(TMPL, T1, T2, RES, COMB)
#define COS_RULE(TMPL, T, RES, COMB)
#define SUM(A, B)
TEMPL(T1) struct Divides0
Definition: Factorize.h:15
Power< typename Sin< A >::type, B >::type type
typedef PROD(F, SUM(RATIO(A, F), RATIO(B, F))) type
Definition: Sum.h:18
#define COMBINE(A, B, RES)
Product< typename Sin< A >::type, typename Cos< A >::type >::type type
#define SIN(A)
static const int p
Definition: Factorize.h:48
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
PROD_S(A, B)> NUM(n))
Definition: Factorize.h:87
RatioStruct< typename Sin< A >::type, typename Cos< A >::type > type
#define POWER_S(A, B)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
#define TYPT1
Definition: Simplify_begin.h:6
#define TAN_S(A)
#define SIN_S(A)