12#ifndef MCRL2_DATA_REPLACE_CAPTURE_AVOIDING_H
13#define MCRL2_DATA_REPLACE_CAPTURE_AVOIDING_H
15#include "mcrl2/atermpp/aterm.h"
16#include "mcrl2/core/detail/print_utility.h"
17#include "mcrl2/data/concepts.h"
18#include "mcrl2/data/assignment.h"
19#include "mcrl2/data/builder.h"
20#include "mcrl2/data/find.h"
30template <
typename Substitution>
45 updates[v].push_back(v1);
52 auto i = updates.find(v);
53 id_generator.remove_identifier(i->second.back().name());
55 if (i->second.empty())
62 template <
typename VariableContainer>
68 [&](
const variable& v)
70 return add_fresh_variable_assignment(v);
76 template <
typename VariableContainer>
87 auto i = updates.find(x);
88 if (i != updates.end())
90 return i->second.back();
99template <
typename Substitution>
102 std::vector<std::string> updates;
103 for (
const auto& p: sigma.updates)
105 updates.push_back(data::pp(p.first) +
" := " + core::detail::print_list(p.second));
107 return out << sigma.sigma <<
" with updates " << core::detail::print_list(updates);
110template <
template <
class>
class Builder,
template <
template <
class>
class,
class,
class>
class Binder,
class Substitution>
125template <
template <
class>
class Builder,
template <
template <
class>
class,
class,
class>
class Binder,
class Substitution>
129 return replace_capture_avoiding_variables_builder<Builder, Binder, Substitution>(sigma);
132template <
template <
class>
class Builder,
class Derived,
class Substitution>
135 using super = Builder<Derived>;
151 result = assignment_list(
154 [&](data::assignment&r,
const data::assignment& a)
156 data::make_assignment(r, a.lhs(), [&](data_expression& r){ apply(r, a.rhs() ); } );
164 result = atermpp::down_cast<T>(sigma(v));
172 auto declarations1 = data::assignment_list(
173 declarations.begin(),
175 [&](
const assignment& a)
177 const data::variable& v = a.lhs();
178 const data_expression& x1 = a.rhs();
180 data::variable v1 = sigma.add_fresh_variable_assignment(v);
181 data::data_expression rhs;
183 return assignment(v1, rhs);
188 make_where_clause(result, body, declarations1);
194 sigma.remove_fresh_variable_assignment(v);
201 variable_list v1 = sigma.add_fresh_variable_assignments(x.variables());
204 data::make_forall(result, v1, body);
211 variable_list v1 = sigma.add_fresh_variable_assignments(x.variables());
214 data::make_exists(result, v1, body);
221 variable_list v1 = sigma.add_fresh_variable_assignments(x.variables());
224 data::make_lambda(result, v1, body);
231 throw mcrl2::runtime_error(
"not implemented yet");
242template <
typename T,
data::IsSubstitution Substitution>
257template <
typename T,
data::IsSubstitution Substitution>
A unordered_map class in which aterms can be stored.
const variable_list & variables() const
const data_expression & body() const
\brief Assignment expression
\brief Assignment of a data expression to a variable
const variable & lhs() const
basic_sort(const atermpp::aterm &term)
const container_type & container_name() const
const sort_expression & element_sort() const
container_sort(const atermpp::aterm &term)
data_specification(const basic_sort_vector &sorts, const alias_vector &aliases, const function_symbol_vector &constructors, const function_symbol_vector &user_defined_mappings, const data_equation_vector &user_defined_equations)
Constructor from its members.
bool is_well_typed() const
Returns true if.
bool is_certainly_finite(const sort_expression &s) const
Checks whether a sort is certainly finite.
existential quantification.
bool is_finite(const container_sort &s)
bool is_finite(const basic_sort &s)
bool is_finite_aux(const sort_expression &s)
bool is_finite(const sort_expression &s)
std::set< sort_expression > m_visiting
bool is_finite(const alias &)
bool is_finite(const function_sort &s)
const data_specification & m_specification
finiteness_helper(const data_specification &specification)
bool is_finite(const structured_sort &s)
universal quantification.
\brief Container type for finite sets
fset_container()
\brief Default constructor X3.
const sort_expression & codomain() const
function_sort(const atermpp::aterm &term)
const sort_expression_list & domain() const
function_symbol(const core::identifier_string &name, const sort_expression &sort)
Constructor.
const core::identifier_string & name() const
const sort_expression & sort() const
\brief Container type for sets
set_container()
\brief Default constructor X3.
Identifier generator that stores the identifiers of the context in a set. Using the operator()() and ...
sort_expression & operator=(const sort_expression &) noexcept=default
sort_expression(const sort_expression &) noexcept=default
Move semantics.
void add_system_defined_sort(const sort_expression &s)
Adds a sort to this specification, and marks it as system defined.
void add_predefined_basic_sorts()
void sorts_are_not_necessarily_normalised_anymore() const
void reconstruct_m_normalised_aliases() const
void import_system_defined_sort(const sort_expression &sort)
Adds the system defined sorts in a sequence. The second argument is used to check which sorts are add...
structured_sort(const atermpp::aterm &term)
const core::identifier_string & name() const
const sort_expression & sort() const
\brief A where expression
const data_expression & body() const
const assignment_expression_list & declarations() const
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
aterm identity(const aterm &x)
The default transformer that maps each term to itself.
std::string file_source(const std::string &filename)
atermpp::aterm load_aterm(std::istream &stream, bool binary=true, const std::string &format="aterm", const std::string &source="", atermpp::aterm_transformer transformer=atermpp::identity)
Attempts to read an aterm from a stream.
bool check_variable_sorts(const VariableContainer &variables, const SortContainer &sorts)
Returns true if the domain sorts and the range sort of the given variables are contained in sorts.
atermpp::aterm add_index(const atermpp::aterm &x)
bool check_variable_names(variable_list const &variables, const std::set< core::identifier_string > &names)
Returns true if names of the given variables are not contained in names.
atermpp::aterm remove_index(const atermpp::aterm &x)
atermpp::aterm remove_index_impl(const atermpp::aterm &x)
replace_capture_avoiding_variables_builder< Builder, Binder, Substitution > apply_replace_capture_avoiding_variables_builder(capture_avoiding_substitution_updater< Substitution > &sigma)
bool check_assignment_variables(assignment_list const &assignments, variable_list const &variables)
Returns true if the left hand sides of assignments are contained in variables.
bool check_sort(const sort_expression &s, const SortContainer &sorts)
Returns true if the domain sorts and the codomain sort of the given sort s are contained in sorts.
bool check_data_spec_sorts(const Container &container, const SortContainer &sorts)
Returns true if the domain sorts and range sort of the given functions are contained in sorts.
data::sort_expression_list parameter_sorts(const Container ¶meters)
Returns the sorts of a sequence of parameters.
std::ostream & operator<<(std::ostream &out, const capture_avoiding_substitution_updater< Substitution > &sigma)
atermpp::aterm add_index_impl(const atermpp::aterm &x)
bool check_sorts(Iterator first, Iterator last, const SortContainer &sorts)
Returns true if the domain sorts and the range sort of the sorts in the sequence [first,...
bool unique_names(const VariableContainer &variables)
Returns true if the names of the given variables are unique.
Namespace for system defined sort bag.
bool is_bag(const sort_expression &e)
Recogniser for sort expression Bag(s)
Namespace for system defined sort bool_.
const basic_sort & bool_()
Constructor for sort expression Bool.
Namespace for system defined sort fbag.
container_sort fbag(const sort_expression &s)
Constructor for sort expression FBag(S)
bool is_fbag(const sort_expression &e)
Recogniser for sort expression FBag(s)
Namespace for system defined sort fset.
bool is_fset(const sort_expression &e)
Recogniser for sort expression FSet(s)
container_sort fset(const sort_expression &s)
Constructor for sort expression FSet(S)
Namespace for system defined sort int_.
const basic_sort & int_()
Constructor for sort expression Int.
Namespace for system defined sort list.
bool is_list(const sort_expression &e)
Recogniser for sort expression List(s)
Namespace for system defined sort nat.
const basic_sort & nat()
Constructor for sort expression Nat.
const basic_sort & natpair()
Constructor for sort expression @NatPair.
Namespace for system defined sort pos.
const basic_sort & pos()
Constructor for sort expression Pos.
Namespace for system defined sort real_.
const basic_sort & real_()
Constructor for sort expression Real.
Namespace for system defined sort set_.
bool is_set(const sort_expression &e)
Recogniser for sort expression Set(s)
container_sort set_(const sort_expression &s)
Constructor for sort expression Set(S)
bool is_structured_sort(const atermpp::aterm &x)
Returns true if the term t is a structured sort.
static sort_expression find_normal_form(const sort_expression &e, const std::multimap< sort_expression, sort_expression > &map1, std::set< sort_expression > sorts_already_seen=std::set< sort_expression >())
void replace_variables_capture_avoiding(T &x, Substitution &sigma, data::set_identifier_generator &id_generator)
void replace_sort_expressions(T &x, const Substitution &sigma, bool innermost)
bool is_untyped_possible_sorts(const atermpp::aterm &x)
Returns true if the term t is an expression for multiple possible sorts.
T replace_variables_capture_avoiding(const T &x, Substitution &sigma, data::set_identifier_generator &id_generator)
bool is_untyped_sort(const atermpp::aterm &x)
Returns true if the term t is the unknown sort.
std::set< data::variable > substitution_variables(const Substitution &)
Returns the variables appearing in the right hand sides of the substitution.
T replace_sort_expressions(const T &x, const Substitution &sigma, bool innermost)
void register_function_symbol_hooks()
bool is_container_sort(const atermpp::aterm &x)
Returns true if the term t is a container sort.
bool is_basic_sort(const atermpp::aterm &x)
Returns true if the term t is a basic sort.
void on_delete_function_symbol(const atermpp::aterm &t)
bool is_function_sort(const atermpp::aterm &x)
Returns true if the term t is a function sort.
void apply(atermpp::term_list< T > &result, const assignment_list &x)
void apply(T &result, const data::exists &x)
void apply(T &result, const variable &v)
void apply(T &result, const data::lambda &x)
capture_avoiding_substitution_updater< Substitution > & sigma
void apply(T &, data_equation &)
void apply(T &result, const data::forall &x)
void apply(T &result, const data::where_clause &x)
add_capture_avoiding_replacement(capture_avoiding_substitution_updater< Substitution > &sigma_)
void remove_fresh_variable_assignments(const VariableContainer &variables)
data::set_identifier_generator & id_generator
variable add_fresh_variable_assignment(const variable &v)
data_expression operator()(const variable &x)
capture_avoiding_substitution_updater(Substitution &sigma_, data::set_identifier_generator &id_generator_)
variable_list add_fresh_variable_assignments(const VariableContainer &variables)
void remove_fresh_variable_assignment(const variable &v)
replace_capture_avoiding_variables_builder(capture_avoiding_substitution_updater< Substitution > &sigma)