mCRL2
Loading...
Searching...
No Matches
abstract.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/abstract.h
10/// \brief The PBES abstract algorithm.
11
12#ifndef MCRL2_PBES_ABSTRACT_H
13#define MCRL2_PBES_ABSTRACT_H
14
15#include "mcrl2/data/consistency.h"
16#include "mcrl2/pbes/builder.h"
17#include "mcrl2/pbes/detail/pbes_parameter_map.h"
18
19
20
21namespace mcrl2::pbes_system
22{
23
24namespace detail
25{
26
27/// \brief Visitor that implements the pbes-abstract algorithm.
29{
31 using super::apply;
32
36
37 pbes_abstract_builder(const std::vector<data::variable>& selected_variables, bool value_true)
40 {}
41
42 /// \brief Returns true if the m_quantifier_stack contains a given data variable
43 bool is_bound(const data::variable& v) const
44 {
45 for (const data::variable_list& variables: m_quantifier_stack)
46 {
47 for (const data::variable& w: variables)
48 {
49 if (w == v)
50 {
51 return true;
52 }
53 }
54 }
55 return false;
56 }
57
58 /// \brief Adds a sequence of variables to the quantifier stack.
59 void push_variables(const data::variable_list& variables)
60 {
61 m_quantifier_stack.push_back(variables);
62 }
63
64 /// \brief Removes the last added sequence of variables from the quantifier stack.
66 {
67 m_quantifier_stack.pop_back();
68 }
69
70 /// \brief Visit data_expression node
71 template <class T>
72 void apply(T& result, const data::data_expression& d)
73 {
74 std::set<data::variable> FV = data::find_free_variables(d);
75 for (const data::variable& v: FV)
76 {
77 if (std::find(m_selected_variables.begin(), m_selected_variables.end(), v) == m_selected_variables.end())
78 {
79 continue;
80 }
81 if (!is_bound(v))
82 {
83 result = atermpp::down_cast<pbes_expression>(m_value);
84 return;
85 }
86 }
87 result = atermpp::down_cast<pbes_expression>(d);
88 }
89
90 /// \brief Visit forall node
91 template <class T>
92 void apply(T& result, const forall& x)
93 {
95 pbes_expression new_expression;
96 apply(new_expression, x.body());
98 result = make_forall_(x.variables(), new_expression);
99 }
100
101 /// \brief Visit exists node
102 template <class T>
103 void apply(T& result, const exists& x)
104 {
106 pbes_expression new_expression;
107 apply(new_expression, x.body());
109 result = make_exists_(x.variables(), new_expression);
110 }
111};
112
113} // namespace detail
114
115
116/// \brief Algorithm class for the abstract algorithm
118{
119 public:
120 /// \brief Runs the algorithm.
121 /// \param p A PBES.
122 /// \param parameter_map A map containing the parameters that should be expanded by the algorithm.
123 /// \param value_true An indication whether the abstraction is towards true or towards false.
124 void run(pbes& p,
125 const detail::pbes_parameter_map& parameter_map,
126 bool value_true
127 )
128 {
129 for (pbes_equation& eqn: p.equations())
130 {
131 auto j = parameter_map.find(eqn.variable().name());
132 if (j != parameter_map.end())
133 {
134 detail::pbes_abstract_builder builder(j->second, value_true);
135 pbes_expression result;
136 builder.apply(result, eqn.formula());
137 eqn.formula() = result;
138 }
139 }
140 }
141};
142
143} // namespace mcrl2::pbes_system
144
145
146
147#endif // MCRL2_PBES_ABSTRACT_H
data_expression(const data_expression &) noexcept=default
Move semantics.
\brief A data variable
Definition variable.h:25
\brief The existential quantification operator for pbes expressions
const data::variable_list & variables() const
const pbes_expression & body() const
\brief The universal quantification operator for pbes expressions
const pbes_expression & body() const
const data::variable_list & variables() const
Algorithm class for the abstract algorithm.
Definition abstract.h:118
void run(pbes &p, const detail::pbes_parameter_map &parameter_map, bool value_true)
Runs the algorithm.
Definition abstract.h:124
parameterized boolean equation system
Definition pbes.h:54
const data_expression & false_()
Definition consistency.h:98
const data_expression & true_()
Definition consistency.h:91
pbes_expression make_exists_(const data::variable_list &l, const pbes_expression &p)
Make an existential quantification. It checks for an empty variable list, which is not allowed.
pbes_expression make_forall_(const data::variable_list &l, const pbes_expression &p)
Make a universal quantification. It checks for an empty variable list, which is not allowed.
Visitor that implements the pbes-abstract algorithm.
Definition abstract.h:29
bool is_bound(const data::variable &v) const
Returns true if the m_quantifier_stack contains a given data variable.
Definition abstract.h:43
pbes_abstract_builder(const std::vector< data::variable > &selected_variables, bool value_true)
Definition abstract.h:37
void apply(T &result, const data::data_expression &d)
Visit data_expression node.
Definition abstract.h:72
void apply(T &result, const exists &x)
Visit exists node.
Definition abstract.h:103
void apply(T &result, const forall &x)
Visit forall node.
Definition abstract.h:92
std::vector< data::variable_list > m_quantifier_stack
Definition abstract.h:33
const std::vector< data::variable > m_selected_variables
Definition abstract.h:34
void pop_variables()
Removes the last added sequence of variables from the quantifier stack.
Definition abstract.h:65
void push_variables(const data::variable_list &variables)
Adds a sequence of variables to the quantifier stack.
Definition abstract.h:59