mirror of
https://github.com/Z3Prover/z3
synced 2026-06-22 08:30:28 +00:00
Merge branch 'master' into c3
This commit is contained in:
commit
e3b80fc578
104 changed files with 10253 additions and 4367 deletions
|
|
@ -4525,10 +4525,60 @@ br_status seq_rewriter::mk_str_to_regexp(expr* a, expr_ref& result) {
|
|||
r* ++ r -> r ++ r*
|
||||
*/
|
||||
br_status seq_rewriter::mk_re_concat(expr* a, expr* b, expr_ref& result) {
|
||||
auto accepts_empty_word = [&](expr* r) {
|
||||
auto info = re().get_info(r);
|
||||
return info.interpreted && info.nullable == l_true && info.min_length == 0;
|
||||
};
|
||||
auto starts_with_full_seq = [&](expr* r) {
|
||||
expr* r1 = nullptr, *r2 = nullptr;
|
||||
return re().is_full_seq(r) || (re().is_concat(r, r1, r2) && re().is_full_seq(r1));
|
||||
};
|
||||
auto ends_with_full_seq = [&](expr* r) {
|
||||
expr* r1 = nullptr, *r2 = nullptr;
|
||||
while (re().is_concat(r, r1, r2))
|
||||
r = r2;
|
||||
return re().is_full_seq(r);
|
||||
};
|
||||
auto all_inter_arms_end_with_full_seq = [&](expr* r) {
|
||||
ptr_buffer<expr> todo;
|
||||
todo.push_back(r);
|
||||
while (!todo.empty()) {
|
||||
expr* r1 = nullptr, *r2 = nullptr;
|
||||
expr* t = todo.back();
|
||||
todo.pop_back();
|
||||
if (re().is_intersection(t, r1, r2)) {
|
||||
todo.push_back(r1);
|
||||
todo.push_back(r2);
|
||||
}
|
||||
else if (!ends_with_full_seq(t)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
if (re().is_full_seq(a) && re().is_full_seq(b)) {
|
||||
result = a;
|
||||
return BR_DONE;
|
||||
}
|
||||
if (re().is_full_seq(a) && accepts_empty_word(b)) {
|
||||
result = a;
|
||||
return BR_DONE;
|
||||
}
|
||||
if (re().is_full_seq(b) && accepts_empty_word(a)) {
|
||||
result = b;
|
||||
return BR_DONE;
|
||||
}
|
||||
expr* u1 = nullptr, *u2 = nullptr;
|
||||
if (re().is_full_seq(a) && re().is_union(b, u1, u2) &&
|
||||
(starts_with_full_seq(u1) || starts_with_full_seq(u2))) {
|
||||
result = mk_regex_union_normalize(mk_regex_concat(a, u1), mk_regex_concat(a, u2));
|
||||
return BR_REWRITE2;
|
||||
}
|
||||
if (re().is_intersection(a, u1, u2) && re().is_full_seq(b) &&
|
||||
all_inter_arms_end_with_full_seq(a)) {
|
||||
result = a;
|
||||
return BR_DONE;
|
||||
}
|
||||
if (re().is_empty(a)) {
|
||||
result = a;
|
||||
return BR_DONE;
|
||||
|
|
@ -4564,7 +4614,8 @@ br_status seq_rewriter::mk_re_concat(expr* a, expr* b, expr_ref& result) {
|
|||
result = re().mk_to_re(str().mk_concat(a_str, b_str));
|
||||
return BR_REWRITE2;
|
||||
}
|
||||
expr* a1 = nullptr, *b1 = nullptr;
|
||||
expr* a1 = nullptr;
|
||||
expr* b1 = nullptr;
|
||||
if (re().is_to_re(a, a1) && re().is_to_re(b, b1)) {
|
||||
result = re().mk_to_re(str().mk_concat(a1, b1));
|
||||
return BR_DONE;
|
||||
|
|
@ -4573,6 +4624,11 @@ br_status seq_rewriter::mk_re_concat(expr* a, expr* b, expr_ref& result) {
|
|||
result = a;
|
||||
return BR_DONE;
|
||||
}
|
||||
expr* b2 = nullptr, *b3 = nullptr;
|
||||
if (re().is_star(a, a1) && re().is_concat(b, b1, b2) && re().is_star(b1, b3) && a1 == b3) {
|
||||
result = b;
|
||||
return BR_DONE;
|
||||
}
|
||||
if (re().is_star(a, a1) && a1 == b) {
|
||||
result = re().mk_concat(b, a);
|
||||
return BR_DONE;
|
||||
|
|
@ -4626,51 +4682,7 @@ bool seq_rewriter::are_complements(expr* r1, expr* r2) const {
|
|||
* basic subset checker.
|
||||
*/
|
||||
bool seq_rewriter::is_subset(expr* r1, expr* r2) const {
|
||||
// return false;
|
||||
expr* ra1 = nullptr, *ra2 = nullptr, *ra3 = nullptr;
|
||||
expr* rb1 = nullptr, *rb2 = nullptr, *rb3 = nullptr;
|
||||
unsigned la, ua, lb, ub;
|
||||
if (re().is_complement(r1, ra1) &&
|
||||
re().is_complement(r2, rb1)) {
|
||||
return is_subset(rb1, ra1);
|
||||
}
|
||||
auto is_concat = [&](expr* r, expr*& a, expr*& b, expr*& c) {
|
||||
return re().is_concat(r, a, b) && re().is_concat(b, b, c);
|
||||
};
|
||||
while (true) {
|
||||
if (r1 == r2)
|
||||
return true;
|
||||
if (re().is_full_seq(r2))
|
||||
return true;
|
||||
if (re().is_dot_plus(r2) && re().get_info(r1).nullable == l_false)
|
||||
return true;
|
||||
if (is_concat(r1, ra1, ra2, ra3) &&
|
||||
is_concat(r2, rb1, rb2, rb3) && ra1 == rb1 && ra2 == rb2) {
|
||||
r1 = ra3;
|
||||
r2 = rb3;
|
||||
continue;
|
||||
}
|
||||
if (re().is_concat(r1, ra1, ra2) &&
|
||||
re().is_concat(r2, rb1, rb2) && re().is_full_seq(rb1)) {
|
||||
r1 = ra2;
|
||||
continue;
|
||||
}
|
||||
// r1=ra3{la,ua}ra2, r2=rb3{lb,ub}rb2, ra3=rb3, lb<=la, ua<=ub
|
||||
if (re().is_concat(r1, ra1, ra2) && re().is_loop(ra1, ra3, la, ua) &&
|
||||
re().is_concat(r2, rb1, rb2) && re().is_loop(rb1, rb3, lb, ub) &&
|
||||
ra3 == rb3 && lb <= la && ua <= ub) {
|
||||
r1 = ra2;
|
||||
r2 = rb2;
|
||||
continue;
|
||||
}
|
||||
// ra1=ra3{la,ua}, r2=rb3{lb,ub}, ra3=rb3, lb<=la, ua<=ub
|
||||
if (re().is_loop(r1, ra3, la, ua) &&
|
||||
re().is_loop(r2, rb3, lb, ub) &&
|
||||
ra3 == rb3 && lb <= la && ua <= ub) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return m_subset.is_subset(r1, r2);
|
||||
}
|
||||
|
||||
br_status seq_rewriter::mk_re_union0(expr* a, expr* b, expr_ref& result) {
|
||||
|
|
@ -6256,4 +6268,3 @@ bool seq_rewriter::get_bounds(expr* e, unsigned& low, unsigned& high) {
|
|||
}
|
||||
return low <= high;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue