3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-24 01:25:31 +00:00

add more simplifiers, fix model reconstruction order for elim_unconstrained

- enable sat.smt in smt_tactic that
is invoked by default on first goals
add flatten-clauses
add push-ite
have tptp5 front-end pretty print SMT2 formulas a little nicer.
This commit is contained in:
Nikolaj Bjorner 2022-12-01 02:35:43 +09:00
parent edb0fc394b
commit cfc8e19baf
10 changed files with 271 additions and 54 deletions

View file

@ -15,19 +15,21 @@ Author:
#pragma once
#include "ast/simplifiers/dependent_expr_state.h"
#include "ast/rewriter/elim_term_ite.h"
#include "ast/normal_forms/elim_term_ite.h""
class elim_term_ite_simplifier : public dependent_expr_simplifier {
elim_term_ite m_elim;
defined_names m_df;
elim_term_ite_rw m_rewriter;
public:
elim_term_ite_simplifier(ast_manager& m, params_ref const& p, dependent_expr_state& fmls):
dependent_expr_simplifier(m, fmls),
m_elim_term_ite(m) {
m_df(m),
m_rewriter(m, m_df) {
}
char const* name() const override { return "distribute-forall"; }
char const* name() const override { return "elim-term-ite"; }
void reduce() override {
if (!m_fmls.has_quantifiers())
@ -42,8 +44,8 @@ public:
}
}
void push() override { dependent_expr_simplifier::push(); m_rewriter.push(); }
void push() override { dependent_expr_simplifier::push(); m_df.push(); m_rewriter.push(); }
void pop(unsigned n) override { dependent_expr_simplifier::pop(n); m_rewriter.pop(n); }
void pop(unsigned n) override { m_rewriter.pop(n); m_df.pop(n); dependent_expr_simplifier::pop(n); }
};

View file

@ -249,6 +249,16 @@ void elim_unconstrained::assert_normalized(vector<dependent_expr>& old_fmls) {
void elim_unconstrained::update_model_trail(generic_model_converter& mc, vector<dependent_expr> const& old_fmls) {
auto& trail = m_fmls.model_trail();
for (auto const& entry : mc.entries()) {
switch (entry.m_instruction) {
case generic_model_converter::instruction::HIDE:
trail.hide(entry.m_f);
break;
case generic_model_converter::instruction::ADD:
break;
}
}
scoped_ptr<expr_replacer> rp = mk_default_expr_replacer(m, false);
scoped_ptr<expr_substitution> sub = alloc(expr_substitution, m, true, false);
rp->set_substitution(sub.get());
@ -265,16 +275,6 @@ void elim_unconstrained::update_model_trail(generic_model_converter& mc, vector<
}
}
trail.push(sub.detach(), old_fmls);
for (auto const& entry : mc.entries()) {
switch (entry.m_instruction) {
case generic_model_converter::instruction::HIDE:
trail.hide(entry.m_f);
break;
case generic_model_converter::instruction::ADD:
break;
}
}
}
void elim_unconstrained::reduce() {

View file

@ -0,0 +1,95 @@
/*++
Copyright (c) 2022 Microsoft Corporation
Module Name:
flatten_clauses.h
Abstract:
flatten clauses
Author:
Nikolaj Bjorner (nbjorner) 2022-11-24
--*/
#pragma once
#include "ast/simplifiers/dependent_expr_state.h"
#include "ast/rewriter/th_rewriter.h"
#include "ast/ast_util.h"
class flatten_clauses : public dependent_expr_simplifier {
unsigned m_num_flat = 0;
bool is_literal(expr* a) {
m.is_not(a, a);
return !is_app(a) || to_app(a)->get_num_args() == 0;
}
bool is_reducible(expr* a, expr* b) {
return b->get_ref_count() == 1 || is_literal(a);
}
public:
flatten_clauses(ast_manager& m, params_ref const& p, dependent_expr_state& fmls):
dependent_expr_simplifier(m, fmls) {
}
char const* name() const override { return "flatten-clauses"; }
void reset_statistics() override { m_num_flat = 0; }
void collect_statistics(statistics& st) const override {
st.update("flatten-clauses-rewrites", m_num_flat);
}
void reduce() override {
bool change = true;
while (change) {
change = false;
for (unsigned idx : indices()) {
auto de = m_fmls[idx];
expr* f = de.fml(), *a, *b, *c;
bool decomposed = false;
if (m.is_or(f, a, b) && m.is_not(b, b) && m.is_or(b) && is_reducible(a, b))
decomposed = true;
else if (m.is_or(f, b, a) && m.is_not(b, b) && m.is_or(b) && is_reducible(a, b))
decomposed = true;
if (decomposed) {
for (expr* arg : *to_app(b))
m_fmls.add(dependent_expr(m, m.mk_or(a, mk_not(m, arg)), de.dep()));
m_fmls.update(idx, dependent_expr(m, m.mk_true(), nullptr));
change = true;
++m_num_flat;
continue;
}
if (m.is_or(f, a, b) && m.is_and(b) && is_reducible(a, b))
decomposed = true;
else if (m.is_or(f, b, a) && m.is_and(b) && is_reducible(a, b))
decomposed = true;
if (decomposed) {
for (expr * arg : *to_app(b))
m_fmls.add(dependent_expr(m, m.mk_or(a, arg), de.dep()));
m_fmls.update(idx, dependent_expr(m, m.mk_true(), nullptr));
change = true;
++m_num_flat;
continue;
}
if (m.is_ite(f, a, b, c)) {
m_fmls.add(dependent_expr(m, m.mk_or(mk_not(m, a), b), de.dep()));
m_fmls.add(dependent_expr(m, m.mk_or(a, c), de.dep()));
m_fmls.update(idx, dependent_expr(m, m.mk_true(), nullptr));
change = true;
++m_num_flat;
continue;
}
}
}
}
};

View file

@ -151,8 +151,10 @@ std::ostream& model_reconstruction_trail::display(std::ostream& out) const {
out << t->m_decl->get_name() << " <- " << mk_pp(t->m_def, m) << "\n";
else {
for (auto const& [v, def] : t->m_subst->sub())
out << mk_pp(v, m) << " <- " << mk_pp(def, m) << "\n";
out << mk_pp(v, m) << " <- " << mk_pp(def, m) << "\n";
}
for (auto const& d : t->m_removed)
out << "rm: " << d << "\n";
}
return out;
}
}

