# Lean 4 and differential testing expose 17 unreported bugs in Clojure's core

Original title: I checked Clojure's core with Lean and found unreported bugs

> Hacker News story 50642939 · language: en · submitted 2026-11-25
> Web version: https://zeli.app/story/50642939
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 153 · by [encyclopedism](<https://news.ycombinator.com/user?id=encyclopedism>) · 💬 53
[original](<https://s.conao3.com/blog/2026/e4f733>) · [HN discussion](<https://news.ycombinator.com/item?id=50642939>)

## Summary

After reading how Lean 4 formal verification uncovered bugs in popular Rust projects, the author applied the same approach to Clojure's Java core. Modeling integer and bit arithmetic in Lean and running differential tests against java.util collections, they found 17 bugs not reported in Clojure's JIRA or ask.clojure.org. These include an infinite loop in reduce on vector-of, a HAMT collision node losing keys after dissoc, and inconsistent removeIf behavior with type hints. The HAMT and vector trees themselves passed millions of operations.

## Key quote

> The HAMT itself showed no mismatch in 3 million operations of differential testing, and the vector tree showed none around its boundaries. The bugs sat in separate code outside the trees, and in places where two mechanisms meet, such as = and hashing.

## HN discussion (53 comments)

### [rvprasad](<https://news.ycombinator.com/item?id=50645750>)

> While the effort is interesting, I found two issues in the list.
>
> First, (.indexOf (seq (byte-array [1 2 3])) 2) fails because byte arrays store bytes and the argument 2 to `.indexOf` is a Long value.  Simple type checking (via eyeballing) could have flagged the incorrect usage.  I think such exercises can be more helpful if we can reduce the noise.
>
> Second, (get "abc" 1.9) fails because `get` coerces the given key to integer in the context of string objects, which makes sense; specifically in the context of weakly typed language.  That said, I believe that detailed documentation of the behavior of `get` can help clients just as well as returning `nil` or not-found value.  However, we are still left with questions such as "who and where do we draw the line about the dynamism of the language?" and "what is the agreed upon semantics that we are checking against?"

### [yababa_y](<https://news.ycombinator.com/item?id=50647213>)

> I found dozens of issues in sbcl, clozure, and ACL2 as well: https://github.com/emberian/common-lisp-compiler-audit

### [networked](<https://news.ycombinator.com/item?id=50646090>)

> So this kind of work is done in Lean now, too? Based on a glimpse into the world of dependently typed languages in the 2010s, I assumed Rocq (formerly Coq) was used to verify program correctness.
>
> Are language models significantly better at writing Lean than Rocq?

### [vitorsr](<https://news.ycombinator.com/item?id=50645910>)

> That is interesting, given heavy hitters like Nubank (Brazilian digital bank) basically runs on Clojure, having bought / acquihired Rich's Cognitect. I would normally expect such primitive types and functions to be spotless.

### [siscia](<https://news.ycombinator.com/item?id=50646011>)

> I really need to learn Lean and these testing mechanism

---

## Cite

- Page: https://zeli.app/story/50642939
- Date: 2026-11-25
- Source: s.conao3.com (https://s.conao3.com/blog/2026/e4f733)
- Hacker News: https://news.ycombinator.com/item?id=50642939

## Other languages

- zh: https://zeli.app/zh/story/50642939 · markdown: https://zeli.app/zh/story/50642939.md
- ja: https://zeli.app/ja/story/50642939 · markdown: https://zeli.app/ja/story/50642939.md
- ko: https://zeli.app/ko/story/50642939 · markdown: https://zeli.app/ko/story/50642939.md
- de: https://zeli.app/de/story/50642939 · markdown: https://zeli.app/de/story/50642939.md
- es: https://zeli.app/es/story/50642939 · markdown: https://zeli.app/es/story/50642939.md
- ru: https://zeli.app/ru/story/50642939 · markdown: https://zeli.app/ru/story/50642939.md
