Prove2Me
Navigate
DiscoverFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Lemma 8 — for any rank iii, the number of vertices of rank iii is at most n/2in/2^in/2i

Proved
HarelTarjan.Compressed.lemma8_rank_count

by mikedeng1 · Sep 27, 2026 · Mathlib 0df444a (Lean v4.33.1)

heavy-pathnearest-common-ancestorp2o-batch-p100bp2o-gran-per-chapterp2o-plan-paperp2o-v1trees

Let TTT be a rooted tree on nnn vertices and CCC its compressed tree, with rank(v)=⌊lg⁡sizeC(v)⌋\mathrm{rank}(v) = \lfloor \lg \mathrm{size}_C(v)\rfloorrank(v)=⌊lgsizeC​(v)⌋. For every i≥0i \ge 0i≥0,

#{ v:rank(v)=i }≤n2i.\#\{\, v : \mathrm{rank}(v) = i \,\} \le \frac{n}{2^i}.#{v:rank(v)=i}≤2in​.

Few vertices have high rank. Summed over i≥ki \ge ki≥k this gives the count of high-rank vertices used for Lemma 9.

Formalization Note The bound is stated without division as #{v:rank(v)=i}⋅2i≤n\#\{v : \mathrm{rank}(v) = i\}\cdot 2^i \le n#{v:rank(v)=i}⋅2i≤n, which is equivalent over the reals.

Preamble
import Mathlib
import Definitions.Def_HarelTarjan_Compressed_RootedTree
import Definitions.Def_HarelTarjan_Compressed_HeavyPath
import Definitions.Def_HarelTarjan_Compressed_CompressedTree
Formal statement
namespace HarelTarjan.Compressed

theorem lemma8_rank_count {V : Type*} [Fintype V] [DecidableEq V] (T : RootedTree V) (i : ℕ) :
    (Finset.univ.filter (fun v => rank T v = i)).card * 2 ^ i ≤ Fintype.card V := by sorry

end HarelTarjan.Compressed
Source
Harel, Tarjan, Fast Algorithms for Finding Nearest Common Ancestors, SIAM J. Comput. 13 (1984), p. 344, Lemma 8
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

Setting. VVV is any finite type with decidable equality. TTT is any rooted tree on VVV with root rrr and parent map ppp, where:

  • p(r)=rp(r) = rp(r)=r;
  • every vertex reaches rrr under some iterate pip^ipi, i≥0i \ge 0i≥0.

iii is any natural number.

Definitions used.

  • size⁡T(w)\operatorname{size}_T(w)sizeT​(w) is the number of uuu with pj(u)=wp^j(u) = wpj(u)=w for some j≥0j \ge 0j≥0, including www itself.
  • A vertex xxx is heavy when x≠rx \ne rx=r and size⁡T(p(x))<2 size⁡T(x)\operatorname{size}_T(p(x)) < 2\,\operatorname{size}_T(x)sizeT​(p(x))<2sizeT​(x).
  • apex⁡(x)=pk(x)\operatorname{apex}(x) = p^k(x)apex(x)=pk(x) for the least k≥0k \ge 0k≥0 with pk(x)p^k(x)pk(x) not heavy.
  • The compressed parent is pC(r)=rp_C(r) = rpC​(r)=r, and pC(x)=apex⁡(p(x))p_C(x) = \operatorname{apex}(p(x))pC​(x)=apex(p(x)) for x≠rx \ne rx=r.
  • size⁡C(w)\operatorname{size}_C(w)sizeC​(w) is the number of uuu with pCj(u)=wp_C^j(u) = wpCj​(u)=w for some j≥0j \ge 0j≥0, including www itself.
  • rank⁡(v)=⌊log⁡2size⁡C(v)⌋\operatorname{rank}(v) = \lfloor \log_2 \operatorname{size}_C(v) \rfloorrank(v)=⌊log2​sizeC​(v)⌋.

Statement. The theorem asserts

#{v∈V:rank⁡(v)=i}⋅2i≤∣V∣.\#\{v \in V : \operatorname{rank}(v) = i\} \cdot 2^i \le |V|.#{v∈V:rank(v)=i}⋅2i≤∣V∣.

In words: at most ∣V∣/2i|V|/2^i∣V∣/2i vertices have rank exactly iii.

Degenerate cases.

  • For i=0i = 0i=0 the claim is only that the number of rank-000 vertices is at most ∣V∣|V|∣V∣, which is trivially true.
  • For iii larger than every attained rank, the left side is 000.
  • If ∣V∣=1|V| = 1∣V∣=1, the single vertex has rank 000, and the claim reduces to 1≤11 \le 11≤1 for i=0i = 0i=0 and 0≤10 \le 10≤1 otherwise.
Human review
  • Endorsed by Shuze Chen · Sep 27, 2026

    Confirmed by the moderator at approval.

  • Endorsed by mikedeng1 · Sep 27, 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 paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me