View file

@ -0,0 +1,66 @@
/*++
Copyright (c) 2022 Microsoft Corporation
Module Name:
push_ite.h
Author:
Nikolaj Bjorner (nbjorner) 2022-11-24
--*/
#pragma once
#include "ast/simplifiers/dependent_expr_state.h"
#include "ast/rewriter/push_app_ite.h"
class push_ite_simplifier : public dependent_expr_simplifier {
push_app_ite_rw m_push;
public:
push_ite_simplifier(ast_manager& m, params_ref const& p, dependent_expr_state& fmls, bool c):
dependent_expr_simplifier(m, fmls),
m_push(m) {
m_push.set_conservative(c);
}
char const* name() const override { return "push-app-ite"; }
void reduce() override {
expr_ref r(m);
for (unsigned idx : indices()) {
auto const& d = m_fmls[idx];
m_push(d.fml(), r);
m_fmls.update(idx, dependent_expr(m, r, d.dep()));
}
}
};
class ng_push_ite_simplifier : public dependent_expr_simplifier {
ng_push_app_ite_rw m_push;
public:
ng_push_ite_simplifier(ast_manager& m, params_ref const& p, dependent_expr_state& fmls, bool c):
dependent_expr_simplifier(m, fmls),
m_push(m) {
m_push.set_conservative(c);
}
char const* name() const override { return "ng-push-app-ite"; }
void reduce() override {
expr_ref r(m);
for (unsigned idx : indices()) {
auto const& d = m_fmls[idx];
m_push(d.fml(), r);
m_fmls.update(idx, dependent_expr(m, r, d.dep()));
}
}
};

View file

@ -64,7 +64,7 @@ public:
}
void reduce() override {
TRACE("simplifier", tout << m_fmls << "\n");
TRACE("simplifier", tout << m_fmls);
for (auto* s : m_simplifiers) {
if (m_fmls.inconsistent())
break;
@ -74,7 +74,7 @@ public:
collect_stats _cs(*s);
s->reduce();
m_fmls.flatten_suffix();
TRACE("simplifier", tout << s->name() << "\n" << m_fmls << "\n");
TRACE("simplifier", tout << s->name() << "\n" << m_fmls);
}
}