ocaml: phase 5.1 ackermann.ml baseline (ack(3, 4) = 125)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
Classic Ackermann function:
let rec ack m n =
if m = 0 then n + 1
else if n = 0 then ack (m - 1) 1
else ack (m - 1) (ack m (n - 1))
ack(3, 4) = 125, expanding to ~6700 evaluator frames — a useful
stress test of the call stack and control transfer. Real OCaml
evaluates this in milliseconds; ours takes ~2 minutes on a
contended host but completes correctly.
40 baseline programs total.
This commit is contained in:
8
lib/ocaml/baseline/ackermann.ml
Normal file
8
lib/ocaml/baseline/ackermann.ml
Normal file
@@ -0,0 +1,8 @@
|
||||
let rec ack m n =
|
||||
if m = 0 then n + 1
|
||||
else if n = 0 then ack (m - 1) 1
|
||||
else ack (m - 1) (ack m (n - 1))
|
||||
|
||||
;;
|
||||
|
||||
ack 3 4
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"ackermann.ml": 125,
|
||||
"anagrams.ml": 3,
|
||||
"bag.ml": 3,
|
||||
"balance.ml": 3,
|
||||
|
||||
@@ -407,6 +407,13 @@ _Newest first._
|
||||
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
|
||||
'a tree`) with insert + in-order traversal. Tests parametric ADT,
|
||||
recursive match, List.append, List.fold_left.
|
||||
- 2026-05-09 Phase 5.1 — ackermann.ml baseline (Ackermann function,
|
||||
ack(3, 4) = 125). Three-arm recursion: m=0 base, n=0 reduces m,
|
||||
else doubly-nested recursion `ack (m-1) (ack m (n-1))`. ack(3, 4)
|
||||
expands to ~6700 frames in our spec-level evaluator, so a useful
|
||||
exercise of the call stack and control transfer. Real OCaml
|
||||
evaluates the same in milliseconds; ours takes ~2 minutes on a
|
||||
contended host but completes correctly. 40 baseline programs total.
|
||||
- 2026-05-09 Phase 5.1 — rpn.ml baseline (Reverse Polish Notation
|
||||
evaluator using Stack). Walks the token list with List.iter, pushes
|
||||
ints onto the stack, on operator tokens pops two operands and
|
||||
|
||||
Reference in New Issue
Block a user