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)> :
49  public SimplifySCRatio<A> { };
50 
51  // sin(a) / tan(a) = cos(a)
53  struct SimplifySTRatio {
54  typedef RATIO_S(SIN(A), TAN(A)) type;
55  COMBINE(SIN_S(A), TAN_S(A), _1 / _2);
56  };
57 
58  TEMPL(T1) struct SimplifySTRatio<A, false> {
59  typedef COS_S(A) type;
60  COMBINE(SIN_S(A), TAN_S(A), type(_1._));
61  };
62 
63  TEMPL(T1) struct Ratio<SIN_S(A), TAN_S(A)> :
64  public SimplifySTRatio<A> { };
65 
66  // cos(a) * tan(a) = sin(a)
69  typedef PROD(COS(A), TAN(A)) type;
70  COMBINE(COS_S(A), TAN_S(A), _1 * _2);
71  };
72 
73  TEMPL(T1) struct SimplifySTProduct<A, false> {
74  typedef SIN(A) type;
75  COMBINE(COS_S(A), TAN_S(A), sin(_1._));
76  };
77 
78  TEMPL(T1) struct Product<COS_S(A), TAN_S(A)> :
79  public SimplifySTProduct<A> { };
80 
81  // cos(a) * sin(a) => sin(a) * cos(a)
82  TEMPL(T1) struct Product<COS_S(A), SIN_S(A)> {
83  typedef PROD(SIN(A), COS(A)) type;
84  COMBINE(COS_S(A), SIN_S(A), _2 * _1);
85  };
86 
87  // cos(a)^b * tan(a)^b = sin(a)^b
89  bool parametric = Parametric<A>::value || Parametric<B>::value>
91  typedef PROD(POWER(COS(A), B), POWER(TAN(A), B)) type;
92  COMBINE(POWER_S(COS_S(A), B), POWER_S(TAN_S(A), B), _1 * _2);
93  };
94 
95  TEMPL(T2) struct SimplifySTnProduct<A, B, false> {
96  typedef POWER(SIN(A), B) type;
97  COMBINE(POWER_S(COS_S(A), B), POWER_S(TAN_S(A), B),
98  pow(sin(_1._1._), _1._2 ));
99  };
100 
101  TEMPL(T2) struct Product<POWER_S(COS_S(A), B),
102  POWER_S(TAN_S(A), B)> :
103  public SimplifySTnProduct<A, B> { };
104 
105  TEMPL(N1T1) struct Product<POWER_S(COS_S(A), NUM(n)),
106  POWER_S(TAN_S(A), NUM(n))> :
107  public SimplifySTnProduct<A, NUM(n)> { };
108 
109  // n cos(a)^2 + m sin(a)^2 = min(n, m) +
110  // (n - min(n, m)) cos(a)^2 + (m - min(n, m)) sin(a)^2
112  struct SimpifyS2C2Sum {
113  typedef SUM(PROD(NUM(n), SIN2(A)),
114  PROD(NUM(m), COS2(A))) type;
115  COMBINE(PROD(NUM(n), SIN2(A)),
116  PROD(NUM(m), COS2(A)), _1 + _2);
117  };
118 
119  TEMPL(N2T1) struct SimpifyS2C2Sum<n, m, A, false> {
120  static const int p = ::boost::mpl::if_c<(n <m),
121  ::boost::mpl::int_<n>, ::boost::mpl::int_<m> >::type::value;
122  typedef SUM(SUM(PROD(NUM(n - p), SIN2(A)),
123  PROD(NUM(m - p), COS2(A))), NUM(p)) type;
124  COMBINE(PROD(NUM(n), SIN2(A)),
125  PROD(NUM(m), COS2(A)), (num<n - p>() * _1._2 +
126  num<m - p>() * _2._2) + num<p>());
127  };
128 
129  TEMPL(T1) struct Sum<POWER_S(SIN_S(A), NUM(2)),
130  POWER_S(COS_S(A), NUM(2))> :
131  public SimpifyS2C2Sum<1, 1, A> { };
132 
133  TEMPL(T1) struct Sum<POWER_S(COS_S(A), NUM(2)),
134  POWER_S(SIN_S(A), NUM(2))> {
135  typedef SUM(SIN2(A), COS2(A)) type;
136  inline static type combine(const COS2(A) & _1, const SIN2(A) & _2)
137  { return Sum<SIN2(A), COS2(A)>::combine(_2, _1); }
138  };
139 
140  TEMPL(N2T1) struct Sum<PROD_S(NUM(n), POWER_S(SIN_S(A), NUM(2))),
141  PROD_S(NUM(m), POWER_S(COS_S(A), NUM(2)))> :
142  public SimpifyS2C2Sum<n, m, A> { };
143 
144  TEMPL(N2T1) struct Sum<PROD_S(NUM(m), POWER_S(COS_S(A), NUM(2))),
145  PROD_S(NUM(n), POWER_S(SIN_S(A), NUM(2)))> {
146  typedef SUM(PROD(NUM(n), SIN2(A)), PROD(NUM(m), COS2(A))) type;
147  inline static type combine(const PROD(NUM(m), COS2(A))& _1,
148  const PROD(NUM(n), SIN2(A))& _2)
150  };
151 
152 }
153 
155 
156 #endif
#define TAN_RULE(TMPL, T, RES, COMB)
const Numerical< n > & num()
Definition: Numerical.h:16
typedef POWER(A, NUM(n)) arg
Definition: Abs.h:5
#define COS(A)
#define TYPT2
Definition: Simplify_begin.h:7
MINUS_S(B)>
Definition: Factorize.h:101
#define MINUS(A)
#define COS2(A)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
PROD_S(A, B)>
Definition: Factorize.h:46
POWER_S(A, NUM(n))>
Definition: Factorize.h:50
#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)
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
Definition: value.py:1
#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:20
typedef PROD(F, SUM(RATIO(A, F), RATIO(B, F))) type
Definition: Sum.h:26
#define COMBINE(A, B, RES)
#define SIN(A)
static const int p
Definition: Factorize.h:59
NUM(n))
Definition: Factorize.h:94
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
#define TYPT1
Definition: Simplify_begin.h:6
#define TAN_S(A)
#define SIN_S(A)