Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The vertices of height hhh are numbered 2h,3⋅2h,5⋅2h,…2^h, 3\cdot 2^h, 5\cdot 2^h, \dots2h,3⋅2h,5⋅2h,… from left to right

Proved
HarelTarjan.SymOrder.height_numbering

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

binary-treenumber-theoryp2o-batch-p100bp2o-gran-per-chapterp2o-plan-paperp2o-v1trees

Let TTT be the complete binary tree of depth ddd, numbered in symmetric order. For any height hhh, the vertices of height hhh are numbered 2h,3⋅2h,5⋅2h,…2^h, 3\cdot 2^h, 5\cdot 2^h, \dots2h,3⋅2h,5⋅2h,… from left to right. Precisely:

  1. every vertex vvv that is the jjj-th vertex of its depth from the left (counting from j=0j = 0j=0) has
sym(v)=(2j+1)⋅2h(v);\mathrm{sym}(v) = (2j+1)\cdot 2^{h(v)};sym(v)=(2j+1)⋅2h(v);
  1. for every height h≤dh \le dh≤d, the set of numbers of the vertices of height hhh is {(2j+1)⋅2h:0≤j<2d−h}\{(2j+1)\cdot 2^h : 0 \le j < 2^{d-h}\}{(2j+1)⋅2h:0≤j<2d−h}.

This is the basic fact about the numbering from which Lemmas 1–4 of §3 are verified.

Formalization Note "The jjj-th vertex from the left" is leftIndex v = j, the path to vvv read as a binary numeral (left =0=0=0, right =1=1=1, most significant turn first). The subtraction d−hd - hd−h is on N\mathbb NN under h≤dh \le dh≤d.

Preamble
import Mathlib
import Definitions.Def_HarelTarjan_SymOrder_Tree
import Definitions.Def_HarelTarjan_SymOrder_Sym
Formal statement
namespace HarelTarjan.SymOrder

/-- The numbers at height `h` (§3, p. 341): the vertices of height `h` are numbered
`2^h, 3·2^h, 5·2^h, …` from left to right. Pointwise, the vertex `v` that is `j`-th from the left
(counting from `0`) among the vertices of its depth has number `(2j + 1)·2^{h(v)}`; and for each
height `h ≤ d` the set of numbers of the vertices of height `h` is
`{(2j + 1)·2^h : 0 ≤ j < 2^{d−h}}`. -/
theorem height_numbering {d : ℕ} :
    (∀ v : Vertex d, sym v = (2 * leftIndex v + 1) * 2 ^ height v) ∧
      ∀ h : ℕ, h ≤ d →
        (Finset.univ.filter (fun v : Vertex d => height v = h)).image sym =
          (Finset.range (2 ^ (d - h))).image (fun j => (2 * j + 1) * 2 ^ h) := by sorry

end HarelTarjan.SymOrder
Source
Harel, Tarjan, Fast Algorithms for Finding Nearest Common Ancestors, SIAM J. Comput. 13 (1984), p. 341, §3, last paragraph (unnumbered)
Read-back

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

This theorem gives a closed formula for sym⁡\operatorname{sym}sym. Let d∈Nd\in\mathbb Nd∈N and let TdT_dTd​ be the set of boolean sequences sv=(b1,…,bm)s_v=(b_1,\dots,b_m)sv​=(b1​,…,bm​) with m≤dm\le dm≤d. The height is h(v)=d−mh(v)=d-mh(v)=d−m. The left index is leftIndex⁡(v)=∑i=1m[bi] 2m−i\operatorname{leftIndex}(v)=\sum_{i=1}^m[b_i]\,2^{m-i}leftIndex(v)=∑i=1m​[bi​]2m−i, i.e. svs_vsv​ read as a binary numeral with true =1=1=1, most significant entry first. The number sym⁡(v)\operatorname{sym}(v)sym(v) counts the u∈Tdu\in T_du∈Td​ with κ(u)≤lexκ(v)\kappa(u)\le_{\mathrm{lex}}\kappa(v)κ(u)≤lex​κ(v). The key κ\kappaκ replaces false by 000 and true by 222 and appends 111, and the order is lexicographic with a proper prefix counting as smaller.

The theorem asserts two things:

  1. For every vertex vvv,
sym⁡(v)=(2leftIndex⁡(v)+1)⋅2h(v).\operatorname{sym}(v)=(2\operatorname{leftIndex}(v)+1)\cdot 2^{h(v)}.sym(v)=(2leftIndex(v)+1)⋅2h(v).
  1. For every h≤dh\le dh≤d, the set of values sym⁡(v)\operatorname{sym}(v)sym(v) over the vertices vvv with h(v)=hh(v)=hh(v)=h equals
{(2j+1) 2h:0≤j<2d−h}.\{(2j+1)\,2^h : 0\le j<2^{d-h}\}.{(2j+1)2h:0≤j<2d−h}.

Degenerate cases:

  • For the root, leftIndex⁡=0\operatorname{leftIndex}=0leftIndex=0 and h=dh=dh=d, so part 1 gives sym⁡=2d\operatorname{sym}=2^dsym=2d.
  • For d=0d=0d=0, only h=0h=0h=0 is covered, and both sides of part 2 are {1}\{1\}{1}.
  • Part 2 says nothing about heights h>dh>dh>d.
  • The subtraction d−hd-hd−h in part 2 never truncates, because h≤dh\le dh≤d.
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 paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me