← Thu, Nov 19 digest

Reverse-Engineering Kevin J. Lang's Lost OCaml Code in Apache DataSketches

read article ↗ hn thread ↗

A developer used an AI agentic workflow to reverse-engineer lost OCaml simulation code and hardcoded lookup tables for Apache DataSketches' CPC sketch.

read it It offers a deep dive into numerical forensics, floating-point edge cases, and using multiple AI models to recover unrecoverable mathematical constants.

summary

When Apache DataSketches maintainers lost the original OCaml simulation code for the CPC sketch's hardcoded lookup tables due to the author's passing, a developer set up an agentic AI workflow with Gemini, Claude, and GPT to reconstruct the generators. By treating the existing static tables as an oracle, the models tested candidate hypotheses for Huffman encoding, Poisson approximations, and polynomial coefficients. The investigation uncovered subtle floating-point cancellation bugs, rounding traps, and exact mathematical derivations matching upstream constants. The successfully recovered generators are now checked into the Rust port as rigorous unit tests.

key points

  1. The CPC sketch relies on hardcoded Huffman tables, column permutations, and degree-19 polynomials whose original OCaml generators were lost when researcher Kevin J. Lang passed away.
  2. An AI agentic workflow using Gemini, Claude, and GPT tested mathematical models against the static tables as a numerical oracle to reconstruct the exact derivations.
  3. Analysis revealed that Poisson occupancy models and direct exponential evaluation were critical to reproducing upstream constants down to IEEE-754 double-precision noise.

who should read it

Software engineers and data scientists interested in numerical computing, algorithmic optimization, and reverse-engineering legacy code.

discussion positive

best comment by hellerve ↗

That’s quite fun, thanks! (Not super far yet)

For some of these lookup tables, I wonder why we wouldn’t just use a macro to generate them (the deterministic ones like Huffman encodings, not the Monte Carlo ones) instead of hardcoding and then using the algorithm in the test. But maybe I’m just being a macro fiend again.

A commenter wonders why deterministic lookup tables aren't generated via compile-time macros instead of hardcoded arrays verified by tests.

Generated by an LLM from the article and thread. Check the sources before relying on it.