evalue.c: extract evalue_extract_affine from bernstein.cc
[barvinok.git] / polysign_polylib.c
blob19e512b887e599b34bb9d6fee5c39ea770765797
1 #include <barvinok/util.h>
2 #include <barvinok/options.h>
3 #include "polysign.h"
5 static enum order_sign interval_minmax(Polyhedron *I)
7 int i;
8 int min = 1;
9 int max = -1;
10 assert(I->Dimension == 1);
11 POL_ENSURE_VERTICES(I);
12 for (i = 0; i < I->NbRays; ++i) {
13 if (value_pos_p(I->Ray[i][1]))
14 max = 1;
15 else if (value_neg_p(I->Ray[i][1]))
16 min = -1;
17 else {
18 if (max < 0)
19 max = 0;
20 if (min > 0)
21 min = 0;
24 if (min > 0)
25 return order_gt;
26 if (max < 0)
27 return order_lt;
28 if (min == max)
29 return order_eq;
30 if (max == 0)
31 return order_le;
32 if (min == 0)
33 return order_ge;
34 return order_unknown;
37 /* Returns the sign of the affine function specified by T on the polyhedron D */
38 enum order_sign PL_polyhedron_affine_sign(Polyhedron *D, Matrix *T,
39 struct barvinok_options *options)
41 enum order_sign sign;
42 Polyhedron *I = Polyhedron_Image(D, T, options->MaxRays);
43 if (POL_ISSET(options->MaxRays, POL_INTEGER))
44 I = DomainConstraintSimplify(I, options->MaxRays);
45 if (emptyQ2(I)) {
46 Polyhedron_Free(I);
47 I = Polyhedron_Image(D, T, options->MaxRays);
49 sign = interval_minmax(I);
50 Polyhedron_Free(I);
51 return sign;