Skip to content

Commit

Permalink
add regex power to API and for Java per request
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
  • Loading branch information
NikolajBjorner committed Mar 16, 2022
1 parent 706d7ea commit e1929ca
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/api/api_seq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,17 @@ extern "C" {
Z3_CATCH_RETURN(nullptr);
}

Z3_ast Z3_API Z3_mk_re_power(Z3_context c, Z3_ast r, unsigned n) {
Z3_TRY;
LOG_Z3_mk_re_power(c, r, n);
RESET_ERROR_CODE();
app* a = mk_c(c)->sutil().re.mk_power(to_expr(r), n);
mk_c(c)->save_ast_trail(a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(nullptr);
}


MK_UNARY(Z3_mk_re_plus, mk_c(c)->get_seq_fid(), OP_RE_PLUS, SKIP);
MK_UNARY(Z3_mk_re_star, mk_c(c)->get_seq_fid(), OP_RE_STAR, SKIP);
MK_UNARY(Z3_mk_re_option, mk_c(c)->get_seq_fid(), OP_RE_OPTION, SKIP);
Expand Down
8 changes: 8 additions & 0 deletions src/api/java/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -2200,6 +2200,14 @@ public <R extends Sort> ReExpr<R> mkStar(Expr<ReSort<R>> re)
return (ReExpr<R>) Expr.create(this, Native.mkReStar(nCtx(), re.getNativeObject()));
}

/**
* Create power regular expression.
*/
public <R extends Sort> ReExpr<R> mkLoop(Expr<ReSort<R>> re, int n)
{
return (ReExpr<R>) Expr.create(this, Native.mkRePower(nCtx(), re.getNativeObject(), n));
}

/**
* Take the lower and upper-bounded Kleene star of a regular expression.
*/
Expand Down
7 changes: 7 additions & 0 deletions src/api/z3_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -3821,6 +3821,13 @@ extern "C" {
*/
Z3_ast Z3_API Z3_mk_re_loop(Z3_context c, Z3_ast r, unsigned lo, unsigned hi);

/**
\brief Create a power regular expression.
def_API('Z3_mk_re_power', AST, (_in(CONTEXT), _in(AST), _in(UINT)))
*/
Z3_ast Z3_API Z3_mk_re_power(Z3_context c, Z3_ast, unsigned n);

/**
\brief Create the intersection of the regular languages.
Expand Down
6 changes: 6 additions & 0 deletions src/ast/seq_decl_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,12 @@ sort* seq_util::rex::to_seq(sort* re) {
return to_sort(re->get_parameter(0).get_ast());
}

app* seq_util::rex::mk_power(expr* r, unsigned n) {
parameter param(n);
return m.mk_app(m_fid, OP_RE_POWER, 1, &param, 1, &r);
}


app* seq_util::rex::mk_loop(expr* r, unsigned lo) {
parameter param(lo);
return m.mk_app(m_fid, OP_RE_LOOP, 1, &param, 1, &r);
Expand Down
1 change: 1 addition & 0 deletions src/ast/seq_decl_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ class seq_util {
app* mk_star(expr* r) { return m.mk_app(m_fid, OP_RE_STAR, r); }
app* mk_plus(expr* r) { return m.mk_app(m_fid, OP_RE_PLUS, r); }
app* mk_opt(expr* r) { return m.mk_app(m_fid, OP_RE_OPTION, r); }
app* mk_power(expr* r, unsigned n);
app* mk_loop(expr* r, unsigned lo);
app* mk_loop(expr* r, unsigned lo, unsigned hi);
expr* mk_loop_proper(expr* r, unsigned lo, unsigned hi);
Expand Down

0 comments on commit e1929ca

Please sign in to comment.