mCRL2
Loading...
Searching...
No Matches
bdd_path_eliminator.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/bdd_path_eliminator.h
10/// \brief BDD inconsistent path elimination using external SMT solvers
11
12#ifndef MCRL2_DATA_DETAIL_PROVER_BDD_PATH_ELIMINATOR_H
13#define MCRL2_DATA_DETAIL_PROVER_BDD_PATH_ELIMINATOR_H
14
15#include "mcrl2/data/detail/prover/bdd_info.h"
16#include "mcrl2/data/detail/prover/bdd_simplifier.h"
17#include "mcrl2/data/detail/prover/manipulator.h"
18#include "mcrl2/data/detail/prover/smt_lib_solver.h"
19#include "mcrl2/data/detail/prover/solver_type.h"
20
21namespace mcrl2::data::detail
22{
23
24/** \brief Base class for eliminating inconsistent paths from BDDs.
25 *
26 * \detail
27 * The class BDD_Path_Eliminator is a base class for classes that
28 * eliminate inconsistent paths from BDDs. The class
29 * BDD_Path_Eliminator inherits from the class BDD_Simplifier. It uses
30 * an SMT solver to eliminate inconsistent paths from BDDs. The
31 * parameter a_solver_type of the constructor
32 * BDD_Path_Eliminator::BDD_Path_Eliminator is used to indicate which
33 * SMT solver should be used for this task. A path in a BDD is
34 * constructed by selecting a set of guards as follows: starting at
35 * the root node, one of the two edges at each guard is followed until
36 * a leaf is reached. Each time the true-edge is chosen, the guard is
37 * added to the set. Each time the false-edge is chosen, the negation
38 * of the guard is added to the set. If the conjunction of all
39 * elements in this set is a contradiction, the path
40 * is inconsistent.
41
42 * The method BDD_Path_Eliminator::simplify receives a BDD as
43 * parameter a_bdd and returns the equivalent BDD from which all
44 * inconsistent paths have been removed.
45*/
47{
48
49 private:
50
51 /// \brief Pointer to an SMT solver used to determine whether or not a path is inconsistent.
53
54 /// \brief Class that provides information about the structure of BDDs.
56
57 /// \brief Returns a list representing the conjunction of all guards in a_path and the guard a_guard.
58 /// \param a_path A list of guards and negated guards, representing a path in a BDD.
59 /// \param a_guard A guard or a negated guard.
60 /// \param a_minimal A boolean value indicating whether or not minimal sets of possibly inconsistent guards are constructed.
61 data_expression_list create_condition(
62 data_expression_list a_path,
63 const data_expression& a_guard,
64 bool a_minimal)
65 {
66 if (!a_minimal)
67 {
68 a_path.push_front(a_guard);
69 return a_path;
70 }
71 else
72 {
73 data_expression_list v_auxiliary_set;
74 data_expression_list v_iterate_over_set;
75 data_expression_list v_iterate_over_path;
76 data_expression v_guard_from_set;
77 data_expression v_guard_from_path;
78
79 data_expression_list v_set = { a_guard };
80 while (v_set != v_auxiliary_set)
81 {
82 v_auxiliary_set = v_set;
83 v_iterate_over_set = v_set;
84 while (!v_iterate_over_set.empty())
85 {
86 v_guard_from_set = v_iterate_over_set.front();
87 v_iterate_over_set.pop_front();
88 v_iterate_over_path = a_path;
89 while (!v_iterate_over_path.empty())
90 {
91 v_guard_from_path = v_iterate_over_path.front();
92 v_iterate_over_path.pop_front();
93 if (variables_overlap(v_guard_from_set, v_guard_from_path))
94 {
95 v_set.push_front(v_guard_from_path);
96 a_path = remove_one_element(a_path, v_guard_from_path);
97 }
98 }
99 }
100 }
101 return v_set;
102 }
103 }
104
105 /// \brief Simplifies the BDD a_bdd using path a_path. Paths whose guards in conjunction with the guards in
106 /// \brief a_path are inconsistent are removed.
107 /// \param a_bdd A binary decision diagram.
108 /// \param a_path A list of guards and negated guards, representing a path in a BDD.
110 const data_expression& a_bdd,
111 const data_expression_list& a_path)
112 {
113 if (f_deadline != 0 && (f_deadline - time(nullptr)) < 0)
114 {
115 mCRL2log(log::log_level_t::debug) << "The time limit has passed." << std::endl;
116 return a_bdd;
117 }
118
120 {
121 return a_bdd;
122 }
123
124 const data_expression v_guard = f_bdd_info.get_guard(a_bdd);
125 const data_expression v_negated_guard = sort_bool::not_(v_guard);
126 const data_expression_list v_true_condition = create_condition(a_path, v_guard, true);
127 bool v_true_branch_enabled = f_smt_solver->is_satisfiable(v_true_condition);
128 if (!v_true_branch_enabled)
129 {
130 data_expression_list v_false_path=a_path;
131 v_false_path.push_front(v_negated_guard);
132 return aux_simplify(f_bdd_info.get_false_branch(a_bdd), v_false_path);
133 }
134 else
135 {
136 data_expression_list v_false_condition = create_condition(a_path, v_negated_guard, true);
137 bool v_false_branch_enabled = f_smt_solver->is_satisfiable(v_false_condition);
138 if (!v_false_branch_enabled)
139 {
140 data_expression_list v_true_path = a_path;
141 v_true_path.push_front(v_guard);
142 return aux_simplify(f_bdd_info.get_true_branch(a_bdd), v_true_path);
143 }
144 else
145 {
146 data_expression_list v_true_path = a_path;
147 v_true_path.push_front(v_guard);
148 data_expression_list v_false_path = a_path;
149 v_false_path.push_front(v_negated_guard);
150 return Manipulator::make_reduced_if_then_else(
151 v_guard,
152 aux_simplify(f_bdd_info.get_true_branch(a_bdd), v_true_path),
153 aux_simplify(f_bdd_info.get_false_branch(a_bdd), v_false_path)
154 );
155 }
156 }
157 }
158
159 /// \brief Returns true if the expression a_expression_1 has variables in common with expression a_expression_2.
160 /// \param a_expression_1 An arbitrary expression.
161 /// \param a_expression_2 An arbitrary expression.
163 const data_expression& a_expression_1,
164 const data_expression& a_expression_2)
165 {
166 std::set < variable > set1=find_all_variables(a_expression_1);
167 std::set < variable > set2=find_all_variables(a_expression_2);
168 std::set < variable > intersection;
169 std::set_intersection(set1.begin(),set1.end(),
170 set2.begin(),set2.end(),
171 std::insert_iterator<std::set < variable > >(intersection,intersection.begin()));
172 return !intersection.empty();
173 }
174
175 public:
176
177 /// \brief Constructor that initializes the field BDD_Path_Eliminator::f_smt_solver.
178 /// \param a_solver_type A value of an enumerated type, representing an SMT solver.
179 BDD_Path_Eliminator(smt_solver_type a_solver_type)
180 {
181#if !(defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__))
182 if (a_solver_type == smt_solver_type::solver_type_cvc)
183 {
184 if (mcrl2::data::detail::prover::cvc_smt_solver::usable())
185 {
186 f_smt_solver = new mcrl2::data::detail::prover::cvc_smt_solver();
187
188 return;
189 }
190 }
191 else if (a_solver_type == smt_solver_type::solver_type_z3)
192 {
193 if (mcrl2::data::detail::prover::z3_smt_solver::usable())
194 {
195 f_smt_solver = new mcrl2::data::detail::prover::z3_smt_solver();
196
197 return;
198 }
199 }
200 else
201 {
202 throw mcrl2::runtime_error("An unknown SMT solver type was passed as argument.");
203 }
204#else
205 throw mcrl2::runtime_error("No SMT solvers available on this platform.");
206#endif // _MSC_VER
207 }
208
209 /// \brief Returns a BDD without inconsistent paths, equivalent to a_bdd.
210 /// precondition: The argument passed as parameter a_bdd is a data expression in internal mCRL2 format with the
211 /// following restrictions: It either represents the constant true or the constant false, or it is an if-then-else
212 /// expression with an expression of sort Bool as guard, and a then-branch and an else-branch that again follow
213 /// these restrictions
214 /// \param a_bdd A binary decision diagram.
216 {
217 return aux_simplify(a_bdd, data_expression_list());
218 }
219};
220
221} // namespace mcrl2::data::detail
222
223#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 & 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.
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
Base class for classes that provide functionality to modify or create terms.
Definition manipulator.h:23
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.
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
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
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_abstraction(const atermpp::aterm &x)
Returns true if the term t is an abstraction.
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