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() {
81 struct ireducer
: public reducer
{
82 ireducer(unsigned dim
) : reducer(dim
) {}
84 virtual void split(vec_ZZ
& num
, ZZ
& num_s
, vec_ZZ
& num_p
,
85 mat_ZZ
& den_f
, vec_ZZ
& den_s
, mat_ZZ
& den_r
);
88 void normalize(ZZ
& sign
, ZZ
& num_s
, vec_ZZ
& num_p
, vec_ZZ
& den_s
, vec_ZZ
& den_p
,
91 // incremental counter
92 struct icounter
: public ireducer
{
95 icounter(unsigned dim
) : ireducer(dim
) {
102 virtual void base(QQ
& c
, const vec_ZZ
& num
, const mat_ZZ
& den_f
);
103 virtual void get_count(Value
*result
) {
104 assert(value_one_p(&count
[0]._mp_den
));
105 value_assign(*result
, &count
[0]._mp_num
);
109 void normalize(ZZ
& sign
, ZZ
& num
, vec_ZZ
& den
);
111 /* An incremental counter for possibly infinite sets.
112 * Rather than just keeping track of the constant term
113 * of the Laurent expansions, we also keep track of the
114 * coefficients of negative powers.
115 * If any of these is non-zero, then the counted set is infinite.
117 struct infinite_icounter
: public ireducer
{
118 /* an array of coefficients; count[i] is the coeffient of
119 * the term with power -i.
124 infinite_icounter(unsigned dim
, unsigned maxlen
) : ireducer(dim
), len(maxlen
+1) {
125 /* Not sure whether it works for dim != 1 */
127 count
= new mpq_t
[len
];
128 for (int i
= 0; i
< len
; ++i
)
132 ~infinite_icounter() {
133 for (int i
= 0; i
< len
; ++i
)
137 virtual void base(QQ
& c
, const vec_ZZ
& num
, const mat_ZZ
& den_f
);