CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
83  template <TYPT2, bool parametric = Parametric<A>::value || Parametric<B>::value>
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
static const bool value
Definition: Factorize.h:100
#define TAN_RULE(TMPL, T, RES, COMB)
const Numerical< n > & num()
Definition: Numerical.h:18
typedef POWER(A, NUM(n)) arg
#define COS(A)
#define TYPT2
Definition: Simplify_begin.h:7
MINUS_S(B)>
Definition: Factorize.h:94
#define MINUS(A)
#define COS2(A)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
PROD_S(A, B)>
Definition: Factorize.h:38
POWER_S(A, NUM(n))>
Definition: Factorize.h:40
#define SIN_RULE(TMPL, T, RES, COMB)
#define RATIO_S(A, B)
#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)
static type combine(const SinStruct< A > &_1, const CosStruct< A > &_2)
#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
typedef PROD(F, SUM(RATIO(A, F), RATIO(B, F))) type
Definition: Sum.h:18
#define COMBINE(A, B, RES)
#define SIN(A)
static const int p
Definition: Factorize.h:48
NUM(n))
Definition: Factorize.h:87
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
#define TYPT1
Definition: Simplify_begin.h:6
def template
Definition: svgfig.py:521
#define TAN_S(A)
#define SIN_S(A)