TRANSMISSION // 2611.28430v1

What AI-Written Lean Libraries Look Like

Source published

A comparison of six Lean libraries finds recurring differences in proof structure and design—but the small, varied sample cannot show that AI authorship caused them.

AI-generated conceptual illustration for What AI-Written Lean Libraries Look Like
AI-generated conceptual illustration; not documentary evidence.

Can simple code statistics reveal how AI-generated mathematics libraries differ from human-reviewed ones? A preprint compares four AI-generated and two human-written Lean libraries with Mathlib, finding patterns in proofs and design choices while emphasizing that purpose, age and subject may also matter.

Lean is a proof assistant: it checks formal mathematical statements and their proofs, while also serving as a programming language for building reusable libraries. A proof can be correct and still be difficult for other people to understand or build on. This study asks whether the structure of AI-generated Lean libraries differs from that of human-reviewed libraries—and whether simple measurements can help describe those differences.

Justin Asher and Pietro Pellegrino compared four AI-generated libraries with two human-written ones, using Mathlib, a large established Lean library, as a reference. They classified a library as human-written when people review every contribution, even if AI helped draft some code; AI-generated libraries were written with little or no line-by-line human review.

The researchers used a Lean program to record declarations—theorems, definitions, instances and types—and the references in their statements and proofs. They also counted source tokens and, in a second pass, examined elaborated proofs to measure tactic steps and intermediate claims. Their measures included proof length, how often declarations were used, and design choices such as type-class instances and private declarations. They compared whole distributions, not just averages, and set Mathlib’s 26 top-level areas alongside the six libraries to show how much statistics vary within human-written code.

Patterns in proofs and library design

Across the sample, the AI-generated libraries had more inline claims per theorem: 0.81 to 3.22, compared with 0.21 to 0.64 in the human-written libraries. An inline claim is an intermediate fact proved inside a particular theorem, typically with Lean’s have or suffices. Unlike a separately named lemma, it cannot be directly reused by another declaration. The AI-generated libraries also had longer median proofs, measured in source tokens: 22 to 49, versus 10 to 17.

The pattern extended beyond proof length. AI-generated libraries registered a smaller share of declarations as instances, which let Lean apply general results to structures automatically: 0.8% to 3.2%, compared with 5.4% to 10.7% in the human-written libraries. They marked more declarations private, meaning other files cannot use them: 14% to 37%, versus 1% to 4%. Their theorems also more often had three or more explicit arguments, which can mean users must supply more information when applying them.

Some reuse measures pointed in the same direction. In two AI-generated libraries, at least half of the source text was in declarations used exactly once within the library, compared with 31% in Mathlib. Such declarations may form chains of supporting results without becoming widely reusable. That is a description of these codebases, not proof that every single-use declaration is unnecessary.

The authors are careful not to treat these patterns as a score of correctness or overall quality. Mathlib’s own areas differ substantially, and proof style appears sensitive to what a library is for. In particular, Mathlib’s Archive and Counterexamples—collections of one-off proofs—had inline-claim patterns closer to the AI-generated libraries. Yet their rates of instances, private declarations and explicit arguments looked more like Mathlib. This suggests that purpose may help explain proof structure, but does not account for every observed difference.

What the comparison cannot settle

The comparison is small: two human-written and four AI-generated libraries. The groups may differ in subject, aims, age, maintenance and project boundaries. Mathlib has been refactored over many years; newer projects may not yet have had the same opportunity. FormalFrontier combines 44 libraries into one unit, further complicating comparisons. The researchers also did not control for subject, and counting every have or suffices equally means a tiny step and a substantial intermediate argument receive the same count.

Most importantly, the authors say the study does not estimate an effect of authorship. These are observed differences among selected projects, not evidence that AI authorship caused them. Nor have the researchers tested whether the metrics respond as intended when code is refactored. Whether the statistics track what maintainers mean by quality remains open.

The work is a preprint, and the available source identifies it as such; it should be read as a research report rather than a settled standard for evaluating Lean code. The authors say they release their analysis code as the lean-census package, which could help others reproduce or extend the measurements. The study’s contribution is narrower but useful: it turns questions about library organization into measurable comparisons, while showing why the numbers need context.

Automatically matched by shared topic keywords. These links do not imply that the sources agree or establish a consensus.