3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-06-28 11:28:49 +00:00
Commit graph

5006 commits

Author SHA1 Message Date
CEisenhofer
be627007e1 Use lookahead for regex decomposition
Make snode const
2026-06-11 15:34:25 +02:00
CEisenhofer
671dfedebe Merge branch 'master' into c3 2026-06-11 11:04:51 +02:00
Margus Veanes
513b81253b
Add OP_RE_XOR and union-find bisimulation for ground regex equivalence (#9804)
Implements the algorithm of Eq(p,q) = Empty(p XOR q)' using a union-find
driven bisimulation closure (per the CAV'26 ERE paper).

### What's added

* **New primitive OP_RE_XOR (re.xor)** wired through seq_decl_plugin:
parser signature, info propagation (nullable, min_length), and
pretty-printer.
* **seq_rewriter**: structural XOR rewrites ( XOR r = empty, XOR empty =
r, ull XOR r = comp(r), comp/comp absorption, complement push, AC
normalisation), nullability (Null(p XOR q) = Null(p) != Null(q)),
derivative (D_a(p XOR q) = D_a(p) XOR D_a(q)), reverse, antimirov
derivative, and `check_deriv_normal_form` coverage.
* **New class seq::regex_bisim** in
`src/ast/rewriter/seq_regex_bisim.{h,cpp}` to keep the bisim logic out
of the already-large `seq_rewriter.cpp`. Uses `basic_union_find` from
`util/union_find.h`, an `obj_map` for the node assignment, and a
50000-step bound (returns `l_undef` on overrun).
* **Integration** in `seq_rewriter::reduce_re_eq` (with a re-entry
guard) and in `seq_regex::propagate_eq` / `propagate_ne` for ground
regexes; on `l_undef` we fall back to the existing axiomatisation.
* **`sls_seq_plugin`**: extend `OP_RE_DIFF` switch arms to also cover
`OP_RE_XOR`.

### Validation

* Full release build with MSVC + Ninja.
* `./test-z3 /a` -- 89/89 tests passing.
* `./test-z3 /seq smt2print_parse` -- PASS.
* Smoke tests with `(a|b)*` vs `(a*b*)*` (equal) and `a*` vs `(a|b)*`
(not equal) return the expected `sat`/`unsat` quickly.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-10 14:58:20 -07:00
CEisenhofer
2dbefbcd56 Lookahead for regex splits applied to membership constraints
Rewriting constraint/prefix/suffix with constant strings to regexes
2026-06-10 20:35:36 +02:00
CEisenhofer
f9f16550e0 Fixed propagation rule 2026-06-10 17:55:14 +02:00
CEisenhofer
aec52551c3 Remove duplicates from unions/intersections 2026-06-10 15:58:36 +02:00
CEisenhofer
dbb3f70873 Moved the regex splitting into rewriter
Added some simplifications
2026-06-10 15:00:58 +02:00
CEisenhofer
294ee984b8 Remove cyclic dependency 2026-06-10 13:56:58 +02:00
CEisenhofer
e3b80fc578 Merge branch 'master' into c3 2026-06-10 13:41:31 +02:00
Lev Nachmanson
6eeb274cd2
Fix FPA incremental soundness for fp.to_* terms (#9022) (#9787)
Fixes #9022.

## Problem

After a `(push)`, Z3 could incorrectly report `unsat` for satisfiable
FPA formulas in which an uninterpreted function returns a floating-point
value (e.g. `int_to_fp`). The example in #9022 has a single `push` and a
single `check-sat` (no `pop`), so the `m_rw.reset()` added in
`pop_scope_eh` by #8712 does not apply.

## Root cause

`theory_fpa` lazily converts FP constraints to bit-vectors and asserts
the equivalences/side conditions as **unit theory axioms**
(`assert_cnstr` → `mk_th_axiom`, which `assign`s the literal at the
current decision level).

For `fp.to_*` terms (`fp.to_real`, `fp.to_ubv`, …) the conversion
equality and side conditions are emitted **only** in
`internalize_term()`, which runs exactly once. The `else if` branch for
fpa-family conversion terms in `relevant_eh` previously did nothing.

These unit axioms are level-local: on DPLL backtracking the assignment
is undone, but `internalize_term()` is not re-run for the
already-internalized term (in particular when the term lives at the
user-`push` base level, where its clause is not a reinit clause). The
side conditions include the axioms linking FP uninterpreted functions to
their bit-vector counterparts (`int_to_fp(i) =
fp(extract(int_to_fp_bv(i)))`). Once lost, `int_to_fp_bv` becomes
unconstrained, enabling an unsound `unsat`. This is exactly the behavior
described in #8345/#9022 (and why the result flips with vs. without
`push`).

## Fix

`relevant_eh` re-fires on relevancy re-propagation after a backtrack.
Re-emit the conversion equality and side conditions for `fp.to_*` terms
there, mirroring `internalize_term`, so the FP↔BV linking axioms stay in
force across backtracking. On an `m_conversions` cache hit this just
re-asserts the (hash-consed) conversion equality and a `true` side
condition, so it adds no new terms and no clause bloat. The change only
adds sound constraints, so it can never turn a satisfiable formula
`unsat`.

## Validation

- #9022 reproducer: no longer reports `unsat` across many random seeds
and longer timeouts; a model (`sat`) is still found (the problem is
inherently hard quantified FP + nonlinear arithmetic, so timeouts are
expected).
- #8345 reproducer: first `check-sat` still `unsat` (the negated
quantifier axiom is valid).
- Additional incremental push/pop FP cases with
`fp.to_real`/`fp.add`/`fp.sub` and FP-returning UFs: correct, consistent
results.
- `test-z3 /a`: all 89 unit tests pass.
- Debug build (soundness assertions enabled): no assertion failures on
the above cases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-09 10:22:03 -07:00
CEisenhofer
89a2ac133f Derived by the wrong "leading character" 2026-06-09 16:56:05 +02:00
CEisenhofer
9f44a9cce8 Flatten concat when deciding if it is constant 2026-06-09 16:39:09 +02:00
CEisenhofer
2e4c165a16 Misclassified giving-up on decomposition as conflict 2026-06-09 16:22:41 +02:00
CEisenhofer
8229bcc5fc Conflicts are not reported correctly in eager regex factorization 2026-06-09 16:14:25 +02:00
CEisenhofer
64f422abc5 sigma of full_seq was missing 2026-06-09 15:49:41 +02:00
CEisenhofer
069068ce5e Don't use enodes for justifying disequality conflicts 2026-06-09 15:40:28 +02:00
CEisenhofer
3c39fc4238 Complement 2026-06-09 15:12:50 +02:00
CEisenhofer
9b357373b0 Preprocess away leading characters; otw. we are unsound 2026-06-09 14:44:41 +02:00
Nikolaj Bjorner
1f5132c396 refactor solver to include settable stats 2026-06-07 14:17:38 -07:00
Copilot
206569c0d6
fix: negate offset on swap in seq_offset_eq::find (#9722)
`seq_offset_eq::find` returned the stored offset with the wrong sign
whenever the enode arguments were reordered to match the canonical key
ordering (`r1.id ≤ r2.id`), causing `len_based_split` to silently skip
~50% of eligible length-based splits.

### Root cause

`m_offset_equalities` stores `(rA, rB) → v` meaning `len(rA) − len(rB) =
v` with `rA.id ≤ rB.id`. `len_offset()` correctly negates `val` when
inserting with swapped keys. `find()` performed the same swap for the
lookup but never negated the returned value, so callers received
`len(n2) − len(n1)` instead of `len(n1) − len(n2)`.

### Fix

```cpp
// BEFORE
if (n1->get_owner_id() > n2->get_owner_id())
    std::swap(n1, n2);
if (m_offset_equalities.find(n1, n2, offset))
    return offset;  // wrong sign when swapped

// AFTER
bool swapped = n1->get_owner_id() > n2->get_owner_id();
if (swapped)
    std::swap(n1, n2);
if (m_offset_equalities.find(n1, n2, offset))
    return swapped ? -offset : offset;
```

This makes `find` consistent with the documented contract (`r1 = r2 +
offset`) and symmetric with the insertion logic in `len_offset()`.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-06-06 13:25:16 -07:00
CEisenhofer
7c7ca27822 Sounder? 2026-06-06 15:24:25 +02:00
CEisenhofer
eee5a9dcef A bit of cleanup 2026-06-05 20:26:58 +02:00
CEisenhofer
67906da97a Corrected string extraction 2026-06-05 19:57:00 +02:00
CEisenhofer
8ac7a242eb Z3 arguments got ignored in the Nielsen graph 2026-06-05 19:19:08 +02:00
CEisenhofer
c20bc0e631 First attempt for monadic decomposition 2026-06-05 18:40:36 +02:00
Can Cebeci
14746d7fb6
Update used_enodes properly (#9695)
https://github.com/Z3Prover/z3/pull/9405 made the trace report
used_enodes incorrectly, since the previous code relied on
update_max_generation to maintain the relevant data structure. This
should fix it.

Co-authored-by: Can Cebeci <t-cancebeci@microsoft.com>
2026-06-03 13:36:37 -07:00
CEisenhofer
9de196b3cb Some signatures changed after merging in master 2026-06-03 17:39:09 +02:00
CEisenhofer
043c6c0ad1 Merge branch 'master' into c3 2026-06-03 17:33:26 +02:00
Copilot
d64ce41b2e
Remove unused defined_names artifacts and simplify fingerprint_set::contains (#9702)
Cleans up dead code left by the "remove side definitions" refactoring
(a0a3047).

- **`smt_model_checker.cpp`** — Remove `defined_names dn(m)` variable
that was declared but never used
- **`smt_model_checker.h`** — Drop the now-unnecessary `#include
"ast/normal_forms/defined_names.h"`
- **`fingerprints.cpp`** — Collapse redundant tail in
`fingerprint_set::contains`:
  ```cpp
  // Before
  if (m_set.contains(d))
      return true;
  return false;

  // After
  return m_set.contains(d);
  ```

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-06-03 08:16:46 -07:00
CEisenhofer
e94b6db8e5 Removed assertion to make the build dependencies acyclic 2026-06-03 10:58:25 +02:00
Nikolaj Bjorner
a0a3047e36 remove side definitions 2026-06-02 21:43:55 -07:00
Nikolaj Bjorner
2dbe233f6a fix condition that skipped mbqi
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2026-06-02 10:38:52 -07:00
Nikolaj Bjorner
eaf7562a1d disable test in tptp, move to native lambdas 2026-06-02 10:38:51 -07:00
CEisenhofer
3908016651 Potentially fixed termination problem with projection operators 2026-06-02 17:04:31 +02:00
Copilot
947af23fc4
[code-simplifier] Align choice axiom naming in theory_array_full (#9660)
This simplifies the recent `choice` axiom path in the SMT array solver
for consistency with the SAT-side implementation. The change is purely
structural: align local naming with the quantifier body it represents,
inline a single-use literal, and remove stray whitespace in the array
decl header.

- **Choice axiom cleanup**
- Rename the local implication term in
`theory_array_full::instantiate_choice_axiom` from `ax` to `body`
- Match the naming already used in
`sat/smt/array_axioms.cpp::assert_choice_axiom`

- **Single-use literal inlining**
- Replace the temporary `literal l = mk_literal(q); assert_axiom(l);`
with a direct call
  - Reduce noise without changing behavior

- **Header whitespace cleanup**
  - Remove trailing whitespace in `src/ast/array_decl_plugin.h`

```c++
expr_ref body(m.mk_implies(px, pc), m);
expr_ref q(m.mk_forall(1, &x_sort, &x_name, body), m);
ctx.get_rewriter()(q);
assert_axiom(mk_literal(q));
```

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2026-06-01 16:03:42 -07:00
Can Cebeci
8ddd435835
Fix misleading generation number in trace (#9687)
Current implementation prints 0 when the cached generation is used
2026-06-01 16:00:59 -07:00
Nikolaj Bjorner
d025b34606 prepare for enodes over lambdas 2026-06-01 13:00:35 -07:00
CEisenhofer
5b41c6eb9f Better tracking for debugging 2026-06-01 19:50:34 +02:00
CEisenhofer
2da7c7b3db Cache result of Z3 emptiness checks 2026-06-01 17:53:28 +02:00
CEisenhofer
1637b006c5 Output automaton 2026-06-01 17:29:09 +02:00
Nikolaj Bjorner
24e5a6ae3f ensure base class has propagation
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2026-05-30 22:21:15 -07:00
Nikolaj Bjorner
a595e98707 fix regression: m_tmp_diseq has 0 arguments, you have to access the expression
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2026-05-30 18:57:21 -07:00
Nikolaj Bjorner
dbe986fdf7 move closure conversion to solver internalization
- only the internalizer performs closure conversion
- theory_array treats propagation of lambdas similar to stores
- ho_matcher treats top-level flex patterns as first-order
- pattern-inference fix to handle quantifiers (lambdas) in patterns that are computed
2026-05-30 18:41:37 -07:00
Nikolaj Bjorner
2cc4422018 use expr based access to enodes to allow for storing first-class lambas 2026-05-30 15:13:08 -07:00
Nikolaj Bjorner
30df8e7ece build warnings 2026-05-29 10:17:46 -07:00
CEisenhofer
cebe57dffa Avoid unnecessary regex cycle splits 2026-05-29 19:14:08 +02:00
CEisenhofer
70031b674c Added real projection operator 2026-05-29 15:51:35 +02:00
CEisenhofer
ff99cb442a Unique name for decomposed regex 2026-05-28 18:45:48 +02:00
CEisenhofer
e5d5b493d3 Remove trivial membership constraints also after simplifications 2026-05-28 18:26:50 +02:00
CEisenhofer
7d7199dec6 use expr id when doing model construction and not internal id 2026-05-28 18:02:41 +02:00