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
85  template <TYPT2, bool parametric = Parametric<A>::value || Parametric<B>::value>
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) {
132  }
133  };
134 
135 } // namespace funct
136 
138 
139 #endif
#define TAN_RULE(TMPL, T, RES, COMB)
const Numerical< n > & num()
Definition: Numerical.h:18
typedef POWER(A, NUM(n)) arg
Definition: Abs.h:5
#define COS(A)
#define TYPT2
Definition: Simplify_begin.h:7
#define COS_RULE(TMPL, T, RES, COMB)
MINUS_S(B)>
Definition: Factorize.h:94
#define MINUS(A)
#define SIN_RULE(TMPL, T, RES, COMB)
#define COS2(A)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
PROD_S(A, B)>
Definition: Factorize.h:43
POWER_S(A, NUM(n))>
Definition: Factorize.h:45
#define RATIO_S(A, B)
#define COMBINE(A, B, RES)
#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)
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
Definition: value.py:1
#define SUM(A, B)
TEMPL(T1) struct Divides0
Definition: Factorize.h:20
typedef PROD(F, SUM(RATIO(A, F), RATIO(B, F))) type
Definition: Sum.h:18
#define PROD_RULE(TMPL, T1, T2, RES, COMB)
#define SIN(A)
static const int p
Definition: Factorize.h:53
NUM(n))
Definition: Factorize.h:87
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
#define TYPT1
Definition: Simplify_begin.h:6
#define TAN_S(A)
#define SIN_S(A)