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

Definition 5.1Strong, weak and restoration mastery

Checked definition or construction Lean contains the definition or construction, with checked properties.

1 Paper text

Definition 5.1 (Strong, weak, and restoration mastery) An agent achieves strong mastery of NIM if it chooses a winning move at every NN-position where it is to move, including positions reached by arbitrary legal play by both players. Reachability is relative to the specified initial positions and player role; unrestricted strong mastery allows every initial position.

It achieves weak mastery relative to an initial position p0p_0 and a designated player role if, whenever that role has a winning strategy from p0p_0, its own strategy wins against every opponent strategy. The guarantee concerns histories consistent with its own preceding actions, not every position reachable under arbitrary actions by both players. For asymptotic claims, the initial positions form a specified family. Strategies may depend on the complete history. Opponent moves are legal; a missing or illegal agent move counts as a loss. On an initially losing position the weak-mastery condition imposes no requirement.

It achieves restoration mastery if, whenever the opponent moves from a PP-position QQ with nim⁡(Q)=0\operatorname{nim}(Q)=0 to a position Q′Q', the agent responds with a move Q′→RQ'\to R such that nim⁡(R)=0\operatorname{nim}(R)=0.

Generated from paper_jmlr.tex, lines 451–458.

2 Explain this

The paper uses three standards of "playing NIM well".

  • Strong mastery: at every winning position where it is to move, the agent chooses a winning move, including positions that only arise after mistakes by either player.
  • Weak mastery (relative to an initial position and a role): if that role can win from the start, the agent's own strategy wins against every opponent. Positions that the agent's own play never reaches do not matter.
  • Restoration mastery: whenever the opponent moves away from a zero-nim-sum position, the agent moves back to nim-sum zero.

Example of the difference. From the single heap (3)(3), the strategy "take all three stones" wins at once, so it weakly masters (3)(3) as first player. It says nothing about (1)(1), which strong mastery would require after (3)→(2)→(1)(3)\to(2)\to(1) (see Appendix D).

Caveats spelled out in the definition. Strategies may use the whole history. Opponent moves are legal; a missing or illegal agent move counts as a loss. If the designated role is losing from the initial position, weak mastery asks nothing at all: it is vacuous there.

3 How this is formalised

Histories and strategies. A history (Mastery.Hist) is the list of boards so far, most recent first; a strategy (Mastery.Strat) maps a history to a proposed next board or to "no action".

Consistency. Mastery.Cons defines the histories consistent with the agent's own play from an initial board P0P_0 in role rr: on the agent's turns only its own prescribed legal action occurs; on the opponent's turns every legal move may occur.

The notions.

  • Mastery.Guarantee: the strategy wins from P0P_0 in role rr against every legal opponent strategy (plays are finite because stones decrease).
  • Mastery.WeakMastery F r σF\ r\ \sigma: from every initial board in the family FF from which role rr has some winning strategy (Mastery.RoleWinnable), σ\sigma has the guarantee.
  • Mastery.StrongMastery F r σF\ r\ \sigma: at every legal history from FF (arbitrary actions by both players) where the agent is to move at a nonzero nim-sum, σ\sigma moves to nim-sum zero.
  • Restoration: Game.restore_correct shows that the two-frame restoration selector has this property under its promise.

Vacuity, made explicit. Mastery.weakMastery_vacuous: on a family of boards from which the role is losing, every strategy, even one that never moves, is weakly masterful. Strong mastery implies weak mastery (Mastery.strong_weak), and the separation example is Appendix D, paragraph 1.

Coverage record
Paper anchordef:mastery (manuscript label)
Displayed asDefinition 5.1
ClaimStrong, weak and restoration mastery
Coverage categoryChecked definition or construction
Statement sourcepaper_jmlr.tex lines 451–458; SHA-256 of the normalised block source b54757884d24e1f8…
Lean declarations
Assumptions and domain

A designated role (first or second player) and a family of initial boards; deterministic, history-dependent strategies; legal opponents; a missing or illegal agent move is a loss.

Prose-to-formal notes

Weak mastery quantifies over histories consistent with the agent's own earlier actions; strong mastery over all legal histories. On an initially losing board the weak-mastery condition is vacuous, and Lean states this explicitly.

