mCRL2
Loading...
Searching...
No Matches
normalize.h
Go to the documentation of this file.
1// Author(s): Wieger Wesselink
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
11
12#ifndef MCRL2_PBES_NORMALIZE_H
13#define MCRL2_PBES_NORMALIZE_H
14
16#include "mcrl2/pbes/builder.h"
18
19namespace mcrl2
20{
21
22namespace pbes_system
23{
24
26// \brief Visitor for checking if a pbes expression is normalized.
27struct is_normalized_traverser: public pbes_expression_traverser<is_normalized_traverser>
28{
29 typedef pbes_expression_traverser<is_normalized_traverser> super;
30 using super::enter;
31 using super::leave;
32 using super::apply;
33
34 bool result;
35
36 is_normalized_traverser()
37 : result(true)
38 {}
39
41 void enter(const not_& /* x */)
42 {
43 result = false;
44 }
45
47 void enter(const imp& /* x */)
48 {
49 result = false;
50 }
51};
53
55// \brief Visitor for checking if a pbes expression is normalized.
56struct normalize_builder: public pbes_expression_builder<normalize_builder>
57{
58 typedef pbes_expression_builder<normalize_builder> super;
59 using super::apply;
60
61 bool negated;
62
63 normalize_builder()
64 : negated(false)
65 {}
66
67 template <class T>
68 void apply(T& result, const data::data_expression& x)
69 {
70 result = negated ? data::not_(x) : x;
71 }
72
73 template <class T>
74 void apply(T& result, const not_& x)
75 {
76 negated = !negated;
77 super::apply(result, x.operand());
78 negated = !negated;
79 }
80
81 template <class T>
82 void apply(T& result, const and_& x)
83 {
84 pbes_expression left;
85 super::apply(left, x.left());
86 pbes_expression right;
87 super::apply(right, x.right());
88 if (negated)
89 {
90 make_or_(result, left, right);
91 }
92 else
93 {
94 make_and_(result, left, right);
95 }
96 }
97
98 template <class T>
99 void apply(T& result, const or_& x)
100 {
101 pbes_expression left;
102 super::apply(left, x.left());
103 pbes_expression right;
104 super::apply(right, x.right());
105 if (negated)
106 {
107 make_and_(result, left, right);
108 }
109 else
110 {
111 make_or_(result, left, right);
112 }
113 }
114
115 template <class T>
116 void apply(T& result, const imp& x)
117 {
118 negated = !negated;
119 pbes_expression left;
120 super::apply(left, x.left());
121 negated = !negated;
122 pbes_expression right;
123 super::apply(right, x.right());
124 if (negated)
125 {
126 make_and_(result, left, right);
127 }
128 else
129 {
130 make_or_(result, left, right);
131 }
132 }
133
134 template <class T>
135 void apply(T& result, const forall& x)
136 {
137 pbes_expression body;
138 super::apply(body, x.body());
139 result = negated ? make_exists_(x.variables(), body) : make_forall_(x.variables(), body);
140 }
141
142 template <class T>
143 void apply(T& result, const exists& x)
144 {
145 pbes_expression body;
146 super::apply(body, x.body());
147 result = negated ? make_forall_(x.variables(), body) : make_exists_(x.variables(), body);
148 }
149
150 template <class T>
151 void apply(T& result, const propositional_variable_instantiation& x)
152 {
153 if (negated)
154 {
155 throw mcrl2::runtime_error(std::string("normalize error: illegal argument ") + pp(x));
156 }
157 result = x;
158 }
159};
161
165template <typename T>
166bool is_normalized(const T& x)
167{
168 is_normalized_traverser f;
169 f.apply(x);
170 return f.result;
171}
172
176template <typename T>
177void normalize(T& x,
178 typename std::enable_if< !std::is_base_of< atermpp::aterm, T >::value>::type* = nullptr
179 )
180{
181 normalize_builder f;
182 f.update(x);
183}
184
188template <typename T>
189T normalize(const T& x,
190 typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value>::type* = nullptr
191 )
192{
193 T result;
194 normalize_builder f;
195 f.apply(result, x);
196 return result;
197}
198
199} // namespace pbes_system
200
201} // namespace mcrl2
202
203#endif // MCRL2_PBES_NORMALIZE_H
Standard exception class for reporting runtime errors.
Definition exception.h:27
This file contains some functions that are present in all libraries except the data library....
std::string pp(const atermpp::aterm &t)
Transform an aterm to an ascii string.
Definition aterm.h:440
const data_expression & right(const data_expression &e)
Function for projecting out argument. right from an application.
Definition bag1.h:1636
const data_expression & left(const data_expression &e)
Function for projecting out argument. left from an application.
Definition bag1.h:1624
void make_and_(data_expression &result, const data_expression &arg0, const data_expression &arg1)
Make an application of function symbol &&.
Definition bool.h:271
void make_or_(data_expression &result, const data_expression &arg0, const data_expression &arg1)
Make an application of function symbol ||.
Definition bool.h:335
data_expression make_exists_(const data::variable_list &v, const data_expression &x)
Make an existential quantification. It checks for an empty variable list, which is not allowed.
data_expression make_forall_(const data::variable_list &v, const data_expression &x)
Make a universal quantification. It checks for an empty variable list, which is not allowed.
void normalize(T &x, typename std::enable_if< !std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
The function normalize brings (embedded) pbes expressions into positive normal form,...
Definition normalize.h:177
bool is_normalized(const T &x)
Checks if a pbes expression is normalized.
Definition normalize.h:166
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
add your file description here.
add your file description here.