mirror of
https://github.com/Z3Prover/z3
synced 2026-01-21 17:44:43 +00:00
Add sequence higher-order functions to Java API (#8226)
* Initial plan * Add four sequence operations to Java API (SeqMap, SeqMapi, SeqFoldl, SeqFoldli) Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> * Fix checkContextMatch call and add test for sequence operations Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> * Add 4-parameter checkContextMatch overload for consistency Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
This commit is contained in:
parent
1be52d95a5
commit
ecea5e2b4e
2 changed files with 132 additions and 0 deletions
|
|
@ -2235,6 +2235,46 @@ public class Context implements AutoCloseable {
|
|||
return (IntExpr)Expr.create(this, Native.mkSeqLastIndex(nCtx(), s.getNativeObject(), substr.getNativeObject()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Map function f over sequence s.
|
||||
* Returns a new sequence where f is applied to each element of s.
|
||||
*/
|
||||
public final <R extends Sort> SeqExpr<R> mkSeqMap(Expr<?> f, Expr<SeqSort<R>> s)
|
||||
{
|
||||
checkContextMatch(f, s);
|
||||
return (SeqExpr<R>) Expr.create(this, Native.mkSeqMap(nCtx(), f.getNativeObject(), s.getNativeObject()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Map function f over sequence s starting at index i.
|
||||
* Returns a new sequence where f is applied to each element of s along with its index starting from i.
|
||||
*/
|
||||
public final <R extends Sort> SeqExpr<R> mkSeqMapi(Expr<?> f, Expr<IntSort> i, Expr<SeqSort<R>> s)
|
||||
{
|
||||
checkContextMatch(f, i, s);
|
||||
return (SeqExpr<R>) Expr.create(this, Native.mkSeqMapi(nCtx(), f.getNativeObject(), i.getNativeObject(), s.getNativeObject()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Left fold of function f over sequence s with accumulator a.
|
||||
* Applies f to accumulate values from left to right over the sequence.
|
||||
*/
|
||||
public final <R extends Sort, A extends Sort> Expr<A> mkSeqFoldl(Expr<?> f, Expr<A> a, Expr<SeqSort<R>> s)
|
||||
{
|
||||
checkContextMatch(f, a, s);
|
||||
return (Expr<A>) Expr.create(this, Native.mkSeqFoldl(nCtx(), f.getNativeObject(), a.getNativeObject(), s.getNativeObject()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Left fold of function f over sequence s with accumulator a starting at index i.
|
||||
* Applies f to accumulate values from left to right over the sequence, tracking the index starting from i.
|
||||
*/
|
||||
public final <R extends Sort, A extends Sort> Expr<A> mkSeqFoldli(Expr<?> f, Expr<IntSort> i, Expr<A> a, Expr<SeqSort<R>> s)
|
||||
{
|
||||
checkContextMatch(f, i, a, s);
|
||||
return (Expr<A>) Expr.create(this, Native.mkSeqFoldli(nCtx(), f.getNativeObject(), i.getNativeObject(), a.getNativeObject(), s.getNativeObject()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the first occurrence of src by dst in s.
|
||||
*/
|
||||
|
|
@ -4430,6 +4470,14 @@ public class Context implements AutoCloseable {
|
|||
checkContextMatch(other3);
|
||||
}
|
||||
|
||||
void checkContextMatch(Z3Object other1, Z3Object other2, Z3Object other3, Z3Object other4)
|
||||
{
|
||||
checkContextMatch(other1);
|
||||
checkContextMatch(other2);
|
||||
checkContextMatch(other3);
|
||||
checkContextMatch(other4);
|
||||
}
|
||||
|
||||
void checkContextMatch(Z3Object[] arr)
|
||||
{
|
||||
if (arr != null)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue