Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Random typing produces a power law in rank (Li's model)

Proved
ZipfLaw.monkey_typing_power_law

by Lucas · Oct 9, 2026 · Mathlib 0df444a (Lean v4.33.1)

harmonic-numberspower-lawzipf-law

Consider a monkey typing on a keyboard with m≥2m\ge2m≥2 letter keys, each pressed with the same probability q>0q>0q>0, and a space bar pressed with probability 1−mq>01-mq>01−mq>0. The probability that the word following a space is exactly the string www of letters is p(w)=q∣w∣(1−mq)p(w)=q^{|w|}(1-mq)p(w)=q∣w∣(1−mq). List all nonempty words in order of non-increasing probability, w1,w2,w3,…w_1,w_2,w_3,\dotsw1​,w2​,w3​,… (ties in any order). Then the probability of the word of rank rrr obeys a power law in rrr: with α=log⁡m(1/q)\alpha=\log_m(1/q)α=logm​(1/q) there are constants 0<C1≤C20<C_1\le C_20<C1​≤C2​ such that for all r≥1r\ge1r≥1

C1 r−α≤p(wr)≤C2 r−α.C_1\,r^{-\alpha}\le p(w_r)\le C_2\,r^{-\alpha}.C1​r−α≤p(wr​)≤C2​r−α.

Formalization Note. Ranks are 000-indexed in Lean: the rank order is a bijection e:N→{nonempty words}e:\mathbb N\to\{\text{nonempty words}\}e:N→{nonempty words} along which ppp is non-increasing, and the bound is stated with (r+1)−α(r+1)^{-\alpha}(r+1)−α.

Preamble
import Mathlib
import Definitions.Def_ZipfLaw_Defs
Formal statement
namespace ZipfLaw

theorem monkey_typing_power_law (m : ℕ) (hm : 2 ≤ m) (q : ℝ) (hq : 0 < q) (hmq : (m : ℝ) * q < 1)
    (e : ℕ → List (Fin m)) (he_inj : Function.Injective e)
    (he_range : Set.range e = {w | w ≠ []})
    (he_sorted : Antitone (fun r => monkeyWordProb m q (e r))) :
    ∃ C₁ C₂ : ℝ, 0 < C₁ ∧ 0 < C₂ ∧ ∀ r : ℕ,
      C₁ * ((r : ℝ) + 1) ^ (-Real.logb m (1 / q)) ≤ monkeyWordProb m q (e r) ∧
        monkeyWordProb m q (e r) ≤ C₂ * ((r : ℝ) + 1) ^ (-Real.logb m (1 / q)) := by sorry

end ZipfLaw
Source
Wikipedia, "Zipf's law" (https://en.wikipedia.org/wiki/Zipf%27s_law), snapshot uploaded by the proposer, section "Statistical explanations" (Li: "in a document in which each character has been chosen randomly from a uniform distribution of all letters (plus a space character), the 'words' with different lengths follow the macro-trend of Zipf's law"; ref. Li 1992, https://doi.org/10.1109/18.165464).
Read-back

What the Lean code literally says, in plain math · Aristotle (Harmonic) - non-blind, same agent as the drafter

Non-blind read-back — not independent testimony. This read-back was written by the same agent (Aristotle, by Harmonic) that drafted the Lean statement, with full knowledge of the source article and of the intended meaning. It is not a blind audit by an independent reader, and no reviewer should treat it as one. Please compare it against the Lean code yourself.

Let m≥2m\ge2m≥2 be a natural number, qqq a real with q>0q>0q>0 and mq<1mq<1mq<1. Let eee be a function from N\mathbb NN to finite lists over an mmm-letter alphabet which is injective, whose image is exactly the set of nonempty lists, and such that r↦q∣e(r)∣(1−mq)r\mapsto q^{|e(r)|}(1-mq)r↦q∣e(r)∣(1−mq) is antitone (non-increasing in rrr). Then there exist reals C1>0C_1>0C1​>0 and C2>0C_2>0C2​>0 such that for every natural rrr:

C1 (r+1)−log⁡m(1/q)≤q∣e(r)∣(1−mq)≤C2 (r+1)−log⁡m(1/q),C_1\,(r+1)^{-\log_m(1/q)}\le q^{|e(r)|}(1-mq)\le C_2\,(r+1)^{-\log_m(1/q)},C1​(r+1)−logm​(1/q)≤q∣e(r)∣(1−mq)≤C2​(r+1)−logm​(1/q),

with log⁡m(1/q)=ln⁡(1/q)/ln⁡m\log_m(1/q)=\ln(1/q)/\ln mlogm​(1/q)=ln(1/q)/lnm and real powers.

Human review
  • Endorsed by Shuze Chen · Oct 10, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Lucas · Oct 10, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me