gen_fun: store terms in a set rather than in a vector
[barvinok.git] / barvinok / genfun.h
blob652841af2a993591d7f9bf6f0b44668c690766e0
1 #ifndef GENFUN_H
2 #define GENFUN_H
4 #include <set>
5 #include <iostream>
6 #include <gmp.h>
7 #include <NTL/mat_ZZ.h>
8 #include <barvinok/evalue.h>
9 #include <barvinok/NTL_QQ.h>
10 #include <barvinok/options.h>
12 #ifdef NTL_STD_CXX
13 using namespace NTL;
14 #endif
16 struct short_rat {
17 struct __short_rat_n {
18 /* rows: terms in numerator */
19 /* coeff has two columns: the numerator and the denominator */
20 vec_QQ coeff;
21 mat_ZZ power;
22 } n;
23 struct __short_rat_d {
24 /* rows: factors in denominator */
25 mat_ZZ power;
26 } d;
27 void add(short_rat *rat);
28 bool reduced();
29 short_rat(Value c);
30 short_rat(const QQ& c, const vec_ZZ& num, const mat_ZZ& den);
31 void normalize();
34 struct short_rat_lex_smaller_denominator {
35 bool operator()(const short_rat* r1, const short_rat* r2) const;
38 typedef std::set<short_rat *, short_rat_lex_smaller_denominator > short_rat_list;
40 struct gen_fun {
41 short_rat_list term;
42 Polyhedron *context;
44 void add(const QQ& c, const vec_ZZ& num, const mat_ZZ& den);
45 /* add c times gf */
46 void add(const QQ& c, const gen_fun *gf);
47 void substitute(Matrix *CP);
48 gen_fun *Hadamard_product(const gen_fun *gf, barvinok_options *options);
49 void add_union(gen_fun *gf, barvinok_options *options);
50 void shift(const vec_ZZ& offset);
51 void divide(const vec_ZZ& power);
52 void print(std::ostream& os, unsigned int nparam, char **param_name) const;
53 operator evalue *() const;
54 void coefficient(Value* params, Value* c) const;
55 gen_fun *summate(int nvar, barvinok_options *options) const;
56 bool summate(Value *sum) const;
58 gen_fun(const gen_fun *gf) {
59 QQ one(1, 1);
60 context = Polyhedron_Copy(gf->context);
61 add(one, gf);
63 gen_fun(Value c);
64 gen_fun(Polyhedron *C = NULL) : context(C) {}
65 ~gen_fun() {
66 if (context)
67 Polyhedron_Free(context);
68 for (short_rat_list::iterator i = term.begin(); i != term.end(); ++i)
69 delete *i;
73 #endif