Skip to content

Commit 4df008a

Browse files
Merge pull request diffblue#4383 from romainbrenguier/enhance/bdd-expr
Make expressions generated by BDDs more compact
2 parents 4fa790b + cb9638a commit 4df008a

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/solvers/prop/bdd_expr.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,30 @@ bddt bdd_exprt::from_expr(const exprt &expr)
9191
return from_expr_rec(expr);
9292
}
9393

94+
/// Conjunction of two expressions. If the second is already an `and_exprt`
95+
/// add to its operands instead of creating a new expression.
96+
static exprt make_and(exprt a, exprt b)
97+
{
98+
if(b.id() == ID_and)
99+
{
100+
b.add_to_operands(std::move(a));
101+
return b;
102+
}
103+
return and_exprt{std::move(a), std::move(b)};
104+
}
105+
106+
/// Disjunction of two expressions. If the second is already an `or_exprt`
107+
/// add to its operands instead of creating a new expression.
108+
static exprt make_or(exprt a, exprt b)
109+
{
110+
if(b.id() == ID_or)
111+
{
112+
b.add_to_operands(std::move(a));
113+
return b;
114+
}
115+
return or_exprt{std::move(a), std::move(b)};
116+
}
117+
94118
/// Helper function for \c bddt to \c exprt conversion
95119
/// \param r: node to convert
96120
/// \param complement: whether we want the negation of the expression
@@ -130,14 +154,14 @@ exprt bdd_exprt::as_expr(
130154
{
131155
if(r.else_branch().is_complement() != complement)
132156
{
133-
return and_exprt(
157+
return make_and(
134158
n_expr,
135159
as_expr(
136160
r.then_branch(),
137161
complement != r.then_branch().is_complement(),
138162
cache));
139163
}
140-
return or_exprt(
164+
return make_or(
141165
not_exprt(n_expr),
142166
as_expr(
143167
r.then_branch(),
@@ -149,14 +173,14 @@ exprt bdd_exprt::as_expr(
149173
{
150174
if(r.then_branch().is_complement() != complement)
151175
{
152-
return and_exprt(
176+
return make_and(
153177
not_exprt(n_expr),
154178
as_expr(
155179
r.else_branch(),
156180
complement != r.else_branch().is_complement(),
157181
cache));
158182
}
159-
return or_exprt(
183+
return make_or(
160184
n_expr,
161185
as_expr(
162186
r.else_branch(),

0 commit comments

Comments
 (0)