mCRL2
Loading...
Searching...
No Matches
structured_sort.h
Go to the documentation of this file.
1// Author(s): Jeroen Keiren, 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_STRUCTURED_SORT_H
13#define MCRL2_DATA_STRUCTURED_SORT_H
14
18
19namespace mcrl2
20{
21
22namespace data
23{
24
26// declare for friendship
27namespace sort_fset
28{
32} // namespace sort_fset
33
34// declare for friendship
35namespace sort_fbag
36{
40} // namespace sort_fbag
42
53//--- start generated class structured_sort ---//
56{
57 public:
60 : sort_expression(core::detail::default_values::SortStruct)
61 {}
62
65 explicit structured_sort(const atermpp::aterm& term)
66 : sort_expression(term)
67 {
69 }
70
73 : sort_expression(atermpp::aterm(core::detail::function_symbol_SortStruct(), constructors))
74 {}
75
77 template <typename Container>
79 : sort_expression(atermpp::aterm(core::detail::function_symbol_SortStruct(), structured_sort_constructor_list(constructors.begin(), constructors.end())))
80 {}
81
83 structured_sort(const structured_sort&) noexcept = default;
84 structured_sort(structured_sort&&) noexcept = default;
85 structured_sort& operator=(const structured_sort&) noexcept = default;
86 structured_sort& operator=(structured_sort&&) noexcept = default;
87
89 {
90 return atermpp::down_cast<structured_sort_constructor_list>((*this)[0]);
91 }
92//--- start user section structured_sort ---//
93
94 friend class data_specification;
95 friend class sort_specification;
96
97 private:
98
105
107 {
108 return !s.recogniser().empty();
109 }
110
112 {
113 function_symbol to_pos_function_("@to_pos", make_function_sort_(s, sort_pos::pos()));
114 return to_pos_function_;
115 }
116
118 {
119 function_symbol equal_arguments_function_("@equal_arguments", make_function_sort_(s, s, sort_bool::bool_()));
120 return equal_arguments_function_;
121 }
122
124 {
125 function_symbol smaller_arguments_function_("@less_arguments", make_function_sort_(s, s, sort_bool::bool_()));
126 return smaller_arguments_function_;
127 }
128
130 {
131 function_symbol smaller_equal_arguments_function_("@less_equal_arguments", make_function_sort_(s, s, sort_bool::bool_()));
132 return smaller_equal_arguments_function_;
133 }
134
136 {
138 for (const auto & i : constructors())
139 {
140 result.push_back(i.constructor_function(s));
141 }
142 return result;
143 }
144
146 {
148 result.push_back(to_pos_function(s));
149 result.push_back(equal_arguments_function(s));
150 result.push_back(smaller_arguments_function(s));
151 result.push_back(smaller_equal_arguments_function(s));
152 return result;
153 }
154
156 {
159 {
160 function_symbol_vector projections(i.projection_functions(s));
161
162 for (function_symbol_vector::const_iterator j = projections.begin(); j != projections.end(); ++j)
163 {
164 result.push_back(*j);
165 }
166 }
167 return result;
168 }
169
171 {
174 {
175 if (i.recogniser() != core::empty_identifier_string())
176 {
177 result.push_back(i.recogniser_function(s));
178 }
179 }
180 return result;
181 }
182
183
185 {
187
188 // First add an equation "equal_arguments(v,v)=true", as it is sometimes useful.
189 variable v("v",s);
191
192 // give every constructor an index.
193 std::size_t index = 1;
195 {
196 // constructor does not take arguments
197 if (i->arguments().empty())
198 {
199 result.push_back(data_equation(to_pos_function(s)(i->constructor_function(s)), sort_pos::pos(index)));
200 result.push_back(data_equation(equal_arguments_function(s)(i->constructor_function(s),i->constructor_function(s)), sort_bool::true_()));
201 result.push_back(data_equation(smaller_arguments_function(s)(i->constructor_function(s),i->constructor_function(s)), sort_bool::false_()));
202 result.push_back(data_equation(smaller_equal_arguments_function(s)(i->constructor_function(s),i->constructor_function(s)), sort_bool::true_()));
203 }
204 else
205 {
206 set_identifier_generator generator;
207
208 std::vector< variable > variables1;
209 std::vector< variable > variables2;
210 for (const structured_sort_constructor_argument& k: i->arguments())
211 {
212 variables1.push_back(variable(generator("v"), k.sort()));
213 variables2.push_back(variable(generator("w"), k.sort()));
214 }
215 application instance1(i->constructor_function(s), variables1);
216 application instance2(i->constructor_function(s), variables2);
217
218 result.push_back(data_equation(variables1, sort_bool::true_(), to_pos_function(s)(instance1), sort_pos::pos(index)));
219
220 // constructors are the same, generate right hand sides of equal_arguments_function, etc.
221 variable_vector::const_reverse_iterator end(variables1.rend());
222 variable_vector::const_reverse_iterator k(variables1.rbegin());
223 variable_vector::const_reverse_iterator l(variables2.rbegin());
224
225 data_expression right_equal = equal_to(*k, *l);
226 data_expression right_smaller = less(*k, *l);
227 data_expression right_smaller_equal = less_equal(*k, *l);
228
229 for (++l, ++k; k != end; ++l, ++k)
230 {
231 // Constructors have one or more arguments:
232 // - rhs for c(x0,...,xn) == c(y0,..,yn):
233 // x0 == y0 && ... && xn == yn
234 right_equal = sort_bool::and_(equal_to(*k, *l), right_equal);
235 // - rhs for c(x0,...,xn) < c(y0,..,yn):
236 // x0 < y0 , when n = 0
237 // x0 < y0 || (x0 == y0 && x1 < y1) , when n = 1
238 // x0 < y0 || (x0 == y0 && (x1 < y1 || (x1 == y1 && x2 < y2))) , when n = 2
239 // etcetera
240 right_smaller = sort_bool::or_(less(*k, *l),
241 sort_bool::and_(equal_to(*k, *l), right_smaller));
242 // - rhs for c(x0,...,xn) <= c(y0,..,yn):
243 // x0 <= y0 , when n = 0
244 // x0 < y0 || (x0 == y0 && x1 <= y1) , when n = 1
245 // x0 < y0 || (x0 == y0 && (x1 < y1 || (x1 == y1 && x2 <= y2))), when n = 2
246 // etcetera
247 right_smaller_equal = sort_bool::or_(less(*k, *l),
248 sort_bool::and_(equal_to(*k, *l), right_smaller_equal));
249 }
250
251 application left_equal = application(equal_arguments_function(s), instance1, instance2);
252 application left_smaller = application(smaller_arguments_function(s), instance1, instance2);
253 application left_smaller_equal = application(smaller_equal_arguments_function(s), instance1, instance2);
254 variables1.insert(variables1.end(),variables2.begin(),variables2.end());
255 result.push_back(data_equation(variables1, sort_bool::true_(),left_equal, right_equal));
256 result.push_back(data_equation(variables1, sort_bool::true_(),left_smaller, right_smaller));
257 result.push_back(data_equation(variables1, sort_bool::true_(),left_smaller_equal, right_smaller_equal));
258 }
259 }
260 return result;
261 }
262
264 {
266
267 variable x("x", s);
268 variable y("y", s);
269 variable_list xy = { x, y };
270 application to_pos_x = application(to_pos_function(s), x);
271 application to_pos_y = application(to_pos_function(s), y);
272 application equal_arguments_xy = application(equal_arguments_function(s), x, y);
273 application smaller_arguments_xy = application(smaller_arguments_function(s), x, y);
274 application smaller_equal_arguments_xy = application(smaller_equal_arguments_function(s), x, y);
275 result.push_back(data_equation(xy, equal_to(to_pos_x, to_pos_y), equal_to(x,y), equal_arguments_xy));
276 result.push_back(data_equation(xy, not_equal_to(to_pos_x, to_pos_y), equal_to(x,y), sort_bool::false_()));
277 result.push_back(data_equation(xy, less(to_pos_x, to_pos_y), less(x,y), sort_bool::true_()));
278 result.push_back(data_equation(xy, equal_to(to_pos_x, to_pos_y), less(x,y), smaller_arguments_xy));
279 result.push_back(data_equation(xy, greater(to_pos_x, to_pos_y), less(x,y), sort_bool::false_()));
280 result.push_back(data_equation(xy, less(to_pos_x, to_pos_y), less_equal(x,y), sort_bool::true_()));
281 result.push_back(data_equation(xy, equal_to(to_pos_x, to_pos_y), less_equal(x,y), smaller_equal_arguments_xy));
282 result.push_back(data_equation(xy, greater(to_pos_x, to_pos_y), less_equal(x,y), sort_bool::false_()));
283 // (JK) The following encoding of the equations would be more desirable; however,
284 // rewriting fails if we use this.
285/*
286 result.push_back(data_equation(xy, sort_bool::true_(), equal_to(x,y), sort_bool::and_(equal_to(to_pos_x, to_pos_y), equal_arguments_xy)));
287 result.push_back(data_equation(xy, sort_bool::true_(), less(x,y), sort_bool::or_(less(to_pos_x, to_pos_y), sort_bool::and_(equal_to(to_pos_x, to_pos_y), smaller_arguments_xy))));
288 result.push_back(data_equation(xy, sort_bool::true_(), less_equal(x,y), sort_bool::or_(less(to_pos_x, to_pos_y), sort_bool::and_(equal_to(to_pos_x, to_pos_y), smaller_equal_arguments_xy))));
289*/
290 return result;
291 }
292
294 {
296
297 for (const auto & i : constructors())
298 {
299 if (!i.arguments().empty())
300 {
301 structured_sort_constructor_argument_list arguments(i.arguments());
302
303 set_identifier_generator generator;
304
305 std::vector< variable > variables;
306
307 // Create variables for equation
308 for (const auto & argument : arguments)
309 {
310 variables.push_back(variable(generator("v"), argument.sort()));
311 }
312
313 std::vector< variable >::const_iterator v = variables.begin();
314
315 for (structured_sort_constructor_argument_list::const_iterator j(arguments.begin()); j != arguments.end(); ++j, ++v)
316 {
317 if (j->name() != core::empty_identifier_string())
318 {
319 application lhs(function_symbol(j->name(), make_function_sort_(s, j->sort()))
320 (application(i.constructor_function(s), variables)));
321
322 result.push_back(data_equation(variables, lhs, *v));
323 }
324 }
325 }
326 }
327
328 return result;
329 }
330
332 {
334
336
337 for (structured_sort_constructor_list::const_iterator i = cl.begin(); i != cl.end(); ++i)
338 {
339 for (const auto & j : cl)
340 {
341 if (j.recogniser() != core::empty_identifier_string())
342 {
343 data_expression right = (*i == j) ? sort_bool::true_() : sort_bool::false_();
344
345 if (i->arguments().empty())
346 {
347 result.push_back(data_equation(j.recogniser_function(s)(i->constructor_function(s)), right));
348 }
349 else
350 {
351
352 set_identifier_generator generator;
353
354 structured_sort_constructor_argument_list arguments(i->arguments());
355
356 // Create variables for equation
357 variable_vector variables;
358
359 for (const auto & argument : arguments)
360 {
361 variables.push_back(variable(generator("v"), argument.sort()));
362 }
363
364 result.push_back(data_equation(variables, j.recogniser_function(s)(
365 application(i->constructor_function(s), variables)), right));
366 }
367 }
368 }
369 }
370
371 return result;
372 }
373
374public:
378 {
379 return constructor_functions(*this);
380 }
381
385 {
386 return comparison_functions(*this);
387 }
388
392 {
393 return projection_functions(*this);
394 }
395
396
400 {
401 return recogniser_functions(*this);
402 }
403
407 {
408 return constructor_equations(*this);
409 }
410
415 {
416 return comparison_equations(*this);
417 }
418
422 {
423 return projection_equations(*this);
424 }
425
430 {
431 return recogniser_equations(*this);
432 }
433//--- end user section structured_sort ---//
434};
435
438template <class... ARGUMENTS>
439inline void make_structured_sort(atermpp::aterm& t, const ARGUMENTS&... args)
440{
442}
443
446
448typedef std::vector<structured_sort> structured_sort_vector;
449
450// prototype declaration
451std::string pp(const structured_sort& x);
452
457inline
458std::ostream& operator<<(std::ostream& out, const structured_sort& x)
459{
460 return out << data::pp(x);
461}
462
465{
466 t1.swap(t2);
467}
468//--- end generated class structured_sort ---//
469
470} // namespace data
471
472} // namespace mcrl2
473
474#endif // MCRL2_DATA_STRUCTURED_SORT_H
475
const_iterator end() const
Returns a const_iterator pointing past the last argument.
Definition aterm.h:172
aterm()
Default constructor.
Definition aterm.h:48
const_iterator begin() const
Returns an iterator pointing to the first argument.
Definition aterm.h:165
bool empty() const
Returns true if the term has no arguments.
Definition aterm.h:158
Iterator for term_list.
A list of aterm objects.
Definition aterm_list.h:24
const_iterator end() const
Returns a const_iterator pointing to the end of the term_list.
Definition aterm_list.h:282
const_iterator begin() const
Returns a const_iterator pointing to the beginning of the term_list.
Definition aterm_list.h:275
void swap(unprotected_aterm_core &t) noexcept
Swaps this term with its argument.
Definition aterm_core.h:152
An application of a data expression to a number of arguments.
\brief A data equation
\brief A function symbol
Identifier generator that stores the identifiers of the context in a set. Using the operator()() and ...
\brief A sort expression
\brief An argument of a constructor of a structured sort
\brief A constructor for a structured sort
const core::identifier_string & recogniser() const
data_equation_vector recogniser_equations() const
Generate equations for the recognisers of this sort, assuming that this sort is referred to with s.
function_symbol smaller_arguments_function(const sort_expression &s) const
function_symbol_vector recogniser_functions(const sort_expression &s) const
function_symbol to_pos_function(const sort_expression &s) const
structured_sort(const structured_sort &) noexcept=default
Move semantics.
function_symbol_vector constructor_functions(const sort_expression &s) const
data_equation_vector comparison_equations() const
Returns the equations for the functions used to implement comparison operators on this sort....
data_equation_vector constructor_equations(const sort_expression &s) const
data_equation_vector recogniser_equations(const sort_expression &s) const
static bool has_recogniser(structured_sort_constructor const &s)
data_equation_vector projection_equations() const
Generate equations for the projection functions of this sort.
function_symbol equal_arguments_function(const sort_expression &s) const
structured_sort(const Container &constructors, typename atermpp::enable_if_container< Container, structured_sort_constructor >::type *=nullptr)
\brief Constructor Z2.
const structured_sort_constructor_list & constructors() const
function_symbol_vector constructor_functions() const
Returns the constructor functions of this sort, such that the result can be used by the rewriter.
function_symbol_vector projection_functions() const
Returns the projection functions of this sort, such that the result can be used by the rewriter.
function_symbol_vector comparison_functions(const sort_expression &s) const
function_symbol_vector comparison_functions() const
Returns the additional functions of this sort, used to implement its comparison operators.
data_equation_vector comparison_equations(const sort_expression &s) const
structured_sort(const structured_sort_constructor_list &constructors)
\brief Constructor Z14.
function_symbol_vector recogniser_functions() const
Returns the recogniser functions of this sort, such that the result can be used by the rewriter.
function_symbol_vector projection_functions(const sort_expression &s) const
structured_sort()
\brief Default constructor X3.
structured_sort(structured_sort &&) noexcept=default
data_equation_vector projection_equations(const sort_expression &s) const
structured_sort(const atermpp::aterm &term)
data_equation_vector constructor_equations() const
Returns the equations for ==, < and <= for this sort, such that the result can be used by the rewrite...
function_symbol smaller_equal_arguments_function(const sort_expression &s) const
\brief A data variable
Definition variable.h:28
The main namespace for the aterm++ library.
Definition algorithm.h:21
void make_term_appl(Term &target, const function_symbol &sym, ForwardIterator begin, ForwardIterator end)
Constructor an aterm in a variable based on a function symbol and an forward iterator providing the a...
Definition aterm.h:213
bool check_term_SortStruct(const Term &t)
const atermpp::function_symbol & function_symbol_SortStruct()
identifier_string empty_identifier_string()
Provides the empty identifier string.
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 & false_()
Constructor for function symbol false.
Definition bool.h:109
const function_symbol & or_()
Constructor for function symbol ||.
Definition bool.h:299
const function_symbol & true_()
Constructor for function symbol true.
Definition bool.h:77
function_symbol_vector fbag_generate_constructors_code(const sort_expression &s)
Give all system defined constructors for fbag.
Definition fbag1.h:165
function_symbol_vector fbag_generate_functions_code(const sort_expression &s)
Give all system defined mappings for fbag.
Definition fbag1.h:777
data_equation_vector fbag_generate_equations_code(const sort_expression &s)
Give all system defined equations for fbag.
Definition fbag1.h:914
function_symbol_vector fset_generate_constructors_code(const sort_expression &s)
Give all system defined constructors for fset.
Definition fset1.h:161
function_symbol_vector fset_generate_functions_code(const sort_expression &s)
Give all system defined mappings for fset.
Definition fset1.h:645
data_equation_vector fset_generate_equations_code(const sort_expression &s)
Give all system defined equations for fset.
Definition fset1.h:778
const basic_sort & pos()
Constructor for sort expression Pos.
Definition pos1.h:45
function_symbol less_equal(const sort_expression &s)
Constructor for function symbol <=.
Definition standard.h:277
void swap(abstraction &t1, abstraction &t2)
\brief swap overload
function_symbol not_equal_to(const sort_expression &s)
Constructor for function symbol !=.
Definition standard.h:163
function_symbol less(const sort_expression &s)
Constructor for function symbol <.
Definition standard.h:240
std::vector< data_equation > data_equation_vector
\brief vector of data_equations
std::vector< structured_sort > structured_sort_vector
\brief vector of structured_sorts
std::vector< variable > variable_vector
\brief vector of variables
Definition variable.h:89
function_sort make_function_sort_(const sort_expression &dom1, const sort_expression &codomain)
Convenience constructor for function sort with domain size 1.
std::string pp(const abstraction &x)
Definition data.cpp:39
atermpp::term_list< structured_sort > structured_sort_list
\brief list of structured_sorts
function_symbol equal_to(const sort_expression &s)
Constructor for function symbol ==.
Definition standard.h:126
void make_structured_sort(atermpp::aterm &t, const ARGUMENTS &... args)
std::vector< function_symbol > function_symbol_vector
\brief vector of function_symbols
std::ostream & operator<<(std::ostream &out, const abstraction &x)
Definition abstraction.h:94
function_symbol greater(const sort_expression &s)
Constructor for function symbol >
Definition standard.h:314
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
The classes set_identifier_generator and multiset_identifier_generator.
Provides utilities for working with data expressions of standard sorts.
The classes structured_sort_constructor.