Skip to content

Commit 530d44f

Browse files
hgvk94agurfinkel
andcommitted
[spacer] implement spacer::is_clause() (Z3Prover#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 e708603 commit 530d44f

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

src/muz/spacer/spacer_context.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -941,8 +941,10 @@ void pred_transformer::add_lemma_core(lemma* lemma, bool ground_only)
941941
SASSERT(!lemma->is_background());
942942
unsigned lvl = lemma->level();
943943
expr* l = lemma->get_expr();
944-
SASSERT(!lemma->is_ground() || is_clause(m, l));
945-
SASSERT(!is_quantifier(l) || is_clause(m, to_quantifier(l)->get_expr()));
944+
CTRACE("spacer", !spacer::is_clause(m, l),
945+
tout << "Lemma not a clause: " << mk_pp(l, m) << "\n";);
946+
SASSERT(!lemma->is_ground() || spacer::is_clause(m, l));
947+
SASSERT(!is_quantifier(l) || spacer::is_clause(m, to_quantifier(l)->get_expr()));
946948

947949
get_context().log_add_lemma(*this, *lemma);
948950

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ namespace spacer {
142142
/// Returns number of free variables in a given expression
143143
unsigned get_num_vars(expr *e);
144144
void get_uninterp_consts(expr *a, expr_ref_vector &out);
145+
bool is_clause(ast_manager &m, expr *n);
146+
bool is_literal(ast_manager &m, expr *n);
147+
bool is_atom(ast_manager &m, expr *n);
145148
}
146149

147150
#endif

0 commit comments

Comments
 (0)