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