evalue.c: evalue_sum: move sign handling into esum_over_domain
[barvinok.git] / summate.c
blobe2be5ba8f8f77027041629d16d704b4abf56eeb7
1 #include <barvinok/options.h>
2 #include "bernoulli.h"
3 #include "euler.h"
4 #include "laurent.h"
5 #include "summate.h"
7 evalue *barvinok_summate(evalue *e, int nvar, struct barvinok_options *options)
9 if (options->summation == BV_SUM_EULER)
10 return euler_summate(e, nvar, options);
11 else if (options->summation == BV_SUM_LAURENT)
12 return laurent_summate(e, nvar, options);
13 else if (options->summation == BV_SUM_BERNOULLI)
14 return Bernoulli_sum_evalue(e, nvar, options);
15 else
16 return evalue_sum(e, nvar, options->MaxRays);
19 /* Turn unweighted counting problem into "weighted" counting problem
20 * with weight equal to 1 and call barvinok_summate on this weighted problem.
22 evalue *barvinok_summate_unweighted(Polyhedron *P, Polyhedron *C,
23 struct barvinok_options *options)
25 Polyhedron *CA, *D;
26 evalue e;
27 evalue *sum;
29 if (emptyQ(P) || emptyQ(C))
30 return evalue_zero();
32 CA = align_context(C, P->Dimension, options->MaxRays);
33 D = DomainIntersection(P, CA, options->MaxRays);
34 Domain_Free(CA);
36 if (emptyQ(D)) {
37 Domain_Free(D);
38 return evalue_zero();
41 value_init(e.d);
42 e.x.p = new_enode(partition, 2, P->Dimension);
43 EVALUE_SET_DOMAIN(e.x.p->arr[0], D);
44 evalue_set_si(&e.x.p->arr[1], 1, 1);
45 sum = barvinok_summate(&e, P->Dimension - C->Dimension, options);
46 free_evalue_refs(&e);
47 return sum;