Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Lemma 2 — the descendants of vvv have numbers in [sym(v)−2h(v)+1,sym(v)+2h(v)−1][\mathrm{sym}(v)-2^{h(v)}+1, \mathrm{sym}(v)+2^{h(v)}-1][sym(v)−2h(v)+1,sym(v)+2h(v)−1]

Proved
HarelTarjan.SymOrder.lemma2_descendants_range

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

binary-treep2o-batch-p100bp2o-gran-per-chapterp2o-plan-paperp2o-v1trees

Let TTT be the complete binary tree of depth ddd, numbered in symmetric order. The descendants of a vertex vvv are exactly the vertices with numbers in the range

[sym(v)−2h(v)+1, sym(v)+2h(v)−1].\left[\mathrm{sym}(v) - 2^{h(v)} + 1,\ \mathrm{sym}(v) + 2^{h(v)} - 1\right].[sym(v)−2h(v)+1, sym(v)+2h(v)−1].

That is, for all vertices v,wv, wv,w: www is a descendant of vvv if and only if sym(v)−2h(v)+1≤sym(w)≤sym(v)+2h(v)−1\mathrm{sym}(v) - 2^{h(v)} + 1 \le \mathrm{sym}(w) \le \mathrm{sym}(v) + 2^{h(v)} - 1sym(v)−2h(v)+1≤sym(w)≤sym(v)+2h(v)−1.

Lemma 2 is the ancestor test of the nca depth algorithm.

Formalization Note The two inequalities are stated additively, sym(v)+1≤sym(w)+2h(v)\mathrm{sym}(v) + 1 \le \mathrm{sym}(w) + 2^{h(v)}sym(v)+1≤sym(w)+2h(v) and sym(w)+1≤sym(v)+2h(v)\mathrm{sym}(w) + 1 \le \mathrm{sym}(v) + 2^{h(v)}sym(w)+1≤sym(v)+2h(v), which are equivalent over the integers and avoid truncated subtraction.

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

/-- Lemma 2 (p. 342): the descendants of vertex `v` are those vertices with numbers in the range
`[sym(v) − 2^{h(v)} + 1, sym(v) + 2^{h(v)} − 1]`. The two endpoint inequalities are written
additively, to avoid truncated subtraction on `ℕ`. -/
theorem lemma2_descendants_range {d : ℕ} (v w : Vertex d) :
    IsAncestor v w ↔
      (sym v + 1 ≤ sym w + 2 ^ height v ∧ sym w + 1 ≤ sym v + 2 ^ height v) := by sorry

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

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

This theorem characterises ancestry by the numbers sym⁡\operatorname{sym}sym. Let d∈Nd\in\mathbb Nd∈N and let TdT_dTd​ be the set of boolean sequences of length ≤d\le d≤d. The height is h(v)=d−∣sv∣h(v)=d-|s_v|h(v)=d−∣sv​∣, and vvv is an ancestor of www when svs_vsv​ is a prefix of sws_wsw​, equality allowed. 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.

For all v,w∈Tdv,w\in T_dv,w∈Td​, the theorem asserts that vvv is an ancestor of www if and only if both of these hold:

sym⁡(v)+1≤sym⁡(w)+2h(v)andsym⁡(w)+1≤sym⁡(v)+2h(v).\operatorname{sym}(v)+1\le\operatorname{sym}(w)+2^{h(v)}\quad\text{and}\quad\operatorname{sym}(w)+1\le\operatorname{sym}(v)+2^{h(v)}.sym(v)+1≤sym(w)+2h(v)andsym(w)+1≤sym(v)+2h(v).

Over the integers, the two conditions together say

sym⁡(v)−2h(v)+1≤sym⁡(w)≤sym⁡(v)+2h(v)−1.\operatorname{sym}(v)-2^{h(v)}+1\le\operatorname{sym}(w)\le\operatorname{sym}(v)+2^{h(v)}-1.sym(v)−2h(v)+1≤sym(w)≤sym(v)+2h(v)−1.

Degenerate cases:

  • If w=vw=vw=v, both sides are true.
  • For a leaf vvv (where h=0h=0h=0), the range collapses to sym⁡(w)=sym⁡(v)\operatorname{sym}(w)=\operatorname{sym}(v)sym(w)=sym(v).
  • For d=0d=0d=0, only the root exists and the claim is trivial.
  • Everything is stated additively on the naturals, so no truncated subtraction occurs.
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