Audited correspondence rowsdef:mastery
Explanationsexplain/def:mastery, formal/def:mastery
Build evidencefresh isolated rebuild, audit report

4 Lean statement and source

Principal declarations

def Mastery.StrongMastery

Module WeakMastery (lean/phase8/WeakMastery.lean, lines 812–817) · file SHA-256 4c83e573f527989c…

Strong mastery (Definition def:mastery, first clause) relative to F and r: at EVERY legal history (arbitrary actions by both players) with the agent to move at an N-position, σ plays a move to a P-position.

Statement as elaborated and printed by Lean 4.26.0

(List ℕ → Prop) → NimAudit.Mastery.Role → NimAudit.Mastery.Strat → Prop
Exact source text, lines 812–817
812/-- Strong mastery (Definition def:mastery, first clause) relative to F and r: at EVERY813    legal history (arbitrary actions by both players) with the agent to move at an814    N-position, σ plays a move to a P-position. -/815def StrongMastery (F : List Nat → Prop) (r : Role) (σ : Strat) : Prop :=816  ∀ P0, F P0 → ∀ h, Legal P0 h → mover h = r → nimSum (cur h) ≠ 0 →817    ∃ Q, σ h = some Q ∧ Move (cur h) Q ∧ nimSum Q = 0

Project declarations in the statement: Mastery.Role, Mastery.Strat

Project declarations used by the proof or definition body

Game.Move, Mastery.Hist, Mastery.Legal, Mastery.Role, Mastery.Strat, Mastery.cur, Mastery.mover, nimSum

def Mastery.WeakMastery

Module WeakMastery (lean/phase8/WeakMastery.lean, lines 614–618) · file SHA-256 4c83e573f527989c…

WEAK MASTERY of policy σ for the family F of initial boards and the designated role r: from every initial board of the family from which the role has SOME winning strategy, σ itself wins against every legal opponent strategy.

Statement as elaborated and printed by Lean 4.26.0

(List ℕ → Prop) → NimAudit.Mastery.Role → NimAudit.Mastery.Strat → Prop
Exact source text, lines 614–618
614/-- WEAK MASTERY of policy σ for the family F of initial boards and the designated role r:615    from every initial board of the family from which the role has SOME winning strategy,616    σ itself wins against every legal opponent strategy. -/617def WeakMastery (F : List Nat → Prop) (r : Role) (σ : Strat) : Prop :=618  ∀ P0, F P0 → RoleWinnable r P0 → Guarantee r σ P0

Project declarations in the statement: Mastery.Role, Mastery.Strat

Project declarations used by the proof or definition body

Mastery.Guarantee, Mastery.Role, Mastery.RoleWinnable, Mastery.Strat

def Mastery.Guarantee

Module WeakMastery (lean/phase8/WeakMastery.lean, lines 287–288) · file SHA-256 4c83e573f527989c…

σ wins from P₀ in role r against EVERY legal opponent strategy.

Statement as elaborated and printed by Lean 4.26.0

NimAudit.Mastery.Role → NimAudit.Mastery.Strat → List ℕ → Prop
Exact source text, lines 287–288
287/-- σ wins from P₀ in role r against EVERY legal opponent strategy. -/288def Guarantee (r : Role) (σ : Strat) (P0 : List Nat) : Prop := ∀ τ, LegalOpp τ → Beats r σ τ P0

Project declarations in the statement: Mastery.Role, Mastery.Strat

Project declarations used by the proof or definition body

Mastery.Beats, Mastery.LegalOpp, Mastery.Role, Mastery.Strat

inductive Mastery.Cons

Module WeakMastery (lean/phase8/WeakMastery.lean, lines 123–129) · file SHA-256 4c83e573f527989c…

Policy-consistent legal histories for the agent in role r using σ: on the agent's turns only its own prescribed legal action occurs; on the opponent's turns any legal move.

Statement as elaborated and printed by Lean 4.26.0

