Skip to content

Commit 12034df

Browse files
add rewrites for #2575
Signed-off-by: Nikolaj Bjorner <[email protected]>
1 parent 78ed71b commit 12034df

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

src/ast/rewriter/seq_rewriter.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,37 @@ br_status seq_rewriter::mk_re_concat(expr* a, expr* b, expr_ref& result) {
16731673
result = a;
16741674
return BR_DONE;
16751675
}
1676+
expr* a1 = nullptr, *b1 = nullptr;
1677+
if (m_util.re.is_star(a, a1) && m_util.re.is_star(b, b1) && a1 == b1) {
1678+
result = a;
1679+
return BR_DONE;
1680+
}
1681+
if (m_util.re.is_star(a, a1) && a1 == b) {
1682+
result = m_util.re.mk_concat(b, a);
1683+
return BR_DONE;
1684+
}
1685+
{
1686+
unsigned lo1, hi1, lo2, hi2;
1687+
if (m_util.re.is_loop(a, a1, lo1, hi1) && m_util.re.is_loop(b, b1, lo2, hi2) && a1 == b1) {
1688+
result = m_util.re.mk_loop(a1, lo1 + lo2, hi1 + hi2);
1689+
return BR_DONE;
1690+
}
1691+
if (m_util.re.is_loop(a, a1, lo1) && m_util.re.is_loop(b, b1, lo2) && a1 == b1) {
1692+
result = m_util.re.mk_loop(a1, lo1 + lo2);
1693+
return BR_DONE;
1694+
}
1695+
}
1696+
{
1697+
expr* lo1, *hi1, *lo2, *hi2;
1698+
if (m_util.re.is_loop(a, a1, lo1, hi1) && m_util.re.is_loop(b, b1, lo2, hi2) && a1 == b1) {
1699+
result = m_util.re.mk_loop(a1, m_autil.mk_add(lo1, lo2), m_autil.mk_add(hi1, hi2));
1700+
return BR_DONE;
1701+
}
1702+
if (m_util.re.is_loop(a, a1, lo1) && m_util.re.is_loop(b, b1, lo2) && a1 == b1) {
1703+
result = m_util.re.mk_loop(a1, m_autil.mk_add(lo1, lo2));
1704+
return BR_DONE;
1705+
}
1706+
}
16761707
return BR_FAILED;
16771708
}
16781709
/*

src/ast/seq_decl_plugin.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,16 @@ app* seq_util::re::mk_loop(expr* r, unsigned lo, unsigned hi) {
10931093
return m.mk_app(m_fid, OP_RE_LOOP, 2, params, 1, &r);
10941094
}
10951095

1096+
app* seq_util::re::mk_loop(expr* r, expr* lo) {
1097+
expr* rs[2] = { r, lo };
1098+
return m.mk_app(m_fid, OP_RE_LOOP, 0, nullptr, 2, rs);
1099+
}
1100+
1101+
app* seq_util::re::mk_loop(expr* r, expr* lo, expr* hi) {
1102+
expr* rs[3] = { r, lo, hi };
1103+
return m.mk_app(m_fid, OP_RE_LOOP, 0, nullptr, 3, rs);
1104+
}
1105+
10961106
app* seq_util::re::mk_full_char(sort* s) {
10971107
return m.mk_app(m_fid, OP_RE_FULL_CHAR_SET, 0, nullptr, 0, nullptr, s);
10981108
}
@@ -1129,3 +1139,28 @@ bool seq_util::re::is_loop(expr const* n, expr*& body, unsigned& lo) {
11291139
}
11301140
return false;
11311141
}
1142+
1143+
bool seq_util::re::is_loop(expr const* n, expr*& body, expr*& lo, expr*& hi) {
1144+
if (is_loop(n)) {
1145+
app const* a = to_app(n);
1146+
if (a->get_num_args() == 3) {
1147+
body = a->get_arg(0);
1148+
lo = a->get_arg(1);
1149+
hi = a->get_arg(2);
1150+
return true;
1151+
}
1152+
}
1153+
return false;
1154+
}
1155+
1156+
bool seq_util::re::is_loop(expr const* n, expr*& body, expr*& lo) {
1157+
if (is_loop(n)) {
1158+
app const* a = to_app(n);
1159+
if (a->get_num_args() == 2) {
1160+
body = a->get_arg(0);
1161+
lo = a->get_arg(1);
1162+
return true;
1163+
}
1164+
}
1165+
return false;
1166+
}

src/ast/seq_decl_plugin.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ class seq_util {
366366
app* mk_opt(expr* r) { return m.mk_app(m_fid, OP_RE_OPTION, r); }
367367
app* mk_loop(expr* r, unsigned lo);
368368
app* mk_loop(expr* r, unsigned lo, unsigned hi);
369+
app* mk_loop(expr* r, expr* lo);
370+
app* mk_loop(expr* r, expr* lo, expr* hi);
369371
app* mk_full_char(sort* s);
370372
app* mk_full_seq(sort* s);
371373
app* mk_empty(sort* s);
@@ -394,6 +396,8 @@ class seq_util {
394396
MATCH_UNARY(is_opt);
395397
bool is_loop(expr const* n, expr*& body, unsigned& lo, unsigned& hi);
396398
bool is_loop(expr const* n, expr*& body, unsigned& lo);
399+
bool is_loop(expr const* n, expr*& body, expr*& lo, expr*& hi);
400+
bool is_loop(expr const* n, expr*& body, expr*& lo);
397401
bool is_unroll(expr const* n) const { return is_app_of(n, m_fid, _OP_RE_UNROLL); }
398402
};
399403
str str;

0 commit comments

Comments
 (0)