12#ifndef MCRL2_LPS_ACTION_RENAME_H
13#define MCRL2_LPS_ACTION_RENAME_H
88 m_variables = atermpp::down_cast<data::variable_list>(*i++);
181 m_action_labels = atermpp::down_cast<process::action_label_list>((*i++)[0]);
197 const std::vector <action_rename_rule>&
rules)
233 const std::vector<action_rename_rule>&
rules()
const
239 std::vector<action_rename_rule>&
rules()
261 std::vector<atermpp::aterm> rules;
287inline void fill_replacement_map(
const data::data_expression& equalities_in_conjunction,
288 std::map<data::data_expression, data::data_expression>& replacement_map)
302 const data::application a=atermpp::down_cast<data::application>(equalities_in_conjunction);
305 replacement_map[a[1]]=a[0];
312inline data::data_expression replace_expressions(
const data::data_expression& e,
313 const std::map<data::data_expression, data::data_expression>& replacement_map)
326 const data::application a=atermpp::down_cast<data::application>(e);
327 return data::application(a.head(),
328 replace_expressions(a[0],replacement_map),
329 replace_expressions(a[1],replacement_map));
331 const std::map<data::data_expression, data::data_expression>::const_iterator i=replacement_map.find(e);
332 if (i!=replacement_map.end())
340inline data::data_expression substitute_equalities(
const data::data_expression& e,
const data::data_expression& equalities_in_conjunction)
342 std::map<data::data_expression, data::data_expression> replacement_map;
343 fill_replacement_map(equalities_in_conjunction, replacement_map);
344 return replace_expressions(e,replacement_map);
352template <
typename IdentifierGenerator>
353void rename_renamerule_variables(data::data_expression& rcond, process::action& rleft, process::action& rright, IdentifierGenerator& generator)
355 data::mutable_map_substitution<> renamings;
359 for (
const data::variable& v: new_vars)
363 if (new_name != v.name())
365 renamings[v] = data::variable(new_name, v.sort());
369 data::set_identifier_generator id_generator;
372 id_generator.add_identifier(v.name());
386 for (action_rename_rule& rule: arspec.rules())
401 for (action_rename_rule& rule: arspec.rules())
403 rule = action_rename_rule(rule.variables(),
432 const bool enable_rewriting)
438 const std::vector <action_rename_rule>& rename_rules = action_rename_spec.
rules();
457 if (!is_tau(new_element) && !is_delta(new_element))
459 rule_new_action = atermpp::down_cast<process::action>(new_element);
462 const bool to_tau = is_tau(new_element);
463 const bool to_delta = is_delta(new_element);
477 if (!is_variable(rule_old_argument_i) &&
481 " are not variables or closed expressions");
489 if (!includes(variables_in_old_rule.begin(),variables_in_old_rule.end(),
490 variables_in_new_rule.begin(),variables_in_new_rule.end()))
493 " of a rename rule not occurring in lhs " +
process::pp(rule_old_action));
498 if (!includes(variables_in_old_rule.begin(),variables_in_old_rule.end(),
499 variables_in_condition.begin(),variables_in_condition.end()))
502 " of a rename rule not occurring in lhs " +
process::pp(rule_old_action));
511 const variable& v = atermpp::down_cast<variable>(d);
512 if (variables_in_old_rule.find(v)==variables_in_old_rule.end())
515 process::pp(rule_old_action) +
" of an action rename rule");
519 variables_in_old_rule.erase(v);
523 assert(variables_in_old_rule.empty());
527 mCRL2log(
log::debug) <<
"Action summands found: " << lps_old_action_summands.size() <<
"\n";
538 std::vector < variable_list >
539 lps_new_sum_vars(1,lps_old_action_summand.summation_variables());
540 std::vector < data_expression > lps_new_condition(1,lps_old_action_summand.condition());
541 std::vector < process::action_list >
543 std::vector < bool > lps_new_actions_is_delta(1,
false);
548 if (equal_signatures(lps_old_action, rule_old_action))
556 detail::rename_renamerule_variables(renamed_rule_condition, renamed_rule_old_action, renamed_rule_new_action, generator);
563 if (is_variable(rule_old_argument_i))
565 new_equalities_condition=lazy::and_(new_equalities_condition,
571 renamed_rule_condition=
572 lazy::and_(renamed_rule_condition,
574 if (enable_rewriting) renamed_rule_condition=rewr(renamed_rule_condition);
576 lps_old_argument_i++;
582 d=lazy::and_(d,new_equalities_condition);
587 for (
const variable& sdvi: new_vars)
595 if (enable_rewriting) renamed_rule_condition=rewr(renamed_rule_condition);
596 if (renamed_rule_condition==sort_bool::true_())
600 std::vector < bool >::iterator i_is_delta=lps_new_actions_is_delta.begin();
610 std::vector < bool >::iterator i_is_delta=lps_new_actions_is_delta.begin();
615 l.push_front(renamed_rule_new_action);
621 else if (renamed_rule_condition==sort_bool::false_())
623 std::vector < bool >::iterator i_is_delta=lps_new_actions_is_delta.begin();
628 l.push_front(lps_old_action);
639 std::vector < process::action_list > lps_new_actions_temp(lps_new_actions);
643 std::vector < bool >::iterator i_is_delta=lps_new_actions_is_delta.begin();
653 l.push_front(renamed_rule_new_action);
662 lps_new_actions_is_delta.push_back(
false);
663 l.push_front(lps_old_action);
666 lps_new_actions.insert(lps_new_actions.end(),
667 lps_new_actions_temp.begin(),
668 lps_new_actions_temp.end());
669 assert(lps_new_actions_is_delta.size()==lps_new_actions.size());
675 std::vector < data_expression > lps_new_condition_temp(lps_new_condition);
680 d=lazy::and_(renamed_rule_condition,detail::substitute_equalities(d,renamed_rule_condition));
686 lps_new_condition.push_back(lazy::and_(d,sort_bool::not_(renamed_rule_condition)));
691 std::size_t size=lps_new_sum_vars.size();
692 lps_new_sum_vars.reserve(2*size);
693 for(std::size_t i=0; i<size; ++i)
695 lps_new_sum_vars.push_back(lps_new_sum_vars[i]);
703 l.push_front(lps_old_action);
712 std::vector < process::action_list > :: iterator i_act=lps_new_actions.begin();
713 std::vector < bool > :: iterator i_act_is_delta=lps_new_actions_is_delta.begin();
714 std::vector < variable_list > :: iterator i_sumvars=lps_new_sum_vars.begin();
723 deadlock(lps_old_action_summand.multi_action().time()));
724 lps_deadlock_summands.push_back(d);
731 multi_action(reverse(*i_act), lps_old_action_summand.multi_action().time()),
732 lps_old_action_summand.assignments(),
733 lps_old_action_summand.distribution());
734 lps_new_action_summands.push_back(lps_new_summand);
741 lps_old_action_summands = lps_new_action_summands;
747 lps_deadlock_summands,
748 lps_old_action_summands);
788 const std::regex& matching_regex,
789 const std::string& replacing_fmt,
793 std::set<process::action_label> new_actions_set;
798 if (std::string(new_action_label.
name()).empty())
800 throw mcrl2::runtime_error(
"After renaming the action " + std::string(
act.name()) +
" becomes empty, which is not allowed.");
802 if(std::string(new_action_label.
name()) !=
"delta" && std::string(new_action_label.
name()) !=
"tau" &&
803 new_actions_set.find(new_action_label) == new_actions_set.end())
806 new_actions_set.insert(new_action_label);
810 new_actions = reverse(new_actions);
813 std::vector<stochastic_action_summand> new_action_summands;
819 bool becomes_deadlock_summand =
false;
823 if(std::string(new_action_label.
name()) ==
"delta")
827 becomes_deadlock_summand =
true;
832 if(std::string(new_action_label.
name()) !=
"tau")
838 if(!becomes_deadlock_summand)
840 new_action_list = reverse(new_action_list);
841 multi_action new_multi_action(new_action_list, as.multi_action().time());
844 stochastic_action_summand new_summand(as.summation_variables(), as.condition(), new_multi_action, as.assignments(), as.distribution());
845 new_action_summands.push_back(new_summand);
850 new_deadlock_summands.push_back(
deadlock_summand(as.summation_variables(), as.condition(),
deadlock(as.multi_action().time())));
855 new_deadlock_summands,
856 new_action_summands);
878 return out <<
"(" << r.
condition() <<
") -> " << r.
lhs() <<
" => " << r.
rhs();
Term containing a string.
const_iterator begin() const
Returns an iterator pointing to the first argument.
size_type size() const
Returns the size of the term_list.
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.
void push_front(const Term &el)
Inserts a new element at the beginning of the current list.
void add_identifiers(const std::set< core::identifier_string > &ids)
Add a set of identifiers to the context.
Rewriter that operates on data expressions.
Identifier generator that stores the identifiers of the context in a set. Using the operator()() and ...
action_rename_rule()
Constructor.
const data::data_expression & condition() const
Returns the condition of the rule.
const process::process_expression & rhs() const
Returns the right hand side of the rule.
data::data_expression & condition()
Returns the condition of the rule.
action_rename_rule(const data::variable_list &variables, const data::data_expression &condition, const process::action &lhs, const process::process_expression &rhs)
Constructor.
process::process_expression m_rhs
right hand side of the rule. Can only be an action, tau or delta.
data::variable_list m_variables
The data variables of the rule.
bool check_that_rhs_is_tau_delta_or_an_action() const
data::variable_list & variables()
Returns the variables of the rule.
process::action m_lhs
The left hand side of the rule.
action_rename_rule(const atermpp::aterm &t)
Constructor.
data::data_expression m_condition
The condition of the rule.
const data::variable_list & variables() const
Returns the variables of the rule.
const process::action & lhs() const
Returns the left hand side of the rule.
Read-only singly linked list of action rename rules.
action_rename_specification()
Constructor.
const std::vector< action_rename_rule > & rules() const
Returns the action rename rules.
data::data_specification m_data
The data specification of the action rename specification.
process::action_label_list & action_labels()
Returns the sequence of action labels.
std::vector< action_rename_rule > m_rules
The action rename rules of the action rename specification.
action_rename_specification(const data::data_specification &data, const process::action_label_list &action_labels, const std::vector< action_rename_rule > &rules)
Constructor.
std::vector< action_rename_rule > & rules()
Returns the action rename rules.
data::data_specification & data()
Returns the data specification.
process::action_label_list m_action_labels
The action labels of the action rename specification.
const data::data_specification & data() const
Returns the data action_rename_specification.
const process::action_label_list & action_labels() const
Returns the sequence of action labels.
action_rename_specification(atermpp::aterm t)
Constructor.
bool is_well_typed() const
Indicates whether the action_rename_specification is well typed.
LPS summand containing a deadlock.
const std::vector< ActionSummand > & action_summands() const
Returns the sequence of action summands.
const deadlock_summand_vector & deadlock_summands() const
Returns the sequence of deadlock summands.
const data::variable_list & process_parameters() const
Returns the sequence of process parameters.
\brief A timed multi-action
const std::set< data::variable > & global_variables() const
Returns the declared free variables of the LPS.
const process::action_label_list & action_labels() const
Returns a sequence of action labels. This sequence contains all action labels occurring in the specif...
const InitialProcessExpression & initial_process() const
Returns the initial process.
const LinearProcess & process() const
Returns the linear process of the specification.
const data::data_specification & data() const
Returns the data specification.
LPS summand containing a multi-action.
Linear process specification.
const core::identifier_string & name() const
const data::data_expression_list & arguments() const
\brief A process expression
Standard exception class for reporting runtime errors.
Parse mCRL2 specifications and expressions.
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
add your file description here.
bool check_rule_ActionRenameSpec(const Term &t)
const atermpp::function_symbol & function_symbol_ActionRenameRule()
bool check_rule_ActionRenameRule(const Term &t)
const atermpp::function_symbol & function_symbol_ActionRenameRules()
const atermpp::function_symbol & function_symbol_ActSpec()
const atermpp::function_symbol & function_symbol_ActionRenameSpec()
atermpp::aterm data_specification_to_aterm(const data_specification &s)
const data_expression & arg(const data_expression &e)
Function for projecting out argument. arg from an application.
const data_expression & right(const data_expression &e)
Function for projecting out argument. right from an application.
const function_symbol & and_()
Constructor for function symbol &&.
bool is_and_application(const atermpp::aterm &e)
Recogniser for application of &&.
bool is_not_application(const atermpp::aterm &e)
Recogniser for application of !.
const function_symbol & not_()
Constructor for function symbol !.
const function_symbol & true_()
Constructor for function symbol true.
const data_expression & left(const data_expression &e)
Function for projecting out argument. left from an application.
Namespace for all data library functionality.
data::data_equation translate_user_notation(const data::data_equation &x)
std::set< data::variable > find_all_variables(const data::data_expression &x)
std::set< data::variable > substitution_variables(const Substitution &)
Returns the variables appearing in the right hand sides of the substitution.
std::string pp(const abstraction &x)
std::set< data::variable > find_free_variables(const data::data_expression &x)
std::set< core::identifier_string > function_and_mapping_identifiers(const data_specification &dataspec)
Returns the names of functions and mappings that occur in a data specification.
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)
data_expression normalize_sorts(const data_expression &x, const data::sort_specification &sortspec)
function_symbol equal_to(const sort_expression &s)
Constructor for function symbol ==.
bool is_equal_to_application(const DataExpression &e)
Recogniser for application of ==.
process::action_label rename_action_label(const process::action_label &act, const std::regex &matching_regex, const std::string &replacing_fmt)
The main namespace for the LPS library.
std::vector< stochastic_action_summand > stochastic_action_summand_vector
\brief vector of stochastic_action_summands
std::vector< deadlock_summand > deadlock_summand_vector
\brief vector of deadlock_summands
lps::stochastic_specification action_rename(const action_rename_specification &action_rename_spec, const lps::stochastic_specification &lps_old_spec, const data::rewriter &rewr, const bool enable_rewriting)
Rename the actions in a linear specification using a given action_rename_spec.
void find_identifiers(const T &x, OutputIterator o)
atermpp::aterm action_rename_specification_to_aterm(const action_rename_specification &spec)
atermpp::aterm action_rename_rule_to_aterm(const action_rename_rule &rule)
std::set< data::variable > find_all_variables(const lps::deadlock &x)
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)
action_label_list normalize_sorts(const action_label_list &x, const data::sort_specification &sortspec)
bool is_action(const atermpp::aterm &x)
std::string pp(const action_label &x)
atermpp::term_list< action > action_list
\brief list of actions
void find_free_variables(const T &x, OutputIterator o)
action translate_user_notation(const action &x)
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
std::ostream & operator<<(std::ostream &out, const mcrl2::lps::action_rename_rule &r)
Output an action_rename_rule to ostream.
add your file description here.
add your file description here.
add your file description here.