Principal declarations
theorem Recurrent.replay_correct
Module NimRecurrent
(lean/phase3/NimRecurrent.lean, lines 274–314) · file SHA-256 1f2994aefc75e7f5… Axioms reported by the fresh build: propext, Quot.sound
REPLAY EXTRACTION IS CORRECT. With sigma = nim(P) from the first scan:
the replay move is none iff P is terminal; every move is legal; and if
sigma ≠ 0 the move reaches nim-sum zero.
Statement as elaborated and printed by Lean 4.26.0
∀ (P : List ℕ),
(NimAudit.Recurrent.replayMove (NimAudit.nimSum P) P = none ↔ NimAudit.Game.Terminal P) ∧
(∀ (i v : ℕ),
NimAudit.Recurrent.replayMove (NimAudit.nimSum P) P = some (i, v) →
∃ x, P[i]? = some x ∧ v < x) ∧
(NimAudit.nimSum P ≠ 0 →
∃ i v,
NimAudit.Recurrent.replayMove (NimAudit.nimSum P) P = some (i, v) ∧
NimAudit.nimSum (P.set i v) = 0)
Exact source text, lines 274–314
274/-- REPLAY EXTRACTION IS CORRECT. With sigma = nim(P) from the first scan:275 the replay move is none iff P is terminal; every move is legal; and if276 sigma ≠ 0 the move reaches nim-sum zero. -/277theorem replay_correct (P : List Nat) :278 (replayMove (nimSum P) P = none ↔ Terminal P) ∧279 (∀ i v, replayMove (nimSum P) P = some (i, v) → ∃ x, P[i]? = some x ∧ v < x) ∧280 (nimSum P ≠ 0 → ∃ i v, replayMove (nimSum P) P = some (i, v) ∧ nimSum (P.set i v) = 0) := by281 rw [replayMove_eq]282 refine ⟨?_, ?_, ?_⟩283 · constructor284 · intro h285 unfold firstSome at h286 split at h287 · cases h288 · exact decIdx_none h289 · intro ht290 rw [terminal_nimSum_zero ht]291 simp [selFor, firstSome, decIdx_terminal ht]292 · intro i v h293 unfold firstSome at h294 split at h295 · next m hm =>296 cases h297 unfold selFor at hm298 split at hm299 · cases hm300 · obtain ⟨x, hx, rfl, hlt⟩ := cancelIdx_some hm301 exact ⟨x, hx, hlt⟩302 · obtain ⟨x, hx, rfl, hlt⟩ := decIdx_some h303 exact ⟨x, hx, by omega⟩304 · intro h0305 obtain ⟨pre, x, post, hp, hlt, _⟩ := exists_decreasing_heap P h0306 cases hc : cancelIdx (nimSum P) P with307 | none => exact absurd hlt (cancelIdx_none hc x (by rw [hp]; simp))308 | some m =>309 obtain ⟨i, v⟩ := m310 obtain ⟨y, hy, rfl, _⟩ := cancelIdx_some hc311 refine ⟨i, y ^^^ nimSum P, ?_, ?_⟩312 · simp [selFor, h0, hc, firstSome]313 · rw [nimSum_set _ hy, Nat.xor_assoc, xor_cancel_left]314 exact Nat.xor_self _
Project declarations in the statement: Game.Terminal, Recurrent.replayMove, nimSum
Project declarations used by the proof or definition body
Attain.cancelIdx, Attain.cancelIdx_none, Attain.cancelIdx_some, Attain.decIdx, Attain.decIdx_none, Attain.decIdx_some, Attain.decIdx_terminal, Game.Terminal, Prob.nimSum_set, Recurrent.firstSome, Recurrent.replayMove, Recurrent.replayMove_eq, Recurrent.selFor, Recurrent.terminal_nimSum_zero, Rollout.exists_decreasing_heap, nimSum, xor_cancel_left
theorem Controller.crun_decision
Module Controller
(lean/phase4/Controller.lean, lines 132–148) · file SHA-256 63d0e09c002db91e… Axioms reported by the fresh build: propext, Quot.sound
ONE DECISION: from an idle state, the controller emits the summary and then the
move computed by replay FROM THE STORED SUMMARY, and returns to an idle state that
retains the summary.
Statement as elaborated and printed by Lean 4.26.0
∀ (s : NimAudit.Controller.CState),
NimAudit.Controller.Idle s →
∀ (P : List ℕ),
NimAudit.Controller.crun s (NimAudit.Controller.dtoks P) =
({ replayMode := false, acc := 0, prev := NimAudit.nimSum P, valid := true,
sig := NimAudit.nimSum P, idx := 0, sel := none, fnz := none },
[NimAudit.Controller.COut.summary (NimAudit.nimSum P)
(if s.valid = true then some (s.prev ^^^ NimAudit.nimSum P) else none),
NimAudit.Controller.COut.move (NimAudit.Recurrent.replayMove (NimAudit.nimSum P) P)])
Exact source text, lines 132–148
132/-- ONE DECISION: from an idle state, the controller emits the summary and then the133 move computed by replay FROM THE STORED SUMMARY, and returns to an idle state that134 retains the summary. -/135theorem crun_decision (s : CState) (hs : Idle s) (P : List Nat) :136 crun s (dtoks P) =137 (⟨false, 0, nimSum P, true, nimSum P, 0, none, none⟩,138 [COut.summary (nimSum P) (if s.valid then some (s.prev ^^^ nimSum P) else none),139 COut.move (replayMove (nimSum P) P)]) := by140 obtain ⟨hm, ha, hi, hsel, hf⟩ := hs141 unfold dtoks142 rw [crun_append, crun_append, crun_append, crun_scan_rows s hm]143 simp only [crun, cstep, Bool.false_eq_true, if_false, ha, Nat.zero_xor, Option.toList]144 rw [crun_replay_rows _ rfl]145 simp only [crun, cstep, if_true, Option.toList, List.nil_append, List.append_nil,146 List.cons_append, List.singleton_append]147 unfold replayMove148 simp
Project declarations in the statement: Controller.COut, Controller.COut.move, Controller.COut.summary, Controller.CState, Controller.CState.mk, Controller.CState.prev, Controller.CState.valid, Controller.Idle, Controller.crun, Controller.dtoks, Recurrent.replayMove, nimSum
Project declarations used by the proof or definition body
Controller.COut, Controller.COut.move, Controller.COut.summary, Controller.CState, Controller.CState.acc, Controller.CState.fnz, Controller.CState.idx, Controller.CState.mk, Controller.CState.prev, Controller.CState.replayMode, Controller.CState.sel, Controller.CState.sig, Controller.CState.valid, Controller.Idle, Controller.Tok, Controller.Tok.row, Controller.Tok.sep, Controller.crun, Controller.crun_append, Controller.crun_replay_rows, Controller.crun_scan_rows, Controller.dtoks, Recurrent.Replay.fnz, Recurrent.Replay.idx, Recurrent.Replay.mk, Recurrent.Replay.sel, Recurrent.firstSome, Recurrent.replay, Recurrent.replayMove, nimSum
theorem Controller.ctrl_wins
Module Controller
(lean/phase4/Controller.lean, lines 223–233) · file SHA-256 63d0e09c002db91e… Axioms reported by the fresh build: propext, Classical.choice, Quot.sound
WINNING AGAINST EVERY LEGAL OPPONENT (checked game semantics): from every board
with nonzero nim-sum, the controller's decisions win.
Statement as elaborated and printed by Lean 4.26.0
∀ (P : List ℕ), NimAudit.nimSum P ≠ 0 → NimAudit.Game.Wins NimAudit.Controller.ctrlSel P
Exact source text, lines 223–233
223/-- WINNING AGAINST EVERY LEGAL OPPONENT (checked game semantics): from every board224 with nonzero nim-sum, the controller's decisions win. -/225theorem ctrl_wins (P : List Nat) (h : nimSum P ≠ 0) : Wins ctrlSel P := by226 obtain ⟨i, v, hd, hz⟩ := (decision_correct P).2.2 h227 obtain ⟨x, hx, hlt, hm⟩ := (decision_correct P).2.1 i v hd228 refine Wins.intro P (P.set i v) (by simp [ctrlSel, hd]) hm ?_229 intro r hr230 have h1 := move_sum_lt hm231 have h2 := move_sum_lt hr232 exact ctrl_wins r (move_from_zero hr hz)233termination_by P.sum
Project declarations in the statement: Controller.ctrlSel, Game.Wins, nimSum
Project declarations used by the proof or definition body
Controller.ctrlSel, Controller.decisionMove, Controller.decision_correct, Game.Move, Game.Terminal, Game.Wins, Game.Wins.intro, Game.move_from_zero, Game.move_sum_lt, nimSum
theorem Controller.stream_fits
Module Controller
(lean/phase4/Controller.lean, lines 324–378) · file SHA-256 63d0e09c002db91e… Axioms reported by the fresh build: propext, Quot.sound
REACHABLE-STATE BOUNDS: along a well-formed stream of boards of N heaps below 2^B,
started from an idle fitting state, EVERY visited state has acc, prev, sig < 2^B,
counter ≤ N, and selected/fallback moves with index < N and value < 2^B. With
N < 2^r, every register fits its r- or B-bit field; the counter never overflows.
Statement as elaborated and printed by Lean 4.26.0
∀ {B N : ℕ} (s : NimAudit.Controller.CState),
NimAudit.Controller.Idle s →
NimAudit.Controller.Fits B N s →
∀ (Ps : List (List ℕ)),
(∀ P ∈ Ps, P.length = N ∧ NimAudit.Game.Width B P) →
∀ st ∈ NimAudit.Controller.crunStates s (NimAudit.Controller.stream Ps),
NimAudit.Controller.Fits B N st
Exact source text, lines 324–378
324/-- REACHABLE-STATE BOUNDS: along a well-formed stream of boards of N heaps below 2^B,325 started from an idle fitting state, EVERY visited state has acc, prev, sig < 2^B,326 counter ≤ N, and selected/fallback moves with index < N and value < 2^B. With327 N < 2^r, every register fits its r- or B-bit field; the counter never overflows. -/328theorem stream_fits {B N : Nat} (s : CState) (hs : Idle s) (hf : Fits B N s) (Ps : List (List Nat))329 (hP : ∀ P ∈ Ps, P.length = N ∧ Width B P) : ∀ st ∈ crunStates s (stream Ps), Fits B N st := by330 induction Ps generalizing s with331 | nil => intro st h; simp [stream, crunStates] at h; subst h; exact hf332 | cons P Ps ih =>333 have e : stream (P :: Ps) = dtoks P ++ stream Ps := by simp [stream]334 rw [e]335 intro st h336 obtain ⟨hlenP, hwP⟩ := hP P (by simp)337 rcases crunStates_append s _ _ st h with h1 | h1338 · -- inside the decision339 unfold dtoks at h1340 rcases crunStates_append s _ _ st h1 with h2 | h2341 · rcases crunStates_append s _ _ st h2 with h3 | h3342 · rcases crunStates_append s _ _ st h3 with h4 | h4343 · exact scan_rows_fit s hs.1 hf P hwP st h4344 · rw [crun_scan_rows s hs.1] at h4345 simp only [crunStates, cstep, Bool.false_eq_true, if_false, List.mem_cons,346 List.mem_singleton] at h4347 have ha : s.acc ^^^ nimSum P < 2 ^ B := Nat.xor_lt_two_pow hf.1 (nimSum_lt hwP)348 rcases h4 with rfl | rfl | h4349 · exact ⟨ha, hf.2.1, hf.2.2.1, hf.2.2.2.1, hf.2.2.2.2.1, hf.2.2.2.2.2⟩350 · exact ⟨Nat.two_pow_pos B, ha, ha, Nat.zero_le _, by simp, by simp⟩351 · simp at h4352 · rw [crun_append, crun_scan_rows s hs.1] at h3353 simp only [crun, cstep, Bool.false_eq_true, if_false] at h3354 have ha : s.acc ^^^ nimSum P < 2 ^ B := Nat.xor_lt_two_pow hf.1 (nimSum_lt hwP)355 exact replay_rows_fit _ rfl ⟨Nat.two_pow_pos B, ha, ha⟩ (by simp) (by simp) P356 (by simp [hlenP]) hwP st h3357 · rw [crun_append, crun_append, crun_scan_rows s hs.1] at h2358 simp only [crun, cstep, Bool.false_eq_true, if_false] at h2359 have ha : s.acc ^^^ nimSum P < 2 ^ B := Nat.xor_lt_two_pow hf.1 (nimSum_lt hwP)360 generalize hS1 : (⟨true, 0, s.acc ^^^ nimSum P, true, s.acc ^^^ nimSum P, 0, none, none⟩ :361 CState) = S1 at h2362 have hS1m : S1.replayMode = true := by rw [← hS1]363 simp only [crunStates, List.mem_cons, List.mem_singleton] at h2364 rcases h2 with rfl | rfl | h2365 · subst hS1366 exact replay_rows_fit _ rfl ⟨Nat.two_pow_pos B, ha, ha⟩ (by simp) (by simp) P367 (by simp [hlenP]) hwP _ (crun_mem_states _ _)368 · rw [crun_replay_rows _ hS1m]369 subst hS1370 simp only [cstep, if_true]371 exact ⟨Nat.two_pow_pos B, ha, ha, Nat.zero_le _, by simp, by simp⟩372 · simp at h2373 · rw [crun_decision s hs P] at h1374 have hidle : Idle (⟨false, 0, nimSum P, true, nimSum P, 0, none, none⟩ : CState) :=375 ⟨rfl, rfl, rfl, rfl, rfl⟩376 have hfit : Fits B N (⟨false, 0, nimSum P, true, nimSum P, 0, none, none⟩ : CState) :=377 ⟨Nat.two_pow_pos B, nimSum_lt hwP, nimSum_lt hwP, Nat.zero_le _, by simp, by simp⟩378 exact ih _ hidle hfit (fun Q hQ => hP Q (by simp [hQ])) st h1
Project declarations in the statement: Controller.CState, Controller.Fits, Controller.Idle, Controller.crunStates, Controller.stream, Game.Width
Project declarations used by the proof or definition body
Controller.COut, Controller.COut.move, Controller.COut.summary, Controller.CState, Controller.CState.acc, Controller.CState.fnz, Controller.CState.idx, Controller.CState.mk, Controller.CState.prev, Controller.CState.replayMode, Controller.CState.sel, Controller.CState.sig, Controller.CState.valid, Controller.Fits, Controller.Idle, Controller.Tok, Controller.Tok.row, Controller.Tok.sep, Controller.crun, Controller.crunStates, Controller.crunStates_append, Controller.crun_append, Controller.crun_decision, Controller.crun_mem_states, Controller.crun_replay_rows, Controller.crun_scan_rows, Controller.cstep, Controller.dtoks, Controller.replay_rows_fit, Controller.scan_rows_fit, Controller.stream, Game.Width, Game.nimSum_lt, Recurrent.Replay.fnz, Recurrent.Replay.idx, Recurrent.Replay.mk, Recurrent.Replay.sel, Recurrent.firstSome, Recurrent.replay, Recurrent.replayMove, nimSum
theorem ThresholdInst.ctrl_counts
Module ThresholdInst
(lean/phase5/ThresholdInst.lean, lines 263–269) · file SHA-256 c8c66599c8e24804… Axioms reported by the fresh build: propext, Quot.sound
Memory and update counts are those of the bit-level controller: 4 + 5B + 3r state
bits (7 + 5B + 3·log₂N with r = log₂N + 1), 2N + 2 network updates per decision,
one extra update per reset token.
Statement as elaborated and printed by Lean 4.26.0
∀ (B N : ℕ) (P : List ℕ),
NimAudit.ControllerBits.stateWidth B (N.log2 + 1) = 7 + 5 * B + 3 * N.log2 ∧
N < 2 ^ (N.log2 + 1) ∧ (NimAudit.Controller.dtoks P).length = 2 * P.length + 2
Exact source text, lines 263–269
263/-- Memory and update counts are those of the bit-level controller: 4 + 5B + 3r state264 bits (7 + 5B + 3·log₂N with r = log₂N + 1), 2N + 2 network updates per decision,265 one extra update per reset token. -/266theorem ctrl_counts (B N : Nat) (P : List Nat) :267 stateWidth B (N.log2 + 1) = 7 + 5 * B + 3 * N.log2 ∧ N < 2 ^ (N.log2 + 1) ∧268 (dtoks P).length = 2 * P.length + 2 :=269 ⟨(counter_width (B := B) N).2, (counter_width (B := B) N).1, dtoks_length P⟩
Project declarations in the statement: Controller.Tok, Controller.dtoks, ControllerBits.stateWidth
Project declarations used by the proof or definition body
Controller.Tok, Controller.dtoks, ControllerBits.counter_width, ControllerBits.dtoks_length, ControllerBits.stateWidth
theorem WholeGame.replay_counts
Module WholeGame
(lean/phase5/WholeGame.lean, lines 313–318) · file SHA-256 809a74ad589db609… Axioms reported by the fresh build: propext, Quot.sound
Update accounting: each decision uses exactly 2N + 2 controller updates; a game adds
one reset update; the state has 4 + 5B + 3r bits (7 + 5B + 3·log₂N for r = log₂N + 1).
Statement as elaborated and printed by Lean 4.26.0
∀ (B N : ℕ) (P : List ℕ),
P.length = N →
(NimAudit.Controller.dtoks P).length = 2 * N + 2 ∧
(NimAudit.Controller.Tok.reset :: NimAudit.Controller.dtoks P).length = 2 * N + 3 ∧
NimAudit.ControllerBits.stateWidth B (N.log2 + 1) = 7 + 5 * B + 3 * N.log2
Exact source text, lines 313–318
313/-- Update accounting: each decision uses exactly 2N + 2 controller updates; a game adds314 one reset update; the state has 4 + 5B + 3r bits (7 + 5B + 3·log₂N for r = log₂N + 1). -/315theorem replay_counts (B N : Nat) (P : List Nat) (hP : P.length = N) :316 (dtoks P).length = 2 * N + 2 ∧ (Tok.reset :: dtoks P).length = 2 * N + 3 ∧317 stateWidth B (N.log2 + 1) = 7 + 5 * B + 3 * N.log2 := by318 refine ⟨by rw [dtoks_length, hP], by simp [dtoks_length, hP], (counter_width (B := B) N).2⟩
Project declarations in the statement: Controller.Tok, Controller.Tok.reset, Controller.dtoks, ControllerBits.stateWidth
Project declarations used by the proof or definition body
Controller.Tok, Controller.Tok.reset, Controller.dtoks, ControllerBits.counter_width, ControllerBits.dtoks_length, ControllerBits.stateWidth
theorem WholeGame.replay_wins
Module WholeGame
(lean/phase5/WholeGame.lean, lines 282–302) · file SHA-256 809a74ad589db609… Axioms reported by the fresh build: propext, Classical.choice, Quot.sound
RECURRENT WHOLE-GAME THEOREM: with N < 2^r heaps of width B, from any idle controller
state whose registers fit (the initial state, and every state reached after earlier
decisions), the threshold controller driven by the replay protocol wins from every
nonzero position against every legal opponent; the move applied is exactly the
emitted one; all controller states over the whole interaction fit the registers.
Statement as elaborated and printed by Lean 4.26.0
∀ {B r N : ℕ},
N < 2 ^ r →
∀ (P : List ℕ),
P.length = N →
NimAudit.Game.Width B P →
NimAudit.nimSum P ≠ 0 →
∀ (s : NimAudit.Controller.CState),
NimAudit.Controller.Idle s →
NimAudit.Controller.Fits B N s → NimAudit.WholeGame.ReplayWins B r s P
Exact source text, lines 282–302
282/-- RECURRENT WHOLE-GAME THEOREM: with N < 2^r heaps of width B, from any idle controller283 state whose registers fit (the initial state, and every state reached after earlier284 decisions), the threshold controller driven by the replay protocol wins from every285 nonzero position against every legal opponent; the move applied is exactly the286 emitted one; all controller states over the whole interaction fit the registers. -/287theorem replay_wins {B r N : Nat} (hN : N < 2 ^ r) : ∀ (P : List Nat), P.length = N → Width B P →288 nimSum P ≠ 0 → ∀ s, Idle s → Fits B N s → ReplayWins B r s P := by289 intro P290 induction P using (measure List.sum).wf.induction with291 | h P ih =>292 intro hP hw h0 s hs hf293 obtain ⟨hdec, hfit⟩ := decide_spec hN hs hf hP hw294 obtain ⟨i, v, hd, hz⟩ := (decision_correct P).2.2 h0295 obtain ⟨x, _, _, hmv⟩ := (decision_correct P).2.1 i v hd296 refine ReplayWins.intro s P (P.set i v) hfit (by rw [hdec, hd]; rfl) hmv (by rw [hdec]) ?_297 intro P' hm'298 have hlt1 := move_sum_lt hmv299 have hlt2 := move_sum_lt hm'300 obtain ⟨hidle, hfit'⟩ := afterState_ok (N := N) hw301 exact ih P' (by show P'.sum < P.sum; omega) (by rw [move_length hm', move_length hmv, hP])302 (width_move (width_move hw hmv) hm') (move_from_zero hm' hz) _ hidle hfit'
Project declarations in the statement: Controller.CState, Controller.Fits, Controller.Idle, Game.Width, WholeGame.ReplayWins, nimSum
Project declarations used by the proof or definition body
Controller.CState, Controller.Fits, Controller.Idle, Controller.crunStates, Controller.decisionMove, Controller.decision_correct, Controller.dtoks, ControllerBits.FitsR, ControllerBits.sbits, Game.Move, Game.Terminal, Game.Width, Game.move_from_zero, Game.move_sum_lt, Game.width_move, SelectCircuit.applyM, WholeGame.ReplayWins, WholeGame.ReplayWins.intro, WholeGame.afterState, WholeGame.afterState_ok, WholeGame.decide, WholeGame.decide_spec, WholeGame.move_length, nimSum
theorem WholeGame.replay_game
Module WholeGame
(lean/phase5/WholeGame.lean, lines 304–311) · file SHA-256 809a74ad589db609… Axioms reported by the fresh build: propext, Classical.choice, Quot.sound
GAME START from an arbitrary bit state: one reset token produces the encoding of the
initial state, from which the replay strategy wins.
Statement as elaborated and printed by Lean 4.26.0
∀ {B r N : ℕ},
N < 2 ^ r →
∀ (v : ℕ → Bool) {P : List ℕ},
P.length = N →
NimAudit.Game.Width B P →
NimAudit.nimSum P ≠ 0 →
(NimAudit.ThresholdInst.tstep B r v NimAudit.Controller.Tok.reset).1 =
NimAudit.ControllerBits.sbits B r NimAudit.Controller.cinit ∧
NimAudit.WholeGame.ReplayWins B r NimAudit.Controller.cinit P
Exact source text, lines 304–311
304/-- GAME START from an arbitrary bit state: one reset token produces the encoding of the305 initial state, from which the replay strategy wins. -/306theorem replay_game {B r N : Nat} (hN : N < 2 ^ r) (v : Nat → Bool) {P : List Nat} (hP : P.length = N)307 (hw : Width B P) (h0 : nimSum P ≠ 0) :308 (tstep B r v Tok.reset).1 = sbits B r cinit ∧ ReplayWins B r cinit P := by309 refine ⟨by rw [tstep_reset], ?_⟩310 exact replay_wins hN P hP hw h0 cinit cinit_idle311 ⟨Nat.two_pow_pos B, Nat.two_pow_pos B, Nat.two_pow_pos B, Nat.zero_le _, by simp [cinit], by simp [cinit]⟩
Project declarations in the statement: Controller.COut, Controller.Tok.reset, Controller.cinit, ControllerBits.sbits, Game.Width, ThresholdInst.tstep, WholeGame.ReplayWins, nimSum
Project declarations used by the proof or definition body
Controller.COut, Controller.CState.acc, Controller.CState.fnz, Controller.CState.idx, Controller.CState.prev, Controller.CState.sel, Controller.CState.sig, Controller.Tok.reset, Controller.cinit, Controller.cinit_idle, ControllerBits.sbits, Game.Width, ThresholdInst.tstep, ThresholdInst.tstep_reset, WholeGame.ReplayWins, WholeGame.replay_wins, nimSum
Definitions these statements use
def Game.Terminal
Module NimGame
(lean/phase2/NimGame.lean, lines 28–29) · file SHA-256 23df6bb87ecfd344…
Terminal board: every heap is empty.
Statement as elaborated and printed by Lean 4.26.0
List ℕ → Prop
Exact source text, lines 28–29
28/-- Terminal board: every heap is empty. -/29def Terminal (p : List Nat) : Prop := ∀ x ∈ p, x = 0
Project declarations in the statement: none
Project declarations used by the proof or definition body
none
def Recurrent.replayMove
Module NimRecurrent
(lean/phase3/NimRecurrent.lean, lines 256–259) · file SHA-256 1f2994aefc75e7f5…
The move chosen after replay.
Statement as elaborated and printed by Lean 4.26.0
ℕ → List ℕ → Option (ℕ × ℕ)
Exact source text, lines 256–259
256/-- The move chosen after replay. -/257def replayMove (σ : Nat) (P : List Nat) : Option (Nat × Nat) :=258 let r := replay σ ⟨0, none, none⟩ P259 firstSome r.sel r.fnz
Project declarations in the statement: none
Project declarations used by the proof or definition body
Recurrent.Replay, Recurrent.Replay.fnz, Recurrent.Replay.mk, Recurrent.Replay.sel, Recurrent.firstSome, Recurrent.replay
def nimSum
Module NimCore
(lean/NimCore.lean, lines 7–9) · file SHA-256 b07db6c505210d5a…
Statement as elaborated and printed by Lean 4.26.0
List ℕ → ℕ
Exact source text, lines 7–9
7def nimSum : List Nat → Nat8 | [] => 09 | h :: t => h ^^^ nimSum t
Project declarations in the statement: none
Project declarations used by the proof or definition body
none
inductive Controller.COut
Module Controller
(lean/phase4/Controller.lean, lines 44–46) · file SHA-256 63d0e09c002db91e…
Statement as elaborated and printed by Lean 4.26.0
Type
Exact source text, lines 44–46
44inductive COut where45 | summary (s : Nat) (diff : Option Nat)46 | move (m : Option (Nat × Nat))
Project declarations in the statement: none
Project declarations used by the proof or definition body
none
inductive Controller.CState
Module Controller
(lean/phase4/Controller.lean, lines 34–42) · file SHA-256 63d0e09c002db91e…
Statement as elaborated and printed by Lean 4.26.0
Type
Exact source text, lines 34–42
34structure CState where35 replayMode : Bool36 acc : Nat37 prev : Nat38 valid : Bool39 sig : Nat40 idx : Nat41 sel : Option (Nat × Nat)42 fnz : Option (Nat × Nat)
Project declarations in the statement: none
Project declarations used by the proof or definition body
none
def Controller.CState.prev
Module Controller
(lean/phase4/Controller.lean, lines 37–37) · file SHA-256 63d0e09c002db91e…
Statement as elaborated and printed by Lean 4.26.0
NimAudit.Controller.CState → ℕ
Exact source text, lines 37–37
37 prev : Nat
Project declarations in the statement: Controller.CState
Project declarations used by the proof or definition body
Controller.CState
def Controller.CState.valid
Module Controller
(lean/phase4/Controller.lean, lines 38–38) · file SHA-256 63d0e09c002db91e…
Statement as elaborated and printed by Lean 4.26.0
NimAudit.Controller.CState → Bool
Exact source text, lines 38–38
38 valid : Bool
Project declarations in the statement: Controller.CState
Project declarations used by the proof or definition body
Controller.CState
def Controller.Idle
Module Controller
(lean/phase4/Controller.lean, lines 83–84) · file SHA-256 63d0e09c002db91e…
Idle: scan mode with empty accumulator and cleared replay registers.
Statement as elaborated and printed by Lean 4.26.0
NimAudit.Controller.CState → Prop
Exact source text, lines 83–84
83/-- Idle: scan mode with empty accumulator and cleared replay registers. -/84def Idle (s : CState) : Prop := s.replayMode = false ∧ s.acc = 0 ∧ s.idx = 0 ∧ s.sel = none ∧ s.fnz = none
Project declarations in the statement: Controller.CState
Project declarations used by the proof or definition body
Controller.CState, Controller.CState.acc, Controller.CState.fnz, Controller.CState.idx, Controller.CState.replayMode, Controller.CState.sel
def Controller.crun
Module Controller
(lean/phase4/Controller.lean, lines 66–68) · file SHA-256 63d0e09c002db91e…
Statement as elaborated and printed by Lean 4.26.0
NimAudit.Controller.CState →
List NimAudit.Controller.Tok → NimAudit.Controller.CState × List NimAudit.Controller.COut
Exact source text, lines 66–68
66def crun : CState → List Tok → CState × List COut67 | s, [] => (s, [])68 | s, t :: ts => ((crun (cstep s t).1 ts).1, (cstep s t).2.toList ++ (crun (cstep s t).1 ts).2)
Project declarations in the statement: Controller.COut, Controller.CState, Controller.Tok
Project declarations used by the proof or definition body
Controller.COut, Controller.CState, Controller.Tok, Controller.cstep
def Controller.dtoks
Module Controller
(lean/phase4/Controller.lean, lines 75–76) · file SHA-256 63d0e09c002db91e…
The tokens of one decision: scan, separator, replay, separator.
Statement as elaborated and printed by Lean 4.26.0
List ℕ → List NimAudit.Controller.Tok
Exact source text, lines 75–76
75/-- The tokens of one decision: scan, separator, replay, separator. -/76def dtoks (P : List Nat) : List Tok := P.map Tok.row ++ [Tok.sep] ++ P.map Tok.row ++ [Tok.sep]
Project declarations in the statement: Controller.Tok
Project declarations used by the proof or definition body
Controller.Tok, Controller.Tok.row, Controller.Tok.sep
def Controller.ctrlSel
Module Controller
(lean/phase4/Controller.lean, lines 220–221) · file SHA-256 63d0e09c002db91e…
The controller as a strategy on boards.
Statement as elaborated and printed by Lean 4.26.0
List ℕ → Option (List ℕ)
Exact source text, lines 220–221
220/-- The controller as a strategy on boards. -/221def ctrlSel (P : List Nat) : Option (List Nat) := (decisionMove P).map (fun m => P.set m.1 m.2)
Project declarations in the statement: none
Project declarations used by the proof or definition body
Controller.decisionMove
inductive Game.Wins
Module NimGame
(lean/phase2/NimGame.lean, lines 125–132) · file SHA-256 23df6bb87ecfd344…
`Wins sel p`: the player to move at `p`, always playing the successor chosen by
`sel`, wins against EVERY legal opponent. The selected move is legal, and after
every legal opponent reply the player is again in a `Wins` position. Because
the predicate is inductive, every such play is finite and ends with the
opponent facing a terminal board (normal play: the opponent loses).
Statement as elaborated and printed by Lean 4.26.0
(List ℕ → Option (List ℕ)) → List ℕ → Prop
Exact source text, lines 125–132
125/-- `Wins sel p`: the player to move at `p`, always playing the successor chosen by126 `sel`, wins against EVERY legal opponent. The selected move is legal, and after127 every legal opponent reply the player is again in a `Wins` position. Because128 the predicate is inductive, every such play is finite and ends with the129 opponent facing a terminal board (normal play: the opponent loses). -/130inductive Wins (sel : List Nat → Option (List Nat)) : List Nat → Prop131 | intro (p q : List Nat) : sel p = some q → Move p q →132 (∀ r, Move q r → Wins sel r) → Wins sel p
Project declarations in the statement: none
Project declarations used by the proof or definition body
Game.Move
def Controller.Fits
Module Controller
(lean/phase4/Controller.lean, lines 237–241) · file SHA-256 63d0e09c002db91e…
Register bounds for N heaps of B bits and an r-bit counter (N < 2^r).
Statement as elaborated and printed by Lean 4.26.0
ℕ → ℕ → NimAudit.Controller.CState → Prop
Exact source text, lines 237–241
237/-- Register bounds for N heaps of B bits and an r-bit counter (N < 2^r). -/238def Fits (B N : Nat) (s : CState) : Prop :=239 s.acc < 2 ^ B ∧ s.prev < 2 ^ B ∧ s.sig < 2 ^ B ∧ s.idx ≤ N ∧240 (∀ i v, s.sel = some (i, v) → i < N ∧ v < 2 ^ B) ∧241 (∀ i v, s.fnz = some (i, v) → i < N ∧ v < 2 ^ B)
Project declarations in the statement: Controller.CState
Project declarations used by the proof or definition body
Controller.CState, Controller.CState.acc, Controller.CState.fnz, Controller.CState.idx, Controller.CState.prev, Controller.CState.sel, Controller.CState.sig
def Controller.crunStates
Module Controller
(lean/phase4/Controller.lean, lines 70–73) · file SHA-256 63d0e09c002db91e…
All states visited (initial state included).
Statement as elaborated and printed by Lean 4.26.0
NimAudit.Controller.CState → List NimAudit.Controller.Tok → List NimAudit.Controller.CState
Exact source text, lines 70–73
70/-- All states visited (initial state included). -/71def crunStates : CState → List Tok → List CState72 | s, [] => [s]73 | s, t :: ts => s :: crunStates (cstep s t).1 ts
Project declarations in the statement: Controller.CState, Controller.Tok
Project declarations used by the proof or definition body
Controller.COut, Controller.CState, Controller.Tok, Controller.cstep
def Controller.stream
Module Controller
(lean/phase4/Controller.lean, lines 78–78) · file SHA-256 63d0e09c002db91e…
Statement as elaborated and printed by Lean 4.26.0
List (List ℕ) → List NimAudit.Controller.Tok
Exact source text, lines 78–78
78def stream (Ps : List (List Nat)) : List Tok := Ps.flatMap dtoks
Project declarations in the statement: Controller.Tok
Project declarations used by the proof or definition body
Controller.Tok, Controller.dtoks
def Game.Width
Module NimGame
(lean/phase2/NimGame.lean, lines 31–32) · file SHA-256 23df6bb87ecfd344…
B-bit board: every heap is below 2^B.
Statement as elaborated and printed by Lean 4.26.0
ℕ → List ℕ → Prop
Exact source text, lines 31–32
31/-- B-bit board: every heap is below 2^B. -/32def Width (B : Nat) (p : List Nat) : Prop := ∀ x ∈ p, x < 2 ^ B
Project declarations in the statement: none
Project declarations used by the proof or definition body
none
inductive Controller.Tok
Module Controller
(lean/phase4/Controller.lean, lines 29–32) · file SHA-256 63d0e09c002db91e…
Statement as elaborated and printed by Lean 4.26.0
Type
Exact source text, lines 29–32
29inductive Tok where30 | row (x : Nat)31 | sep32 | reset
Project declarations in the statement: none
Project declarations used by the proof or definition body
none
def ControllerBits.stateWidth
Module ControllerBits
(lean/phase4/ControllerBits.lean, lines 788–789) · file SHA-256 4e23680da471fd69…
Number of state wires.
Statement as elaborated and printed by Lean 4.26.0
ℕ → ℕ → ℕ
Exact source text, lines 788–789
788/-- Number of state wires. -/789def stateWidth (B r : Nat) : Nat := 4 + 5 * B + 3 * r
Project declarations in the statement: none
Project declarations used by the proof or definition body
none
inductive WholeGame.ReplayWins
Module WholeGame
(lean/phase5/WholeGame.lean, lines 266–276) · file SHA-256 809a74ad589db609…
Stateful interaction predicate (player to move at P; the controller holds the
canonical encoding of the semantic state s). At each decision: every intermediate
controller state fits the registers, the emitted move is applied to the board and is
legal, the controller's new vector encodes `afterState P` (the stored summary feeds
the next decision), and after every legal opponent reply the interaction continues.
Statement as elaborated and printed by Lean 4.26.0
ℕ → ℕ → NimAudit.Controller.CState → List ℕ → Prop
Exact source text, lines 266–276
266/-- Stateful interaction predicate (player to move at P; the controller holds the267 canonical encoding of the semantic state s). At each decision: every intermediate268 controller state fits the registers, the emitted move is applied to the board and is269 legal, the controller's new vector encodes `afterState P` (the stored summary feeds270 the next decision), and after every legal opponent reply the interaction continues. -/271inductive ReplayWins (B r : Nat) : CState → List Nat → Prop272 | intro (s : CState) (P R : List Nat) :273 (∀ st ∈ crunStates s (dtoks P), FitsR B r st) →274 applyM P (decide B r (sbits B r s) P).2 = some R → Move P R →275 (decide B r (sbits B r s) P).1 = sbits B r (afterState P) →276 (∀ P', Move R P' → ReplayWins B r (afterState P) P') → ReplayWins B r s P
Project declarations in the statement: Controller.CState
Project declarations used by the proof or definition body
Controller.CState, Controller.crunStates, Controller.dtoks, ControllerBits.FitsR, ControllerBits.sbits, Game.Move, SelectCircuit.applyM, WholeGame.afterState, WholeGame.decide
def Controller.cinit
Module Controller
(lean/phase4/Controller.lean, lines 48–48) · file SHA-256 63d0e09c002db91e…
Statement as elaborated and printed by Lean 4.26.0
NimAudit.Controller.CState
Exact source text, lines 48–48
48def cinit : CState := ⟨false, 0, 0, false, 0, 0, none, none⟩
Project declarations in the statement: Controller.CState
Project declarations used by the proof or definition body
Controller.CState.mk
def ControllerBits.sbits
Module ControllerBits
(lean/phase4/ControllerBits.lean, lines 104–108) · file SHA-256 4e23680da471fd69…
The canonical state vector (4 + 5B + 3r bits; false beyond).
Statement as elaborated and printed by Lean 4.26.0
ℕ → ℕ → NimAudit.Controller.CState → ℕ → Bool
Exact source text, lines 104–108
104/-- The canonical state vector (4 + 5B + 3r bits; false beyond). -/105def sbits (B r : Nat) (s : CState) : Nat → Bool :=106 layout B r false s.replayMode s.acc.testBit s.prev.testBit s.valid s.sig.testBit s.idx.testBit107 s.sel.isSome (optI s.sel).testBit (optV s.sel).testBit s.fnz.isSome (optI s.fnz).testBit108 (optV s.fnz).testBit
Project declarations in the statement: Controller.CState
Project declarations used by the proof or definition body
Controller.CState, Controller.CState.acc, Controller.CState.fnz, Controller.CState.idx, Controller.CState.prev, Controller.CState.replayMode, Controller.CState.sel, Controller.CState.sig, Controller.CState.valid, ControllerBits.layout, ControllerBits.optI, ControllerBits.optV
def ThresholdInst.tstep
Module ThresholdInst
(lean/phase5/ThresholdInst.lean, lines 128–131) · file SHA-256 c8c66599c8e24804…
One update of the threshold-network controller.
Statement as elaborated and printed by Lean 4.26.0
ℕ → ℕ → (ℕ → Bool) → NimAudit.Controller.Tok → (ℕ → Bool) × Option NimAudit.Controller.COut
Exact source text, lines 128–131
128/-- One update of the threshold-network controller. -/129def tstep (B r : Nat) (v : Nat → Bool) (t : Tok) : (Nat → Bool) × Option COut :=130 ((fun j => if j < stateWidth B r then evalNet (ctrlNet B r) (inp B r v t) j else false),131 outDecode B r (fun k => evalNet (ctrlNet B r) (inp B r v t) (stateWidth B r + k)))
Project declarations in the statement: Controller.COut, Controller.Tok
Project declarations used by the proof or definition body
AC0.evalNet, Controller.COut, Controller.Tok, ControllerBits.inp, ControllerBits.stateWidth, ThresholdInst.ctrlNet, ThresholdInst.outDecode
Full modules
Build evidence: fresh isolated rebuild of all 38 bundled modules with Lean (version 4.26.0, started 2026-10-10T15:21:56Z, finished 2026-10-10T15:27:00Z: 38/38 modules compiled, 1588 axiom reports, no errors. See Build for the commands and the independent audit of 2026-10-10 (dated evidence).