mCRL2
Loading...
Searching...
No Matches
formula_checker.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/formula_checker.h
10/// \brief Interface to class Formula_Checker
11
12#ifndef FORMULA_CHECKER_H
13#define FORMULA_CHECKER_H
14
15#include "mcrl2/data/detail/prover/bdd_prover.h"
16#include "mcrl2/data/detail/prover/bdd2dot.h"
17
18namespace mcrl2::data::detail
19{
20
21/// \brief The class formula checker takes a data specification in mCRL2 format and a list of expressions
22/// \brief of sort Bool in the mCRL2 format and determines whether or not these expersions are tautologies or
23/// \brief contradictions.
24/// The class Formula_Checker is initialized with a specification of data equations in internal mCRL2 format using the
25/// \brief Constructor Formula_Checker::Formula_Checker. After initialization, the function Formula_Checker::check_formulas can
26/// be called any number of times to check whether the expressions of sort Bool in internal mCRL2 format in the list
27/// passed as parameter a_formulas are tautologies or contradictions.
28///
29/// The class Formula_Checker uses an instance of the class BDD_Prover to prove a number of propositional formulas. The
30/// prover is initialized with the parameters a_rewrite_strategy, a_time_limit, a_path_eliminator, a_solver_type,
31/// a_apply_induction and a_lps. The parameter a_rewrite_strategy specifies which rewrite strategy is used by the prover's
32/// rewriter. It can be set to either GS_REWR_JITTY or GS_REWR_JITTYC. The parameter
33/// a_time_limit specifies the maximum amount of time in seconds to be spent by the prover on proving a single formula. If
34/// a_time_limit is set to 0, no time limit will be enforced. The parameter a_path_eliminator specifies whether or not
35/// path elimination is applied. When path elimination is applied, the prover uses an SMT solver to remove inconsistent
36/// paths from BDDs. The parameter a_solver_type specifies which SMT solver is used for path elimination. Either the SMT
37/// solver ario (http://www.eecs.umich.edu/~ario/) or cvc-lite (http://www.cs.nyu.edu/acsys/cvcl/) can be used. To use one
38/// of these solvers, the directory containing the corresponding executable must be in the path. If the parameter
39/// a_path_eliminator is set to false, the parameter a_solver_type is ignored. The parameter a_time_limit specifies the
40/// data equations used by the prover's rewriter. The parameter a_apply_induction indicates whether or not induction on
41/// list will be applied.
42///
43/// The parameter a_dot_file_name specifies whether a file in dot format of the resulting BDD is saved each time the
44/// prover cannot determine whether an expression of sort Bool is a contradiction or a tautology. If the parameter is set
45/// to 0, no .dot files are saved. If a string is passed as parameter a_dot_file_name, this string will be used as the
46/// prefix of the filenames. An instance of the class BDD2Dot is used to save these files in dot format.
47///
48/// If the parameter a_counter_example is set to true, a so called counter example is printed to stderr each time an
49/// expression is encountered that is neither a contradiction nor a tautology. A counter example is a valuation for which
50/// the expression does not hold.
51///
52/// If the parameter a_witness is set to false, a so called witness is printed to stderr each time such an expression is
53/// encountered. A witness is a valuation for which the expression holds.
54///
55/// The function Formula_Checker::check_formulas prints information to stderr indicating whether the expressions in the
56/// list of formulas passed as parameter a_formulas are tautologies or contradictions. In some cases the BDD based prover
57/// may be unable to determine whether an expression is a tautology or a contradiction. If this is the case, the function
58/// Formula_Checker::check_formulas will print information to stderr indicating this fact.
60{
61 private:
62 /// \brief BDD based prover.
64
65 /// \brief Class that outputs BDDs in dot format.
67
68 /// \brief Flag indicating whether or not counter-examples are displayed.
70
71 /// \brief Flag indicating whether or not witnesses are displayed.
73
74 /// \brief Prefix for the names of the files containing BDDs in dot format.
76
77 /// \brief Displays a witness.
79 {
80 if (f_witness)
81 {
82 const data_expression v_witness = f_bdd_prover.get_witness();
83 if (v_witness==data_expression())
84 {
85 throw mcrl2::runtime_error(
86 "Cannot print witness. This is probably caused by an abrupt stop of the\n"
87 "conversion from expression to EQ-BDD. This typically occurs when a time limit is set.\n"
88 );
89 }
90 else
91 {
92 mCRL2log(log::log_level_t::info) << " Witness: " << v_witness << std::endl;
93 }
94 }
95 }
96
97 /// \brief Displays a counter-example.
99 {
101 {
102 const data_expression v_counter_example = f_bdd_prover.get_counter_example();
103 if (v_counter_example==data_expression())
104 {
105 throw mcrl2::runtime_error(
106 "Cannot print counter example. This is probably caused by an abrupt stop of the\n"
107 "conversion from expression to EQ-BDD. This typically occurs when a time limit is set.\n"
108 );
109 }
110 else
111 {
112 mCRL2log(log::log_level_t::info) << " Counter-example: " << v_counter_example << std::endl;
113 }
114 }
115 }
116
117 /// \brief Writes the BDD corresponding to the formula with number a_formula_number to a dot file.
118 void save_dot_file(int a_formula_number)
119 {
120 if (!f_dot_file_name.empty())
121 {
122 f_bdd2dot.output_bdd(f_bdd_prover.get_bdd(), f_dot_file_name + "-" + std::to_string(a_formula_number) + ".dot");
123 }
124 }
125
126 public:
127 /// \brief Constructor that initializes Formula_Checker::f_counter_example, Formula_Checker::f_witness,
128 /// \brief Formula_Checker::f_bdd_prover and Formula_Checker::f_dot_file_name.
129 /// precondition: the argument passed as parameter a_time_limit is greater than or equal to 0. If the argument is equal
130 /// to 0, no time limit will be enforced
132 mcrl2::data::rewriter::strategy a_rewrite_strategy = mcrl2::data::rewrite_strategy::jitty,
133 int a_time_limit = 0,
134 bool a_path_eliminator = false,
135 mcrl2::data::detail::smt_solver_type a_solver_type = mcrl2::data::detail::smt_solver_type::solver_type_cvc,
136 bool a_apply_induction = false,
137 bool a_counter_example = false,
138 bool a_witness = false,
139 char const* a_dot_file_name = nullptr)
148 {
149 f_counter_example = a_counter_example;
150 f_witness = a_witness;
151 }
152
153 /// \brief Destructor without any specific functionality.
154 ~Formula_Checker() = default;
155
156 /// \brief Checks the formulas in the list a_formulas.
157 /// precondition: the parameter a_formulas is a list of expressions of sort Bool in internal mCRL2 format
158 void check_formulas(const data_expression_list& a_formulas)
159 {
160 int v_formula_number = 1;
161
162 for (const auto& v_formula: a_formulas)
163 {
164 mCRL2log(log::log_level_t::info) << "'" << v_formula << "'";
165 f_bdd_prover.set_formula(v_formula);
166 Answer v_is_tautology = f_bdd_prover.is_tautology();
167 Answer v_is_contradiction = f_bdd_prover.is_contradiction();
168 if (v_is_tautology == Answer::answer_yes)
169 {
170 mCRL2log(log::log_level_t::info) << "Tautology" << std::endl;
171 }
172 else if (v_is_contradiction == Answer::answer_yes)
173 {
174 mCRL2log(log::log_level_t::info) << "Contradiction" << std::endl;
175 }
176 else
177 {
178 mCRL2log(log::log_level_t::info) << "Undeterminable" << std::endl;
179 print_counter_example();
180 print_witness();
181 save_dot_file(v_formula_number);
182 }
183 v_formula_number++;
184 }
185 }
186
187};
188
189} // namespace mcrl2::data::detail
190
191#endif
data_expression()
\brief Default constructor X3.
The class BDD2Dot offers the ability to write binary decision diagrams to dot files....
Definition bdd2dot.h:26
The class formula checker takes a data specification in mCRL2 format and a list of expressions.
bool f_witness
Flag indicating whether or not witnesses are displayed.
void print_counter_example()
Displays a counter-example.
~Formula_Checker()=default
Destructor without any specific functionality.
std::string f_dot_file_name
Prefix for the names of the files containing BDDs in dot format.
void save_dot_file(int a_formula_number)
Writes the BDD corresponding to the formula with number a_formula_number to a dot file.
Formula_Checker(mcrl2::data::data_specification a_data_spec, mcrl2::data::rewriter::strategy a_rewrite_strategy=mcrl2::data::rewrite_strategy::jitty, int a_time_limit=0, bool a_path_eliminator=false, mcrl2::data::detail::smt_solver_type a_solver_type=mcrl2::data::detail::smt_solver_type::solver_type_cvc, bool a_apply_induction=false, bool a_counter_example=false, bool a_witness=false, char const *a_dot_file_name=nullptr)
Constructor that initializes Formula_Checker::f_counter_example, Formula_Checker::f_witness,...
void print_witness()
Displays a witness.
void check_formulas(const data_expression_list &a_formulas)
Checks the formulas in the list a_formulas. precondition: the parameter a_formulas is a list of expre...
mcrl2::data::detail::BDD_Prover f_bdd_prover
BDD based prover.
BDD2Dot f_bdd2dot
Class that outputs BDDs in dot format.
bool f_counter_example
Flag indicating whether or not counter-examples are displayed.
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:435