mCRL2
Loading...
Searching...
No Matches
selection.h
Go to the documentation of this file.
1// Author(s): Jeroen van der Wulp
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//
11
12#ifndef MCRL2_DATA_SELECTION_H
13#define MCRL2_DATA_SELECTION_H
14
16#include "mcrl2/data/find.h"
17#include "mcrl2/data/fset.h"
18
19namespace mcrl2
20{
21
22namespace data
23{
24
37{
38 private:
39
40 std::set< function_symbol > m_used_symbols;
41
42 bool add_all;
43
45 {
46 m_used_symbols.insert(f);
47 }
48
49 template < typename Range >
50 void add_symbols(Range const& r)
51 {
52 m_used_symbols.insert(r.begin(), r.end());
53 }
54
55 protected:
57 {
58 // Always add if:Bool#Bool#Bool->Bool; This symbol is used in the prover.
60 // Always add and,or:Bool#Bool->Bool and not:Bool->Bool; This symbol is generated when eliminating quantifiers
64
65 // Add all constructors of all sorts as they may be used when enumerating over these sorts
66 std::set< sort_expression > sorts(specification.sorts().begin(),specification.sorts().end());
67 for (const sort_expression& sort: sorts)
68 {
69 add_symbols(specification.constructors(sort));
70 // Always add equality and inequality of each sort. The one point rewriter is using this for instance.
71 add_symbol(equal_to(sort));
73
74 // Always add insert for an FSet(S) function, as it is used when enumerating the elements of an FSet.
75 if (sort_fset::is_fset(sort))
76 {
77 const container_sort &s = atermpp::down_cast<container_sort>(sort);
79 }
80
81 // Always add the if:Bool#S#S->S for every sort as enumerating elements over function sorts S1 #... # S # ... # Sn -> S
82 // rewriting over functions of this shape.
83 add_symbol(if_(sort));
84 }
85
86 std::map< data_equation, std::set< function_symbol > > symbols_for_equation;
87
88 for (const data_equation& equation: specification.equations())
89 {
90 std::set< function_symbol > used_symbols;
91
92 data::detail::make_find_function_symbols_traverser<data::data_expression_traverser>(std::inserter(used_symbols, used_symbols.end())).apply(equation.lhs());
93 symbols_for_equation[equation].swap(used_symbols);
94 }
95
96 /* Calculate the closure under the function symbols that can be introduced by applying equations, such that all
97 the function symbols that can occur during rewriting are present in the datatype */
98 std::vector<bool> equations_of_which_symbols_have_been_added(specification.equations().size(),false);
99 bool stable=false;
100 while (!stable)
101 {
102 stable=true;
103 std::size_t equation_count=0;
104 for (const data_equation& e: specification.equations())
105 {
106 if (!equations_of_which_symbols_have_been_added[equation_count] &&
107 std::includes(m_used_symbols.begin(), m_used_symbols.end(), symbols_for_equation[e].begin(), symbols_for_equation[e].end()))
108 {
109 add_function_symbols(e.rhs());
110 add_function_symbols(e.condition());
111 equations_of_which_symbols_have_been_added[equation_count]=true;
112 stable=false;
113 }
114 equation_count++;
115 }
116 }
117 }
118
119 public:
120
123 {
124 if (add_all)
125 {
126 return true;
127 }
128 return m_used_symbols.count(f)>0;
129 }
130
132 bool operator()(const data_equation& e) const
133 {
134 if (add_all)
135 {
136 return true;
137 }
138
139 std::set< function_symbol > used_symbols;
140
141 data::detail::make_find_function_symbols_traverser<data::data_expression_traverser>(std::inserter(used_symbols, used_symbols.end())).apply(e.lhs());
142
143 return std::includes(m_used_symbols.begin(), m_used_symbols.end(), used_symbols.begin(), used_symbols.end());
144 }
145
147 {
148 data::detail::make_find_function_symbols_traverser<data::data_expression_traverser>(std::inserter(m_used_symbols, m_used_symbols.end())).apply(t);
149 }
150
153 add_all(true)
154 {}
155
157 template <typename Range>
158 used_data_equation_selector(data_specification const& data_spec, Range const& context):
159 add_all(false)
160 {
161 add_symbols(context);
163 }
164
166 const std::set<function_symbol>& function_symbols,
167 const std::set<data::variable>& global_variables,
168 const bool do_not_remove_function_symbols
169 ):add_all(do_not_remove_function_symbols)
170 {
171 // Compensate for symbols that could be used as part of an instantiation of free variables
172 for (const variable& global_variable: global_variables)
173 {
174 add_symbols(specification.constructors(global_variable.sort()));
175 add_symbols(specification.mappings(global_variable.sort()));
176 }
177 m_used_symbols.insert(function_symbols.begin(), function_symbols.end());
178 add_data_specification_symbols(specification);
179 }
180
183 add_all(true)
184 {
185 /* add_symbols(specification.constructors());
186 add_symbols(specification.mappings());
187 add_data_specification_symbols(specification); */
188 }
189};
190
191} // namespace data
192
193} // namespace mcrl2
194
195#endif // MCRL2_DATA_SELECTION_H
\brief A container sort
const sort_expression & element_sort() const
\brief A data equation
const data_expression & lhs() const
const std::set< data_equation > & equations() const
Gets all equations in this specification including those that are system defined.
const function_symbol_vector & constructors() const
Gets all constructors including those that are system defined.
const function_symbol_vector & mappings() const
Gets all mappings in this specification including those that are system defined.
\brief A function symbol
\brief A sort expression
const std::set< sort_expression > & sorts() const
Gets the normalised sort declarations including those that are system defined. This is the set with a...
Component for selecting a subset of equations that are actually used in an encompassing specification...
Definition selection.h:37
used_data_equation_selector(const data_specification &specification, const std::set< function_symbol > &function_symbols, const std::set< data::variable > &global_variables, const bool do_not_remove_function_symbols)
Definition selection.h:165
void add_data_specification_symbols(const data_specification &specification)
Definition selection.h:56
used_data_equation_selector()
default constructor
Definition selection.h:152
used_data_equation_selector(const data_specification &)
select all equations
Definition selection.h:182
void add_function_symbols(const data_expression &t)
Definition selection.h:146
used_data_equation_selector(data_specification const &data_spec, Range const &context)
context is a range of function symbols
Definition selection.h:158
void add_symbol(const function_symbol &f)
Definition selection.h:44
bool operator()(const data_equation &e) const
Check whether data equation relates to used symbols, and therefore is important.
Definition selection.h:132
bool operator()(const data::function_symbol &f) const
Check whether the symbol is used.
Definition selection.h:122
std::set< function_symbol > m_used_symbols
Definition selection.h:40
\brief A data variable
Definition variable.h:28
Search functions of the data library.
The class data_specification.
The standard sort fset.
const basic_sort & bool_()
Constructor for sort expression Bool.
Definition bool.h:44
const function_symbol & and_()
Constructor for function symbol &&.
Definition bool.h:235
const function_symbol & or_()
Constructor for function symbol ||.
Definition bool.h:299
const function_symbol & not_()
Constructor for function symbol !.
Definition bool.h:173
function_symbol insert(const sort_expression &s)
Constructor for function symbol @fset_insert.
Definition fset1.h:107
bool is_fset(const sort_expression &e)
Recogniser for sort expression FSet(s)
Definition fset1.h:52
function_symbol not_equal_to(const sort_expression &s)
Constructor for function symbol !=.
Definition standard.h:163
function_symbol equal_to(const sort_expression &s)
Constructor for function symbol ==.
Definition standard.h:126
function_symbol if_(const sort_expression &s)
Constructor for function symbol if.
Definition standard.h:200
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72