4 #include <NTL/mat_ZZ.h>
5 #include <barvinok/NTL_QQ.h>
6 #include <barvinok/options.h>
7 #include "decomposer.h"
16 /* base for non-parametric counting */
17 struct np_base
: public polar_decomposer
{
21 np_base(unsigned dim
) {
26 virtual void handle_polar(Polyhedron
*C
, Value
*vertex
, QQ c
) = 0;
27 virtual void handle_polar(Polyhedron
*C
, int s
);
28 virtual void start(Polyhedron
*P
, barvinok_options
*options
);
29 void do_vertex_cone(const QQ
& factor
, Polyhedron
*Cone
,
30 Value
*vertex
, barvinok_options
*options
) {
31 current_vertex
= vertex
;
32 this->factor
= factor
;
33 decompose(Cone
, options
);
35 virtual void init(Polyhedron
*P
) {
37 virtual void get_count(Value
*result
) {
45 Value
*current_vertex
;
48 struct reducer
: public np_base
{
55 int lower
; // call base when only this many variables is left
57 reducer(unsigned dim
) : np_base(dim
) {
70 virtual void handle_polar(Polyhedron
*C
, Value
*vertex
, QQ c
);
71 void reduce(QQ c
, vec_ZZ
& num
, mat_ZZ
& den_f
);
72 virtual void base(QQ
& c
, const vec_ZZ
& num
, const mat_ZZ
& den_f
) = 0;
73 virtual void split(vec_ZZ
& num
, ZZ
& num_s
, vec_ZZ
& num_p
,
74 mat_ZZ
& den_f
, vec_ZZ
& den_s
, mat_ZZ
& den_r
) = 0;
75 virtual gen_fun
*get_gf() {
80 struct ireducer
: public reducer
{
81 ireducer(unsigned dim
) : reducer(dim
) {}
83 virtual void split(vec_ZZ
& num
, ZZ
& num_s
, vec_ZZ
& num_p
,
84 mat_ZZ
& den_f
, vec_ZZ
& den_s
, mat_ZZ
& den_r
);
87 void normalize(ZZ
& sign
, ZZ
& num_s
, vec_ZZ
& num_p
, vec_ZZ
& den_s
, vec_ZZ
& den_p
,
90 // incremental counter
91 struct icounter
: public ireducer
{
94 icounter(unsigned dim
) : ireducer(dim
) {
101 virtual void base(QQ
& c
, const vec_ZZ
& num
, const mat_ZZ
& den_f
);
102 virtual void get_count(Value
*result
) {
103 assert(value_one_p(&count
[0]._mp_den
));
104 value_assign(*result
, &count
[0]._mp_num
);
108 void normalize(ZZ
& sign
, ZZ
& num
, vec_ZZ
& den
);
110 /* An incremental counter for possibly infinite sets.
111 * Rather than just keeping track of the constant term
112 * of the Laurent expansions, we also keep track of the
113 * coefficients of negative powers.
114 * If any of these is non-zero, then the counted set is infinite.
116 struct infinite_icounter
: public ireducer
{
117 /* an array of coefficients; count[i] is the coeffient of
118 * the term wtih power -i.
123 infinite_icounter(unsigned dim
, unsigned maxlen
) : ireducer(dim
), len(maxlen
+1) {
124 count
= new mpq_t
[len
];
125 for (int i
= 0; i
< len
; ++i
)
129 ~infinite_icounter() {
130 for (int i
= 0; i
< len
; ++i
)
134 virtual void base(QQ
& c
, const vec_ZZ
& num
, const mat_ZZ
& den_f
);