mCRL2
Loading...
Searching...
No Matches
lts2pbes_rhs.h
Go to the documentation of this file.
1// Author(s): Wieger Wesselink
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9/// \file mcrl2/pbes/detail/lts2pbes_rhs.h
10/// \brief add your file description here.
11
12#ifndef MCRL2_PBES_DETAIL_LTS2PBES_RHS_H
13#define MCRL2_PBES_DETAIL_LTS2PBES_RHS_H
14
15#include "mcrl2/pbes/replace.h"
16#include "mcrl2/pbes/detail/lps2pbes_par.h"
17#include "mcrl2/pbes/detail/lps2pbes_sat.h"
18#include "mcrl2/pbes/detail/lts2pbes_lts.h"
19#include "mcrl2/utilities/progress_meter.h"
20
21
22
23
24
25namespace mcrl2::pbes_system::detail {
26
28
29inline
30core::identifier_string make_identifier(const core::identifier_string& name, lts2pbes_state_type s)
31{
32 return core::identifier_string(std::string(name) + "'" + std::to_string(s));
33}
34
36{
37 const state_formulas::state_formula& phi0; // the original formula
41 utilities::progress_meter& pm;
42
44 const lts::lts_lts_t& lts0_,
45 const lts2pbes_lts& lts1_,
46 data::set_identifier_generator& id_generator_,
47 utilities::progress_meter& pm_
48 )
49 : phi0(phi0_), lts0(lts0_), lts1(lts1_), id_generator(id_generator_), pm(pm_)
50 {}
51
52 template <typename TermTraits>
54 const pbes_expression& left, // Sat(a(x), alpha)
55 const pbes_expression& right, // RHS(phi, t)
56 std::size_t, /* i */
57 const lps::multi_action& /* a */,
58 lts2pbes_state_type /* s */,
59 lts2pbes_state_type /* t */,
60 TermTraits
61 )
62 {
63 using tr = TermTraits;
64 if (is_must)
65 {
66 return tr::imp(left, right);
67 }
68 else
69 {
70 return tr::and_(left, right);
71 }
72 }
73};
74
75// TODO: reuse code from lps2pbes_counter_example_parameters
77{
78 std::vector<propositional_variable> Zpos; // represents the additional equations { nu Zpos_i(s, a(i), s) = true }
79 std::vector<propositional_variable> Zneg; // represents the additional equations { nu Zneg_i(s, a(i), t) = false }
80 data::variable_list s_list; // contains the process parameter s: Nat
81 data::variable_list t_list; // contains the process parameter t: Nat
82
83 // creates variables corresponding to the action label sorts in actions
84 data::variable_list action_variables(const process::action_list& actions) const
85 {
86 std::vector<data::variable> result;
87 for (const process::action& a: actions)
88 {
89 for (const data::sort_expression& s: a.label().sorts())
90 {
91 data::variable v(id_generator("v"), s);
92 result.push_back(v);
93 }
94 }
95 return data::variable_list(result.begin(), result.end());
96 }
97
98 // returns the concatenation of the arguments of the list of actions
99 data::data_expression_list action_expressions(const process::action_list& actions) const
100 {
101 std::vector<data::data_expression> result;
102 for (const process::action& a: actions)
103 {
104 auto const& args = a.arguments();
105 result.insert(result.end(), args.begin(), args.end());
106 }
107 return data::data_expression_list(result.begin(), result.end());
108 }
109
110 // returns the equations needed for counter example generation
112 {
113 std::vector<pbes_equation> result;
114 for (auto const& p: Zneg)
115 {
116 pbes_equation eqn(fixpoint_symbol::nu(), p, false_());
117 result.push_back(eqn);
118 }
119 for (auto const& p: Zpos)
120 {
121 pbes_equation eqn(fixpoint_symbol::nu(), p, true_());
122 result.push_back(eqn);
123 }
124 return result;
125 }
126
128 {
129 std::vector<std::string> v;
130 for (const process::action& ai: a.actions())
131 {
132 v.emplace_back(ai.label().name());
133 }
134 return utilities::string_join(v, "_");
135 }
136
138 const lts::lts_lts_t& lts0,
139 const lts2pbes_lts& lts1,
140 data::set_identifier_generator& id_generator,
141 utilities::progress_meter& pm
142 )
143 : lts2pbes_parameters(phi0, lts0, lts1, id_generator, pm),
146 {
147 std::size_t n = lts0.get_transitions().size();
148 Zpos = std::vector<propositional_variable>(n);
149 Zneg = std::vector<propositional_variable>(n);
150 for (const auto& p: lts1.state_map())
151 {
152 for (const lts2pbes_lts::edge& e: p.second)
153 {
154 const lps::multi_action& ai = lts1.action_labels()[e.label];
155 data::variable_list actvars = action_variables(ai.actions());
156 std::string suffix = utilities::number2string(e.index) + "_" + multi_action_name(ai);
157 core::identifier_string pos = id_generator("Zpos_" + suffix);
158 core::identifier_string neg = id_generator("Zneg_" + suffix);
159 Zpos[e.index] = propositional_variable(pos, s_list + actvars + t_list);
160 Zneg[e.index] = propositional_variable(neg, s_list + actvars + t_list);
161 }
162 }
163 }
164
165 data::data_expression equal_to(const data::variable_list& d, const data::data_expression_list& e) const
166 {
167 std::vector<data::data_expression> v;
168 auto i = d.begin();
169 auto j = e.begin();
170 for (; i != d.end(); ++i, ++j)
171 {
172 v.push_back(data::equal_to(*i, *j));
173 }
174 return data::lazy::join_and(v.begin(), v.end());
175 }
176
177 template <typename TermTraits>
179 const pbes_expression& left, // Sat(a(x), alpha)
180 const pbes_expression& right, // RHS(phi, t)
181 std::size_t i, // The index of the transition s --a--> t
182 const lps::multi_action& a,
183 lts2pbes_state_type s,
184 lts2pbes_state_type t,
185 TermTraits
186 )
187 {
188 using tr = TermTraits;
189 auto f = action_expressions(a.actions());
190 data::data_expression_list dx = data::data_expression_list({ data::sort_nat::nat(s) }) + f + data::data_expression_list({ data::sort_nat::nat(t) });
191 propositional_variable_instantiation Pos(Zpos[i].name(), dx);
192 propositional_variable_instantiation Neg(Zneg[i].name(), dx);
193 auto right1 = right;
194
195 if (is_must)
196 {
197 right1 = tr::or_(tr::and_(right, Pos), Neg);
198 return tr::imp(left, right1);
199 }
200 else
201 {
202 right1 = tr::and_(tr::or_(right, Neg), Pos);
203 return tr::and_(left, right1);
204 }
205 }
206};
207
208template <typename TermTraits, typename Parameters>
210 lts2pbes_state_type s,
211 Parameters& parameters,
212 TermTraits tr);
213
214template <typename Derived, typename TermTraits, typename Parameters>
216{
218 using tr = TermTraits;
219
220 using super::enter;
221 using super::leave;
222 using super::apply;
223
225 Parameters& parameters;
227
228 rhs_lts2pbes_traverser(lts2pbes_state_type s_,
229 Parameters& parameters_,
230 TermTraits
231 )
232 : s(s_), parameters(parameters_)
233 {}
234
235 Derived& derived()
236 {
237 return static_cast<Derived&>(*this);
238 }
239
240 void push(const pbes_expression& x)
241 {
242 result_stack.push_back(x);
243 }
244
246 {
247 return result_stack.back();
248 }
249
250 const pbes_expression& top() const
251 {
252 return result_stack.back();
253 }
254
256 {
257 pbes_expression result = top();
258 result_stack.pop_back();
259 return result;
260 }
261
262 void leave(const data::data_expression& x)
263 {
264 push(atermpp::down_cast<pbes_expression>(x));
265 }
266
268 {
270 }
271
273 {
275 }
276
278 {
279 throw mcrl2::runtime_error("rhs_lts2pbes_traverser: negation is not supported!");
280 }
281
283 {
284 pbes_expression right = pop();
285 pbes_expression left = pop();
286 push(tr::and_(left, right));
287 }
288
290 {
291 pbes_expression right = pop();
292 pbes_expression left = pop();
293 push(tr::or_(left, right));
294 }
295
297 {
298 throw mcrl2::runtime_error("rhs_lts2pbes_traverser: implication is not supported!");
299 }
300
302 {
303 derived().apply(x.body());
304 top() = forall(x.variables(), top());
305 }
306
308 {
309 derived().apply(x.body());
310 top() = exists(x.variables(), top());
311 }
312
313 void apply(const state_formulas::must& x)
314 {
315 const auto& lts1 = parameters.lts1;
316 std::vector<pbes_expression> v;
318 const auto& alpha = atermpp::down_cast<const action_formulas::action_formula>(x.formula());
320
321 // traverse all transitions s --a--> t
322 for (const lts2pbes_lts::edge& e: lts1.edges(s))
323 {
324 lts2pbes_state_type t = e.state;
325 const lps::multi_action& a = lts1.action_labels()[e.label];
326 pbes_expression left = detail::Sat(a, alpha, parameters.id_generator, TermTraits());
327 pbes_expression right = RHS(phi, t, parameters, TermTraits());
328 pbes_expression p = parameters.rhs_may_must(true, left, right, e.index, a, s, t, TermTraits());
329 v.push_back(p);
330 }
331 push(tr::join_and(v.begin(), v.end()));
332 }
333
334 void apply(const state_formulas::may& x)
335 {
336 const auto& lts1 = parameters.lts1;
337 std::vector<pbes_expression> v;
339 const auto& alpha = atermpp::down_cast<const action_formulas::action_formula>(x.formula());
341
342 // traverse all transitions s --a--> t
343 for (const lts2pbes_lts::edge& e: lts1.edges(s))
344 {
345 lts2pbes_state_type t = e.state;
346 const lps::multi_action& a = lts1.action_labels()[e.label];
347 pbes_expression left = detail::Sat(a, alpha, parameters.id_generator, TermTraits());
348 pbes_expression right = RHS(phi, t, parameters, TermTraits());
349 pbes_expression p = parameters.rhs_may_must(false, left, right, e.index, a, s, t, TermTraits());
350 v.push_back(p);
351 }
352 push(tr::join_or(v.begin(), v.end()));
353 }
354
356 {
357 throw mcrl2::runtime_error("rhs_lts2pbes_traverser: yaled is not supported!");
358 }
359
361 {
362 throw mcrl2::runtime_error("rhs_lts2pbes_traverser: yaled_timed is not supported!");
363 }
364
366 {
367 throw mcrl2::runtime_error("rhs_lts2pbes_traverser: yaled is not supported!");
368 }
369
371 {
372 throw mcrl2::runtime_error("rhs_lts2pbes_traverser: delay_timed is not supported!");
373 }
374
376 {
377 const core::identifier_string& X = x.name();
378 core::identifier_string X_s = make_identifier(X, s);
379 const data::data_expression_list& e = x.arguments();
380 push(propositional_variable_instantiation(X_s, e + detail::Par(X, data::variable_list(), parameters.phi0)));
381 }
382
383 void apply(const state_formulas::nu& x)
384 {
385 const core::identifier_string& X = x.name();
386 core::identifier_string X_s = make_identifier(X, s);
387 data::data_expression_list e = detail::mu_expressions(x);
388 push(propositional_variable_instantiation(X_s, e + detail::Par(X, data::variable_list(), parameters.phi0)));
389 }
390
391 void apply(const state_formulas::mu& x)
392 {
393 const core::identifier_string& X = x.name();
394 core::identifier_string X_s = make_identifier(X, s);
395 data::data_expression_list e = detail::mu_expressions(x);
396 push(propositional_variable_instantiation(X_s, e + detail::Par(X, data::variable_list(), parameters.phi0)));
397 }
398};
399
400template <template <class, class, class> class Traverser, typename TermTraits, typename Parameters>
402{
404 using super::enter;
405 using super::leave;
406 using super::apply;
407
408 apply_rhs_lts2pbes_traverser(lts2pbes_state_type s, Parameters& parameters, TermTraits tr)
409 : super(s, parameters, tr)
410 {}
411};
412
413template <typename TermTraits, typename Parameters>
415 lts2pbes_state_type s,
416 Parameters& parameters,
417 TermTraits tr)
418{
419 apply_rhs_lts2pbes_traverser<rhs_lts2pbes_traverser, TermTraits, Parameters> f(s, parameters, tr);
420 f.apply(x);
421 return f.top();
422}
423
424} // namespace mcrl2::pbes_system::detail
425
426
427
428
429
430#endif // MCRL2_PBES_DETAIL_LTS2PBES_RHS_H
Identifier generator that stores the identifiers of the context in a set. Using the operator()() and ...
\brief A timed multi-action
This class contains labelled transition systems in .lts format.
Definition lts_lts.h:369
\brief The existential quantification operator for pbes expressions
\brief The universal quantification operator for pbes expressions
\brief A propositional variable instantiation
\brief The and operator for state formulas
\brief The timed delay operator for state formulas
\brief The delay operator for state formulas
\brief The existential quantification operator for state formulas
const state_formula & body() const
const data::variable_list & variables() const
\brief The value false for state formulas
\brief The universal quantification operator for state formulas
const state_formula & body() const
const data::variable_list & variables() const
\brief The implication operator for state formulas
\brief The may operator for state formulas
const state_formula & operand() const
const regular_formulas::regular_formula & formula() const
\brief The mu operator for state formulas
const core::identifier_string & name() const
\brief The must operator for state formulas
const regular_formulas::regular_formula & formula() const
const state_formula & operand() const
\brief The not operator for state formulas
\brief The nu operator for state formulas
const core::identifier_string & name() const
\brief The or operator for state formulas
\brief The value true for state formulas
\brief The state formula variable
const core::identifier_string & name() const
const data::data_expression_list & arguments() const
\brief The timed yaled operator for state formulas
\brief The yaled operator for state formulas
bool is_action_formula(const atermpp::aterm &x)
The main namespace for the LPS library.
Definition constelm.h:18
pbes_expression RHS(const state_formulas::state_formula &x, lts2pbes_state_type s, Parameters &parameters, TermTraits tr)
core::identifier_string make_identifier(const core::identifier_string &name, lts2pbes_state_type s)
const pbes_expression & true_()
const pbes_expression & false_()
The main namespace for the Process library.
apply_rhs_lts2pbes_traverser(lts2pbes_state_type s, Parameters &parameters, TermTraits tr)
data::data_expression equal_to(const data::variable_list &d, const data::data_expression_list &e) const
lts2pbes_counter_example_parameters(const state_formulas::state_formula &phi0, const lts::lts_lts_t &lts0, const lts2pbes_lts &lts1, data::set_identifier_generator &id_generator, utilities::progress_meter &pm)
pbes_expression rhs_may_must(bool is_must, const pbes_expression &left, const pbes_expression &right, std::size_t i, const lps::multi_action &a, lts2pbes_state_type s, lts2pbes_state_type t, TermTraits)
std::string multi_action_name(const lps::multi_action &a) const
data::data_expression_list action_expressions(const process::action_list &actions) const
data::variable_list action_variables(const process::action_list &actions) const
const state_formulas::state_formula & phi0
data::set_identifier_generator & id_generator
pbes_expression rhs_may_must(bool is_must, const pbes_expression &left, const pbes_expression &right, std::size_t, const lps::multi_action &, lts2pbes_state_type, lts2pbes_state_type, TermTraits)
lts2pbes_parameters(const state_formulas::state_formula &phi0_, const lts::lts_lts_t &lts0_, const lts2pbes_lts &lts1_, data::set_identifier_generator &id_generator_, utilities::progress_meter &pm_)
rhs_lts2pbes_traverser(lts2pbes_state_type s_, Parameters &parameters_, TermTraits)
void leave(const state_formulas::yaled_timed &)
void leave(const state_formulas::or_ &)
void apply(const state_formulas::exists &x)
void leave(const state_formulas::variable &x)
void leave(const state_formulas::true_ &)
void apply(const state_formulas::must &x)
void leave(const data::data_expression &x)
void apply(const state_formulas::forall &x)
void leave(const state_formulas::delay_timed &)
void apply(const state_formulas::mu &x)
void leave(const state_formulas::delay &)
void leave(const state_formulas::false_ &)
void apply(const state_formulas::imp &)
void apply(const state_formulas::nu &x)
void apply(const state_formulas::may &x)
void leave(const state_formulas::and_ &)
void leave(const state_formulas::yaled &)
void apply(const state_formulas::not_ &)