CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SimplifyTrigonometric.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_Utilities_SimplifyTrigonometric_h
2 #define PhysicsTools_Utilities_SimplifyTrigonometric_h
3 
13 
15 
16 namespace funct {
17  // sin(-a) = - sin(a)
18  SIN_RULE(TYPT1, MINUS_S(A), MINUS(SIN(A)), -sin(_._));
19 
20  // cos(-a) = cos(a)
21  COS_RULE(TYPT1, MINUS_S(A), COS(A), cos(_._));
22 
23  // tan(-a) = - tan(a)
24  TAN_RULE(TYPT1, MINUS_S(A), MINUS(TAN(A)), -tan(_._));
25 
26  // sin(x) * x = x * sin(x)
27  PROD_RULE(TYPT1, SIN_S(A), A, PROD(A, SIN(A)), _2 * _1 );
28 
29  // cos(x) * x = x * cos(x)
30  PROD_RULE(TYPT1, COS_S(A), A, PROD(A, COS(A)), _2 * _1 );
31 
32  // tan(x) * x = x * tan(x)
33  PROD_RULE(TYPT1, TAN_S(A), A, PROD(A, TAN(A)), _2 * _1 );
34 
35  // sin(a) / cos(a) = tan(a)
37  struct SimplifySCRatio {
38  typedef RATIO_S(SIN(A), COS(A)) type;
39  COMBINE(SIN_S(A), COS_S(A), _1 / _2);
40  };
41 
42  TEMPL(T1) struct SimplifySCRatio<A, false> {
43  typedef TAN_S(A) type;
44  COMBINE(SIN_S(A), COS_S(A), type(_1._));
45  };
46 
47  TEMPL(T1) struct Ratio<SIN_S(A), COS_S(A)> :
48  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)> :
63  public SimplifySTRatio<A> { };
64 
65  // cos(a) * tan(a) = sin(a)
68  typedef PROD(COS(A), TAN(A)) type;
69  COMBINE(COS_S(A), TAN_S(A), _1 * _2);
70  };
71 
72  TEMPL(T1) struct SimplifySTProduct<A, false> {
73  typedef SIN(A) type;
74  COMBINE(COS_S(A), TAN_S(A), sin(_1._));
75  };
76 
77  TEMPL(T1) struct Product<COS_S(A), TAN_S(A)> :
78  public SimplifySTProduct<A> { };
79 
80  // cos(a) * sin(a) => sin(a) * cos(a)
81  TEMPL(T1) struct Product<COS_S(A), SIN_S(A)> {
82  typedef PROD(SIN(A), COS(A)) type;
83  COMBINE(COS_S(A), SIN_S(A), _2 * _1);
84  };
85 
86  // cos(a)^b * tan(a)^b = sin(a)^b
88  bool parametric = Parametric<A>::value || Parametric<B>::value>
90  typedef PROD(POWER(COS(A), B), POWER(TAN(A), B)) type;
91  COMBINE(POWER_S(COS_S(A), B), POWER_S(TAN_S(A), B), _1 * _2);
92  };
93 
94  TEMPL(T2) struct SimplifySTnProduct<A, B, false> {
95  typedef POWER(SIN(A), B) type;
96  COMBINE(POWER_S(COS_S(A), B), POWER_S(TAN_S(A), B),
97  pow(sin(_1._1._), _1._2 ));
98  };
99 
100  TEMPL(T2) struct Product<POWER_S(COS_S(A), B),
101  POWER_S(TAN_S(A), B)> :
102  public SimplifySTnProduct<A, B> { };
103 
104  TEMPL(N1T1) struct Product<POWER_S(COS_S(A), NUM(n)),
105  POWER_S(TAN_S(A), NUM(n))> :
106  public SimplifySTnProduct<A, NUM(n)> { };
107 
108  // n cos(a)^2 + m sin(a)^2 = min(n, m) +
109  // (n - min(n, m)) cos(a)^2 + (m - min(n, m)) sin(a)^2
111  struct SimpifyS2C2Sum {
112  typedef SUM(PROD(NUM(n), SIN2(A)),
113  PROD(NUM(m), COS2(A))) type;
114  COMBINE(PROD(NUM(n), SIN2(A)),
115  PROD(NUM(m), COS2(A)), _1 + _2);
116  };
117 
118  TEMPL(N2T1) struct SimpifyS2C2Sum<n, m, A, false> {
119  static const int p = ::boost::mpl::if_c<(n <m),
120  ::boost::mpl::int_<n>, ::boost::mpl::int_<m> >::type::value;
121  typedef SUM(SUM(PROD(NUM(n - p), SIN2(A)),
122  PROD(NUM(m - p), COS2(A))), NUM(p)) type;
123  COMBINE(PROD(NUM(n), SIN2(A)),
124  PROD(NUM(m), COS2(A)), (num<n - p>() * _1._2 +
125  num<m - p>() * _2._2) + num<p>());
126  };
127 
128  TEMPL(T1) struct Sum<POWER_S(SIN_S(A), NUM(2)),
129  POWER_S(COS_S(A), NUM(2))> :
130  public SimpifyS2C2Sum<1, 1, A> { };
131 
132  TEMPL(T1) struct Sum<POWER_S(COS_S(A), NUM(2)),
133  POWER_S(SIN_S(A), NUM(2))> {
134  typedef SUM(SIN2(A), COS2(A)) type;
135  inline static type combine(const COS2(A) & _1, const SIN2(A) & _2)
136  { return Sum<SIN2(A), COS2(A)>::combine(_2, _1); }
137  };
138 
139  TEMPL(N2T1) struct Sum<PROD_S(NUM(n), POWER_S(SIN_S(A), NUM(2))),
140  PROD_S(NUM(m), POWER_S(COS_S(A), NUM(2)))> :
141  public SimpifyS2C2Sum<n, m, A> { };
142 
143  TEMPL(N2T1) struct Sum<PROD_S(NUM(m), POWER_S(COS_S(A), NUM(2))),
144  PROD_S(NUM(n), POWER_S(SIN_S(A), NUM(2)))> {
145  typedef SUM(PROD(NUM(n), SIN2(A)), PROD(NUM(m), COS2(A))) type;
146  inline static type combine(const PROD(NUM(m), COS2(A))& _1,
147  const PROD(NUM(n), SIN2(A))& _2)
149  };
150 
151 }
152 
154 
155 #endif
static const bool value
Definition: Factorize.h:107
#define TAN_RULE(TMPL, T, RES, COMB)
const Numerical< n > & num()
Definition: Numerical.h:16
typedef POWER(A, NUM(n)) arg
#define COS(A)
#define TYPT2
Definition: Simplify_begin.h:7
MINUS_S(B)>
Definition: Factorize.h:99
#define MINUS(A)
#define COS2(A)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
PROD_S(A, B)>
Definition: Factorize.h:44
POWER_S(A, NUM(n))>
Definition: Factorize.h:48
#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:18
string const
Definition: compareJSON.py:14
typedef PROD(F, SUM(RATIO(A, F), RATIO(B, F))) type
Definition: Sum.h:27
#define COMBINE(A, B, RES)
#define SIN(A)
static const int p
Definition: Factorize.h:57
NUM(n))
Definition: Factorize.h:92
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
#define TYPT1
Definition: Simplify_begin.h:6
def template
Definition: svgfig.py:520
#define TAN_S(A)
#define SIN_S(A)