(String[] args)
| 6 | |
| 7 | public class SeqOperationsExample { |
| 8 | public static void main(String[] args) { |
| 9 | Context ctx = new Context(); |
| 10 | |
| 11 | try { |
| 12 | System.out.println("Testing new sequence operations in Java API\n"); |
| 13 | |
| 14 | // Test 1: mkSeqMap |
| 15 | System.out.println("Test 1: mkSeqMap"); |
| 16 | IntSort intSort = ctx.mkIntSort(); |
| 17 | SeqSort<IntSort> seqIntSort = ctx.mkSeqSort(intSort); |
| 18 | |
| 19 | // Create a sequence variable |
| 20 | Expr<SeqSort<IntSort>> seq = ctx.mkConst("s", seqIntSort); |
| 21 | |
| 22 | // Create a lambda function that adds 1 to an integer: (lambda (x) (+ x 1)) |
| 23 | Expr<IntSort> x = ctx.mkIntConst("x"); |
| 24 | Lambda<IntSort> f = ctx.mkLambda(new Expr<?>[] { x }, ctx.mkAdd(x, ctx.mkInt(1))); |
| 25 | |
| 26 | // Create map expression (conceptually maps f over seq) |
| 27 | SeqExpr<IntSort> mapped = ctx.mkSeqMap(f, seq); |
| 28 | System.out.println("mkSeqMap result type: " + mapped.getClass().getName()); |
| 29 | System.out.println("mkSeqMap created successfully: " + mapped); |
| 30 | System.out.println(); |
| 31 | |
| 32 | // Test 2: mkSeqMapi |
| 33 | System.out.println("Test 2: mkSeqMapi"); |
| 34 | // Lambda that takes index and element: (lambda (i x) (+ x i)) |
| 35 | Expr<IntSort> xElem = ctx.mkIntConst("xElem"); |
| 36 | Expr<IntSort> iIdx = ctx.mkIntConst("iIdx"); |
| 37 | Lambda<IntSort> fWithIdx = ctx.mkLambda(new Expr<?>[] { iIdx, xElem }, ctx.mkAdd(xElem, iIdx)); |
| 38 | IntExpr i = ctx.mkIntConst("start_idx"); |
| 39 | SeqExpr<IntSort> mappedWithIndex = ctx.mkSeqMapi(fWithIdx, i, seq); |
| 40 | System.out.println("mkSeqMapi result type: " + mappedWithIndex.getClass().getName()); |
| 41 | System.out.println("mkSeqMapi created successfully: " + mappedWithIndex); |
| 42 | System.out.println(); |
| 43 | |
| 44 | // Test 3: mkSeqFoldl |
| 45 | System.out.println("Test 3: mkSeqFoldl"); |
| 46 | // Lambda that accumulates: (lambda (acc elem) (+ acc elem)) |
| 47 | IntExpr accVar = ctx.mkIntConst("accVar"); |
| 48 | IntExpr elemVar = ctx.mkIntConst("elemVar"); |
| 49 | Lambda<IntSort> foldFunc = ctx.mkLambda(new Expr<?>[] { accVar, elemVar }, ctx.mkAdd(accVar, elemVar)); |
| 50 | IntExpr acc = ctx.mkIntConst("acc"); |
| 51 | Expr<IntSort> folded = ctx.mkSeqFoldl(foldFunc, acc, seq); |
| 52 | System.out.println("mkSeqFoldl result type: " + folded.getClass().getName()); |
| 53 | System.out.println("mkSeqFoldl created successfully: " + folded); |
| 54 | System.out.println(); |
| 55 | |
| 56 | // Test 4: mkSeqFoldli |
| 57 | System.out.println("Test 4: mkSeqFoldli"); |
| 58 | // Lambda with index: (lambda (idx acc elem) (+ acc elem idx)) |
| 59 | IntExpr idxVar = ctx.mkIntConst("idxVar"); |
| 60 | IntExpr accVar2 = ctx.mkIntConst("accVar2"); |
| 61 | IntExpr elemVar2 = ctx.mkIntConst("elemVar2"); |
| 62 | ArithExpr<?> tempSum = ctx.mkAdd(accVar2, elemVar2); |
| 63 | ArithExpr<?> finalSum = ctx.mkAdd(tempSum, idxVar); |
| 64 | Lambda<IntSort> foldFuncWithIdx = ctx.mkLambda( |
| 65 | new Expr<?>[] { idxVar, accVar2, elemVar2 }, |
nothing calls this directly
no test coverage detected