NIM paper · interactive edition Interactive edition · paper, explanations and Lean proofs.

Section 5.5, “From a summary to a move”Replay protocol rows,SEP,rows,SEP: 2N+2 updates, 4+5B+3r state bits, a legal winning move

Checked theorem Lean checks a formal statement corresponding to this claim.

1 Paper text

From a summary to a move. Computing σt\sigma_t does not by itself retain the heap rows needed to choose a move. One implementation replays the current position after the first scan. If σt≠0\sigma_t\ne0, select the first row ii for which xt,i′=xt,i⊕σt<xt,i.x_{t,i}'=x_{t,i}\oplus\sigma_t<x_{t,i}. Such a row exists: choose a heap containing the highest set bit of σt\sigma_t. Replacing that heap by xt,i′x_{t,i}' leaves nim-sum zero. XOR, binary comparison and conditional selection are constant-depth operations; the replay uses O(B+log⁡N)O(B+\log N) state bits to retain the summary, a selected move and its row index. The explicit protocol is rows(Pt), SEP, rows(Pt), SEP.\mathtt{rows}(P_t),\ \mathtt{SEP},\ \mathtt{rows}(P_t),\ \mathtt{SEP}. The first separator stores the summary and switches to replay; the second emits the move and returns to scan mode. This takes exactly 2N+22N+2 updates, with one additional reset token at the start of a game. If σt=0\sigma_t=0, choose the first nonempty heap and decrement it, or report termination when all heaps are empty. Lean verifies the complete replay controller, including its binary move output and its fixed-scale threshold implementation. With an rr-bit counter satisfying N<2rN<2^r, its state uses 4+5B+3r4+5B+3r bits. The strict inequality allows the counter to hold the end value NN, whereas an output index alone only needs N≤2rN\le2^r. Alternatively, store the current board in O(NB)O(NB) bits during the initial scan and use a constant-depth selector at the separator, as in Appendix C. This avoids replay at the cost of board-sized memory. The distinction matters for a stream in which each position is supplied only once. Both variants have checked bit-level circuits, fixed-scale network implementations and winning-play guarantees. The board-storage variant uses NB+B+rNB+B+r state bits and N+1N+1 updates per decision, with N<2rN<2^r, plus a reset update when initialising the controller.

Generated from paper_jmlr.tex, lines 850–860.

2 Explain this

A nim-sum alone does not say which heap to change: the rows have already gone by. The replay protocol sends the current board twice: rows(P), SEP, rows(P), SEP.

  • First scan: compute σ=nim⁡(P)\sigma=\operatorname{nim}(P); at the first SEP store it and switch to replay mode.
  • Replay: for each row ii, test whether xi⊕σ<xix_i\oplus\sigma<x_i, keeping the first such row and a fallback (first nonempty heap).
  • Second SEP: emit the move (cancel at the first qualifying row; else decrement the first nonempty heap; or report termination) and return to scan mode.

Costs. Exactly 2N+22N+2 updates per decision, plus one reset at the start of a game. With an rr-bit counter, N<2rN<2^r, the state has 4+5B+3r4+5B+3r bits.

Caveat. The second copy of the board is supplied by the environment as part of the input protocol; the controller does not secretly store the board.

Row-wise recurrence: registers, separators and replay

Exact construction trace Every value is computed from the construction’s definitions for the example shown.

The board arrives as a stream of rows, one heap per token, with separators (SEP) between positions and a reset at the start of a game. Step through the replay controller: in scan mode it XORs each row into the accumulator; the first separator outputs the summary, stores it and switches to replay mode; during replay the same rows arrive again and each is tested against the stored summary, keeping the first cancelling candidate and a fallback; the second separator outputs the move. The board-storage variant instead writes the rows into memory and chooses the move at its single separator. In the replay controller a separator clears the accumulator and keeps the summary of the position just completed, with its validity bit; an extra separator is read as an empty position, whose summary is 0. Only a reset returns every register, validity included, to its initial value. The board-storage separator clears its accumulator and pointer and keeps the stored board. The third protocol shows the summary mechanism of Proposition 5.13 alone: it reports summaries and differences but chooses no move.

