diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index b97ffddf..35b76e82 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -22,6 +22,7 @@ "hanoi.ml": 1023, "fizzbuzz.ml": 57, "list_ops.ml": 30, + "mat_mul.ml": 621, "json_pretty.ml": 24, "kadane.ml": 6, "lambda_calc.ml": 7, diff --git a/lib/ocaml/baseline/mat_mul.ml b/lib/ocaml/baseline/mat_mul.ml new file mode 100644 index 00000000..e7593f4f --- /dev/null +++ b/lib/ocaml/baseline/mat_mul.ml @@ -0,0 +1,18 @@ +let mat_mul a b n = + let c = Array.make (n * n) 0 in + for i = 0 to n - 1 do + for j = 0 to n - 1 do + for k = 0 to n - 1 do + c.(i * n + j) <- c.(i * n + j) + a.(i * n + k) * b.(k * n + j) + done + done + done; + c + +;; + +let n = 3 in +let a = Array.of_list [1;2;3; 4;5;6; 7;8;9] in +let b = Array.of_list [9;8;7; 6;5;4; 3;2;1] in +let c = mat_mul a b n in +Array.fold_left (+) 0 c diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index 5a516692..68e5a959 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 — mat_mul.ml baseline (3x3 row-major matrix + multiply, sum of result = 621). Triple-nested for loop over + i / j / k with row-major indexing `c.(i * n + j) <- c.(i * n + j) + + a.(i * n + k) * b.(k * n + j)`. Tests deeply nested for loops on + Array, Array.make + arr.(i) + arr.(i) <- v + Array.fold_left, and + multi-arg let chains with intermediate Array bindings. 50 baseline + programs total — milestone. - 2026-05-09 Phase 5.1 — bsearch.ml baseline (binary search, position-sum 6 + 2 + (-1) = 7). Iterative bsearch on a sorted int array using two index refs `lo`/`hi` and a sentinel `found = -1`.