AUTHORS: update support information
[barvinok.git] / ex_convert.cc
blobfbcabcf26ddde49ae6155a0bbdfc2afa0a98864a
1 #include <bernstein/bernstein.h>
2 #include "ex_convert.h"
4 using namespace GiNaC;
5 using namespace bernstein;
7 #define ALLOC(type) (type*)malloc(sizeof(type))
9 static evalue *ex2evalue(const ex& poly, const exvector& params, int pos)
11 if (pos >= params.size()) {
12 evalue *c = ALLOC(evalue);
13 value_init(c->d);
14 value_init(c->x.n);
15 assert(is_a<numeric>(poly));
16 numeric2value(ex_to<numeric>(poly).numer(), c->x.n);
17 numeric2value(ex_to<numeric>(poly).denom(), c->d);
18 return c;
21 evalue *v = evalue_var(pos);
22 evalue *sum = ex2evalue(poly.coeff(params[pos], poly.degree(params[pos])),
23 params, pos+1);
24 for (int i = poly.degree(params[pos])-1; i >= 0; --i) {
25 evalue *t = ex2evalue(poly.coeff(params[pos], i), params, pos+1);
26 emul(v, sum);
27 eadd(t, sum);
28 evalue_free(t);
30 evalue_free(v);
31 return sum;
34 evalue *ex2evalue(const ex& poly, const exvector& params)
36 return ex2evalue(poly, params, 0);