Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spacer Global Guidance #6026

Merged
merged 78 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
94b32b8
Make spacer_sem_matcher::reset() public
agurfinkel Apr 27, 2022
ed44d3b
Add .clang-format for src/muz/spacer
hgvk94 Feb 16, 2021
bd52554
Mark substitution::get_bindings() as const
agurfinkel Apr 27, 2022
87ff0e9
Fix in spacer_antiunify
hgvk94 Feb 12, 2021
4dcd1bf
Various helper methods in spacer_util
agurfinkel Apr 27, 2022
54f3e52
Add spacer_cluster for clustering lemmas
agurfinkel Apr 30, 2022
68dd69d
Integrate spacer_cluster into spacer_context
agurfinkel Apr 30, 2022
7aacc8b
Custom clang-format pragmas for spacer_context
agurfinkel May 4, 2022
7db923a
Computation of convex closure and matrix kernel
hgvk94 Feb 16, 2021
61bdaea
Add spacer_concretize
hgvk94 Feb 16, 2021
45532fa
Utility methods for spacer conjecture rule
hgvk94 Feb 16, 2021
a601cc1
Add spacer_expand_bnd_generalizer
agurfinkel Apr 28, 2022
f6d0fc3
Add spacer_global_generalizer
agurfinkel May 4, 2022
bd7e6c3
Remove fp.spacer.print_json option
agurfinkel Apr 27, 2022
e8bb6f9
Workaround for segfault in spacer_proof_utils
hgvk94 Feb 12, 2021
c3cb7d5
Revert bug for incomplete models
agurfinkel Apr 28, 2022
62c2158
Use local fresh variables in spacer_global_generalizer
agurfinkel May 9, 2022
c873a85
Cleanup of spacer_convex_closure
agurfinkel May 11, 2022
6791848
Allow arbitrary expressions to name cols in convex_closure
agurfinkel May 11, 2022
98efe6e
WIP: convex closure
agurfinkel May 12, 2022
9c7a80a
WIP: convex closure
agurfinkel May 12, 2022
b0d5d82
Fix bindings order in spacer_global_generalizer
agurfinkel May 12, 2022
0104cae
Increase verbosity level for smt_context stats
agurfinkel May 12, 2022
8efc9b9
Dead code in qe_mbp
agurfinkel May 12, 2022
d6f1754
bug fixes in spacer_global_generalizer::subsumer
agurfinkel May 12, 2022
790ddad
Partially remove dependence of size of m_alphas
agurfinkel May 12, 2022
42eeee1
Subtle bug in kernel computation
agurfinkel May 13, 2022
9f21c78
another test for sparse_matrix_ops::kernel
agurfinkel May 13, 2022
7baeb20
Implementation of matrix kernel using Fraction Free Elimination
agurfinkel May 13, 2022
f42ca70
clang-format sparse_matrix_ops.h
agurfinkel May 14, 2022
aff6a43
another implementation of ffe kernel in sparse_matrix_ops
agurfinkel May 14, 2022
7ff6c77
Re-do arith_kernel and convex_closure
agurfinkel May 14, 2022
0bbb723
update spacer_global_generalization for new subsumer
agurfinkel May 14, 2022
717cf1d
remove spacer.gg.use_sage parameter
agurfinkel May 14, 2022
f27c346
cleanup of spacer_global_generalizer
agurfinkel May 14, 2022
31b0fd6
Removed dependency on sage
agurfinkel May 14, 2022
44f27b1
fix in spacer_convex_closure
agurfinkel May 14, 2022
e1ddc8a
spacer_sem_matcher: consider an additional semantic matching
agurfinkel Aug 4, 2022
9a2da38
spacer_global_generalizer: improve do_conjecture
agurfinkel Aug 4, 2022
0f534d0
spacer_conjecture: formatting
agurfinkel Aug 4, 2022
be1e9c0
spacer_cluster: improve debug prints
agurfinkel Aug 4, 2022
7eb3aea
spacer_context: improve debug prints
agurfinkel Aug 4, 2022
ab44f86
spacer_context: re-queue may pobs
agurfinkel Aug 4, 2022
bc05b82
spacer_cluster print formatting
agurfinkel Jun 9, 2022
78d95bd
reset methods on pob
agurfinkel Jun 9, 2022
0d15b29
cleanup of print and local variable names
agurfinkel Jun 9, 2022
1ca2918
formatting
agurfinkel Jun 9, 2022
30131ba
reset generalization data once it has been used
agurfinkel Jun 9, 2022
bf58d4d
refactored extra pob creation during global guidance
agurfinkel Jun 10, 2022
dfdc3fe
fix bug copying sparse matrix into spacer matrix
agurfinkel Jun 10, 2022
8d6cd33
bug fix in spacer_convex_closure
agurfinkel Jun 16, 2022
36818b1
formatting change in spacer_context
agurfinkel Jun 16, 2022
57525a3
spacer_cluster: get_min_lvl
agurfinkel Jul 11, 2022
c317839
spacer_context: add desired_level to pob
agurfinkel Jul 11, 2022
1a7def5
spacer_context: renamed subsume stats
agurfinkel Jul 11, 2022
4b2a9b3
spacer_convex_closure: fix prototype of is_congruent_mod()
agurfinkel Jul 11, 2022
1e39629
spacer_convex_closure: hacks in infer_div_pred()
agurfinkel Jul 11, 2022
d556eff
spacer_util: do not expand literals with mod
agurfinkel Jul 11, 2022
dc29e8f
spacer_util: rename m_util into m_arith
agurfinkel Jul 11, 2022
69a5ba4
spacer_util: cleanup normalize()
agurfinkel Jul 11, 2022
46ae6ef
spacer_util: formatting
agurfinkel Jul 11, 2022
2fd7038
spacer_context: formatting cleanup on subsume and conjecture
agurfinkel Jul 11, 2022
002b3a1
spacer_context: fix handling may pobs when abs_weakness is enabled
agurfinkel Jul 11, 2022
71a5669
spacer_arith_kernel: enhance debug print
agurfinkel Jul 11, 2022
5c3b297
spacer_global_generalizer: improve matching on conjecture
agurfinkel Jul 11, 2022
84cb6e6
spacer_global_generalizer: set desired level on conjecture pob
agurfinkel Jul 11, 2022
02224c6
spacer_global_generalizer: debug print
agurfinkel Jul 11, 2022
7deadf2
spacer_global_generalizer: set min level on new pobs
agurfinkel Jul 11, 2022
99af59d
spacer_global_generalizer: do no re-create closed pobs
agurfinkel Jul 11, 2022
0dbb22c
spacer_context: normalize twice
agurfinkel Jul 12, 2022
21d14bc
spacer_context: forward propagate only same kind of pobs
agurfinkel Aug 4, 2022
e484431
sketch of inductive generalizer
agurfinkel Jul 28, 2022
a62fc72
fix ordering in spacer_cluster_util
agurfinkel Aug 30, 2022
5a8eb94
fix resetting of substitution matcher in spacer_conjecture
agurfinkel Aug 30, 2022
d14f012
add spacer_util is_normalized() method
agurfinkel Aug 30, 2022
a715d93
simplify normalization of pob expressions
agurfinkel Aug 30, 2022
dc2a51d
fix in spacer_global_generalizer
agurfinkel Aug 30, 2022
2d664ba
fix in spacer_context
agurfinkel Aug 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ast/substitution/substitution.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class substitution {
return find(to_var(v.get_expr()), v.get_offset(), r);
}

