mCRL2
Loading...
Searching...
No Matches
find.h
Go to the documentation of this file.
1// Author(s): Jan Friso Groote. Based on pbes/find.h by 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/pres/find.h
10/// \brief Search functions of the pres library.
11
12#ifndef MCRL2_PRES_FIND_H
13#define MCRL2_PRES_FIND_H
14
15#include "mcrl2/pres/add_binding.h"
16#include "mcrl2/pres/traverser.h"
17
18namespace mcrl2
19{
20
21namespace pres_system
22{
23
24namespace detail
25{
26
27template <template <class> class Traverser, class OutputIterator>
29{
31 using super::enter;
32 using super::leave;
33 using super::apply;
34
35 OutputIterator out;
36
38 : out(out_)
39 {}
40
41 // instead of deriving from a traverser in the data library
43 {}
44
46 {
47 *out = v;
48 }
49};
50
51template <template <class> class Traverser, class OutputIterator>
54{
55 return find_propositional_variables_traverser<Traverser, OutputIterator>(out);
56}
57
58} // namespace detail
59
60//--- start generated pres_system find code ---//
61/// \\brief Returns all variables that occur in an object
62/// \\param[in] x an object containing variables
63/// \\param[in,out] o an output iterator to which all variables occurring in x are written.
64/// \\return All variables that occur in the term x
65template <typename T, typename OutputIterator>
66void find_all_variables(const T& x, OutputIterator o)
67{
68 data::detail::make_find_all_variables_traverser<pres_system::variable_traverser>(o).apply(x);
69}
70
71/// \\brief Returns all variables that occur in an object
72/// \\param[in] x an object containing variables
73/// \\return All variables that occur in the object x
74template <typename T>
76{
77 std::set<data::variable> result;
78 pres_system::find_all_variables(x, std::inserter(result, result.end()));
79 return result;
80}
81
82/// \\brief Returns all variables that occur in an object
83/// \\param[in] x an object containing variables
84/// \\param[in,out] o an output iterator to which all variables occurring in x are added.
85/// \\return All free variables that occur in the object x
86template <typename T, typename OutputIterator>
87void find_free_variables(const T& x, OutputIterator o)
88{
89 data::detail::make_find_free_variables_traverser<pres_system::data_expression_traverser, pres_system::add_data_variable_traverser_binding>(o).apply(x);
90}
91
92/// \\brief Returns all variables that occur in an object
93/// \\param[in] x an object containing variables
94/// \\param[in,out] o an output iterator to which all variables occurring in x are written.
95/// \\param[in] bound a container of variables
96/// \\return All free variables that occur in the object x
97template <typename T, typename OutputIterator, typename VariableContainer>
98void find_free_variables_with_bound(const T& x, OutputIterator o, const VariableContainer& bound)
99{
100 data::detail::make_find_free_variables_traverser<pres_system::data_expression_traverser, pres_system::add_data_variable_traverser_binding>(o, bound).apply(x);
101}
102
103/// \\brief Returns all variables that occur in an object
104/// \\param[in] x an object containing variables
105/// \\return All free variables that occur in the object x
106template <typename T>
108{
109 std::set<data::variable> result;
110 pres_system::find_free_variables(x, std::inserter(result, result.end()));
111 return result;
112}
113
114/// \\brief Returns all variables that occur in an object
115/// \\param[in] x an object containing variables
116/// \\param[in] bound a bound a container of variables
117/// \\return All free variables that occur in the object x
118template <typename T, typename VariableContainer>
120{
121 std::set<data::variable> result;
122 pres_system::find_free_variables_with_bound(x, std::inserter(result, result.end()), bound);
123 return result;
124}
125
126/// \\brief Returns all identifiers that occur in an object
127/// \\param[in] x an object containing identifiers
128/// \\param[in,out] o an output iterator to which all identifiers occurring in x are written.
129/// \\return All identifiers that occur in the term x
130template <typename T, typename OutputIterator>
131void find_identifiers(const T& x, OutputIterator o)
132{
133 data::detail::make_find_identifiers_traverser<pres_system::identifier_string_traverser>(o).apply(x);
134}
135
136/// \\brief Returns all identifiers that occur in an object
137/// \\param[in] x an object containing identifiers
138/// \\return All identifiers that occur in the object x
139template <typename T>
141{
142 std::set<core::identifier_string> result;
143 pres_system::find_identifiers(x, std::inserter(result, result.end()));
144 return result;
145}
146
147/// \\brief Returns all sort expressions that occur in an object
148/// \\param[in] x an object containing sort expressions
149/// \\param[in,out] o an output iterator to which all sort expressions occurring in x are written.
150/// \\return All sort expressions that occur in the term x
151template <typename T, typename OutputIterator>
152void find_sort_expressions(const T& x, OutputIterator o)
153{
154 data::detail::make_find_sort_expressions_traverser<pres_system::sort_expression_traverser>(o).apply(x);
155}
156
157/// \\brief Returns all sort expressions that occur in an object
158/// \\param[in] x an object containing sort expressions
159/// \\return All sort expressions that occur in the object x
160template <typename T>
162{
163 std::set<data::sort_expression> result;
164 pres_system::find_sort_expressions(x, std::inserter(result, result.end()));
165 return result;
166}
167
168/// \\brief Returns all function symbols that occur in an object
169/// \\param[in] x an object containing function symbols
170/// \\param[in,out] o an output iterator to which all function symbols occurring in x are written.
171/// \\return All function symbols that occur in the term x
172template <typename T, typename OutputIterator>
173void find_function_symbols(const T& x, OutputIterator o)
174{
175 data::detail::make_find_function_symbols_traverser<pres_system::data_expression_traverser>(o).apply(x);
176}
177
178/// \\brief Returns all function symbols that occur in an object
179/// \\param[in] x an object containing function symbols
180/// \\return All function symbols that occur in the object x
181template <typename T>
183{
184 std::set<data::function_symbol> result;
185 pres_system::find_function_symbols(x, std::inserter(result, result.end()));
186 return result;
187}
188//--- end generated pres_system find code ---//
189
190/// \brief Returns all data variables that occur in a range of expressions
191/// \param[in] container a container with expressions
192/// \param[in,out] o an output iterator to which all data variables occurring in t
193/// are added.
194/// \return All data variables that occur in the term t
195template <typename Container, typename OutputIterator>
196void find_propositional_variable_instantiations(Container const& container, OutputIterator o)
197{
198 pres_system::detail::make_find_propositional_variables_traverser<pres_system::pres_expression_traverser>(o).apply(container);
199}
200
201/// \brief Returns all data variables that occur in a range of expressions
202/// \param[in] container a container with expressions
203/// \return All data variables that occur in the term t
204template <typename Container>
206{
207 std::set<propositional_variable_instantiation> result;
208 pres_system::find_propositional_variable_instantiations(container, std::inserter(result, result.end()));
209 return result;
210}
211
212/// \brief Returns true if the term has a given variable as subterm.
213/// \param[in] x an expression
214/// \param[in] v a variable
215/// \return True if v occurs in x.
216template <typename T>
217bool search_variable(const T& x, const data::variable& v)
218{
219 data::detail::search_variable_traverser<pres_system::variable_traverser> f(v);
220 f.apply(x);
221 return f.found;
222}
223
224} // namespace pres_system
225
226} // namespace mcrl2
227
228#endif // MCRL2_PRES_FIND_H
Components for generating an arbitrary element of a sort.
representative_generator(const data_specification &specification)
Constructor with data specification as context.
Identifier generator that stores the identifiers of the context in a set. Using the operator()() and ...
void add_identifier(const core::identifier_string &s) override
Adds the identifier s to the context.
\brief A data variable
Definition variable.h:28
const core::identifier_string & name() const
Definition variable.h:38
\brief The and operator for pres expressions
\brief The multiplication with a positive constant with the constant at the right.
\brief The multiplication with a positive constant with the constant at the left.
\brief The implication operator for pres expressions
\brief The infimum over a data type for pres expressions
const pres_expression & body() const
\brief The not operator for pres expressions
\brief The or operator for pres expressions
pres_expression & formula()
Returns the predicate formula on the right hand side of the equation.
bool is_solved() const
Returns true if the predicate formula on the right hand side contains no predicate variables.
Definition pres.cpp:106
const pres_expression & formula() const
Returns the predicate formula on the right hand side of the equation.
pres_expression & operator=(const pres_expression &) noexcept=default
parameterized boolean equation system
Definition pres.h:59
std::set< propositional_variable_instantiation > occurring_variable_instantiations() const
Returns the set of occurring propositional variable instantiations of the pres. This is the set of va...
Definition pres.cpp:111
\brief A propositional variable instantiation
\brief The generic sum operator for pres expressions
const pres_expression & body() const
\brief The supremeum over a data type for pres expressions
const pres_expression & body() const
D_ParserTables parser_tables_mcrl2
Definition dparser.cpp:20
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:391
void syntax_error_fn(struct D_Parser *ap)
Custom syntax error function that prints both the line number and the column.
Definition dparser.cpp:463
D_ParseNode * ambiguity_fn(struct D_Parser *, int n, struct D_ParseNode **v)
Function for resolving parser ambiguities.
Definition dparser.cpp:332
void warn_and_or(const parse_node &)
Prints a warning for each occurrence of 'x && y || z' in the parse tree.
Namespace for all data library functionality.
Definition data.cpp:22
atermpp::term_list< variable > variable_list
\brief list of variables
void instantiate_global_variables(pres &p)
Attempts to eliminate the free variables of a PRES, by substituting a constant value for them....
Definition pres.cpp:68
bool is_res(const pres &x)
Returns true if a PRES is in RES form.
Definition pres.cpp:73
data::mutable_map_substitution instantiate_global_variables(pres &p)
Eliminates the global variables of a PRES, by substituting a constant value for them....
void complete_pres(pres &x)
Definition pres.cpp:147
untyped_pres parse_pres_new(const std::string &text)
Definition pres.cpp:136
bool is_well_typed(const pres_equation &eqn)
Checks if the equation is well typed.
void replace_global_variables(pres &p, const data::mutable_map_substitution<> &sigma)
Applies a global variable substitution to a PRES.
propositional_variable parse_propositional_variable(const std::string &text)
Definition pres.cpp:154
bool has_propositional_variables(const pres_expression &x)
find_propositional_variables_traverser< Traverser, OutputIterator > make_find_propositional_variables_traverser(OutputIterator out)
Definition find.h:53
pres_expression parse_pres_expression_new(const std::string &text)
Definition pres.cpp:125
pres_expression parse_pres_expression(const std::string &text)
Definition pres.cpp:163
The main namespace for the PRES library.
void translate_user_notation(pres_system::pres &x)
Definition pres.cpp:53
std::string pp(const pres_system::supremum &x)
Definition pres.cpp:37
void replace_propositional_variables(T &x, const Substitution &sigma, typename std::enable_if< !std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Applies a propositional variable substitution.
Definition replace.h:236
std::vector< pres_expression > pres_expression_vector
\brief vector of pres_expressions
T replace_propositional_variables(const T &x, const Substitution &sigma, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Applies a propositional variable substitution.
Definition replace.h:246
std::string pp(const pres_system::const_multiply &x)
Definition pres.cpp:43
std::set< data::variable > find_free_variables(const pres_system::pres &x)
Definition pres.cpp:57
void typecheck_pres(pres &presspec)
Type check a parsed mCRL2 pres specification. Throws an exception if something went wrong.
Definition typecheck.h:341
void replace_free_variables(T &x, const Substitution &sigma, const VariableContainer &bound_variables, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Definition replace.h:208
void find_free_variables(const T &x, OutputIterator o)
Definition find.h:87
std::vector< propositional_variable_instantiation > propositional_variable_instantiation_vector
\brief vector of propositional_variable_instantiations
void replace_propositional_variables(T &result, const T &x, const Substitution &sigma, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Applies a propositional variable substitution.
Definition replace.h:258
std::string pp(const pres_system::fixpoint_symbol &x)
Definition pres.cpp:38
bool is_well_typed_equation(const pres_equation &eqn, const std::set< data::sort_expression > &declared_sorts, const std::set< data::variable > &declared_global_variables, const data::data_specification &data_spec)
Definition pres.cpp:85
std::string pp(const pres_system::pres_expression &x)
Definition pres.cpp:47
std::string pp(const pres_system::infimum &x)
Definition pres.cpp:39
std::set< core::identifier_string > find_identifiers(const T &x)
Definition find.h:140
void replace_variables_capture_avoiding(T &x, Substitution &sigma, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
T replace_pres_expressions(const T &x, const Substitution &sigma, bool innermost=true, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Definition replace.h:278
void find_propositional_variable_instantiations(Container const &container, OutputIterator o)
Returns all data variables that occur in a range of expressions.
Definition find.h:196
T replace_data_expressions(const T &x, const Substitution &sigma, bool innermost, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Definition replace.h:127
std::string pp(const pres_system::pres_equation &x)
Definition pres.cpp:46
void replace_pres_expressions(T &x, const Substitution &sigma, bool innermost=true, typename std::enable_if< !std::is_base_of< atermpp::aterm, T >::value >::type *=0)
Definition replace.h:268
void find_sort_expressions(const T &x, OutputIterator o)
Definition find.h:152
void normalize_sorts(pres_system::pres_equation_vector &x, const data::sort_specification &sortspec)
Definition pres.cpp:50
std::string pp(const pres_system::propositional_variable_list &x)
Definition pres.cpp:31
std::set< data::variable > find_free_variables_with_bound(const T &x, VariableContainer const &bound)
Definition find.h:119
bool search_variable(const pres_system::pres_expression &x, const data::variable &v)
Definition pres.cpp:63
std::string pp(const pres_system::or_ &x)
Definition pres.cpp:36
std::set< propositional_variable_instantiation > find_propositional_variable_instantiations(Container const &container)
Returns all data variables that occur in a range of expressions.
Definition find.h:205
void find_all_variables(const T &x, OutputIterator o)
Definition find.h:66
std::string pp(const pres_system::const_multiply_alt &x)
Definition pres.cpp:44
void replace_variables_capture_avoiding(T &x, Substitution &sigma, data::set_identifier_generator &id_generator, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
std::vector< pres_equation > pres_equation_vector
\brief vector of pres_equations
std::set< pres_system::propositional_variable_instantiation > find_propositional_variable_instantiations(const pres_system::pres_expression &x)
Definition pres.cpp:61
void replace_sort_expressions(T &x, const Substitution &sigma, bool innermost, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Definition replace.h:95
std::set< data::sort_expression > find_sort_expressions(const pres_system::pres &x)
Definition pres.cpp:55
std::set< data::function_symbol > find_function_symbols(const pres_system::pres &x)
Definition pres.cpp:60
std::set< data::variable > find_free_variables(const T &x)
Definition find.h:107
void normalize_sorts(pres_system::pres &x, const data::sort_specification &)
Definition pres.cpp:51
std::set< data::variable > find_free_variables(const pres_system::pres_expression &x)
Definition pres.cpp:58
atermpp::term_list< pres_expression > pres_expression_list
\brief list of pres_expressions
void replace_free_variables(T &x, const Substitution &sigma, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Definition replace.h:182
std::string pp(const pres_system::pres_expression_list &x)
Definition pres.cpp:29
std::string pp(const pres_system::sum &x)
Definition pres.cpp:40
bool is_well_typed_pres(const std::set< data::sort_expression > &declared_sorts, const std::set< data::variable > &declared_global_variables, const std::set< data::variable > &occurring_global_variables, const std::set< propositional_variable > &declared_variables, const std::set< propositional_variable_instantiation > &occ, const propositional_variable_instantiation &init, const data::data_specification &data_spec)
Definition pres.cpp:94
atermpp::term_list< pbes_system::propositional_variable > propositional_variable_list
\brief list of propositional_variables
std::set< data::variable > find_all_variables(const T &x)
Definition find.h:75
std::set< data::variable > find_free_variables(const pres_system::pres_equation &x)
Definition pres.cpp:59
std::string pp(const pres_system::pres_equation_vector &x)
Definition pres.cpp:28
T replace_variables_capture_avoiding(const T &x, Substitution &sigma, data::set_identifier_generator &id_generator, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
void find_free_variables_with_bound(const T &x, OutputIterator o, const VariableContainer &bound)
Definition find.h:98
T replace_free_variables(const T &x, const Substitution &sigma, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Definition replace.h:194
void replace_variables(T &x, const Substitution &sigma, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Definition replace.h:140
std::string pp(const pres_system::and_ &x)
Definition pres.cpp:35
pres_system::pres_expression translate_user_notation(const pres_system::pres_expression &x)
Definition pres.cpp:54
void find_function_symbols(const T &x, OutputIterator o)
Definition find.h:173
T replace_free_variables(const T &x, const Substitution &sigma, const VariableContainer &bound_variables, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Definition replace.h:221
std::set< core::identifier_string > find_identifiers(const pres_system::pres_expression &x)
Definition pres.cpp:62
std::set< data::function_symbol > find_function_symbols(const T &x)
Definition find.h:182
bool search_variable(const T &x, const data::variable &v)
Returns true if the term has a given variable as subterm.
Definition find.h:217
std::set< data::sort_expression > find_sort_expressions(const T &x)
Definition find.h:161
void find_identifiers(const T &x, OutputIterator o)
Definition find.h:131
std::string pp(const pres_system::pres &x)
Definition pres.cpp:45
std::string pp(const pres_system::imp &x)
Definition pres.cpp:41
std::vector< pbes_system::propositional_variable > propositional_variable_vector
\brief vector of propositional_variables
std::string pp(const pres_system::propositional_variable_instantiation &x)
Definition pres.cpp:49
void replace_data_expressions(T &x, const Substitution &sigma, bool innermost, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Definition replace.h:117
T replace_sort_expressions(const T &x, const Substitution &sigma, bool innermost, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Definition replace.h:105
T replace_variables(const T &x, const Substitution &sigma, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Definition replace.h:149
void replace_all_variables(T &x, const Substitution &sigma, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Definition replace.h:160
std::string pp(const pres_system::minus &x)
Definition pres.cpp:42
pres_system::pres_expression normalize_sorts(const pres_system::pres_expression &x, const data::sort_specification &sortspec)
Definition pres.cpp:52
T replace_variables_capture_avoiding(const T &x, Substitution &sigma, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
std::string pp(const pres_system::propositional_variable_instantiation_list &x)
Definition pres.cpp:33
void complete_data_specification(pres &)
Adds all sorts that appear in the PRES p to the data specification of p.
Definition pres.h:320
std::set< data::variable > find_all_variables(const pres_system::pres &x)
Definition pres.cpp:56
std::string pp(const pres_system::propositional_variable &x)
Definition pres.cpp:48
bool is_well_typed(const pres_equation &eqn)
Definition pres.cpp:80
atermpp::term_list< propositional_variable_instantiation > propositional_variable_instantiation_list
\brief list of propositional_variable_instantiations
T replace_all_variables(const T &x, const Substitution &sigma, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Definition replace.h:169
Wrapper for D_ParseNode.
Definition dparser.h:86
Wrapper for D_Parser and its corresponding D_ParserTables.
Definition dparser.h:148
parse_node parse(const std::string &text, unsigned int start_symbol_index=0, bool partial_parses=false)
Parses a string. N.B. The user is responsible for destruction of the returned value by calling destro...
Definition dparser.cpp:209
parser(D_ParserTables &tables, D_AmbiguityFn ambiguity_fn=nullptr, D_SyntaxErrorFn syntax_error_fn=nullptr, std::size_t max_error_message_count=1)
Definition dparser.cpp:174
unsigned int start_symbol_index(const std::string &name) const
Definition dparser.cpp:204
add_capture_avoiding_replacement(data::detail::capture_avoiding_substitution_updater< Substitution > &sigma)
data::detail::add_capture_avoiding_replacement< Builder, Derived, Substitution > super
void apply(const propositional_variable_instantiation &v)
Definition find.h:45
Traverser< find_propositional_variables_traverser< Traverser, OutputIterator > > super
Definition find.h:30
pres_expression_traverser< has_propositional_variables_traverser > super
pres_system::pres_expression parse_PresExpr(const core::parse_node &node) const
Definition parse_impl.h:33
pres_system::propositional_variable parse_PropVarDecl(const core::parse_node &node) const
Definition parse_impl.h:59
pres_actions(const core::parser &parser_)
Definition parse_impl.h:29
untyped_pres parse_PresSpec(const core::parse_node &node) const
Definition parse_impl.h:96
std::size_t operator()(const atermpp::detail::reference_aterm< T > &t) const