From 510db58fc164e0dec6946e5d968f97eacd7e335f Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 16 Oct 2007 16:24:40 +0200 Subject: [PATCH] gen_fun::add: context of sum should be union of contexts of the terms --- 4coins.cc | 4 ++-- barvinok/genfun.h | 4 +++- genfun.cc | 11 +++++++++++ scarf.cc | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/4coins.cc b/4coins.cc index ea233a7..88d00a9 100644 --- a/4coins.cc +++ b/4coins.cc @@ -59,7 +59,7 @@ bool is_indicator(gen_fun *gf, barvinok_options *options) QQ mone(-1, 1); test = gf->Hadamard_product(gf, options); - test->add(mone, gf); + test->add(mone, gf, options); test->print(std::cerr, 0, NULL); cerr << endl; @@ -138,7 +138,7 @@ int main(int argc, char **argv) do { S_shift->shift(up); hp = S->Hadamard_product(S_shift, options); - S->add(mone, hp); + S->add(mone, hp, options); delete hp; S_divide->shift(up); diff --git a/barvinok/genfun.h b/barvinok/genfun.h index de1e505..a64d0ba 100644 --- a/barvinok/genfun.h +++ b/barvinok/genfun.h @@ -47,7 +47,7 @@ struct gen_fun { void add(const QQ& c, const vec_ZZ& num, const mat_ZZ& den); void add(short_rat *r); /* add c times gf */ - void add(const QQ& c, const gen_fun *gf); + void add(const QQ& c, const gen_fun *gf, barvinok_options *options); void substitute(Matrix *CP); gen_fun *Hadamard_product(const gen_fun *gf, barvinok_options *options); void add_union(gen_fun *gf, barvinok_options *options); @@ -77,6 +77,8 @@ struct gen_fun { Polyhedron_Free(context); clear_terms(); } +private: + void add(const QQ& c, const gen_fun *gf); }; std::ostream & operator<< (std::ostream & os, const gen_fun& gf); diff --git a/genfun.cc b/genfun.cc index 2707fb9..0094b06 100644 --- a/genfun.cc +++ b/genfun.cc @@ -248,6 +248,17 @@ void gen_fun::add(short_rat *r) term.insert(r); } +void gen_fun::add(const QQ& c, const gen_fun *gf, barvinok_options *options) +{ + Polyhedron *U = DomainUnion(context, gf->context, options->MaxRays); + Polyhedron *C = DomainConvex(U, options->MaxRays); + Domain_Free(U); + Domain_Free(context); + context = C; + + add(c, gf); +} + void gen_fun::add(const QQ& c, const gen_fun *gf) { QQ p; diff --git a/scarf.cc b/scarf.cc index bf5730c..fd1fbef 100644 --- a/scarf.cc +++ b/scarf.cc @@ -939,7 +939,7 @@ void scarf_collector_gf::add(Polyhedron *P, int sign, Polyhedron *C, gen_fun *gf2; c.n = sign; gf2 = barvinok_series_with_options(P, C, options); - gf->add(c, gf2); + gf->add(c, gf2, options); delete gf2; } } -- 2.11.4.GIT