Skip to content

Commit 91dc02d

Browse files
NikolajBjornerdependabot[bot]liguriolevnachChuyueSun
authored
Sls (#7439)
* reorg sls * sls * na * split into base and plugin * move sat_params to params directory, add op_def repair options * move sat_ddfw to sls, initiate sls-bv-plugin * porting bv-sls * adding basic plugin * na Signed-off-by: Nikolaj Bjorner <[email protected]> * add sls-sms solver * bv updates * updated dependencies Signed-off-by: Nikolaj Bjorner <[email protected]> * updated dependencies Signed-off-by: Nikolaj Bjorner <[email protected]> * use portable ptr-initializer Signed-off-by: Nikolaj Bjorner <[email protected]> * move definitions to cpp Signed-off-by: Nikolaj Bjorner <[email protected]> * use template<> syntax Signed-off-by: Nikolaj Bjorner <[email protected]> * fix compiler errors for gcc Signed-off-by: Nikolaj Bjorner <[email protected]> * Bump docker/build-push-action from 6.0.0 to 6.1.0 (#7265) Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 6.0.0 to 6.1.0. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](docker/build-push-action@v6.0.0...v6.1.0) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * set clean shutdown for local search and re-enable local search when it parallelizes with PB solver Signed-off-by: Nikolaj Bjorner <[email protected]> * Bump docker/build-push-action from 6.1.0 to 6.2.0 (#7269) Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 6.1.0 to 6.2.0. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](docker/build-push-action@v6.1.0...v6.2.0) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Fix a comment for Z3_solver_from_string (#7271) Z3_solver_from_string accepts a string buffer with solver assertions, not a string buffer with filename. * trigger the build with a comment change Signed-off-by: Lev Nachmanson <[email protected]> * remove macro distinction #7270 * fix #7268 * kludge to address #7232, probably superseeded by planned revision to setup/pypi Signed-off-by: Nikolaj Bjorner <[email protected]> * add new ema invariant (#7288) * Bump docker/build-push-action from 6.2.0 to 6.3.0 (#7280) Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 6.2.0 to 6.3.0. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](docker/build-push-action@v6.2.0...v6.3.0) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * merge Signed-off-by: Nikolaj Bjorner <[email protected]> * fix unit test build Signed-off-by: Nikolaj Bjorner <[email protected]> * remove shared attribute Signed-off-by: Nikolaj Bjorner <[email protected]> * remove stale files Signed-off-by: Nikolaj Bjorner <[email protected]> * fix build of unit test Signed-off-by: Nikolaj Bjorner <[email protected]> * fixes and rename sls-cc to sls-euf-plugin Signed-off-by: Nikolaj Bjorner <[email protected]> * na Signed-off-by: Nikolaj Bjorner <[email protected]> * testing / debugging arithmetic * updates to repair logic, mainly arithmetic * fixes to sls * evolve sls arith * bugfixes in sls-arith * fix typo Signed-off-by: Nikolaj Bjorner <[email protected]> * bug fixes * Update sls_test.cpp * fixes * fixes Signed-off-by: Nikolaj Bjorner <[email protected]> * fix build Signed-off-by: Nikolaj Bjorner <[email protected]> * refactor basic plugin and clause generation Signed-off-by: Nikolaj Bjorner <[email protected]> * fixes to ite and other Signed-off-by: Nikolaj Bjorner <[email protected]> * updates * update Signed-off-by: Nikolaj Bjorner <[email protected]> * fix division by 0 Signed-off-by: Nikolaj Bjorner <[email protected]> * disable fail restart Signed-off-by: Nikolaj Bjorner <[email protected]> * disable tabu when using reset moves Signed-off-by: Nikolaj Bjorner <[email protected]> * update sls_test Signed-off-by: Nikolaj Bjorner <[email protected]> * add factoring Signed-off-by: Nikolaj Bjorner <[email protected]> * fixes to semantics Signed-off-by: Nikolaj Bjorner <[email protected]> * re-add tabu override Signed-off-by: Nikolaj Bjorner <[email protected]> * generalize factoring Signed-off-by: Nikolaj Bjorner <[email protected]> * fix bug Signed-off-by: Nikolaj Bjorner <[email protected]> * remove restart Signed-off-by: Nikolaj Bjorner <[email protected]> * disable tabu in fallback modes Signed-off-by: Nikolaj Bjorner <[email protected]> * localize impact of factoring Signed-off-by: Nikolaj Bjorner <[email protected]> * delay factoring Signed-off-by: Nikolaj Bjorner <[email protected]> * flatten products Signed-off-by: Nikolaj Bjorner <[email protected]> * perform lookahead update + nested mul Signed-off-by: Nikolaj Bjorner <[email protected]> * disable nested mul Signed-off-by: Nikolaj Bjorner <[email protected]> * disable nested mul, use non-lookahead Signed-off-by: Nikolaj Bjorner <[email protected]> * make reset updates recursive Signed-off-by: Nikolaj Bjorner <[email protected]> * include linear moves Signed-off-by: Nikolaj Bjorner <[email protected]> * include 5% reset probability Signed-off-by: Nikolaj Bjorner <[email protected]> * separate linear update Signed-off-by: Nikolaj Bjorner <[email protected]> * separate linear update remove 20% threshold Signed-off-by: Nikolaj Bjorner <[email protected]> * remove linear opt Signed-off-by: Nikolaj Bjorner <[email protected]> * enable multiplier expansion, enable linear move Signed-off-by: Nikolaj Bjorner <[email protected]> * use unit coefficients for muls Signed-off-by: Nikolaj Bjorner <[email protected]> * disable non-tabu version of find_nl_moves Signed-off-by: Nikolaj Bjorner <[email protected]> * remove coefficient from multiplication definition Signed-off-by: Nikolaj Bjorner <[email protected]> * reorg monomials Signed-off-by: Nikolaj Bjorner <[email protected]> * add smt params to path Signed-off-by: Nikolaj Bjorner <[email protected]> * avoid negative reward Signed-off-by: Nikolaj Bjorner <[email protected]> * use reward as proxy for score Signed-off-by: Nikolaj Bjorner <[email protected]> * use reward as proxy for score Signed-off-by: Nikolaj Bjorner <[email protected]> * use exponential decay with breaks Signed-off-by: Nikolaj Bjorner <[email protected]> * use std::pow Signed-off-by: Nikolaj Bjorner <[email protected]> * fixes to bv Signed-off-by: Nikolaj Bjorner <[email protected]> * fixes to fixed Signed-off-by: Nikolaj Bjorner <[email protected]> * fixup repairs Signed-off-by: Nikolaj Bjorner <[email protected]> * reserve for multiplication Signed-off-by: Nikolaj Bjorner <[email protected]> * fixing repair Signed-off-by: Nikolaj Bjorner <[email protected]> * include bounds checks in set random * na * fixes to mul Signed-off-by: Nikolaj Bjorner <[email protected]> * fix mul inverse Signed-off-by: Nikolaj Bjorner <[email protected]> * fixes to handling signed operators Signed-off-by: Nikolaj Bjorner <[email protected]> * logging and fixes Signed-off-by: Nikolaj Bjorner <[email protected]> * gcm Signed-off-by: Nikolaj Bjorner <[email protected]> * peli Signed-off-by: Nikolaj Bjorner <[email protected]> * Add .env to gitignore to prevent environment files from being tracked * Add m_num_pelis counter to stats in sls_context * Remove m_num_pelis member from stats struct in sls_context * Enhance bv_sls_eval with improved repair and logging, refine is_bv_predicate in sls_bv_plugin * Remove verbose logging in register_term function of sls_basic_plugin and fix formatting in sls_context * Rename source files for consistency in `src/ast/sls` directory * Refactor bv_sls files to sls_bv with namespace and class name adjustments * Remove typename from member declarations in bv_fixed class * fixing conca Signed-off-by: Nikolaj Bjorner <[email protected]> * Add initial implementation of bit-vector SLS evaluation module in bv_sls_eval.cpp * Remove bv_sls_eval.cpp as part of code cleanup and refactoring * Refactor alignment of member variables in bv_plugin of sls namespace * Rename SLS engine related files to reflect their specific use for bit-vectors * Refactor SLS engine and evaluator components for bit-vector specifics and adjust memory manager alignment * Enhance bv_eval with use_current, lookahead strategies, and randomization improvements in SLS module * Refactor verbose logging and fix logic in range adjustment functions in sls bv modules * Remove commented verbose output in sls_bv_plugin.cpp during repair process * Add early return after setting fixed subterms in sls_bv_fixed.cpp * Remove redundant return statement in sls_bv_fixed.cpp * fixes to new value propagation Signed-off-by: Nikolaj Bjorner <[email protected]> * Refactor sls bv evaluation and fix logic checks for bit operations * Add array plugin support and update bv_eval in ast_sls module * Add array, model value, and user sort plugins to SLS module with enhancements in array propagation logic * Refactor array_plugin in sls to improve handling of select expressions with multiple arguments * Enhance array plugin with early termination and propagation verification, and improve euf and user sort plugins with propagation adjustments and debugging enhancements * Add support for handling 'distinct' expressions in SLS context and user sort plugin * Remove model value and user sort plugins from SLS theory * replace user plugin by euf plugin Signed-off-by: Nikolaj Bjorner <[email protected]> * remove extra file Signed-off-by: Nikolaj Bjorner <[email protected]> * Refactor handling of term registration and enhance distinct handling in sls_euf_plugin * Add TODO list for enhancements in sls_euf_plugin.cpp * add incremental mode * updated package * fix sls build Signed-off-by: Nikolaj Bjorner <[email protected]> * break sls build Signed-off-by: Nikolaj Bjorner <[email protected]> * fix build * break build again * fix build Signed-off-by: Nikolaj Bjorner <[email protected]> * fixes Signed-off-by: Nikolaj Bjorner <[email protected]> * fixing incremental Signed-off-by: Nikolaj Bjorner <[email protected]> * avoid units Signed-off-by: Nikolaj Bjorner <[email protected]> * fixup handling of disequality propagation Signed-off-by: Nikolaj Bjorner <[email protected]> * fx Signed-off-by: Nikolaj Bjorner <[email protected]> * recover shift-weight loop Signed-off-by: Nikolaj Bjorner <[email protected]> * alternate Signed-off-by: Nikolaj Bjorner <[email protected]> * throttle save model Signed-off-by: Nikolaj Bjorner <[email protected]> * allow for alternating Signed-off-by: Nikolaj Bjorner <[email protected]> * fix test for new signature of flip Signed-off-by: Nikolaj Bjorner <[email protected]> * bug fixes Signed-off-by: Nikolaj Bjorner <[email protected]> * restore use of value_hash Signed-off-by: Nikolaj Bjorner <[email protected]> * fixes Signed-off-by: Nikolaj Bjorner <[email protected]> * adding dt plugin Signed-off-by: Nikolaj Bjorner <[email protected]> * adt Signed-off-by: Nikolaj Bjorner <[email protected]> * dt updates Signed-off-by: Nikolaj Bjorner <[email protected]> * added cycle detection Signed-off-by: Nikolaj Bjorner <[email protected]> * updated sls-datatype Signed-off-by: Nikolaj Bjorner <[email protected]> * Refactor context management, improve datatype handling, and enhance logging in sls plugins. * axiomatize dt Signed-off-by: Nikolaj Bjorner <[email protected]> * add missing factory plugins to model Signed-off-by: Nikolaj Bjorner <[email protected]> * fixup finite domain search Signed-off-by: Nikolaj Bjorner <[email protected]> * fixup finite domain search Signed-off-by: Nikolaj Bjorner <[email protected]> * fixes Signed-off-by: Nikolaj Bjorner <[email protected]> * redo dfs Signed-off-by: Nikolaj Bjorner <[email protected]> * fixing model construction for underspecified operators Signed-off-by: Nikolaj Bjorner <[email protected]> * fixes to occurs check Signed-off-by: Nikolaj Bjorner <[email protected]> * fixup interpretation building Signed-off-by: Nikolaj Bjorner <[email protected]> * saturate worklist Signed-off-by: Nikolaj Bjorner <[email protected]> * delay distinct axiom Signed-off-by: Nikolaj Bjorner <[email protected]> * adding model-based sls for datatatypes * update the interface in sls_solver to transfer phase between SAT and SLS * add value transfer option Signed-off-by: Nikolaj Bjorner <[email protected]> * rename aux functions * Track shared variables using a unit set * debugging parallel integration * fix dirty flag setting * update log level * add plugin to smt_context, factor out sls_smt_plugin functionality. * bug fixes * fixes * use common infrastructure for sls-smt * fix build Signed-off-by: Nikolaj Bjorner <[email protected]> * fix build Signed-off-by: Nikolaj Bjorner <[email protected]> * remove declaration of context Signed-off-by: Nikolaj Bjorner <[email protected]> * add virtual destructor Signed-off-by: Nikolaj Bjorner <[email protected]> * build warnings Signed-off-by: Nikolaj Bjorner <[email protected]> * reorder inclusion order to define smt_context before theory_sls Signed-off-by: Nikolaj Bjorner <[email protected]> * change namespace for single threaded Signed-off-by: Nikolaj Bjorner <[email protected]> * check delayed eqs before nla Signed-off-by: Nikolaj Bjorner <[email protected]> * use independent completion flag for sls to avoid conflating with genuine cancelation * validate sls-arith lemmas Signed-off-by: Nikolaj Bjorner <[email protected]> * bugfixes Signed-off-by: Nikolaj Bjorner <[email protected]> * add intblast to legacy SMT solver * fixup model generation for theory_intblast Signed-off-by: Nikolaj Bjorner <[email protected]> * na Signed-off-by: Nikolaj Bjorner <[email protected]> * mk_value needs to accept more cases where integer expression doesn't evalate Signed-off-by: Nikolaj Bjorner <[email protected]> * use th-axioms to track origins of assertions Signed-off-by: Nikolaj Bjorner <[email protected]> * add missing operator handling for bitwise operators Signed-off-by: Nikolaj Bjorner <[email protected]> * add missing operator handling for bitwise operators Signed-off-by: Nikolaj Bjorner <[email protected]> * normalizing inequality Signed-off-by: Nikolaj Bjorner <[email protected]> * add virtual destructor Signed-off-by: Nikolaj Bjorner <[email protected]> * rework elim_unconstrained * fix non-termination Signed-off-by: Nikolaj Bjorner <[email protected]> * use glue as computed without adjustment * update model generation to fix model bug Signed-off-by: Nikolaj Bjorner <[email protected]> * fixes to model construction * remove package and package lock Signed-off-by: Nikolaj Bjorner <[email protected]> * fix build warning Signed-off-by: Nikolaj Bjorner <[email protected]> * use original gai Signed-off-by: Nikolaj Bjorner <[email protected]> --------- Signed-off-by: Nikolaj Bjorner <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Lev Nachmanson <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sergey Bronnikov <[email protected]> Co-authored-by: Lev Nachmanson <[email protected]> Co-authored-by: LiviaSun <[email protected]>
1 parent ecdfab8 commit 91dc02d

File tree

120 files changed

+11132
-4108
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+11132
-4108
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ rebase.cmd
66
callgrind.out.*
77
# .hpp files are automatically generated
88
*.hpp
9+
.env
910
.z3-trace
1011
.env
1112
.genaiscript
@@ -28,6 +29,8 @@ ocamlz3
2829
# Emacs temp files
2930
\#*\#
3031
# Directories with generated code and documentation
32+
node_modules/*
33+
.genaiscript/*
3134
release/*
3235
build/*
3336
trace/*
@@ -105,3 +108,4 @@ CMakeSettings.json
105108
.DS_Store
106109
dbg/**
107110
*.wsp
111+
CppProperties.json

scripts/mk_project.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ def init_project_def():
2828
add_lib('parser_util', ['ast'], 'parsers/util')
2929
add_lib('euf', ['ast'], 'ast/euf')
3030
add_lib('grobner', ['ast', 'dd', 'simplex'], 'math/grobner')
31-
add_lib('sat', ['params', 'util', 'dd', 'grobner'])
32-
add_lib('nlsat', ['polynomial', 'sat'])
33-
add_lib('lp', ['util', 'nlsat', 'grobner', 'interval', 'smt_params'], 'math/lp')
3431
add_lib('rewriter', ['ast', 'polynomial', 'interval', 'automata', 'params'], 'ast/rewriter')
35-
add_lib('bit_blaster', ['rewriter'], 'ast/rewriter/bit_blaster')
3632
add_lib('normal_forms', ['rewriter'], 'ast/normal_forms')
37-
add_lib('substitution', ['rewriter'], 'ast/substitution')
38-
add_lib('proofs', ['rewriter'], 'ast/proofs')
3933
add_lib('macros', ['rewriter'], 'ast/macros')
4034
add_lib('model', ['macros'])
4135
add_lib('converters', ['model'], 'ast/converters')
36+
add_lib('ast_sls', ['ast','normal_forms','converters','smt_params','euf'], 'ast/sls')
37+
add_lib('sat', ['params', 'util', 'dd', 'ast_sls', 'grobner'])
38+
add_lib('nlsat', ['polynomial', 'sat'])
39+
add_lib('lp', ['util', 'nlsat', 'grobner', 'interval', 'smt_params'], 'math/lp')
40+
add_lib('bit_blaster', ['rewriter'], 'ast/rewriter/bit_blaster')
41+
add_lib('substitution', ['rewriter'], 'ast/substitution')
42+
add_lib('proofs', ['rewriter'], 'ast/proofs')
4243
add_lib('simplifiers', ['euf', 'normal_forms', 'bit_blaster', 'converters', 'substitution'], 'ast/simplifiers')
43-
add_lib('ast_sls', ['ast','normal_forms','converters'], 'ast/sls')
4444
add_lib('tactic', ['simplifiers'])
4545
add_lib('mbp', ['model', 'simplex'], 'qe/mbp')
4646
add_lib('qe_lite', ['tactic', 'mbp'], 'qe/lite')

src/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ add_subdirectory(ast/euf)
5454
add_subdirectory(ast/converters)
5555
add_subdirectory(ast/substitution)
5656
add_subdirectory(ast/simplifiers)
57-
add_subdirectory(ast/sls)
5857
add_subdirectory(tactic)
5958
add_subdirectory(qe/mbp)
6059
add_subdirectory(qe/lite)
@@ -74,6 +73,7 @@ add_subdirectory(parsers/smt2)
7473
add_subdirectory(solver/assertions)
7574
add_subdirectory(ast/pattern)
7675
add_subdirectory(math/lp)
76+
add_subdirectory(ast/sls)
7777
add_subdirectory(sat/smt)
7878
add_subdirectory(sat/tactic)
7979
add_subdirectory(nlsat/tactic)

src/ast/arith_decl_plugin.h

+1
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ class arith_recognizers {
365365
MATCH_BINARY(is_div0);
366366
MATCH_BINARY(is_idiv0);
367367
MATCH_BINARY(is_power);
368+
MATCH_BINARY(is_power0);
368369

369370
MATCH_UNARY(is_sin);
370371
MATCH_UNARY(is_asin);

src/ast/ast.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,7 @@ ast * ast_manager::register_node_core(ast * n) {
17141714

17151715
n->m_id = is_decl(n) ? m_decl_id_gen.mk() : m_expr_id_gen.mk();
17161716

1717-
// track_id(*this, n, 77);
1717+
// track_id(*this, n, 9213);
17181718

17191719
// TRACE("ast", tout << (s_count++) << " Object " << n->m_id << " was created.\n";);
17201720
TRACE("mk_var_bug", tout << "mk_ast: " << n->m_id << "\n";);

src/ast/bv_decl_plugin.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -932,13 +932,13 @@ unsigned bv_util::get_int2bv_size(parameter const& p) {
932932
return static_cast<unsigned>(sz);
933933
}
934934

935-
app * bv_util::mk_bv2int(expr* e) {
935+
app * bv_util::mk_bv2int(expr* e) const {
936936
sort* s = m_manager.mk_sort(m_manager.mk_family_id("arith"), INT_SORT);
937937
parameter p(s);
938938
return m_manager.mk_app(get_fid(), OP_BV2INT, 1, &p, 1, &e);
939939
}
940940

941-
app* bv_util::mk_int2bv(unsigned sz, expr* e) {
941+
app* bv_util::mk_int2bv(unsigned sz, expr* e) const {
942942
parameter p(sz);
943943
return m_manager.mk_app(get_fid(), OP_INT2BV, 1, &p, 1, &e);
944944
}

src/ast/bv_decl_plugin.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ class bv_util : public bv_recognizers {
549549
app * mk_bv_ashr(expr* arg1, expr* arg2) { return m_manager.mk_app(get_fid(), OP_BASHR, arg1, arg2); }
550550
app * mk_bv_lshr(expr* arg1, expr* arg2) { return m_manager.mk_app(get_fid(), OP_BLSHR, arg1, arg2); }
551551

552-
app * mk_bv2int(expr* e);
553-
app * mk_int2bv(unsigned sz, expr* e);
552+
app * mk_bv2int(expr* e) const;
553+
app * mk_int2bv(unsigned sz, expr* e) const;
554554

555555
app* mk_bv_rotate_left(expr* arg1, expr* arg2) { return m_manager.mk_app(get_fid(), OP_EXT_ROTATE_LEFT, arg1, arg2); }
556556
app* mk_bv_rotate_right(expr* arg1, expr* arg2) { return m_manager.mk_app(get_fid(), OP_EXT_ROTATE_RIGHT, arg1, arg2); }

src/ast/datatype_decl_plugin.h

+2
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,10 @@ namespace datatype {
341341
ast_manager & get_manager() const { return m; }
342342
// sort * mk_datatype_sort(symbol const& name, unsigned n, sort* const* params);
343343
bool is_datatype(sort const* s) const { return is_sort_of(s, fid(), DATATYPE_SORT); }
344+
bool is_datatype(expr* e) const { return is_datatype(e->get_sort()); }
344345
bool is_enum_sort(sort* s);
345346
bool is_recursive(sort * ty);
347+
bool is_recursive(expr* e) { return is_recursive(e->get_sort()); }
346348
bool is_recursive_nested(sort * ty);
347349
bool is_constructor(func_decl * f) const { return is_decl_of(f, fid(), OP_DT_CONSTRUCTOR); }
348350
bool is_recognizer(func_decl * f) const { return is_recognizer0(f) || is_is(f); }

src/ast/euf/euf_egraph.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ namespace euf {
8282

8383
void egraph::reinsert_equality(enode* p) {
8484
SASSERT(p->is_equality());
85-
if (p->value() != l_true && p->get_arg(0)->get_root() == p->get_arg(1)->get_root())
85+
if (p->value() != l_true && p->get_arg(0)->get_root() == p->get_arg(1)->get_root()) {
8686
queue_literal(p, nullptr);
87+
if (p->value() == l_false && !m_on_propagate_literal)
88+
set_conflict(p->get_arg(0), p->get_arg(1), p->m_lit_justification);
89+
}
8790
}
8891

8992
void egraph::queue_literal(enode* p, enode* ante) {
@@ -201,6 +204,18 @@ namespace euf {
201204
}
202205
}
203206

207+
void egraph::new_diseq(enode* n, void* reason) {
208+
force_push();
209+
SASSERT(m.is_eq(n->get_expr()));
210+
auto j = justification::external(reason);
211+
auto a = n->get_arg(0), b = n->get_arg(1);
212+
auto r1 = a->get_root(), r2 = b->get_root();
213+
if (r1 == r2)
214+
set_conflict(a, b, j);
215+
else
216+
set_value(n, l_false, j);
217+
}
218+
204219
void egraph::new_diseq(enode* n) {
205220
SASSERT(n->is_equality());
206221
SASSERT(n->value() == l_false);

src/ast/euf/euf_egraph.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,11 @@ namespace euf {
278278
*/
279279
void merge(enode* n1, enode* n2, void* reason) { merge(n1, n2, justification::external(reason)); }
280280
void new_diseq(enode* n);
281+
void new_diseq(enode* n, void* reason);
281282

282283

283284
/**
284-
\brief propagate set of merges.
285+
\brief propagate set of merges.
285286
This call may detect an inconsistency. Then inconsistent() is true.
286287
Use then explain() to extract an explanation for the conflict.
287288

src/ast/rewriter/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ z3_add_component(rewriter
44
array_rewriter.cpp
55
ast_counter.cpp
66
bit2int.cpp
7+
bv2int_translator.cpp
78
bool_rewriter.cpp
89
bv_bounds.cpp
910
bv_elim.cpp

src/ast/rewriter/arith_rewriter.cpp

+124-1
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,129 @@ br_status arith_rewriter::reduce_power(expr * arg1, expr * arg2, op_kind kind, e
515515
}
516516
}
517517

518+
bool arith_rewriter::is_mul_factor(expr* s, expr* t) {
519+
if (m_util.is_mul(t))
520+
return any_of(*to_app(t), [&](expr* m) { return is_mul_factor(s, m); });
521+
return s == t;
522+
}
523+
524+
bool arith_rewriter::is_add_factor(expr* s, expr* t) {
525+
if (m_util.is_add(t))
526+
return all_of(*to_app(t), [&](expr* f) { return is_add_factor(s, f); });
527+
return is_mul_factor(s, t);
528+
}
529+
530+
expr_ref arith_rewriter::remove_factor(expr* s, expr* t) {
531+
532+
if (m_util.is_mul(t)) {
533+
ptr_buffer<expr> r;
534+
r.push_back(t);
535+
for (unsigned i = 0; i < r.size(); ++i) {
536+
expr* arg = r[i];
537+
if (m_util.is_mul(arg)) {
538+
r.append(to_app(arg)->get_num_args(), to_app(arg)->get_args());
539+
r[i] = r.back();
540+
r.pop_back();
541+
--i;
542+
continue;
543+
}
544+
if (s == arg) {
545+
r[i] = r.back();
546+
r.pop_back();
547+
break;
548+
}
549+
}
550+
switch (r.size()) {
551+
case 0:
552+
return expr_ref(m_util.mk_numeral(rational(1), m_util.is_int(t)), m);
553+
case 1:
554+
return expr_ref(r[0], m);
555+
default:
556+
return expr_ref(m_util.mk_mul(r.size(), r.data()), m);
557+
}
558+
}
559+
if (m_util.is_add(t)) {
560+
expr_ref_vector sum(m);
561+
sum.push_back(t);
562+
for (unsigned i = 0; i < sum.size(); ++i) {
563+
expr* arg = sum.get(i);
564+
if (m_util.is_add(arg)) {
565+
sum.append(to_app(arg)->get_num_args(), to_app(arg)->get_args());
566+
sum[i] = sum.back();
567+
sum.pop_back();
568+
--i;
569+
continue;
570+
}
571+
sum[i] = remove_factor(s, arg);
572+
}
573+
if (sum.size() == 1)
574+
return expr_ref(sum.get(0), m);
575+
else
576+
return expr_ref(m_util.mk_add(sum.size(), sum.data()), m);
577+
}
578+
else {
579+
SASSERT(s == t);
580+
return expr_ref(m_util.mk_numeral(rational(1), m_util.is_int(t)), m);
581+
}
582+
}
583+
584+
585+
void arith_rewriter::get_nl_muls(expr* t, ptr_buffer<expr>& muls) {
586+
if (m_util.is_mul(t)) {
587+
for (expr* arg : *to_app(t))
588+
get_nl_muls(arg, muls);
589+
}
590+
else if (!m_util.is_numeral(t))
591+
muls.push_back(t);
592+
}
593+
594+
expr* arith_rewriter::find_nl_factor(expr* t) {
595+
ptr_buffer<expr> sum, muls;
596+
sum.push_back(t);
597+
598+
for (unsigned i = 0; i < sum.size(); ++i) {
599+
expr* arg = sum[i];
600+
if (m_util.is_add(arg))
601+
sum.append(to_app(arg)->get_num_args(), to_app(arg)->get_args());
602+
else if (m_util.is_mul(arg)) {
603+
muls.reset();
604+
get_nl_muls(arg, muls);
605+
if (muls.size() <= 1)
606+
continue;
607+
for (auto m : muls) {
608+
if (is_add_factor(m, t))
609+
return m;
610+
}
611+
return nullptr;
612+
}
613+
}
614+
return nullptr;
615+
}
616+
617+
br_status arith_rewriter::factor_le_ge_eq(expr * arg1, expr * arg2, op_kind kind, expr_ref & result) {
618+
619+
if (is_zero(arg2)) {
620+
expr* f = find_nl_factor(arg1);
621+
if (!f)
622+
return BR_FAILED;
623+
expr_ref f2 = remove_factor(f, arg1);
624+
expr* z = m_util.mk_numeral(rational(0), m_util.is_int(arg1));
625+
result = m.mk_or(m_util.mk_eq(f, z), m_util.mk_eq(f2, z));
626+
switch (kind) {
627+
case EQ:
628+
break;
629+
case GE:
630+
result = m.mk_or(m.mk_iff(m_util.mk_ge(f, z), m_util.mk_ge(f2, z)), result);
631+
break;
632+
case LE:
633+
result = m.mk_or(m.mk_not(m.mk_iff(m_util.mk_ge(f, z), m_util.mk_ge(f2, z))), result);
634+
break;
635+
}
636+
return BR_REWRITE3;
637+
}
638+
return BR_FAILED;
639+
}
640+
518641
br_status arith_rewriter::mk_le_ge_eq_core(expr * arg1, expr * arg2, op_kind kind, expr_ref & result) {
519642
expr *orig_arg1 = arg1, *orig_arg2 = arg2;
520643
expr_ref new_arg1(m);
@@ -655,7 +778,7 @@ br_status arith_rewriter::mk_le_ge_eq_core(expr * arg1, expr * arg2, op_kind kin
655778
default: result = m.mk_eq(arg1, arg2); return BR_DONE;
656779
}
657780
}
658-
return BR_FAILED;
781+
return factor_le_ge_eq(arg1, arg2, kind, result);
659782
}
660783

661784

src/ast/rewriter/arith_rewriter.h

+6
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ class arith_rewriter : public poly_rewriter<arith_rewriter_core> {
7373
br_status is_separated(expr * arg1, expr * arg2, op_kind kind, expr_ref & result);
7474
bool is_non_negative(expr* e);
7575
br_status mk_le_ge_eq_core(expr * arg1, expr * arg2, op_kind kind, expr_ref & result);
76+
bool is_add_factor(expr* s, expr* t);
77+
bool is_mul_factor(expr* s, expr* t);
78+
expr* find_nl_factor(expr* t);
79+
void get_nl_muls(expr* t, ptr_buffer<expr>& muls);
80+
expr_ref remove_factor(expr* s, expr* t);
81+
br_status factor_le_ge_eq(expr * arg1, expr * arg2, op_kind kind, expr_ref & result);
7682

7783
bool elim_to_real_var(expr * var, expr_ref & new_var);
7884
bool elim_to_real_mon(expr * monomial, expr_ref & new_monomial);

0 commit comments

Comments
 (0)