4 #include <NTL/mat_ZZ.h>
5 #include <barvinok/NTL_QQ.h>
6 #include "decomposer.h"
15 /* base for non-parametric counting */
16 struct np_base
: public polar_decomposer
{
20 np_base(unsigned dim
) {
25 virtual void handle_polar(Polyhedron
*C
, Value
*vertex
, QQ c
) = 0;
26 virtual void handle_polar(Polyhedron
*C
, int s
);
27 virtual void start(Polyhedron
*P
, unsigned MaxRays
);
28 void do_vertex_cone(const QQ
& factor
, Polyhedron
*Cone
,
29 Value
*vertex
, unsigned MaxRays
) {
30 current_vertex
= vertex
;
31 this->factor
= factor
;
32 decompose(Cone
, MaxRays
);
34 virtual void init(Polyhedron
*P
) {
36 virtual void get_count(Value
*result
) {
44 Value
*current_vertex
;
47 struct reducer
: public np_base
{
54 int lower
; // call base when only this many variables is left
56 reducer(unsigned dim
) : np_base(dim
) {
69 virtual void handle_polar(Polyhedron
*C
, Value
*vertex
, QQ c
);
70 void reduce(QQ c
, vec_ZZ
& num
, mat_ZZ
& den_f
);
71 virtual void base(QQ
& c
, const vec_ZZ
& num
, const mat_ZZ
& den_f
) = 0;
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
) = 0;
74 virtual gen_fun
*get_gf() {
79 struct ireducer
: public reducer
{
80 ireducer(unsigned dim
) : reducer(dim
) {}
82 virtual void split(vec_ZZ
& num
, ZZ
& num_s
, vec_ZZ
& num_p
,
83 mat_ZZ
& den_f
, vec_ZZ
& den_s
, mat_ZZ
& den_r
);
86 void normalize(ZZ
& sign
, ZZ
& num_s
, vec_ZZ
& num_p
, vec_ZZ
& den_s
, vec_ZZ
& den_p
,
89 // incremental counter
90 struct icounter
: public ireducer
{
93 icounter(unsigned dim
) : ireducer(dim
) {
100 virtual void base(QQ
& c
, const vec_ZZ
& num
, const mat_ZZ
& den_f
);
101 virtual void get_count(Value
*result
) {
102 assert(value_one_p(&count
[0]._mp_den
));
103 value_assign(*result
, &count
[0]._mp_num
);
107 void normalize(ZZ
& sign
, ZZ
& num
, vec_ZZ
& den
);
109 /* An incremental counter for possibly infinite sets.
110 * Rather than just keeping track of the constant term
111 * of the Laurent expansions, we also keep track of the
112 * coefficients of negative powers.
113 * If any of these is non-zero, then the counted set is infinite.
115 struct infinite_icounter
: public ireducer
{
116 /* an array of coefficients; count[i] is the coeffient of
117 * the term wtih power -i.
122 infinite_icounter(unsigned dim
, unsigned maxlen
) : ireducer(dim
), len(maxlen
+1) {
123 count
= new mpq_t
[len
];
124 for (int i
= 0; i
< len
; ++i
)
128 ~infinite_icounter() {
129 for (int i
= 0; i
< len
; ++i
)
133 virtual void base(QQ
& c
, const vec_ZZ
& num
, const mat_ZZ
& den_f
);