The current NIM board already determines optimal play. The memory shown here makes that answer computationally accessible by retaining partial results across rows; an earlier game position is needed only for the optional comparison of consecutive positions.

  1. RESETreset
  2. row 3scan
  3. row 4scan
  4. row 6scan
  5. SEPsummary
  6. row 3replay
  7. row 4replay
  8. row 6replay
  9. SEPmove
  10. row 2scan
  11. row 4scan
  12. row 1scan
  13. SEPsummary
  14. row 2replay
  15. row 4replay
  16. row 1replay
  17. SEPmove

17 / 17 SEP: separator after replay: output the move, return to scan mode

Registers after this update

mode
scan
accumulator
0 000
previous summary
7 111
stored summary used in replay
7
heap counter
0
first candidate
no move
first fallback
no move

Outputs so far

  • after token 5: summary σ = 1 (no previous summary)
  • after token 9: move heap 0 → 2
  • after token 13: summary σ = 7, difference from the previous summary 6
  • after token 17: move heap 1 → 3

Counting the work

  • One decision on 3 heaps takes 2N + 2 = 8 updates: N scan rows, a separator, the same N rows again, a separator (plus one reset at the start of a game). The board is supplied twice; the controller does not store it.
  • Memory: accumulator, previous summary, stored summary, counter, candidate and fallback registers: 4 + 5B + 3r bits with N < 2r; here B = 3, r = 2, so 25 bits.
  • Each single update is a shallow circuit (replay controller: Boolean depth ≤ 8, ≤ 18 threshold layers). The number of sequential updates grows with N. That no shallow family computes the complete board-to-move map is a separate statement, conditional on the named classical input that parity is not in AC0.
All 17 updates as a table
#TokenRegisters afterOutput
1RESETscan, acc 0, prev 0*, idx 0, cand no move, fb no move
2row 3scan, acc 3, prev 0*, idx 0, cand no move, fb no move
3row 4scan, acc 7, prev 0*, idx 0, cand no move, fb no move
4row 6scan, acc 1, prev 0*, idx 0, cand no move, fb no move
5SEPreplay, acc 0, prev 1, idx 0, cand no move, fb no moveσ = 1
6row 3replay, acc 0, prev 1, idx 1, cand heap 0 → 2, fb heap 0 → 2
7row 4replay, acc 0, prev 1, idx 2, cand heap 0 → 2, fb heap 0 → 2
8row 6replay, acc 0, prev 1, idx 3, cand heap 0 → 2, fb heap 0 → 2
9SEPscan, acc 0, prev 1, idx 0, cand no move, fb no movemove heap 0 → 2
10row 2scan, acc 2, prev 1, idx 0, cand no move, fb no move
11row 4scan, acc 6, prev 1, idx 0, cand no move, fb no move
12row 1scan, acc 7, prev 1, idx 0, cand no move, fb no move
13SEPreplay, acc 0, prev 7, idx 0, cand no move, fb no moveσ = 7, diff 6
14row 2replay, acc 0, prev 7, idx 1, cand no move, fb heap 0 → 1
15row 4replay, acc 0, prev 7, idx 2, cand heap 1 → 3, fb heap 0 → 1
16row 1replay, acc 0, prev 7, idx 3, cand heap 1 → 3, fb heap 0 → 1
17SEPscan, acc 0, prev 7, idx 0, cand no move, fb no movemove heap 1 → 3

* no previous summary yet (validity bit 0).

Game: (3, 4, 6) —your move (δ = 1)→ (2, 4, 6) —opponent (δ = 7)→ (2, 4, 1)

Only the boards at your decision times

Position fedsummary σdifference
(3, 4, 6)1—
(2, 4, 1)76

The difference 6 = 1 ⊕ 7 spans two moves: yours and the opponent’s.

Including your own post-move board

Position fedsummary σdifference
(3, 4, 6)1—
(2, 4, 6)01
(2, 4, 1)77

Now the last difference is 7, the opponent’s move alone, because your post-move board (2, 4, 6) is the preceding frame.

Computed with the replay controller; feeding your post-move board costs another 2N + 2 updates, and the move it then outputs is discarded.

