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 signed_cone_consumer
{
21 np_base(unsigned dim
) {
26 virtual void handle(const mat_ZZ
& rays
, Value
*vertex
, QQ c
, int *closed
,
27 barvinok_options
*options
) = 0;
28 virtual void handle(const signed_cone
& sc
, barvinok_options
*options
);
29 virtual void start(Polyhedron
*P
, barvinok_options
*options
);
30 void do_vertex_cone(const QQ
& factor
, Polyhedron
*Cone
,
31 Value
*vertex
, barvinok_options
*options
) {
32 current_vertex
= vertex
;
33 this->factor
= factor
;
34 barvinok_decompose(Cone
, *this, options
);
36 virtual void init(Polyhedron
*P
) {
38 virtual void get_count(Value
*result
) {
46 Value
*current_vertex
;
49 struct reducer
: public np_base
{
56 int lower
; // call base when only this many variables is left
58 reducer(unsigned dim
) : np_base(dim
) {
71 virtual void handle(const mat_ZZ
& rays
, Value
*vertex
, QQ c
, int *closed
,
72 barvinok_options
*options
);
73 void reduce(QQ c
, vec_ZZ
& num
, const mat_ZZ
& den_f
);
74 virtual void base(QQ
& c
, const vec_ZZ
& num
, const mat_ZZ
& den_f
) = 0;
75 virtual void split(vec_ZZ
& num
, ZZ
& num_s
, vec_ZZ
& num_p
,
76 const mat_ZZ
& den_f
, vec_ZZ
& den_s
, mat_ZZ
& den_r
) = 0;
77 virtual gen_fun
*get_gf() {
83 struct ireducer
: public reducer
{
84 ireducer(unsigned dim
) : reducer(dim
) {}
86 virtual void split(vec_ZZ
& num
, ZZ
& num_s
, vec_ZZ
& num_p
,
87 const mat_ZZ
& den_f
, vec_ZZ
& den_s
, mat_ZZ
& den_r
);
90 void normalize(ZZ
& sign
, ZZ
& num_s
, vec_ZZ
& num_p
, vec_ZZ
& den_s
, vec_ZZ
& den_p
,
93 // incremental counter
94 struct icounter
: public ireducer
{
97 icounter(unsigned dim
) : ireducer(dim
) {
104 virtual void base(QQ
& c
, const vec_ZZ
& num
, const mat_ZZ
& den_f
);
105 virtual void get_count(Value
*result
) {
106 assert(value_one_p(&count
[0]._mp_den
));
107 value_assign(*result
, &count
[0]._mp_num
);
111 void normalize(ZZ
& sign
, ZZ
& num
, vec_ZZ
& den
);
113 /* An incremental counter for possibly infinite sets.
114 * Rather than just keeping track of the constant term
115 * of the Laurent expansions, we also keep track of the
116 * coefficients of negative powers.
117 * If any of these is non-zero, then the counted set is infinite.
119 struct infinite_icounter
: public ireducer
{
120 /* an array of coefficients; count[i] is the coeffient of
121 * the term with power -i.
126 infinite_icounter(unsigned dim
, unsigned maxlen
) : ireducer(dim
), len(maxlen
+1) {
127 /* Not sure whether it works for dim != 1 */
129 count
= new mpq_t
[len
];
130 for (int i
= 0; i
< len
; ++i
)
134 ~infinite_icounter() {
135 for (int i
= 0; i
< len
; ++i
)
139 virtual void base(QQ
& c
, const vec_ZZ
& num
, const mat_ZZ
& den_f
);