Skip to content

Commit 5f90e72

Browse files
ensure generation is increased #2667
Signed-off-by: Nikolaj Bjorner <[email protected]>
1 parent 1281964 commit 5f90e72

File tree

4 files changed

+52
-86
lines changed

4 files changed

+52
-86
lines changed

src/smt/cost_evaluator.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,27 @@ Revision History:
2020
#include "util/warning.h"
2121

2222
cost_evaluator::cost_evaluator(ast_manager & m):
23-
m_manager(m),
23+
m(m),
2424
m_util(m) {
2525
}
2626

2727
float cost_evaluator::eval(expr * f) const {
2828
#define E(IDX) eval(to_app(f)->get_arg(IDX))
2929
if (is_app(f)) {
30-
unsigned num_args;
3130
family_id fid = to_app(f)->get_family_id();
32-
if (fid == m_manager.get_basic_family_id()) {
31+
if (fid == m.get_basic_family_id()) {
3332
switch (to_app(f)->get_decl_kind()) {
3433
case OP_TRUE: return 1.0f;
3534
case OP_FALSE: return 0.0f;
3635
case OP_NOT: return E(0) == 0.0f ? 1.0f : 0.0f;
37-
case OP_AND:
38-
num_args = to_app(f)->get_num_args();
39-
for (unsigned i = 0; i < num_args; i++)
40-
if (E(i) == 0.0f)
36+
case OP_AND:
37+
for (expr* arg : *to_app(f))
38+
if (eval(arg) == 0.0f)
4139
return 0.0f;
4240
return 1.0f;
4341
case OP_OR:
44-
num_args = to_app(f)->get_num_args();
45-
for (unsigned i = 0; i < num_args; i++)
46-
if (E(i) != 0.0f)
42+
for (expr* arg : *to_app(f))
43+
if (eval(arg) != 0.0f)
4744
return 1.0f;
4845
return 0.0f;
4946
case OP_ITE: return E(0) != 0.0f ? E(1) : E(2);

src/smt/cost_evaluator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Revision History:
2323
#include "ast/arith_decl_plugin.h"
2424

2525
class cost_evaluator {
26-
ast_manager & m_manager;
26+
ast_manager & m;
2727
arith_util m_util;
2828
unsigned m_num_args;
2929
float const * m_args;

src/smt/qi_queue.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ Module Name:
1616
Revision History:
1717
1818
--*/
19-
#include "smt/smt_context.h"
20-
#include "smt/qi_queue.h"
2119
#include "util/warning.h"
20+
#include "util/stats.h"
2221
#include "ast/ast_pp.h"
2322
#include "ast/ast_ll_pp.h"
2423
#include "ast/rewriter/var_subst.h"
25-
#include "util/stats.h"
24+
#include "smt/smt_context.h"
25+
#include "smt/qi_queue.h"
2626

2727
namespace smt {
2828

@@ -130,7 +130,7 @@ namespace smt {
130130
// max_top_generation and min_top_generation are not available for computing inc_gen
131131
set_values(q, nullptr, generation, 0, 0, cost);
132132
float r = m_evaluator(m_new_gen_function, m_vals.size(), m_vals.c_ptr());
133-
return static_cast<unsigned>(r);
133+
return std::max(generation + 1, static_cast<unsigned>(r));
134134
}
135135

136136
void qi_queue::insert(fingerprint * f, app * pat, unsigned generation, unsigned min_top_generation, unsigned max_top_generation) {
@@ -140,7 +140,7 @@ namespace smt {
140140
tout << "new instance of " << q->get_qid() << ", weight " << q->get_weight()
141141
<< ", generation: " << generation << ", scope_level: " << m_context.get_scope_level() << ", cost: " << cost << "\n";
142142
for (unsigned i = 0; i < f->get_num_args(); i++) {
143-
tout << "#" << f->get_arg(i)->get_owner_id() << " ";
143+
tout << "#" << f->get_arg(i)->get_owner_id() << " d:" << f->get_arg(i)->get_owner()->get_depth() << " ";
144144
}
145145
tout << "\n";);
146146
TRACE("new_entries_bug", tout << "[qi:insert]\n";);
@@ -201,7 +201,7 @@ namespace smt {
201201

202202
ent.m_instantiated = true;
203203

204-
TRACE("qi_queue_profile", tout << q->get_qid() << ", gen: " << generation << " " << *f;);
204+
TRACE("qi_queue_profile", tout << q->get_qid() << ", gen: " << generation << " " << *f << " cost: " << ent.m_cost << "\n";);
205205

206206
if (m_checker.is_sat(q->get_expr(), num_bindings, bindings)) {
207207
TRACE("checker", tout << "instance already satisfied\n";);

src/tactic/fd_solver/smtfd_solver.cpp

Lines changed: 38 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -780,9 +780,27 @@ namespace smtfd {
780780
{}
781781

782782
void check_term(expr* t, unsigned round) override {
783+
sort* s = m.get_sort(t);
783784
if (round == 0 && is_uf(t)) {
784785
TRACE("smtfd_verbose", tout << "check-term: " << mk_bounded_pp(t, m, 2) << "\n";);
785-
enforce_congruence(to_app(t)->get_decl(), to_app(t), m.get_sort(t));
786+
enforce_congruence(to_app(t)->get_decl(), to_app(t), s);
787+
}
788+
else if (round == 1 && sort_covered(s) && m.is_value(t)) {
789+
expr_ref v = eval_abs(t);
790+
val2elem_t& v2e = get_table(s);
791+
expr* e;
792+
if (v2e.find(v, e)) {
793+
if (e != t) {
794+
m_context.add(m.mk_not(m.mk_eq(e, t)), __FUNCTION__);
795+
}
796+
}
797+
else {
798+
m_pinned.push_back(v);
799+
v2e.insert(v, t);
800+
}
801+
}
802+
if (m.is_value(t)) {
803+
// std::cout << mk_bounded_pp(t, m, 2) << " " << eval_abs(t) << " " << mk_pp(s, m) << "\n";
786804
}
787805
}
788806

@@ -797,7 +815,7 @@ namespace smtfd {
797815
}
798816
}
799817
check_term(t, 0);
800-
return is_uf(t) || is_uninterp_const(t);
818+
return is_uf(t) || is_uninterp_const(t) || sort_covered(s);
801819
}
802820

803821
bool sort_covered(sort* s) override {
@@ -1352,7 +1370,10 @@ namespace smtfd {
13521370
if (!m_model->eval_expr(q->get_expr(), tmp, true)) {
13531371
return l_undef;
13541372
}
1355-
if (m.is_true(tmp)) {
1373+
if (is_forall(q) && m.is_true(tmp)) {
1374+
return l_false;
1375+
}
1376+
if (is_exists(q) && m.is_false(tmp)) {
13561377
return l_false;
13571378
}
13581379
TRACE("smtfd",
@@ -1664,27 +1685,31 @@ namespace smtfd {
16641685
m_context.reset(m_model);
16651686
expr_ref_vector terms(core);
16661687
terms.append(m_axioms);
1667-
TRACE("smtfd", tout << "axioms: " << m_axioms << "\n";);
16681688
for (expr* t : subterms(core)) {
16691689
if (is_forall(t) || is_exists(t)) {
16701690
has_q = true;
16711691
}
16721692
}
16731693
for (expr* t : subterms(terms)) {
1674-
if (!m_context.term_covered(t) || !m_context.sort_covered(m.get_sort(t))) {
1694+
if (!is_forall(t) && !is_exists(t) && (!m_context.term_covered(t) || !m_context.sort_covered(m.get_sort(t)))) {
16751695
is_decided = l_false;
16761696
}
16771697
}
16781698
m_context.populate_model(m_model, terms);
16791699
TRACE("smtfd",
1680-
for (expr* a : subterms(terms)) {
1681-
expr_ref val0 = (*m_model)(a);
1682-
expr_ref val1 = (*m_model)(abs(a));
1683-
if (val0 != val1 && m.get_sort(val0) == m.get_sort(val1)) {
1684-
tout << mk_bounded_pp(a, m, 2) << " := " << val0 << " " << val1 << "\n";
1685-
}
1686-
});
1687-
TRACE("smtfd", tout << "has quantifier: " << has_q << "\n" << core << "\n";);
1700+
tout << "axioms: " << m_axioms << "\n";
1701+
for (expr* a : subterms(terms)) {
1702+
expr_ref val0 = (*m_model)(a);
1703+
expr_ref val1 = (*m_model)(abs(a));
1704+
if (val0 != val1 && m.get_sort(val0) == m.get_sort(val1)) {
1705+
tout << mk_bounded_pp(a, m, 2) << " := " << val0 << " " << val1 << "\n";
1706+
}
1707+
if (!is_forall(a) && !is_exists(a) && (!m_context.term_covered(a) || !m_context.sort_covered(m.get_sort(a)))) {
1708+
tout << "not covered: " << mk_pp(a, m) << " " << mk_pp(m.get_sort(a), m) << " ";
1709+
tout << m_context.term_covered(a) << " " << m_context.sort_covered(m.get_sort(a)) << "\n";
1710+
}
1711+
}
1712+
tout << "has quantifier: " << has_q << "\n" << core << "\n";);
16881713
if (!has_q) {
16891714
return is_decided;
16901715
}
@@ -1850,59 +1875,6 @@ namespace smtfd {
18501875
TRACE("smtfd", tout << "block:\n" << mk_bounded_pp(fml, m, 3) << "\n" << mk_bounded_pp(abs(fml), m, 3) << "\n";);
18511876
assert_fd(fml);
18521877
}
1853-
#if 0
1854-
lbool check_sat_core2(unsigned num_assumptions, expr * const * assumptions) override {
1855-
init();
1856-
flush_assertions();
1857-
lbool r;
1858-
expr_ref_vector core(m);
1859-
while (true) {
1860-
IF_VERBOSE(1, verbose_stream() << "(smtfd-check-sat :rounds " << m_stats.m_num_rounds << " lemmas: " << m_stats.m_num_lemmas << " :qi " << m_stats.m_num_mbqi << ")\n");
1861-
m_stats.m_num_rounds++;
1862-
checkpoint();
1863-
1864-
// phase 1: check sat of abs
1865-
r = check_abs(num_assumptions, assumptions);
1866-
if (r != l_true) {
1867-
return r;
1868-
}
1869-
1870-
// phase 2: find prime implicate over FD (abstraction)
1871-
r = get_prime_implicate(num_assumptions, assumptions, core);
1872-
if (r != l_false) {
1873-
return r;
1874-
}
1875-
1876-
// phase 3: prime implicate over SMT
1877-
r = check_smt(core);
1878-
if (r == l_true) {
1879-
return r;
1880-
}
1881-
1882-
// phase 4: add theory lemmas
1883-
if (r == l_false) {
1884-
block_core(core);
1885-
}
1886-
if (add_theory_axioms(core)) {
1887-
continue;
1888-
}
1889-
if (r != l_undef) {
1890-
continue;
1891-
}
1892-
switch (is_decided_sat(core)) {
1893-
case l_true:
1894-
return l_true;
1895-
case l_undef:
1896-
break;
1897-
case l_false:
1898-
// m_max_conflicts = UINT_MAX;
1899-
break;
1900-
}
1901-
}
1902-
return l_undef;
1903-
}
1904-
1905-
#else
19061878

19071879
lbool check_sat_core2(unsigned num_assumptions, expr * const * assumptions) override {
19081880
init();
@@ -2008,9 +1980,6 @@ namespace smtfd {
20081980
return r;
20091981
}
20101982

2011-
#endif
2012-
2013-
20141983
void updt_params(params_ref const & p) override {
20151984
::solver::updt_params(p);
20161985
if (m_fd_sat_solver) {

0 commit comments

Comments
 (0)