void get_binding(unsigned binding_num, var_offset& var, expr_offset& r) {
void get_binding(unsigned binding_num, var_offset& var, expr_offset& r) const {
var = m_vars[binding_num];
VERIFY(m_subst.find(var.first, var.second, r));
}
Expand Down
4 changes: 4 additions & 0 deletions src/math/simplex/simplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ namespace simplex {
sparse_matrix_ops::kernel(M, K);
}

void kernel_ffe(sparse_matrix<mpq_ext> &M, vector<vector<rational>> &K) {
sparse_matrix_ops::kernel_ffe(M, K);
}

void ensure_rational_solution(simplex<mpq_ext>& S) {
rational delta(1);
for (unsigned i = 0; i < S.get_num_vars(); ++i) {
Expand Down
1 change: 1 addition & 0 deletions src/math/simplex/simplex.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,6 @@ namespace simplex {
void ensure_rational_solution(simplex<mpq_ext>& s);

void kernel(sparse_matrix<mpq_ext>& s, vector<vector<rational>>& K);
void kernel_ffe(sparse_matrix<mpq_ext> &s, vector<vector<rational>> &K);
};

1 change: 1 addition & 0 deletions src/math/simplex/sparse_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ namespace simplex {
void add_var(row r, numeral const& n, var_t var);
void add(row r, numeral const& n, row src);
void mul(row r, numeral const& n);
void div(row r, numeral const& n);
void neg(row r);
void del(row r);

Expand Down
19 changes: 19 additions & 0 deletions src/math/simplex/sparse_matrix_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,25 @@ namespace simplex {
}
}

/**
\brief Set row <- n/row
*/
template <typename Ext>
void sparse_matrix<Ext>::div(row r, numeral const &n) {
SASSERT(!m.is_zero(n));
if (m.is_one(n)) {
// no op
} else if (m.is_minus_one(n)) {
neg(r);
} else {
row_iterator it = row_begin(r);
row_iterator end = row_end(r);
for (; it != end; ++it) {
m.div(it->m_coeff, n, it->m_coeff);
}
}
}

/**
\brief Delete row.
*/
Expand Down
159 changes: 156 additions & 3 deletions src/math/simplex/sparse_matrix_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class sparse_matrix_ops {
for (auto [row, row_entry] : M.get_rows(k)) {
if (c[row.id()] != 0) continue;
auto &m_jk = row_entry->m_coeff;
if (mpq_manager<false>::is_zero(m_jk)) continue;
if (m.is_zero(m_jk)) continue;

// D = rational(-1) / m_jk;
m.set(D, m_jk);
Expand All @@ -68,9 +68,10 @@ class sparse_matrix_ops {
K.push_back(vector<rational>());
for (unsigned i = 0; i < n_vars; ++i) {
if (d[i] > 0) {
auto r = sparse_matrix<mpq_ext>::row(d[i] - 1);
auto r = typename sparse_matrix<Ext>::row(d[i] - 1);
K.back().push_back(rational(M.get_coeff(r, k)));
} else if (i == k)
}
else if (i == k)
K.back().push_back(rational(1));
else
K.back().push_back(rational(0));
Expand All @@ -81,5 +82,157 @@ class sparse_matrix_ops {
static void kernel(sparse_matrix<mpq_ext> &M, vector<vector<rational>> &K) {
kernel<mpq_ext>(M, K);
}

/// \brief Kernel computation using fraction-free-elimination
///
template <typename Ext>
static void kernel_ffe(sparse_matrix<Ext> &M, vector<vector<rational>> &K) {
using scoped_numeral = typename Ext::scoped_numeral;

/// Based on George Nakos, Peter R. Turner, Robert M. Williams:
/// Fraction-free algorithms for linear and polynomial equations. SIGSAM
/// Bull. 31(3): 11-19 (1997)
vector<unsigned> d, c;
unsigned n_vars = M.num_vars(), n_rows = M.num_rows();
c.resize(n_rows, 0u);
d.resize(n_vars, 0u);

auto &m = M.get_manager();
scoped_numeral m_ik(m);
scoped_numeral m_jk(m);
scoped_numeral last_pv(m);

m.set(last_pv, 1);

for (unsigned k = 0; k < n_vars; ++k) {
d[k] = 0;
for (auto [row, row_entry] : M.get_rows(k)) {
if (c[row.id()] != 0) continue;
auto &m_jk_ref = row_entry->m_coeff;
if (m.is_zero(m_jk_ref))
// XXX: should not happen, the matrix is sparse
continue;

// this a pivot column
m.set(m_jk, m_jk_ref);

// ensure that pivot is negative
if (m.is_pos(m_jk_ref)) { M.neg(row); }
else { m.neg(m_jk); }
// m_jk is abs(M[j]][k])

for (auto row_i : M.get_rows()) {
if (row_i.id() == row.id()) continue;

m.set(m_ik, M.get_coeff(row_i, k));
// row_i *= m_jk
M.mul(row_i, m_jk);
if (!m.is_zero(m_ik)) {
// row_i += m_ik * row
M.add(row_i, m_ik, row);
}
M.div(row_i, last_pv);
}
c[row.id()] = k + 1;
d[k] = row.id() + 1;
m.set(last_pv, m_jk);
break;
}
}

for (unsigned k = 0; k < n_vars; ++k) {
if (d[k] != 0) continue;
K.push_back(vector<rational>());
for (unsigned i = 0; i < n_vars; ++i) {
if (d[i] > 0) {
auto r = typename sparse_matrix<Ext>::row(d[i] - 1);
K.back().push_back(rational(M.get_coeff(r, k)));
}
else if (i == k)
K.back().push_back(rational(last_pv));
else
K.back().push_back(rational(0));
}
}
}

static void kernel_ffe(sparse_matrix<mpq_ext> &M,
vector<vector<rational>> &K) {
kernel_ffe<mpq_ext>(M, K);
}


template <typename Ext>
static void kernel_ffe(sparse_matrix<Ext> &M, sparse_matrix<Ext> &K,
vector<unsigned> &basics) {
using scoped_numeral = typename Ext::scoped_numeral;

/// Based on George Nakos, Peter R. Turner, Robert M. Williams:
/// Fraction-free algorithms for linear and polynomial equations. SIGSAM
/// Bull. 31(3): 11-19 (1997)
vector<unsigned> d, c;
unsigned n_vars = M.num_vars(), n_rows = M.num_rows();
c.resize(n_rows, 0u);
d.resize(n_vars, 0u);

auto &m = M.get_manager();
scoped_numeral m_ik(m);
scoped_numeral m_jk(m);
scoped_numeral last_pv(m);

m.set(last_pv, 1);

for (unsigned k = 0; k < n_vars; ++k) {
d[k] = 0;
for (auto [row, row_entry] : M.get_rows(k)) {
if (c[row.id()] != 0) continue;
auto &m_jk_ref = row_entry->m_coeff;
if (m.is_zero(m_jk_ref))
// XXX: should not happen, the matrix is sparse
continue;

// this a pivot column
m.set(m_jk, m_jk_ref);

// ensure that pivot is negative
if (m.is_pos(m_jk_ref)) { M.neg(row); }
else { m.neg(m_jk); }
// m_jk is abs(M[j]][k])

for (auto row_i : M.get_rows()) {
if (row_i.id() == row.id()) continue;

m.set(m_ik, M.get_coeff(row_i, k));
// row_i *= m_jk
M.mul(row_i, m_jk);
if (!m.is_zero(m_ik)) {
// row_i += m_ik * row
M.add(row_i, m_ik, row);
}
M.div(row_i, last_pv);
}
c[row.id()] = k + 1;
d[k] = row.id() + 1;
m.set(last_pv, m_jk);
break;
}
}

K.ensure_var(n_vars - 1);
for (unsigned k = 0; k < n_vars; ++k) {
if (d[k] != 0) continue;
auto row = K.mk_row();
basics.push_back(k);
for (unsigned i = 0; i < n_vars; ++i) {
if (d[i] > 0) {
auto r = typename sparse_matrix<Ext>::row(d[i] - 1);
K.add_var(row, M.get_coeff(r, k), i);
}
else if (i == k)
K.add_var(row, last_pv, i);
}
}
}

};
} // namespace simplex
7 changes: 6 additions & 1 deletion src/muz/base/fp_params.pyg
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ def_module_params('fp',
('spacer.p3.share_lemmas', BOOL, False, 'Share frame lemmas'),
('spacer.p3.share_invariants', BOOL, False, "Share invariants lemmas"),
('spacer.min_level', UINT, 0, 'Minimal level to explore'),
('spacer.print_json', SYMBOL, '', 'Print pobs tree in JSON format to a given file'),
('spacer.trace_file', SYMBOL, '', 'Log file for progress events'),
('spacer.ctp', BOOL, True, 'Enable counterexample-to-pushing'),
('spacer.use_inc_clause', BOOL, True, 'Use incremental clause to represent trans'),
Expand All @@ -181,4 +180,10 @@ def_module_params('fp',
('spacer.use_lim_num_gen', BOOL, False, 'Enable limit numbers generalizer to get smaller numbers'),
('spacer.logic', SYMBOL, '', 'SMT-LIB logic to configure internal SMT solvers'),
('spacer.arith.solver', UINT, 2, 'arithmetic solver: 0 - no solver, 1 - bellman-ford based solver (diff. logic only), 2 - simplex based solver, 3 - floyd-warshall based solver (diff. logic only) and no theory combination 4 - utvpi, 5 - infinitary lra, 6 - lra solver'),
('spacer.global', BOOL, False, 'Enable global guidance'),
('spacer.gg.concretize', BOOL, True, 'Enable global guidance concretize'),
('spacer.gg.conjecture', BOOL, True, 'Enable global guidance conjecture'),
('spacer.gg.subsume', BOOL, True, 'Enable global guidance subsume'),
('spacer.use_iuc', BOOL, True, 'Enable Interpolating Unsat Core(IUC) for lemma generalization'),
('spacer.expand_bnd', BOOL, False, 'Enable expand-bound lemma generalization'),
))
8 changes: 8 additions & 0 deletions src/muz/spacer/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
BasedOnStyle: LLVM
AllowShortFunctionsOnASingleLine: All
IndentWidth: '4'
AllowShortBlocksOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
...
10 changes: 9 additions & 1 deletion src/muz/spacer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ z3_add_component(spacer
spacer_prop_solver.cpp
spacer_sym_mux.cpp
spacer_util.cpp
spacer_cluster_util.cpp
spacer_iuc_solver.cpp
spacer_legacy_mbp.cpp
spacer_proof_utils.cpp
Expand All @@ -22,12 +23,19 @@ z3_add_component(spacer
spacer_sem_matcher.cpp
spacer_quant_generalizer.cpp
spacer_arith_generalizers.cpp
spacer_global_generalizer.cpp
spacer_ind_lemma_generalizer.cpp
spacer_expand_bnd_generalizer.cpp
spacer_cluster.cpp
spacer_callback.cpp
spacer_json.cpp
spacer_iuc_proof.cpp
spacer_mbc.cpp
spacer_pdr.cpp
spacer_sat_answer.cpp
spacer_concretize.cpp
spacer_convex_closure.cpp
spacer_conjecture.cpp
spacer_arith_kernel.cpp
COMPONENT_DEPENDENCIES
arith_tactics
core_tactics
Expand Down
1 change: 1 addition & 0 deletions src/muz/spacer/spacer_antiunify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ void anti_unifier::operator()(expr *e1, expr *e2, expr_ref &res,
m_pinned.push_back(u);
m_cache.insert(n1, n2, u);
}
m_todo.pop_back();
}

expr *r;
Expand Down
Loading