3 #include <barvinok/barvinok.h>
4 #include <barvinok/options.h>
5 #include <barvinok/util.h>
6 #include "barvinok_summate_options.h"
7 #include "evalue_convert.h"
8 #include "evalue_read.h"
15 #define ALLOCN(type,n) (type*)malloc((n) * sizeof(type))
17 static int check_poly_sum(const struct check_poly_data
*data
,
19 const struct verify_options
*options
);
21 struct check_poly_sum_data
: public check_EP_data
{
24 check_poly_sum_data(const evalue
*EP
, evalue
*sum
) : sum(sum
) {
26 this->cp
.check
= check_poly_sum
;
30 static void sum(Polyhedron
*S
, int pos
, const check_poly_sum_data
*data
,
31 evalue
*s
, const struct verify_options
*options
)
34 evalue
*e
= evalue_eval(data
->EP
, data
->cp
.z
+1);
42 ok
= !(lower_upper_bounds(1+pos
, S
, data
->cp
.z
, &LB
, &UB
));
44 for (; value_le(LB
, UB
); value_increment(LB
, LB
)) {
45 value_assign(data
->cp
.z
[1+pos
], LB
);
46 sum(S
->next
, pos
+1, data
, s
, options
);
48 value_set_si(data
->cp
.z
[1+pos
], 0);
54 static evalue
*sum(const check_poly_sum_data
*data
,
55 const struct verify_options
*options
)
57 evalue
*s
= evalue_zero();
58 for (int i
= 0; i
< data
->n_S
; ++i
)
59 if (!emptyQ2(data
->S
[i
]))
60 sum(data
->S
[i
], 0, data
, s
, options
);
64 static int check_poly_sum(const struct check_poly_data
*data
,
66 const struct verify_options
*options
)
68 const check_poly_sum_data
*sum_data
;
69 sum_data
= (const check_poly_sum_data
*)data
;
74 e
= evalue_eval(sum_data
->sum
, z
);
75 s
= sum(sum_data
, options
);
79 check_poly_print(ok
, nparam
, z
, s
->x
.n
, s
->d
, e
->x
.n
, e
->d
,
80 "sum", "sum(EP)", "summation", options
);
88 static int verify(evalue
*EP
, evalue
*sum
, unsigned nvar
, unsigned nparam
,
89 struct verify_options
*options
)
91 check_poly_sum_data
data(EP
, sum
);
92 return !check_EP(&data
, nvar
, nparam
, options
);
95 int main(int argc
, char **argv
)
98 const char **all_vars
= NULL
;
102 struct options
*options
= options_new_with_defaults();
104 argc
= options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
106 EP
= evalue_read_from_file(stdin
, options
->var_list
, &all_vars
,
107 &nvar
, &nparam
, options
->verify
->barvinok
->MaxRays
);
110 if (options
->verify
->verify
)
111 verify_options_set_range(options
->verify
, nvar
+nparam
);
113 evalue_convert(EP
, options
->convert
, options
->verify
->barvinok
->verbose
,
116 if (EVALUE_IS_ZERO(*EP
))
117 print_evalue(stdout
, EP
, all_vars
);
119 evalue
*sum
= barvinok_summate(EP
, nvar
, options
->verify
->barvinok
);
121 if (options
->verify
->verify
)
122 result
= verify(EP
, sum
, nvar
, nparam
, options
->verify
);
124 print_evalue(stdout
, sum
, all_vars
+nvar
);
130 Free_ParamNames(all_vars
, nvar
+nparam
);
131 options_free(options
);