3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-06-10 19:07:18 +00:00
z3/src/ast/rewriter
Copilot f0956a622f
Refactor regex subset logic into seq_subset with depth-bounded recursion and optimized concat traversal (#9777)
`seq_rewriter::is_subset` was too localized and missed key subset
implications for regex concatenations. This change extracts subset
reasoning into a dedicated component and adds heuristic
closure/monotonicity rules, then tunes the recursion strategy based on
profiling feedback.

- **Architecture: isolate subset reasoning**
  - Introduce `seq_subset` in `src/ast/rewriter` (`seq_subset.h/.cpp`).
- Add `seq_subset` as an attribute on `seq_rewriter` and route
`seq_rewriter::is_subset` through it.
- Keep `seq_rewriter` focused on rewrite orchestration while subset
logic evolves independently.

- **Subset rules: broaden inferable cases**
- Add derive-style subset decomposition across `union`, `intersection`,
`complement`, `concat`, and bounded `loop`.
  - Add E3-style closure rules:
    - `R ⊆ R*`
    - `R1* ⊆ R2*  ⇐  R1 ⊆ R2`
    - `R1+ ⊆ R2+  ⇐  R1 ⊆ R2`
  - Add missing cheap cases:
    - `ε ⊆ R` when `R` is nullable
    - `R ⊆ R+`
    - `R+ ⊆ R*`
    - Range containment: `[c1–c2] ⊆ [c3–c4]` when `c3 ≤ c1 ∧ c2 ≤ c4`
    - `to_re(s) ⊆ range` for single-character string constants
    - Difference monotonicity: `a1 \ a2 ⊆ b` when `a1 ⊆ b`
- Star absorption checks for concat/star combinations (`R·R* ⊆ R*`,
`R*·R ⊆ R*`)
- Preserve nullable-based `. +` handling and top/bottom regular-language
shortcuts.

- **Concatenation reasoning and traversal tuning**
- Remove `flatten_concat` and assume right-associative concatenation
traversal.
- Keep containment shortcuts for both `R ⊆ Σ*·R'` and `R ⊆ R'·Σ*` when
`R ⊆ R'`.
  - Make concat/concat handling tail-recursive on second arguments.

- **Depth-bounded recursion (profiling follow-up)**
- Replace visited-pair hash-table recursion state with an explicit depth
parameter in `is_subset_rec`.
  - Add `m_max_depth = 3` and return `false` when the bound is reached.
- Increment depth on recursive calls, except for the tail-recursive
concat-second-argument step.

- **Build integration**
  - Register `seq_subset.cpp` in `src/ast/rewriter/CMakeLists.txt`.

```cpp
// seq_rewriter.cpp
bool seq_rewriter::is_subset(expr* r1, expr* r2) const {
    return m_subset.is_subset(r1, r2);
}
```

---------

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2026-06-09 13:42:28 -07:00
..
bit_blaster Standardize for-loop increments to prefix form (++i) (#8199) 2026-02-18 20:57:29 -08:00
arith_rewriter.cpp Fix #7507: simplify (>= product_of_consecutive_ints 0) to true 2026-02-27 06:37:07 -10:00
arith_rewriter.h Refactor arith_rewriter::find_nl_factor() to use std::optional (#8313) 2026-02-18 20:57:53 -08:00
array_rewriter.cpp Fix unsound array equality rewrite for const-array store chains (#9572) 2026-05-21 11:15:42 -07:00
array_rewriter.h split into separate function 2023-01-08 19:16:46 -08:00
ast_counter.cpp Refactor counter::get_max_positive to use std::optional (#8289) 2026-02-18 20:57:52 -08:00
ast_counter.h Refactor counter::get_max_positive to use std::optional (#8289) 2026-02-18 20:57:52 -08:00
bit2int.cpp Fix static analysis findings: uninitialized vars, bitwise shift UB, garbage values 2026-03-02 00:13:55 +00:00
bit2int.h Convert internal class enums to enum class for type safety (#8158) 2026-02-18 20:57:09 -08:00
bool_rewriter.cpp Standardize for-loop increments to prefix form (++i) (#8199) 2026-02-18 20:57:29 -08:00
bool_rewriter.h Refactor mk_and and mk_app to use std::span API (#8285) 2026-02-18 20:57:52 -08:00
bv2int_translator.cpp Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
bv2int_translator.h Replace empty destructors with = default for compiler optimization (#8189) 2026-02-18 20:57:12 -08:00
bv_bounds.cpp Refactor mk_and/mk_or call sites to use vector overloads (#8286) 2026-02-18 20:57:52 -08:00
bv_bounds.h
bv_bounds_base.h Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
bv_elim.cpp Standardize for-loop increments to prefix form (++i) (#8199) 2026-02-18 20:57:29 -08:00
bv_elim.h
bv_rewriter.cpp Refactor mk_concat call sites to use std::initializer_list (#8494) 2026-02-18 20:58:03 -08:00
bv_rewriter.h fix #7572 and fix #7574 2025-03-07 10:46:29 -08:00
cached_var_subst.cpp Standardize for-loop increments to prefix form (++i) (#8199) 2026-02-18 20:57:29 -08:00
cached_var_subst.h Migrate codebase to std::string_view (except z3++.h) (#8266) 2026-02-18 20:57:50 -08:00
char_rewriter.cpp rewrites for characters 2022-07-02 11:37:21 -07:00
char_rewriter.h rewrites for characters 2022-07-02 11:37:21 -07:00
CMakeLists.txt Refactor regex subset logic into seq_subset with depth-bounded recursion and optimized concat traversal (#9777) 2026-06-09 13:42:28 -07:00
datatype_rewriter.cpp Refactor mk_and and mk_app to use std::span API (#8285) 2026-02-18 20:57:52 -08:00
datatype_rewriter.h
der.cpp Refactor der.cpp topological sort to use structured bindings (#8401) 2026-02-18 20:57:59 -08:00
der.h add destructive equality resolution to existentials 2022-11-19 18:43:46 +07:00
distribute_forall.cpp Standardize for-loop increments to prefix form (++i) (#8199) 2026-02-18 20:57:29 -08:00
distribute_forall.h
dl_rewriter.cpp
dl_rewriter.h
dom_simplifier.cpp Refactor mk_and and mk_app to use std::span API (#8285) 2026-02-18 20:57:52 -08:00
dom_simplifier.h move dominator simplifier functionality to rewriter and simplifier, move bv_bounds simplifier functionality to simplifier 2023-01-27 17:11:48 -08:00
elim_bounds.cpp Refactor mk_and/mk_or call sites to use vector overloads (#8286) 2026-02-18 20:57:52 -08:00
elim_bounds.h Remove empty leaf destructors. (#6211) 2022-07-30 10:07:03 +01:00
enum2bv_rewriter.cpp build warnings 2026-05-29 10:17:46 -07:00
enum2bv_rewriter.h
expr_replacer.cpp set up model reconstruction trail 2022-11-04 11:25:39 -07:00
expr_replacer.h fixing build, wip on model reconstruction integration into dependent-expr-state 2022-11-04 14:04:44 -07:00
expr_safe_replace.cpp Optimize expr_safe_replace for quantifiers when all source patterns are vars (#7481) 2024-12-19 23:05:13 +01:00
expr_safe_replace.h add bv-size reduce #6137 2022-08-16 16:35:14 -07:00
factor_equivs.cpp Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
factor_equivs.h fix warning with iterators due to non-const comparator 2024-09-23 08:10:56 +01:00
factor_rewriter.cpp Refactor mk_and and mk_app to use std::span API (#8285) 2026-02-18 20:57:52 -08:00
factor_rewriter.h
finite_set_axioms.cpp fix bug reported by Maria Novoszel 2026-02-27 12:02:55 -08:00
finite_set_axioms.h remove incorrect assertion, make sat case for range + size conservative 2025-12-06 13:07:14 -08:00
finite_set_rewriter.cpp fix empty set declaration, add axioms and rewrites 2025-10-27 18:18:46 +01:00
finite_set_rewriter.h add finite sets to datatype recursion, delay initialize finite_set plugin, fix bugs in are_distinct and equality simplification 2025-10-27 10:37:19 +01:00
fpa_rewriter.cpp Refactor mk_concat call sites to use std::initializer_list (#8494) 2026-02-18 20:58:03 -08:00
fpa_rewriter.h remove a few trivial destructors so they get inlined 2021-04-04 17:13:59 +01:00
func_decl_replace.cpp fix #5827 #5828 2022-02-14 10:31:04 +02:00
func_decl_replace.h
inj_axiom.cpp Standardize for-loop increments to prefix form (++i) (#8199) 2026-02-18 20:57:29 -08:00
inj_axiom.h
label_rewriter.cpp remove default destructors & some default constructors 2024-09-04 22:30:23 +01:00
label_rewriter.h remove default destructors & some default constructors 2024-09-04 22:30:23 +01:00
macro_replacer.cpp Standardize for-loop increments to prefix form (++i) (#8199) 2026-02-18 20:57:29 -08:00
macro_replacer.h wip - dependent expr simpliifer 2022-11-30 13:41:40 +07:00
maximize_ac_sharing.cpp Standardize for-loop increments to prefix form (++i) (#8199) 2026-02-18 20:57:29 -08:00
maximize_ac_sharing.h expose propagate created 2021-12-17 16:12:47 -08:00
mk_extract_proc.cpp minor fixes 2022-11-02 08:44:55 -07:00
mk_extract_proc.h
mk_simplified_app.cpp
mk_simplified_app.h
pb2bv_rewriter.cpp replace some copies with moves 2026-02-18 21:02:17 -08:00
pb2bv_rewriter.h
pb_rewriter.cpp Refactor pb_rewriter to use structured bindings for expression/coefficient pairs (#8380) 2026-02-18 20:57:57 -08:00
pb_rewriter.h
pb_rewriter_def.h Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
poly_rewriter.h try big M for linux build 2022-12-04 09:49:32 -08:00
poly_rewriter_def.h Standardize for-loop increments to prefix form (++i) (#8199) 2026-02-18 20:57:29 -08:00
push_app_ite.cpp Standardize for-loop increments to prefix form (++i) (#8199) 2026-02-18 20:57:29 -08:00
push_app_ite.h Remove empty leaf destructors. (#6211) 2022-07-30 10:07:03 +01:00
quant_hoist.cpp Refactor mk_and and mk_app to use std::span API (#8285) 2026-02-18 20:57:52 -08:00
quant_hoist.h
recfun_replace.h Remove empty leaf destructors. (#6211) 2022-07-30 10:07:03 +01:00
recfun_rewriter.cpp fix #8109 2026-02-18 20:57:05 -08:00
recfun_rewriter.h fix #8109 2026-02-18 20:57:05 -08:00
rewriter.cpp Standardize for-loop increments to prefix form (++i) (#8199) 2026-02-18 20:57:29 -08:00
rewriter.h Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
rewriter.txt
rewriter_def.h fix #9657 2026-05-28 09:01:48 -07:00
rewriter_types.h fix #7006 2023-11-28 15:06:27 -08:00
seq_axioms.cpp fix #8572 2026-02-18 21:02:20 -08:00
seq_axioms.h sketch replace_all 2022-01-01 17:39:37 -08:00
seq_eq_solver.cpp Remove unreachable return false in match_ubv2s1 2026-03-05 17:59:50 +00:00
seq_eq_solver.h Add and fix a few general compiler warnings. (#5628) 2021-10-29 15:42:32 +02:00
seq_rewriter.cpp Refactor regex subset logic into seq_subset with depth-bounded recursion and optimized concat traversal (#9777) 2026-06-09 13:42:28 -07:00
seq_rewriter.h Refactor regex subset logic into seq_subset with depth-bounded recursion and optimized concat traversal (#9777) 2026-06-09 13:42:28 -07:00
seq_skolem.cpp filter length limits to be non-skolems and under concat/""/unit 2022-09-15 07:41:13 -07:00
seq_skolem.h Fix some typos. (#7115) 2024-02-07 23:06:43 -08:00
seq_subset.cpp Refactor regex subset logic into seq_subset with depth-bounded recursion and optimized concat traversal (#9777) 2026-06-09 13:42:28 -07:00
seq_subset.h Refactor regex subset logic into seq_subset with depth-bounded recursion and optimized concat traversal (#9777) 2026-06-09 13:42:28 -07:00
th_rewriter.cpp Standardize for-loop increments to prefix form (++i) (#8199) 2026-02-18 20:57:29 -08:00
th_rewriter.h remove theory_str and classes that are only used by it 2025-08-07 21:05:12 -07:00
value_sweep.cpp Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
value_sweep.h
var_subst.cpp Standardize for-loop increments to prefix form (++i) (#8199) 2026-02-18 20:57:29 -08:00
var_subst.h delete more default constructors 2024-09-23 12:59:04 +01:00