12#ifndef MCRL2_DATA_ENUMERATOR_H
13#define MCRL2_DATA_ENUMERATOR_H
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"
33 for (
const data_expression& set_element: set_elements)
35 if (function_index % 2 == 1)
37 result=sort_fset::insert(element_sort, set_element, result);
39 function_index = function_index / 2;
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)
51 if (argument_index == data_domain_expressions.size())
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];
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)
62 if (i == current_enumerated_elements.rbegin())
64 result = make_if_expression_(function_index, argument_index + 1, data_domain_expressions, codomain_expressions, parameters);
68 const data_expression lhs = make_if_expression_(function_index, argument_index + 1, data_domain_expressions, codomain_expressions, parameters);
71 result = if_(equal_to(parameters[argument_index], *i), lhs, result);
79template <
class Rewriter, IsSubstitution MutableSubstitution>
82 Rewriter datar, MutableSubstitution& sigma,
83 data_expression_vector& result,
88 data_expression_vector all_element_expressions = enumerate_expressions(sort.element_sort(), dataspec, datar, id_generator);
89 if (all_element_expressions.size() >= 32)
93 if (all_element_expressions.size() > 16)
95 mCRL2log(log::log_level_t::warning) <<
"Generate 2^" << all_element_expressions.size() <<
" sets to enumerate sort " << sort <<
"\n";
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)
100 result.push_back(datar(make_set_(i, sort.element_sort(), all_element_expressions), sigma));
106template <
class Rewriter>
111 data_expression_vector& result,
112 variable_list& function_parameter_list
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;
120 for (
const sort_expression& s: sort.domain())
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);
127 if (total_domain_size * utilities::ceil_log2(codomain_expressions.size()) >= 32)
132 if (total_domain_size * utilities::ceil_log2(codomain_expressions.size()) > 16)
134 mCRL2log(log::log_level_t::warning) <<
"Generate " << codomain_expressions.size() <<
"^" << total_domain_size <<
" functions to enumerate sort " << sort <<
"\n";
137 function_parameter_list = variable_list(function_parameters.begin(), function_parameters.end());
139 const std::size_t number_of_functions = utilities::power_size_t(codomain_expressions.size(), total_domain_size);
141 if (number_of_functions == 1)
143 result.push_back(abstraction(lambda_binder(), function_parameter_list, codomain_expressions.front()));
147 for (std::size_t i = 0; i < number_of_functions; ++i)
149 std::size_t function_index = i;
150 result.push_back(abstraction(lambda_binder(), function_parameter_list, make_if_expression_(function_index, 0, domain_expressions, codomain_expressions, function_parameters)));
156template <
typename Rewriter>
158 const Rewriter& rewr,
160 std::list<sort_expression>& parents)
162 assert(sort == normalize_sorts(sort,dataspec));
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);
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));
186 const function_symbol_vector& constructors = dataspec.constructors(sort,
true);
187 if (constructors.empty())
193 if (std::find(parents.begin(), parents.end(), sort) != parents.end())
197 parents.push_back(sort);
198 bool result = std::all_of(constructors.begin(), constructors.end(), [&](
const function_symbol& constructor)
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); });
219template <
typename Rewriter>
222 std::list<sort_expression> parentstack;
223 return detail::is_enumerable(dataspec, rewr, sort, parentstack);
235 using expression_type = Expression;
247 const Expression& phi_,
255 const Expression& phi_,
286 phi = atermpp::down_cast<Expression>(data::undefined_data_expression());
300 void mark(atermpp::term_mark_stack& todo)
const
309 void set(
const data::variable_list& v_,
const Expression& phi_)
331 const Expression& phi_,
352 using expression_type = Expression;
364 const Expression& phi,
375 const data::variable_list& v,
376 const Expression& phi,
385 m_variables.push_front(d);
386 m_expressions.push_front(e);
390 template <
typename VariableList, IsSubstitution MutableSubstitution,
typename Rewriter>
391 void add_assignments(
const VariableList& v, MutableSubstitution& result,
const Rewriter& rewriter)
const
397 result[v_i] = rewriter(sigma
(v_i
));
402 template <
typename VariableList, IsSubstitution MutableSubstitution>
413 template <
typename VariableList,
typename Rewriter>
418 return data_expression_list(v.begin(), v.end(), [&](
const data::variable& v_i) {
return rewriter(sigma(v_i)); });
423 return data::enumerator_substitution(m_variables, m_expressions);
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);
440 const Expression& 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);
455 const Expression& phi,
459 m_variables=elem.m_variables;
460 m_expressions=elem.m_expressions;
464template <
typename Expression>
468 const variable_list& variables = p.variables();
469 for (variable_list::const_iterator i = variables.begin(); i != variables.end(); ++i)
471 if (i != variables.begin())
475 out << *i <<
": " << i->sort();
477 return out <<
"], " << p.expression() <<
" }";
480template <
typename Expression>
484 const variable_list& variables = p.variables();
485 for (variable_list::const_iterator i = variables.begin(); i != variables.end(); ++i)
487 if (i != variables.begin())
491 out << *i <<
": " << i->sort();
493 return out <<
"], " << p.expression() <<
", " << p.sigma() <<
" }";
497template <
typename EnumeratorListElement>
515 using value_type = EnumeratorListElement;
528#ifdef MCRL2_LOG_ENUMERATOR
529 std::cout <<
"push_back " << x << std::endl;
534 template <
class... Args>
537#ifdef MCRL2_LOG_ENUMERATOR
538 std::cout <<
"emplace_back " << EnumeratorListElement(args...) << std::endl;
540 P.emplace_back(std::forward<Args>(args)...);
558 const EnumeratorListElement&
front()
const
568 const EnumeratorListElement&
back()
const
588 template <
class... Args>
608 const DataRewriter&
r;
619#ifdef MCRL2_ENUMERATOR_COUNT_REWRITE_CALLS
625 std::ostringstream out;
626 out << x <<
": " << x.sort();
630 template <
typename Expression, IsSubstitution MutableSubstitution>
632 Expression
rewrite(
const Expression& phi, MutableSubstitution& sigma)
const
634#ifdef MCRL2_ENUMERATOR_COUNT_REWRITE_CALLS
637 return const_cast<Rewriter&>(
R)(phi, sigma);
640 template <
typename Expression, IsSubstitution MutableSubstitution>
642 void rewrite(Expression& result,
const Expression& phi, MutableSubstitution& sigma)
const
644#ifdef MCRL2_ENUMERATOR_COUNT_REWRITE_CALLS
647 const_cast<Rewriter&>(
R)(result, phi, sigma);
653 const DataRewriter& datar_,
655 bool accept_solutions_with_variables,
670#ifdef MCRL2_ENUMERATOR_COUNT_REWRITE_CALLS
671 std::cout <<
"number of enumerator rewrite calls: " << rewrite_calls << std::endl;
680 template <
typename T>
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>
706 MutableSubstitution& sigma,
707 ReportSolution report_solution,
708 Reject reject = Reject(),
709 Accept accept = Accept()
713 const EnumeratorListElement& p = P.front();
715 auto add_element = [&](
const data::variable_list& variables,
716 const typename EnumeratorListElement::expression_type& phi,
721 rewrite(P.scratch_expression, phi, sigma);
722 if (reject(P.scratch_expression))
726 if ((accept(P.scratch_expression) && m_accept_solutions_with_variables) || variables.empty())
728 return report_solution(P.enumerator_element_cache(variables, P.scratch_expression, p, v, e));
730 P.emplace_back(variables, P.scratch_expression, p, v, e);
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,
739 const bool =
false) ->
bool
741 rewrite(P.scratch_expression, phi, sigma);
742 if (reject(P.scratch_expression))
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))
751 return report_solution(
752 P.enumerator_element_cache(variables + added_variables, P.scratch_expression, p, v, e));
754 if (added_variables_empty)
756 P.emplace_back(variables, P.scratch_expression, p, v, e);
760 P.emplace_back(variables + added_variables, P.scratch_expression, p, v, e);
765 const variable_list& v = p.variables();
766 const typename EnumeratorListElement::expression_type& phi = p.expression();
770 rewrite(P.scratch_expression, phi, sigma);
771 if (reject(P.scratch_expression))
775 return report_solution(P.enumerator_element_cache(v, P.scratch_expression, p));
779 const variable_list& v_tail = v.tail();
788 const function_sort& function = atermpp::down_cast<function_sort>(v1_sort);
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);
796 throw mcrl2::runtime_error(
"Sort " + data::pp(v1_sort) +
" has too many elements to enumerate.");
799 for (
const data_expression& f: function_sorts)
802 if (add_element(v_tail, phi, v1, f))
811 throw mcrl2::runtime_error(
"Cannot enumerate elements of function sort " + data::pp(v1_sort) +
".");
816 const sort_expression& element_sort = atermpp::down_cast<container_sort>(v1_sort).element_sort();
823 if (add_element_with_variables(v_tail, { fset_variable }, phi, v1, e,
true))
831 throw mcrl2::runtime_error(
"Cannot enumerate elements of set sort " + data::pp(v1_sort) +
".");
836 const container_sort& fset = atermpp::down_cast<container_sort>(v1_sort);
839 data_expression_vector set_elements;
840 bool result = detail::compute_finite_set_elements(fset, dataspec, r, sigma, set_elements, id_generator);
843 throw mcrl2::runtime_error(
"Finite set sort " + data::pp(v1_sort) +
" has too many elements to enumerate.");
846 for (
const data_expression& e: set_elements)
849 if (add_element(v_tail, phi, v1, e))
858 throw mcrl2::runtime_error(
"Cannot enumerate elements of finite set sort " + data::pp(v1_sort) +
".");
863 throw mcrl2::runtime_error(
"Cannot enumerate elements of bag sort " + data::pp(v1_sort) +
".");
867 throw mcrl2::runtime_error(
"Cannot enumerate elements of finite bag sort " + data::pp(v1_sort) +
".");
871 const function_symbol_vector& C = dataspec.constructors(v1_sort);
874 for (
const function_symbol& c: C)
876 if (data::is_function_sort(c.sort()))
878 const sort_expression_list& domain = atermpp::down_cast<data::function_sort>(c.sort()).domain();
879 atermpp::make_term_list(P.scratch_variable_list,
882 [&](
const data::sort_expression& s) {
return data::variable(id_generator(), s); });
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))
895 r(P.scratch_data_expression,c,sigma);
896 sigma[v1] = P.scratch_data_expression;
897 if (add_element(v_tail, phi, v1, P.scratch_data_expression))
907 throw mcrl2::runtime_error(
"Cannot enumerate elements of sort " + data::pp(v1_sort) +
" without constructors.");
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>
938 std::size_t count = 0;
941 if (count++ >= m_max_count)
945 if (enumerate_front(P, sigma, report_solution, reject, accept))
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>
980 return enumerate_all(P, sigma, report_solution, reject, accept);
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>
1011 P.emplace_back(vars, cond);
1012 return enumerate_all(P, sigma, report_solution, reject, accept);
1027template <
class Rewriter>
1033 using term_type =
typename Rewriter::term_type;
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;
1042 const variable_list v_list{ v };
1043 E.
template enumerate<enumerator_element>(
1047 [&](
const enumerator_element& p)
1049 p.add_assignments(v_list, sigma, rewr);
1050 result.push_back(sigma(v));
1062template <
class Rewriter>
1068 return enumerate_expressions(s, dataspec, rewr, id_generator);
aterm()
Default constructor.
A unordered_map class in which aterms can be stored.
An abstraction expression.
const variable_list & variables() const
abstraction(const binder_type &binding_operator, const variable_list &variables, const data_expression &body)
Constructor.
const data_expression & body() const
const binder_type & binding_operator() const
Rewriter class for the mCRL2 Library. It only works for terms of type data_expression and data_expres...
const data::enumerator_identifier_generator & identifier_generator() const
Expose the identifier generator present in m_rewriter.
basic_rewriter(const data_specification &d, const used_data_equation_selector &equation_selector, const strategy s=rewrite_strategy::jitty)
Constructor.
basic_rewriter(const std::shared_ptr< detail::Rewriter > &r)
Constructor.
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.
basic_rewriter(const data_specification &d, const strategy s=rewrite_strategy::jitty)
Constructor.
const sort_expression & element_sort() const
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.
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.
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.
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.
static bool is_false(const data_expression &a_bdd)
Method that indicates whether or not a BDD equals false.
static const mcrl2::data::data_expression & get_guard(const mcrl2::data::data_expression &a_bdd)
Method that returns the guard of a BDD.
static const mcrl2::data::data_expression & argument(const mcrl2::data::data_expression &x, std::size_t n)
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.
static bool is_true(const data_expression &a_bdd)
Method that indicates whether or not a BDD equals true.
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.
Induction f_induction
Class that creates all statements needed to prove a given property using induction.
strategy rewriter_strategy() const
Returns the strategy of the rewriter used inside this proving rewriter.
std::vector< variable > f_variables
The variables in the expression in order.
std::shared_ptr< BDD_Simplifier > f_bdd_simplifier
Class that simplifies a BDD.
static constexpr bool f_reverse
Flag indicating whether or not the result of the comparison between the first two arguments.
void set_substitution(substitution_type &sigma)
Set the substitution to be used to construct the BDD.
void set_formula(const data_expression &formula)
Sets Prover::f_formula to formula. precondition: the argument passed as parameter formula is an expre...
std::string indent(size_t n)
bool smallest(const data_expression &formula, data_expression &result)
Returns the smallest guard in the formula formula.
data_expression f_bdd
A binary decision diagram in the internal representation of mCRL2.
const Info f_info
A class that provides information about expressions.
data_expression bdd_down(const data_expression &formula, const size_t a_indent=0)
Creates the EQ-BDD corresponding to the formula formula.
static constexpr bool f_full
Flag indicating whether or not the arguments of equality functions are taken into account.
void eliminate_paths()
Removes all inconsistent paths from the BDD BDD_Prover::f_bdd.
BDD_Prover(const rewriter &r, double time_limit=0, bool apply_induction=false)
data_expression get_counter_example()
Returns all the guards on a path in the BDD that leads to a leaf labelled "false",...
substitution_type bdd_sigma
A binary decision diagram in the internal representation of the rewriter.
Answer f_tautology
A flag that indicates whether or not the formala Prover::f_formula is a tautology.
Answer is_contradiction()
Indicates whether or not the formula Prover::f_formula is a contradiction.
data_expression f_formula
An expression of sort Bool.
std::chrono::milliseconds f_deadline
A timestamp representing the moment when the maximal amount of milliseconds has been spent on process...
bool f_processed
A flag that indicates whether or not the formala Prover::f_formula has been processed.
void update_answers()
Updates the values of Prover::f_tautology and Prover::f_contradiction.
std::shared_ptr< detail::Rewriter > get_rewriter()
Returns the rewriter used by this prover (i.e. it returns Prover::f_rewriter).
const double f_time_limit
An integer representing the maximal amount of seconds to be spent on processing a formula.
Manipulator f_manipulator
A class that can be used to manipulate expressions.
bool f_apply_induction
A flag indicating whether or not induction on lists is applied.
void build_bdd()
Constructs the EQ-BDD corresponding to the formula Prover::f_formula.
std::unordered_map< data_expression, data_expression > f_smallest
A hashtable that maps formulas to the smallest guard occuring in those formulas.
Answer f_contradiction
A flag that indicates whether or not the formala Prover::f_formula is a contradiction.
std::unordered_map< data_expression, data_expression > f_formula_to_bdd
A hashtable that maps formulas to BDDs.
data_expression get_bdd()
Returns the BDD BDD_Prover::f_bdd.
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...
void set_substitution_internal(substitution_type &sigma)
Set the substitution in internal format to be used to construct the BDD.
Answer is_tautology()
Indicates whether or not the formula Prover::f_formula is a tautology.
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)
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.
sort_expression get_sort_of_list_elements(const variable &a_list_variable) const
data_expression create_hypotheses(const data_expression &a_hypothesis, variable_list a_list_of_variables, variable_list a_list_of_dummies) const
bool can_apply_induction() const
std::size_t f_count
The number of variables used during the last application of induction.
variable_vector f_list_variables
data_expression f_formula
An expression of sort Bool in mCRL2 format.
set_identifier_generator fresh_identifier_generator
variable_vector recurse_expression_for_lists(const data_expression &a_expression) const
variable get_fresh_dummy(const sort_expression &a_sort)
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)
void initialize(const data_expression &a_formula)
data_expression apply_induction()
data_expression apply_induction_one(const core::identifier_string &fresh_name) const
Base class for classes that provide information about the structure of.
data_expression get_operator(const data_expression &term) const
Returns the main operator of the term term;.
constexpr Info(bool a_full, bool a_reverse)
Constructor that initializes the rewriter.
Compare_Result compare_term_free_variables(const data_expression &term1, const data_expression &term2) const
Compare_Result compare_guard_equality(const data_expression &guard1, const data_expression &guard2) const
Compares two guards by their arguments.
Compare_Result compare_address(const atermpp::aterm &term1, const atermpp::aterm &term2) const
static bool occurs(const data_expression &t1, const data_expression &t2)
Compare_Result lexico(const Compare_Result &a_result1, const Compare_Result &a_result2) const
Compare_Result compare_term_type(const data_expression &term1, const data_expression &term2) const
Compares terms by their type.
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.
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.
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.
const bool f_full
Flag indicating whether or not the arguments of equality functions are taken into account.
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.
Compare_Result compare_term(const data_expression &term1, const data_expression &term2) const
Compares two terms.
Compare_Result compare_guard(const data_expression &guard1, const data_expression &guard2, const std::vector< variable > &f_variables) const
Compares two guards.
const bool f_reverse
Flag indicating whether or not the result of the comparison between the first two arguments.
Base class for classes that provide functionality to modify or create terms.
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...
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.
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.
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.
RewriterProver(const data_specification &data_spec, mcrl2::data::rewriter::strategy strat, const used_data_equation_selector &equations_selector)
RewriterProver(const RewriterProver &other)=delete
data_expression rewrite(const data_expression &t, substitution_type &sigma) override
Rewrite an mCRL2 data term.
rewrite_strategy getStrategy() override
Get rewriter strategy that is used.
void rewrite(data_expression &result, const data_expression &t, substitution_type &sigma) override
Rewrite an mCRL2 data term.
~RewriterProver() override=default
RewriterProver(const RewriterProver &rewr, BDD_Prover prover_obj_)
void thread_initialise() override
std::shared_ptr< Rewriter > clone() override
Clone a rewriter.
Rewriter interface class.
void rewrite_where(data_expression &result, const where_clause &term, substitution_type &sigma)
virtual void thread_initialise()
Rewriter(const data_specification &data_spec, const used_data_equation_selector &eq_selector)
Constructor. Do not use directly; use createRewriter() function instead.
std::map< function_symbol, std::size_t > f_operators
~SMT_LIB_Solver() override=default
void translate_less_than(const data_expression &a_clause)
void produce_notes_for_operators()
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)
std::set< variable > f_pos_variables
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 produce_notes_for_predicates()
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)
std::string f_operators_extrafuns
std::set< variable > f_nat_variables
std::string f_variables_extrafuns
void translate_variable(const variable &a_clause)
std::string f_sorts_notes
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 declare_predicates()
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)
std::string f_predicates_notes
void produce_notes_for_sorts()
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)
std::string f_operators_notes
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)
std::set< variable > f_variables
void translate_multiplication(const data_expression &a_clause)
const data_expression & left(const data_expression &x) const
virtual ~SMT_Solver()=default
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.
void rewrite(Expression &result, const Expression &phi, MutableSubstitution &sigma) const
enumerator_identifier_generator & id_generator
std::size_t m_max_count
max_count The enumeration is aborted after max_count iterations
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....
void reset_id_generator()
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...
std::size_t max_count() const
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 ...
std::string print(const data::variable &x) const
bool m_accept_solutions_with_variables
If true, solutions with a non-empty list of variables may be reported.
const data::data_specification & dataspec
A data specification.
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....
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)())
Expression rewrite(const Expression &phi, MutableSubstitution &sigma) const
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...
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])
data::data_expression_list assign_expressions(const VariableList &v, const Rewriter &rewriter) const
Returns the right hand sides corresponding to the variables v.
enumerator_list_element_with_substitution(const data::variable_list &v, const Expression &phi)
Constructs the element (v, phi, [])
void remove_assignments(const VariableList &v, MutableSubstitution &result) const
Removes the assignments corresponding with this element from the substitution result.
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]).
data::variable_list m_variables
data::data_expression_list m_expressions
void add_assignments(const VariableList &v, MutableSubstitution &result, const Rewriter &rewriter) const
Adds the assignments that correspond with this element to the substitution result.
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]).
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...
data::enumerator_substitution sigma() const
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])
enumerator_list_element_with_substitution()=default
Default constructor.
The default element for the todo list of the enumerator.
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)
void set(const data::variable_list &v_, const Expression &phi_)
Set the variables and the condition explicitly.
enumerator_list_element(data::variable_list v_, const Expression &phi_)
Constructs the element (v, phi)
enumerator_list_element(data::variable_list v_, const Expression &phi_, const enumerator_list_element &)
Constructs the element (v, phi)
bool is_valid() const
Returns true if the element is valid. If it becomes false, this is used to signal that the enumeratio...
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]).
Expression & expression()
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...
void set(const data::variable_list &v_, const Expression &phi_, const enumerator_list_element &)
Set the variables and the condition explicitly.
void invalidate()
Invalidates the element, by giving phi an undefined value.
const data::variable_list & variables() const
const Expression & expression() const
Contains the enumerator queue.
atermpp::deque< EnumeratorListElement > P
atermpp::deque< EnumeratorListElement >::size_type size() const
enumerator_queue()=default
Default constructor.
const EnumeratorListElement & enumerator_element_cache(const Args &... args)
EnumeratorListElement::expression_type scratch_expression
variable_list scratch_variable_list
const EnumeratorListElement & back() const
void push_back(const EnumeratorListElement &x)
void emplace_back(Args &&... args)
EnumeratorListElement m_enumerator_element_cache
EnumeratorListElement & back()
EnumeratorListElement & front()
enumerator_queue(const EnumeratorListElement &value)
Initializes the enumerator queue with the given value.
data_expression scratch_data_expression
const EnumeratorListElement & front() const
const sort_expression & codomain() const
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.
void operator()(data_expression &result, const data_expression &d) const
Rewrites a data expression.
rewriter(const std::shared_ptr< detail::Rewriter > &r)
Constructor for internal use.
static const data_specification & default_specification()
Default specification used if no specification is specified at construction.
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.
void thread_initialise()
Initialises this rewriter with thread dependent information.
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.
static substitution_type & empty_substitution()
rewriter clone()
Create a clone of the rewriter in which the underlying rewriter is copied, and not passed as a shared...
rewriter(const data_specification &d=rewriter::default_specification(), const strategy s=rewrite_strategy::jitty)
Constructor.
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.
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.
rewriter(const data_specification &d, const EquationSelector &selector, const strategy s=rewrite_strategy::jitty)
Constructor.
data_expression operator()(const data_expression &d) const
Rewrites a data expression.
Identifier generator that stores the identifiers of the context in a set. Using the operator()() and ...
Component for selecting a subset of equations that are actually used in an encompassing specification...
variable(const variable &) noexcept=default
Move semantics.
const sort_expression & sort() const
variable(const core::identifier_string &name, const sort_expression &sort)
Constructor.
\brief A where expression
const assignment_list & assignments() const
const data_expression & body() const
Standard exception class for reporting runtime errors.
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
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...
static void checkPattern(const data_expression &p)
static void check_vars(application::const_iterator begin, const application::const_iterator &end, const std::set< variable > &vars, std::set< variable > &used_vars)
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.
static bool occur_check(const variable &v, const atermpp::aterm &e)
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 ¶meters)
bool is_enumerable(const data_specification &dataspec, const Rewriter &rewr, const sort_expression &sort, std::list< sort_expression > &parents)
static void checkPattern(application::const_iterator begin, const application::const_iterator &end)
Answer
A prover that uses EQ-BDDs.
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)
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)
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...
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,...
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.
bool is_bag(const sort_expression &e)
Recogniser for sort expression Bag(s)
Namespace for system defined sort bool_.
void make_not(data_expression &result, const data_expression &arg0)
Make an application of function symbol !.
bool is_false_function_symbol(const atermpp::aterm &e)
Recogniser for function false.
void make_and(data_expression &result, const data_expression &arg0, const data_expression &arg1)
Make an application of function symbol &&.
bool is_or_application(const atermpp::aterm &e)
Recogniser for application of ||.
const basic_sort & bool_()
Constructor for sort expression Bool.
bool is_implies_application(const atermpp::aterm &e)
Recogniser for application of =>.
application not_(const data_expression &arg0)
Application of function symbol !.
application and_(const data_expression &arg0, const data_expression &arg1)
Application of function symbol &&.
application implies(const data_expression &arg0, const data_expression &arg1)
Application of function symbol =>.
application or_(const data_expression &arg0, const data_expression &arg1)
Application of function symbol ||.
const function_symbol & false_()
Constructor for function symbol false.
bool is_and_application(const atermpp::aterm &e)
Recogniser for application of &&.
void make_or(data_expression &result, const data_expression &arg0, const data_expression &arg1)
Make an application of function symbol ||.
bool is_true_function_symbol(const atermpp::aterm &e)
Recogniser for function true.
bool is_not_application(const atermpp::aterm &e)
Recogniser for application of !.
const function_symbol & true_()
Constructor for function symbol true.
void make_implies(data_expression &result, const data_expression &arg0, const data_expression &arg1)
Make an application of function symbol =>.
Namespace for system defined sort fbag.
bool is_fbag(const sort_expression &e)
Recogniser for sort expression FBag(s)
Namespace for system defined sort fset.
bool is_fset(const sort_expression &e)
Recogniser for sort expression FSet(s)
function_symbol empty(const sort_expression &s)
Constructor for function symbol {}.
container_sort fset(const sort_expression &s)
Constructor for sort expression FSet(S)
Namespace for system defined sort int_.
bool is_cint_application(const atermpp::aterm &e)
Recogniser for application of @cInt.
bool is_integer_constant(const data_expression &n)
Determines whether n is an integer constant.
Namespace for system defined sort list.
bool is_list(const sort_expression &e)
Recogniser for sort expression List(s)
Namespace for system defined sort nat.
bool is_cnat_application(const atermpp::aterm &e)
Recogniser for application of @cNat.
bool is_nat(const sort_expression &e)
Recogniser for sort expression Nat.
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.
bool is_add_with_carry_application(const atermpp::aterm &e)
Recogniser for application of @addc.
Namespace for system defined sort real_.
bool is_abs_application(const atermpp::aterm &e)
Recogniser for application of abs.
bool is_plus_application(const atermpp::aterm &e)
Recogniser for application of +.
bool is_maximum_application(const atermpp::aterm &e)
Recogniser for application of max.
bool is_pred_application(const atermpp::aterm &e)
Recogniser for application of pred.
bool is_succ_application(const atermpp::aterm &e)
Recogniser for application of succ.
bool is_times_application(const atermpp::aterm &e)
Recogniser for application of *.
bool is_negate_application(const atermpp::aterm &e)
Recogniser for application of -.
bool is_minimum_application(const atermpp::aterm &e)
Recogniser for application of min.
bool is_minus_application(const atermpp::aterm &e)
Recogniser for application of -.
Namespace for system defined sort set_.
bool is_set(const sort_expression &e)
Recogniser for sort expression Set(s)
function_symbol false_function(const sort_expression &s)
Constructor for function symbol @false_.
application constructor(const sort_expression &s, const data_expression &arg0, const data_expression &arg1)
Application of function symbol @set.
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.
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)
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)
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)
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)
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'.
bool is_variable(const atermpp::aterm &x)
Returns true if the term t is a variable.
static std::size_t max_enumerator_iterations
bool operator()(const atermpp::aterm &t) const
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
rewriter_wrapper(Rewriter *r)
bool operator()(const T &)
enumerator_error(const std::string &message)
Substitution that stores the assignments as a sequence of variables and a sequence of expressions....
data::data_expression operator()(const data::variable &v) const