From df3bff8d4d480b6431da2fb479dcf905b0b1b65b Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 8 Mar 2008 20:28:57 +0100 Subject: [PATCH] introduce evalue_shift_variables --- barvinok/evalue.h | 1 + bernoulli.c | 32 ++------------------------------ evalue.c | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/barvinok/evalue.h b/barvinok/evalue.h index 069f672..ac385e4 100644 --- a/barvinok/evalue.h +++ b/barvinok/evalue.h @@ -129,6 +129,7 @@ evalue *affine2evalue(Value *coeff, Value denom, int nvar); void evalue_substitute(evalue *e, evalue **subs); void evalue_backsubstitute(evalue *e, Matrix *CP, unsigned MaxRays); evalue *evalue_polynomial(Vector *c, const evalue* X); +void evalue_shift_variables(evalue *e, int n); struct evalue_section { Polyhedron *D; diff --git a/bernoulli.c b/bernoulli.c index 494e968..c40c5a2 100644 --- a/bernoulli.c +++ b/bernoulli.c @@ -151,40 +151,12 @@ struct poly_list *faulhaber_compute(int n) return bernoulli_faulhaber_compute(n, &faulhaber, 1); } -/* shift variables in polynomial one down */ -static void shift(evalue *e) -{ - int i; - if (value_notzero_p(e->d)) - return; - assert(e->x.p->type == polynomial || e->x.p->type == fractional); - if (e->x.p->type == polynomial) { - assert(e->x.p->pos > 1); - e->x.p->pos--; - } - for (i = 0; i < e->x.p->size; ++i) - shift(&e->x.p->arr[i]); -} - -/* shift variables in polynomial n up */ -static void unshift(evalue *e, unsigned n) -{ - int i; - if (value_notzero_p(e->d)) - return; - assert(e->x.p->type == polynomial || e->x.p->type == fractional); - if (e->x.p->type == polynomial) - e->x.p->pos += n; - for (i = 0; i < e->x.p->size; ++i) - unshift(&e->x.p->arr[i], n); -} - static evalue *shifted_copy(const evalue *src) { evalue *e = ALLOC(evalue); value_init(e->d); evalue_copy(e, src); - shift(e); + evalue_shift_variables(e, -1); return e; } @@ -903,7 +875,7 @@ static evalue *sum_over_polytope_with_equalities(Polyhedron *P, evalue *E, new_nparam); else subs[nvar+j] = evalue_var(j); - unshift(subs[nvar+j], new_dim-new_nparam); + evalue_shift_variables(subs[nvar+j], new_dim-new_nparam); } E = evalue_dup(E); diff --git a/evalue.c b/evalue.c index 4ee1f1d..7754fff 100644 --- a/evalue.c +++ b/evalue.c @@ -4360,3 +4360,18 @@ evalue *evalue_from_section_array(struct evalue_section *s, int n) } return res; } + +/* shift variables in polynomial n up */ +void evalue_shift_variables(evalue *e, int n) +{ + int i; + if (value_notzero_p(e->d)) + return; + assert(e->x.p->type == polynomial || e->x.p->type == fractional); + if (e->x.p->type == polynomial) { + assert(e->x.p->pos + n >= 1); + e->x.p->pos += n; + } + for (i = 0; i < e->x.p->size; ++i) + evalue_shift_variables(&e->x.p->arr[i], n); +} -- 2.11.4.GIT