mCRL2
Loading...
Searching...
No Matches
lps2pbes.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/lps2pbes.h
10/// \brief Add your file description here.
11
12#ifndef MCRL2_PBES_LPS2PBES_H
13#define MCRL2_PBES_LPS2PBES_H
14
15#include "mcrl2/data/merge_data_specifications.h"
16#include "mcrl2/lps/detail/make_timed_lps.h"
17#include "mcrl2/lps/linearise.h"
18#include "mcrl2/modal_formula/algorithms.h"
19#include "mcrl2/modal_formula/preprocess_state_formula.h"
20#include "mcrl2/pbes/algorithms.h"
21#include "mcrl2/pbes/detail/lps2pbes_e.h"
22#include "mcrl2/pbes/detail/term_traits_optimized.h"
23#include "mcrl2/pbes/is_monotonous.h"
24#include "mcrl2/process/merge_action_specifications.h"
25
26
27
28namespace mcrl2::pbes_system
29{
30
31/// \brief Algorithm for translating a state formula and a timed specification to a pbes.
33{
34 protected:
36 bool m_check_only = false;
37
38 template <typename Parameters>
39 void run(const state_formulas::state_formula& f, bool structured, bool unoptimized, std::vector<pbes_equation>& equations, Parameters& parameters)
40 {
41 if (structured)
42 {
43 if (unoptimized)
44 {
45 detail::E_structured(f, parameters, equations, core::term_traits<pbes_expression>());
46 }
47 else
48 {
49 detail::E_structured(f, parameters, equations, core::term_traits_optimized<pbes_expression>());
50 }
51 }
52 else
53 {
54 if (unoptimized)
55 {
56 detail::E(f, parameters, equations, core::term_traits<pbes_expression>());
57 }
58 else
59 {
60 detail::E(f, parameters, equations, core::term_traits_optimized<pbes_expression>());
61 }
62 }
63 }
64
65 public:
66 /// \brief Constructor
67 explicit lps2pbes_algorithm(bool check_only = false)
68 : m_check_only(check_only)
69 {}
70
71 /// \brief Runs the translation algorithm
72 /// \param formula A modal formula that represents a property about the system modeled by the given specification
73 /// \param lpsspec A linear process specification
74 /// \param structured use the 'structured' approach of generating equations
75 /// \param unoptimized do not optimize the resulting PBES.
76 /// \param preprocess_modal_operators insert dummy fixpoints in modal operators, which may lead to smaller PBESs
77 /// \param generate_counter_example If true, then the PBES is enhanced with additional equations that are used to extract a counter example.
78 /// \param T The time parameter. If T == data::variable() the untimed version of lps2pbes is applied.
79 /// \return A PBES that encodes the property applied to the given specification
81 const lps::stochastic_specification& lpsspec,
82 bool structured = false,
83 bool unoptimized = false,
84 bool preprocess_modal_operators = false,
85 bool generate_counter_example = false,
87 )
88 {
89 state_formulas::state_formula f = formula;
90
91 std::set<core::identifier_string> lps_ids = lps::find_identifiers(lpsspec);
92 std::set<core::identifier_string> dataspec_ids = data::function_and_mapping_identifiers(lpsspec.data());
93 lps_ids.insert(dataspec_ids.begin(), dataspec_ids.end());
94 f = state_formulas::preprocess_state_formula(f, lps_ids, preprocess_modal_operators);
95
96 if (m_check_only)
97 {
98 return pbes();
99 }
100
101 m_generator.clear_context();
102 m_generator.add_identifiers(lps::find_identifiers(lpsspec));
103 m_generator.add_identifiers(data::function_and_mapping_identifiers(lpsspec.data()));
104 m_generator.add_identifiers(state_formulas::find_identifiers(f));
105
106 std::vector<pbes_equation> equations;
107 if (generate_counter_example)
108 {
109 detail::lps2pbes_counter_example_parameters parameters(f, lpsspec.process(), m_generator, T);
110 run(f, structured, unoptimized, equations, parameters);
111 equations = equations + parameters.equations();
112 }
113 else
114 {
115 detail::lps2pbes_parameters parameters(f, lpsspec.process(), m_generator, T);
116 run(f, structured, unoptimized, equations, parameters);
117 }
118
119 // compute the initial state
120 assert(!equations.empty());
121 pbes_equation e1 = equations.front();
122 core::identifier_string Xe(e1.variable().name());
124 const core::identifier_string& Xf = detail::mu_name(f);
125 data::data_expression_list fi = detail::mu_expressions(f);
126 data::data_expression_list pi = lpsspec.initial_process().expressions();
127 data::data_expression_list e = fi + pi + detail::Par(Xf, data::variable_list(), f);
129 {
130 e.push_front(data::sort_real::real_(0));
131 }
133
134 pbes result(lpsspec.data(), lpsspec.global_variables(), equations, init);
135 assert(is_monotonous(result));
138 assert(result.is_closed());
140 return result;
141 }
142};
143
144/// \brief Translates a linear process specification and a state formula to a PBES. If the solution of the PBES
145/// is true, the formula holds for the specification.
146/// \param lpsspec A stochastic linear process specification.
147/// \param formula A modal formula.
148/// \param timed determines whether the timed or untimed variant of the algorithm is chosen.
149/// \param structured use the 'structured' approach of generating equations.
150/// \param unoptimized if true, the resulting PBES is not simplified, if false (default),
151/// the PBES is simplified.
152/// \param preprocess_modal_operators A boolean indicating that the modal operators can be preprocessed to
153/// obtain a more compact PBES.
154/// \param generate_counter_example A boolean indicating that a counter example must be generated.
155/// \return The resulting pbes.
156inline
158 const state_formulas::state_formula& formula,
159 bool timed = false,
160 bool structured = false,
161 bool unoptimized = false,
162 bool preprocess_modal_operators = false,
163 bool generate_counter_example = false,
164 bool check_only = false
165 )
166{
167 if ((formula.has_time() || lpsspec.process().has_time()) && !timed)
168 {
169 mCRL2log(log::warning) << "Switch to timed translation because formula has "
170 << (formula.has_time()?"":"no ") << "time, and process has "
171 << (lpsspec.process().has_time()?"":"no ") << "time" << std::endl;
172 timed = true;
173 }
174
175 if (timed)
176 {
177 lps::stochastic_specification lpsspec_timed = lpsspec;
179 generator.add_identifiers(lps::find_identifiers(lpsspec));
180 generator.add_identifiers(state_formulas::find_identifiers(formula));
181 generator.add_identifiers(data::function_and_mapping_identifiers(lpsspec.data()));
182 data::variable T(generator("T"), data::sort_real::real_());
183 lps::detail::make_timed_lps(lpsspec_timed.process(), generator.context());
184 return lps2pbes_algorithm(check_only).run(formula, lpsspec_timed, structured, unoptimized, preprocess_modal_operators, generate_counter_example, T);
185 }
186 else
187 {
188 return lps2pbes_algorithm(check_only).run(formula, lpsspec, structured, unoptimized, preprocess_modal_operators, generate_counter_example);
189 }
190}
191
192/// \brief Translates a linear process specification and a state formula to a PBES. If the solution of the PBES
193/// is true, the formula holds for the specification.
194/// \param lpsspec A linear process specification.
195/// \param formula A modal formula.
196/// \param timed determines whether the timed or untimed variant of the algorithm is chosen.
197/// \param structured use the 'structured' approach of generating equations.
198/// \param unoptimized if true, the resulting PBES is not simplified, if false (default),
199/// the PBES is simplified.
200/// \param preprocess_modal_operators A boolean indicating that the modal operators can be preprocessed to
201/// obtain a more compact PBES.
202/// \param generate_counter_example A boolean indicating that a counter example must be generated.
203/// \return The resulting pbes.
204inline
206 const state_formulas::state_formula& formula,
207 bool timed = false,
208 bool structured = false,
209 bool unoptimized = false,
210 bool preprocess_modal_operators = false,
211 bool generate_counter_example = false,
212 bool check_only = false
213 )
214{
216 formula,
217 timed,
218 structured,
219 unoptimized,
220 preprocess_modal_operators,
221 generate_counter_example,
222 check_only);
223
224}
225
226/// \brief Translates a linear process specification and a state formula to a PBES. If the solution of the PBES
227/// is true, the formula holds for the specification.
228/// \param lpsspec A linear process specification.
229/// \param formspec A modal formula specification.
230/// \param timed determines whether the timed or untimed variant of the algorithm is chosen.
231/// \param structured use the 'structured' approach of generating equations.
232/// \param unoptimized if true, the resulting PBES is not simplified, if false (default),
233/// the PBES is simplified.
234/// \param preprocess_modal_operators A boolean indicating that the modal operators can be preprocessed to
235/// obtain a more compact PBES.
236/// \param generate_counter_example A boolean indicating that a counter example must be generated.
237/// \param check_only If check_only is true, only the formula will be checked, but no PBES is generated
238/// \return The resulting pbes.
239inline
242 bool timed = false,
243 bool structured = false,
244 bool unoptimized = false,
245 bool preprocess_modal_operators = false,
246 bool generate_counter_example = false,
247 bool check_only = false
248 )
249{
250 lps::stochastic_specification lpsspec1 = lpsspec;
251 lpsspec1.data() = data::merge_data_specifications(lpsspec1.data(), formspec.data());
252 lps::normalize_sorts(lpsspec1, lpsspec1.data());
253 lpsspec1.action_labels() = process::merge_action_specifications(lpsspec1.action_labels(), formspec.action_labels());
254 return lps2pbes(lpsspec1, formspec.formula(), timed, structured, unoptimized, preprocess_modal_operators, generate_counter_example, check_only);
255}
256
257/// \brief Applies the lps2pbes algorithm.
258/// \param spec_text A string.
259/// \param formula_text A string.
260/// \param timed Determines whether the timed or untimed version of the translation algorithm is used.
261/// \param structured use the 'structured' approach of generating equations.
262/// \param unoptimized if true, the resulting PBES is not simplified, if false (default),
263/// the PBES is simplified.
264/// \param preprocess_modal_operators A boolean indicating that the modal operators can be preprocessed to
265/// obtain a more compact PBES.
266/// \param generate_counter_example A boolean indicating that a counter example must be generated.
267/// \param check_only If check_only is true, only the formula will be checked, but no PBES is generated
268/// \return The result of the algorithm
269inline
270pbes lps2pbes(const std::string& spec_text,
271 const std::string& formula_text,
272 bool timed = false,
273 bool structured = false,
274 bool unoptimized = false,
275 bool preprocess_modal_operators = false,
276 bool generate_counter_example = false,
277 bool check_only = false
278 )
279{
280 pbes result;
281 lps::stochastic_specification lpsspec = lps::linearise(spec_text);
282 lps::specification temp_lpsspec = remove_stochastic_operators(lpsspec); // Just to check that there are no stochastic operators.
283
284 const bool formula_is_quantitative = false;
285 state_formulas::state_formula f = state_formulas::algorithms::parse_state_formula(formula_text, lpsspec, formula_is_quantitative);
286 return lps2pbes(lpsspec, f, timed, structured, unoptimized, preprocess_modal_operators, generate_counter_example, check_only);
287}
288
289} // namespace mcrl2::pbes_system
290
291
292
293#endif // MCRL2_PBES_LPS2PBES_H
aterm_string(const aterm_string &t) noexcept=default
Identifier generator that stores the identifiers of the context in a set. Using the operator()() and ...
\brief A data variable
Definition variable.h:25
Linear process specification.
stochastic_specification(const specification &other)
Constructor. This constructor is explicit as implicit conversions of this kind is a source of bugs.
Algorithm for translating a state formula and a timed specification to a pbes.
Definition lps2pbes.h:33
pbes run(const state_formulas::state_formula &formula, const lps::stochastic_specification &lpsspec, bool structured=false, bool unoptimized=false, bool preprocess_modal_operators=false, bool generate_counter_example=false, const data::variable &T=data::undefined_real_variable())
Runs the translation algorithm.
Definition lps2pbes.h:80
data::set_identifier_generator m_generator
Definition lps2pbes.h:35
lps2pbes_algorithm(bool check_only=false)
Constructor.
Definition lps2pbes.h:67
void run(const state_formulas::state_formula &f, bool structured, bool unoptimized, std::vector< pbes_equation > &equations, Parameters &parameters)
Definition lps2pbes.h:39
propositional_variable & variable()
Returns the pbes variable of the equation.
parameterized boolean equation system
Definition pbes.h:54
bool is_closed() const
True if the pbes is closed.
Definition pbes.h:239
pbes()=default
Constructor.
\brief A propositional variable instantiation
const core::identifier_string & name() const
const state_formula & formula() const
Returns the formula of the state formula specification.
bool has_time() const
Returns true if the formula is timed.
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:393
Namespace for system defined sort real_.
const basic_sort & real_()
Constructor for sort expression Real.
Definition real1.h:45
data_specification merge_data_specifications(const data_specification &dataspec1, const data_specification &dataspec2)
Merges two data specifications. Throws an exception if conflicts are detected.
const data::variable & undefined_real_variable()
Returns a data variable that corresponds to 'undefined'.
Definition undefined.h:42
The main namespace for the LPS library.
Definition constelm.h:18
specification remove_stochastic_operators(const stochastic_specification &spec)
Converts a stochastic specification to a specification. Throws an exception if non-empty distribution...
bool is_normalized(const pbes &x)
Checks if a PBEs is normalized.
void normalize(pbes &x)
The function normalize brings (embedded) pbes expressions into positive normal form,...
const core::identifier_string & mu_name(const state_formulas::state_formula &f)
The main namespace for the PBES library.
pbes lps2pbes(const lps::stochastic_specification &lpsspec, const state_formulas::state_formula_specification &formspec, bool timed=false, bool structured=false, bool unoptimized=false, bool preprocess_modal_operators=false, bool generate_counter_example=false, bool check_only=false)
Translates a linear process specification and a state formula to a PBES. If the solution of the PBES ...
Definition lps2pbes.h:240
pbes lps2pbes(const lps::specification &lpsspec, const state_formulas::state_formula &formula, bool timed=false, bool structured=false, bool unoptimized=false, bool preprocess_modal_operators=false, bool generate_counter_example=false, bool check_only=false)
Translates a linear process specification and a state formula to a PBES. If the solution of the PBES ...
Definition lps2pbes.h:205
pbes lps2pbes(const std::string &spec_text, const std::string &formula_text, bool timed=false, bool structured=false, bool unoptimized=false, bool preprocess_modal_operators=false, bool generate_counter_example=false, bool check_only=false)
Applies the lps2pbes algorithm.
Definition lps2pbes.h:270
pbes lps2pbes(const lps::stochastic_specification &lpsspec, const state_formulas::state_formula &formula, bool timed=false, bool structured=false, bool unoptimized=false, bool preprocess_modal_operators=false, bool generate_counter_example=false, bool check_only=false)
Translates a linear process specification and a state formula to a PBES. If the solution of the PBES ...
Definition lps2pbes.h:157
void complete_data_specification(pbes &)
Adds all sorts that appear in the PBES p to the data specification of p.
Definition pbes.h:308
bool is_monotonous(const pbes &p)
Returns true if the pbes is monotonous.
bool is_nu(const atermpp::aterm &x)
bool is_mu(const atermpp::aterm &x)