summaryrefslogtreecommitdiff
path: root/tests/Grid/bhz03widening1.cc
blob: ac98a2630857da9b509d604f0985c4654ea83bb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* Test Pointset_Powerset<Grid>::BHZ03_widening_assign().
   Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
   Copyright (C) 2010-2011 BUGSENG srl (http://bugseng.com)

This file is part of the Parma Polyhedra Library (PPL).

The PPL is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version.

The PPL is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.

For the most up-to-date information see the Parma Polyhedra Library
site: http://www.cs.unipr.it/ppl/ . */

#include "ppl_test.hh"

using namespace Parma_Polyhedra_Library::IO_Operators;

typedef Pointset_Powerset<Grid> GSet;

namespace {

// Joins of grids in powersets shows that series is stabilizing.
bool
test01() {
  Variable A(0);
  Variable B(1);

  GSet grs1(2, EMPTY);
  Grid gr1(2);
  gr1.add_congruence(A %= 0);
  gr1.add_congruence(B %= 0);
  grs1.add_disjunct(gr1);

  print_congruences<Grid>(grs1, "*** grs1 ***");

  GSet grs2(2, EMPTY);
  Grid gr2(2);
  gr2.add_congruence(A %= 0);
  grs2.add_disjunct(gr2);

  print_congruences<Grid>(grs2, "*** grs2 ***");

  GSet known_grs = grs2;

  grs2.BHZ03_widening_assign<Grid_Certificate>
    (grs1, widen_fun_ref(&Grid::widening_assign));

  bool ok = (grs2 == known_grs);

  print_congruences<Grid>(grs1, "*** grs2.BHZ03_widening_assign<Grid_Certificate>(grs1, widen_fun_ref(&Grid::widening_assign) ***");

  return ok;
}

// Widening falls back to a singleton join of the grids in the larger
// grid set.
bool
test02() {
  Variable A(0);
  Variable B(1);

  GSet grs1(2, EMPTY);
  Grid gr1(2);
  gr1.add_congruence(A - B %= 0);
  Grid gr2(2);
  gr2.add_congruence((A %= 0) / 2);
  grs1.add_disjunct(gr1);
  grs1.add_disjunct(gr2);

  print_congruences<Grid>(grs1, "*** grs1 ***");

  GSet grs2(2, EMPTY);
  Grid gr3(2);
  gr3.add_congruence(A - B %= 0);
  Grid gr4(2);
  gr4.add_congruence((A %= 0) / 2);
  grs2.add_disjunct(gr3);
  grs2.add_disjunct(gr4);

  print_congruences<Grid>(grs2, "*** grs2 ***");

  Grid known_gr = gr3;
  known_gr.upper_bound_assign(gr4);

  grs2.BHZ03_widening_assign<Grid_Certificate>
    (grs1, widen_fun_ref(&Grid::widening_assign));

  GSet known_grs(2, EMPTY);
  known_grs.add_disjunct(known_gr);

  bool ok = (grs2 == known_grs);

  print_congruences<Grid>(grs1, "*** grs2.BHZ03_widening_assign<Grid_Certificate>(grs1, widen_fun_ref(&Grid::widening_assign) ***");

  return ok;
}

} // namespace

BEGIN_MAIN
  DO_TEST(test01);
  DO_TEST(test02);
END_MAIN