1 /*************************************************/
3 /* program to compare effective number of points */
4 /* in a polytope with the corresponding */
5 /* evaluation of the Ehrhart polynomial. */
6 /* Parameters vary in range -RANGE to RANGE */
7 /* (define below) by default. */
8 /* Can be overridden by specifying */
9 /* -r<RANGE>, or -m<min> and -M<max> */
11 /* written by Vincent Loechner (c) 2000. */
12 /* loechner@icps.u-strasbg.fr */
13 /*************************************************/
20 #include <barvinok/evalue.h>
21 #include <barvinok/barvinok.h>
22 #include "verif_ehrhart.h"
24 #undef CS /* for Solaris 10 */
26 struct check_poly_EP_data
{
27 struct check_poly_data cp
;
33 static int cp_EP(const struct check_poly_data
*data
, int nparam
, Value
*z
,
34 const struct verify_options
*options
)
39 int pa
= options
->barvinok
->polynomial_approximation
;
40 struct check_poly_EP_data
* EP_data
= (struct check_poly_EP_data
*) data
;
41 const evalue
*EP
= EP_data
->EP
;
42 int exist
= EP_data
->exist
;
43 Polyhedron
*S
= EP_data
->S
;
48 /* Computes the ehrhart polynomial */
49 if (!options
->exact
) {
50 double d
= compute_evalue(EP
, z
);
51 if (pa
== BV_APPROX_SIGN_LOWER
)
53 else if (pa
== BV_APPROX_SIGN_UPPER
)
55 value_set_double(c
, d
+.25);
57 evalue
*res
= evalue_eval(EP
, z
);
58 if (pa
== BV_APPROX_SIGN_LOWER
)
59 mpz_cdiv_q(c
, res
->x
.n
, res
->d
);
60 else if (pa
== BV_APPROX_SIGN_UPPER
)
61 mpz_fdiv_q(c
, res
->x
.n
, res
->d
);
63 mpz_tdiv_q(c
, res
->x
.n
, res
->d
);
67 if (options
->print_all
) {
69 value_print(stdout
, VALUE_FMT
, z
[0]);
70 for (k
= 1; k
< nparam
; ++k
) {
72 value_print(stdout
, VALUE_FMT
, z
[k
]);
75 value_print(stdout
, VALUE_FMT
, c
);
78 /* Manually count the number of points */
80 count_points_e(1, S
, exist
, nparam
, data
->z
, &tmp
);
82 count_points(1, S
, data
->z
, &tmp
);
84 if (options
->print_all
) {
86 value_print(stdout
, VALUE_FMT
, tmp
);
90 if (pa
== BV_APPROX_SIGN_APPROX
)
91 /* just accept everything */
93 else if (pa
== BV_APPROX_SIGN_LOWER
)
94 ok
= value_le(c
, tmp
);
95 else if (pa
== BV_APPROX_SIGN_UPPER
)
96 ok
= value_ge(c
, tmp
);
98 ok
= value_eq(c
, tmp
);
103 fprintf(stderr
, "Error !\n");
104 fprintf(stderr
, "EP(");
105 value_print(stderr
, VALUE_FMT
, z
[0]);
106 for (k
= 1; k
< nparam
; ++k
) {
107 fprintf(stderr
,", ");
108 value_print(stderr
, VALUE_FMT
, z
[k
]);
110 fprintf(stderr
, ") should be ");
111 value_print(stderr
, VALUE_FMT
, tmp
);
112 fprintf(stderr
, ", while EP eval gives ");
113 value_print(stderr
, VALUE_FMT
, c
);
114 fprintf(stderr
, ".\n");
115 print_evalue(stderr
, EP
, options
->params
);
116 if (value_zero_p(EP
->d
) && EP
->x
.p
->type
== partition
)
117 for (k
= 0; k
< EP
->x
.p
->size
/2; ++k
) {
118 Polyhedron
*D
= EVALUE_DOMAIN(EP
->x
.p
->arr
[2*k
]);
119 if (in_domain(D
, z
)) {
120 Print_Domain(stderr
, D
, options
->params
);
121 print_evalue(stderr
, &EP
->x
.p
->arr
[2*k
+1], options
->params
);
124 } else if (options
->print_all
)
133 int check_poly_EP(Polyhedron
*S
, Polyhedron
*CS
, evalue
*EP
, int exist
,
134 int nparam
, int pos
, Value
*z
, const struct verify_options
*options
)
136 struct check_poly_EP_data data
;
138 data
.cp
.check
= cp_EP
;
142 return check_poly(CS
, &data
.cp
, nparam
, pos
, z
+S
->Dimension
-nparam
+1, options
);