Files
rose-ash/lib/ocaml/baseline
giles eb621240d7
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
ocaml: phase 5.1 simpson_int.ml baseline (Simpson 1/3 rule, integral_0^1 x^2 -> 10000)
Composite Simpson's 1/3 rule with 100 panels:

  let simpson f a b n =
    let h = (b -. a) /. float_of_int n in
    let sum = ref (f a +. f b) in
    for i = 1 to n - 1 do
      let x = a +. float_of_int i *. h in
      let coef = if i mod 2 = 0 then 2.0 else 4.0 in
      sum := !sum +. coef *. f x
    done;
    h *. !sum /. 3.0

The 1-4-2-4-...-4-1 coefficient pattern is implemented via even/odd
index dispatch. Endpoints get coefficient 1.

For x^2 over [0, 1], exact value is 1/3 ~= 0.33333. Scaled by 30000
gives 9999.99..., int_of_float -> 10000.

Tests higher-order function (passing the integrand 'fun x -> x *. x'),
float arithmetic in for-loop, and float_of_int for index->x conversion.

89 baseline programs total.
2026-05-09 18:09:33 +00:00
..