remove a few duplicate definitions of MAXRAYS
[barvinok.git] / reducer.h
blob8fd1c1f42c76dcb4fdd2d2f74312423be177e827
1 #ifndef REDUCER_H
2 #define REDUCER_H
4 #include <NTL/mat_ZZ.h>
5 #include <barvinok/NTL_QQ.h>
6 #include <barvinok/options.h>
7 #include "decomposer.h"
8 #include "dpoly.h"
10 #ifdef NTL_STD_CXX
11 using namespace NTL;
12 #endif
14 struct gen_fun;
16 /* base for non-parametric counting */
17 struct np_base : public polar_decomposer {
18 unsigned dim;
19 ZZ one;
21 np_base(unsigned dim) {
22 this->dim = dim;
23 one = 1;
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) {
38 assert(0);
40 virtual ~np_base() {
43 private:
44 QQ factor;
45 Value *current_vertex;
48 struct reducer : public np_base {
49 vec_ZZ vertex;
50 //vec_ZZ den;
51 ZZ num;
52 mpq_t tcount;
53 mpz_t tn;
54 mpz_t td;
55 int lower; // call base when only this many variables is left
57 reducer(unsigned dim) : np_base(dim) {
58 //den.SetLength(dim);
59 mpq_init(tcount);
60 mpz_init(tn);
61 mpz_init(td);
64 ~reducer() {
65 mpq_clear(tcount);
66 mpz_clear(tn);
67 mpz_clear(td);
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() {
76 assert(0);
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,
88 mat_ZZ& f);
90 // incremental counter
91 struct icounter : public ireducer {
92 mpq_t count;
94 icounter(unsigned dim) : ireducer(dim) {
95 mpq_init(count);
96 lower = 1;
98 ~icounter() {
99 mpq_clear(count);
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.
120 mpq_t *count;
121 unsigned len;
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)
126 mpq_init(count[i]);
127 lower = 1;
129 ~infinite_icounter() {
130 for (int i = 0; i < len; ++i)
131 mpq_clear(count[i]);
132 delete [] count;
134 virtual void base(QQ& c, const vec_ZZ& num, const mat_ZZ& den_f);
137 #endif