3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-06-19 15:16:29 +00:00
Commit graph

57 commits

Author SHA1 Message Date
Nikolaj Bjorner
898178fbe5 merge with master
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2026-06-10 15:54:33 -07:00
Nikolaj Bjorner
c9cd5147be merge
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2026-06-10 15:31:01 -07:00
Nikolaj Bjorner
0c2ed444ca fix build
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2026-06-10 15:27:48 -07:00
copilot-swe-agent[bot]
1e906ba585 Remove is_nullable_rec from seq_rewriter, delegate to derive::nullable 2026-06-10 15:27:42 -07:00
copilot-swe-agent[bot]
70a9dbfae2 Apply follow-up derive validation fixes 2026-06-10 15:26:46 -07:00
copilot-swe-agent[bot]
bf9707a316 Address PR feedback on derive, nullability, and requested reverts 2026-06-10 15:26:40 -07:00
Nikolaj Bjorner
458878b5e1 cleanup
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2026-06-10 15:25:06 -07:00
Nikolaj Bjorner
0e29a35da5 updates
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2026-06-10 15:25:05 -07:00
Nikolaj Bjorner
dbd725bdc0 Refactor merge_union and mk_union_core functions 2026-06-10 15:25:05 -07:00
Nikolaj Bjorner
72575ff962 reuse char extraction from seq_util 2026-06-10 15:25:04 -07:00
Nikolaj Bjorner
867dc175c5 tune and fix derive 2026-06-10 15:25:03 -07:00
Nikolaj Bjorner
61093fadf6 updates to derive 2026-06-10 15:25:03 -07:00
Nikolaj Bjorner
ff8a1034d6 Refactor seq_derive: inline path pruning with ACI normalization
Replace simplify_ite_rec post-hoc pass with inline path pruning:
- push/pop API with lbool return (l_true=implied, l_undef=pushed, l_false=contradicts)
- apply_ite hoists ITE through union/inter/complement with path-aware pruning
- Path-aware caching for mk_union, mk_inter, mk_complement
- Incremental path expression maintenance for cache keys
- Complement always pushes through ITE for same-condition merge
- ACI normalization (flatten/sort/deduplicate) for union base case
- is_subset subsumption prevents unbounded union growth
- Prefix factoring (a·x ∪ a·y = a·(x ∪ y)) for loop derivatives
- seq_rewriter passed as reference to derive class
- Depth-limited single-ITE hoisting (path_stack.size() < 8)
- pred_implies with signed atoms avoids mk_not allocations
- extract_char_range properly checks m_ele identity

Results: 0 timeouts on regression suite (vs 2 on master).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-10 15:24:57 -07:00
Nikolaj Bjorner
13d0de42bc tuning 2026-06-10 15:24:06 -07:00
Nikolaj Bjorner
9456297046 tuning simplification processing
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2026-06-10 15:24:04 -07:00
Nikolaj Bjorner
f42172e65a conservative expansions 2026-06-10 15:24:03 -07:00
Nikolaj Bjorner
98a7992a65 handle more cass with intervals 2026-06-10 15:24:02 -07:00
Nikolaj Bjorner
18a0db9d48 cr updates
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2026-06-10 15:24:01 -07:00
Nikolaj Bjorner
6b862ddf19 intervals
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2026-06-10 15:24:01 -07:00
Nikolaj Bjorner
6289b91f17 Add interval-based range simplification for ITE conditions
Introduce exclusion intervals alongside the existing path-based condition
tracking in simplify_ite_rec. The intervals track which character values
are still possible at each point in the ITE tree, enabling simplification
of nested range conditions that the per-entry path approach cannot handle.

Key additions:
- intervals_t type and push_intervals() to maintain live character ranges
- eval_range_cond() checks AND-of-char_le conditions against intervals
- intersect_intervals/exclude_interval utilities from seq_rewriter pattern
- Negated AND handling: ¬(lo<=x ∧ x<=hi) excludes [lo,hi] from intervals

The interval check runs before the existing eval_path_cond logic, catching
cases like: if(0<=x<=10, t, if(1<=x<=8, t2, e2)) → if(0<=x<=10, t, e2)
where the inner range [1,8] is fully contained in the excluded outer range.

Fixes remaining regression timeouts on 5728 P2 and 5731 P4.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-10 15:24:00 -07:00
Nikolaj Bjorner
d54d62a07a Fix regression timeouts via range condition simplification
- Simplify trivial range bounds in derive_range: when lo=0, omit
  the lo<=x condition; when hi=max_char, omit the x<=hi condition.
  Full charset ranges return epsilon directly.

- Add char_le(0,x)=true and char_le(x,max)=true to eval_cond for
  always-valid bounds.

- Add range implication logic to simplify_ite_rec: when path has
  negated/positive char_le constraints, detect implied or contradicted
  char_le conditions (e.g., ¬(x<=127) implies 128<=x).

- Add is_subset(a, .+) check: non-nullable regexes are subsets of .+

- In update_state_graph, skip recursive exploration of nullable targets
  to avoid state explosion.

