12#ifndef MCRL2_DATA_REWRITERS_ONE_POINT_RULE_REWRITER_H
13#define MCRL2_DATA_REWRITERS_ONE_POINT_RULE_REWRITER_H
15#include "mcrl2/data/equality_one_point_substitution.h"
16#include "mcrl2/data/expression_traits.h"
17#include "mcrl2/data/find_equalities.h"
18#include "mcrl2/data/optimized_boolean_operators.h"
19#include "mcrl2/data/replace.h"
20#include "mcrl2/data/substitutions/mutable_map_substitution.h"
28template <
typename Derived>
38 return static_cast<Derived&>(*
this);
46 std::vector<variable> variables;
48 std::map<variable, std::set<data_expression> > inequalities = find_inequalities(body);
49 if (!inequalities.empty())
51 auto [sigma, remaining_variables] = make_one_point_rule_substitution(inequalities, x.variables());
52 if (remaining_variables.size() != x.variables().size())
54 mCRL2log(log::debug) <<
"Apply substitution sigma = " << sigma <<
" to x = " << body << std::endl;
55 body = data::replace_variables_capture_avoiding(body, sigma);
57 if (remaining_variables.empty())
64 mCRL2log(log::debug) <<
"Replaced " << x <<
"\nwith " << forall(v, body) << std::endl;
65 make_forall(result, v, body);
77 std::vector<variable> variables;
79 std::map<variable, std::set<data_expression> > equalities = find_equalities(body);
80 if (!equalities.empty())
82 auto [sigma, remaining_variables] = make_one_point_rule_substitution(equalities, x.variables());
83 if (remaining_variables.size() != x.variables().size())
85 mCRL2log(log::debug) <<
"Apply substitution sigma = " << sigma <<
" to x = " << body << std::endl;
86 body = data::replace_variables_capture_avoiding(body, sigma);
88 if (remaining_variables.empty())
95 mCRL2log(log::debug) <<
"Replaced " << x <<
"\nwith " << exists(v, body) << std::endl;
96 make_exists(result, v, body);
mcrl2::utilities::shared_guard lock_shared()
Acquire a shared lock on this thread aterm pool.
bool operator==(const unprotected_aterm_core &t) const
Comparison operator.
bool operator!=(const unprotected_aterm_core &t) const
Inequality operator on two unprotected aterms.
const variable_list & variables() const
const data_expression & body() const
void apply(T &result, const forall &x)
data_expression_builder< Derived > super
void apply(T &result, const exists &x)
existential quantification.
universal quantification.
Rewriter that operates on data expressions.
void thread_initialise()
Initialises this rewriter with thread dependent information.
logger(const log_level_t l)
Default constructor.
void insert(const state &s) override
void swap(breadth_first_todo_set &other)
atermpp::deque< state > & todo_buffer()
breadth_first_todo_set(ForwardIterator first, ForwardIterator last)
breadth_first_todo_set(const state &init)
void choose_element(state &result) override
void choose_element(state &result) override
depth_first_todo_set(ForwardIterator first, ForwardIterator last)
depth_first_todo_set(const state &init)
void insert(const state &s) override
std::vector< data::variable > m_process_parameters
void generate_transitions(const explorer_summand &summand, const SummandSequence &confluent_summands, data::mutable_indexed_substitution<> &sigma, data::rewriter &rewr, data::data_expression &condition, state_type &s1, atermpp::aterm key, data::enumerator_algorithm<> &enumerator, data::enumerator_identifier_generator &id_generator, ReportTransition report_transition=ReportTransition())
void make_timed_state(state &result, const state &s, const data::data_expression &t) const
explorer(const Specification &lpsspec, const explorer_options &options_)
data::enumerator_algorithm m_global_enumerator
void abort() override
Abort the state space generation.
lps::multi_action rewrite_action(const lps::multi_action &a, data::mutable_indexed_substitution<> &sigma, data::rewriter &rewr) const
Rewrite action a, and put it back in place.
std::vector< state > generate_successors(const state &s0, const SummandSequence &summands, data::mutable_indexed_substitution<> &sigma, data::rewriter &rewr, data::enumerator_algorithm<> &enumerator, data::enumerator_identifier_generator &id_generator, const SummandSequence &confluent_summands=SummandSequence())
const state_type & make_state(const stochastic_state &s) const
void generate_state_space(bool recursive, const StateType &s0, const SummandSequence ®ular_summands, const SummandSequence &confluent_summands, indexed_set_for_states_type &discovered, DiscoverState discover_state=DiscoverState(), ExamineTransition examine_transition=ExamineTransition(), StartState start_state=StartState(), FinishState finish_state=FinishState(), DiscoverInitialState discover_initial_state=DiscoverInitialState())
std::vector< std::pair< lps::multi_action, state > > generate_transitions(const data::data_expression_list &init, data::mutable_indexed_substitution<> &sigma, data::rewriter &rewr)
Generates outgoing transitions for a given state.
const indexed_set_for_states_type & state_map() const
Returns a mapping containing all discovered states.
bool less_equal(const data::data_expression &t0, const data::data_expression &t1, data::mutable_indexed_substitution<> &sigma, data::rewriter &rewr) const
const std::vector< data::variable > & process_parameters() const
const std::vector< explorer_summand > & confluent_summands() const
void set_process_parameter_values(const data::data_expression_list &values, data::mutable_indexed_substitution<> &sigma)
void set_process_parameter_values(const data::data_expression_list &values)
std::set< data::function_symbol > add_real_operators(std::set< data::function_symbol > s) const
data::enumerator_identifier_generator m_global_id_generator
Specification m_global_lpsspec
data::data_expression_list process_parameter_values() const
Process parameter values for use in a single thread.
void generate_state_space_dfs_recursive(bool recursive, DiscoverState discover_state=DiscoverState(), ExamineTransition examine_transition=ExamineTransition(), TreeEdge tree_edge=TreeEdge(), BackEdge back_edge=BackEdge(), ForwardOrCrossEdge forward_or_cross_edge=ForwardOrCrossEdge(), FinishState finish_state=FinishState())
static constexpr bool is_timed
const data::data_expression_list & initial_state() const
void generate_state_space(bool recursive, DiscoverState discover_state=DiscoverState(), ExamineTransition examine_transition=ExamineTransition(), StartState start_state=StartState(), FinishState finish_state=FinishState(), DiscoverInitialState discover_initial_state=DiscoverInitialState())
Generates the state space, and reports all discovered states and transitions by means of callback fun...
void generate_state_space_dfs_recursive(const state &s0, std::unordered_set< state > gray, std::unordered_set< state > &discovered, const SummandSequence ®ular_summands, const SummandSequence &confluent_summands, DiscoverState discover_state=DiscoverState(), ExamineTransition examine_transition=ExamineTransition(), TreeEdge tree_edge=TreeEdge(), BackEdge back_edge=BackEdge(), ForwardOrCrossEdge forward_or_cross_edge=ForwardOrCrossEdge(), FinishState finish_state=FinishState())
indexed_set_for_states_type m_discovered
state find_representative(state &u0, const SummandSequence &summands, data::mutable_indexed_substitution<> &sigma, data::rewriter &rewr, data::enumerator_algorithm<> &enumerator, data::enumerator_identifier_generator &id_generator)
std::vector< explorer_summand > m_regular_summands
const explorer_options m_options
void compute_stochastic_state(stochastic_state &result, const stochastic_distribution &distribution, const DataExpressionSequence &next_state, data::mutable_indexed_substitution<> &sigma, data::rewriter &rewr, data::enumerator_algorithm<> &enumerator) const
summand_cache_map global_cache
const data::rewriter & get_rewriter() const
data::data_expression_list m_initial_state
std::mutex m_exclusive_state_access
data::mutable_indexed_substitution m_global_sigma
data::data_expression_list process_parameter_values(data::mutable_indexed_substitution<> &sigma) const
std::vector< std::pair< lps::multi_action, state_type > > generate_transitions(const state &d0, data::mutable_indexed_substitution<> &sigma, data::rewriter &rewr, data::enumerator_algorithm<> &enumerator, data::enumerator_identifier_generator &id_generator)
Generates outgoing transitions for a given state.
state_type make_state(const state &s) const
lps::stochastic_distribution m_initial_distribution
std::vector< explorer_summand > m_confluent_summands
volatile std::atomic< bool > m_must_abort
data::rewriter m_global_rewr
void generate_state_space_dfs_iterative(const state &s0, std::unordered_set< state > &discovered, const SummandSequence ®ular_summands, const SummandSequence &confluent_summands, DiscoverState discover_state=DiscoverState(), ExamineTransition examine_transition=ExamineTransition(), TreeEdge tree_edge=TreeEdge(), BackEdge back_edge=BackEdge(), ForwardOrCrossEdge forward_or_cross_edge=ForwardOrCrossEdge(), FinishState finish_state=FinishState())
void check_enumerator_solution(const data::data_expression &p_expression, const explorer_summand &summand, data::mutable_indexed_substitution<> &sigma, data::rewriter &rewr) const
const std::vector< explorer_summand > & regular_summands() const
void generate_state_space_thread(std::unique_ptr< todo_set > &todo, const std::size_t thread_index, std::atomic< std::size_t > &number_of_active_processes, std::atomic< std::size_t > &number_of_idle_processes, const SummandSequence ®ular_summands, const SummandSequence &confluent_summands, indexed_set_for_states_type &discovered, DiscoverState discover_state, ExamineTransition examine_transition, StartState start_state, FinishState finish_state, data::rewriter thread_rewr, data::mutable_indexed_substitution<> thread_sigma)
std::unique_ptr< todo_set > make_todo_set(const state &init)
void compute_state(state &result, const DataExpressionSequence &v, data::mutable_indexed_substitution<> &sigma, data::rewriter &rewr) const
std::vector< std::pair< lps::multi_action, state_type > > generate_transitions(const state &d0)
Generates outgoing transitions for a given state, using the global substitution, rewriter,...
data::rewriter construct_rewriter(const Specification &lpsspec, bool remove_unused_rewrite_rules)
std::unique_ptr< todo_set > make_todo_set(ForwardIterator first, ForwardIterator last)
std::list< transition > out_edges(const state &s)
std::vector< data::data_expression > timed_state
std::vector< std::pair< lps::multi_action, state_type > > generate_transitions(const data::data_expression_list &init, std::size_t i, data::mutable_indexed_substitution<> &sigma, data::rewriter &rewr, data::data_expression &condition, state_type &d0, data::enumerator_algorithm<> &enumerator, data::enumerator_identifier_generator &id_generator)
Generates outgoing transitions for a given state, reachable via the summand with index i.
std::list< transition > out_edges(const state &s, const SummandSequence ®ular_summands, const SummandSequence &confluent_summands, data::mutable_indexed_substitution<> &sigma, data::rewriter &rewr, data::enumerator_algorithm<> &enumerator, data::enumerator_identifier_generator &id_generator)
Specification preprocess(const Specification &lpsspec)
std::list< transition > out_edges(const state &s, const std::size_t summand_index)
bool is_confluent_tau(const multi_action &a)
atermpp::indexed_set< state, mcrl2::utilities::detail::GlobalThreadSafe > indexed_set_for_states_type
static constexpr bool is_stochastic
void generate_state_space_dfs_iterative(bool recursive, DiscoverState discover_state=DiscoverState(), ExamineTransition examine_transition=ExamineTransition(), TreeEdge tree_edge=TreeEdge(), BackEdge back_edge=BackEdge(), ForwardOrCrossEdge forward_or_cross_edge=ForwardOrCrossEdge(), FinishState finish_state=FinishState())
highway_todo_set(const state &init, std::size_t N_)
std::size_t size() const override
highway_todo_set(ForwardIterator first, ForwardIterator last, std::size_t N_)
std::random_device device
void insert(const state &s) override
void choose_element(state &result) override
bool empty() const override
breadth_first_todo_set new_states
void finish_state() override
\brief A timed multi-action
const process::action_list & actions() const
const data::data_expression & time() const
void enable_auto_select_probability(bool enable)
If enabled, automatically a probabilistic state is chosen using its intrinsic probability.
void select_transition(std::size_t transition_number)
Choose outgoing transition indexed by transition_number and add its state to the state vector.
void add_new_state(const lps::stochastic_state &s)
std::uniform_int_distribution< std::size_t > m_distrib
std::deque< simulator_state_t > m_full_trace
void randomly_select_state()
Randomly choose one state among a sequence of probabilistic states.
bool m_auto_select_probabilistic_state
void select_state(std::size_t state_number)
Choose one state among a sequence of probabilistic states.
simulation(const stochastic_specification &specification, data::rewrite_strategy strategy=data::rewrite_strategy())
Constructor.
void randomly_select_transition()
Randomly choose an outgoing transition and add its state to the state vector.
bool match_trace_transition(lts::trace &trace)
bool match_trace_probabilistic_state(lts::trace &trace)
void save(const std::string &filename) const
Save the trace to a file.
bool probabilistic_state_must_be_selected(const std::size_t state_index) const
Indicate whether a probabilistic state has been selected.
const std::deque< simulator_state_t > & trace() const
Returns the current annotated state vector.
stochastic_specification m_specification
void truncate(std::size_t state_number, bool probabilistic)
Remove states from the end of the simulation, making state_number the last state.
std::vector< transition_t > transitions(const lps::state &source_state)
void load(const std::string &filename)
Load a trace from a file.
Linear process specification.
LPS summand containing a multi-action.
const stochastic_distribution & distribution() const
Returns the distribution of this summand.
\brief A stochastic distribution
bool is_defined() const
Returns true if the distribution is defined, i.e. it contains a valid distribution....
Linear process specification.
virtual bool empty() const
todo_set(ForwardIterator first, ForwardIterator last)
atermpp::deque< state > todo
virtual void choose_element(state &result)
virtual ~todo_set()=default
virtual std::size_t size() const
todo_set(const state &init)
virtual void insert(const state &s)
virtual void finish_state()
This class contains a trace consisting of a sequence of (timed) actions possibly with intermediate st...
void increase_position()
Increase the current position by one, except if this brings one beyond the end of the trace.
bool current_action_exists() const
Indicate whether the current action exists.
bool current_state_exists() const
Indicate whether a current state exists.
const lps::state & current_state() const
Get the state at the current position in the trace.
void reset_position()
Set the current position back to the beginning of the trace.
void save(const std::string &filename, trace_format tf=tfMcrl2) const
Output the trace into a file with the indicated name.
mcrl2::lps::multi_action current_action()
Get the outgoing action from the current position in the trace.
Standard exception class for reporting runtime errors.
A shared lock guard for the shared_mutex.
void unlock_shared()
Unlocks the acquired shared guard explicitly. Otherwise, performed in destructor.
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
thread_aterm_pool & g_thread_term_pool()
A reference to the thread local term pool storage.
The main namespace for the aterm++ library.
Namespace for system defined sort bool_.
const function_symbol & true_()
Constructor for function symbol true.
Namespace for system defined sort real_.
data_expression & real_one()
data_expression & real_zero()
Namespace for all data library functionality.
bool is_false(const data_expression &x)
Test if x is false.
void add_assignments(data::mutable_indexed_substitution<> &sigma, const VariableSequence &v, const DataExpressionSequence &e)
Adds assignments [v := e] to the substitution sigma for each variable in v.
rewrite_strategy
The strategy of the rewriter.
void remove_assignments(data::mutable_indexed_substitution<> &sigma, const VariableSequence &v)
Removes assignments to variables in v from the substitution sigma.
atermpp::term_list< data_expression > data_expression_list
\brief list of data_expressions
void one_point_rule_rewrite(T &x, typename std::enable_if< !std::is_base_of< atermpp::aterm, T >::value >::type *=0)
atermpp::term_list< variable > variable_list
\brief list of variables
T one_point_rule_rewrite(const T &x, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type *=0)
The main namespace for the LPS library.
const stochastic_distribution & summand_distribution(const lps::stochastic_action_summand &summand)
const stochastic_distribution & summand_distribution(const Summand &)
Node find_representative(Node &u0, GenerateSuccessors generate_successors)
Search for a unique representative in a graph.
atermpp::term_balanced_tree< data::data_expression > state
std::vector< data::data_expression > make_data_expression_vector(const data::data_expression_list &v)
const stochastic_distribution & initial_distribution(const lps::stochastic_specification &lpsspec)
void check_stochastic_state(const stochastic_state &s, const data::rewriter &rewr)
atermpp::utilities::unordered_map< atermpp::aterm, atermpp::term_list< data::data_expression_list >, detail::cache_hash, detail::cache_equality, std::allocator< std::pair< atermpp::aterm, atermpp::term_list< data::data_expression_list > > >, true > summand_cache_map
void one_point_rule_rewrite(T &x, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Applies the one point rule rewriter to all embedded data expressions in an object x.
T one_point_rule_rewrite(const T &x, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Applies the one point rule rewriter to all embedded data expressions in an object x.
const stochastic_distribution & initial_distribution(const lps::specification &)
The main namespace for the Process library.
atermpp::term_list< action > action_list
\brief list of actions
void write_text(const std::string &filename, const std::string &text)
Saves text to the file filename, or to stdout if filename equals "-".
std::string read_text(const std::string &filename)
Reads text from the file filename, or from stdin if filename equals "-".
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
data_expression operator()(const data_expression &x) const
bool operator()(const atermpp::aterm &key1, const cheap_cache_key &key2) const
bool operator()(const atermpp::aterm &key1, const atermpp::aterm &key2) const
std::size_t operator()(const cheap_cache_key &key) const
std::size_t operator()(const std::pair< const atermpp::aterm, std::list< atermpp::term_list< mcrl2::data::data_expression > > > &pair) const
std::size_t operator()(const atermpp::aterm &key) const
cheap_cache_key(data::mutable_indexed_substitution<> &sigma, const std::vector< data::variable > &gamma)
const std::vector< data::variable > & m_gamma
data::mutable_indexed_substitution & m_sigma
void apply(T &result, const data::data_expression &x)
data::one_point_rule_rewriter r
lps::data_expression_builder< one_point_rule_rewrite_builder > super
transition(lps::multi_action action_, const state_type &state_)
bool detect_nondeterminism
std::set< core::identifier_string > actions_internal_for_divergencies
bool replace_constants_by_variables
std::set< core::identifier_string > trace_actions
explorer_options(data::rewrite_strategy rewr_strat)
exploration_strategy search_strategy
std::string confluence_action
bool remove_unused_rewrite_rules
bool discard_lts_state_labels
explorer_options & operator=(const explorer_options &other)=default
std::set< lps::multi_action > trace_multiactions
explorer_options(const explorer_options &other)=default
bool one_point_rule_rewrite
std::size_t number_of_threads
std::size_t highway_todo_max
bool suppress_progress_messages
data::variable_list variables
std::vector< data::variable > gamma
std::vector< data::variable > free_variables(const T &x, const data::variable_list &v)
explorer_summand(const ActionSummand &summand, std::size_t summand_index, const data::variable_list &process_parameters, caching cache_strategy_)
stochastic_distribution distribution
data::data_expression condition
summand_cache_map local_cache
atermpp::function_symbol f_gamma
void compute_key(atermpp::aterm &key, data::mutable_indexed_substitution<> &sigma) const
std::vector< data::data_expression > next_state
std::vector< transition_t > transitions
std::size_t transition_number
lps::stochastic_state source_state
stochastic_state(const state &s)
The skip operation with a variable number of arguments.
void operator()(const Args &...) const
std::size_t operator()(const atermpp::detail::reference_aterm< T > &t) const