mCRL2
Loading...
Searching...
No Matches
manipulator.h
Go to the documentation of this file.
1// Author(s): Luc Engelen
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/detail/prover/manipulator.h
10/// \brief Interface to classes Manipulator.
11
12#ifndef MCRL2_DATA_DETAIL_PROVER_MANIPULATOR_H
13#define MCRL2_DATA_DETAIL_PROVER_MANIPULATOR_H
14
15#include "mcrl2/data/detail/prover/info.h"
16
17namespace mcrl2::data::detail
18{
19
20/// \brief Base class for classes that provide functionality to modify or create terms.
21
23{
24 protected:
25 /// \brief A class that provides information on the structure of expressions in one of the
26 /// \brief internal formats of the rewriter.
27 const Info& f_info;
28
29 /// \brief A table used by the method Manipulator::orient.
30 /// The method Manipulator::orient stores resulting terms in this
31 /// table. If a term is encountered that has already been processed, it is
32 /// not processed again, but retreived from this table.
34
35 /// \brief Replaces all occurences of \c a_guard in \c a_formula by \c true. Additionally, if the variable
36 /// \brief on the righthand side of the guard is encountered in \c a_formula, it is replaced by the variable
37 /// \brief on the lefthand side.
39 const data_expression& a_formula,
40 const data_expression& a_guard,
41 std::unordered_map < data_expression, data_expression >& f_set_true) const
42 {
43 if (is_machine_number(a_formula))
44 {
45 return a_formula;
46 }
47
48 if (is_function_symbol(a_formula))
49 {
50 return a_formula;
51 }
52
53 if (is_abstraction(a_formula))
54 {
55 const abstraction& t=atermpp::down_cast<abstraction>(a_formula);
56 return abstraction(t.binding_operator(), t.variables(), set_true_auxiliary(t.body(), a_guard, f_set_true));
57 }
58
59 if (a_formula == a_guard)
60 {
61 return sort_bool::true_();
62 }
63
64 if (is_equal_to_application(a_guard))
65 {
66 const application& a = atermpp::down_cast<application>(a_guard);
67 if (a[1]==a_formula)
68 {
69 // We can be sure that a[1] does not occur in a[0], due to the ordering on terms
70 // Therefore, there are no never-ending substitutions occuring
71 return a[0];
72 }
73 }
74
75 if (is_variable(a_formula))
76 {
77 return a_formula;
78 }
79
80 std::unordered_map < data_expression, data_expression >::const_iterator i=f_set_true.find(a_formula);
81 if (i!=f_set_true.end())
82 {
83 return i->second;
84 }
85
86 const application& t=atermpp::down_cast<application>(a_formula);
87 data_expression v_result = application(t.head(),
88 t.begin(),
89 t.end(),
90 [&a_guard, &f_set_true, this](const data_expression& d){ return set_true_auxiliary(d, a_guard,f_set_true);});
91
92 f_set_true[a_formula]=v_result;
93
94 return v_result;
95 }
96
97 /// \brief Replaces all occurences of \c a_guard in \c a_formula by \c false.
99 const data_expression& a_formula,
100 const data_expression& a_guard,
101 std::unordered_map < data_expression, data_expression >& f_set_false) const
102 {
103 if (is_machine_number(a_formula))
104 {
105 return a_formula;
106 }
107
108 if (is_function_symbol(a_formula))
109 {
110 return a_formula;
111 }
112
113 if (is_abstraction(a_formula))
114 {
115 const abstraction& t=atermpp::down_cast<abstraction>(a_formula);
116 return abstraction(t.binding_operator(), t.variables(), set_false_auxiliary(t.body(), a_guard, f_set_false));
117 }
118
119 if (a_formula == a_guard)
120 {
121 return sort_bool::false_();
122 }
123
124 if (is_variable(a_formula))
125 {
126 return a_formula;
127 }
128
129 std::unordered_map < data_expression, data_expression >::const_iterator i=f_set_false.find(a_formula);
130 if (i!=f_set_false.end())
131 {
132 return i->second;
133 }
134
135 const application t(a_formula);
136 data_expression v_result = application(t.head(),
137 t.begin(),
138 t.end(),
139 [&a_guard, &f_set_false, this](const data_expression& d){ return set_false_auxiliary(d, a_guard,f_set_false);});
140 f_set_false[a_formula]=v_result;
141 return v_result;
142 }
143
144 public:
145 /// \brief Constructor initializing the rewriter and the field \c f_info.
146 Manipulator(const Info& a_info):
147 f_info(a_info)
148 {}
149
150 /// \brief Returns an expression in the internal format of the rewriter with the jitty strategy.
151 /// \brief The main operator of this expression is an \c if \c then \c else function. Its guard is \c a_expr,
152 /// \brief the true-branch is \c a_high and the false-branch is \c a_low. If \c a_high equals \c a_low, the
153 /// \brief method returns \c a_high instead.
155 const data_expression& a_high,
156 const data_expression& a_low)
157 {
158 return a_high == a_low ? a_high : if_(a_expr, a_high, a_low);
159 }
160
161 /// \brief Orients the term \c a_term such that all equations of the form t1 == t2 are
162 /// \brief replaced by t2 == t1 if t1 > t2.
164 {
165 if (is_variable(a_term) || is_function_symbol(a_term) || is_where_clause(a_term) || is_machine_number(a_term))
166 {
167 return a_term;
168 }
169
170 if (is_abstraction(a_term))
171 {
172 const abstraction a(atermpp::down_cast<abstraction>(a_term));
174 }
175
176 std::unordered_map < data_expression, data_expression> :: const_iterator it=f_orient.find(a_term);
177 if (it!=f_orient.end()) // found
178 {
179 return it->second;
180 }
181
182 const application& a = atermpp::down_cast<application>(a_term);
183 application v_result(a.head(), a.begin(), a.end(), [this](const data_expression& d){return orient(d); });
184
185 if (is_equal_to_application(v_result))
186 {
187 const data_expression& v_term1(v_result[0]);
188 const data_expression& v_term2(v_result[1]);
190 {
191 v_result = application(v_result.head(), v_term2, v_term1);
192 }
193 }
194 f_orient[a_term]=v_result;
195
196 return v_result;
197 }
198
199 /// \brief Initializes the table Manipulator::f_set_true and calls
200 /// \brief f_set_true_auxiliary.
202 const data_expression& a_formula,
203 const data_expression& a_guard) const
204 {
205 std::unordered_map < data_expression, data_expression > f_set_true;
206 return set_true_auxiliary(a_formula, a_guard, f_set_true);
207 }
208
209 /// \brief Initializes the table Manipulator::f_set_false and calls the method
210 /// \brief AM_Jitty::f_set_false_auxiliary.
212 const data_expression& a_formula,
213 const data_expression& a_guard) const
214 {
215 std::unordered_map < data_expression, data_expression > f_set_false;
216 return set_false_auxiliary(a_formula, a_guard,f_set_false);
217 }
218};
219
220} // namespace mcrl2::data::detail
221
222#endif
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
\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
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
Base class for classes that provide information about the structure of.
Definition info.h:32
constexpr Info(bool a_full, bool a_reverse)
Constructor that initializes the rewriter.
Definition info.h:181
Compare_Result compare_term(const data_expression &term1, const data_expression &term2) const
Compares two terms.
Definition info.h:205
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
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
The default element for the todo list of the enumerator.
Definition enumerator.h:229
Rewriter that operates on data expressions.
Definition rewriter.h:84
void thread_initialise()
Initialises this rewriter with thread dependent information.
Definition rewriter.h:153
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 rewriter &r)=default
Constructor.
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.
\brief A where expression
const assignment_list & assignments() const
const data_expression & body() const
#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:582
static void checkPattern(const data_expression &p)
Definition rewrite.cpp:567
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:524
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:640
static bool occur_check(const variable &v, const atermpp::aterm &e)
Definition rewrite.cpp:44
static void checkPattern(application::const_iterator begin, const application::const_iterator &end)
Definition rewrite.cpp:558
Answer
A prover that uses EQ-BDDs.
Definition bdd_prover.h:77
static void check_vars(const data_expression &expr, const std::set< variable > &vars, std::set< variable > &used_vars)
Definition rewrite.cpp:535
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 bool_.
Definition bool.h:29
bool is_false_function_symbol(const atermpp::aterm &e)
Recogniser for function false.
Definition bool.h:116
const basic_sort & bool_()
Constructor for sort expression Bool.
Definition bool.h:41
application not_(const data_expression &arg0)
Application of function symbol !.
Definition bool.h:194
const function_symbol & false_()
Constructor for function symbol false.
Definition bool.h:106
bool is_true_function_symbol(const atermpp::aterm &e)
Recogniser for function true.
Definition bool.h:84
const function_symbol & true_()
Constructor for function symbol true.
Definition bool.h:74
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
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.
bool is_exists(const atermpp::aterm &x)
Returns true if the term t is an existential quantification.
bool is_machine_number(const atermpp::aterm &x)
Returns true if the term t is a machine_number.
bool is_lambda(const atermpp::aterm &x)
Returns true if the term t is a lambda abstraction.
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