3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-24 01:25:31 +00:00

hoist co-factors eagerly without adding axioms

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2020-05-25 15:10:45 -07:00
parent e938ee33bb
commit a97bc65af4
6 changed files with 94 additions and 68 deletions

View file

@ -2278,6 +2278,13 @@ expr_ref seq_rewriter::derivative(expr* elem, expr* r) {
result = array.mk_select(2, args);
result = kleene_predicate(result, seq_sort);
}
else if (m().is_ite(r, p, r1, r2)) {
dr1 = derivative(elem, r1);
dr2 = derivative(elem, r2);
if (dr1 && dr2) {
result = m().mk_ite(p, dr1, dr2);
}
}
return result;
}

View file

@ -1220,6 +1220,44 @@ app* seq_util::str::mk_is_empty(expr* s) const {
return m.mk_eq(s, mk_empty(get_sort(s)));
}
unsigned seq_util::str::min_length(expr* s) const {
SASSERT(u.is_seq(s));
expr_ref_vector es(m);
unsigned result = 0;
get_concat_units(s, es);
for (expr* arg : es) {
if (is_unit(arg))
result++;
}
return result;
}
unsigned seq_util::re::min_length(expr* r) const {
SASSERT(u.is_re(r));
expr* r1 = nullptr, *r2 = nullptr, *s = nullptr;
if (is_empty(r))
return UINT_MAX;
if (is_concat(r, r1, r2)) {
unsigned l1 = min_length(r1);
if (l1 == UINT_MAX)
return l1;
unsigned l2 = min_length(r2);
if (l2 == UINT_MAX)
return l2;
return l1 + l2;
}
if (m.is_ite(r, s, r1, r2))
return std::min(min_length(r1), min_length(r2));
if (is_diff(r, r1, r2))
return min_length(r1);
if (is_union(r, r1, r2))
return std::min(min_length(r1), min_length(r2));
if (is_intersection(r, r1, r2))
return std::max(min_length(r1), min_length(r2));
if (is_to_re(r, s))
return u.str.min_length(s);
return 0;
}
sort* seq_util::re::to_seq(sort* re) {
(void)u;

View file

@ -394,6 +394,8 @@ public:
void get_concat_units(expr* e, expr_ref_vector& es) const;
expr* get_leftmost_concat(expr* e) const { expr* e1, *e2; while (is_concat(e, e1, e2)) e = e1; return e; }
expr* get_rightmost_concat(expr* e) const { expr* e1, *e2; while (is_concat(e, e1, e2)) e = e2; return e; }
unsigned min_length(expr* s) const;
};
class re {
@ -456,6 +458,7 @@ public:
bool is_loop(expr const* n, expr*& body, unsigned& lo);
bool is_loop(expr const* n, expr*& body, expr*& lo, expr*& hi);
bool is_loop(expr const* n, expr*& body, expr*& lo);
unsigned min_length(expr* r) const;
};
str str;
re re;