mCRL2
Loading...
Searching...
No Matches
enumerator.h
Go to the documentation of this file.
1// Author(s): Wieger Wesselink, Jan Friso Groote
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/data/enumerator.h
10/// \brief The class enumerator.
11
12#ifndef MCRL2_DATA_ENUMERATOR_H
13#define MCRL2_DATA_ENUMERATOR_H
14
15#include <boost/iterator/iterator_facade.hpp>
16#include "mcrl2/utilities/math.h"
17#include "mcrl2/atermpp/standard_containers/deque.h"
18#include "mcrl2/core/detail/print_utility.h"
19#include "mcrl2/data/rewriter.h"
20#include "mcrl2/data/concepts.h"
21#include "mcrl2/data/substitutions/enumerator_substitution.h"
22
23namespace mcrl2::data
24{
25
26namespace detail
27{
28
29inline
30data_expression make_set_(std::size_t function_index, const sort_expression& element_sort, const data_expression_vector& set_elements)
31{
32 data_expression result = sort_fset::empty(element_sort);
33 for (const data_expression& set_element: set_elements)
34 {
35 if (function_index % 2 == 1)
36 {
37 result=sort_fset::insert(element_sort, set_element, result);
38 }
39 function_index = function_index / 2;
40 }
41 return result;
42}
43
44inline
45data_expression make_if_expression_(std::size_t& function_index,
46 const std::size_t argument_index,
47 const std::vector<data_expression_vector>& data_domain_expressions,
48 const data_expression_vector& codomain_expressions,
49 const variable_vector& parameters)
50{
51 if (argument_index == data_domain_expressions.size())
52 {
53 std::size_t result_expression_index = function_index % codomain_expressions.size();
54 function_index = function_index / codomain_expressions.size();
55 return codomain_expressions[result_expression_index];
56 }
57
58 data_expression result;
59 const data_expression_vector& current_enumerated_elements = data_domain_expressions[argument_index];
60 for (data_expression_vector::const_reverse_iterator i = current_enumerated_elements.rbegin(); i != current_enumerated_elements.rend(); ++i)
61 {
62 if (i == current_enumerated_elements.rbegin())
63 {
64 result = make_if_expression_(function_index, argument_index + 1, data_domain_expressions, codomain_expressions, parameters);
65 }
66 else
67 {
68 const data_expression lhs = make_if_expression_(function_index, argument_index + 1, data_domain_expressions, codomain_expressions, parameters);
69 if (lhs != result) // Optimize: if the lhs and rhs are equal, return the rhs.
70 {
71 result = if_(equal_to(parameters[argument_index], *i), lhs, result);
72 }
73 }
74 }
75 return result;
76}
77
78/// \brief Computes the elements of a finite set sort, and puts them in result. If there are too many elements, false is returned.
79template <class Rewriter, IsSubstitution MutableSubstitution>
81 const data_specification& dataspec,
82 Rewriter datar, MutableSubstitution& sigma,
83 data_expression_vector& result,
85{
86 // TODO: This routine would really benefit from caching the calculated set of elements, as the same set is often generated
87 // over and over again.
88 data_expression_vector all_element_expressions = enumerate_expressions(sort.element_sort(), dataspec, datar, id_generator);
89 if (all_element_expressions.size() >= 32) // If there are at least 2^32 functions, then enumerating them makes little sense.
90 {
91 return false;
92 }
93 if (all_element_expressions.size() > 16) // If there are more than 2^16 functions, provide a warning.
94 {
95 mCRL2log(log::log_level_t::warning) << "Generate 2^" << all_element_expressions.size() << " sets to enumerate sort " << sort << "\n";
96 }
97 const std::size_t number_of_sets = utilities::power_size_t(2, all_element_expressions.size());
98 for (std::size_t i = 0; i < number_of_sets; ++i)
99 {
100 result.push_back(datar(make_set_(i, sort.element_sort(), all_element_expressions), sigma));
101 }
102 return true;
103}
104
105/// \brief Computes the elements of a finite function sort, and puts them in result. If there are too many elements, false is returned.
106template <class Rewriter>
109 const data::data_specification& dataspec,
110 Rewriter datar,
111 data_expression_vector& result,
112 variable_list& function_parameter_list
113 )
114{
115 data_expression_vector codomain_expressions = enumerate_expressions(sort.codomain(), dataspec, datar, id_generator);
116 std::vector<data_expression_vector> domain_expressions;
117 std::size_t total_domain_size = 1;
118 variable_vector function_parameters;
119
120 for (const sort_expression& s: sort.domain())
121 {
122 domain_expressions.push_back(enumerate_expressions(s, dataspec, datar, id_generator));
123 total_domain_size = total_domain_size * domain_expressions.back().size();
124 function_parameters.emplace_back(id_generator(), s);
125 }
126
127 if (total_domain_size * utilities::ceil_log2(codomain_expressions.size()) >= 32) // If there are at least 2^32 functions, then enumerating them makes little sense.
128 {
129 return false;
130 }
131
132 if (total_domain_size * utilities::ceil_log2(codomain_expressions.size()) > 16) // If there are more than 2^16 functions, provide a warning.
133 {
134 mCRL2log(log::log_level_t::warning) << "Generate " << codomain_expressions.size() << "^" << total_domain_size << " functions to enumerate sort " << sort << "\n";
135 }
136
137 function_parameter_list = variable_list(function_parameters.begin(), function_parameters.end());
138
139 const std::size_t number_of_functions = utilities::power_size_t(codomain_expressions.size(), total_domain_size);
140
141 if (number_of_functions == 1)
142 {
143 result.push_back(abstraction(lambda_binder(), function_parameter_list, codomain_expressions.front()));
144 }
145 else
146 {
147 for (std::size_t i = 0; i < number_of_functions; ++i)
148 {
149 std::size_t function_index = i; // function_index is changed in make_if_expression. A copy is therefore required.
150 result.push_back(abstraction(lambda_binder(), function_parameter_list, make_if_expression_(function_index, 0, domain_expressions, codomain_expressions, function_parameters)));
151 }
152 }
153 return true;
154}
155
156template <typename Rewriter>
158 const Rewriter& rewr,
159 const sort_expression& sort,
160 std::list<sort_expression>& parents)
161{
162 assert(sort == normalize_sorts(sort,dataspec));
164 {
165 return false;
166 }
167 else if (is_function_sort(sort))
168 {
169 const function_sort& func = atermpp::down_cast<function_sort>(sort);
171 data_expression_vector expr_vec;
172 variable_list var_list;
173 return dataspec.is_certainly_finite(func) &&
174 detail::compute_finite_function_sorts(func, id_gen, dataspec, rewr, expr_vec, var_list);
175 }
176 else if (sort_set::is_set(sort) || sort_fset::is_fset(sort))
177 {
179 data_expression_vector expr_vec;
180 mutable_indexed_substitution<> mut_sub;
181 return dataspec.is_certainly_finite(atermpp::down_cast<container_sort>(sort).element_sort()) &&
182 (!sort_fset::is_fset(sort) || detail::compute_finite_set_elements(atermpp::down_cast<container_sort>(sort), dataspec, rewr, mut_sub, expr_vec, id_gen));
183 }
184 else
185 {
186 const function_symbol_vector& constructors = dataspec.constructors(sort, true);
187 if (constructors.empty())
188 {
189 return false;
190 }
191 else
192 {
193 if (std::find(parents.begin(), parents.end(), sort) != parents.end())
194 {
195 return true;
196 }
197 parents.push_back(sort);
198 bool result = std::all_of(constructors.begin(), constructors.end(), [&](const function_symbol& constructor)
199 {
200 return !is_function_sort(constructor.sort()) ||
201 std::all_of(atermpp::down_cast<function_sort>(constructor.sort()).domain().begin(), atermpp::down_cast<function_sort>(constructor.sort()).domain().end(),
202 [&](const sort_expression& arg_sort){ return is_enumerable(dataspec, rewr, arg_sort, parents); });
203 });
204 parents.pop_back();
205 return result;
206 }
207 }
208}
209
210} // namespace detail
211
212/// \brief Enumerator exception
214{
215 explicit enumerator_error(const std::string& message): mcrl2::runtime_error(message)
216 {}
217};
218
219template <typename Rewriter>
220static bool is_enumerable(const data_specification& dataspec, const Rewriter& rewr, const sort_expression& sort)
221{
222 std::list<sort_expression> parentstack;
223 return detail::is_enumerable(dataspec, rewr, sort, parentstack);
224}
225
226/// \brief The default element for the todo list of the enumerator
227template <typename Expression = data::data_expression>
229{
230 protected:
231 data::variable_list v;
232 Expression phi;
233
234 public:
235 using expression_type = Expression;
236
237 /// \brief Default constructor
239
240 /// \brief Constructs the element (v, phi)
241 enumerator_list_element(data::variable_list v_, const Expression& phi_)
242 : v(std::move(v_)), phi(phi_)
243 {}
244
245 /// \brief Constructs the element (v, phi)
246 enumerator_list_element(data::variable_list v_,
247 const Expression& phi_,
249 )
250 : v(std::move(v_)), phi(phi_)
251 {}
252
253 /// \brief Constructs the element (v, phi)
254 enumerator_list_element(data::variable_list v_,
255 const Expression& phi_,
257 const data::variable&,
258 const data::data_expression&
259 )
260 : v(std::move(v_)), phi(phi_)
261 {}
262
263 const data::variable_list& variables() const
264 {
265 return v;
266 }
267
268 const Expression& expression() const
269 {
270 return phi;
271 }
272
273 Expression& expression()
274 {
275 return phi;
276 }
277
278 bool is_solution() const
279 {
280 return v.empty();
281 }
282
283 /// \brief Invalidates the element, by giving phi an undefined value
285 {
286 phi = atermpp::down_cast<Expression>(data::undefined_data_expression());
287 }
288
289 /// \brief Returns true if the element is valid. If it becomes false, this is used to signal that
290 /// the enumeration has been aborted.
291 bool is_valid() const
292 {
294 }
295
296 /// \brief The following function is needed to mark the aterms in this class,
297 /// when elements of this class are used in an atermpp standard container.
298 /// When garbage collection of aterms is taking place this function is
299 /// called for all elements of this class in the atermpp container.
300 void mark(atermpp::term_mark_stack& todo) const
301 {
302 mark_term(v,todo);
303 mark_term(phi,todo);
304 }
305
306 /// \brief Set the variables and the condition explicitly.
307 /// \param v_ The variable list.
308 /// \param phi_ The condition.
309 void set(const data::variable_list& v_, const Expression& phi_)
310 {
311 v=v_;
312 phi=phi_;
313 }
314
315 /// \brief Set the variables and the condition explicitly.
316 /// \param v_ The variable list.
317 /// \param phi_ The condition.
318 /// \details Other arguments than the first two are ignored.
319 void set(const data::variable_list& v_, const Expression& phi_,const enumerator_list_element&)
320 {
321 v=v_;
322 phi=phi_;
323 }
324
325 /// \brief Set the variable ands and the expression explicitly
326 /// as the element (v, phi, e.sigma[v := x]).
327 /// \param v_ The variable list.
328 /// \param phi_ The condition.
329 /// \details Other arguments than the first two are ignored.
330 void set(const data::variable_list& v_,
331 const Expression& phi_,
333 const data::variable&,
334 const data::data_expression&)
335 {
336 v=v_;
337 phi=phi_;
338 }
339
340};
341
342/// \brief An element for the todo list of the enumerator that collects the substitution
343/// corresponding to the expression phi
344template <typename Expression = data::data_expression>
346{
347 protected:
348 data::variable_list m_variables;
349 data::data_expression_list m_expressions;
350
351 public:
352 using expression_type = Expression;
353
354 /// \brief Default constructor
356
357 /// \brief Constructs the element (v, phi, [])
358 enumerator_list_element_with_substitution(const data::variable_list& v, const Expression& phi)
359 : enumerator_list_element<Expression>(v, phi)
360 {}
361
362 /// \brief Constructs the element (v, phi, e.sigma[v := x])
364 const Expression& phi,
365 const enumerator_list_element_with_substitution<Expression>& elem
366 )
367 : enumerator_list_element<Expression>(v, phi),
370 {
371 }
372
373 /// \brief Constructs the element (v, phi, e.sigma[v := x])
375 const data::variable_list& v,
376 const Expression& phi,
377 const enumerator_list_element_with_substitution<Expression>& elem,
378 const data::variable& d,
379 const data::data_expression& e
380 )
381 : enumerator_list_element<Expression>(v, phi),
384 {
385 m_variables.push_front(d);
386 m_expressions.push_front(e);
387 }
388
389 /// \brief Adds the assignments that correspond with this element to the substitution result.
390 template <typename VariableList, IsSubstitution MutableSubstitution, typename Rewriter>
391 void add_assignments(const VariableList& v, MutableSubstitution& result, const Rewriter& rewriter) const
392 {
393 data::enumerator_substitution sigma(m_variables, m_expressions);
394 sigma.revert();
395 for (const data::variable& v_i: v)
396 {
397 result[v_i] = rewriter(sigma(v_i));
398 }
399 }
400
401 /// \brief Removes the assignments corresponding with this element from the substitution result.
402 template <typename VariableList, IsSubstitution MutableSubstitution>
403 void remove_assignments(const VariableList& v, MutableSubstitution& result) const
404 {
405 for (const data::variable& v_i: v)
406 {
407 result[v_i] = v_i;
408 }
409 }
410
411 /// \brief Returns the right hand sides corresponding to the variables v
412 /// \pre variables in v must be contained in variables()
413 template <typename VariableList, typename Rewriter>
414 data::data_expression_list assign_expressions(const VariableList& v, const Rewriter& rewriter) const
415 {
416 data::enumerator_substitution sigma(m_variables, m_expressions);
417 sigma.revert();
418 return data_expression_list(v.begin(), v.end(), [&](const data::variable& v_i) { return rewriter(sigma(v_i)); });
419 }
420
422 {
423 return data::enumerator_substitution(m_variables, m_expressions);
424 }
425
426 /// \brief The following function is needed to mark the aterms in this class,
427 /// when elements of this class are used in an atermpp standard container.
428 /// When garbage collection of aterms is taking place this function is
429 /// called for all elements of this class in the atermpp container.
431 {
432 mark_term(*atermpp::detail::address(m_variables), todo);
433 mark_term(*atermpp::detail::address(m_expressions), todo);
434 enumerator_list_element<Expression>::mark(todo);
435 }
436
437 /// \brief Set the variable ands and the expression explicitly
438 /// as the element (v, phi, e.sigma[v := x]).
439 void set(const data::variable_list& v,
440 const Expression& phi,
441 const enumerator_list_element_with_substitution<Expression>& elem,
442 const data::variable& d,
443 const data::data_expression& e)
444 {
445 enumerator_list_element<Expression>::set(v, phi);
446 m_variables=elem.m_variables;
447 m_expressions=elem.m_expressions;
448 m_variables.push_front(d);
449 m_expressions.push_front(e);
450 }
451
452 /// \brief Set the variable ands and the expression explicitly
453 /// as the element (v, phi, e.sigma[v := x]).
454 void set(const data::variable_list& v,
455 const Expression& phi,
456 const enumerator_list_element_with_substitution<Expression>& elem)
457 {
458 enumerator_list_element<Expression>::set(v, phi);
459 m_variables=elem.m_variables;
460 m_expressions=elem.m_expressions;
461 }
462};
463
464template <typename Expression>
466{
467 out << "{ [";
468 const variable_list& variables = p.variables();
469 for (variable_list::const_iterator i = variables.begin(); i != variables.end(); ++i)
470 {
471 if (i != variables.begin())
472 {
473 out << ", ";
474 }
475 out << *i << ": " << i->sort();
476 }
477 return out << "], " << p.expression() << " }";
478}
479
480template <typename Expression>
482{
483 out << "{ [";
484 const variable_list& variables = p.variables();
485 for (variable_list::const_iterator i = variables.begin(); i != variables.end(); ++i)
486 {
487 if (i != variables.begin())
488 {
489 out << ", ";
490 }
491 out << *i << ": " << i->sort();
492 }
493 return out << "], " << p.expression() << ", " << p.sigma() << " }";
494}
495
496/// \brief Contains the enumerator queue.
497template <typename EnumeratorListElement>
499{
500 protected:
502 EnumeratorListElement m_enumerator_element_cache; // This element is used to temporarily store
503 // information, which is more efficient than
504 // declaring such a variable on the stack
505 // as its protection using a protection set
506 // is expensive.
507
508 public:
509 // The following variables are used for local store, to prevent the
510 // variables to be inserted and removed continuously in a protection set.
511 typename EnumeratorListElement::expression_type scratch_expression;
514
515 using value_type = EnumeratorListElement;
517
518 /// \brief Default constructor
519 enumerator_queue() = default;
520
521 /// \brief Initializes the enumerator queue with the given value
522 explicit enumerator_queue(const EnumeratorListElement& value)
523 : P({value})
524 { }
525
526 void push_back(const EnumeratorListElement& x)
527 {
528#ifdef MCRL2_LOG_ENUMERATOR
529 std::cout << "push_back " << x << std::endl;
530#endif
531 P.push_back(x);
532 }
533
534 template <class... Args>
535 void emplace_back(Args&&... args)
536 {
537#ifdef MCRL2_LOG_ENUMERATOR
538 std::cout << "emplace_back " << EnumeratorListElement(args...) << std::endl;
539#endif
540 P.emplace_back(std::forward<Args>(args)...);
541 }
542
543 bool empty() const
544 {
545 return P.empty();
546 }
547
548 void clear()
549 {
550 P.clear();
551 }
552
554 {
555 return P.size();
556 }
557
558 const EnumeratorListElement& front() const
559 {
560 return P.front();
561 }
562
563 EnumeratorListElement& front()
564 {
565 return P.front();
566 }
567
568 const EnumeratorListElement& back() const
569 {
570 return P.back();
571 }
572
573 EnumeratorListElement& back()
574 {
575 return P.back();
576 }
577
579 {
580 P.pop_front();
581 }
582
583 void pop_back()
584 {
585 P.pop_back();
586 }
587
588 template <class... Args>
589 const EnumeratorListElement& enumerator_element_cache(const Args&... args)
590 {
591 m_enumerator_element_cache.set(args...);
593 }
594};
595
596/// \brief An enumerator algorithm that generates solutions of a condition.
597template <typename Rewriter = data::rewriter, typename DataRewriter = data::rewriter>
599{
600 protected:
601 // A rewriter
602 const Rewriter& R;
603
604 /// \brief A data specification.
606
607 // Needed for enumerate_expressions
608 const DataRewriter& r;
609
610 // A name generator
612
613 /// \brief max_count The enumeration is aborted after max_count iterations
615
616 /// \brief If true, solutions with a non-empty list of variables may be reported.
618
619#ifdef MCRL2_ENUMERATOR_COUNT_REWRITE_CALLS
620 mutable std::size_t rewrite_calls = 0;
621#endif
622
623 std::string print(const data::variable& x) const
624 {
625 std::ostringstream out;
626 out << x << ": " << x.sort();
627 return out.str();
628 }
629
630 template <typename Expression, IsSubstitution MutableSubstitution>
631 inline
632 Expression rewrite(const Expression& phi, MutableSubstitution& sigma) const
633 {
634#ifdef MCRL2_ENUMERATOR_COUNT_REWRITE_CALLS
635 rewrite_calls++;
636#endif
637 return const_cast<Rewriter&>(R)(phi, sigma);
638 }
639
640 template <typename Expression, IsSubstitution MutableSubstitution>
641 inline
642 void rewrite(Expression& result, const Expression& phi, MutableSubstitution& sigma) const
643 {
644#ifdef MCRL2_ENUMERATOR_COUNT_REWRITE_CALLS
645 rewrite_calls++;
646#endif
647 const_cast<Rewriter&>(R)(result, phi, sigma);
648 }
649
650 public:
651 enumerator_algorithm(const Rewriter& R_,
652 const data::data_specification& dataspec_,
653 const DataRewriter& datar_,
654 enumerator_identifier_generator& id_generator_,
655 bool accept_solutions_with_variables,
656 std::size_t max_count = (std::numeric_limits<std::size_t>::max)()
657 )
658 : R(R_),
659 dataspec(dataspec_),
660 r(datar_),
661 id_generator(id_generator_),
663 m_accept_solutions_with_variables(accept_solutions_with_variables)
664 {}
665
666 enumerator_algorithm(const enumerator_algorithm<Rewriter, DataRewriter>&) = delete;
667
669 {
670#ifdef MCRL2_ENUMERATOR_COUNT_REWRITE_CALLS
671 std::cout << "number of enumerator rewrite calls: " << rewrite_calls << std::endl;
672#endif
673 }
674
676 {
678 }
679
680 template <typename T>
682 {
683 bool operator()(const T&) { return false; }
684 };
685
686 /// \brief Enumerates the front element of the todo list P.
687 /// The enumeration is interrupted when report_solution returns true for the reported solution.
688 /// \param P The todo list of the algorithm.
689 /// \param sigma A mutable substitution that is applied by the rewriter.
690 /// \param report_solution A callback function that is called whenever a solution is found.
691 /// It takes an enumerator element as argument.
692 /// If report_solution returns true, the enumeration is interrupted.
693 /// N.B. If the enumeration is resumed after an interruption, the element p that
694 /// was interrupted will be enumerated again.
695 /// \param reject Elements p for which reject(p) is true are discarded.
696 /// \param accept Elements p for which accept(p) is true are reported as a solution, even if the list of variables of the enumerator element is non-empty.
697 /// \pre !P.empty()
698 /// \return If the return value is true, enumeration will be interrupted
699 template <typename EnumeratorListElement,
700 IsSubstitution MutableSubstitution,
701 typename ReportSolution,
702 typename Reject = always_false<typename EnumeratorListElement::expression_type>,
703 typename Accept = always_false<typename EnumeratorListElement::expression_type>
704 >
705 bool enumerate_front(enumerator_queue<EnumeratorListElement>& P,
706 MutableSubstitution& sigma,
707 ReportSolution report_solution,
708 Reject reject = Reject(),
709 Accept accept = Accept()
710 ) const
711 {
712 assert(!P.empty());
713 const EnumeratorListElement& p = P.front();
714
715 auto add_element = [&](const data::variable_list& variables,
716 const typename EnumeratorListElement::expression_type& phi,
717 const data::variable& v,
718 const data::data_expression& e
719 ) -> bool
720 {
721 rewrite(P.scratch_expression, phi, sigma);
722 if (reject(P.scratch_expression))
723 {
724 return false;
725 }
726 if ((accept(P.scratch_expression) && m_accept_solutions_with_variables) || variables.empty())
727 {
728 return report_solution(P.enumerator_element_cache(variables, P.scratch_expression, p, v, e));
729 }
730 P.emplace_back(variables, P.scratch_expression, p, v, e);
731 return false;
732 };
733
734 auto add_element_with_variables = [&](const data::variable_list& variables,
735 const data::variable_list& added_variables,
736 const typename EnumeratorListElement::expression_type& phi,
737 const data::variable& v,
738 const data::data_expression& e,
739 const bool /*print*/ = false) -> bool
740 {
741 rewrite(P.scratch_expression, phi, sigma);
742 if (reject(P.scratch_expression))
743 {
744 return false;
745 }
746 bool added_variables_empty
747 = added_variables.empty() || (P.scratch_expression == phi && m_accept_solutions_with_variables);
748 if ((accept(P.scratch_expression) && m_accept_solutions_with_variables)
749 || (variables.empty() && added_variables_empty))
750 {
751 return report_solution(
752 P.enumerator_element_cache(variables + added_variables, P.scratch_expression, p, v, e));
753 }
754 if (added_variables_empty)
755 {
756 P.emplace_back(variables, P.scratch_expression, p, v, e);
757 }
758 else
759 {
760 P.emplace_back(variables + added_variables, P.scratch_expression, p, v, e);
761 }
762 return false;
763 };
764
765 const variable_list& v = p.variables();
766 const typename EnumeratorListElement::expression_type& phi = p.expression();
767
768 if (v.empty())
769 {
770 rewrite(P.scratch_expression, phi, sigma);
771 if (reject(P.scratch_expression))
772 {
773 return false;
774 }
775 return report_solution(P.enumerator_element_cache(v, P.scratch_expression, p));
776 }
777
778 const variable& v1 = v.front();
779 const variable_list& v_tail = v.tail();
780 const sort_expression& v1_sort = v1.sort();
781
782 if (reject(phi))
783 {
784 // skip
785 }
786 else if (data::is_function_sort(v1_sort))
787 {
788 const function_sort& function = atermpp::down_cast<function_sort>(v1_sort);
790 {
791 data_expression_vector function_sorts;
792 variable_list function_parameter_list;
793 bool result = detail::compute_finite_function_sorts(function, id_generator, dataspec, r, function_sorts, function_parameter_list);
794 if (!result)
795 {
796 throw mcrl2::runtime_error("Sort " + data::pp(v1_sort) + " has too many elements to enumerate.");
797 }
798
799 for (const data_expression& f: function_sorts)
800 {
801 sigma[v1] = f;
802 if (add_element(v_tail, phi, v1, f))
803 {
804 sigma[v1] = v1;
805 return true;
806 }
807 }
808 }
809 else
810 {
811 throw mcrl2::runtime_error("Cannot enumerate elements of function sort " + data::pp(v1_sort) + ".");
812 }
813 }
814 else if (sort_set::is_set(v1_sort))
815 {
816 const sort_expression& element_sort = atermpp::down_cast<container_sort>(v1_sort).element_sort();
817 if (dataspec.is_certainly_finite(element_sort))
818 {
819 const data_expression false_term = sort_set::false_function(element_sort);
820 const variable fset_variable(id_generator(), sort_fset::fset(element_sort));
821 data_expression e = sort_set::constructor(element_sort, false_term, fset_variable);
822 sigma[v1] = e;
823 if (add_element_with_variables(v_tail, { fset_variable }, phi, v1, e, true))
824 {
825 sigma[v1] = v1;
826 return true;
827 }
828 }
829 else
830 {
831 throw mcrl2::runtime_error("Cannot enumerate elements of set sort " + data::pp(v1_sort) + ".");
832 }
833 }
834 else if (sort_fset::is_fset(v1_sort))
835 {
836 const container_sort& fset = atermpp::down_cast<container_sort>(v1_sort);
838 {
839 data_expression_vector set_elements;
840 bool result = detail::compute_finite_set_elements(fset, dataspec, r, sigma, set_elements, id_generator);
841 if (!result)
842 {
843 throw mcrl2::runtime_error("Finite set sort " + data::pp(v1_sort) + " has too many elements to enumerate.");
844 }
845
846 for (const data_expression& e: set_elements)
847 {
848 sigma[v1] = e;
849 if (add_element(v_tail, phi, v1, e))
850 {
851 sigma[v1] = v1;
852 return true;
853 }
854 }
855 }
856 else
857 {
858 throw mcrl2::runtime_error("Cannot enumerate elements of finite set sort " + data::pp(v1_sort) + ".");
859 }
860 }
861 else if (sort_bag::is_bag(v1_sort))
862 {
863 throw mcrl2::runtime_error("Cannot enumerate elements of bag sort " + data::pp(v1_sort) + ".");
864 }
865 else if (sort_fbag::is_fbag(v1_sort))
866 {
867 throw mcrl2::runtime_error("Cannot enumerate elements of finite bag sort " + data::pp(v1_sort) + ".");
868 }
869 else
870 {
871 const function_symbol_vector& C = dataspec.constructors(v1_sort);
872 if (!C.empty())
873 {
874 for (const function_symbol& c: C)
875 {
876 if (data::is_function_sort(c.sort()))
877 {
878 const sort_expression_list& domain = atermpp::down_cast<data::function_sort>(c.sort()).domain();
879 atermpp::make_term_list(P.scratch_variable_list,
880 domain.begin(),
881 domain.end(),
882 [&](const data::sort_expression& s) { return data::variable(id_generator(), s); });
883 // data_expression cy = r(application(c, y.begin(), y.end()));
884 // below sigma is not used, but it prevents generating a dummy sigma.
885 r(P.scratch_data_expression, application(c, P.scratch_variable_list.begin(), P.scratch_variable_list.end()),sigma);
886 sigma[v1] = P.scratch_data_expression;
887 if (add_element_with_variables(v_tail, P.scratch_variable_list, phi, v1, P.scratch_data_expression))
888 {
889 sigma[v1] = v1;
890 return true;
891 }
892 }
893 else
894 {
895 r(P.scratch_data_expression,c,sigma); // sigma is not used, but in this way no dummy sigma needs to be created.
896 sigma[v1] = P.scratch_data_expression;
897 if (add_element(v_tail, phi, v1, P.scratch_data_expression))
898 {
899 sigma[v1] = v1;
900 return true;
901 }
902 }
903 }
904 }
905 else
906 {
907 throw mcrl2::runtime_error("Cannot enumerate elements of sort " + data::pp(v1_sort) + " without constructors.");
908 }
909 }
910 sigma[v1] = v1;
911 return false;
912 }
913
914 /// \brief Enumerates until P is empty. Solutions are reported using the callback function report_solution.
915 /// The enumeration is interrupted when report_solution returns true for the reported solution.
916 /// \param P The todo list of the algorithm.
917 /// \param sigma A substitution.
918 /// \param report_solution A callback function that is called whenever a solution is found.
919 /// It takes an enumerator element as argument.
920 /// If report_solution returns true, the enumeration is interrupted.
921 /// N.B. If the enumeration is resumed after an interruption, the element p that
922 /// was interrupted will be enumerated again.
923 /// \param reject Elements p for which reject(p) is true are discarded.
924 /// \param accept Elements p for which accept(p) is true are reported as a solution, even if the list of variables of the enumerator element is non-empty.
925 /// \return The number of elements that have been processed
926 template <typename EnumeratorListElement,
927 IsSubstitution MutableSubstitution,
928 typename ReportSolution,
929 typename Reject = always_false<typename EnumeratorListElement::expression_type>,
930 typename Accept = always_false<typename EnumeratorListElement::expression_type>
931 >
935 Reject reject = Reject(),
936 Accept accept = Accept()) const
937 {
938 std::size_t count = 0;
939 while (!P.empty())
940 {
941 if (count++ >= m_max_count)
942 {
943 break;
944 }
945 if (enumerate_front(P, sigma, report_solution, reject, accept))
946 {
947 break;
948 }
949 P.pop_front();
950 }
951 return count;
952 }
953
954 /// \brief Enumerates the element p. Solutions are reported using the callback function report_solution.
955 /// The enumeration is interrupted when report_solution returns true for the reported solution.
956 /// \param p An enumerator element, i.e. an expression with a list of variables.
957 /// \param sigma A substitution.
958 /// \param report_solution A callback function that is called whenever a solution is found.
959 /// It takes an enumerator element as argument.
960 /// If report_solution returns true, the enumeration is interrupted.
961 /// N.B. If the enumeration is resumed after an interruption, the element p that
962 /// was interrupted will be enumerated again.
963 /// \param reject Elements p for which reject(p) is true are discarded.
964 /// \param accept Elements p for which accept(p) is true are reported as a solution, even if the list of variables of the enumerator element is non-empty.
965 /// \return The number of elements that have been processed
966 template <typename EnumeratorListElement,
967 IsSubstitution MutableSubstitution,
968 typename ReportSolution,
969 typename Reject = always_false<typename EnumeratorListElement::expression_type>,
970 typename Accept = always_false<typename EnumeratorListElement::expression_type>
971 >
975 Reject reject = Reject(),
977 ) const
978 {
979 enumerator_queue<EnumeratorListElement> P(p);
980 return enumerate_all(P, sigma, report_solution, reject, accept);
981 }
982
983 /// \brief Enumerates the variables v for condition c. Solutions are reported using the callback function report_solution.
984 /// The enumeration is interrupted when report_solution returns true for the reported solution.
985 /// \param vars The list of variables v to enumerate over.
986 /// \param cond The condition to evaluate for each enumerated value.
987 /// \param sigma A substitution.
988 /// \param report_solution A callback function that is called whenever a solution is found.
989 /// It takes an enumerator element as argument.
990 /// If report_solution returns true, the enumeration is interrupted.
991 /// N.B. If the enumeration is resumed after an interruption, the element p that
992 /// was interrupted will be enumerated again.
993 /// \param reject Elements p for which reject(p) is true are discarded.
994 /// \param accept Elements p for which accept(p) is true are reported as a solution, even if the list of variables of the enumerator element is non-empty.
995 /// \return The number of elements that have been processed
996 template <typename EnumeratorListElement,
997 IsSubstitution MutableSubstitution,
998 typename ReportSolution,
999 typename Reject = always_false<typename EnumeratorListElement::expression_type>,
1000 typename Accept = always_false<typename EnumeratorListElement::expression_type>
1001 >
1006 Reject reject = Reject(),
1007 Accept accept = Accept()
1008 ) const
1009 {
1010 enumerator_queue<EnumeratorListElement> P;
1011 P.emplace_back(vars, cond);
1012 return enumerate_all(P, sigma, report_solution, reject, accept);
1013 }
1014
1016 {
1017 return m_max_count;
1018 }
1019};
1020
1021/// \brief Returns a vector with all expressions of sort s.
1022/// \param s A sort expression.
1023/// \param dataspec The data specification defining the terms of sort \a s.
1024/// \param rewr A rewriter to be used to simplify terms and conditions.
1025/// \param id_generator An identifier generator used to generate new names for variables.
1026/// \details It is assumed that the sort s has only a finite number of elements.
1027template <class Rewriter>
1030 const Rewriter& rewr,
1032{
1033 using term_type = typename Rewriter::term_type;
1034 using enumerator_element = enumerator_list_element_with_substitution<term_type>;
1035 assert(dataspec.is_certainly_finite(s));
1036
1037 bool accept_solutions_with_variables = false;
1038 enumerator_algorithm<Rewriter, Rewriter> E(rewr, dataspec, rewr, id_generator, accept_solutions_with_variables);
1039 data_expression_vector result;
1040 mutable_indexed_substitution<> sigma;
1041 const variable v("@var@", s);
1042 const variable_list v_list{ v };
1043 E.template enumerate<enumerator_element>(
1044 v_list,
1045 sort_bool::true_(),
1046 sigma,
1047 [&](const enumerator_element& p)
1048 {
1049 p.add_assignments(v_list, sigma, rewr);
1050 result.push_back(sigma(v));
1051 return false;
1052 }
1053 );
1054 return result;
1055}
1056
1057/// \brief Returns a vector with all expressions of sort s.
1058/// \param s A sort expression.
1059/// \param dataspec The data specification defining the terms of sort \a s.
1060/// \param rewr A rewriter to be used to simplify terms and conditions.
1061/// \details It is assumed that the sort s has only a finite number of elements.
1062template <class Rewriter>
1065 const Rewriter& rewr)
1066{
1068 return enumerate_expressions(s, dataspec, rewr, id_generator);
1069}
1070
1071} // namespace mcrl2::data
1072
1073#endif // MCRL2_DATA_ENUMERATOR_H
aterm()
Default constructor.
Definition aterm.h:51
A unordered_map class in which aterms can be stored.
An abstraction expression.
Definition abstraction.h:23
const variable_list & variables() const
Definition abstraction.h:60
abstraction(const binder_type &binding_operator, const variable_list &variables, const data_expression &body)
Constructor.
Definition abstraction.h:39
const data_expression & body() const
Definition abstraction.h:65
const binder_type & binding_operator() const
Definition abstraction.h:55
Rewriter class for the mCRL2 Library. It only works for terms of type data_expression and data_expres...
Definition rewriter.h:26
const data::enumerator_identifier_generator & identifier_generator() const
Expose the identifier generator present in m_rewriter.
Definition rewriter.h:44
basic_rewriter(const data_specification &d, const used_data_equation_selector &equation_selector, const strategy s=rewrite_strategy::jitty)
Constructor.
Definition rewriter.h:71
basic_rewriter(const std::shared_ptr< detail::Rewriter > &r)
Constructor.
Definition rewriter.h:53
basic_rewriter(const basic_rewriter &other)=default
Copy Constructor.
basic_rewriter & operator=(const basic_rewriter &other)=default
Assignment operator.
std::shared_ptr< detail::Rewriter > m_rewriter
The wrapped Rewriter.
Definition rewriter.h:33
basic_rewriter(const data_specification &d, const strategy s=rewrite_strategy::jitty)
Constructor.
Definition rewriter.h:66
\brief A container sort
const sort_expression & element_sort() const
\brief A data equation
const data_expression & lhs() const
const variable_list & variables() const
data_expression & operator=(const data_expression &) noexcept=default
data_expression & operator=(data_expression &&) noexcept=default
sort_expression sort() const
Returns the sort of the data expression.
Definition data.cpp:107
bool is_certainly_finite(const sort_expression &s) const
Checks whether a sort is certainly finite.
The class BDD_Info provides information about the structure of binary decision diagrams.
Definition bdd_info.h:22
static const mcrl2::data::data_expression & get_true_branch(const mcrl2::data::data_expression &a_bdd)
Method that returns the true-branch of a BDD.
Definition bdd_info.h:43
static bool is_if_then_else(const data_expression &a_bdd)
Method that indicates wether or not the root of a BDD is a guard node.
Definition bdd_info.h:78
static bool is_false(const data_expression &a_bdd)
Method that indicates whether or not a BDD equals false.
Definition bdd_info.h:69
static const mcrl2::data::data_expression & get_guard(const mcrl2::data::data_expression &a_bdd)
Method that returns the guard of a BDD.
Definition bdd_info.h:35
static const mcrl2::data::data_expression & argument(const mcrl2::data::data_expression &x, std::size_t n)
Definition bdd_info.h:24
static const mcrl2::data::data_expression & get_false_branch(const mcrl2::data::data_expression &a_bdd)
Method that returns the false-branch of a BDD.
Definition bdd_info.h:51
static bool is_true(const data_expression &a_bdd)
Method that indicates whether or not a BDD equals true.
Definition bdd_info.h:60
Base class for eliminating inconsistent paths from BDDs.
data_expression simplify(const data_expression &a_bdd) override
Returns a BDD without inconsistent paths, equivalent to a_bdd. precondition: The argument passed as p...
data_expression aux_simplify(const data_expression &a_bdd, const data_expression_list &a_path)
Simplifies the BDD a_bdd using path a_path. Paths whose guards in conjunction with the guards in.
BDD_Info f_bdd_info
Class that provides information about the structure of BDDs.
SMT_Solver * f_smt_solver
Pointer to an SMT solver used to determine whether or not a path is inconsistent.
bool variables_overlap(const data_expression &a_expression_1, const data_expression &a_expression_2)
Returns true if the expression a_expression_1 has variables in common with expression a_expression_2.
BDD_Path_Eliminator(smt_solver_type a_solver_type)
Constructor that initializes the field BDD_Path_Eliminator::f_smt_solver.
data_expression_list create_condition(data_expression_list a_path, const data_expression &a_guard, bool a_minimal)
Returns a list representing the conjunction of all guards in a_path and the guard a_guard.
bool get_branch(const data_expression &a_bdd, const bool a_polarity, data_expression &result)
Returns branch of the BDD a_bdd, depending on the polarity a_polarity.
Definition bdd_prover.h:423
Induction f_induction
Class that creates all statements needed to prove a given property using induction.
Definition bdd_prover.h:144
strategy rewriter_strategy() const
Returns the strategy of the rewriter used inside this proving rewriter.
Definition bdd_prover.h:618
std::vector< variable > f_variables
The variables in the expression in order.
Definition bdd_prover.h:130
std::shared_ptr< BDD_Simplifier > f_bdd_simplifier
Class that simplifies a BDD.
Definition bdd_prover.h:141
static constexpr bool f_reverse
Flag indicating whether or not the result of the comparison between the first two arguments.
Definition bdd_prover.h:94
void set_substitution(substitution_type &sigma)
Set the substitution to be used to construct the BDD.
Definition bdd_prover.h:523
void set_formula(const data_expression &formula)
Sets Prover::f_formula to formula. precondition: the argument passed as parameter formula is an expre...
Definition bdd_prover.h:625
std::string indent(size_t n)
Definition bdd_prover.h:178
bool smallest(const data_expression &formula, data_expression &result)
Returns the smallest guard in the formula formula.
Definition bdd_prover.h:338
data_expression f_bdd
A binary decision diagram in the internal representation of mCRL2.
Definition bdd_prover.h:467
const Info f_info
A class that provides information about expressions.
Definition bdd_prover.h:105
data_expression bdd_down(const data_expression &formula, const size_t a_indent=0)
Creates the EQ-BDD corresponding to the formula formula.
Definition bdd_prover.h:184
static constexpr bool f_full
Flag indicating whether or not the arguments of equality functions are taken into account.
Definition bdd_prover.h:98
void eliminate_paths()
Removes all inconsistent paths from the BDD BDD_Prover::f_bdd.
Definition bdd_prover.h:248
BDD_Prover(const rewriter &r, double time_limit=0, bool apply_induction=false)
Definition bdd_prover.h:513
data_expression get_counter_example()
Returns all the guards on a path in the BDD that leads to a leaf labelled "false",...
Definition bdd_prover.h:584
substitution_type bdd_sigma
A binary decision diagram in the internal representation of the rewriter.
Definition bdd_prover.h:464
Answer f_tautology
A flag that indicates whether or not the formala Prover::f_formula is a tautology.
Definition bdd_prover.h:114
Answer is_contradiction()
Indicates whether or not the formula Prover::f_formula is a contradiction.
Definition bdd_prover.h:542
data_expression f_formula
An expression of sort Bool.
Definition bdd_prover.h:102
std::chrono::milliseconds f_deadline
A timestamp representing the moment when the maximal amount of milliseconds has been spent on process...
Definition bdd_prover.h:123
bool f_processed
A flag that indicates whether or not the formala Prover::f_formula has been processed.
Definition bdd_prover.h:111
void update_answers()
Updates the values of Prover::f_tautology and Prover::f_contradiction.
Definition bdd_prover.h:266
std::shared_ptr< detail::Rewriter > get_rewriter()
Returns the rewriter used by this prover (i.e. it returns Prover::f_rewriter).
Definition bdd_prover.h:612
const double f_time_limit
An integer representing the maximal amount of seconds to be spent on processing a formula.
Definition bdd_prover.h:120
Manipulator f_manipulator
A class that can be used to manipulate expressions.
Definition bdd_prover.h:108
bool f_apply_induction
A flag indicating whether or not induction on lists is applied.
Definition bdd_prover.h:127
void build_bdd()
Constructs the EQ-BDD corresponding to the formula Prover::f_formula.
Definition bdd_prover.h:147
std::unordered_map< data_expression, data_expression > f_smallest
A hashtable that maps formulas to the smallest guard occuring in those formulas.
Definition bdd_prover.h:138
Answer f_contradiction
A flag that indicates whether or not the formala Prover::f_formula is a contradiction.
Definition bdd_prover.h:117
std::unordered_map< data_expression, data_expression > f_formula_to_bdd
A hashtable that maps formulas to BDDs.
Definition bdd_prover.h:134
data_expression get_bdd()
Returns the BDD BDD_Prover::f_bdd.
Definition bdd_prover.h:549
data_expression get_witness()
Returns all the guards on a path in the BDD that leads to a leaf labelled "true", if such a leaf exis...
Definition bdd_prover.h:556
void set_substitution_internal(substitution_type &sigma)
Set the substitution in internal format to be used to construct the BDD.
Definition bdd_prover.h:529
Answer is_tautology()
Indicates whether or not the formula Prover::f_formula is a tautology.
Definition bdd_prover.h:535
BDD_Prover(const data_specification &data_spec, const used_data_equation_selector &equations_selector, mcrl2::data::rewriter::strategy a_rewrite_strategy=mcrl2::data::rewrite_strategy::jitty, double a_time_limit=0, bool a_path_eliminator=false, smt_solver_type a_solver_type=smt_solver_type::solver_type_cvc, bool a_apply_induction=false)
Definition bdd_prover.h:470
A base class for simplifying binary decision diagrams.
void set_time_limit(time_t a_time_limit)
Sets the attribute BDD_Simplifier::f_deadline.
virtual data_expression simplify(const data_expression &a_bdd)
Returns a simplified BDD, equivalent to the bdd a_bdd. precondition: The argument passed as parameter...
virtual ~BDD_Simplifier()=default
Destructor without any additional functionality.
time_t f_deadline
An integer representing the moment in time when the maximal amount of seconds has been spent on simpl...
The class Induction generates statements corresponding to.
Definition induction.h:25
sort_expression get_sort_of_list_elements(const variable &a_list_variable) const
Definition induction.h:53
data_expression create_hypotheses(const data_expression &a_hypothesis, variable_list a_list_of_variables, variable_list a_list_of_dummies) const
Definition induction.h:87
std::size_t f_count
The number of variables used during the last application of induction.
Definition induction.h:30
variable_vector f_list_variables
Definition induction.h:36
data_expression f_formula
An expression of sort Bool in mCRL2 format.
Definition induction.h:33
set_identifier_generator fresh_identifier_generator
Definition induction.h:27
variable_vector recurse_expression_for_lists(const data_expression &a_expression) const
Definition induction.h:39
variable get_fresh_dummy(const sort_expression &a_sort)
Definition induction.h:60
data_expression_list create_clauses(const data_expression &a_formula, const data_expression &a_hypothesis, const std::size_t a_variable_number, const std::size_t a_number_of_variables, const variable_list &a_list_of_variables, const variable_list &a_list_of_dummies)
Definition induction.h:117
void initialize(const data_expression &a_formula)
Definition induction.h:160
data_expression apply_induction()
Definition induction.h:173
data_expression apply_induction_one(const core::identifier_string &fresh_name) const
Definition induction.h:67
Base class for classes that provide information about the structure of.
Definition info.h:32
data_expression get_operator(const data_expression &term) const
Returns the main operator of the term term;.
Definition info.h:236
constexpr Info(bool a_full, bool a_reverse)
Constructor that initializes the rewriter.
Definition info.h:181
Compare_Result compare_term_free_variables(const data_expression &term1, const data_expression &term2) const
Definition info.h:136
Compare_Result compare_guard_equality(const data_expression &guard1, const data_expression &guard2) const
Compares two guards by their arguments.
Definition info.h:114
Compare_Result compare_address(const atermpp::aterm &term1, const atermpp::aterm &term2) const
Definition info.h:51
static bool occurs(const data_expression &t1, const data_expression &t2)
Definition info.h:187
Compare_Result lexico(const Compare_Result &a_result1, const Compare_Result &a_result2) const
Definition info.h:44
Compare_Result compare_term_type(const data_expression &term1, const data_expression &term2) const
Compares terms by their type.
Definition info.h:152
std::size_t get_number_of_arguments(const data_expression &a_term) const
Returns the number of arguments of the main operator of a term.
Definition info.h:223
double get_guard_structure(const data_expression &guard, const std::vector< variable > &f_variables) const
Returns an integer corresponding to the structure of the guard passed as argument guard.
Definition info.h:68
Compare_Result compare_term_occurs(const data_expression &term1, const data_expression &term2) const
Compares terms by checking whether one is a part of the other.
Definition info.h:166
const bool f_full
Flag indicating whether or not the arguments of equality functions are taken into account.
Definition info.h:37
Compare_Result compare_guard_structure(const data_expression &guard1, const data_expression &guard2, const std::vector< variable > &f_variables) const
Compares the structure of two guards.
Definition info.h:100
Compare_Result compare_term(const data_expression &term1, const data_expression &term2) const
Compares two terms.
Definition info.h:205
Compare_Result compare_guard(const data_expression &guard1, const data_expression &guard2, const std::vector< variable > &f_variables) const
Compares two guards.
Definition info.h:193
const bool f_reverse
Flag indicating whether or not the result of the comparison between the first two arguments.
Definition info.h:42
Base class for classes that provide functionality to modify or create terms.
Definition manipulator.h:23
data_expression orient(const data_expression &a_term)
Orients the term a_term such that all equations of the form t1 == t2 are.
Manipulator(const Info &a_info)
Constructor initializing the rewriter and the field f_info.
data_expression set_true(const data_expression &a_formula, const data_expression &a_guard) const
Initializes the table Manipulator::f_set_true and calls.
std::unordered_map< data_expression, data_expression > f_orient
A table used by the method Manipulator::orient. The method Manipulator::orient stores resulting terms...
Definition manipulator.h:33
data_expression set_false(const data_expression &a_formula, const data_expression &a_guard) const
Initializes the table Manipulator::f_set_false and calls the method.
const Info & f_info
A class that provides information on the structure of expressions in one of the.
Definition manipulator.h:27
static data_expression make_reduced_if_then_else(const data_expression &a_expr, const data_expression &a_high, const data_expression &a_low)
Returns an expression in the internal format of the rewriter with the jitty strategy.
data_expression set_false_auxiliary(const data_expression &a_formula, const data_expression &a_guard, std::unordered_map< data_expression, data_expression > &f_set_false) const
Replaces all occurences of a_guard in a_formula by false.
Definition manipulator.h:98
data_expression set_true_auxiliary(const data_expression &a_formula, const data_expression &a_guard, std::unordered_map< data_expression, data_expression > &f_set_true) const
Replaces all occurences of a_guard in a_formula by true. Additionally, if the variable.
Definition manipulator.h:38
RewriterProver(const data_specification &data_spec, mcrl2::data::rewriter::strategy strat, const used_data_equation_selector &equations_selector)
Definition with_prover.h:28
RewriterProver(const RewriterProver &other)=delete
data_expression rewrite(const data_expression &t, substitution_type &sigma) override
Rewrite an mCRL2 data term.
Definition with_prover.h:68
rewrite_strategy getStrategy() override
Get rewriter strategy that is used.
Definition with_prover.h:38
void rewrite(data_expression &result, const data_expression &t, substitution_type &sigma) override
Rewrite an mCRL2 data term.
Definition with_prover.h:53
RewriterProver(const RewriterProver &rewr, BDD_Prover prover_obj_)
Definition with_prover.h:88
std::shared_ptr< Rewriter > clone() override
Clone a rewriter.
Definition with_prover.h:96
Rewriter interface class.
Definition rewrite.h:39
void rewrite_where(data_expression &result, const where_clause &term, substitution_type &sigma)
Definition rewrite.cpp:61
virtual void thread_initialise()
Definition rewrite.h:164
Rewriter(const data_specification &data_spec, const used_data_equation_selector &eq_selector)
Constructor. Do not use directly; use createRewriter() function instead.
Definition rewrite.h:60
std::map< function_symbol, std::size_t > f_operators
void translate_less_than(const data_expression &a_clause)
void translate_less_than_or_equal(const data_expression &a_clause)
void translate_max(const data_expression &a_clause)
void translate_pred(const data_expression &a_clause)
void translate_unary_minus(const data_expression &a_clause)
void translate_unknown_operator(const data_expression &a_clause)
void add_bool2pred_and_translate_clause(const data_expression &a_clause)
const data_expression & arg(const data_expression &x) const
void translate(data_expression_list a_formula)
void translate_nat_variable(const variable &a_clause)
void translate_add_c(const data_expression &a_clause)
void translate_c_nat(const data_expression &a_clause)
void translate_nat_constant(const data_expression &a_clause)
void translate_int_constant(const data_expression &a_clause)
void translate_binary_minus(const data_expression &a_clause)
void translate_greater_than(const data_expression &a_clause)
void translate_equality(const data_expression &a_clause)
void translate_variable(const variable &a_clause)
void translate_c_int(const data_expression &a_clause)
void translate_inequality(const data_expression &a_clause)
std::map< sort_expression, std::size_t > f_sorts
void translate_not(const data_expression &a_clause)
const data_expression & right(const data_expression &x) const
void translate_clause(const data_expression &a_clause, const bool a_expecting_predicate)
void translate_abs(const data_expression &a_clause)
void translate_pos_constant(const data_expression &a_clause)
void translate_pos_variable(const variable &a_clause)
void translate_greater_than_or_equal(const data_expression &a_clause)
void translate_min(const data_expression &a_clause)
void translate_plus(const data_expression &a_clause)
void translate_function_symbol(const data_expression &a_clause)
void translate_succ(const data_expression &a_clause)
void translate_multiplication(const data_expression &a_clause)
const data_expression & left(const data_expression &x) const
virtual bool is_satisfiable(const data_expression_list &a_formula)=0
static bool execute(std::string const &benchmark)
A strategy is a list of rules and the number of variables that occur in it.
An enumerator algorithm that generates solutions of a condition.
Definition enumerator.h:599
void rewrite(Expression &result, const Expression &phi, MutableSubstitution &sigma) const
Definition enumerator.h:642
enumerator_identifier_generator & id_generator
Definition enumerator.h:611
std::size_t m_max_count
max_count The enumeration is aborted after max_count iterations
Definition enumerator.h:614
std::size_t enumerate(const EnumeratorListElement &p, MutableSubstitution &sigma, ReportSolution report_solution, Reject reject=Reject(), Accept accept=Accept()) const
Enumerates the element p. Solutions are reported using the callback function report_solution....
Definition enumerator.h:972
enumerator_algorithm(const enumerator_algorithm< Rewriter, DataRewriter > &)=delete
std::size_t enumerate(const variable_list &vars, const typename EnumeratorListElement::expression_type &cond, MutableSubstitution &sigma, ReportSolution report_solution, Reject reject=Reject(), Accept accept=Accept()) const
Enumerates the variables v for condition c. Solutions are reported using the callback function report...
bool enumerate_front(enumerator_queue< EnumeratorListElement > &P, MutableSubstitution &sigma, ReportSolution report_solution, Reject reject=Reject(), Accept accept=Accept()) const
Enumerates the front element of the todo list P. The enumeration is interrupted when report_solution ...
Definition enumerator.h:705
std::string print(const data::variable &x) const
Definition enumerator.h:623
bool m_accept_solutions_with_variables
If true, solutions with a non-empty list of variables may be reported.
Definition enumerator.h:617
const data::data_specification & dataspec
A data specification.
Definition enumerator.h:605
std::size_t enumerate_all(enumerator_queue< EnumeratorListElement > &P, MutableSubstitution &sigma, ReportSolution report_solution, Reject reject=Reject(), Accept accept=Accept()) const
Enumerates until P is empty. Solutions are reported using the callback function report_solution....
Definition enumerator.h:932
enumerator_algorithm(const Rewriter &R_, const data::data_specification &dataspec_, const DataRewriter &datar_, enumerator_identifier_generator &id_generator_, bool accept_solutions_with_variables, std::size_t max_count=(std::numeric_limits< std::size_t >::max)())
Definition enumerator.h:651
Expression rewrite(const Expression &phi, MutableSubstitution &sigma) const
Definition enumerator.h:632
core::identifier_string operator()()
Generates a unique function symbol with the given prefix followed by a number.
An element for the todo list of the enumerator that collects the substitution corresponding to the ex...
Definition enumerator.h:346
enumerator_list_element_with_substitution(const data::variable_list &v, const Expression &phi, const enumerator_list_element_with_substitution< Expression > &elem, const data::variable &d, const data::data_expression &e)
Constructs the element (v, phi, e.sigma[v := x])
Definition enumerator.h:374
data::data_expression_list assign_expressions(const VariableList &v, const Rewriter &rewriter) const
Returns the right hand sides corresponding to the variables v.
Definition enumerator.h:414
enumerator_list_element_with_substitution(const data::variable_list &v, const Expression &phi)
Constructs the element (v, phi, [])
Definition enumerator.h:358
void remove_assignments(const VariableList &v, MutableSubstitution &result) const
Removes the assignments corresponding with this element from the substitution result.
Definition enumerator.h:403
void set(const data::variable_list &v, const Expression &phi, const enumerator_list_element_with_substitution< Expression > &elem, const data::variable &d, const data::data_expression &e)
Set the variable ands and the expression explicitly as the element (v, phi, e.sigma[v := x]).
Definition enumerator.h:439
void add_assignments(const VariableList &v, MutableSubstitution &result, const Rewriter &rewriter) const
Adds the assignments that correspond with this element to the substitution result.
Definition enumerator.h:391
void set(const data::variable_list &v, const Expression &phi, const enumerator_list_element_with_substitution< Expression > &elem)
Set the variable ands and the expression explicitly as the element (v, phi, e.sigma[v := x]).
Definition enumerator.h:454
void mark(std::stack< std::reference_wrapper< atermpp::detail::_aterm > > &todo) const
The following function is needed to mark the aterms in this class, when elements of this class are us...
Definition enumerator.h:430
data::enumerator_substitution sigma() const
Definition enumerator.h:421
enumerator_list_element_with_substitution(const data::variable_list &v, const Expression &phi, const enumerator_list_element_with_substitution< Expression > &elem)
Constructs the element (v, phi, e.sigma[v := x])
Definition enumerator.h:363
enumerator_list_element_with_substitution()=default
Default constructor.
The default element for the todo list of the enumerator.
Definition enumerator.h:229
enumerator_list_element(data::variable_list v_, const Expression &phi_, const enumerator_list_element &, const data::variable &, const data::data_expression &)
Constructs the element (v, phi)
Definition enumerator.h:254
void set(const data::variable_list &v_, const Expression &phi_)
Set the variables and the condition explicitly.
Definition enumerator.h:309
enumerator_list_element(data::variable_list v_, const Expression &phi_)
Constructs the element (v, phi)
Definition enumerator.h:241
enumerator_list_element(data::variable_list v_, const Expression &phi_, const enumerator_list_element &)
Constructs the element (v, phi)
Definition enumerator.h:246
bool is_valid() const
Returns true if the element is valid. If it becomes false, this is used to signal that the enumeratio...
Definition enumerator.h:291
void set(const data::variable_list &v_, const Expression &phi_, const enumerator_list_element &, const data::variable &, const data::data_expression &)
Set the variable ands and the expression explicitly as the element (v, phi, e.sigma[v := x]).
Definition enumerator.h:330
enumerator_list_element()=default
Default constructor.
void mark(atermpp::term_mark_stack &todo) const
The following function is needed to mark the aterms in this class, when elements of this class are us...
Definition enumerator.h:300
void set(const data::variable_list &v_, const Expression &phi_, const enumerator_list_element &)
Set the variables and the condition explicitly.
Definition enumerator.h:319
void invalidate()
Invalidates the element, by giving phi an undefined value.
Definition enumerator.h:284
const data::variable_list & variables() const
Definition enumerator.h:263
const Expression & expression() const
Definition enumerator.h:268
Contains the enumerator queue.
Definition enumerator.h:499
atermpp::deque< EnumeratorListElement > P
Definition enumerator.h:501
atermpp::deque< EnumeratorListElement >::size_type size() const
Definition enumerator.h:553
enumerator_queue()=default
Default constructor.
const EnumeratorListElement & enumerator_element_cache(const Args &... args)
Definition enumerator.h:589
EnumeratorListElement::expression_type scratch_expression
Definition enumerator.h:511
variable_list scratch_variable_list
Definition enumerator.h:513
const EnumeratorListElement & back() const
Definition enumerator.h:568
void push_back(const EnumeratorListElement &x)
Definition enumerator.h:526
void emplace_back(Args &&... args)
Definition enumerator.h:535
EnumeratorListElement m_enumerator_element_cache
Definition enumerator.h:502
EnumeratorListElement & back()
Definition enumerator.h:573
EnumeratorListElement & front()
Definition enumerator.h:563
enumerator_queue(const EnumeratorListElement &value)
Initializes the enumerator queue with the given value.
Definition enumerator.h:522
data_expression scratch_data_expression
Definition enumerator.h:512
const EnumeratorListElement & front() const
Definition enumerator.h:558
\brief A function sort
const sort_expression & codomain() const
\brief A function symbol
const sort_expression & sort() const
Components for generating an arbitrary element of a sort.
bool find_representative(const function_symbol &symbol, std::set< sort_expression > &visited_sorts, data_expression &result)
Finds a representative of the form f(t1,...,tn) where f is the function symbol.
std::map< sort_expression, data_expression > m_representatives_cache
Serves as a cache for later find operations.
const data_specification & m_specification
Data specification context.
bool search_for_lexicographically_minimal_symbol(function_symbol &f_result, const sort_expression &sort, const std::vector< function_symbol > &function_symbols)
bool find_representative(const sort_expression &sort, std::set< sort_expression > &visited_sorts, data_expression &result)
Finds a representative element for an arbitrary sort expression.
data_expression operator()(const sort_expression &sort)
Returns a representative of a sort.
representative_generator(const data_specification &specification)
Constructor with data specification as context.
void set_representative(const sort_expression &sort, const data_expression &representative)
Sets a data expression as representative of the sort.
Rewriter that operates on data expressions.
Definition rewriter.h:84
void operator()(data_expression &result, const data_expression &d) const
Rewrites a data expression.
Definition rewriter.h:169
rewriter(const std::shared_ptr< detail::Rewriter > &r)
Constructor for internal use.
Definition rewriter.h:108
static const data_specification & default_specification()
Default specification used if no specification is specified at construction.
Definition rewriter.h:100
void operator()(data_expression &result, const data_expression &d, substitution_type &sigma) const
Rewrites the data expression d, and on the fly applies a substitution function to data variables.
Definition rewriter.h:225
void thread_initialise()
Initialises this rewriter with thread dependent information.
Definition rewriter.h:153
data_expression operator()(const data_expression &d, substitution_type &sigma) const
Rewrites the data expression d, and on the fly applies a substitution function to data variables.
Definition rewriter.h:211
static substitution_type & empty_substitution()
Definition rewriter.h:87
rewriter clone()
Create a clone of the rewriter in which the underlying rewriter is copied, and not passed as a shared...
Definition rewriter.h:143
rewriter(const data_specification &d=rewriter::default_specification(), const strategy s=rewrite_strategy::jitty)
Constructor.
Definition rewriter.h:126
rewriter(const rewriter &r)=default
Constructor.
void operator()(data_expression &result, const data_expression &d, const SubstitutionFunction &sigma) const
Rewrites the data expression d, and on the fly applies a substitution function. to data variables.
Definition rewriter.h:193
data_expression operator()(const data_expression &d, const SubstitutionFunction &sigma) const
Rewrites the data expression d, and on the fly applies a substitution function. to data variables.
Definition rewriter.h:180
rewriter(const data_specification &d, const EquationSelector &selector, const strategy s=rewrite_strategy::jitty)
Constructor.
Definition rewriter.h:135
data_expression operator()(const data_expression &d) const
Rewrites a data expression.
Definition rewriter.h:161
Identifier generator that stores the identifiers of the context in a set. Using the operator()() and ...
\brief A sort expression
Component for selecting a subset of equations that are actually used in an encompassing specification...
Definition selection.h:36
\brief A data variable
Definition variable.h:25
variable(const variable &) noexcept=default
Move semantics.
const sort_expression & sort() const
Definition variable.h:40
variable(const core::identifier_string &name, const sort_expression &sort)
Constructor.
Definition variable.h:59
\brief A where expression
const assignment_list & assignments() const
const data_expression & body() const
Standard exception class for reporting runtime errors.
Definition exception.h:27
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:435
void CheckRewriteRule(const data_equation &data_eqn)
Check that an mCRL2 data equation is a valid rewrite rule. If not, an runtime_error is thrown indicat...
Definition rewrite.cpp:603
static void checkPattern(const data_expression &p)
Definition rewrite.cpp:588
static void check_vars(application::const_iterator begin, const application::const_iterator &end, const std::set< variable > &vars, std::set< variable > &used_vars)
Definition rewrite.cpp:545
void set_enumerator_iteration_limit(std::size_t size)
bool isValidRewriteRule(const data_equation &data_eqn)
Check whether or not an mCRL2 data equation is a valid rewrite rule.
Definition rewrite.cpp:661
static bool occur_check(const variable &v, const atermpp::aterm &e)
Definition rewrite.cpp:44
data_expression make_if_expression_(std::size_t &function_index, const std::size_t argument_index, const std::vector< data_expression_vector > &data_domain_expressions, const data_expression_vector &codomain_expressions, const variable_vector &parameters)
Definition enumerator.h:45
bool is_enumerable(const data_specification &dataspec, const Rewriter &rewr, const sort_expression &sort, std::list< sort_expression > &parents)
Definition enumerator.h:157
static void checkPattern(application::const_iterator begin, const application::const_iterator &end)
Definition rewrite.cpp:579
Answer
A prover that uses EQ-BDDs.
Definition bdd_prover.h:77
variable_list set_intersection(const variable_list &x, const std::set< variable > &y)
Returns the intersection of a list and a set of variables.
static void check_vars(const data_expression &expr, const std::set< variable > &vars, std::set< variable > &used_vars)
Definition rewrite.cpp:556
variable_list set_difference(const variable_list &x, const std::set< variable > &y)
Returns a list of variables equal to the first list, not containing the elements in the second.
data_expression make_set_(std::size_t function_index, const sort_expression &element_sort, const data_expression_vector &set_elements)
Definition enumerator.h:30
bool compute_finite_function_sorts(const function_sort &sort, enumerator_identifier_generator &id_generator, const data::data_specification &dataspec, Rewriter datar, data_expression_vector &result, variable_list &function_parameter_list)
Computes the elements of a finite function sort, and puts them in result. If there are too many eleme...
Definition enumerator.h:107
bool compute_finite_set_elements(const container_sort &sort, const data_specification &dataspec, Rewriter datar, MutableSubstitution &sigma, data_expression_vector &result, enumerator_identifier_generator &id_generator)
Computes the elements of a finite set sort, and puts them in result. If there are too many elements,...
Definition enumerator.h:80
A collection of utilities for lazy expression construction.
data_expression and_(data_expression const &p, data_expression const &q)
Returns an expression equivalent to p or q.
Namespace for system defined sort bag.
Definition bag1.h:35
bool is_bag(const sort_expression &e)
Recogniser for sort expression Bag(s)
Definition bag1.h:52
Namespace for system defined sort bool_.
Definition bool.h:29
void make_not(data_expression &result, const data_expression &arg0)
Make an application of function symbol !.
Definition bool.h:204
bool is_false_function_symbol(const atermpp::aterm &e)
Recogniser for function false.
Definition bool.h:116
void make_and(data_expression &result, const data_expression &arg0, const data_expression &arg1)
Make an application of function symbol &&.
Definition bool.h:268
bool is_or_application(const atermpp::aterm &e)
Recogniser for application of ||.
Definition bool.h:342
const basic_sort & bool_()
Constructor for sort expression Bool.
Definition bool.h:41
bool is_implies_application(const atermpp::aterm &e)
Recogniser for application of =>.
Definition bool.h:406
application not_(const data_expression &arg0)
Application of function symbol !.
Definition bool.h:194
application and_(const data_expression &arg0, const data_expression &arg1)
Application of function symbol &&.
Definition bool.h:257
application implies(const data_expression &arg0, const data_expression &arg1)
Application of function symbol =>.
Definition bool.h:385
application or_(const data_expression &arg0, const data_expression &arg1)
Application of function symbol ||.
Definition bool.h:321
const function_symbol & false_()
Constructor for function symbol false.
Definition bool.h:106
bool is_and_application(const atermpp::aterm &e)
Recogniser for application of &&.
Definition bool.h:278
void make_or(data_expression &result, const data_expression &arg0, const data_expression &arg1)
Make an application of function symbol ||.
Definition bool.h:332
bool is_true_function_symbol(const atermpp::aterm &e)
Recogniser for function true.
Definition bool.h:84
bool is_not_application(const atermpp::aterm &e)
Recogniser for application of !.
Definition bool.h:214
const function_symbol & true_()
Constructor for function symbol true.
Definition bool.h:74
void make_implies(data_expression &result, const data_expression &arg0, const data_expression &arg1)
Make an application of function symbol =>.
Definition bool.h:396
Namespace for system defined sort fbag.
Definition fbag1.h:34
bool is_fbag(const sort_expression &e)
Recogniser for sort expression FBag(s)
Definition fbag1.h:51
Namespace for system defined sort fset.
Definition fset1.h:32
bool is_fset(const sort_expression &e)
Recogniser for sort expression FSet(s)
Definition fset1.h:49
function_symbol empty(const sort_expression &s)
Constructor for function symbol {}.
Definition fset1.h:72
container_sort fset(const sort_expression &s)
Constructor for sort expression FSet(S)
Definition fset1.h:38
Namespace for system defined sort int_.
bool is_cint_application(const atermpp::aterm &e)
Recogniser for application of @cInt.
Definition int1.h:121
bool is_integer_constant(const data_expression &n)
Determines whether n is an integer constant.
Namespace for system defined sort list.
Definition list1.h:33
bool is_list(const sort_expression &e)
Recogniser for sort expression List(s)
Definition list1.h:50
Namespace for system defined sort nat.
bool is_cnat_application(const atermpp::aterm &e)
Recogniser for application of @cNat.
Definition nat1.h:181
bool is_nat(const sort_expression &e)
Recogniser for sort expression Nat.
Definition nat1.h:53
bool is_natural_constant(const data_expression &n)
Determines whether n is a natural constant.
Namespace for system defined sort pos.
bool is_positive_constant(const data_expression &n)
Determines whether n is a positive constant.
bool is_pos(const sort_expression &e)
Recogniser for sort expression Pos.
Definition pos1.h:52
bool is_add_with_carry_application(const atermpp::aterm &e)
Recogniser for application of @addc.
Definition pos1.h:567
Namespace for system defined sort real_.
bool is_abs_application(const atermpp::aterm &e)
Recogniser for application of abs.
Definition real1.h:791
bool is_plus_application(const atermpp::aterm &e)
Recogniser for application of +.
Definition real1.h:1133
bool is_maximum_application(const atermpp::aterm &e)
Recogniser for application of max.
Definition real1.h:631
bool is_pred_application(const atermpp::aterm &e)
Recogniser for application of pred.
Definition real1.h:1040
bool is_succ_application(const atermpp::aterm &e)
Recogniser for application of succ.
Definition real1.h:957
bool is_times_application(const atermpp::aterm &e)
Recogniser for application of *.
Definition real1.h:1303
bool is_negate_application(const atermpp::aterm &e)
Recogniser for application of -.
Definition real1.h:874
bool is_minimum_application(const atermpp::aterm &e)
Recogniser for application of min.
Definition real1.h:716
bool is_minus_application(const atermpp::aterm &e)
Recogniser for application of -.
Definition real1.h:1218
Namespace for system defined sort set_.
Definition set1.h:33
bool is_set(const sort_expression &e)
Recogniser for sort expression Set(s)
Definition set1.h:50
function_symbol false_function(const sort_expression &s)
Constructor for function symbol @false_.
Definition set1.h:663
application constructor(const sort_expression &s, const data_expression &arg0, const data_expression &arg1)
Application of function symbol @set.
Definition set1.h:98
bool is_application(const data_expression &t)
Returns true if the term t is an application.
bool is_where_clause(const atermpp::aterm &x)
Returns true if the term t is a where clause.
bool is_abstraction(const atermpp::aterm &x)
Returns true if the term t is an abstraction.
application if_(const data_expression &arg0, const data_expression &arg1, const data_expression &arg2)
Application of function symbol if.
Definition standard.h:224
data_expression_vector enumerate_expressions(const sort_expression &s, const data_specification &dataspec, const Rewriter &rewr, enumerator_identifier_generator &id_generator)
Returns a vector with all expressions of sort s.
std::ostream & operator<<(std::ostream &out, const enumerator_list_element_with_substitution< Expression > &p)
Definition enumerator.h:481
bool is_forall(const atermpp::aterm &x)
Returns true if the term t is a universal quantification.
bool is_function_symbol(const atermpp::aterm &x)
Returns true if the term t is a function symbol.
std::set< data::variable > find_free_variables(const data::data_expression &x)
Definition data.cpp:98
bool is_exists(const atermpp::aterm &x)
Returns true if the term t is an existential quantification.
static bool is_enumerable(const data_specification &dataspec, const Rewriter &rewr, const sort_expression &sort)
Definition enumerator.h:220
bool is_function_sort(const atermpp::aterm &x)
Returns true if the term t is a function sort.
bool is_machine_number(const atermpp::aterm &x)
Returns true if the term t is a machine_number.
std::ostream & operator<<(std::ostream &out, const enumerator_list_element< Expression > &p)
Definition enumerator.h:465
bool is_lambda(const atermpp::aterm &x)
Returns true if the term t is a lambda abstraction.
data_expression_vector enumerate_expressions(const sort_expression &s, const data_specification &dataspec, const Rewriter &rewr)
Returns a vector with all expressions of sort s.
const data::data_expression & undefined_data_expression()
Returns a data expression that corresponds to 'undefined'.
Definition undefined.h:58
bool is_variable(const atermpp::aterm &x)
Returns true if the term t is a variable.
bool operator()(const atermpp::aterm &t) const
Definition rewrite.cpp:37
void operator()(data_expression &result, const data_expression &t, Rewriter::substitution_type &sigma) const
data_expression operator()(const data_expression &t, Rewriter::substitution_type &sigma) const
void operator()(data_expression &result, const data_expression &t) const
data_expression operator()(const data_expression &t) const
Enumerator exception.
Definition enumerator.h:214
enumerator_error(const std::string &message)
Definition enumerator.h:215
Substitution that stores the assignments as a sequence of variables and a sequence of expressions....
data::data_expression operator()(const data::variable &v) const