These fixes resolve timeouts on 5724 (all problems), 5721 P1, and 5693.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-10 15:23:59 -07:00
Nikolaj Bjorner
88a177f6c5 Fix derivative instability and recursion bugs
- Add top-level cache (m_top_cache) to ensure stable AST node identity
  across repeated derivative calls, preventing state graph divergence
- Add get_head_tail helper for derive_to_re with str.is_unit/str.is_concat
- Add ITE hoisting in mk_union/mk_inter to keep ITEs at top level
- Add De Morgan rule in mk_complement: ~(A∪B) → ~A ∩ ~B
- Add ~ε → .+ simplification in mk_complement
- Add prefix factoring: a·x ∪ a·y = a·(x∪y) and a·x ∩ a·y = a·(x∩y)
- Add r* ∩ .+ = r+ special case in mk_inter
- Enhance is_subset with union/intersection distributivity and complement
- Remove De Morgan from mk_inter to prevent infinite recursion loop

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-10 15:23:59 -07:00
Nikolaj Bjorner
c1637ab806 Address PR review: push_path helper, lbool eval_cond, fix year
- Add push_path(path, c, sign) that decomposes conjuncts/disjuncts
- Add simplify_ite_rec(path, c, t, e) helper for cleaner recursion
- Change eval_cond signature to return lbool (l_undef = undetermined)
- Fix copyright year from 2025 to 2026

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-10 15:23:58 -07:00
Nikolaj Bjorner
0f50702c9e Address PR review: subsumption, is_value, simplify_ite fixes
- Add lightweight structural is_subset for union/inter simplification
- Use m.is_value instead of is_const_char for swap checks
- Move eval_cond to beginning of simplify_ite_rec
- Use path.shrink(sz) instead of copying extended_path
- Fix normalize_reverse stuck case to return mk_reverse(r)
- Expose subsumes() in public API

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-10 15:23:57 -07:00
Nikolaj Bjorner
2e3dd32b90 Address PR review comments: cache, simplify_ite_rec, itos
- Cache now indexes by (ele, r) pair using obj_pair_map
- Remove eval() function; operator()(ele, r) handles all cases
- Rewrite simplify_ite_rec with path vector of signed conditions
- Add range-based simplification: (lo <= x, false) + (x <= hi, false)
  eliminates ite(x = v, t, e) when v is outside [lo, hi]
- Add is_itos case in derive_to_re: guards on n >= 0, digit range,
  and first character match
- Port is_reverse normalization (previous commit)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-10 15:23:56 -07:00
Nikolaj Bjorner
3a22994b80 Port reverse normalization into derive class
Instead of treating reverse(r) as stuck (returning symbolic mk_derivative),
normalize it by pushing reverse inward through the regex structure, then
compute the derivative of the normalized result. Mirrors mk_re_reverse logic.

Handles: concat, union, intersection, diff, ite, opt, complement, star,
plus, loop, to_re (string literals, units, concats), and symmetric cases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-10 15:23:56 -07:00
Nikolaj Bjorner
2b06d6ddb2 Add simplify_ite_rec and eval for two-phase derivative
- Add simplify_ite post-processing in operator() to simplify ITE conditions
- Add simplify_ite_rec(cond, sign, r) for propagating condition truth values
- Handles c == cond, x=ch1 vs x=ch2 with different constants
- Add eval(ele, d) for efficient two-phase: symbolic derivative + concrete eval
- mk_derivative uses two-phase pattern: m_derive(r) then m_derive.eval(ele, d)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-10 15:23:55 -07:00
Nikolaj Bjorner
a59a7296fb make reset private 2026-06-10 15:23:54 -07:00
Nikolaj Bjorner
8eb6491e6c updates per PR comments 2026-06-10 15:23:54 -07:00
Nikolaj Bjorner
e74d2d2151 move seq_derive and fix include paths, remove antimirov code 2026-06-10 15:23:46 -07:00
copilot-swe-agent[bot]
b6a29b800b
Remove is_nullable_rec from seq_rewriter, delegate to derive::nullable 2026-06-10 18:53:55 +00:00
copilot-swe-agent[bot]
4cd4d16868
Apply follow-up derive validation fixes 2026-06-10 18:20:49 +00:00
copilot-swe-agent[bot]
00fcd3a36d
Address PR feedback on derive, nullability, and requested reverts 2026-06-10 18:18:46 +00:00
Nikolaj Bjorner
77ac58484f updates
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2026-06-09 17:42:11 -07:00
Nikolaj Bjorner
2e57911693 Merge branch 'derive' of https://github.com/z3prover/z3 into derive 2026-06-09 15:19:33 -07:00
Nikolaj Bjorner
fc4d15e4f8 reuse char extraction from seq_util 2026-06-09 15:19:15 -07:00
Nikolaj Bjorner
3c3abeeeb2
Refactor merge_union and mk_union_core functions 2026-06-09 13:36:13 -07:00
Nikolaj Bjorner
758aff4f1e tune and fix derive 2026-06-09 11:10:07 -07:00
Nikolaj Bjorner
143e5b9ffd updates to derive 2026-06-08 23:07:05 -07:00
Nikolaj Bjorner
8deac03ca8 Refactor seq_derive: inline path pruning with ACI normalization
Replace simplify_ite_rec post-hoc pass with inline path pruning:
- push/pop API with lbool return (l_true=implied, l_undef=pushed, l_false=contradicts)
- apply_ite hoists ITE through union/inter/complement with path-aware pruning
- Path-aware caching for mk_union, mk_inter, mk_complement
- Incremental path expression maintenance for cache keys
- Complement always pushes through ITE for same-condition merge
- ACI normalization (flatten/sort/deduplicate) for union base case
- is_subset subsumption prevents unbounded union growth
- Prefix factoring (a·x ∪ a·y = a·(x ∪ y)) for loop derivatives
- seq_rewriter passed as reference to derive class
- Depth-limited single-ITE hoisting (path_stack.size() < 8)
- pred_implies with signed atoms avoids mk_not allocations
- extract_char_range properly checks m_ele identity

