README: update note on shared libraries and NTL
[barvinok.git] / param_polynomial.cc
blob84dd7d21d933c8173efad185516ae0d22eddf128
1 #include "param_polynomial.h"
3 using std::vector;
5 /* Expand "polynomial" as a sum of powers of the "nvar" variables,
6 * and collect the terms in "terms".
7 */
8 static void collect_terms(vector<struct param_term> &terms, vector<int> &powers,
9 const evalue *polynomial, unsigned nvar)
11 if (EVALUE_IS_ZERO(*polynomial))
12 return;
14 if (value_zero_p(polynomial->d))
15 assert(polynomial->x.p->type == ::polynomial);
16 if (value_notzero_p(polynomial->d) || polynomial->x.p->pos > nvar) {
17 struct param_term t;
18 t.powers = powers;
19 t.coeff = polynomial;
20 terms.push_back(t);
21 return;
24 for (int i = polynomial->x.p->size-1; i >= 0; --i) {
25 powers[polynomial->x.p->pos-1] = i;
26 collect_terms(terms, powers, &polynomial->x.p->arr[i], nvar);
30 param_polynomial::param_polynomial(const evalue *polynomial, unsigned nvar)
32 vector<int> powers(nvar);
33 for (int i = 0; i < nvar; ++i)
34 powers[i] = 0;
35 collect_terms(terms, powers, polynomial, nvar);
38 unsigned param_polynomial::degree()
40 unsigned max_degree = 0;
42 for (int i = 0; i < terms.size(); ++i) {
43 int sum = 0;
44 for (int j = 0; j < terms[i].powers.size(); ++j)
45 sum += terms[i].powers[j];
46 if (sum > max_degree)
47 max_degree = sum;
49 return max_degree;