4 #include <NTL/mat_ZZ.h>
5 #include <barvinok/NTL_QQ.h>
6 #include "decomposer.h"
13 /* base for non-parametric counting */
14 struct np_base
: public polar_decomposer
{
18 np_base(unsigned dim
) {
23 virtual void handle_polar(Polyhedron
*C
, Value
*vertex
, QQ c
) = 0;
24 virtual void handle_polar(Polyhedron
*C
, int s
);
25 void start(Polyhedron
*P
, unsigned MaxRays
);
26 void do_vertex_cone(const QQ
& factor
, Polyhedron
*Cone
,
27 Value
*vertex
, unsigned MaxRays
) {
28 current_vertex
= vertex
;
29 this->factor
= factor
;
30 decompose(Cone
, MaxRays
);
32 virtual void init(Polyhedron
*P
) {
37 Value
*current_vertex
;
40 struct reducer
: public np_base
{
47 int lower
; // call base when only this many variables is left
49 reducer(unsigned dim
) : np_base(dim
) {
62 virtual void handle_polar(Polyhedron
*C
, Value
*vertex
, QQ c
);
63 void reduce(QQ c
, vec_ZZ
& num
, mat_ZZ
& den_f
);
64 virtual void base(QQ
& c
, const vec_ZZ
& num
, const mat_ZZ
& den_f
) = 0;
65 virtual void split(vec_ZZ
& num
, ZZ
& num_s
, vec_ZZ
& num_p
,
66 mat_ZZ
& den_f
, vec_ZZ
& den_s
, mat_ZZ
& den_r
) = 0;
69 struct ireducer
: public reducer
{
70 ireducer(unsigned dim
) : reducer(dim
) {}
72 virtual void split(vec_ZZ
& num
, ZZ
& num_s
, vec_ZZ
& num_p
,
73 mat_ZZ
& den_f
, vec_ZZ
& den_s
, mat_ZZ
& den_r
);
76 void normalize(ZZ
& sign
, ZZ
& num_s
, vec_ZZ
& num_p
, vec_ZZ
& den_s
, vec_ZZ
& den_p
,
79 // incremental counter
80 struct icounter
: public ireducer
{
83 icounter(unsigned dim
) : ireducer(dim
) {
90 virtual void base(QQ
& c
, const vec_ZZ
& num
, const mat_ZZ
& den_f
);
93 void normalize(ZZ
& sign
, ZZ
& num
, vec_ZZ
& den
);
95 /* An incremental counter for possibly infinite sets.
96 * Rather than just keeping track of the constant term
97 * of the Laurent expansions, we also keep track of the
98 * coefficients of negative powers.
99 * If any of these is non-zero, then the counted set is infinite.
101 struct infinite_icounter
: public ireducer
{
102 /* an array of coefficients; count[i] is the coeffient of
103 * the term wtih power -i.
108 infinite_icounter(unsigned dim
, unsigned maxlen
) : ireducer(dim
), len(maxlen
+1) {
109 count
= new mpq_t
[len
];
110 for (int i
= 0; i
< len
; ++i
)
114 ~infinite_icounter() {
115 for (int i
= 0; i
< len
; ++i
)
119 virtual void base(QQ
& c
, const vec_ZZ
& num
, const mat_ZZ
& den_f
);