1 #ifndef PhysicsTools_Utilities_Factorize_h 2 #define PhysicsTools_Utilities_Factorize_h 8 #include <boost/type_traits.hpp> 9 #include <boost/mpl/and.hpp> 10 #include <boost/mpl/not.hpp> 11 #include <boost/mpl/int.hpp> 12 #include <boost/mpl/if.hpp> 20 static const bool value =
false;
27 public Divides0<
A> { };
30 public Divides0<
PROD_S(A, B)> { };
33 public Divides<A, void> { };
36 static const bool value =
true;
42 TEMPL(T1) struct Divides<
A, A> :
48 TEMPL(N1T1)
struct Divides<POWER_S(A, NUM(n)),
53 public Divides<POWER(A, NUM(n)), void> { };
56 static const bool value =
true;
58 static const int p = ::boost::mpl::if_c<(n <
m),
59 ::boost::mpl::int_<n>, ::boost::mpl::int_<m> >::
type::value;
65 TEMPL(N2T1) struct Divides<POWER_S(A, NUM(n)),
69 TEMPL(N1T1)
struct Divides<A, POWER_S(A, NUM(n))> :
72 TEMPL(N1T1)
struct Divides<POWER_S(A, NUM(n)), A> :
77 template<
int n,
bool positive = (n>= 0)>
78 struct abs {
enum { value = n }; };
81 struct abs<n, false> {
enum { value = -n }; };
85 TEMPL(N2) struct Divides<NUM(n), NUM(m)> {
87 static const bool value = (gcd != 1);
93 TEMPL(N1) struct Divides<NUM(n), NUM(n)> {
94 static const bool value =
true;
101 public Divides<A,
B> { };
104 public Divides<
PROD_S(A, B),
C> { };
106 TEMPL(T2)
struct Divides<MINUS_S(A), B> {
107 typedef Divides<A, B>
Div;
114 TEMPL(T2) struct Divides<MINUS_S(A), MINUS_S(B)> {
115 typedef Divides<A, B>
Div;
123 typedef Divides<A, PROD_S(B, C)>
Div;
130 TEMPL(T3)
struct Divides<A, PROD_S(B, C)> {
132 typedef Divides<arg, void>
D0;
133 typedef Divides<arg, B>
D1;
134 typedef Divides<arg, C>
D2;
135 typedef typename ::boost::mpl::if_<
D1,
D1,
142 TEMPL(T3) struct Divides<PROD_S(A, B), C> {
144 typedef Divides<arg, void>
D0;
145 typedef Divides<A, C>
D1;
146 typedef Divides<B, C>
D2;
147 typedef typename ::boost::mpl::if_<
D1,
D1,
155 TEMPL(T4) struct Divides<PROD_S(A, B), PROD_S(C, D)> {
157 typedef Divides<arg, void>
D0;
158 typedef Divides<arg, C>
D1;
159 typedef Divides<arg, D>
D2;
160 typedef typename ::boost::mpl::if_<
D1,
D1,
187 inline static type
combine(
const A& _1,
const B& _2) {
189 return f * ((_1 /
f) + (_2 / f));
196 TEMPL(T3)
struct Sum<A, PROD_S(B, C)> :
205 TEMPL(T4)
struct Sum<PROD_S(A, B), PROD_S(C, D)> :
208 TEMPL(T4)
struct Sum<MINUS_S(PROD_S(A, B)),
209 MINUS_S(PROD_S(C, D))> :
211 MINUS_S(PROD_S(C, D))> { };
214 MINUS_S(PROD_S(C, D))> :
216 MINUS_S(PROD_S(C, D))> { };
218 TEMPL(T4)
struct Sum<MINUS_S(PROD_S(A, B)),
223 TEMPL(N1T2)
struct Sum<PROD_S(A, B), NUM(n)> :
226 TEMPL(N1T2)
struct Sum<NUM(n), PROD_S(A, B)> :
const Numerical< n > & num()
typedef POWER(A, NUM(n)) arg
static type combine(const A &_1, const B &_2)
DecomposeProduct< arg, typename Div::arg > D
TEMPL(T1) struct Divides0
typedef PROD(F, SUM(RATIO(A, F), RATIO(B, F))) type
#define COMBINE(A, B, RES)
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
static type get(const PROD_S(A, B)&_)
Power< A, B >::type pow(const A &a, const B &b)
T get(const Candidate &c)
::boost::mpl::if_< D1, D1, typename::boost::mpl::if_< D2, D2, D0 >::type >::type Div