Skip to content

Commit

Permalink
Sls (#7439)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
5 people authored Nov 2, 2024
1 parent ecdfab8 commit 91dc02d
Show file tree
Hide file tree
Showing 120 changed files with 11,132 additions and 4,108 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ rebase.cmd
callgrind.out.*
# .hpp files are automatically generated
*.hpp
.env
.z3-trace
.env
.genaiscript
Expand All @@ -28,6 +29,8 @@ ocamlz3
# Emacs temp files
\#*\#
# Directories with generated code and documentation
node_modules/*
.genaiscript/*
release/*
build/*
trace/*
Expand Down Expand Up @@ -105,3 +108,4 @@ CMakeSettings.json
.DS_Store
dbg/**
*.wsp
CppProperties.json
14 changes: 7 additions & 7 deletions scripts/mk_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ def init_project_def():
add_lib('parser_util', ['ast'], 'parsers/util')
add_lib('euf', ['ast'], 'ast/euf')
add_lib('grobner', ['ast', 'dd', 'simplex'], 'math/grobner')
add_lib('sat', ['params', 'util', 'dd', 'grobner'])
add_lib('nlsat', ['polynomial', 'sat'])
add_lib('lp', ['util', 'nlsat', 'grobner', 'interval', 'smt_params'], 'math/lp')
add_lib('rewriter', ['ast', 'polynomial', 'interval', 'automata', 'params'], 'ast/rewriter')
add_lib('bit_blaster', ['rewriter'], 'ast/rewriter/bit_blaster')
add_lib('normal_forms', ['rewriter'], 'ast/normal_forms')
add_lib('substitution', ['rewriter'], 'ast/substitution')
add_lib('proofs', ['rewriter'], 'ast/proofs')
add_lib('macros', ['rewriter'], 'ast/macros')
add_lib('model', ['macros'])
add_lib('converters', ['model'], 'ast/converters')
add_lib('ast_sls', ['ast','normal_forms','converters','smt_params','euf'], 'ast/sls')
add_lib('sat', ['params', 'util', 'dd', 'ast_sls', 'grobner'])
add_lib('nlsat', ['polynomial', 'sat'])
add_lib('lp', ['util', 'nlsat', 'grobner', 'interval', 'smt_params'], 'math/lp')
add_lib('bit_blaster', ['rewriter'], 'ast/rewriter/bit_blaster')
add_lib('substitution', ['rewriter'], 'ast/substitution')
add_lib('proofs', ['rewriter'], 'ast/proofs')
add_lib('simplifiers', ['euf', 'normal_forms', 'bit_blaster', 'converters', 'substitution'], 'ast/simplifiers')
add_lib('ast_sls', ['ast','normal_forms','converters'], 'ast/sls')
add_lib('tactic', ['simplifiers'])
add_lib('mbp', ['model', 'simplex'], 'qe/mbp')
add_lib('qe_lite', ['tactic', 'mbp'], 'qe/lite')
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ add_subdirectory(ast/euf)
add_subdirectory(ast/converters)
add_subdirectory(ast/substitution)
add_subdirectory(ast/simplifiers)
add_subdirectory(ast/sls)
add_subdirectory(tactic)
add_subdirectory(qe/mbp)
add_subdirectory(qe/lite)
Expand All @@ -74,6 +73,7 @@ add_subdirectory(parsers/smt2)
add_subdirectory(solver/assertions)
add_subdirectory(ast/pattern)
add_subdirectory(math/lp)
add_subdirectory(ast/sls)
add_subdirectory(sat/smt)
add_subdirectory(sat/tactic)
add_subdirectory(nlsat/tactic)
Expand Down
1 change: 1 addition & 0 deletions src/ast/arith_decl_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ class arith_recognizers {
MATCH_BINARY(is_div0);
MATCH_BINARY(is_idiv0);
MATCH_BINARY(is_power);
MATCH_BINARY(is_power0);

MATCH_UNARY(is_sin);
MATCH_UNARY(is_asin);
Expand Down
2 changes: 1 addition & 1 deletion src/ast/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,7 @@ ast * ast_manager::register_node_core(ast * n) {

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

// track_id(*this, n, 77);
// track_id(*this, n, 9213);

// TRACE("ast", tout << (s_count++) << " Object " << n->m_id << " was created.\n";);
TRACE("mk_var_bug", tout << "mk_ast: " << n->m_id << "\n";);
Expand Down
4 changes: 2 additions & 2 deletions src/ast/bv_decl_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,13 +932,13 @@ unsigned bv_util::get_int2bv_size(parameter const& p) {
return static_cast<unsigned>(sz);
}

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

app* bv_util::mk_int2bv(unsigned sz, expr* e) {
app* bv_util::mk_int2bv(unsigned sz, expr* e) const {
parameter p(sz);
return m_manager.mk_app(get_fid(), OP_INT2BV, 1, &p, 1, &e);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ast/bv_decl_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,8 @@ class bv_util : public bv_recognizers {
app * mk_bv_ashr(expr* arg1, expr* arg2) { return m_manager.mk_app(get_fid(), OP_BASHR, arg1, arg2); }
app * mk_bv_lshr(expr* arg1, expr* arg2) { return m_manager.mk_app(get_fid(), OP_BLSHR, arg1, arg2); }

app * mk_bv2int(expr* e);
app * mk_int2bv(unsigned sz, expr* e);
app * mk_bv2int(expr* e) const;
app * mk_int2bv(unsigned sz, expr* e) const;

app* mk_bv_rotate_left(expr* arg1, expr* arg2) { return m_manager.mk_app(get_fid(), OP_EXT_ROTATE_LEFT, arg1, arg2); }
app* mk_bv_rotate_right(expr* arg1, expr* arg2) { return m_manager.mk_app(get_fid(), OP_EXT_ROTATE_RIGHT, arg1, arg2); }
Expand Down
2 changes: 2 additions & 0 deletions src/ast/datatype_decl_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,10 @@ namespace datatype {
ast_manager & get_manager() const { return m; }
// sort * mk_datatype_sort(symbol const& name, unsigned n, sort* const* params);
bool is_datatype(sort const* s) const { return is_sort_of(s, fid(), DATATYPE_SORT); }
bool is_datatype(expr* e) const { return is_datatype(e->get_sort()); }
bool is_enum_sort(sort* s);
bool is_recursive(sort * ty);
bool is_recursive(expr* e) { return is_recursive(e->get_sort()); }
bool is_recursive_nested(sort * ty);
bool is_constructor(func_decl * f) const { return is_decl_of(f, fid(), OP_DT_CONSTRUCTOR); }
bool is_recognizer(func_decl * f) const { return is_recognizer0(f) || is_is(f); }
Expand Down
17 changes: 16 additions & 1 deletion src/ast/euf/euf_egraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ namespace euf {

void egraph::reinsert_equality(enode* p) {
SASSERT(p->is_equality());
if (p->value() != l_true && p->get_arg(0)->get_root() == p->get_arg(1)->get_root())
if (p->value() != l_true && p->get_arg(0)->get_root() == p->get_arg(1)->get_root()) {
queue_literal(p, nullptr);
if (p->value() == l_false && !m_on_propagate_literal)
set_conflict(p->get_arg(0), p->get_arg(1), p->m_lit_justification);
}
}

void egraph::queue_literal(enode* p, enode* ante) {
Expand Down Expand Up @@ -201,6 +204,18 @@ namespace euf {
}
}

void egraph::new_diseq(enode* n, void* reason) {
force_push();
SASSERT(m.is_eq(n->get_expr()));
auto j = justification::external(reason);
auto a = n->get_arg(0), b = n->get_arg(1);
auto r1 = a->get_root(), r2 = b->get_root();
if (r1 == r2)
set_conflict(a, b, j);
else
set_value(n, l_false, j);
}

void egraph::new_diseq(enode* n) {
SASSERT(n->is_equality());
SASSERT(n->value() == l_false);
Expand Down
3 changes: 2 additions & 1 deletion src/ast/euf/euf_egraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,11 @@ namespace euf {
*/
void merge(enode* n1, enode* n2, void* reason) { merge(n1, n2, justification::external(reason)); }
void new_diseq(enode* n);
void new_diseq(enode* n, void* reason);


/**
\brief propagate set of merges.
\brief propagate set of merges.
This call may detect an inconsistency. Then inconsistent() is true.
Use then explain() to extract an explanation for the conflict.
Expand Down
1 change: 1 addition & 0 deletions src/ast/rewriter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ z3_add_component(rewriter
array_rewriter.cpp
ast_counter.cpp
bit2int.cpp
bv2int_translator.cpp
bool_rewriter.cpp
bv_bounds.cpp
bv_elim.cpp
Expand Down
125 changes: 124 additions & 1 deletion src/ast/rewriter/arith_rewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,129 @@ br_status arith_rewriter::reduce_power(expr * arg1, expr * arg2, op_kind kind, e
}
}

bool arith_rewriter::is_mul_factor(expr* s, expr* t) {
if (m_util.is_mul(t))
return any_of(*to_app(t), [&](expr* m) { return is_mul_factor(s, m); });
return s == t;
}

bool arith_rewriter::is_add_factor(expr* s, expr* t) {
if (m_util.is_add(t))
return all_of(*to_app(t), [&](expr* f) { return is_add_factor(s, f); });
return is_mul_factor(s, t);
}

expr_ref arith_rewriter::remove_factor(expr* s, expr* t) {

if (m_util.is_mul(t)) {
ptr_buffer<expr> r;
r.push_back(t);
for (unsigned i = 0; i < r.size(); ++i) {
expr* arg = r[i];
if (m_util.is_mul(arg)) {
r.append(to_app(arg)->get_num_args(), to_app(arg)->get_args());
r[i] = r.back();
r.pop_back();
--i;
continue;
}
if (s == arg) {
r[i] = r.back();
r.pop_back();
break;
}
}
switch (r.size()) {
case 0:
return expr_ref(m_util.mk_numeral(rational(1), m_util.is_int(t)), m);
case 1:
return expr_ref(r[0], m);
default:
return expr_ref(m_util.mk_mul(r.size(), r.data()), m);
}
}
if (m_util.is_add(t)) {
expr_ref_vector sum(m);
sum.push_back(t);
for (unsigned i = 0; i < sum.size(); ++i) {
expr* arg = sum.get(i);
if (m_util.is_add(arg)) {
sum.append(to_app(arg)->get_num_args(), to_app(arg)->get_args());
sum[i] = sum.back();
sum.pop_back();
--i;
continue;
}
sum[i] = remove_factor(s, arg);
}
if (sum.size() == 1)
return expr_ref(sum.get(0), m);
else
return expr_ref(m_util.mk_add(sum.size(), sum.data()), m);
}
else {
SASSERT(s == t);
return expr_ref(m_util.mk_numeral(rational(1), m_util.is_int(t)), m);
}
}


void arith_rewriter::get_nl_muls(expr* t, ptr_buffer<expr>& muls) {
if (m_util.is_mul(t)) {
for (expr* arg : *to_app(t))
get_nl_muls(arg, muls);
}
else if (!m_util.is_numeral(t))
muls.push_back(t);
}

expr* arith_rewriter::find_nl_factor(expr* t) {
ptr_buffer<expr> sum, muls;
sum.push_back(t);

for (unsigned i = 0; i < sum.size(); ++i) {
expr* arg = sum[i];
if (m_util.is_add(arg))
sum.append(to_app(arg)->get_num_args(), to_app(arg)->get_args());
else if (m_util.is_mul(arg)) {
muls.reset();
get_nl_muls(arg, muls);
if (muls.size() <= 1)
continue;
for (auto m : muls) {
if (is_add_factor(m, t))
return m;
}
return nullptr;
}
}
return nullptr;
}

br_status arith_rewriter::factor_le_ge_eq(expr * arg1, expr * arg2, op_kind kind, expr_ref & result) {

if (is_zero(arg2)) {
expr* f = find_nl_factor(arg1);
if (!f)
return BR_FAILED;
expr_ref f2 = remove_factor(f, arg1);
expr* z = m_util.mk_numeral(rational(0), m_util.is_int(arg1));
result = m.mk_or(m_util.mk_eq(f, z), m_util.mk_eq(f2, z));
switch (kind) {
case EQ:
break;
case GE:
result = m.mk_or(m.mk_iff(m_util.mk_ge(f, z), m_util.mk_ge(f2, z)), result);
break;
case LE:
result = m.mk_or(m.mk_not(m.mk_iff(m_util.mk_ge(f, z), m_util.mk_ge(f2, z))), result);
break;
}
return BR_REWRITE3;
}
return BR_FAILED;
}

br_status arith_rewriter::mk_le_ge_eq_core(expr * arg1, expr * arg2, op_kind kind, expr_ref & result) {
expr *orig_arg1 = arg1, *orig_arg2 = arg2;
expr_ref new_arg1(m);
Expand Down Expand Up @@ -655,7 +778,7 @@ br_status arith_rewriter::mk_le_ge_eq_core(expr * arg1, expr * arg2, op_kind kin
default: result = m.mk_eq(arg1, arg2); return BR_DONE;
}
}
return BR_FAILED;
return factor_le_ge_eq(arg1, arg2, kind, result);
}


Expand Down
6 changes: 6 additions & 0 deletions src/ast/rewriter/arith_rewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class arith_rewriter : public poly_rewriter<arith_rewriter_core> {
br_status is_separated(expr * arg1, expr * arg2, op_kind kind, expr_ref & result);
bool is_non_negative(expr* e);
br_status mk_le_ge_eq_core(expr * arg1, expr * arg2, op_kind kind, expr_ref & result);
bool is_add_factor(expr* s, expr* t);
bool is_mul_factor(expr* s, expr* t);
expr* find_nl_factor(expr* t);
void get_nl_muls(expr* t, ptr_buffer<expr>& muls);
expr_ref remove_factor(expr* s, expr* t);
br_status factor_le_ge_eq(expr * arg1, expr * arg2, op_kind kind, expr_ref & result);

bool elim_to_real_var(expr * var, expr_ref & new_var);
bool elim_to_real_mon(expr * monomial, expr_ref & new_monomial);
Expand Down
Loading

0 comments on commit 91dc02d

Please sign in to comment.