Skip to content

Commit dbfa3dd

Browse files
hgvk94agurfinkel
andauthored
[spacer] implement spacer::is_clause() (#4170)
Spacer has a different defintion of is_clause() than ast_util. It is currently only used in assertions. Main difference: x=y where x and y are Bool atoms is considered to be an atom, so that (or (= x y) (not (= z y))) is a literal Co-authored-by: Arie Gurfinkel <[email protected]>
1 parent 799b613 commit dbfa3dd

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

src/muz/spacer/spacer_context.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,8 +926,10 @@ void pred_transformer::add_lemma_core(lemma* lemma, bool ground_only)
926926
SASSERT(!lemma->is_background());
927927
unsigned lvl = lemma->level();
928928
expr* l = lemma->get_expr();
929-
SASSERT(!lemma->is_ground() || is_clause(m, l));
930-
SASSERT(!is_quantifier(l) || is_clause(m, to_quantifier(l)->get_expr()));
929+
CTRACE("spacer", !spacer::is_clause(m, l),
930+
tout << "Lemma not a clause: " << mk_pp(l, m) << "\n";);
931+
SASSERT(!lemma->is_ground() || spacer::is_clause(m, l));
932+
SASSERT(!is_quantifier(l) || spacer::is_clause(m, to_quantifier(l)->get_expr()));
931933

932934
get_context().log_add_lemma(*this, *lemma);
933935

src/muz/spacer/spacer_unsat_core_plugin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ namespace spacer {
7373
// the current step needs to be interpolated:
7474
expr* fact = m.get_fact(pf);
7575
// if we trust the current step and we are able to use it
76-
if (m_ctx.is_b_pure (pf) && (m.is_asserted(pf) || is_literal(m, fact))) {
76+
if (m_ctx.is_b_pure (pf) && (m.is_asserted(pf) || spacer::is_literal(m, fact))) {
7777
// just add it to the core
7878
m_ctx.add_lemma_to_core(fact);
7979
}
@@ -558,7 +558,7 @@ namespace spacer {
558558
// if we trust the current step and we are able to use it
559559
if (m_ctx.is_b_pure (current) &&
560560
(m.is_asserted(current) ||
561-
is_literal(m, m.get_fact(current))))
561+
spacer::is_literal(m, m.get_fact(current))))
562562
{
563563
// we found a leaf of the subproof, so
564564
// 1) we add corresponding edges

src/muz/spacer/spacer_util.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,44 @@ Revision History:
6969

7070
namespace spacer {
7171

72+
bool is_clause(ast_manager &m, expr *n) {
73+
if (spacer::is_literal(m, n))
74+
return true;
75+
if (m.is_or(n)) {
76+
for (expr *arg : *to_app(n)){
77+
if (!spacer::is_literal(m, arg))
78+
return false;
79+
return true;
80+
}
81+
}
82+
return false;
83+
}
84+
85+
bool is_literal(ast_manager &m, expr *n) {
86+
return spacer::is_atom(m, n) || (m.is_not(n) && spacer::is_atom(m, to_app(n)->get_arg(0)));
87+
}
88+
89+
bool is_atom(ast_manager &m, expr *n) {
90+
if (is_quantifier(n) || !m.is_bool(n))
91+
return false;
92+
if (is_var(n))
93+
return true;
94+
SASSERT(is_app(n));
95+
if (to_app(n)->get_family_id() != m.get_basic_family_id()) {
96+
return true;
97+
}
98+
99+
if ((m.is_eq(n) && !m.is_bool(to_app(n)->get_arg(0))) ||
100+
m.is_true(n) || m.is_false(n))
101+
return true;
102+
103+
// x=y is atomic if x and y are Bool and atomic
104+
expr *e1, *e2;
105+
if (m.is_eq(n, e1, e2) && spacer::is_atom(m, e1) && spacer::is_atom(m, e2))
106+
return true;
107+
return false;
108+
}
109+
72110
void subst_vars(ast_manager& m,
73111
app_ref_vector const& vars, model& mdl, expr_ref& fml) {
74112
model::scoped_model_completion _sc_(mdl, true);

src/muz/spacer/spacer_util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ namespace spacer {
136136
mk_epp(ast *t, ast_manager &m, unsigned indent = 0, unsigned num_vars = 0, char const * var_prefix = nullptr);
137137
void rw(expr *e, expr_ref &out);
138138
};
139+
140+
bool is_clause(ast_manager &m, expr *n);
141+
bool is_literal(ast_manager &m, expr *n);
142+
bool is_atom(ast_manager &m, expr *n);
139143
}
140144

141145
#endif

0 commit comments

Comments
 (0)