Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Layer recurrence for breadth-first search

Proved
WilliamsonShmoys.bfs_layer_step

by もち · Nov 24, 2026 · Mathlib 0df444a (Lean v4.33.1)

bfsgraph-theory

Let GGG be a simple graph, r,wr,wr,w vertices and t∈Nt\in\mathbb Nt∈N. Suppose www is not reachable from rrr within distance ttt, that is, not (www reachable from rrr and dist⁡(r,w)≤t\operatorname{dist}(r,w)\le tdist(r,w)≤t). Then

(w reachable from r ∧ dist⁡(r,w)=t+1)  ⟺  ∃u: u reachable from r, dist⁡(r,u)=t, u∼w.\bigl(w\text{ reachable from }r\ \wedge\ \operatorname{dist}(r,w)=t+1\bigr)\iff\exists u:\ u\text{ reachable from }r,\ \operatorname{dist}(r,u)=t,\ u\sim w.(w reachable from r ∧ dist(r,w)=t+1)⟺∃u: u reachable from r, dist(r,u)=t, u∼w.

This is the recurrence behind layer-by-layer breadth-first search: the vertices at distance exactly t+1t+1t+1 are the vertices not yet reached that have a neighbour at distance ttt. It is the correctness core of an O(n2)O(n^2)O(n2) RAM computation of Baker's BFS levels, which scans the adjacency row of each vertex once.

Formalization Note. dist⁡\operatorname{dist}dist is SimpleGraph.dist, which is 000 for unreachable pairs; reachability is stated explicitly for that reason.

Preamble
import Mathlib

set_option autoImplicit false
Formal statement
theorem WilliamsonShmoys.bfs_layer_step {V : Type} (G : SimpleGraph V) (r w : V) (t : ℕ)
    (hw : ¬ (G.Reachable r w ∧ G.dist r w ≤ t)) :
    (G.Reachable r w ∧ G.dist r w = t + 1) ↔
      ∃ u, G.Reachable r u ∧ G.dist r u = t ∧ G.Adj u w := by sorry
Source
Standard BFS layering; used for the RAM computation of Baker levels in Williamson–Shmoys, Sect. 10.2, p. 270

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