Prove2Me
Navigate
DiscoverFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Proof of Theorem 1 (p. 340) — a nonleaf www lies in AxA_xAx​ for all leaves below one of its children

Proved
HarelTarjan.PointerLB.nonleaf_dichotomy

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

lower-boundnearest-common-ancestorp2o-batch-p100bp2o-gran-per-chapterp2o-plan-paperp2o-v1pointer-machine

Let TTT be the complete binary tree of height hhh, represented in a list structure with two pointers per node by a map rep\mathrm{rep}rep from vertices to nodes, and suppose that every nca query on two leaves is answered in kkk steps. For a leaf xxx let AxA_xAx​ be the set of tree vertices whose nodes are accessible from rep(x)\mathrm{rep}(x)rep(x) in kkk steps or less.

Let www be a nonleaf vertex of TTT, with children u=w0u = w0u=w0 and v=w1v = w1v=w1. Then either

w∈Ax for every leaf x that is a descendant of u,orw∈Ay for every leaf y that is a descendant of v.w \in A_x \text{ for every leaf } x \text{ that is a descendant of } u, \quad\text{or}\quad w \in A_y \text{ for every leaf } y \text{ that is a descendant of } v.w∈Ax​ for every leaf x that is a descendant of u,orw∈Ay​ for every leaf y that is a descendant of v.

This dichotomy is what forces every vertex to be seen from many leaves, and it drives the counting in the proof of Theorem 1.

Formalization Note The statement does not assume that rep\mathrm{rep}rep is injective; the paper's representation is, and the claim holds without it.

Preamble
import Mathlib
import Definitions.Def_HarelTarjan_PointerLB_BinaryTree
import Definitions.Def_HarelTarjan_PointerLB_PointerMachine
Formal statement
namespace HarelTarjan.PointerLB

theorem nonleaf_dichotomy {N : Type*} {h k : ℕ} (ptr : N → Fin 2 → Option N)
    (rep : Vertex h → N) (hk : AnswersLeafQueriesIn ptr rep k)
    (w : Vertex h) (hw : w.1.length < h) :
    (∀ x : Vertex h, IsLeaf x → w.1 ++ [false] <+: x.1 → w ∈ A ptr rep k x) ∨
      (∀ y : Vertex h, IsLeaf y → w.1 ++ [true] <+: y.1 → w ∈ A ptr rep k y) := by sorry

end HarelTarjan.PointerLB
Source
Harel, Tarjan, Fast Algorithms for Finding Nearest Common Ancestors, SIAM J. Comput. 13 (1984), p. 340, proof of Theorem 1, first paragraph ("We claim that either …")
Read-back

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

Setup.

  • h,k∈Nh,k\in\mathbb{N}h,k∈N, and NNN is any type of nodes.
  • ptr\mathrm{ptr}ptr assigns to each node mmm and field i∈{0,1}i\in\{0,1\}i∈{0,1} a node or nil.
  • rep\mathrm{rep}rep is an arbitrary map, not necessarily injective, from vertices of the height-hhh complete binary tree to nodes. A vertex is a boolean sequence of length at most hhh; a leaf is a vertex of length exactly hhh.

Let acck(a)\mathrm{acc}_k(a)acck​(a) be the set of nodes reachable from aaa by following at most kkk non-nil pointer fields. For a vertex xxx, define:

Ax={t:rep(t)∈acck(rep(x))}.A_x=\{t : \mathrm{rep}(t)\in\mathrm{acc}_k(\mathrm{rep}(x))\}.Ax​={t:rep(t)∈acck​(rep(x))}.

Hypotheses.

  • For every pair of leaves x,yx, yx,y, some run of at most kkk steps holds rep(nca(x,y))\mathrm{rep}(\mathrm{nca}(x,y))rep(nca(x,y)). A run starts holding [rep(x),rep(y)][\mathrm{rep}(x),\mathrm{rep}(y)][rep(x),rep(y)], and each step adds a non-nil field ptr(m,i)\mathrm{ptr}(m,i)ptr(m,i) of a held node mmm. Here nca(x,y)\mathrm{nca}(x,y)nca(x,y) is the longest common prefix of xxx and yyy.
  • www is a vertex with ∣w∣<h|w|<h∣w∣<h, that is, a non-leaf.

Conclusion. At least one of the following holds:

  • for every leaf xxx whose sequence begins with www followed by false: w∈Axw\in A_xw∈Ax​;
  • for every leaf yyy whose sequence begins with www followed by true: w∈Ayw\in A_yw∈Ay​.

Degenerate cases.

  • When h=0h=0h=0, no vertex satisfies ∣w∣<0|w|<0∣w∣<0, so the statement is vacuous.
  • If rep\mathrm{rep}rep is not injective, "w∈Axw\in A_xw∈Ax​" means only that the node rep(w)\mathrm{rep}(w)rep(w) is reachable. That node may also represent other vertices.
  • For k=0k=0k=0 and h≥1h\ge1h≥1, the query hypothesis can be satisfied only if rep(nca(x,y))∈{rep(x),rep(y)}\mathrm{rep}(\mathrm{nca}(x,y))\in\{\mathrm{rep}(x),\mathrm{rep}(y)\}rep(nca(x,y))∈{rep(x),rep(y)} for all leaf pairs. This requires a non-injective rep\mathrm{rep}rep; otherwise the hypothesis is unsatisfiable.
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