NimAudit.Mastery.Role → NimAudit.Mastery.Strat → List ℕ → NimAudit.Mastery.Hist → Prop
Exact source text, lines 123–129
123/-- Policy-consistent legal histories for the agent in role r using σ: on the agent's turns124    only its own prescribed legal action occurs; on the opponent's turns any legal move. -/125inductive Cons (r : Role) (σ : Strat) (P0 : List Nat) : Hist → Prop126  | init : Cons r σ P0 [P0]127  | opp {h : Hist} {Q : List Nat} : Cons r σ P0 h → mover h ≠ r → Move (cur h) Q → Cons r σ P0 (Q :: h)128  | own {h : Hist} {Q : List Nat} : Cons r σ P0 h → mover h = r → σ h = some Q → Move (cur h) Q →129      Cons r σ P0 (Q :: h)

Project declarations in the statement: Mastery.Hist, Mastery.Role, Mastery.Strat

Project declarations used by the proof or definition body

Game.Move, Mastery.Hist, Mastery.Role, Mastery.Strat, Mastery.cur, Mastery.mover

theorem Mastery.weakMastery_vacuous

Module WeakMastery (lean/phase8/WeakMastery.lean, lines 636–642) · file SHA-256 4c83e573f527989c… Axioms reported by the fresh build: propext, Classical.choice, Quot.sound

THE CONDITIONAL CASE MADE EXPLICIT: at an initial board from which the role is losing there is nothing to check, so on a family of losing boards EVERY policy (even one that never moves) is weakly masterful. Weak mastery is informative only where the role is winnable.

Statement as elaborated and printed by Lean 4.26.0

∀ {F : List ℕ → Prop} {r : NimAudit.Mastery.Role},
  (∀ (P0 : List ℕ), F P0 → ¬NimAudit.Mastery.RoleWinnable r P0) →
    ∀ (σ : NimAudit.Mastery.Strat), NimAudit.Mastery.WeakMastery F r σ
Exact source text, lines 636–642
636/-- THE CONDITIONAL CASE MADE EXPLICIT: at an initial board from which the role is losing637    there is nothing to check, so on a family of losing boards EVERY policy (even one that638    never moves) is weakly masterful.  Weak mastery is informative only where the role is639    winnable. -/640theorem weakMastery_vacuous {F : List Nat → Prop} {r : Role} (hF : ∀ P0, F P0 → ¬ RoleWinnable r P0)641    (σ : Strat) : WeakMastery F r σ :=642  fun P0 h1 h2 => absurd h2 (hF P0 h1)

Project declarations in the statement: Mastery.Role, Mastery.RoleWinnable, Mastery.Strat, Mastery.WeakMastery

Project declarations used by the proof or definition body

Mastery.Guarantee, Mastery.Role, Mastery.RoleWinnable, Mastery.Strat

theorem Game.restore_correct

Module NimGame (lean/phase2/NimGame.lean, lines 412–425) · file SHA-256 23df6bb87ecfd344… Axioms reported by the fresh build: propext, Quot.sound

Statement as elaborated and printed by Lean 4.26.0

