Polyhedron_Factor: make sure group information gets updated
[barvinok.git] / barvinok / genfun.h
blobfdd1c0c7e70e79ff6b7071e43c3fcde61d9b31bb
1 #ifndef GENFUN_H
2 #define GENFUN_H
4 #include <barvinok/set.h>
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 using namespace NTL;
14 struct short_rat {
15 struct __short_rat_n {
16 /* rows of power/columns of coeff: terms in numerator */
17 vec_QQ coeff;
18 mat_ZZ power;
19 } n;
20 struct __short_rat_d {
21 /* rows: factors in denominator */
22 mat_ZZ power;
23 } d;
24 void add(const short_rat *rat);
25 QQ coefficient(Value* params, barvinok_options *options) const;
26 bool reduced();
27 short_rat(const short_rat& r);
28 short_rat(Value c);
29 short_rat(const QQ& c, const vec_ZZ& num, const mat_ZZ& den);
30 short_rat(const vec_QQ& c, const mat_ZZ& num, const mat_ZZ& den);
31 void normalize();
32 void print(std::ostream& os, unsigned int nparam,
33 const char **param_name) const;
36 struct short_rat_lex_smaller_denominator {
37 bool operator()(const short_rat* r1, const short_rat* r2) const;
40 typedef std::set<short_rat *, short_rat_lex_smaller_denominator > short_rat_list;
42 struct gen_fun {
43 short_rat_list term;
44 Polyhedron *context;
46 void add(const QQ& c, const vec_ZZ& num, const mat_ZZ& den);
47 void add(short_rat *r);
48 /* add c times gf */
49 void add(const QQ& c, const gen_fun *gf, barvinok_options *options);
50 void substitute(Matrix *CP);
51 gen_fun *Hadamard_product(const gen_fun *gf, barvinok_options *options);
52 void add_union(gen_fun *gf, barvinok_options *options);
53 void shift(const vec_ZZ& offset);
54 void divide(const vec_ZZ& power);
55 void print(std::ostream& os, unsigned int nparam,
56 const char **param_name) const;
57 static gen_fun *read(std::istream& is, barvinok_options *options);
58 operator evalue *() const;
59 ZZ coefficient(Value* params, barvinok_options *options) const;
60 void coefficient(Value* params, Value* c) const;
61 gen_fun *summate(int nvar, barvinok_options *options) const;
62 bool summate(Value *sum) const;
63 bool is_zero() const;
65 gen_fun(const gen_fun *gf) {
66 QQ one(1, 1);
67 context = Polyhedron_Copy(gf->context);
68 add(one, gf);
70 gen_fun(Value c);
71 gen_fun(Polyhedron *C) : context(C) {}
72 void clear_terms() {
73 for (short_rat_list::iterator i = term.begin(); i != term.end(); ++i)
74 delete *i;
75 term.clear();
77 ~gen_fun() {
78 Polyhedron_Free(context);
79 clear_terms();
81 private:
82 void extend_context(const gen_fun *gf, barvinok_options *options);
83 void add(const QQ& c, const gen_fun *gf);
86 std::ostream & operator<< (std::ostream & os, const gen_fun& gf);
88 #endif