From 70b9b4f6cf38dfa6aff86eec1caa8c6b481ca5d3 Mon Sep 17 00:00:00 2001 From: giles Date: Sat, 9 May 2026 08:50:12 +0000 Subject: [PATCH] ocaml: phase 5.1 ackermann.ml baseline (ack(3, 4) = 125) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- lib/ocaml/baseline/ackermann.ml | 8 ++++++++ lib/ocaml/baseline/expected.json | 1 + plans/ocaml-on-sx.md | 7 +++++++ 3 files changed, 16 insertions(+) create mode 100644 lib/ocaml/baseline/ackermann.ml diff --git a/lib/ocaml/baseline/ackermann.ml b/lib/ocaml/baseline/ackermann.ml new file mode 100644 index 00000000..8964ab06 --- /dev/null +++ b/lib/ocaml/baseline/ackermann.ml @@ -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 diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index f2f5b5c2..dce3387c 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -1,4 +1,5 @@ { + "ackermann.ml": 125, "anagrams.ml": 3, "bag.ml": 3, "balance.ml": 3, diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index a5c1e94f..c1386138 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -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