Skip to content

Commit 435ea6e

Browse files
ilanashapiroNikolajBjornerhumnrdble
authored
fixed-size min-heap for tracking top-k literals (#7752)
* very basic setup * ensure solve_eqs is fully disabled when smt.solve_eqs=false, #7743 Signed-off-by: Nikolaj Bjorner <[email protected]> * respect smt configuration parameter in elim_unconstrained simplifier Signed-off-by: Nikolaj Bjorner <[email protected]> * indentation * add bash files for test runs * add option to selectively disable variable solving for only ground expressions Signed-off-by: Nikolaj Bjorner <[email protected]> * remove verbose output Signed-off-by: Nikolaj Bjorner <[email protected]> * fix #7745 axioms for len(substr(...)) escaped due to nested rewriting * ensure atomic constraints are processed by arithmetic solver * #7739 optimization add simplification rule for at(x, offset) = "" Introducing j just postpones some rewrites that prevent useful simplifications. Z3 already uses common sub-expressions. The example highlights some opportunities for simplification, noteworthy at(..) = "". The example is solved in both versions after adding this simplification. * fix unsound len(substr) axiom Signed-off-by: Nikolaj Bjorner <[email protected]> * FreshConst is_sort (#7748) * #7750 add pre-processing simplification * Add parameter validation for selected API functions * updates to ac-plugin fix incrementality bugs by allowing destructive updates during saturation at the cost of redoing saturation after a pop. * enable passive, add check for bloom up-to-date * add top-k fixed-sized min-heap priority queue for top scoring literals --------- Signed-off-by: Nikolaj Bjorner <[email protected]> Co-authored-by: Nikolaj Bjorner <[email protected]> Co-authored-by: humnrdble <[email protected]>
1 parent a9b4e35 commit 435ea6e

24 files changed

+738
-279
lines changed

run_local_tests.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
# run from inside ./z3/build
3+
4+
Z3=./z3
5+
OPTIONS="-v:0 -st smt.threads=4"
6+
OUT_FILE="../z3_results.txt"
7+
BASE_PATH="../../z3-poly-testing/inputs/"
8+
9+
# List of relative test files (relative to BASE_PATH)
10+
REL_TEST_FILES=(
11+
"QF_NIA_small/Ton_Chanh_15__Singapore_v1_false-termination.c__p27381_terminationG_0.smt2"
12+
"QF_UFDTLIA_SAT/52759_bec3a2272267494faeecb6bfaf253e3b_10_QF_UFDTLIA.smt2"
13+
)
14+
15+
# Clear output file
16+
> "$OUT_FILE"
17+
18+
# Loop through and run Z3 on each file
19+
for rel_path in "${REL_TEST_FILES[@]}"; do
20+
full_path="$BASE_PATH$rel_path"
21+
test_name="$rel_path"
22+
23+
echo "Running: $test_name"
24+
echo "===== $test_name =====" | tee -a "$OUT_FILE"
25+
26+
# Run Z3 and pipe output to both screen and file
27+
$Z3 "$full_path" $OPTIONS 2>&1 | tee -a "$OUT_FILE"
28+
29+
echo "" | tee -a "$OUT_FILE"
30+
done
31+
32+
echo "Results written to $OUT_FILE"

src/api/api_ast.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,15 @@ extern "C" {
225225
Z3_TRY;
226226
LOG_Z3_mk_fresh_func_decl(c, prefix, domain_size, domain, range);
227227
RESET_ERROR_CODE();
228+
CHECK_IS_SORT(range, nullptr);
229+
CHECK_SORTS(domain_size, domain, nullptr);
228230
if (prefix == nullptr) {
229231
prefix = "";
230232
}
231233

232234
func_decl* d = mk_c(c)->m().mk_fresh_func_decl(prefix,
233235
domain_size,
234-
reinterpret_cast<sort*const*>(domain),
236+
to_sorts(domain),
235237
to_sort(range), false);
236238

237239
mk_c(c)->save_ast_trail(d);
@@ -243,9 +245,11 @@ extern "C" {
243245
Z3_TRY;
244246
LOG_Z3_mk_fresh_const(c, prefix, ty);
245247
RESET_ERROR_CODE();
248+
CHECK_IS_SORT(ty, nullptr);
246249
if (prefix == nullptr) {
247250
prefix = "";
248251
}
252+
249253
app* a = mk_c(c)->m().mk_fresh_const(prefix, to_sort(ty), false);
250254
mk_c(c)->save_ast_trail(a);
251255
RETURN_Z3(of_ast(a));
@@ -654,6 +658,7 @@ extern "C" {
654658
Z3_TRY;
655659
LOG_Z3_get_sort_name(c, t);
656660
RESET_ERROR_CODE();
661+
CHECK_IS_SORT(t, of_symbol(symbol::null));
657662
CHECK_VALID_AST(t, of_symbol(symbol::null));
658663
return of_symbol(to_sort(t)->get_name());
659664
Z3_CATCH_RETURN(of_symbol(symbol::null));

src/api/api_context.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,13 @@ namespace api {
286286
inline api::context * mk_c(Z3_context c) { return reinterpret_cast<api::context*>(c); }
287287
#define RESET_ERROR_CODE() { mk_c(c)->reset_error_code(); }
288288
#define SET_ERROR_CODE(ERR, MSG) { mk_c(c)->set_error_code(ERR, MSG); }
289-
#define CHECK_NON_NULL(_p_,_ret_) { if (_p_ == 0) { SET_ERROR_CODE(Z3_INVALID_ARG, "ast is null"); return _ret_; } }
290-
#define CHECK_VALID_AST(_a_, _ret_) { if (_a_ == 0 || !CHECK_REF_COUNT(_a_)) { SET_ERROR_CODE(Z3_INVALID_ARG, "not a valid ast"); return _ret_; } }
289+
#define CHECK_NON_NULL(_p_,_ret_) { if (_p_ == nullptr) { SET_ERROR_CODE(Z3_INVALID_ARG, "ast is null"); return _ret_; } }
290+
#define CHECK_VALID_AST(_a_, _ret_) { if (_a_ == nullptr || !CHECK_REF_COUNT(_a_)) { SET_ERROR_CODE(Z3_INVALID_ARG, "not a valid ast"); return _ret_; } }
291291
inline bool is_expr(Z3_ast a) { return is_expr(to_ast(a)); }
292-
#define CHECK_IS_EXPR(_p_, _ret_) { if (_p_ == 0 || !is_expr(_p_)) { SET_ERROR_CODE(Z3_INVALID_ARG, "ast is not an expression"); return _ret_; } }
292+
#define CHECK_IS_EXPR(_p_, _ret_) { if (_p_ == nullptr || !is_expr(_p_)) { SET_ERROR_CODE(Z3_INVALID_ARG, "ast is not an expression"); return _ret_; } }
293+
#define CHECK_IS_SORT(_p_, _ret_) { if (_p_ == nullptr || !is_sort(_p_)) { SET_ERROR_CODE(Z3_INVALID_ARG, "ast is not a sort"); return _ret_; } }
294+
#define CHECK_SORTS(_n_, _ps_, _ret_) { for (unsigned i = 0; i < _n_; ++i) if (!is_sort(_ps_[i])) { SET_ERROR_CODE(Z3_INVALID_ARG, "ast is not a sort"); return _ret_; } }
295+
293296
inline bool is_bool_expr(Z3_context c, Z3_ast a) { return is_expr(a) && mk_c(c)->m().is_bool(to_expr(a)); }
294-
#define CHECK_FORMULA(_a_, _ret_) { if (_a_ == 0 || !CHECK_REF_COUNT(_a_) || !is_bool_expr(c, _a_)) { SET_ERROR_CODE(Z3_INVALID_ARG, nullptr); return _ret_; } }
297+
#define CHECK_FORMULA(_a_, _ret_) { if (_a_ == nullptr || !CHECK_REF_COUNT(_a_) || !is_bool_expr(c, _a_)) { SET_ERROR_CODE(Z3_INVALID_ARG, nullptr); return _ret_; } }
295298
inline void check_sorts(Z3_context c, ast * n) { mk_c(c)->check_sorts(n); }

src/api/api_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ inline ast * const * to_asts(Z3_ast const* a) { return reinterpret_cast<ast* con
6767

6868
inline sort * to_sort(Z3_sort a) { return reinterpret_cast<sort*>(a); }
6969
inline Z3_sort of_sort(sort* s) { return reinterpret_cast<Z3_sort>(s); }
70+
inline bool is_sort(Z3_sort a) { return is_sort(to_sort(a)); }
7071

7172
inline sort * const * to_sorts(Z3_sort const* a) { return reinterpret_cast<sort* const*>(a); }
7273
inline Z3_sort const * of_sorts(sort* const* s) { return reinterpret_cast<Z3_sort const*>(s); }

src/api/python/z3/z3.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,8 @@ def Consts(names, sort):
15061506

15071507
def FreshConst(sort, prefix="c"):
15081508
"""Create a fresh constant of a specified sort"""
1509+
if z3_debug():
1510+
_z3_assert(is_sort(sort), f"Z3 sort expected, got {type(sort)}")
15091511
ctx = _get_ctx(sort.ctx)
15101512
return _to_expr_ref(Z3_mk_fresh_const(ctx.ref(), prefix, sort.ast), ctx)
15111513

0 commit comments

Comments
 (0)