Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

One first return to the queue test preserves the concrete invariant

Open
DirKECC1549.Main.reverse_search_queue_first_return

by parclytaxel · Nov 14, 2026 · Mathlib 0df444a (Lean v4.33.1)

graph-algorithmsword-ram

Fix a graph G with n vertices and m edges, root r, original graph-layout memory M with encoded root, and word width satisfying 32B+256 at most 2^w, where B=n+2m+3. Let s be any state satisfying ReverseSearchQueueInvariant for G, r, and M.

Run the actual lowered reverseSearchAlgorithm from s, retaining its memory and tick count. Suppose positive interpreter fuel f gives a running state t at counter 70, and no intermediate fuel j with 0<j<f gives a running state at counter 70. Then

ReverseSearchQueueInvariant⁡(G,r,M,t).\operatorname{ReverseSearchQueueInvariant}(G,r,M,t).ReverseSearchQueueInvariant(G,r,M,t).

This is preservation across one complete first return of the queue loop. The starting state need not be assumed reachable from M beyond satisfying the explicit concrete invariant. The statement neither assumes preservation across multiple queue iterations nor asserts that a return exists or gives a tick bound. All register, spill, queue, visited-array, parent-array, and scan-history conditions are explicit in the imported invariant definition.

Preamble
import Definitions.Def_DirKECC1549_Main_ReverseSearchQueueInvariant
set_option autoImplicit false
open WordRAM
Formal statement
namespace DirKECC1549.Main

theorem reverse_search_queue_first_return
    (n m : ℕ) (G : Fin m → Fin n × Fin n) (r : Fin n)
    (w : Width) (initial : Memory w) (s : State w) (fuel : ℕ)
    (hwidth : 32 * blk n m + 256 ≤ 2 ^ w.bits)
    (hgraph : GraphLayout G initial)
    (hroot : (initial (paramCell n m 2)).toNat = r)
    (hinv : ReverseSearchQueueInvariant G r initial s)
    (hpositive : 0 < fuel)
    (hpc : (run Uniform.noConstants
      (Complexity.Program.lower w reverseSearchAlgorithm.code) fuel s).pc = 70)
    (hrunning : (run Uniform.noConstants
      (Complexity.Program.lower w reverseSearchAlgorithm.code) fuel s).halted = false)
    (hfirst : ∀ j : ℕ, 0 < j → j < fuel →
      ¬ ((run Uniform.noConstants
        (Complexity.Program.lower w reverseSearchAlgorithm.code) j s).pc = 70 ∧
        (run Uniform.noConstants
          (Complexity.Program.lower w reverseSearchAlgorithm.code) j s).halted = false)) :
    ReverseSearchQueueInvariant G r initial
      (run Uniform.noConstants (Complexity.Program.lower w reverseSearchAlgorithm.code) fuel s) := by sorry

end DirKECC1549.Main
Source
Initialization/preservation decomposition of DirKECC1549.Main.reverse_search_dequeue_invariant, https://prove2.me/theorems/ce954fc0-ecef-4653-a28a-65dc63c36dda. The concrete assertion is Definitions.Def_DirKECC1549_Main_ReverseSearchQueueInvariant; actual instructions are reverseSearchAlgorithm in Definitions.Def_DirKECC1549_Main_ReverseSearchCode. PCs 0–69 initialize the search; PC 70 tests the queue; PCs 71–110 process a dequeued vertex and incoming-edge scans.

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