2 #include <NTL/mat_ZZ.h>
4 #include <polylib/polylibgmp.h>
5 #include "ev_operations.h"
11 #include "verif_ehrhart.h"
13 #ifdef HAVE_GROWING_CHERNIKOVA
21 #define getopt_long(a,b,c,d,e) getopt(a,b,c)
24 struct option options
[] = {
25 { "explicit", no_argument
, 0, 'e' },
26 { "series", no_argument
, 0, 's' },
27 { "verbose", no_argument
, 0, 'v' },
28 { "version", no_argument
, 0, 'V' },
33 /* RANGE : normal range for evalutations (-RANGE -> RANGE) */
36 /* SRANGE : small range for evalutations */
39 /* if dimension >= BIDDIM, use SRANGE */
42 /* VSRANGE : very small range for evalutations */
45 /* if dimension >= VBIDDIM, use VSRANGE */
48 int check_series(Polyhedron
*S
, Polyhedron
*CS
, gen_fun
*gf
,
49 int nparam
,int pos
,Value
*z
)
61 /* Computes the coefficient */
62 gf
->coefficient(&z
[S
->Dimension
-nparam
+1], &c
);
64 /* if c=0 we may be out of context. */
65 /* scanning is useless in this case*/
67 #ifdef PRINT_ALL_RESULTS
69 value_print(stdout
,VALUE_FMT
,z
[S
->Dimension
-nparam
+1]);
70 for(k
=S
->Dimension
-nparam
+2;k
<=S
->Dimension
;++k
) {
72 value_print(stdout
,VALUE_FMT
,z
[k
]);
75 value_print(stdout
,VALUE_FMT
,c
);
78 /* Manually count the number of points */
79 count_points(1,S
,z
,&tmp
);
80 #ifdef PRINT_ALL_RESULTS
82 value_print(stdout
, P_VALUE_FMT
, tmp
);
89 fprintf(stderr
,"Error !\n");
90 fprintf(stderr
,"EP( ");
91 value_print(stderr
,VALUE_FMT
,z
[S
->Dimension
-nparam
+1]);
92 for(k
=S
->Dimension
-nparam
+2;k
<=S
->Dimension
;++k
) {
94 value_print(stderr
,VALUE_FMT
,z
[k
]);
96 fprintf(stderr
," ) should be ");
97 value_print(stderr
,VALUE_FMT
,tmp
);
98 fprintf(stderr
,", while EP eval gives ");
99 value_print(stderr
,VALUE_FMT
,c
);
100 fprintf(stderr
,".\n");
101 #ifndef DONT_BREAK_ON_ERROR
102 value_clear(c
); value_clear(tmp
);
106 #ifdef PRINT_ALL_RESULTS
112 !(lower_upper_bounds(1+pos
, CS
, &z
[S
->Dimension
-nparam
], &LB
, &UB
));
114 for(value_assign(tmp
,LB
); value_le(tmp
,UB
); value_increment(tmp
,tmp
)) {
115 #ifndef PRINT_ALL_RESULTS
116 k
= VALUE_TO_INT(tmp
);
117 if(!pos
&& !(k
%st
)) {
122 value_assign(z
[pos
+S
->Dimension
-nparam
+1],tmp
);
123 if(!check_series(S
, CS
, gf
, nparam
, pos
+1, z
)) {
124 value_clear(c
); value_clear(tmp
);
130 value_set_si(z
[pos
+S
->Dimension
-nparam
+1],0);
140 int main(int argc
,char *argv
[]) {
142 Matrix
*C1
, *P1
, *MM
;
143 Polyhedron
*C
, *P
, *S
, *CS
, *U
;
149 int m
= INT_MAX
, M
= INT_MIN
, r
;
156 while ((c
= getopt_long(argc
, argv
, "m:M:r:sveV", options
, &ind
)) != -1) {
178 printf(barvinok_version());
184 /******* Read the input *********/
188 if(C1
->NbColumns
< 2) {
189 fprintf(stderr
,"Not enough parameters !\n");
193 P
= Constraints2Polyhedron(P1
,MAXRAYS
);
194 C
= Constraints2Polyhedron(C1
,MAXRAYS
);
195 params
= Read_ParamNames(stdin
, C
->Dimension
);
199 /******* Read the options: initialize Min and Max ********/
200 if(P
->Dimension
>= VBIGDIM
)
202 else if(P
->Dimension
>= BIGDIM
)
213 fprintf(stderr
,"Nothing to do: Min > Max !\n");
222 /******* Compute true context *******/
223 CC
= align_context(C
,P
->Dimension
,MAXRAYS
);
224 PP
= DomainIntersection(P
,CC
,MAXRAYS
);
226 C1
= Matrix_Alloc(C
->Dimension
+1,P
->Dimension
+1);
228 for(i
=0;i
<C1
->NbRows
;i
++)
229 for(j
=0;j
<C1
->NbColumns
;j
++)
230 if(i
==j
-P
->Dimension
+C
->Dimension
)
231 value_set_si(C1
->p
[i
][j
],1);
233 value_set_si(C1
->p
[i
][j
],0);
234 CC
= Polyhedron_Image(PP
,C1
,MAXRAYS
);
240 /* Intersect context with range */
241 if(C
->Dimension
> 0) {
242 MM
= Matrix_Alloc(2*C
->Dimension
, C
->Dimension
+2);
243 for (i
= 0; i
< C
->Dimension
; ++i
) {
244 value_set_si(MM
->p
[2*i
][0], 1);
245 value_set_si(MM
->p
[2*i
][1+i
], 1);
246 value_set_si(MM
->p
[2*i
][1+C
->Dimension
], -m
);
247 value_set_si(MM
->p
[2*i
+1][0], 1);
248 value_set_si(MM
->p
[2*i
+1][1+i
], -1);
249 value_set_si(MM
->p
[2*i
+1][1+C
->Dimension
], M
);
251 CC
= AddConstraints(MM
->p
[0], 2*C
->Dimension
, C
, MAXRAYS
);
252 U
= Universe_Polyhedron(0);
253 CS
= Polyhedron_Scan(CC
, U
, MAXRAYS
);
262 /******* Compute EP *********/
264 en
= barvinok_enumerate(P
,C
,MAXRAYS
);
267 gf
= barvinok_series(P
, C
, MAXRAYS
);
269 gf
->print(C
->Dimension
, params
);
274 en
= partition2enumeration(EP
);
278 /******* Initializations for check *********/
279 p
= (Value
*)malloc(sizeof(Value
) * (P
->Dimension
+2));
280 for(i
=0;i
<=P
->Dimension
;i
++) {
282 value_set_si(p
[i
],0);
285 value_set_si(p
[i
],1);
287 /* S = scanning list of polyhedra */
288 S
= Polyhedron_Scan(P
,C
,MAXRAYS
);
290 #ifndef PRINT_ALL_RESULTS
291 if(C
->Dimension
> 0) {
292 value_subtract(tmp
,Max
,Min
);
293 if (VALUE_TO_INT(tmp
) > 80)
294 st
= 1+(VALUE_TO_INT(tmp
))/80;
297 for(i
=VALUE_TO_INT(Min
);i
<=VALUE_TO_INT(Max
);i
+=st
)
304 /******* CHECK NOW *********/
306 if (!series
|| function
) {
307 if (!check_poly(S
, CS
,en
,C
->Dimension
,0,p
))
310 if (!check_series(S
, CS
,gf
,C
->Dimension
,0,p
))
317 fprintf(stderr
,"Check failed !\n");
319 #ifndef PRINT_ALL_RESULTS
326 for(i
=0;i
<=(P
->Dimension
+1);i
++)
330 Free_ParamNames(params
, C
->Dimension
);