mCRL2
Loading...
Searching...
No Matches
replace_capture_avoiding_with_an_identifier_generator.h
Go to the documentation of this file.
1// Author(s): Jan Friso Groote
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/replace_capture_avoiding_with_an_identifier_generator.h
10/// \brief add your file description here.
11
12#ifndef MCRL2_MODAL_FORMULA_REPLACE_CAPTURE_AVOIDING_WITH_AN_IDENTIFIER_GENERATOR_H
13#define MCRL2_MODAL_FORMULA_REPLACE_CAPTURE_AVOIDING_WITH_AN_IDENTIFIER_GENERATOR_H
14
15#include "mcrl2/lps/replace_capture_avoiding_with_an_identifier_generator.h"
16#include "mcrl2/modal_formula/add_binding.h"
17#include "mcrl2/modal_formula/builder.h"
18
19namespace mcrl2 {
20
21namespace action_formulas {
22
23namespace detail {
24
25// Below the functions to do a capture avoiding replacement with an identifier generator are given.
26template <template <class> class Builder, class Derived, class Substitution, class IdentifierGenerator>
28{
30 using super::enter;
31 using super::leave;
32 using super::update;
33 using super::apply;
34 using super::update_sigma;
35
36 template <class T>
37 void apply(T& result, const forall& x)
38 {
39 data::variable_list v = update_sigma.push(x.variables());
40 action_formula body;
41 apply(body, x.body());
42 make_forall(result, v, body);
43 update_sigma.pop(v);
44 }
45
46 template <class T>
47 void apply(T& result, const exists& x)
48 {
49 data::variable_list v = update_sigma.push(x.variables());
50 action_formula body;
51 apply(body, x.body());
52 make_exists(result, v, body);
53 update_sigma.pop(v);
54 }
55
56 add_capture_avoiding_replacement_with_an_identifier_generator(Substitution& sigma, IdentifierGenerator& id_generator)
58 { }
59};
60
61} // namespace detail
62
63//--- start generated action_formulas replace_capture_avoiding_with_identifier_generator code ---//
64/// \\brief Applies sigma as a capture avoiding substitution to x using an identifier generator.
65/// \\details This substitution function is much faster than replace_variables_capture_avoiding, but
66/// it requires an identifier generator that generates strings for fresh variables. These
67/// strings must be unique in the sense that they have not been used for other variables.
68/// \\param x The object to which the subsitution is applied.
69/// \\param sigma A mutable substitution of which it can efficiently be checked whether a variable occurs in its
70/// right hand side. The class maintain_variables_in_rhs is useful for this purpose.
71/// \\param id_generator A generator that generates unique strings, not yet used as variable names.
72
73template <typename T, typename Substitution, typename IdentifierGenerator>
75 Substitution& sigma,
76 IdentifierGenerator& id_generator,
77 typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
78 )
79{
80 data::detail::apply_replace_capture_avoiding_variables_builder_with_an_identifier_generator<action_formulas::data_expression_builder, action_formulas::detail::add_capture_avoiding_replacement_with_an_identifier_generator>(sigma, id_generator).update(x);
81}
82
83/// \\brief Applies sigma as a capture avoiding substitution to x using an identifier generator..
84/// \\details This substitution function is much faster than replace_variables_capture_avoiding, but
85/// it requires an identifier generator that generates strings for fresh variables. These
86/// strings must be unique in the sense that they have not been used for other variables.
87/// \\param x The object to which the substiution is applied.
88/// \\param sigma A mutable substitution of which it can efficiently be checked whether a variable occurs in its
89/// right hand side. The class maintain_variables_in_rhs is useful for this purpose.
90/// \\param id_generator A generator that generates unique strings, not yet used as variable names.
91/// \\return The result is the term x to which sigma has been applied.
92template <typename T, typename Substitution, typename IdentifierGenerator>
94 Substitution& sigma,
95 IdentifierGenerator& id_generator,
96 typename std::enable_if<std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
97 )
98{
99 T result;
100 data::detail::apply_replace_capture_avoiding_variables_builder_with_an_identifier_generator<action_formulas::data_expression_builder, action_formulas::detail::add_capture_avoiding_replacement_with_an_identifier_generator>(sigma, id_generator).apply(result, x);
101 return result;
102}
103//--- end generated action_formulas replace_capture_avoiding_with_identifier_generator code ---//
104
105} // namespace action_formulas
106
107} // namespace mcrl2
108
109namespace mcrl2 {
110
111namespace regular_formulas {
112
113namespace detail {
114
115// Below the code is provided for a capture avoiding replacement with an identifier generator.
116template <template <class> class Builder, class Derived, class Substitution, class IdentifierGenerator>
118{
120 using super::enter;
121 using super::leave;
122 using super::update;
123 using super::apply;
124 using super::update_sigma;
125
126 add_capture_avoiding_replacement_with_an_identifier_generator(Substitution& sigma, IdentifierGenerator& id_generator)
128 { }
129};
130
131template <template <class> class Builder, class Substitution, class IdentifierGenerator>
134{
135 return add_capture_avoiding_replacement_with_an_identifier_generator<Builder, Derived, Substitution, IdentifierGenerator>(sigma, id_generator);
136}
137
138} // namespace detail
139
140//--- start generated regular_formulas replace_capture_avoiding_with_identifier_generator code ---//
141/// \\brief Applies sigma as a capture avoiding substitution to x using an identifier generator.
142/// \\details This substitution function is much faster than replace_variables_capture_avoiding, but
143/// it requires an identifier generator that generates strings for fresh variables. These
144/// strings must be unique in the sense that they have not been used for other variables.
145/// \\param x The object to which the subsitution is applied.
146/// \\param sigma A mutable substitution of which it can efficiently be checked whether a variable occurs in its
147/// right hand side. The class maintain_variables_in_rhs is useful for this purpose.
148/// \\param id_generator A generator that generates unique strings, not yet used as variable names.
149
150template <typename T, typename Substitution, typename IdentifierGenerator>
152 Substitution& sigma,
153 IdentifierGenerator& id_generator,
154 typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
155 )
156{
157 data::detail::apply_replace_capture_avoiding_variables_builder_with_an_identifier_generator<regular_formulas::data_expression_builder, regular_formulas::detail::add_capture_avoiding_replacement_with_an_identifier_generator>(sigma, id_generator).update(x);
158}
159
160/// \\brief Applies sigma as a capture avoiding substitution to x using an identifier generator..
161/// \\details This substitution function is much faster than replace_variables_capture_avoiding, but
162/// it requires an identifier generator that generates strings for fresh variables. These
163/// strings must be unique in the sense that they have not been used for other variables.
164/// \\param x The object to which the substiution is applied.
165/// \\param sigma A mutable substitution of which it can efficiently be checked whether a variable occurs in its
166/// right hand side. The class maintain_variables_in_rhs is useful for this purpose.
167/// \\param id_generator A generator that generates unique strings, not yet used as variable names.
168/// \\return The result is the term x to which sigma has been applied.
169template <typename T, typename Substitution, typename IdentifierGenerator>
171 Substitution& sigma,
172 IdentifierGenerator& id_generator,
173 typename std::enable_if<std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
174 )
175{
176 T result;
177 data::detail::apply_replace_capture_avoiding_variables_builder_with_an_identifier_generator<regular_formulas::data_expression_builder, regular_formulas::detail::add_capture_avoiding_replacement_with_an_identifier_generator>(sigma, id_generator).apply(result, x);
178 return result;
179}
180//--- end generated regular_formulas replace_capture_avoiding_with_identifier_generator code ---//
181
182} // namespace regular_formulas
183
184} // namespace mcrl2
185
186namespace mcrl2 {
187
188namespace state_formulas {
189
190namespace detail {
191
192// Below the code for add capture avoiding replacment with an identifier generator is provided.
193
194template <template <class> class Builder, class Derived, class Substitution, class IdentifierGenerator>
196{
198 using super::enter;
199 using super::leave;
200 using super::update;
201 using super::apply;
202 using super::sigma;
203 using super::update_sigma;
204
206 {
207 data::variable_list v = update_sigma.push(x.variables());
208 state_formula result = forall(v, (*this)(x.body()));
209 update_sigma.pop(v);
210 return result;
211 }
212
214 {
215 data::variable_list v = update_sigma.push(x.variables());
216 state_formula result = exists(v, (*this)(x.body()));
217 update_sigma.pop(v);
218 return result;
219 }
220
221 add_capture_avoiding_replacement_with_an_identifier_generator(Substitution& sigma, IdentifierGenerator& id_generator)
223 { }
224};
225
226template <template <class> class Builder, class Substitution, class IdentifierGenerator>
229{
230 return add_capture_avoiding_replacement_with_an_identifier_generator<Builder, Derived, Substitution, IdentifierGenerator>(sigma, id_generator);
231}
232
233} // namespace detail
234
235//--- start generated state_formulas replace_capture_avoiding_with_identifier_generator code ---//
236/// \\brief Applies sigma as a capture avoiding substitution to x using an identifier generator.
237/// \\details This substitution function is much faster than replace_variables_capture_avoiding, but
238/// it requires an identifier generator that generates strings for fresh variables. These
239/// strings must be unique in the sense that they have not been used for other variables.
240/// \\param x The object to which the subsitution is applied.
241/// \\param sigma A mutable substitution of which it can efficiently be checked whether a variable occurs in its
242/// right hand side. The class maintain_variables_in_rhs is useful for this purpose.
243/// \\param id_generator A generator that generates unique strings, not yet used as variable names.
244
245template <typename T, typename Substitution, typename IdentifierGenerator>
247 Substitution& sigma,
248 IdentifierGenerator& id_generator,
249 typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
250 )
251{
252 data::detail::apply_replace_capture_avoiding_variables_builder_with_an_identifier_generator<state_formulas::data_expression_builder, state_formulas::detail::add_capture_avoiding_replacement_with_an_identifier_generator>(sigma, id_generator).update(x);
253}
254
255/// \\brief Applies sigma as a capture avoiding substitution to x using an identifier generator..
256/// \\details This substitution function is much faster than replace_variables_capture_avoiding, but
257/// it requires an identifier generator that generates strings for fresh variables. These
258/// strings must be unique in the sense that they have not been used for other variables.
259/// \\param x The object to which the substiution is applied.
260/// \\param sigma A mutable substitution of which it can efficiently be checked whether a variable occurs in its
261/// right hand side. The class maintain_variables_in_rhs is useful for this purpose.
262/// \\param id_generator A generator that generates unique strings, not yet used as variable names.
263/// \\return The result is the term x to which sigma has been applied.
264template <typename T, typename Substitution, typename IdentifierGenerator>
266 Substitution& sigma,
267 IdentifierGenerator& id_generator,
268 typename std::enable_if<std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
269 )
270{
271 T result;
272 data::detail::apply_replace_capture_avoiding_variables_builder_with_an_identifier_generator<state_formulas::data_expression_builder, state_formulas::detail::add_capture_avoiding_replacement_with_an_identifier_generator>(sigma, id_generator).apply(result, x);
273 return result;
274}
275//--- end generated state_formulas replace_capture_avoiding_with_identifier_generator code ---//
276
277} // namespace state_formulas
278
279} // namespace mcrl2
280
281#endif // MCRL2_MODAL_FORMULA_REPLACE_CAPTURE_AVOIDING_WITH_AN_IDENTIFIER_GENERATOR_H
\brief The existential quantification operator for action formulas
const action_formula & body() const
\brief The universal quantification operator for action formulas
const action_formula & body() const
\brief The existential quantification operator for state formulas
\brief The universal quantification operator for state formulas
void replace_variables_capture_avoiding_with_an_identifier_generator(T &x, Substitution &sigma, IdentifierGenerator &id_generator, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
T replace_variables_capture_avoiding_with_an_identifier_generator(const T &x, Substitution &sigma, IdentifierGenerator &id_generator, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Namespace for all data library functionality.
Definition data.cpp:22
atermpp::term_list< variable > variable_list
\brief list of variables
add_capture_avoiding_replacement_with_an_identifier_generator< Builder, class Derived, Substitution, IdentifierGenerator > make_add_capture_avoiding_replacement_with_an_identifier_generator(Substitution &sigma, IdentifierGenerator &id_generator)
void replace_variables_capture_avoiding_with_an_identifier_generator(T &x, Substitution &sigma, IdentifierGenerator &id_generator, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
T replace_variables_capture_avoiding_with_an_identifier_generator(const T &x, Substitution &sigma, IdentifierGenerator &id_generator, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
add_capture_avoiding_replacement_with_an_identifier_generator< Builder, class Derived, Substitution, IdentifierGenerator > make_add_capture_avoiding_replacement_with_an_identifier_generator(Substitution &sigma, IdentifierGenerator &id_generator)
T replace_variables_capture_avoiding_with_an_identifier_generator(const T &x, Substitution &sigma, IdentifierGenerator &id_generator, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
void replace_variables_capture_avoiding_with_an_identifier_generator(T &x, Substitution &sigma, IdentifierGenerator &id_generator, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
lps::detail::add_capture_avoiding_replacement_with_an_identifier_generator< Builder, Derived, Substitution, IdentifierGenerator > super
action_formulas::detail::add_capture_avoiding_replacement_with_an_identifier_generator< Builder, Derived, Substitution, IdentifierGenerator > super
data::detail::add_capture_avoiding_replacement_with_an_identifier_generator< Builder, Derived, Substitution, IdentifierGenerator > super