12#ifndef MCRL2_LPS_LPSPARUNFOLDLIB_H
14#define MCRL2_LPS_LPSPARUNFOLDLIB_H
36 std::map<mcrl2::data::sort_expression, mcrl2::data::function_symbol>
case_functions;
60 std::map<data::sort_expression, std::size_t> used_arguments;
66 if(used_arguments.find(arg_sort) == used_arguments.end())
68 used_arguments[arg_sort] = 0;
72 if(
m_variables[arg_sort].size() == used_arguments[arg_sort])
78 result.push_back(
m_variables[arg_sort].at(used_arguments[arg_sort]));
79 ++used_arguments[arg_sort];
87 std::map<data::sort_expression, data::variable_vector>
m_variables;
95 std::map< mcrl2::data::sort_expression , unfold_cache_element >&
m_cache;
162 args.push_back(first_arg);
259 return c==
' ' || c==
':' || c==
',' || c==
'|'
260 || c==
'>' || c==
'[' || c==
']' || c==
'@'
261 || c==
'.' || c==
'{' || c==
'}' || c==
'#'
262 || c==
'%' || c==
'&' || c==
'*' || c==
'!'
282 std::map<data::function_symbol, data::data_equation>
m_new_eqns;
292 result.push_back(eqn);
304 return find_result->second;
307 bool result = std::all_of(eqns.begin(), eqns.end(),
308 [&](
auto& eqn) { return data::is_pattern_matching_rule(m_datamgr, eqn); });
319 new_eqn = find_result->second;
327 std::map<data::variable, data::data_expression>
sigma;
328 auto it1 = atermpp::down_cast<data::application>(new_eqn.
lhs()).begin();
329 auto it2 = args.begin();
330 while (it2 != args.end())
332 sigma[atermpp::down_cast<data::variable>(*it1++)] = *it2++;
392 if (std::find_if(udm.begin(), udm.end(),
393 [&](
const auto& f2){ return f.name() == f2.name() && dataspec.equal_sorts(f.sort(), f2.sort()); }) == udm.end())
407 std::vector<std::size_t> result;
414 std::size_t f_num_args = atermpp::down_cast<data::function_sort>(f.
sort()).domain().size();
415 for (std::size_t arg = 0; arg < f_num_args; arg++)
419 const data::application& lhs_appl = atermpp::down_cast<data::application>(eq.lhs());
422 result.push_back(arg);
462 template <
template <
class>
class Builder>
465 typedef Builder<replace_pattern_match_builder<Builder> >
super;
483 for(
const std::size_t i: pattern_matching_args)
509 super::apply(branch1, x[1]);
511 super::apply(branch2, x[2]);
526 super::apply(result, intermediate_result);
531 super::apply(result, x);
541 m_unfolder(intermediate_result1, atermpp::down_cast<data::application>(x[0]));
545 super::apply(intermediate_result2, intermediate_result1);
548 mCRL2log(
log::debug) <<
"Unfolded " << x[0] <<
" into " << intermediate_result2 << std::endl;
554 super::apply(result, x);
589 std::map< data::sort_expression , unfold_cache_element >& cache,
590 bool alt_case_placement =
false,
591 bool possibly_inconsistent =
false,
592 bool unfold_pattern_matching =
true);
599 void algorithm(
const std::size_t parameter_at_index);
658 std::size_t parameter_at_index);
665template <
template <
class>
class Builder,
template <
template <
class>
class,
class,
class>
class Binder>
667Binder<Builder, parunfold_replacement<Builder, Binder>, parunfold_replacement<Builder, Binder>>
682 , sigma1(*this, id_generator)
684 this->case_funcs = case_funcs;
690 if (current_replacement !=
data::data_expression() || data::is_and(x) || data::is_or(x) || data::is_not(x) || data::is_imp(x) || data::is_if_application(x))
693 super::apply(result, x);
698 apply_case_function(result, x);
704 auto& [par, case_f, det_f, replacements] = case_funcs;
706 if (data::find_free_variables(expr).count(par) == 0)
711 super::apply(result, expr);
716 args.push_back(det_f);
720 current_replacement = r;
722 super::apply(arg, expr);
727 if (case_f.find(expr.
sort()) == case_f.end())
730 data::pp(expr.
sort()) +
" not declared.");
743 if (std::get<0>(case_funcs) != x)
747 return current_replacement;
751template <
template <
class>
class Builder,
template <
template <
class>
class,
class,
class>
class Binder>
752parunfold_replacement<Builder, Binder>
763 typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* =
nullptr
766 apply_parunfold_replacement_builder<lps::data_expression_builder, lps::detail::add_capture_avoiding_replacement>(cfv, id_generator).update(x);
772 typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* =
nullptr
777 auto& [par, case_f, det_f, replacements] = cfv;
780 id_generator.
add_identifier(case_f.find(par.sort())->second.name());
Term containing a string.
const_iterator begin() const
Returns an iterator pointing to the first argument.
const_iterator end() const
Returns a const_iterator pointing to the end of the term_list.
const_iterator begin() const
Returns a const_iterator pointing to the beginning of the term_list.
An application of a data expression to a number of arguments.
const_iterator end() const
Returns an iterator pointing past the last argument of the application.
const_iterator begin() const
Returns an iterator pointing to the first argument of the application.
const data_expression & head() const
Get the function at the head of this expression.
const data_expression & lhs() const
const data_expression & rhs() const
sort_expression sort() const
Returns the sort of the data expression.
const_iterator end() const
const_iterator begin() const
const std::set< data_equation > & equations() const
Gets all equations in this specification including those that are system defined.
const function_symbol_vector & constructors() const
Gets all constructors including those that are system defined.
const function_symbol_vector & mappings() const
Gets all mappings in this specification including those that are system defined.
const sort_expression & sort() const
Abstract base class for identifier generators. Identifier generators generate fresh names that do not...
void add_identifiers(const std::set< core::identifier_string > &ids)
Add a set of identifiers to the context.
Components for generating an arbitrary element of a sort.
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.
const sort_expression & target_sort() const
Returns the target sort of this expression.
Fresh variable generator for the arguments of a function symbol.
data::set_identifier_generator & m_identifier_generator
std::map< data::sort_expression, data::variable_vector > m_variables
data::variable_vector arguments(const data::function_symbol &f)
Generate argument variables for f.
data_equation_argument_generator(data::set_identifier_generator &identifier_generator)
Algorithm class for algorithms on linear process specifications. It can be instantiated with lps::spe...
Class for unfolding expressions f(a1,...,an) based on the pattern-matching rewrite rules that define ...
std::map< data::function_symbol, bool > m_is_pattern_matching
bool matches_only_known_sorts(const data::function_symbol &f)
Determines whether f pattern matches on argument arg.
bool is_det_or_pi(const data::application &expr) const
Checks whether expr is of the shape Det(h(a1,...,an)) or pi(h(a1,...,an)), where h is defined by patt...
void operator()(T &result, const data::application &x)
Unfolds expr if it is of the shape h(a1,...,an) and h is defined by pattern matching.
pattern_match_unfolder(unfold_data_manager &datamgr)
data::data_expression unfolded_expr(const data::function_symbol &f, const data::data_expression_vector &args)
bool is_pattern_matching(const data::function_symbol &f)
Checks whether f is defined by pattern matching.
bool is_constructor(const data::function_symbol &f)
data::representative_generator m_repgen
std::vector< std::size_t > pattern_matching_args(const data::function_symbol &f)
std::map< data::function_symbol, data::data_equation > m_new_eqns
bool can_unfold(const data::data_expression &x)
unfold_data_manager & m_datamgr
const data::data_equation_vector find_equations(const data::function_symbol &f)
Finds all rewriting equations for f.
void add_used_identifier(const core::identifier_string &id)
data::data_specification & m_dataspec
bool m_possibly_inconsistent
Boolean indicating whether rewrite rules may be added that could make the data specification inconsis...
mcrl2::data::set_identifier_generator m_identifier_generator
set of identifiers to use during fresh variable generation
void create_determine_function(const data::sort_expression &sort)
Creates the determine function.
void add_used_identifiers(const std::set< core::identifier_string > &ids)
bool is_constructor(const data::function_symbol &f) const
unfold_cache_element & get_cache_element(const data::sort_expression &sort)
mcrl2::core::identifier_string generate_fresh_function_symbol_name(const std::string &str)
Generates a fresh name for a constructor or mapping.
void generate_case_function_equations(const data::sort_expression &sort, const data::function_symbol &case_function)
Create the data equations for case functions.
const data::data_specification & dataspec() const
data::set_identifier_generator & id_gen()
void generate_determine_function_equations(const data::sort_expression &sort)
Create the data equations for the determine function.
void generate_projection_function_equations(const data::sort_expression &sort)
Create the data equations for the projection functions.
void create_new_constructors(const data::sort_expression &sort)
Creates a set of constructors for the fresh basic sort.
std::map< mcrl2::data::sort_expression, unfold_cache_element > & m_cache
cache for previously unfolded sorts. facilitates reuse of previously introduced sorts and function sy...
std::string filter_illegal_characters(std::string in) const
mcrl2::data::variable generate_fresh_variable(std::string str, const data::sort_expression &sort)
Generates variable of type sort based on a given string str.
mcrl2::data::representative_generator m_representative_generator
a generator for default data expressions of a given sort;
mcrl2::data::basic_sort generate_fresh_basic_sort(const data::sort_expression &sort)
Generates a fresh basic sort given a sort expression.
const data::function_symbol_vector & get_projection_funcs(const data::function_symbol &f)
data::function_symbol create_case_function(const data::sort_expression &det_sort, const data::sort_expression &output_sort)
Creates the case function with number of arguments determined by the number of affected constructors,...
void create_distribution_law_over_case(const data::sort_expression &sort, const data::function_symbol &function_for_distribution, const data::function_symbol case_function)
Create distribution rules for distribution_functions over case_functions.
data::data_expression create_cases(const data::data_expression &target, const data::data_expression_vector &rhss)
unfold_data_manager(std::map< mcrl2::data::sort_expression, unfold_cache_element > &cache, data::data_specification &dataspec, bool possibly_inconsistent)
static bool char_filter(char c)
detail::data_equation_argument_generator m_data_equation_argument_generator
generator for arguments in left hand side of data equations
bool is_cached(const data::sort_expression &sort) const
const std::vector< data::function_symbol > & get_constructors(const data::sort_expression &sort)
void create_projection_functions(const data::sort_expression &sort)
Creates projection functions for the unfolded process parameter.
void determine_affected_constructors(const data::sort_expression &sort)
Determines the constructors that are affected with the unfold process parameter.
std::map< mcrl2::data::variable, mcrl2::data::data_expression > parameter_substitution()
substitute function for replacing process parameters with unfolded process parameters functions.
void update_linear_process(std::size_t parameter_at_index)
substitute unfold process parameter in the linear process
std::tuple< data::variable, std::map< data::sort_expression, data::function_symbol >, data::variable, data::data_expression_vector > case_func_replacement
void update_linear_process_initialization(std::size_t parameter_at_index)
substitute unfold process parameter in the initialization of the linear process
detail::pattern_match_unfolder m_pattern_unfolder
mcrl2::data::variable process_parameter_at(const std::size_t index)
Get the process parameter at given index.
detail::lps_algorithm< lps::stochastic_specification > super
bool m_alt_case_placement
Boolean to indicate if alternative placement of case functions should be used.
void algorithm(const std::size_t parameter_at_index)
Applies lpsparunfold algorithm on a process parameter of an mCRL2 process specification .
case_func_replacement parameter_case_function()
bool m_run_before
set to true when the algorithm has been run once; as the algorithm should run only once....
bool m_unfold_pattern_matching
Indicates whether functions defined by pattern matching that occur in the scope of a Det or pi in a s...
mcrl2::data::data_expression_vector unfold_constructor(const mcrl2::data::data_expression &de)
unfolds a data expression into a vector of process parameters
void unfold_summands(mcrl2::lps::stochastic_action_summand_vector &summands)
detail::unfold_data_manager m_datamgr
Bookkeeper for recogniser and projection functions.
data::data_expression apply_function(const data::function_symbol &f, const data::data_expression &de) const
mcrl2::data::variable m_unfold_parameter
The process parameter that needs to be unfold.
mcrl2::data::variable_vector m_injected_parameters
The process parameters that are inserted.
Linear process specification.
Standard exception class for reporting runtime errors.
This file contains some functions that are present in all libraries except the data library....
static RewriterCompilingJitty::substitution_type & sigma(RewriterCompilingJitty *this_rewriter)
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
add your file description here.
Add your file description here.
function_symbol get_top_fs(const data_expression &expr)
Get the top level function symbol f if expr is of the shape f or f(t1,...,tn)
void find_identifiers(const T &x, OutputIterator o)
std::vector< sort_expression > sort_expression_vector
\brief vector of sort_expressions
bool is_if_application(const DataExpression &e)
Recogniser for application of if.
void replace_all_variables(T &x, const Substitution &sigma, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
std::vector< data_equation > data_equation_vector
\brief vector of data_equations
std::vector< variable > variable_vector
\brief vector of variables
std::vector< data_expression > data_expression_vector
\brief vector of data_expressions
bool is_function_sort(const atermpp::aterm &x)
Returns true if the term t is a function sort.
bool is_application(const atermpp::aterm &x)
Returns true if the term t is an application.
std::vector< function_symbol > function_symbol_vector
\brief vector of function_symbols
function_symbol if_(const sort_expression &s)
Constructor for function symbol if.
data_equation unfold_pattern_matching(const function_symbol &mapping, const data_equation_vector &rewrite_rules, StructInfo &ssf, representative_generator &gen, set_identifier_generator &id_gen)
This converts a collection of rewrite rules for a give function symbol into a one-rule specification ...
bool is_variable(const atermpp::aterm &x)
Returns true if the term t is a variable.
void make_application(atermpp::aterm &result)
Make function for an application.
The main namespace for the LPS library.
std::vector< stochastic_action_summand > stochastic_action_summand_vector
\brief vector of stochastic_action_summands
void insert_case_functions(T &x, const lpsparunfold::case_func_replacement &cfv, data::set_identifier_generator &id_generator, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
void find_identifiers(const T &x, OutputIterator o)
parunfold_replacement< Builder, Binder > apply_parunfold_replacement_builder(const lpsparunfold::case_func_replacement &case_funcs, data::set_identifier_generator &id_generator)
bool contains(const atermpp::indexed_set< Key, ThreadSafe, Hash, Equals, Allocator, KeyTable > &c, const typename atermpp::indexed_set< Key, ThreadSafe, Hash, Equals, Allocator, KeyTable >::key_type &v, const std::size_t thread_index=0)
Component for generating representatives of sorts.
Generic substitution function. The substitution is stored as a mapping of variables to expressions.
Builder< replace_pattern_match_builder< Builder > > super
void apply(T &result, const data::application &x)
pattern_match_unfolder & m_unfolder
bool is_applied_to_constructor(const data::application &x)
std::size_t m_current_depth
replace_pattern_match_builder(pattern_match_unfolder &unfolder)
bool m_currently_recursing
data::data_expression current_replacement
data::detail::capture_avoiding_substitution_updater< parunfold_replacement< Builder, Binder > > sigma1
data::data_expression operator()(const data::variable &x)
parunfold_replacement(const lpsparunfold::case_func_replacement &case_funcs, data::set_identifier_generator &id_generator)
Binder< Builder, parunfold_replacement< Builder, Binder >, parunfold_replacement< Builder, Binder > > super
void apply(T &result, const data::application &x)
void apply_case_function(data::data_expression &result, const data::application &expr)
lpsparunfold::case_func_replacement case_funcs
Element in the cache that keeps track of the information for a single unfolded sort,...
std::map< mcrl2::data::sort_expression, mcrl2::data::function_symbol > case_functions
mcrl2::data::basic_sort fresh_basic_sort
mcrl2::data::function_symbol_vector affected_constructors
mcrl2::data::function_symbol determine_function
mcrl2::data::function_symbol_vector projection_functions
mcrl2::data::function_symbol_vector new_constructors
mcrl2::core::identifier_string case_function_name