Results: 0 timeouts on regression suite (vs 2 on master).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-08 20:43:43 -07:00
Nikolaj Bjorner
2738e4317f tuning 2026-06-07 09:10:02 -07:00
Nikolaj Bjorner
ee67a94a9c tuning simplification processing
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2026-06-06 15:26:12 -07:00
Nikolaj Bjorner
583775129f conservative expansions 2026-06-06 11:34:26 -07:00
Nikolaj Bjorner
f40eb62e83 handle more cass with intervals 2026-06-05 11:49:35 -07:00
Nikolaj Bjorner
120b4e4712 cr updates
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2026-06-05 01:37:10 -07:00
Nikolaj Bjorner
ed2c64208d intervals
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2026-06-04 18:21:26 -07:00
Nikolaj Bjorner
dc8179212e Add interval-based range simplification for ITE conditions
Introduce exclusion intervals alongside the existing path-based condition
tracking in simplify_ite_rec. The intervals track which character values
are still possible at each point in the ITE tree, enabling simplification
of nested range conditions that the per-entry path approach cannot handle.

Key additions:
- intervals_t type and push_intervals() to maintain live character ranges
- eval_range_cond() checks AND-of-char_le conditions against intervals
- intersect_intervals/exclude_interval utilities from seq_rewriter pattern
- Negated AND handling: ¬(lo<=x ∧ x<=hi) excludes [lo,hi] from intervals

The interval check runs before the existing eval_path_cond logic, catching
cases like: if(0<=x<=10, t, if(1<=x<=8, t2, e2)) → if(0<=x<=10, t, e2)
where the inner range [1,8] is fully contained in the excluded outer range.

Fixes remaining regression timeouts on 5728 P2 and 5731 P4.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-04 16:59:59 -07:00
Nikolaj Bjorner
ebdbf83314 Fix regression timeouts via range condition simplification
- Simplify trivial range bounds in derive_range: when lo=0, omit
  the lo<=x condition; when hi=max_char, omit the x<=hi condition.
  Full charset ranges return epsilon directly.

- Add char_le(0,x)=true and char_le(x,max)=true to eval_cond for
  always-valid bounds.

- Add range implication logic to simplify_ite_rec: when path has
  negated/positive char_le constraints, detect implied or contradicted
  char_le conditions (e.g., ¬(x<=127) implies 128<=x).

- Add is_subset(a, .+) check: non-nullable regexes are subsets of .+

- In update_state_graph, skip recursive exploration of nullable targets
  to avoid state explosion.

These fixes resolve timeouts on 5724 (all problems), 5721 P1, and 5693.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-04 15:44:43 -07:00
Nikolaj Bjorner
6aea54fdad Fix derivative instability and recursion bugs
- Add top-level cache (m_top_cache) to ensure stable AST node identity
  across repeated derivative calls, preventing state graph divergence
- Add get_head_tail helper for derive_to_re with str.is_unit/str.is_concat
- Add ITE hoisting in mk_union/mk_inter to keep ITEs at top level
- Add De Morgan rule in mk_complement: ~(A∪B) → ~A ∩ ~B
- Add ~ε → .+ simplification in mk_complement
- Add prefix factoring: a·x ∪ a·y = a·(x∪y) and a·x ∩ a·y = a·(x∩y)
- Add r* ∩ .+ = r+ special case in mk_inter
- Enhance is_subset with union/intersection distributivity and complement
- Remove De Morgan from mk_inter to prevent infinite recursion loop

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-04 10:43:08 -07:00
Nikolaj Bjorner
07cea49e4b Address PR review: push_path helper, lbool eval_cond, fix year
- Add push_path(path, c, sign) that decomposes conjuncts/disjuncts
- Add simplify_ite_rec(path, c, t, e) helper for cleaner recursion
- Change eval_cond signature to return lbool (l_undef = undetermined)
- Fix copyright year from 2025 to 2026

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-04 08:29:44 -07:00