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' },
32 /* RANGE : normal range for evalutations (-RANGE -> RANGE) */
35 /* SRANGE : small range for evalutations */
38 /* if dimension >= BIDDIM, use SRANGE */
41 /* VSRANGE : very small range for evalutations */
44 /* if dimension >= VBIDDIM, use VSRANGE */
47 int check_series(Polyhedron
*S
,Polyhedron
*C
, gen_fun
*gf
,
48 int nparam
,int pos
,Value
*z
)
56 /* Computes the coefficient */
57 gf
->coefficient(&z
[S
->Dimension
-nparam
+1], &c
);
59 /* if c=0 we may be out of context. */
60 /* scanning is useless in this case*/
61 if(!in_domain(C
,&z
[S
->Dimension
-nparam
+1])) {
65 #ifdef PRINT_ALL_RESULTS
67 value_print(stdout
,VALUE_FMT
,z
[S
->Dimension
-nparam
+1]);
68 for(k
=S
->Dimension
-nparam
+2;k
<=S
->Dimension
;++k
) {
70 value_print(stdout
,VALUE_FMT
,z
[k
]);
73 value_print(stdout
,VALUE_FMT
,c
);
76 /* Manually count the number of points */
77 count_points(1,S
,z
,&tmp
);
78 #ifdef PRINT_ALL_RESULTS
80 value_print(stdout
, P_VALUE_FMT
, tmp
);
87 fprintf(stderr
,"Error !\n");
88 fprintf(stderr
,"EP( ");
89 value_print(stderr
,VALUE_FMT
,z
[S
->Dimension
-nparam
+1]);
90 for(k
=S
->Dimension
-nparam
+2;k
<=S
->Dimension
;++k
) {
92 value_print(stderr
,VALUE_FMT
,z
[k
]);
94 fprintf(stderr
," ) should be ");
95 value_print(stderr
,VALUE_FMT
,tmp
);
96 fprintf(stderr
,", while EP eval gives ");
97 value_print(stderr
,VALUE_FMT
,c
);
98 fprintf(stderr
,".\n");
99 #ifndef DONT_BREAK_ON_ERROR
100 value_clear(c
); value_clear(tmp
);
104 #ifdef PRINT_ALL_RESULTS
110 for(value_assign(tmp
,Min
); value_le(tmp
,Max
);
111 value_increment(tmp
,tmp
)) {
112 #ifndef PRINT_ALL_RESULTS
113 k
= VALUE_TO_INT(tmp
);
114 if(!pos
&& !(k
%st
)) {
119 value_assign(z
[pos
+S
->Dimension
-nparam
+1],tmp
);
120 if(!check_series(S
,C
,gf
,nparam
,pos
+1,z
)) {
121 value_clear(c
); value_clear(tmp
);
131 int main(int argc
,char *argv
[]) {
134 Polyhedron
*C
, *P
, *S
;
146 /******* Read the input *********/
150 if(C1
->NbColumns
< 2) {
151 fprintf(stderr
,"Not enough parameters !\n");
155 P
= Constraints2Polyhedron(P1
,MAXRAYS
);
156 C
= Constraints2Polyhedron(C1
,MAXRAYS
);
157 params
= Read_ParamNames(stdin
, C
->Dimension
);
161 /******* Read the options: initialize Min and Max ********/
162 if(P
->Dimension
>= VBIGDIM
)
164 else if(P
->Dimension
>= BIGDIM
)
170 while ((c
= getopt_long(argc
, argv
, "m:M:r:sve", options
, &ind
)) != -1) {
195 fprintf(stderr
,"Nothing to do: Min > Max !\n");
204 /******* Compute true context *******/
205 CC
= align_context(C
,P
->Dimension
,MAXRAYS
);
206 PP
= DomainIntersection(P
,CC
,MAXRAYS
);
208 C1
= Matrix_Alloc(C
->Dimension
+1,P
->Dimension
+1);
210 for(i
=0;i
<C1
->NbRows
;i
++)
211 for(j
=0;j
<C1
->NbColumns
;j
++)
212 if(i
==j
-P
->Dimension
+C
->Dimension
)
213 value_set_si(C1
->p
[i
][j
],1);
215 value_set_si(C1
->p
[i
][j
],0);
216 CC
= Polyhedron_Image(PP
,C1
,MAXRAYS
);
222 /******* Compute EP *********/
224 en
= barvinok_enumerate(P
,C
,MAXRAYS
);
227 gf
= barvinok_series(P
, C
, MAXRAYS
);
229 gf
->print(C
->Dimension
, params
);
234 en
= partition2enumeration(EP
);
238 /******* Initializations for check *********/
239 p
= (Value
*)malloc(sizeof(Value
) * (P
->Dimension
+2));
240 for(i
=0;i
<=P
->Dimension
;i
++) {
242 value_set_si(p
[i
],0);
245 value_set_si(p
[i
],1);
247 /* S = scanning list of polyhedra */
248 S
= Polyhedron_Scan(P
,C
,MAXRAYS
);
250 #ifndef PRINT_ALL_RESULTS
251 if(C
->Dimension
> 0) {
252 value_substract(tmp
,Max
,Min
);
253 if (VALUE_TO_INT(tmp
) > 80)
254 st
= 1+(VALUE_TO_INT(tmp
))/80;
257 for(i
=VALUE_TO_INT(Min
);i
<=VALUE_TO_INT(Max
);i
+=st
)
264 /******* CHECK NOW *********/
266 if (!series
|| function
) {
267 if (!check_poly(S
,C
,en
,C
->Dimension
,0,p
))
270 if (!check_series(S
,C
,gf
,C
->Dimension
,0,p
))
276 fprintf(stderr
,"Check failed !\n");
278 #ifndef PRINT_ALL_RESULTS
285 for(i
=0;i
<=(P
->Dimension
+1);i
++)
288 Free_ParamNames(params
, C
->Dimension
);