1 #include "param_polynomial.h"
5 /* Expand "polynomial" as a sum of powers of the "nvar" variables,
6 * and collect the terms in "terms".
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
))
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
) {
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
)
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
) {
44 for (int j
= 0; j
< terms
[i
].powers
.size(); ++j
)
45 sum
+= terms
[i
].powers
[j
];