iscc: support addition on a pair of a fold and a quasipolynomial.
[barvinok.git] / counter.h
bloba03c468b78a0bbdfef083c8d6c2f256166afe89d
1 #include "reducer.h"
3 struct counter_base: public np_base {
4 Vector *lambda;
5 Matrix *den;
6 Matrix *num;
7 mpq_t count;
8 Value tmp;
10 counter_base(unsigned dim, unsigned long max_index) : np_base(dim) {
11 mpq_init(count);
12 num = Matrix_Alloc(max_index, 1);
13 den = Matrix_Alloc(dim, 1);
14 lambda = Vector_Alloc(dim);
15 value_init(tmp);
18 virtual void init(Polyhedron *P, int n_try) {
19 vec_ZZ l;
20 randomvector(P, l, dim, n_try);
21 zz2values(l, lambda->p);
24 virtual void reset() {
25 mpq_set_si(count, 0, 0);
28 ~counter_base() {
29 Matrix_Free(num);
30 Matrix_Free(den);
31 Vector_Free(lambda);
32 mpq_clear(count);
33 value_clear(tmp);
36 virtual void add_lattice_points(int sign) = 0;
38 virtual void handle(const mat_ZZ& rays, Value *vertex, const QQ& c,
39 unsigned long det, barvinok_options *options);
40 virtual void get_count(Value *result) {
41 assert(value_one_p(&count[0]._mp_den));
42 value_assign(*result, &count[0]._mp_num);
46 struct counter : public counter_base {
47 counter(unsigned dim, unsigned long max_index) :
48 counter_base(dim, max_index) {}
50 virtual void add_lattice_points(int sign);
53 struct tcounter : public counter_base {
54 mpq_t tcount;
55 dpoly todd;
56 Vector *todd_denom;
57 Value denom;
59 tcounter(unsigned dim, unsigned long max_index) :
60 counter_base(dim, max_index), todd(dim) {
61 mpq_init(tcount);
62 setup_todd(dim);
63 value_init(denom);
66 void setup_todd(unsigned dim);
68 void adapt_todd(dpoly& t, const Value c);
69 void add_powers(dpoly& n, const Value c);
71 ~tcounter() {
72 mpq_clear(tcount);
73 Vector_Free(todd_denom);
74 value_clear(denom);
77 virtual void add_lattice_points(int sign);
80 /* A counter for possibly infinite sets.
81 * Rather than just keeping track of the constant term
82 * of the Laurent expansions, we also keep track of the
83 * coefficients of negative powers.
84 * If any of these is non-zero, then the counted set is infinite.
86 struct infinite_counter {
87 /* an array of coefficients; count[i] is the coeffient of
88 * the term with power -i.
90 vec_ZZ lambda;
91 mpq_t *count;
92 unsigned maxlen;
93 Value tz;
95 infinite_counter(unsigned dim, unsigned maxlen) : maxlen(maxlen) {
96 count = new mpq_t[maxlen+1];
97 for (int i = 0; i <= maxlen; ++i)
98 mpq_init(count[i]);
99 value_init(tz);
102 void init(Polyhedron *context, int n_try);
104 void reduce(const vec_QQ& c, const mat_ZZ& num, const mat_ZZ& den_f);
106 ~infinite_counter() {
107 for (int i = 0; i <= maxlen; ++i)
108 mpq_clear(count[i]);
109 delete [] count;
110 value_clear(tz);