How this relates to the Lean proof. Each update is one step of Controller.cstep (replay) or BoardStore.bsStep (board storage) on the token streams Controller.dtoks and BoardStore.btoks. The whole-game theorems WholeGame.replay_wins and BoardStore.bits_store_wins prove that, from every board with nonzero nim-sum, iterating these updates wins against every legal opponent. The summary mechanism is Recurrent.step. The comparison of decision-time boards with the post-move board is Bypass.diff_with_postMove and Bypass.diff_decision_only.

What this does not show. Each single update is shallow; the number of updates per decision (2N+22N+2, or N+1N+1 with board storage) grows with the board. That no shallow family computes the complete board-to-move map is a separate statement, conditional on the named classical input that parity is not in AC0\mathrm{AC}^0. The edge cases (an extra separator, a reset) lie outside the protocol streams that the theorems quantify over; the update rule is simply applied. The recurrent strategies are proved in their own stateful game semantics; connecting them to the later history model of weak mastery is a separate adapter that has not been built (coverage record). No recurrent network was trained.

Depicted in Lean: Controller.cstep, Controller.dtoks, Recurrent.replayStep, Recurrent.step, Recurrent.sep_resets, ControllerBits.bstep_reset, BoardStore.bsStep, BoardStore.btoks, Controller.crun_decision, Controller.stream_fits, WholeGame.replay_wins, BoardStore.bits_store_wins, Bypass.diff_with_postMove, Bypass.diff_decision_only, Recurrent.circuit_resources, BoardStore.bsForms_res, BoardStore.bsOuts_res, BoardStore.bs_net.

Computed in your browser by a short re-implementation of the definitions above (tools/visuals/nimvis-core.js). It is not itself checked by Lean. At build time it agreed with Lean's own evaluation of those definitions on all 566 reference cases. The comparison compares every register and output after every token.

3 How this is formalised

  • Recurrent.replay_correct: with σ\sigma from the first scan, the replay move is absent iff the board is terminal, every move is legal, and if σ≠0\sigma\ne0 the move reaches nim-sum zero.
  • Controller.crun_decision: from an idle state, one decision emits the summary and then the move computed from the stored summary, and returns to an idle state.
  • Controller.ctrl_wins: the controller's decisions win from every nonzero board against every legal opponent.
  • Controller.stream_fits: along any well-formed stream every register fits its field; the counter never overflows (with N<2rN<2^r).
  • ThresholdInst.ctrl_counts: with r=⌊log⁡2N⌋+1r=\lfloor\log_2N\rfloor+1 (so N<2rN<2^r) the state has 7+5B+3⌊log⁡2N⌋7+5B+3\lfloor\log_2N\rfloor bits, which is the general width 4+5B+3r4+5B+3r of ControllerBits.stateWidth; each decision uses 2N+22N+2 updates.
  • WholeGame.replay_wins and WholeGame.replay_game: the compiled threshold controller, driven by the protocol, wins from every nonzero position; one reset token starts a game from an arbitrary bit state.
Coverage record
Paper anchorc-replay (website anchor; the manuscript has no label here)
Displayed asSection 5.5, “From a summary to a move”
ClaimReplay protocol rows,SEP,rows,SEP: 2N+2 updates, 4+5B+3r state bits, a legal winning move
Coverage categoryChecked theorem
Statement sourcepaper_jmlr.tex lines 850–860; SHA-256 of the normalised block source 96c224147ee6fabe…
Lean declarations
Assumptions and domain

N<2rN<2^r for the rr-bit counter; heaps below 2B2^B; the environment supplies the current board twice (the replay is an input-protocol assumption, not hidden memory).

Depends onProposition 5.13
Audited correspondence rowsprop:bypass-interfaces
Explanationsexplain/c-replay, formal/c-replay
Build evidencefresh isolated rebuild, audit report

4 Lean statement and source

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

ModuleFileLinesImports
Controllerlean/phase4/Controller.lean401NimRecurrent, AttainCircuit
ControllerBitslean/phase4/ControllerBits.lean1148Controller, NimCorrBridge
NimCorelean/NimCore.lean139Std
NimGamelean/phase2/NimGame.lean634NimRollout
NimRecurrentlean/phase3/NimRecurrent.lean555NimAttain, Circuit
ThresholdInstlean/phase5/ThresholdInst.lean475ThresholdNet, PriorityEncoder
WholeGamelean/phase5/WholeGame.lean347ThresholdInst

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).