∀ {Q Q' : List ℕ},
  NimAudit.nimSum Q = 0 →
    NimAudit.Game.Move Q Q' →
      ∃ R, NimAudit.Game.restore Q Q' = some R ∧ NimAudit.Game.Move Q' R ∧ NimAudit.nimSum R = 0
Exact source text, lines 412–425
412theorem restore_correct {Q Q' : List Nat} (h0 : nimSum Q = 0) (hm : Move Q Q') :413    ∃ R, restore Q Q' = some R ∧ Move Q' R ∧ nimSum R = 0 := by414  have hne := move_from_zero hm h0415  have hd : nimSum Q ^^^ nimSum Q' = nimSum Q' := by rw [h0, Nat.zero_xor]416  obtain ⟨R, hsel, hmR, hR⟩ := selectMove_zero hne417  refine ⟨R, ?_, hmR, hR⟩418  unfold restore419  rw [hd]420  simp only [selectMove, hne, if_false] at hsel421  split at hsel422  · next q' hq' => cases hsel; exact hq'423  · next _ hnone =>424    obtain ⟨pre, x, post, hp, hlt, _⟩ := exists_decreasing_heap Q' hne425    exact absurd hlt (cancelFirst_none hnone x (by rw [hp]; simp))

Project declarations in the statement: Game.Move, Game.restore, nimSum

Project declarations used by the proof or definition body

Game.Move, Game.cancelFirst, Game.cancelFirst_none, Game.move_from_zero, Game.restore, Game.selectMove, Game.selectMove_zero, Rollout.exists_decreasing_heap, Rollout.subFirstPos, nimSum

Definitions these statements use

def Mastery.Hist

Module WeakMastery (lean/phase8/WeakMastery.lean, lines 51–52) · file SHA-256 4c83e573f527989c…

A history: the boards so far, MOST RECENT FIRST; its last entry is the initial board.

Statement as elaborated and printed by Lean 4.26.0

Type
Exact source text, lines 51–52
51/-- A history: the boards so far, MOST RECENT FIRST; its last entry is the initial board. -/52abbrev Hist := List (List Nat)

Project declarations in the statement: none

Project declarations used by the proof or definition body

none

def Mastery.Strat

Module WeakMastery (lean/phase8/WeakMastery.lean, lines 54–55) · file SHA-256 4c83e573f527989c…

A (history-dependent) strategy proposes the next board; `none` means no action.

Statement as elaborated and printed by Lean 4.26.0

Type
Exact source text, lines 54–55
54/-- A (history-dependent) strategy proposes the next board; `none` means no action. -/55abbrev Strat := Hist → Option (List Nat)

Project declarations in the statement: none

Project declarations used by the proof or definition body

Mastery.Hist

def Mastery.RoleWinnable

Module WeakMastery (lean/phase8/WeakMastery.lean, lines 419–420) · file SHA-256 4c83e573f527989c…

The role r has a winning strategy from P₀ (existence, separate from any policy).

Statement as elaborated and printed by Lean 4.26.0

NimAudit.Mastery.Role → List ℕ → Prop
Exact source text, lines 419–420
419/-- The role r has a winning strategy from P₀ (existence, separate from any policy). -/420def RoleWinnable (r : Role) (P0 : List Nat) : Prop := ∃ σ : Strat, Guarantee r σ P0

Project declarations in the statement: Mastery.Role

Project declarations used by the proof or definition body

Mastery.Guarantee, Mastery.Role, Mastery.Strat

inductive Mastery.Role

Module WeakMastery (lean/phase8/WeakMastery.lean, lines 37–40) · file SHA-256 4c83e573f527989c…

Statement as elaborated and printed by Lean 4.26.0

Type
Exact source text, lines 37–40
37inductive Role where38  | first39  | second40  deriving DecidableEq

Project declarations in the statement: none

Project declarations used by the proof or definition body

none

def Game.Move

Module NimGame (lean/phase2/NimGame.lean, lines 24–26) · file SHA-256 23df6bb87ecfd344…

An ordinary legal Nim move: exactly one heap strictly decreases.

Statement as elaborated and printed by Lean 4.26.0

List ℕ → List ℕ → Prop
Exact source text, lines 24–26
24/-- An ordinary legal Nim move: exactly one heap strictly decreases. -/25def Move (p q : List Nat) : Prop :=26  ∃ pre x post y, p = pre ++ x :: post ∧ q = pre ++ y :: post ∧ y < x

Project declarations in the statement: none

Project declarations used by the proof or definition body

none

def Game.restore

Module NimGame (lean/phase2/NimGame.lean, lines 407–410) · file SHA-256 23df6bb87ecfd344…

Two-frame restoration selector (paper Prop. restore / Thm search-gap (iii)): from the predecessor Q and current board Q', cancel delta = nim(Q) XOR nim(Q').

Statement as elaborated and printed by Lean 4.26.0

List ℕ → List ℕ → Option (List ℕ)
Exact source text, lines 407–410
407/-- Two-frame restoration selector (paper Prop. restore / Thm search-gap (iii)):408    from the predecessor Q and current board Q', cancel delta = nim(Q) XOR nim(Q'). -/409def restore (Q Q' : List Nat) : Option (List Nat) :=410  cancelFirst (nimSum Q ^^^ nimSum Q') Q'

Project declarations in the statement: none

Project declarations used by the proof or definition body

Game.cancelFirst, nimSum

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

Full modules

ModuleFileLinesImports
NimCorelean/NimCore.lean139Std
NimGamelean/phase2/NimGame.lean634NimRollout
WeakMasterylean/phase8/WeakMastery.lean959Misc

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