mCRL2
Loading...
Searching...
No Matches
maximal_closed_subformula.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//
9/// \file mcrl2/modal_formula/maximal_closed_subformula.h
10/// \brief add your file description here.
11
12#ifndef MCRL2_MODAL_FORMULA_MAXIMAL_CLOSED_SUBFORMULA_H
13#define MCRL2_MODAL_FORMULA_MAXIMAL_CLOSED_SUBFORMULA_H
14
15#include "mcrl2/modal_formula/traverser.h"
16
17namespace mcrl2::state_formulas
18{
19
20namespace detail {
21
22inline
24{
25 if (data::is_data_expression(x)) { return 0; }
26 else if (state_formulas::is_true(x)) { return 0; }
27 else if (state_formulas::is_false(x)) { return 0; }
28 else if (state_formulas::is_not(x)) { return 1; }
29 else if (state_formulas::is_and(x)) { return 2; }
30 else if (state_formulas::is_or(x)) { return 2; }
31 else if (state_formulas::is_imp(x)) { return 2; }
32 else if (state_formulas::is_forall(x)) { return 1; }
33 else if (state_formulas::is_exists(x)) { return 1; }
34 else if (state_formulas::is_must(x)) { return 1; }
35 else if (state_formulas::is_may(x)) { return 1; }
36 else if (state_formulas::is_yaled(x)) { return 0; }
37 else if (state_formulas::is_yaled_timed(x)) { return 0; }
38 else if (state_formulas::is_delay(x)) { return 0; }
39 else if (state_formulas::is_delay_timed(x)) { return 0; }
40 else if (state_formulas::is_variable(x)) { return 0; }
41 else if (state_formulas::is_nu(x)) { return 1; }
42 else if (state_formulas::is_mu(x)) { return 1; }
43 throw mcrl2::runtime_error("child_count: unknown argument");
44 return 0;
45}
46
47template <template <class> class Traverser, class Node, class Derived>
48struct bottom_up_traverser: public Traverser<Derived>
49{
50 using super = Traverser<Derived>;
51 using super::enter;
52 using super::apply;
53
54 Derived& derived()
55 {
56 return static_cast<Derived&>(*this);
57 }
58
59 // Maintain a stack with nodes, used to store intermediate results
62
63 // Push a node to node_stack
64 void push(const Node& node)
65 {
66 node_stack.push_back(node);
67 mCRL2log(log::debug) << "<push>" << node << std::endl;
68 }
69
70 // Pop the top element of node_stack and return it
71 Node pop()
72 {
73 Node result = node_stack.back();
74 node_stack.pop_back();
75 return result;
76 }
77
78 // Return the top element of node_stack
79 Node& top()
80 {
81 return node_stack.back();
82 }
83
84 // Return the top element of node_stack
85 const Node& top() const
86 {
87 return node_stack.back();
88 }
89
90 template <typename T>
91 void join(const T& /* x */, node_iterator /* first */, node_iterator /* last */, Node& /* result */)
92 {
93 }
94
95 // Override the leave function, such that it combines the results of child nodes
96 template <typename T>
97 void leave(const T& x)
98 {
99 Node result;
100 std::size_t n = child_count(atermpp::down_cast<state_formula>(x));
101 derived().join(x, node_stack.end() - n, node_stack.end(), result);
102 node_stack.erase(node_stack.end() - n, node_stack.end());
103 push(result);
104 }
105
106 // This leave function needs to be disabled.
107 // TODO: It seems more logical that the call to this leave function is not generated in
108 // the traverser, to avoid that the same term is visited twice.
110 {
111 }
112};
113
115{
117
118 free_variables_node(const std::set<data::variable>& variables_ = std::set<data::variable>())
120 { }
121};
122
124{
126
127 maximal_closed_subformula_node(const std::set<data::variable>& variables = std::set<data::variable>(),
128 const std::set<state_formulas::state_formula>& formulas_ = std::set<state_formulas::state_formula>()
129 )
132 { }
133};
134
136{
137 out << "<node>variables = ";
138 for (const data::variable& v: node.variables)
139 {
140 out << v << " ";
141 }
142 out << " formulas = ";
143 for (const state_formula& f: node.formulas)
144 {
145 out << f << " ";
146 }
147 return out;
148}
149
150template <typename Derived>
152{
154 using super::enter;
155 using super::leave;
156 using super::apply;
157 using super::push;
158 using super::pop;
159 using super::top;
160 using super::node_stack;
161
163
164 Derived& derived()
165 {
166 return static_cast<Derived&>(*this);
167 }
168
169 template <typename T>
170 void update_free_variables(const T& /* x */, maximal_closed_subformula_node& /* result */)
171 { }
172
174 {
175 data::find_free_variables(x, std::inserter(result.variables, result.variables.end()));
176 }
177
179 {
180 for (const data::variable& v: x.variables())
181 {
182 result.variables.erase(v);
183 }
184 }
185
187 {
188 for (const data::variable& v: x.variables())
189 {
190 result.variables.erase(v);
191 }
192 }
193
195 {
196 for (const data::data_expression& e: x.arguments())
197 {
198 data::find_free_variables(e, std::inserter(result.variables, result.variables.end()));
199 }
200 }
201
202 template <typename T>
204 {
205 if (result.variables.empty())
206 {
207 result.formulas.clear();
208 result.formulas.insert(x);
209 }
210 }
211
212 template <typename T>
213 void join(const T& x, node_iterator first, node_iterator last, maximal_closed_subformula_node& result)
214 {
215 for (node_iterator i = first; i != last; ++i)
216 {
217 result.variables.insert(i->variables.begin(), i->variables.end());
218 }
219 update_free_variables(x, result);
220 if (result.variables.empty())
221 {
222 result.formulas.insert(atermpp::down_cast<state_formula>(x));
223 }
224 else
225 {
226 for (node_iterator i = first; i != last; ++i)
227 {
228 result.formulas.insert(i->formulas.begin(), i->formulas.end());
229 }
230 }
231 }
232};
233
235{
237 using super::enter;
238 using super::leave;
239 using super::apply;
240 using super::top;
241};
242
243}; // namespace detail
244
245inline
247{
249 f.apply(x);
250 return f.top().formulas;
251}
252
253} // namespace mcrl2::state_formulas
254
255#endif // MCRL2_MODAL_FORMULA_MAXIMAL_CLOSED_SUBFORMULA_H
\brief The existential quantification operator for state formulas
\brief The universal quantification operator for state formulas
\brief The state formula variable
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:392
bool is_data_expression(const atermpp::aterm &x)
Test for a data_expression expression.
std::ostream & operator<<(std::ostream &out, const maximal_closed_subformula_node &node)
std::size_t child_count(const state_formula &x)
bool is_and(const atermpp::aterm &x)
bool is_delay_timed(const atermpp::aterm &x)
bool is_exists(const atermpp::aterm &x)
bool is_not(const atermpp::aterm &x)
bool is_must(const atermpp::aterm &x)
std::set< state_formulas::state_formula > maximal_closed_subformulas(const state_formula &x)
bool is_yaled(const atermpp::aterm &x)
bool is_true(const atermpp::aterm &x)
bool is_variable(const atermpp::aterm &x)
bool is_may(const atermpp::aterm &x)
bool is_yaled_timed(const atermpp::aterm &x)
bool is_imp(const atermpp::aterm &x)
bool is_nu(const atermpp::aterm &x)
bool is_delay(const atermpp::aterm &x)
bool is_false(const atermpp::aterm &x)
bool is_mu(const atermpp::aterm &x)
bool is_forall(const atermpp::aterm &x)
bool is_or(const atermpp::aterm &x)
void leave(const state_formulas::state_formula &)
void join(const T &, node_iterator, node_iterator, Node &)
free_variables_node(const std::set< data::variable > &variables_=std::set< data::variable >())
maximal_closed_subformula_node(const std::set< data::variable > &variables=std::set< data::variable >(), const std::set< state_formulas::state_formula > &formulas_=std::set< state_formulas::state_formula >())
void update_free_variables(const data::data_expression &x, maximal_closed_subformula_node &result)
void join(const T &x, node_iterator first, node_iterator last, maximal_closed_subformula_node &result)
void update_free_variables(const T &, maximal_closed_subformula_node &)
void update_free_variables(const state_formulas::exists &x, maximal_closed_subformula_node &result)
void update_maximal_closed_formulas(const T &x, maximal_closed_subformula_node &result)
void update_free_variables(const state_formulas::variable &x, maximal_closed_subformula_node &result)
void update_free_variables(const state_formulas::forall &x, maximal_closed_subformula_node &result)