mCRL2
Loading...
Searching...
No Matches
remove_parameters.h
Go to the documentation of this file.
1// Author(s): Wieger Wesselink
2// Copyright: see the accompanying file COPYING.
3//
4// Distributed under the Boost Software License, Version 1.0.
5// (See accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt)
7//
8/// \file mcrl2/pbes/remove_parameters.h
9/// \brief Functions for removing insignificant parameters from pbes types.
10
11#ifndef MCRL2_PBES_REMOVE_PARAMETERS_H
12#define MCRL2_PBES_REMOVE_PARAMETERS_H
13
14#include "mcrl2/pbes/builder.h"
15
16namespace mcrl2::pbes_system
17{
18
19/// \cond INTERNAL_DOCS
20namespace detail
21{
22
23/// \brief Removes elements with indices in a given sequence from the sequence l
24/// \param l A sequence of terms
25/// \param to_be_removed A sorted sequence of integers
26/// \return The removal result
27template <typename Term>
28atermpp::term_list<Term> remove_elements(const atermpp::term_list<Term>& l, const std::vector<std::size_t>& to_be_removed)
29{
30 assert(std::is_sorted(to_be_removed.begin(), to_be_removed.end()));
31 std::size_t index = 0;
32 std::vector<Term> result;
33 auto j = to_be_removed.begin();
34 for (auto i = l.begin(); i != l.end(); ++i, ++index)
35 {
36 if (j != to_be_removed.end() && index == *j)
37 {
38 ++j;
39 }
40 else
41 {
42 result.push_back(*i);
43 }
44 }
45 return atermpp::term_list<Term>(result.begin(),result.end());
46}
47
48template <typename Derived>
49struct remove_parameters_builder: public pbes_system::pbes_expression_builder<Derived>
50{
51 using super = pbes_system::pbes_expression_builder<Derived>;
52 using super::enter;
53 using super::leave;
54 using super::update;
55 using super::apply;
56
57 const std::vector<std::size_t>& to_be_removed;
58
59 remove_parameters_builder(const std::vector<std::size_t>& to_be_removed_)
60 : to_be_removed(to_be_removed_)
61 {}
62
63 template <class T>
64 void apply(T& result, const propositional_variable& x)
65 {
66 make_propositional_variable(result, x.name(), detail::remove_elements(x.parameters(), to_be_removed));
67 }
68
69 template <class T>
70 void apply(T& result, const propositional_variable_instantiation& x)
71 {
72 make_propositional_variable_instantiation(result, x.name(), detail::remove_elements(x.parameters(), to_be_removed));
73 }
74
75 void update(pbes_equation& x)
76 {
78 static_cast<Derived&>(*this).apply(variable, x.variable());
79 x.variable() = variable;
80 pbes_expression formula;
81 static_cast<Derived&>(*this).apply(formula, x.formula());
82 x.formula() = formula;
83 }
84
85 void update(pbes& x)
86 {
87 static_cast<Derived&>(*this).update(x.equations());
89 static_cast<Derived&>(*this).apply(initial_state, x.initial_state());
90 x.initial_state() = initial_state;
91 static_cast<Derived&>(*this).update(x.global_variables());
92 }
93};
94
95
96} // namespace detail
97/// \endcond
98
99/// \brief Removes parameters from propositional variable instantiations in a pbes expression
100/// \param x A PBES library object that derives from atermpp::aterm
101/// \param to_be_removed The indices of parameters that are to be removed
102/// \return The expression \p x with parameters removed according to the mapping \p to_be_removed
103template <typename T>
104 requires(std::is_base_of_v<atermpp::aterm, T>)
107{
108 T result;
110 return result;
111}
112
113/// \brief Removes parameters from propositional variable instantiations in a pbes expression
114/// \param x A PBES library object that does not derive from atermpp::aterm
115/// \param to_be_removed The indices of parameters that are to be removed
116/// \return The expression \p x with parameters removed according to the mapping \p to_be_removed
117template <typename T>
118 requires(!std::is_base_of_v<atermpp::aterm, T>)
121{
123}
124
125/// \cond INTERNAL_DOCS
126namespace detail
127{
128
129template <typename Derived>
131{
133 using super::enter;
134 using super::leave;
135 using super::update;
136 using super::apply;
137
139
142 {}
143
144 // to prevent default operator() being called
145 template <class T>
146 void apply(T& result, const data::data_expression& x)
147 {
149 }
150
151 template <class T>
152 void apply(T& result, const propositional_variable& x)
153 {
154 auto i = to_be_removed.find(x.name());
155 if (i == to_be_removed.end())
156 {
157 result = x;
158 return;
159 }
161 }
162
163 template <class T>
165 {
166 auto i = to_be_removed.find(x.name());
167 if (i == to_be_removed.end())
168 {
169 result = x;
170 }
171 else
172 {
174 }
175 }
176
177 void update(pbes_equation& x)
178 {
180 static_cast<Derived&>(*this).apply(variable, x.variable());
181 x.variable() = variable;
183 static_cast<Derived&>(*this).apply(formula, x.formula());
184 x.formula() = formula;
185 }
186
187 void update(pbes& x)
188 {
189 static_cast<Derived&>(*this).update(x.equations());
191 static_cast<Derived&>(*this).apply(initial_state, x.initial_state());
193 }
194};
195} // namespace detail
196/// \endcond
197
198/// \brief Removes parameters from propositional variable instantiations in a pbes expression
199/// \param x A PBES library object that derives from atermpp::aterm
200/// \param to_be_removed A mapping that maps propositional variable names to indices of parameters that are removed
201/// \return The expression \p x with parameters removed according to the mapping \p to_be_removed
202template <typename T>
203 requires(std::is_base_of_v<atermpp::aterm, T>)
206{
207 T result;
209 return result;
210}
211
212/// \brief Removes parameters from propositional variable instantiations in a pbes expression
213/// \param x A PBES library object that does not derive from atermpp::aterm
214/// \param to_be_removed A mapping that maps propositional variable names to a sorted vector of parameter indices that
215/// need to be removed
216/// \return The expression \p x with parameters removed according to the mapping \p to_be_removed
217template <typename T>
218 requires(!std::is_base_of_v<atermpp::aterm, T>)
221{
223}
224
225/// \cond INTERNAL_DOCS
226namespace detail
227{
228
229template <typename Derived>
231{
233 using super::enter;
234 using super::leave;
235 using super::update;
236 using super::apply;
237
239
242 {}
243
244 void remove_parameters(std::set<data::variable>& x) const
245 {
246 for (const auto& i: to_be_removed)
247 {
248 x.erase(i);
249 }
250 }
251
252 void apply_(data::variable_list& result, const data::variable_list& l) const
253 {
254 using utilities::detail::contains;
255
257 for (const data::variable& v: l)
258 {
259 if (!contains(to_be_removed, v))
260 {
262 }
263 }
265 }
266
267 template <class T>
268 void apply(T& result, const data::assignment_list& l) const
269 {
270 using utilities::detail::contains;
271 std::vector<data::assignment> a(l.begin(), l.end());
272 a.erase(std::remove_if(a.begin(), a.end(), [&](const data::assignment& y) { return contains(to_be_removed, y.lhs()); }), a.end());
274 }
275
276 template <class T>
277 void apply(T& result, const propositional_variable& x)
278 {
280 static_cast<Derived&>(*this).apply_(vars, x.parameters()); // Underscore is nasty trick to select the correct apply.
282 }
283
284 void update(pbes_equation& x)
285 {
287 static_cast<Derived&>(*this).apply(variable, x.variable());
288 x.variable() = variable;
290 static_cast<Derived&>(*this).apply(formula, x.formula());
291 x.formula() = formula;
292 }
293
294 void update(pbes& x)
295 {
296 static_cast<Derived&>(*this).update(x.equations());
298 static_cast<Derived&>(*this).apply(initial_state, x.initial_state());
301 }
302};
303} // namespace detail
304/// \endcond
305
306/// \brief Removes parameters from propositional variable instantiations in a pbes expression
307/// \param x A PBES library object that derives from atermpp::aterm
308/// \param to_be_removed A set of parameters that are to be removed
309/// \return The expression \p x with parameters removed according to the mapping \p to_be_removed
310template <typename T>
311 requires(std::is_base_of_v<atermpp::aterm, T>)
314{
315 T result;
317 return result;
318}
319
320/// \brief Removes parameters from propositional variable instantiations in a pbes expression
321/// \param x A PBES library object that does not derive from atermpp::aterm
322/// \param to_be_removed A set of parameters that are to be removed
323/// \return The expression \p x with parameters removed according to the mapping \p to_be_removed
324template <typename T>
325 requires(!std::is_base_of_v<atermpp::aterm, T>)
328{
330}
331
332
333/// \cond INTERNAL_DOCS
334// used in pbes.h
335inline
338 )
339{
341}
342/// \endcond
343
344} // namespace mcrl2::pbes_system
345
346#endif // MCRL2_PBES_REMOVE_PARAMETERS_H
A list of aterm objects.
Definition aterm_list.h:26
A unordered_map class in which aterms can be stored.
Rewriter that operates on data expressions.
Definition rewriter.h:84
Identifier generator that stores the identifiers of the context in a set. Using the operator()() and ...
\brief A data variable
Definition variable.h:25
\brief The and operator for pbes expressions
\brief The existential quantification operator for pbes expressions
const data::variable_list & variables() const
\brief The universal quantification operator for pbes expressions
const data::variable_list & variables() const
\brief The implication operator for pbes expressions
\brief The not operator for pbes expressions
\brief The or operator for pbes expressions
propositional_variable & variable()
Returns the pbes variable of the equation.
pbes_expression & formula()
Returns the predicate formula on the right hand side of the equation.
pbes_expression & operator=(const pbes_expression &) noexcept=default
parameterized boolean equation system
Definition pbes.h:54
propositional_variable_instantiation & initial_state()
Returns the initial state.
Definition pbes.h:195
Algorithm class for the finite pbesinst algorithm.
data::enumerator_identifier_generator m_id_generator
Identifier generator for the enumerator.
std::size_t m_equation_count
The number of generated equations.
void run(pbes &pbesspec, const pbesinst_variable_map &variable_map)
Runs the algorithm.
std::string print_equation_count(std::size_t size) const
Prints a message for every 1000-th equation.
data::rewriter::strategy m_rewriter_strategy
The strategy of the data rewriter.
void compute_index_map(const std::vector< pbes_equation > &equations, const pbesinst_variable_map &variable_map, pbesinst_index_map &index_map)
Returns true if the container contains the given element.
pbesinst_finite_algorithm(data::rewriter::strategy rewriter_strategy=data::jitty)
Constructor.
\brief A propositional variable instantiation
propositional_variable_instantiation(const core::identifier_string &name, const data::data_expression_list &parameters)
Constructor.
propositional_variable_instantiation & operator=(const propositional_variable_instantiation &) noexcept=default
\brief A propositional variable declaration
propositional_variable & operator=(const propositional_variable &) noexcept=default
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:393
data_expression and_(const data_expression &x, const data_expression &y)
const data_expression & true_()
Definition consistency.h:91
std::set< data::variable > significant_variables(const pbes_expression &x)
Returns the significant variables of a pbes expression.
void remove_parameters(pbes &x, const std::set< data::variable > &to_be_removed)
Removes parameters from propositional variable instantiations in a pbes expression.
void remove_parameters(pbes &x, const std::map< core::identifier_string, std::vector< std::size_t > > &to_be_removed)
Removes parameters from propositional variable instantiations in a pbes expression.
void pbesinst_finite(pbes &p, data::rewrite_strategy rewrite_strategy, const std::string &finite_parameter_selection)
Apply finite instantiation to the given PBES.
void instantiate_global_variables(pbes &p)
Attempts to eliminate the free variables of a PBES, by substituting a constant value for them....
Definition pbes.cpp:64
bool is_normalized(const pbes &x)
Checks if a PBEs is normalized.
std::vector< propositional_variable > remove_unreachable_variables(pbes &p)
Removes equations that are not (syntactically) reachable from the initial state of a PBES.
std::string print_removed_equations(const std::vector< propositional_variable > &removed)
Print removed equations.
void normalize(pbes &x)
The function normalize brings (embedded) pbes expressions into positive normal form,...
std::ostream & print_pbes_parameter_map(std::ostream &out, const pbes_parameter_map &m)
Print a parameter map.
bool match_declaration(const std::string &text, const data::variable &d, const data::data_specification &data_spec)
Returns true if the declaration text matches with the variable d.
std::string print_removed_equations(const std::vector< propositional_variable > &removed)
void split_parameters(const PropositionalVariable &X, const pbesinst_index_map &index_map, std::vector< Parameter > &finite, std::vector< Parameter > &infinite)
Computes the subset with variables of finite sort and infinite.
pbes_parameter_map parse_pbes_parameter_map(const pbes &p, const std::string &text)
Parses parameter selection for finite pbesinst algorithm.
std::vector< data::variable > find_matching_parameters(const pbes &p, const std::string &name, const std::set< std::string > &declarations)
Find parameter declarations that match a given string.
The main namespace for the PBES library.
std::set< propositional_variable > reachable_variables(const pbes &p)
pbes_expression make_exists_(const data::variable_list &l, const pbes_expression &p)
Make an existential quantification. It checks for an empty variable list, which is not allowed.
void pbesinst_finite(pbes &p, data::rewrite_strategy rewrite_strategy, const std::string &finite_parameter_selection)
pbes_expression make_forall_(const data::variable_list &l, const pbes_expression &p)
Make a universal quantification. It checks for an empty variable list, which is not allowed.
std::vector< propositional_variable > remove_unreachable_variables(pbes &p)
Removes equations that are not (syntactically) reachable from the initial state of a PBES.
bool is_normalized(const T &x)
Checks if a pbes expression is normalized.
Definition normalize.h:155
An empty struct that is used to denote the absence of a substitution. Used for rewriters.
Visitor that applies a propositional variable substitution to a pbes expression.
data::data_expression make_condition(const VariableContainer &variables, const ExpressionContainer &expressions) const
Computes the condition 'for all i: variables[i] == expressions[i]'.
void apply(T &result, const propositional_variable_instantiation &x)
data::data_expression_list rewrite_container(const DataExpressionContainer &v, const data::rewriter &rewr, const data::mutable_indexed_substitution<> &sigma)
std::string print_parameters(const std::vector< data::data_expression > &finite_parameters, const std::vector< data::data_expression > &infinite_parameters) const
propositional_variable_instantiation visit_initial_state(const propositional_variable_instantiation &init)
data::data_expression_list rewrite_container(const DataExpressionContainer &v, const data::rewriter &rewr)
pbesinst_finite_builder(const DataRewriter &R, SubstitutionFunction &sigma, const pbesinst_finite_rename &rho, const data::data_specification &data_spec, const pbesinst_index_map &index_map, const pbesinst_variable_map &variable_map)
Exception that is used to signal an empty parameter selection.
Function object for renaming a propositional variable instantiation.
core::identifier_string operator()(const core::identifier_string &name, const data::data_expression_list &parameters) const
Renames the propositional variable x.
std::unordered_map< propositional_variable_instantiation, core::identifier_string > m
core::identifier_string rename(const core::identifier_string &name, const data::data_expression_list &parameters) const