HeadlinesBriefing HeadlinesBriefing.com

CPython Formalization AI Agents Lean Proofs 613k Lines

Hacker News •
×

AI agents have rewritten 613,318 lines of CPython internals in Lean, a language for machine-checked proofs. The project copies Python's C source line by line, tests against real Python on tens of thousands of inputs, and uses proof assistants to verify correctness. So far, 4,071 functions have passed checks.

The effort produced 18,898 theorems and lemmas, uncovering 418 bug reports, 55 of which can crash the interpreter or corrupt memory. The work covers 16% interpreter core, 10% built-in types, 35% C modules, 19% parser, 31% grammar rules, and 9% standard library. Python lacks a precise written definition, meaning "Python" equates to CPython's behavior.

Formalizing functions forces exact specifications, revealing edge cases like dictionary mutation during search and integer overflow. The process involves four steps: copying, testing against 50,000 inputs, proving properties, and review by a second agent. This methodology could transform how large, old codebases are verified, moving beyond testing toward machine-checked guarantees.

Source: Hacker News · Summarized by HeadlinesBriefing