From 5bd2d5ec9a27a917c641a6641b9e7b3a04a8ffaa Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 11 Oct 2007 10:27:08 +0200 Subject: [PATCH] verify: add check_poly_print helper function --- barvinok_enumerate.cc | 43 +++++++++--------------------------------- summate.cc | 52 ++------------------------------------------------- verif_ehrhart.c | 42 ++++++++--------------------------------- verify.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ verify.h | 6 ++++++ 5 files changed, 76 insertions(+), 118 deletions(-) diff --git a/barvinok_enumerate.cc b/barvinok_enumerate.cc index 66eeba9..f7627b7 100644 --- a/barvinok_enumerate.cc +++ b/barvinok_enumerate.cc @@ -180,13 +180,15 @@ static int check_series(Polyhedron *S, Polyhedron *CS, skewed_gen_fun *gf, int nparam, int pos, Value *z, verify_options *options) { int k; - Value c, tmp; + Value c, tmp, one; Value LB, UB; value_init(c); value_init(tmp); value_init(LB); value_init(UB); + value_init(one); + value_set_si(one, 1); if (pos == nparam) { /* Computes the coefficient */ @@ -195,47 +197,19 @@ static int check_series(Polyhedron *S, Polyhedron *CS, skewed_gen_fun *gf, /* if c=0 we may be out of context. */ /* scanning is useless in this case*/ - if (options->print_all) { - printf("EP( "); - value_print(stdout,VALUE_FMT,z[S->Dimension-nparam+1]); - for(k=S->Dimension-nparam+2;k<=S->Dimension;++k) { - printf(", "); - value_print(stdout,VALUE_FMT,z[k]); - } - printf(" ) = "); - value_print(stdout,VALUE_FMT,c); - printf(" "); - } - /* Manually count the number of points */ count_points(1,S,z,&tmp); - if (options->print_all) { - printf(", count = "); - value_print(stdout, P_VALUE_FMT, tmp); - printf(". "); - } + + check_poly_print(value_eq(tmp, c), nparam, z+1+S->Dimension-nparam, + tmp, one, c, one, + "EP", "count", "EP eval", options); if (value_ne(tmp,c)) { - printf("\n"); - fflush(stdout); - fprintf(stderr,"Error !\n"); - fprintf(stderr,"EP( "); - value_print(stderr,VALUE_FMT,z[S->Dimension-nparam+1]); - for (k=S->Dimension-nparam+2;k<=S->Dimension;++k) { - fprintf(stderr,", "); - value_print(stderr,VALUE_FMT,z[k]); - } - fprintf(stderr," ) should be "); - value_print(stderr,VALUE_FMT,tmp); - fprintf(stderr,", while EP eval gives "); - value_print(stderr,VALUE_FMT,c); - fprintf(stderr,".\n"); if (!options->continue_on_error) { value_clear(c); value_clear(tmp); return 0; } - } else if (options->print_all) - printf("OK.\n"); + } } else { int ok = !(lower_upper_bounds(1+pos, CS, &z[S->Dimension-nparam], &LB, &UB)); @@ -261,6 +235,7 @@ static int check_series(Polyhedron *S, Polyhedron *CS, skewed_gen_fun *gf, value_clear(c); value_clear(tmp); + value_clear(one); value_clear(LB); value_clear(UB); return 1; diff --git a/summate.cc b/summate.cc index 48f13d2..9d1fdb2 100644 --- a/summate.cc +++ b/summate.cc @@ -116,60 +116,12 @@ static int check_poly_sum(const struct check_poly_data *data, int ok; e = evalue_eval(sum_data->sum, z); - if (options->print_all) { - printf("sum("); - value_print(stdout, VALUE_FMT, z[0]); - for (k = 1; k < nparam; ++k) { - printf(", "); - value_print(stdout, VALUE_FMT, z[k]); - } - printf(") = "); - value_print(stdout, VALUE_FMT, e->x.n); - if (value_notone_p(e->d)) { - printf("/"); - value_print(stdout, VALUE_FMT, e->d); - } - } - s = sum(sum_data, options); - if (options->print_all) { - printf(", sum(EP) = "); - value_print(stdout, VALUE_FMT, s->x.n); - if (value_notone_p(s->d)) { - printf("/"); - value_print(stdout, VALUE_FMT, s->d); - } - printf(". "); - } - ok = eequal(e, s); - if (!ok) { - printf("\n"); - fflush(stdout); - fprintf(stderr,"Error !\n"); - fprintf(stderr,"sum( "); - value_print(stderr, VALUE_FMT, z[0]); - for (k = 1; k < nparam; ++k) { - fprintf(stderr, ", "); - value_print(stderr, VALUE_FMT, z[k]); - } - fprintf(stderr," ) should be "); - value_print(stderr, VALUE_FMT, s->x.n); - if (value_notone_p(s->d)) { - fprintf(stderr, "/"); - value_print(stderr, VALUE_FMT, s->d); - } - fprintf(stderr,", while summation gives "); - value_print(stderr, VALUE_FMT, e->x.n); - if (value_notone_p(e->d)) { - fprintf(stderr, "/"); - value_print(stderr, VALUE_FMT, e->d); - } - fprintf(stderr, ".\n"); - } else if (options->print_all) - printf("OK.\n"); + check_poly_print(ok, nparam, z, s->x.n, s->d, e->x.n, e->d, + "sum", "sum(EP)", "summation", options); evalue_free(s); evalue_free(e); diff --git a/verif_ehrhart.c b/verif_ehrhart.c index 1f59f8f..b925297 100644 --- a/verif_ehrhart.c +++ b/verif_ehrhart.c @@ -35,7 +35,7 @@ static int cp_EP(const struct check_poly_data *data, int nparam, Value *z, { int k; int ok; - Value c, tmp; + Value c, tmp, one; int pa = options->barvinok->polynomial_approximation; struct check_poly_EP_data* EP_data = (struct check_poly_EP_data*) data; const evalue *EP = EP_data->EP; @@ -44,6 +44,8 @@ static int cp_EP(const struct check_poly_data *data, int nparam, Value *z, value_init(c); value_init(tmp); + value_init(one); + value_set_si(one, 1); /* Computes the ehrhart polynomial */ if (!options->exact) { @@ -64,29 +66,12 @@ static int cp_EP(const struct check_poly_data *data, int nparam, Value *z, evalue_free(res); } - if (options->print_all) { - printf("EP("); - value_print(stdout, VALUE_FMT, z[0]); - for (k = 1; k < nparam; ++k) { - printf(", "); - value_print(stdout, VALUE_FMT, z[k]); - } - printf(") = "); - value_print(stdout, VALUE_FMT, c); - } - /* Manually count the number of points */ if (exist) count_points_e(1, S, exist, nparam, data->z, &tmp); else count_points(1, S, data->z, &tmp); - if (options->print_all) { - printf(", count = "); - value_print(stdout, VALUE_FMT, tmp); - printf(". "); - } - if (pa == BV_APPROX_SIGN_APPROX) /* just accept everything */ ok = 1; @@ -97,21 +82,10 @@ static int cp_EP(const struct check_poly_data *data, int nparam, Value *z, else ok = value_eq(c, tmp); + check_poly_print(ok, nparam, z, tmp, one, c, one, + "EP", "count", "EP eval", options); + if (!ok) { - printf("\n"); - fflush(stdout); - fprintf(stderr, "Error !\n"); - fprintf(stderr, "EP("); - value_print(stderr, VALUE_FMT, z[0]); - for (k = 1; k < nparam; ++k) { - fprintf(stderr,", "); - value_print(stderr, VALUE_FMT, z[k]); - } - fprintf(stderr, ") should be "); - value_print(stderr, VALUE_FMT, tmp); - fprintf(stderr, ", while EP eval gives "); - value_print(stderr, VALUE_FMT, c); - fprintf(stderr, ".\n"); print_evalue(stderr, EP, options->params); if (value_zero_p(EP->d) && EP->x.p->type == partition) for (k = 0; k < EP->x.p->size/2; ++k) { @@ -121,11 +95,11 @@ static int cp_EP(const struct check_poly_data *data, int nparam, Value *z, print_evalue(stderr, &EP->x.p->arr[2*k+1], options->params); } } - } else if (options->print_all) - printf("OK.\n"); + } value_clear(c); value_clear(tmp); + value_clear(one); return ok; } diff --git a/verify.c b/verify.c index 0602c44..5c7a1ec 100644 --- a/verify.c +++ b/verify.c @@ -166,6 +166,57 @@ void check_poly_init(Polyhedron *C, struct verify_options *options) fflush(stdout); } +static void print_rational(FILE *out, Value n, Value d) +{ + value_print(out, VALUE_FMT, n); + if (value_notone_p(d)) { + fprintf(out, "/"); + value_print(out, VALUE_FMT, d); + } +} + +void check_poly_print(int ok, int nparam, Value *z, + Value want_n, Value want_d, + Value got_n, Value got_d, + const char *op, const char *check, + const char *long_op, + const struct verify_options *options) +{ + int k; + + if (options->print_all) { + printf("%s(", op); + value_print(stdout, VALUE_FMT, z[0]); + for (k = 1; k < nparam; ++k) { + printf(", "); + value_print(stdout, VALUE_FMT, z[k]); + } + printf(") = "); + print_rational(stdout, got_n, got_d); + printf(", %s = ", check); + print_rational(stdout, want_n, want_d); + printf(". "); + } + + if (!ok) { + printf("\n"); + fflush(stdout); + fprintf(stderr, "Error !\n"); + fprintf(stderr, "%s(", op); + value_print(stderr, VALUE_FMT, z[0]); + for (k = 1; k < nparam; ++k) { + fprintf(stderr,", "); + value_print(stderr, VALUE_FMT, z[k]); + } + fprintf(stderr, ") should be "); + print_rational(stderr, want_n, want_d); + fprintf(stderr, ", while %s gives ", long_op); + print_rational(stderr, got_n, got_d); + fprintf(stderr, ".\n"); + } else if (options->print_all) + printf("OK.\n"); +} + /****************************************************/ /* function check_poly : */ /* scans the parameter space from Min to Max (all */ diff --git a/verify.h b/verify.h index b130df0..21bcb2c 100644 --- a/verify.h +++ b/verify.h @@ -29,6 +29,12 @@ Polyhedron *check_poly_context_scan(Polyhedron *P, Polyhedron **C, unsigned nparam, const struct verify_options *options); void check_poly_init(Polyhedron *C, struct verify_options *options); +void check_poly_print(int ok, int nparam, Value *z, + Value want_n, Value want_d, + Value got_n, Value got_d, + const char *op, const char *check, + const char *long_op, + const struct verify_options *options); struct check_poly_data; typedef int (*check_poly_fun)(const struct check_poly_data *data, -- 2.11.4.GIT