cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
counterexample_beautification.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Counterexample Beautification using Incremental SAT
4
5
Author: Daniel Kroening, kroening@kroening.com
6
7
\*******************************************************************/
8
11
12
#include "
counterexample_beautification.h
"
13
14
#include <
util/std_expr.h
>
15
16
#include <
solvers/prop/prop_minimize.h
>
17
18
counterexample_beautificationt::counterexample_beautificationt
(
19
message_handlert
&message_handler)
20
:
log
(message_handler)
21
{
22
}
23
24
void
counterexample_beautificationt::get_minimization_list
(
25
prop_convt
&prop_conv,
26
const
symex_target_equationt
&equation,
27
minimization_listt
&minimization_list)
28
{
29
// ignore the ones that are assigned under false guards
30
31
for
(symex_target_equationt::SSA_stepst::const_iterator it =
32
equation.
SSA_steps
.begin();
33
it != equation.
SSA_steps
.end();
34
it++)
35
{
36
if
(
37
it->is_assignment() &&
38
it->assignment_type ==
symex_targett::assignment_typet::STATE
)
39
{
40
if
(prop_conv.
get
(it->guard_handle) !=
false
)
41
{
42
const
typet
&type = it->ssa_lhs.type();
43
44
if
(type !=
bool_typet
())
45
{
46
// we minimize the absolute value, if applicable
47
if
(
48
type.
id
() == ID_signedbv || type.
id
() == ID_fixedbv ||
49
type.
id
() == ID_floatbv)
50
{
51
abs_exprt
abs_expr(it->ssa_lhs);
52
minimization_list.insert(abs_expr);
53
}
54
else
55
minimization_list.insert(it->ssa_lhs);
56
}
57
}
58
}
59
60
// reached failed assertion?
61
if
(it ==
failed
)
62
break
;
63
}
64
}
65
66
symex_target_equationt::SSA_stepst::const_iterator
67
counterexample_beautificationt::get_failed_property
(
68
const
prop_convt
&prop_conv,
69
const
symex_target_equationt
&equation)
70
{
71
// find failed property
72
73
for
(symex_target_equationt::SSA_stepst::const_iterator it =
74
equation.
SSA_steps
.begin();
75
it != equation.
SSA_steps
.end();
76
it++)
77
{
78
if
(
79
it->is_assert() && prop_conv.
get
(it->guard_handle) ==
true
&&
80
prop_conv.
get
(it->cond_handle) ==
false
)
81
{
82
return
it;
83
}
84
}
85
86
UNREACHABLE
;
87
return
equation.
SSA_steps
.end();
88
}
89
90
void
counterexample_beautificationt::
91
operator()
(
boolbvt
&boolbv,
const
symex_target_equationt
&equation)
92
{
93
// find failed property
94
95
failed
=
get_failed_property
(boolbv, equation);
96
97
// lock the failed assertion
98
boolbv.
set_to
(
failed
->cond_handle,
false
);
99
100
{
101
log
.status() <<
"Beautifying counterexample (guards)"
<<
messaget::eom
;
102
103
// compute weights for guards
104
typedef
std::map<literalt, unsigned> guard_countt;
105
guard_countt guard_count;
106
107
for
(symex_target_equationt::SSA_stepst::const_iterator it =
108
equation.
SSA_steps
.begin();
109
it != equation.
SSA_steps
.end();
110
it++)
111
{
112
if
(
113
it->is_assignment() &&
114
it->assignment_type !=
symex_targett::assignment_typet::HIDDEN
)
115
{
116
literalt
l = boolbv.
convert
(it->guard_handle);
117
if
(!l.
is_constant
())
118
guard_count[l]++;
119
}
120
121
// reached failed assertion?
122
if
(it ==
failed
)
123
break
;
124
}
125
126
// give to propositional minimizer
127
prop_minimizet
prop_minimize{boolbv,
log
.get_message_handler()};
128
129
for
(
const
auto
&g : guard_count)
130
prop_minimize.
objective
(g.first, g.second);
131
132
// minimize
133
prop_minimize();
134
}
135
136
{
137
log
.status() <<
"Beautifying counterexample (values)"
<<
messaget::eom
;
138
139
// get symbols we care about
140
minimization_listt
minimization_list;
141
142
get_minimization_list
(boolbv, equation, minimization_list);
143
144
// minimize
145
bv_minimizet
bv_minimize(boolbv,
log
.get_message_handler());
146
bv_minimize(minimization_list);
147
}
148
}
minimization_listt
std::set< exprt > minimization_listt
Definition
bv_minimize.h:23
abs_exprt
Absolute value.
Definition
std_expr.h:430
bool_typet
The Boolean type.
Definition
std_types.h:36
boolbvt
Definition
boolbv.h:50
boolbvt::set_to
void set_to(const exprt &expr, bool value) override
For a Boolean expression expr, add the constraint 'expr' if value is true, otherwise add 'not expr'.
Definition
boolbv.cpp:533
bv_minimizet
Definition
bv_minimize.h:26
counterexample_beautificationt::log
messaget log
Definition
counterexample_beautification.h:42
counterexample_beautificationt::operator()
void operator()(boolbvt &boolbv, const symex_target_equationt &equation)
Definition
counterexample_beautification.cpp:91
counterexample_beautificationt::get_minimization_list
void get_minimization_list(prop_convt &prop_conv, const symex_target_equationt &equation, minimization_listt &minimization_list)
Definition
counterexample_beautification.cpp:24
counterexample_beautificationt::failed
symex_target_equationt::SSA_stepst::const_iterator failed
Definition
counterexample_beautification.h:40
counterexample_beautificationt::get_failed_property
symex_target_equationt::SSA_stepst::const_iterator get_failed_property(const prop_convt &prop_conv, const symex_target_equationt &equation)
Definition
counterexample_beautification.cpp:67
counterexample_beautificationt::counterexample_beautificationt
counterexample_beautificationt(message_handlert &message_handler)
Definition
counterexample_beautification.cpp:18
decision_proceduret::get
virtual exprt get(const exprt &) const =0
Return expr with variables replaced by values from satisfying assignment if available.
irept::id
const irep_idt & id() const
Definition
irep.h:388
literalt
Definition
literal.h:26
literalt::is_constant
bool is_constant() const
Definition
literal.h:166
message_handlert
Definition
message.h:27
messaget::eom
static eomt eom
Definition
message.h:289
prop_conv_solvert::convert
literalt convert(const exprt &expr) override
Convert a Boolean expression and return the corresponding literal.
Definition
prop_conv_solver.cpp:154
prop_convt
Definition
prop_conv.h:22
prop_minimizet
Computes a satisfying assignment of minimal cost according to a const function using incremental SAT.
Definition
prop_minimize.h:26
prop_minimizet::objective
void objective(const literalt condition, const weightt weight=1)
Add an objective.
Definition
prop_minimize.cpp:27
symex_target_equationt
Inheriting the interface of symex_targett this class represents the SSA form of the input program as ...
Definition
symex_target_equation.h:34
symex_target_equationt::SSA_steps
SSA_stepst SSA_steps
Definition
symex_target_equation.h:251
symex_targett::assignment_typet::STATE
@ STATE
Definition
symex_target.h:70
symex_targett::assignment_typet::HIDDEN
@ HIDDEN
Definition
symex_target.h:71
typet
The type of an expression, extends irept.
Definition
type.h:29
counterexample_beautification.h
Counterexample Beautification.
prop_minimize.h
SAT Minimizer.
UNREACHABLE
#define UNREACHABLE
This should be used to mark dead code.
Definition
invariant.h:525
std_expr.h
API to expression classes.
goto-checker
counterexample_beautification.cpp
Generated by
1.17.0