12#ifndef MCRL2_PBES_DETAIL_STATEGRAPH_PBES_H
13#define MCRL2_PBES_DETAIL_STATEGRAPH_PBES_H
15#include "mcrl2/core/detail/print_utility.h"
16#include "mcrl2/pbes/detail/guard_traverser.h"
17#include "mcrl2/pbes/detail/stategraph_simplify_rewriter.h"
18#include "mcrl2/pbes/detail/stategraph_utility.h"
80 return mapped_value(m_source, k, data::undefined_data_expression());
92 return mapped_value(m_target, k, data::undefined_data_expression());
104 return mapped_value(m_copy, k, data::undefined_index());
121 m_guard = R(m_guard);
126 std::ostringstream out;
127 out <<
"predicate variable X = " << X << std::endl;
128 out <<
"guard = " << m_guard << std::endl;
129 out <<
"sigma = " << m_sigma << std::endl;
130 out <<
"source = " << core::detail::print_map(m_source) << std::endl;
131 out <<
"target = " << core::detail::print_map(m_target) << std::endl;
132 out <<
"copy = " << core::detail::print_map(m_copy) << std::endl;
133 out <<
"used = " << core::detail::print_set(m_used) << std::endl;
134 out <<
"changed = " << core::detail::print_set(m_changed) << std::endl;
142 return out << x.variable();
159 std::vector<pbes_expression> conjuncts;
160 detail::stategraph_split_and(x, conjuncts);
161 for (
const pbes_expression& expr: conjuncts)
163 if (data::is_data_expression(expr))
165 const auto& v_i = atermpp::down_cast<
const data::data_expression>(expr);
166 if (data::is_equal_to_application(v_i))
168 const data::data_expression& left = data::binary_left1(v_i);
169 const data::data_expression& right = data::binary_right1(v_i);
170 if (data::is_variable(left) && std::find(d.begin(), d.end(), data::variable(left)) != d.end() && data::is_constant(right))
172 const auto& vleft = atermpp::down_cast<data::variable>(left);
173 result[vleft] = right;
175 else if (data::is_variable(right) && std::find(d.begin(), d.end(), data::variable(right)) != d.end() && data::is_constant(left))
177 const auto& vright = atermpp::down_cast<data::variable>(right);
178 result[vright] = left;
182 else if (data::is_variable(v_i) && data::is_bool(v_i.sort()) && std::find(d.begin(), d.end(), data::variable(v_i)) != d.end())
184 const auto& v = atermpp::down_cast<data::variable>(v_i);
185 result[v] = data::true_();
187 else if (data::is_not(v_i))
189 const data::data_expression& narg = data::sort_bool::arg(v_i);
190 if (data::is_variable(narg) && data::is_bool(v_i.sort()) && std::find(d.begin(), d.end(), data::variable(narg)) != d.end())
192 const auto& v = atermpp::down_cast<data::variable>(narg);
193 result[v] = data::false_();
198 mCRL2log(log::log_level_t::trace) <<
" computing source: expression = " << x <<
", d_X = " << core::detail::print_list(d) <<
", result = " << core::detail::print_map(result) << std::endl;
203 auto j = is_control_flow.find(X);
204 assert(j != is_control_flow.end());
205 const std::vector<
bool>& cf = j->second;
206 assert(i < cf.size());
213 for (predicate_variable& predvar: m_predvars)
215 std::map<data::variable, data::data_expression> sigma;
216 find_equality_conjuncts(predvar.m_guard, m_parameters, sigma);
219 for (std::size_t j = 0; j < m_parameters.size(); j++)
221 data::variable d_j = m_parameters[j];
222 auto k = sigma.find(d_j);
223 if (k != sigma.end())
225 data::data_expression e = k->second;
226 predvar.m_source[j] = e;
227 predvar.m_sigma[d_j] = e;
235 for (predicate_variable& Ye: m_predvars)
237 auto const& e = Ye.parameters();
238 std::size_t j_index = 0;
239 for (
auto j = e.begin(); j != e.end(); ++j, ++j_index)
241 data::data_expression c = R(*j, Ye.sigma());
242 if (data::is_constant(c))
244 Ye.m_target[j_index] = c;
252 for (predicate_variable& predvar: m_predvars)
254 auto const& e = predvar.X.parameters();
255 for (std::size_t j = 0; j < m_parameters.size(); j++)
257 std::size_t k_index = 0;
258 for (
auto k = e.begin(); k != e.end(); ++k, ++k_index)
260 if (m_parameters[j] == *k)
262 predvar.m_copy[j] = k_index;
273 auto const& d_X = m_parameters;
274 for (predicate_variable& Ye : m_predvars)
276 auto v = pbes_system::find_free_variables(Ye.guard());
277 for (std::size_t j = 0; j < d_X.size(); j++)
279 if (contains(v, d_X[j]))
283 std::size_t p_index = 0;
284 auto const& e = Ye.parameters();
285 for (
auto p = e.begin(); p != e.end(); ++p, ++p_index)
287 auto freevars = data::find_free_variables(*p);
288 if (contains(freevars, d_X[j]))
290 if ( (Ye.name() != variable().name()) || p_index != j )
302 auto const& d_X = m_parameters;
303 for (predicate_variable& Ye: m_predvars)
305 if (Ye.name() != variable().name())
309 std::size_t j_index = 0;
310 auto const& e = Ye.parameters();
311 for (
auto j = e.begin(); j != e.end(); ++j, ++j_index)
313 if (*j != d_X[j_index])
315 Ye.m_changed.insert(j_index);
327 const std::vector<std::pair<propositional_variable_instantiation, pbes_expression>>& guards = f.expression_stack.back().guards;
328 for (
const auto& guard: guards)
330 m_predvars.emplace_back(guard.first, guard.second);
333 data::variable_list params = variable().parameters();
334 m_parameters = std::vector<data::variable>(params.begin(), params.end());
350 m_control_flow_parameter_indices = std::vector<std::size_t>(CFP.begin(), CFP.end());
351 for (std::size_t i: m_control_flow_parameter_indices)
353 m_control_flow_parameters.push_back(m_parameters[i]);
361 m_data_parameter_indices = std::vector<std::size_t>(DP.begin(), DP.end());
362 for (std::size_t i: m_data_parameter_indices)
364 m_data_parameters.push_back(m_parameters[i]);
370 return m_control_flow_parameters;
375 return m_control_flow_parameter_indices;
380 return m_data_parameters;
385 return m_data_parameter_indices;
390 for (
const predicate_variable& predvar: m_predvars)
393 if (!pbes_system::is_false(predvar.guard()))
423 std::ostringstream out;
424 out <<
"equation = " << print_equation(*
this) << std::endl;
425 out <<
"guards:" << std::endl;
426 for (
const predicate_variable& predvar: m_predvars)
428 out <<
"variable = " << predvar.variable() <<
" guard = " << predvar.guard() << std::endl;
430 out <<
"simple = " << std::boolalpha << is_simple() << std::endl;
436 std::ostringstream out;
437 std::string X(variable().name());
438 for (std::size_t i = 0; i < m_predvars.size(); i++)
440 out <<
" predvar[" << i <<
"] = " << m_predvars[i] <<
" guard = " << m_predvars[i].guard() << std::endl;
443 auto const& source = m_predvars[i].source();
444 for (
const auto& j: source)
446 out <<
" source(" << X <<
", " << i <<
", " << j.first <<
") = " << j.second << std::endl;
450 out <<
" sigma = " << m_predvars[i].sigma() << std::endl;
453 const std::map<std::size_t, data::data_expression>& target = m_predvars[i].target();
454 for (
const auto& j: target)
456 out <<
" target(" << X <<
", " << i <<
", " << j.first <<
") = " << j.second << std::endl;
460 auto const& copy = m_predvars[i].copy();
461 for (
const auto& j: copy)
463 out <<
" copy(" << X <<
", " << i <<
", " << j.first <<
") = " << j.second << std::endl;
465 out <<
" used = " << core::detail::print_set(m_predvars[i].used()) << std::endl;
466 out <<
" changed = " << core::detail::print_set(m_predvars[i].changed()) << std::endl;
474 assert(e.size() == m_parameters.size());
475 data::data_expression_vector result;
476 for (std::size_t i: m_control_flow_parameter_indices)
478 result.push_back(nth_element(e, i));
480 return data::data_expression_list(result.begin(), result.end());
501 const std::vector<pbes_equation>& equations = p.equations();
502 for (
const pbes_equation& equation: equations)
504 m_equations.emplace_back(equation, rewr);
520 return m_global_variables;
525 return m_global_variables;
540 auto const& eqn = equations()[k];
541 auto const& sigma = eqn.predicate_variables()[i].sigma();
557 for (stategraph_equation& eqn: equations())
559 eqn.compute_source_target_copy(R);
565 std::ostringstream out;
566 for (
const stategraph_equation& eqn: equations())
568 out <<
"equation = " << print_equation(eqn) << std::endl;
569 out << eqn.print_source_target_copy() << std::endl;
Rewriter that operates on data expressions.
std::map< std::size_t, data::data_expression > m_source
std::set< std::size_t > m_changed
const propositional_variable_instantiation & variable() const
std::string print() const
std::size_t copy(std::size_t k) const
const std::set< std::size_t > & used() const
data::data_expression source(std::size_t k) const
std::set< std::size_t > m_used
std::map< std::size_t, data::data_expression > m_target
predicate_variable(const propositional_variable_instantiation &X_, const pbes_expression &guard_)
const std::set< std::size_t > & changed() const
data::rewriter::substitution_type m_sigma
const std::map< std::size_t, data::data_expression > & target() const
const data::data_expression_list & parameters() const
const data::rewriter::substitution_type & sigma() const
data::data_expression target(std::size_t k) const
const std::map< std::size_t, data::data_expression > & source() const
const core::identifier_string & name() const
propositional_variable_instantiation X
const std::map< std::size_t, std::size_t > & copy() const
std::map< std::size_t, std::size_t > m_copy
const pbes_expression & guard() const
const std::vector< std::size_t > & control_flow_parameter_indices() const
std::vector< std::size_t > m_data_parameter_indices
data::data_expression_list project(const data::data_expression_list &e) const
const data::variable_vector & data_parameters() const
pbes_expression m_condition
const std::vector< data::variable > & parameters() const
void find_equality_conjuncts(const pbes_expression &x, const std::vector< data::variable > &d, std::map< data::variable, data::data_expression > &result) const
void set_data_parameters(const std::set< std::size_t > &DP) const
Sets the data parameters of this equation.
void compute_target(data::rewriter &R)
std::string print_source_target_copy() const
std::vector< predicate_variable > & predicate_variables()
stategraph_equation(const pbes_equation &eqn, const data::rewriter &rewr)
const std::vector< predicate_variable > & predicate_variables() const
data::variable_vector m_data_parameters
const pbes_expression & simple_guard() const
void set_control_flow_parameters(const std::set< std::size_t > &CFP) const
Sets the control flow parameters of this equation.
std::vector< data::variable > m_parameters
std::vector< predicate_variable > m_predvars
bool is_cf(const std::map< core::identifier_string, std::vector< bool > > &is_control_flow, const core::identifier_string &X, std::size_t i) const
void compute_source_target_copy(data::rewriter &R)
std::vector< std::size_t > m_control_flow_parameter_indices
data::variable_vector m_control_flow_parameters
const data::variable_vector & control_flow_parameters() const
std::string print() const
const std::vector< std::size_t > & data_parameter_indices() const
propositional_variable_instantiation m_initial_state
std::set< data::variable > m_global_variables
stategraph_pbes()=default
std::string print_source_target_copy() const
const std::set< data::variable > & global_variables() const
void compute_source_target_copy()
const propositional_variable_instantiation & initial_state() const
const std::vector< stategraph_equation > & equations() const
data::data_expression source(std::size_t k, std::size_t i, std::size_t n) const
std::vector< stategraph_equation > & equations()
data::data_specification m_data
std::set< data::variable > & global_variables()
std::vector< stategraph_equation > m_equations
stategraph_pbes(const pbes &p, const data::rewriter &rewr)
Constructor.
A rewriter that simplifies expressions that simplifies quantifiers.
const pbes_expression & formula() const
Returns the predicate formula on the right hand side of the equation.
pbes_expression(const pbes_expression &) noexcept=default
Move semantics.
parameterized boolean equation system
const propositional_variable_instantiation & initial_state() const
Returns the initial state.
\brief A propositional variable instantiation
const data::data_expression_list & parameters() const
propositional_variable_instantiation(const propositional_variable_instantiation &) noexcept=default
Move semantics.
const core::identifier_string & name() const
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
const data::data_expression & undefined_data_expression()
Returns a data expression that corresponds to 'undefined'.
std::ostream & operator<<(std::ostream &out, const predicate_variable &x)
Computes a multimap of propositional variable instantiations and the corresponding guards from a PBES...
guard_traverser(const data::rewriter &r)