mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 09:05:31 +00:00
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 <nbjorner@microsoft.com> * add sls-sms solver * bv updates * updated dependencies Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * updated dependencies Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * use portable ptr-initializer Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * move definitions to cpp Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * use template<> syntax Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fix compiler errors for gcc Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * 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](https://github.com/docker/build-push-action/compare/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] <support@github.com> 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 <nbjorner@microsoft.com> * 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](https://github.com/docker/build-push-action/compare/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] <support@github.com> 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 <levnach@hotmail.com> * remove macro distinction #7270 * fix #7268 * kludge to address #7232, probably superseeded by planned revision to setup/pypi Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * 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](https://github.com/docker/build-push-action/compare/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] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * merge Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fix unit test build Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * remove shared attribute Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * remove stale files Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fix build of unit test Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixes and rename sls-cc to sls-euf-plugin Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * na Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * 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 <nbjorner@microsoft.com> * bug fixes * Update sls_test.cpp * fixes * fixes Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fix build Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * refactor basic plugin and clause generation Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixes to ite and other Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * updates * update Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fix division by 0 Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * disable fail restart Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * disable tabu when using reset moves Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * update sls_test Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * add factoring Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixes to semantics Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * re-add tabu override Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * generalize factoring Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fix bug Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * remove restart Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * disable tabu in fallback modes Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * localize impact of factoring Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * delay factoring Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * flatten products Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * perform lookahead update + nested mul Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * disable nested mul Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * disable nested mul, use non-lookahead Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * make reset updates recursive Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * include linear moves Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * include 5% reset probability Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * separate linear update Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * separate linear update remove 20% threshold Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * remove linear opt Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * enable multiplier expansion, enable linear move Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * use unit coefficients for muls Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * disable non-tabu version of find_nl_moves Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * remove coefficient from multiplication definition Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * reorg monomials Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * add smt params to path Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * avoid negative reward Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * use reward as proxy for score Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * use reward as proxy for score Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * use exponential decay with breaks Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * use std::pow Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixes to bv Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixes to fixed Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixup repairs Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * reserve for multiplication Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixing repair Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * include bounds checks in set random * na * fixes to mul Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fix mul inverse Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixes to handling signed operators Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * logging and fixes Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * gcm Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * peli Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * 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 <nbjorner@microsoft.com> * 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 <nbjorner@microsoft.com> * 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 <nbjorner@microsoft.com> * remove extra file Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * 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 <nbjorner@microsoft.com> * break sls build Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fix build * break build again * fix build Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixes Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixing incremental Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * avoid units Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixup handling of disequality propagation Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fx Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * recover shift-weight loop Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * alternate Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * throttle save model Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * allow for alternating Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fix test for new signature of flip Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * bug fixes Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * restore use of value_hash Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixes Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * adding dt plugin Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * adt Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * dt updates Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * added cycle detection Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * updated sls-datatype Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * Refactor context management, improve datatype handling, and enhance logging in sls plugins. * axiomatize dt Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * add missing factory plugins to model Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixup finite domain search Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixup finite domain search Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixes Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * redo dfs Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixing model construction for underspecified operators Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixes to occurs check Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixup interpretation building Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * saturate worklist Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * delay distinct axiom Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * 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 <nbjorner@microsoft.com> * 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 <nbjorner@microsoft.com> * fix build Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * remove declaration of context Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * add virtual destructor Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * build warnings Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * reorder inclusion order to define smt_context before theory_sls Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * change namespace for single threaded Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * check delayed eqs before nla Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * use independent completion flag for sls to avoid conflating with genuine cancelation * validate sls-arith lemmas Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * bugfixes Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * add intblast to legacy SMT solver * fixup model generation for theory_intblast Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * na Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * mk_value needs to accept more cases where integer expression doesn't evalate Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * use th-axioms to track origins of assertions Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * add missing operator handling for bitwise operators Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * add missing operator handling for bitwise operators Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * normalizing inequality Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * add virtual destructor Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * rework elim_unconstrained * fix non-termination Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * use glue as computed without adjustment * update model generation to fix model bug Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixes to model construction * remove package and package lock Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fix build warning Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * use original gai Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> --------- Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Lev Nachmanson <levnach@hotmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sergey Bronnikov <estetus@gmail.com> Co-authored-by: Lev Nachmanson <levnach@hotmail.com> Co-authored-by: LiviaSun <33578456+ChuyueSun@users.noreply.github.com>
This commit is contained in:
parent
ecdfab81a6
commit
91dc02d862
120 changed files with 11172 additions and 4148 deletions
|
@ -61,11 +61,13 @@ z3_add_component(smt
|
|||
theory_dl.cpp
|
||||
theory_dummy.cpp
|
||||
theory_fpa.cpp
|
||||
theory_intblast.cpp
|
||||
theory_lra.cpp
|
||||
theory_opt.cpp
|
||||
theory_pb.cpp
|
||||
theory_recfun.cpp
|
||||
theory_seq.cpp
|
||||
theory_sls.cpp
|
||||
theory_special_relations.cpp
|
||||
theory_str.cpp
|
||||
theory_str_mc.cpp
|
||||
|
|
|
@ -37,6 +37,7 @@ Revision History:
|
|||
#include "smt/uses_theory.h"
|
||||
#include "smt/theory_special_relations.h"
|
||||
#include "smt/theory_polymorphism.h"
|
||||
#include "smt/theory_sls.h"
|
||||
#include "smt/smt_for_each_relevant_expr.h"
|
||||
#include "smt/smt_model_generator.h"
|
||||
#include "smt/smt_model_checker.h"
|
||||
|
@ -103,6 +104,10 @@ namespace smt {
|
|||
*/
|
||||
|
||||
bool context::get_cancel_flag() {
|
||||
if (l_true == m_sls_completed && !m.limit().suspended()) {
|
||||
m_last_search_failure = CANCELED;
|
||||
return true;
|
||||
}
|
||||
if (m.limit().inc())
|
||||
return false;
|
||||
m_last_search_failure = CANCELED;
|
||||
|
@ -3503,9 +3508,13 @@ namespace smt {
|
|||
m_case_split_queue->display(tout << "case splits\n");
|
||||
);
|
||||
display_profile(verbose_stream());
|
||||
if (r == l_true && get_cancel_flag()) {
|
||||
if (r == l_true && get_cancel_flag())
|
||||
r = l_undef;
|
||||
if (r == l_undef && m_sls_completed == l_true && has_sls_model()) {
|
||||
m_last_search_failure = OK;
|
||||
r = l_true;
|
||||
}
|
||||
m_sls_completed = l_false;
|
||||
if (r == l_true && gparams::get_value("model_validate") == "true") {
|
||||
recfun::util u(m);
|
||||
if (u.get_rec_funs().empty() && m_proto_model) {
|
||||
|
@ -3581,6 +3590,17 @@ namespace smt {
|
|||
return r;
|
||||
}
|
||||
|
||||
bool context::has_sls_model() {
|
||||
if (!m_fparams.m_sls_enable)
|
||||
return false;
|
||||
auto tid = m.get_family_id("sls");
|
||||
auto p = m_theories.get_plugin(tid);
|
||||
if (!p)
|
||||
return false;
|
||||
m_model = dynamic_cast<theory_sls*>(p)->get_model();
|
||||
return m_model.get() != nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Setup the logical context based on the current set of
|
||||
asserted formulas and execute the check command.
|
||||
|
@ -3734,6 +3754,7 @@ namespace smt {
|
|||
m_phase_default = false;
|
||||
m_case_split_queue ->init_search_eh();
|
||||
m_next_progress_sample = 0;
|
||||
m_sls_completed = l_undef;
|
||||
if (m.has_type_vars() && !m_theories.get_plugin(poly_family_id))
|
||||
register_plugin(alloc(theory_polymorphism, *this));
|
||||
TRACE("literal_occ", display_literal_num_occs(tout););
|
||||
|
|
|
@ -128,6 +128,7 @@ namespace smt {
|
|||
class parallel* m_par = nullptr;
|
||||
unsigned m_par_index = 0;
|
||||
bool m_internalizing_assertions = false;
|
||||
lbool m_sls_completed = l_undef;
|
||||
|
||||
|
||||
// -----------------------------------
|
||||
|
@ -288,6 +289,11 @@ namespace smt {
|
|||
|
||||
bool get_cancel_flag();
|
||||
|
||||
void set_sls_completed() {
|
||||
if (m_sls_completed == l_undef)
|
||||
m_sls_completed = l_true;
|
||||
}
|
||||
|
||||
region & get_region() {
|
||||
return m_region;
|
||||
}
|
||||
|
@ -619,6 +625,9 @@ namespace smt {
|
|||
friend class set_var_theory_trail;
|
||||
void set_var_theory(bool_var v, theory_id tid);
|
||||
|
||||
|
||||
bool has_sls_model();
|
||||
|
||||
// -----------------------------------
|
||||
//
|
||||
// Backtracking support
|
||||
|
@ -939,6 +948,8 @@ namespace smt {
|
|||
mk_th_clause(tid, num_lits, lits, num_params, params, CLS_TH_AXIOM);
|
||||
}
|
||||
|
||||
void mk_th_axiom(theory_id tid, literal l1, unsigned num_params = 0, parameter * params = nullptr);
|
||||
|
||||
void mk_th_axiom(theory_id tid, literal l1, literal l2, unsigned num_params = 0, parameter * params = nullptr);
|
||||
|
||||
void mk_th_axiom(theory_id tid, literal l1, literal l2, literal l3, unsigned num_params = 0, parameter * params = nullptr);
|
||||
|
|
|
@ -1562,6 +1562,10 @@ namespace smt {
|
|||
mk_clause(num_lits, lits, js, k);
|
||||
}
|
||||
|
||||
void context::mk_th_axiom(theory_id tid, literal l1, unsigned num_params, parameter * params) {
|
||||
mk_th_axiom(tid, 1, &l1, num_params, params);
|
||||
}
|
||||
|
||||
void context::mk_th_axiom(theory_id tid, literal l1, literal l2, unsigned num_params, parameter * params) {
|
||||
literal ls[2] = { l1, l2 };
|
||||
mk_th_axiom(tid, 2, ls, num_params, params);
|
||||
|
|
|
@ -27,6 +27,7 @@ Revision History:
|
|||
#include "smt/theory_array.h"
|
||||
#include "smt/theory_array_full.h"
|
||||
#include "smt/theory_bv.h"
|
||||
#include "smt/theory_intblast.h"
|
||||
#include "smt/theory_datatype.h"
|
||||
#include "smt/theory_recfun.h"
|
||||
#include "smt/theory_dummy.h"
|
||||
|
@ -35,6 +36,7 @@ Revision History:
|
|||
#include "smt/theory_seq.h"
|
||||
#include "smt/theory_char.h"
|
||||
#include "smt/theory_special_relations.h"
|
||||
#include "smt/theory_sls.h"
|
||||
#include "smt/theory_pb.h"
|
||||
#include "smt/theory_fpa.h"
|
||||
#include "smt/theory_str.h"
|
||||
|
@ -67,6 +69,7 @@ namespace smt {
|
|||
case CFG_AUTO: setup_auto_config(); break;
|
||||
}
|
||||
setup_card();
|
||||
setup_sls();
|
||||
}
|
||||
|
||||
void setup::setup_default() {
|
||||
|
@ -471,12 +474,12 @@ namespace smt {
|
|||
void setup::setup_QF_BV() {
|
||||
TRACE("setup", tout << "qf-bv\n";);
|
||||
m_params.setup_QF_BV();
|
||||
m_context.register_plugin(alloc(smt::theory_bv, m_context));
|
||||
setup_bv();
|
||||
}
|
||||
|
||||
void setup::setup_QF_AUFBV() {
|
||||
m_params.setup_QF_AUFBV();
|
||||
m_context.register_plugin(alloc(smt::theory_bv, m_context));
|
||||
setup_bv();
|
||||
setup_arrays();
|
||||
}
|
||||
|
||||
|
@ -693,7 +696,15 @@ namespace smt {
|
|||
family_id bv_fid = m_manager.mk_family_id("bv");
|
||||
if (m_context.get_theory(bv_fid))
|
||||
return;
|
||||
switch(m_params.m_bv_mode) {
|
||||
switch (m_params.m_bv_solver) {
|
||||
case 2:
|
||||
m_context.register_plugin(alloc(smt::theory_intblast, m_context));
|
||||
setup_lra_arith();
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (m_params.m_bv_mode) {
|
||||
case BS_NO_BV:
|
||||
m_context.register_plugin(alloc(smt::theory_dummy, m_context, bv_fid, "no bit-vector"));
|
||||
break;
|
||||
|
@ -766,6 +777,11 @@ namespace smt {
|
|||
m_context.register_plugin(alloc(theory_pb, m_context));
|
||||
}
|
||||
|
||||
void setup::setup_sls() {
|
||||
if (m_params.m_sls_enable)
|
||||
m_context.register_plugin(alloc(theory_sls, m_context));
|
||||
}
|
||||
|
||||
void setup::setup_fpa() {
|
||||
setup_bv();
|
||||
m_context.register_plugin(alloc(theory_fpa, m_context));
|
||||
|
|
|
@ -103,6 +103,7 @@ namespace smt {
|
|||
void setup_seq();
|
||||
void setup_char();
|
||||
void setup_card();
|
||||
void setup_sls();
|
||||
void setup_i_arith();
|
||||
void setup_mi_arith();
|
||||
void setup_lra_arith();
|
||||
|
|
191
src/smt/theory_intblast.cpp
Normal file
191
src/smt/theory_intblast.cpp
Normal file
|
@ -0,0 +1,191 @@
|
|||
/*++
|
||||
Copyright (c) 2020 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
theory_intblast
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2024-10-27
|
||||
|
||||
--*/
|
||||
|
||||
#include "smt/smt_context.h"
|
||||
#include "smt/theory_intblast.h"
|
||||
#include "smt/smt_model_generator.h"
|
||||
|
||||
namespace smt {
|
||||
|
||||
void theory_intblast::translator_trail::push(push_back_vector<expr_ref_vector> const& c) {
|
||||
ctx.push_trail(c);
|
||||
}
|
||||
void theory_intblast::translator_trail::push(push_back_vector<ptr_vector<app>> const& c) {
|
||||
ctx.push_trail(c);
|
||||
}
|
||||
|
||||
void theory_intblast::translator_trail::push_idx(set_vector_idx_trail<expr_ref_vector> const& c) {
|
||||
ctx.push_trail(c);
|
||||
}
|
||||
|
||||
theory_intblast::theory_intblast(context& ctx):
|
||||
theory(ctx, ctx.get_manager().mk_family_id("bv")),
|
||||
m_trail(ctx),
|
||||
m_translator(m, m_trail),
|
||||
bv(m),
|
||||
a(m)
|
||||
{}
|
||||
|
||||
theory_intblast::~theory_intblast() {}
|
||||
|
||||
final_check_status theory_intblast::final_check_eh() {
|
||||
for (auto e : m_translator.bv2int()) {
|
||||
auto* n = ctx.get_enode(e);
|
||||
auto* r1 = n->get_arg(0)->get_root();
|
||||
for (auto sib : *n) {
|
||||
if (sib == n)
|
||||
continue;
|
||||
if (!bv.is_bv2int(sib->get_expr()))
|
||||
continue;
|
||||
if (sib->get_arg(0)->get_root() == r1)
|
||||
continue;
|
||||
if (bv.get_bv_size(r1->get_expr()) != bv.get_bv_size(sib->get_arg(0)->get_expr()))
|
||||
continue;
|
||||
auto a = mk_eq(n->get_expr(), sib->get_expr(), false);
|
||||
auto b = mk_eq(sib->get_arg(0)->get_expr(), n->get_arg(0)->get_expr(), false);
|
||||
ctx.mark_as_relevant(a);
|
||||
ctx.mark_as_relevant(b);
|
||||
ctx.mk_th_axiom(m_id, ~a, b);
|
||||
return final_check_status::FC_CONTINUE;
|
||||
}
|
||||
}
|
||||
// ensure that int2bv respects values
|
||||
// bv2int(int2bv(x)) = x mod N
|
||||
for (auto e : m_translator.int2bv()) {
|
||||
auto n = ctx.get_enode(e);
|
||||
auto x = n->get_arg(0)->get_expr();
|
||||
auto bv2int = bv.mk_bv2int(e);
|
||||
ctx.internalize(bv2int, false);
|
||||
auto N = rational::power_of_two(bv.get_bv_size(e));
|
||||
auto xModN = a.mk_mod(x, a.mk_int(N));
|
||||
ctx.internalize(xModN, false);
|
||||
auto nBv2int = ctx.get_enode(bv2int);
|
||||
auto nxModN = ctx.get_enode(xModN);
|
||||
if (nBv2int->get_root() != nxModN->get_root()) {
|
||||
auto a = mk_eq(nBv2int->get_expr(), nxModN->get_expr(), false);
|
||||
ctx.mark_as_relevant(a);
|
||||
ctx.mk_th_axiom(m_id, 1, &a);
|
||||
return final_check_status::FC_CONTINUE;
|
||||
}
|
||||
}
|
||||
return final_check_status::FC_DONE;
|
||||
}
|
||||
|
||||
bool theory_intblast::add_bound_axioms() {
|
||||
auto const& vars = m_translator.vars();
|
||||
if (m_vars_qhead == vars.size())
|
||||
return false;
|
||||
ctx.push_trail(value_trail(m_vars_qhead));
|
||||
for (; m_vars_qhead < vars.size(); ++m_vars_qhead) {
|
||||
auto v = vars[m_vars_qhead];
|
||||
auto w = m_translator.translated(v);
|
||||
auto sz = rational::power_of_two(bv.get_bv_size(v->get_sort()));
|
||||
auto lo = mk_literal(a.mk_ge(w, a.mk_int(0)));
|
||||
auto hi = mk_literal(a.mk_le(w, a.mk_int(sz - 1)));
|
||||
ctx.mark_as_relevant(lo);
|
||||
ctx.mark_as_relevant(hi);
|
||||
ctx.mk_th_axiom(m_id, 1, &lo);
|
||||
ctx.mk_th_axiom(m_id, 1, &hi);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool theory_intblast::add_predicate_axioms() {
|
||||
auto const& preds = m_translator.preds();
|
||||
if (m_preds_qhead == preds.size())
|
||||
return false;
|
||||
ctx.push_trail(value_trail(m_preds_qhead));
|
||||
for (; m_preds_qhead < preds.size(); ++m_preds_qhead) {
|
||||
expr* e = preds[m_preds_qhead];
|
||||
expr_ref r(m_translator.translated(e), m);
|
||||
ctx.get_rewriter()(r);
|
||||
auto a = mk_literal(e);
|
||||
auto b = mk_literal(r);
|
||||
ctx.mark_as_relevant(a);
|
||||
ctx.mark_as_relevant(b);
|
||||
ctx.mk_th_axiom(m_id, ~a, b);
|
||||
ctx.mk_th_axiom(m_id, a, ~b);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool theory_intblast::can_propagate() {
|
||||
return m_preds_qhead < m_translator.preds().size() || m_vars_qhead < m_translator.vars().size();
|
||||
}
|
||||
|
||||
void theory_intblast::propagate() {
|
||||
add_bound_axioms();
|
||||
add_predicate_axioms();
|
||||
}
|
||||
|
||||
bool theory_intblast::internalize_atom(app * atom, bool gate_ctx) {
|
||||
return internalize_term(atom);
|
||||
}
|
||||
|
||||
void theory_intblast::apply_sort_cnstr(enode* n, sort* s) {
|
||||
SASSERT(bv.is_bv_sort(s));
|
||||
if (!is_attached_to_var(n)) {
|
||||
m_translator.internalize_bv(n->get_expr());
|
||||
auto v = mk_var(n);
|
||||
ctx.attach_th_var(n, this, v);
|
||||
}
|
||||
}
|
||||
|
||||
bool theory_intblast::internalize_term(app* term) {
|
||||
|
||||
ctx.internalize(term->get_args(), term->get_num_args(), false);
|
||||
m_translator.internalize_bv(term);
|
||||
enode* n;
|
||||
if (!ctx.e_internalized(term))
|
||||
n = ctx.mk_enode(term, false, false, false);
|
||||
else
|
||||
n = ctx.get_enode(term);
|
||||
|
||||
if (!is_attached_to_var(n)) {
|
||||
auto v = mk_var(n);
|
||||
ctx.attach_th_var(n, this, v);
|
||||
}
|
||||
if (m.is_bool(term)) {
|
||||
literal l(ctx.mk_bool_var(term));
|
||||
ctx.set_var_theory(l.var(), get_id());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void theory_intblast::internalize_eq_eh(app * atom, bool_var v) {
|
||||
m_translator.translate_eq(atom);
|
||||
}
|
||||
|
||||
void theory_intblast::init_model(model_generator& mg) {
|
||||
m_factory = alloc(bv_factory, m);
|
||||
mg.register_factory(m_factory);
|
||||
}
|
||||
|
||||
model_value_proc* theory_intblast::mk_value(enode* n, model_generator& mg) {
|
||||
expr* e = n->get_expr();
|
||||
SASSERT(bv.is_bv(e));
|
||||
rational r;
|
||||
expr* ie = nullptr;
|
||||
expr_ref val(m);
|
||||
if (!bv.is_numeral(e, r)) {
|
||||
for (enode* sib : *n) {
|
||||
ie = m_translator.translated(sib->get_expr());
|
||||
if (ctx.e_internalized(ie) && ctx.get_value(ctx.get_enode(ie), val) && a.is_numeral(val, r))
|
||||
break;
|
||||
}
|
||||
}
|
||||
return alloc(expr_wrapper_proc, m_factory->mk_num_value(r, bv.get_bv_size(e)));
|
||||
}
|
||||
|
||||
|
||||
}
|
73
src/smt/theory_intblast.h
Normal file
73
src/smt/theory_intblast.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*++
|
||||
Copyright (c) 2020 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
theory_intblast
|
||||
|
||||
Abstract:
|
||||
|
||||
Intblast version of bit-vector solver
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2024-10-24
|
||||
|
||||
--*/
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "util/rlimit.h"
|
||||
#include "ast/sls/sat_ddfw.h"
|
||||
#include "smt/smt_theory.h"
|
||||
#include "model/model.h"
|
||||
#include "model/numeral_factory.h"
|
||||
#include "ast/rewriter/bv2int_translator.h"
|
||||
|
||||
|
||||
namespace smt {
|
||||
|
||||
class theory_intblast : public theory {
|
||||
|
||||
class translator_trail : public bv2int_translator_trail {
|
||||
context& ctx;
|
||||
public:
|
||||
translator_trail(context& ctx):ctx(ctx) {}
|
||||
void push(push_back_vector<expr_ref_vector> const& c) override;
|
||||
void push(push_back_vector<ptr_vector<app>> const& c) override;
|
||||
void push_idx(set_vector_idx_trail<expr_ref_vector> const& c) override;
|
||||
};
|
||||
|
||||
translator_trail m_trail;
|
||||
bv2int_translator m_translator;
|
||||
bv_util bv;
|
||||
arith_util a;
|
||||
unsigned m_vars_qhead = 0, m_preds_qhead = 0;
|
||||
bv_factory * m_factory = nullptr;
|
||||
|
||||
bool add_bound_axioms();
|
||||
bool add_predicate_axioms();
|
||||
|
||||
public:
|
||||
theory_intblast(context& ctx);
|
||||
~theory_intblast() override;
|
||||
|
||||
char const* get_name() const override { return "bv-intblast"; }
|
||||
smt::theory* mk_fresh(context* new_ctx) override { return alloc(theory_intblast, *new_ctx); }
|
||||
final_check_status final_check_eh() override;
|
||||
void display(std::ostream& out) const override {}
|
||||
bool can_propagate() override;
|
||||
void propagate() override;
|
||||
bool internalize_atom(app * atom, bool gate_ctx) override;
|
||||
bool internalize_term(app* term) override;
|
||||
void internalize_eq_eh(app * atom, bool_var v) override;
|
||||
void apply_sort_cnstr(enode* n, sort* s) override;
|
||||
void init_model(model_generator& m) override;
|
||||
model_value_proc* mk_value(enode* n, model_generator& m) override;
|
||||
void new_eq_eh(theory_var v1, theory_var v2) override {}
|
||||
void new_diseq_eh(theory_var v1, theory_var v2) override {}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -154,6 +154,7 @@ class theory_lra::imp {
|
|||
svector<delayed_atom> m_asserted_atoms;
|
||||
ptr_vector<expr> m_not_handled;
|
||||
ptr_vector<app> m_underspecified;
|
||||
ptr_vector<app> m_bv_terms;
|
||||
vector<ptr_vector<api_bound> > m_use_list; // bounds where variables are used.
|
||||
|
||||
// attributes for incremental version:
|
||||
|
@ -470,6 +471,13 @@ class theory_lra::imp {
|
|||
st.to_ensure_var().push_back(n1);
|
||||
st.to_ensure_var().push_back(n2);
|
||||
}
|
||||
else if (a.is_band(n) || a.is_shl(n) || a.is_ashr(n) || a.is_lshr(n)) {
|
||||
m_bv_terms.push_back(to_app(n));
|
||||
ctx().push_trail(push_back_vector(m_bv_terms));
|
||||
mk_bv_axiom(to_app(n));
|
||||
for (expr* arg : *to_app(n))
|
||||
st.to_ensure_var().push_back(arg);
|
||||
}
|
||||
else if (!a.is_div0(n)) {
|
||||
found_unsupported(n);
|
||||
}
|
||||
|
@ -1611,6 +1619,7 @@ public:
|
|||
if (!lp().is_feasible() || lp().has_changed_columns())
|
||||
is_sat = make_feasible();
|
||||
final_check_status st = FC_DONE;
|
||||
bool int_undef = false;
|
||||
switch (is_sat) {
|
||||
case l_true:
|
||||
TRACE("arith", display(tout));
|
||||
|
@ -1621,6 +1630,7 @@ public:
|
|||
case FC_CONTINUE:
|
||||
return FC_CONTINUE;
|
||||
case FC_GIVEUP:
|
||||
int_undef = true;
|
||||
TRACE("arith", tout << "check-lia giveup\n";);
|
||||
if (ctx().get_fparams().m_arith_ignore_int)
|
||||
st = FC_CONTINUE;
|
||||
|
@ -1642,6 +1652,9 @@ public:
|
|||
++m_stats.m_assume_eqs;
|
||||
return FC_CONTINUE;
|
||||
}
|
||||
|
||||
if (!int_undef && !check_bv_terms())
|
||||
return FC_CONTINUE;
|
||||
|
||||
for (expr* e : m_not_handled) {
|
||||
if (!ctx().is_relevant(e))
|
||||
|
@ -2442,6 +2455,180 @@ public:
|
|||
return null_literal;
|
||||
}
|
||||
|
||||
bool check_bv_terms() {
|
||||
for (app* n : m_bv_terms) {
|
||||
if (!check_bv_term(n)) {
|
||||
++m_stats.m_bv_axioms;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool check_bv_term(app* n) {
|
||||
unsigned sz = 0;
|
||||
expr* _x = nullptr, * _y = nullptr;
|
||||
if (!ctx().is_relevant(ctx().get_enode(n)))
|
||||
return true;
|
||||
expr_ref vx(m), vy(m),vn(m);
|
||||
rational valn, valx, valy;
|
||||
bool is_int;
|
||||
VERIFY(a.is_band(n, sz, _x, _y) || a.is_shl(n, sz, _x, _y) || a.is_ashr(n, sz, _x, _y) || a.is_lshr(n, sz, _x, _y));
|
||||
if (!get_value(ctx().get_enode(_x), vx) || !get_value(ctx().get_enode(_y), vy) || !get_value(ctx().get_enode(n), vn)) {
|
||||
IF_VERBOSE(2, verbose_stream() << "could not get value of " << mk_pp(n, m) << "\n");
|
||||
found_unsupported(n);
|
||||
return true;
|
||||
}
|
||||
if (!a.is_numeral(vn, valn, is_int) || !is_int || !a.is_numeral(vx, valx, is_int) || !is_int || !a.is_numeral(vy, valy, is_int) || !is_int) {
|
||||
IF_VERBOSE(2, verbose_stream() << "could not get value of " << mk_pp(n, m) << "\n");
|
||||
found_unsupported(n);
|
||||
return true;
|
||||
}
|
||||
rational N = rational::power_of_two(sz);
|
||||
valx = mod(valx, N);
|
||||
valy = mod(valy, N);
|
||||
expr_ref x(a.mk_mod(_x, a.mk_int(N)), m);
|
||||
expr_ref y(a.mk_mod(_y, a.mk_int(N)), m);
|
||||
SASSERT(0 <= valn && valn < N);
|
||||
|
||||
// x mod 2^{i + 1} >= 2^i means the i'th bit is 1.
|
||||
auto bitof = [&](expr* x, unsigned i) {
|
||||
expr_ref r(m);
|
||||
r = a.mk_ge(a.mk_mod(x, a.mk_int(rational::power_of_two(i+1))), a.mk_int(rational::power_of_two(i)));
|
||||
return mk_literal(r);
|
||||
};
|
||||
|
||||
if (a.is_band(n)) {
|
||||
IF_VERBOSE(2, verbose_stream() << "band: " << mk_bounded_pp(n, m) << " " << valn << " := " << valx << "&" << valy << "\n");
|
||||
for (unsigned i = 0; i < sz; ++i) {
|
||||
bool xb = valx.get_bit(i);
|
||||
bool yb = valy.get_bit(i);
|
||||
bool nb = valn.get_bit(i);
|
||||
if (xb && yb && !nb)
|
||||
ctx().mk_th_axiom(get_id(), ~bitof(x, i), ~bitof(y, i), bitof(n, i));
|
||||
else if (nb && !xb)
|
||||
ctx().mk_th_axiom(get_id(), ~bitof(n, i), bitof(x, i));
|
||||
else if (nb && !yb)
|
||||
ctx().mk_th_axiom(get_id(), ~bitof(n, i), bitof(y, i));
|
||||
else
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (a.is_shl(n)) {
|
||||
SASSERT(valy >= 0);
|
||||
if (valy >= sz || valy == 0)
|
||||
return true;
|
||||
unsigned k = valy.get_unsigned();
|
||||
sat::literal eq = th.mk_eq(n, a.mk_mod(a.mk_mul(_x, a.mk_int(rational::power_of_two(k))), a.mk_int(N)), false);
|
||||
if (ctx().get_assignment(eq) == l_true)
|
||||
return true;
|
||||
ctx().mk_th_axiom(get_id(), ~th.mk_eq(y, a.mk_int(k), false), eq);
|
||||
IF_VERBOSE(2, verbose_stream() << "shl: " << mk_bounded_pp(n, m) << " " << valn << " := " << valx << " << " << valy << "\n");
|
||||
return false;
|
||||
}
|
||||
if (a.is_lshr(n)) {
|
||||
SASSERT(valy >= 0);
|
||||
if (valy >= sz || valy == 0)
|
||||
return true;
|
||||
unsigned k = valy.get_unsigned();
|
||||
sat::literal eq = th.mk_eq(n, a.mk_idiv(x, a.mk_int(rational::power_of_two(k))), false);
|
||||
if (ctx().get_assignment(eq) == l_true)
|
||||
return true;
|
||||
ctx().mk_th_axiom(get_id(), ~th.mk_eq(y, a.mk_int(k), false), eq);
|
||||
IF_VERBOSE(2, verbose_stream() << "lshr: " << mk_bounded_pp(n, m) << " " << valn << " := " << valx << " >>l " << valy << "\n");
|
||||
return false;
|
||||
}
|
||||
if (a.is_ashr(n)) {
|
||||
SASSERT(valy >= 0);
|
||||
if (valy >= sz || valy == 0)
|
||||
return true;
|
||||
unsigned k = valy.get_unsigned();
|
||||
sat::literal signx = mk_literal(a.mk_ge(x, a.mk_int(N/2)));
|
||||
sat::literal eq;
|
||||
expr* xdiv2k;
|
||||
switch (ctx().get_assignment(signx)) {
|
||||
case l_true:
|
||||
// x < 0 & y = k -> n = (x div 2^k - 2^{N-k}) mod 2^N
|
||||
xdiv2k = a.mk_idiv(x, a.mk_int(rational::power_of_two(k)));
|
||||
eq = th.mk_eq(n, a.mk_mod(a.mk_add(xdiv2k, a.mk_int(-rational::power_of_two(sz - k))), a.mk_int(N)), false);
|
||||
if (ctx().get_assignment(eq) == l_true)
|
||||
return true;
|
||||
break;
|
||||
case l_false:
|
||||
// x >= 0 & y = k -> n = x div 2^k
|
||||
xdiv2k = a.mk_idiv(x, a.mk_int(rational::power_of_two(k)));
|
||||
eq = th.mk_eq(n, xdiv2k, false);
|
||||
if (ctx().get_assignment(eq) == l_true)
|
||||
return true;
|
||||
break;
|
||||
case l_undef:
|
||||
ctx().mark_as_relevant(signx);
|
||||
return false;
|
||||
}
|
||||
ctx().mk_th_axiom(get_id(), ~th.mk_eq(y, a.mk_int(k), false), ~signx, eq);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
expr_ref mk_le(expr* x, expr* y) {
|
||||
if (a.is_numeral(y))
|
||||
return expr_ref(a.mk_le(x, y), m);
|
||||
if (a.is_numeral(x))
|
||||
return expr_ref(a.mk_ge(y, x), m);
|
||||
return expr_ref(a.mk_le(a.mk_sub(x, y), a.mk_numeral(rational(0), x->get_sort())), m);
|
||||
}
|
||||
|
||||
void mk_bv_axiom(app* n) {
|
||||
unsigned sz = 0;
|
||||
expr* _x = nullptr, * _y = nullptr;
|
||||
VERIFY(a.is_band(n, sz, _x, _y) || a.is_shl(n, sz, _x, _y) || a.is_ashr(n, sz, _x, _y) || a.is_lshr(n, sz, _x, _y));
|
||||
rational N = rational::power_of_two(sz);
|
||||
expr_ref x(a.mk_mod(_x, a.mk_int(N)), m);
|
||||
expr_ref y(a.mk_mod(_y, a.mk_int(N)), m);
|
||||
|
||||
// 0 <= n < 2^sz
|
||||
|
||||
ctx().mk_th_axiom(get_id(), mk_literal(a.mk_ge(n, a.mk_int(0))));
|
||||
ctx().mk_th_axiom(get_id(), mk_literal(a.mk_le(n, a.mk_int(N - 1))));
|
||||
|
||||
if (a.is_band(n)) {
|
||||
|
||||
// x&y <= x
|
||||
// x&y <= y
|
||||
// TODO? x = y => x&y = x
|
||||
|
||||
ctx().mk_th_axiom(get_id(), mk_literal(mk_le(n, x)));
|
||||
ctx().mk_th_axiom(get_id(), mk_literal(mk_le(n, y)));
|
||||
}
|
||||
else if (a.is_shl(n)) {
|
||||
// y >= sz => n = 0
|
||||
// y = 0 => n = x
|
||||
ctx().mk_th_axiom(get_id(), ~mk_literal(a.mk_ge(y, a.mk_int(sz))), mk_literal(m.mk_eq(n, a.mk_int(0))));
|
||||
ctx().mk_th_axiom(get_id(), ~mk_literal(a.mk_eq(y, a.mk_int(0))), mk_literal(m.mk_eq(n, x)));
|
||||
}
|
||||
else if (a.is_lshr(n)) {
|
||||
// y >= sz => n = 0
|
||||
// y = 0 => n = x
|
||||
ctx().mk_th_axiom(get_id(), ~mk_literal(a.mk_ge(y, a.mk_int(sz))), mk_literal(m.mk_eq(n, a.mk_int(0))));
|
||||
ctx().mk_th_axiom(get_id(), ~mk_literal(a.mk_eq(y, a.mk_int(0))), mk_literal(m.mk_eq(n, x)));
|
||||
}
|
||||
else if (a.is_ashr(n)) {
|
||||
// y >= sz & x < 2^{sz-1} => n = 0
|
||||
// y >= sz & x >= 2^{sz-1} => n = -1
|
||||
// y = 0 => n = x
|
||||
auto signx = mk_literal(a.mk_ge(x, a.mk_int(N/2)));
|
||||
ctx().mk_th_axiom(get_id(), ~mk_literal(a.mk_ge(a.mk_mod(y, a.mk_int(N)), a.mk_int(sz))), signx, mk_literal(m.mk_eq(n, a.mk_int(0))));
|
||||
ctx().mk_th_axiom(get_id(), ~mk_literal(a.mk_ge(a.mk_mod(y, a.mk_int(N)), a.mk_int(sz))), ~signx, mk_literal(m.mk_eq(n, a.mk_int(N-1))));
|
||||
ctx().mk_th_axiom(get_id(), ~mk_literal(a.mk_eq(a.mk_mod(y, a.mk_int(N)), a.mk_int(0))), mk_literal(m.mk_eq(n, x)));
|
||||
}
|
||||
else
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
|
||||
void mk_bound_axioms(api_bound& b) {
|
||||
if (!ctx().is_searching()) {
|
||||
//
|
||||
|
@ -3254,7 +3441,7 @@ public:
|
|||
tout << "@" << ctx().get_scope_level() << (is_conflict ? " conflict":" lemma");
|
||||
for (auto const& p : m_params) tout << " " << p;
|
||||
tout << "\n";
|
||||
display_evidence(tout, m_explanation););
|
||||
display_evidence(tout << core << " ", m_explanation););
|
||||
for (auto ev : m_explanation)
|
||||
set_evidence(ev.ci(), m_core, m_eqs);
|
||||
|
||||
|
@ -3276,6 +3463,8 @@ public:
|
|||
for (literal & c : m_core) {
|
||||
c.neg();
|
||||
ctx().mark_as_relevant(c);
|
||||
if (ctx().get_assignment(c) == l_true)
|
||||
return;
|
||||
}
|
||||
TRACE("arith", ctx().display_literals_verbose(tout, m_core) << "\n";);
|
||||
ctx().mk_th_axiom(get_id(), m_core.size(), m_core.data());
|
||||
|
|
133
src/smt/theory_sls.cpp
Normal file
133
src/smt/theory_sls.cpp
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*++
|
||||
Copyright (c) 2020 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
theory_sls
|
||||
|
||||
Abstract:
|
||||
|
||||
Interface to Concurrent SLS solver
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2024-10-24
|
||||
|
||||
--*/
|
||||
|
||||
|
||||
#include "smt/smt_context.h"
|
||||
#include "ast/sls/sls_context.h"
|
||||
#include "ast/for_each_expr.h"
|
||||
#include "smt/theory_sls.h"
|
||||
|
||||
namespace smt {
|
||||
|
||||
theory_sls::theory_sls(smt::context& ctx) :
|
||||
theory(ctx, ctx.get_manager().mk_family_id("sls"))
|
||||
{}
|
||||
|
||||
#ifndef SINGLE_THREAD
|
||||
|
||||
theory_sls::~theory_sls() {
|
||||
finalize();
|
||||
}
|
||||
|
||||
params_ref theory_sls::get_params() {
|
||||
return ctx.get_params();
|
||||
}
|
||||
|
||||
void theory_sls::initialize_value(expr* t, expr* v) {
|
||||
//ctx.user_propagate_initialize_value(t, v);
|
||||
}
|
||||
|
||||
void theory_sls::force_phase(sat::literal lit) {
|
||||
//
|
||||
// ctx.force_phase(lit);
|
||||
}
|
||||
|
||||
void theory_sls::set_has_new_best_phase(bool b) {
|
||||
|
||||
}
|
||||
|
||||
bool theory_sls::get_best_phase(sat::bool_var v) {
|
||||
return false;
|
||||
}
|
||||
|
||||
expr* theory_sls::bool_var2expr(sat::bool_var v) {
|
||||
return ctx.bool_var2expr(v);
|
||||
}
|
||||
|
||||
void theory_sls::set_finished() {
|
||||
ctx.set_sls_completed();
|
||||
}
|
||||
|
||||
unsigned theory_sls::get_num_bool_vars() const {
|
||||
return ctx.get_num_bool_vars();
|
||||
}
|
||||
|
||||
void theory_sls::finalize() {
|
||||
if (!m_smt_plugin)
|
||||
return;
|
||||
|
||||
m_smt_plugin->finalize(m_model, m_st);
|
||||
m_model = nullptr;
|
||||
m_smt_plugin = nullptr;
|
||||
}
|
||||
|
||||
void theory_sls::propagate() {
|
||||
if (m_smt_plugin && !m_checking) {
|
||||
expr_ref_vector fmls(m);
|
||||
for (unsigned i = 0; i < ctx.get_num_asserted_formulas(); ++i)
|
||||
fmls.push_back(ctx.get_asserted_formula(i));
|
||||
m_checking = true;
|
||||
vector<sat::literal_vector> clauses;
|
||||
m_smt_plugin->check(fmls, clauses);
|
||||
return;
|
||||
}
|
||||
if (!m_smt_plugin)
|
||||
return;
|
||||
if (!m_smt_plugin->completed())
|
||||
return;
|
||||
m_smt_plugin->finalize(m_model, m_st);
|
||||
m_smt_plugin = nullptr;
|
||||
}
|
||||
|
||||
void theory_sls::pop_scope_eh(unsigned n) {
|
||||
if (!m_smt_plugin)
|
||||
return;
|
||||
|
||||
unsigned scope_lvl = ctx.get_scope_level();
|
||||
if (ctx.get_search_level() == scope_lvl - n) {
|
||||
auto& lits = ctx.assigned_literals();
|
||||
for (; m_trail_lim < lits.size() && ctx.get_assign_level(lits[m_trail_lim]) == scope_lvl; ++m_trail_lim)
|
||||
m_smt_plugin->add_unit(lits[m_trail_lim]);
|
||||
}
|
||||
#if 0
|
||||
if (ctx.has_new_best_phase())
|
||||
m_smt_plugin->import_phase_from_smt();
|
||||
|
||||
#endif
|
||||
|
||||
// m_smt_plugin->import_from_sls();
|
||||
}
|
||||
|
||||
void theory_sls::init() {
|
||||
if (m_smt_plugin)
|
||||
finalize();
|
||||
m_smt_plugin = alloc(sls::smt_plugin, *this);
|
||||
m_checking = false;
|
||||
}
|
||||
|
||||
void theory_sls::collect_statistics(::statistics& st) const {
|
||||
st.copy(m_st);
|
||||
}
|
||||
|
||||
void theory_sls::display(std::ostream& out) const {
|
||||
out << "theory-sls\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
}
|
93
src/smt/theory_sls.h
Normal file
93
src/smt/theory_sls.h
Normal file
|
@ -0,0 +1,93 @@
|
|||
/*++
|
||||
Copyright (c) 2020 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
theory_sls
|
||||
|
||||
Abstract:
|
||||
|
||||
Interface to Concurrent SLS solver
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2024-10-24
|
||||
|
||||
--*/
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "util/rlimit.h"
|
||||
#include "ast/sls/sat_ddfw.h"
|
||||
#include "smt/smt_theory.h"
|
||||
#include "model/model.h"
|
||||
|
||||
|
||||
#ifdef SINGLE_THREAD
|
||||
|
||||
namespace smt {
|
||||
class theory_sls : public theory {
|
||||
model_ref m_model;
|
||||
public:
|
||||
theory_sls(context& ctx);
|
||||
~theory_sls() override {}
|
||||
model_ref get_model() { return m_model; }
|
||||
char const* get_name() const override { return "sls"; }
|
||||
smt::theory* mk_fresh(context* new_ctx) override { return alloc(theory_sls, *new_ctx); }
|
||||
void display(std::ostream& out) const override {}
|
||||
bool internalize_atom(app* atom, bool gate_ctx) override { return false; }
|
||||
bool internalize_term(app* term) override { return false; }
|
||||
void new_eq_eh(theory_var v1, theory_var v2) override {}
|
||||
void new_diseq_eh(theory_var v1, theory_var v2) override {}
|
||||
};
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include "ast/sls/sls_smt_plugin.h"
|
||||
|
||||
|
||||
namespace smt {
|
||||
|
||||
class theory_sls : public theory, public sls::smt_context {
|
||||
model_ref m_model;
|
||||
sls::smt_plugin* m_smt_plugin = nullptr;
|
||||
unsigned m_trail_lim = 0;
|
||||
bool m_checking = false;
|
||||
::statistics m_st;
|
||||
|
||||
void finalize();
|
||||
|
||||
public:
|
||||
theory_sls(context& ctx);
|
||||
~theory_sls() override;
|
||||
model_ref get_model() { return m_model; }
|
||||
|
||||
// smt::theory interface
|
||||
char const* get_name() const override { return "sls"; }
|
||||
void init() override;
|
||||
void pop_scope_eh(unsigned n) override;
|
||||
smt::theory* mk_fresh(context* new_ctx) override { return alloc(theory_sls, *new_ctx); }
|
||||
void collect_statistics(::statistics& st) const override;
|
||||
void propagate() override;
|
||||
void display(std::ostream& out) const override;
|
||||
bool internalize_atom(app * atom, bool gate_ctx) override { return false; }
|
||||
bool internalize_term(app* term) override { return false; }
|
||||
void new_eq_eh(theory_var v1, theory_var v2) override {}
|
||||
void new_diseq_eh(theory_var v1, theory_var v2) override {}
|
||||
|
||||
// sls::smt_context interface
|
||||
ast_manager& get_manager() override { return m; }
|
||||
params_ref get_params() override;
|
||||
void initialize_value(expr* t, expr* v) override;
|
||||
void force_phase(sat::literal lit) override;
|
||||
void set_has_new_best_phase(bool b) override;
|
||||
bool get_best_phase(sat::bool_var v) override;
|
||||
expr* bool_var2expr(sat::bool_var v) override;
|
||||
void set_finished() override;
|
||||
unsigned get_num_bool_vars() const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue