Sprague–Grundy theorem
In combinatorial game theory, the Sprague–Grundy theorem states that every impartial game under the normal play convention is equivalent to a one-heap game of nim, or to an infinite generalization of nim. It can therefore be represented as a natural number, the size of the heap in its equivalent game of nim, as an ordinal number in the infinite generalization, or alternatively as a nimber, the value of that one-heap game in an algebraic system whose addition operation combines multiple heaps to form a single equivalent heap in nim.
The Grundy value or nim-value of any impartial game is the unique nimber that the game is equivalent to. In the case of a game whose positions are indexed by the natural numbers (like nim itself, which is indexed by its heap sizes), the sequence of nimbers for successive positions of the game is called the nim-sequence of the game.
The Sprague–Grundy theorem and its proof encapsulate the main results of a theory discovered independently by R. P. Sprague (1936)[1] and P. M. Grundy (1939).[2]
Definitions
For the purposes of the Sprague–Grundy theorem, a game is a two-player sequential game of perfect information satisfying the ending condition (all games come to an end: there are no infinite lines of play) and the normal play condition (a player who cannot move loses).
At any given point in the game, a player's position is the set of moves they are allowed to make. As an example, we can define the zero game to be the two-player game where neither player has any legal moves. Referring to the two players as [math]\displaystyle{ A }[/math] (for Alice) and [math]\displaystyle{ B }[/math] (for Bob), we would denote their positions as [math]\displaystyle{ (A, B) = (\{\}, \{\}) }[/math], since the set of moves each player can make is empty.
An impartial game is one in which at any given point in the game, each player is allowed exactly the same set of moves. Normal-play nim is an example of an impartial game. In nim, there are one or more heaps of objects, and two players (we'll call them Alice and Bob), take turns choosing a heap and removing 1 or more objects from it. The winner is the player who removes the final object from the final heap. The game is impartial because for any given configuration of pile sizes, the moves Alice can make on her turn are exactly the same moves Bob would be allowed to make if it were his turn. In contrast, a game such as checkers is not impartial because, supposing Alice were playing red and Bob were playing black, for any given arrangement of pieces on the board, if it were Alice's turn, she would only be allowed to move the red pieces, and if it were Bob's turn, he would only be allowed to move the black pieces.
Note that any configuration of an impartial game can therefore be written as a single position, because the moves will be the same no matter whose turn it is. For example, the position of the zero game can simply be written [math]\displaystyle{ \{\} }[/math], because if it's Alice's turn, she has no moves to make, and if it's Bob's turn, he has no moves to make either. A move can be associated with the position it leaves the next player in.
Doing so allows positions to be defined recursively. For example, consider the following game of Nim played by Alice and Bob.
Example Nim Game
Sizes of heaps Moves A B C 1 2 2 Alice takes 1 from A 0 2 2 Bob takes 1 from B 0 1 2 Alice takes 1 from C 0 1 1 Bob takes 1 from B 0 0 1 Alice takes 1 from C 0 0 0 Bob has no moves, so Alice wins
- At step 6 of the game (when all of the heaps are empty) the position is [math]\displaystyle{ \{\} }[/math], because Bob has no valid moves to make. We name this position [math]\displaystyle{ *0 }[/math].
- At step 5, Alice had exactly one option: to remove one object from heap C, leaving Bob with no moves. Since her move leaves Bob in position [math]\displaystyle{ *0 }[/math], her position is written [math]\displaystyle{ \{ *0 \} }[/math]. We name this position [math]\displaystyle{ *1 }[/math].
- At step 4, Bob had two options: remove one from B or remove one from C. Note, however, that it didn't really matter which heap Bob removed the object from: Either way, Alice would be left with exactly one object in exactly one pile. So, using our recursive definition, Bob really only has one move: [math]\displaystyle{ *1 }[/math]. Thus, Bob's position is [math]\displaystyle{ \{*1\} }[/math].
- At step 3, Alice had 3 options: remove two from C, remove one from C, or remove one from B. Removing two from C leaves Bob in position [math]\displaystyle{ *1 }[/math]. Removing one from C leaves Bob with two piles, each of size one, i.e., position [math]\displaystyle{ \{*1\} }[/math], as described in step 4. However, removing 1 from B would leave Bob with two objects in a single pile. His moves would then be [math]\displaystyle{ *0 }[/math] and [math]\displaystyle{ *1 }[/math], so her move would result in the position [math]\displaystyle{ \{*0, *1\} }[/math]. We call this position [math]\displaystyle{ *2 }[/math]. Alice's position is then the set of all her moves: [math]\displaystyle{ \big\{*1, \{*1\}, *2\big\} }[/math].
- Following the same recursive logic, at step 2, Bob's position is [math]\displaystyle{ \big\{ \{*1, \{*1\}, *2\}, *2\big\}. }[/math]
- Finally, at step 1, Alice's position is [math]\displaystyle{ \Big\{ \big\{*1, \{*1\}, *2\big\}, \big\{*2, \{*1, \{*1\},*2\} \big\}, \big\{\{*1\}, \{\{*1\}\}, \{*1, \{*1\}, *2\}\big\} \Big\}. }[/math]
Nimbers
The special names [math]\displaystyle{ *0 }[/math], [math]\displaystyle{ *1 }[/math], and [math]\displaystyle{ *2 }[/math] referenced in our example game are called nimbers. In general, the nimber [math]\displaystyle{ *n }[/math] corresponds to the position in a game of nim where there are exactly [math]\displaystyle{ n }[/math] objects in exactly one heap. Formally, nimbers are defined inductively as follows: [math]\displaystyle{ *0 }[/math] is [math]\displaystyle{ \{\} }[/math], [math]\displaystyle{ *1 = \{*0\} }[/math], [math]\displaystyle{ *2 = \{*0, *1\} }[/math] and for all [math]\displaystyle{ n \geq 0 }[/math], [math]\displaystyle{ *(n+1) = *n \cup \{*n\} }[/math].
While the word nimber comes from the game nim, nimbers can be used to describe the positions of any finite, impartial game, and in fact, the Sprague–Grundy theorem states that every instance of a finite, impartial game can be associated with a single nimber.
Combining Games
Two games can be combined by adding their positions together. For example, consider another game of nim with heaps [math]\displaystyle{ A' }[/math], [math]\displaystyle{ B' }[/math], and [math]\displaystyle{ C' }[/math].
Example Game 2
Sizes of heaps Moves A' B' C' 1 1 1 Alice takes 1 from A' 0 1 1 Bob takes one from B' 0 0 1 Alice takes one from C' 0 0 0 Bob has no moves, so Alice wins.
We can combine it with our first example to get a combined game with six heaps: [math]\displaystyle{ A }[/math], [math]\displaystyle{ B }[/math], [math]\displaystyle{ C }[/math], [math]\displaystyle{ A' }[/math], [math]\displaystyle{ B' }[/math], and [math]\displaystyle{ C' }[/math]:
Combined Game
Sizes of heaps Moves A B C A' B' C' 1 2 2 1 1 1 Alice takes 1 from A 0 2 2 1 1 1 Bob takes 1 from A' 0 2 2 0 1 1 Alice takes 1 from B' 0 2 2 0 0 1 Bob takes 1 from C' 0 2 2 0 0 0 Alice takes 2 from B 0 0 2 0 0 0 Bob takes 2 from C 0 0 0 0 0 0 Alice has no moves, so Bob wins.
To differentiate between the two games, for the first example game, we'll label its starting position [math]\displaystyle{ \color{blue}S }[/math], and color it blue: [math]\displaystyle{ \color{blue}S = \Big\{ \big\{*1, \{*1\}, *2\big\}, \big\{*2, \{*1, \{*1\},*2\} \big\}, \big\{\{*1\}, \{\{*1\}\}, \{*1, \{*1\}, *2\}\big\} \Big\} }[/math]
For the second example game, we'll label the starting position [math]\displaystyle{ \color{red}S' }[/math] and color it red: [math]\displaystyle{ \color{red}S' = \Big\{\{*1\}\Big\}. }[/math]
To compute the starting position of the combined game, remember that a player can either make a move in the first game, leaving the second game untouched, or make a move in the second game, leaving the first game untouched. So the combined game's starting position is: [math]\displaystyle{ \color{blue}S \color{black} + \color{red}S' \color{black}= \Big\{ \color{blue}S\color{black} + \color{red} \{*1\} \color{black} \Big\} \cup \Big\{ \color{red}S'\color{black} + \color{blue}\{*1, \{*1\}, *2\} \color{black}, \color{red}S'\color{black} + \color{blue} \{*2, \{*1, \{*1\},*2\} \} \color{black}, \color{red}S'\color{black} + \color{blue} \{\{*1\}, \{\{*1\}\}, \{*1, \{*1\}, *2\}\} \color{black} \Big\} }[/math]
The explicit formula for adding positions is: [math]\displaystyle{ S+S'=\{S+s'\mid s'\in S'\}\cup\{s+S'\mid s\in S\} }[/math], which means that addition is both commutative and associative.
Equivalence
Positions in impartial games fall into two outcome classes: either the next player (the one whose turn it is) wins (an [math]\displaystyle{ \boldsymbol{\mathcal{N}} }[/math]- position), or the previous player wins (a [math]\displaystyle{ \boldsymbol{\mathcal{P}} }[/math]- position). So, for example, [math]\displaystyle{ *0 }[/math] is a [math]\displaystyle{ \mathcal{P} }[/math]-position, while [math]\displaystyle{ *1 }[/math] is an [math]\displaystyle{ \mathcal{N} }[/math]-position.
Two positions [math]\displaystyle{ G }[/math] and [math]\displaystyle{ G' }[/math] are equivalent if, no matter what position [math]\displaystyle{ H }[/math] is added to them, they are always in the same outcome class. Formally, [math]\displaystyle{ G \approx G' }[/math] if and only if [math]\displaystyle{ \forall H }[/math], [math]\displaystyle{ G + H }[/math] is in the same outcome class as [math]\displaystyle{ G' + H }[/math].
To use our running examples, notice that in both the first and second games above, we can show that on every turn, Alice has a move that forces Bob into a [math]\displaystyle{ \mathcal{P} }[/math]-position. Thus, both [math]\displaystyle{ \color{blue}S }[/math] and [math]\displaystyle{ \color{red}S' }[/math] are [math]\displaystyle{ \mathcal{N} }[/math]-positions. (Notice that in the combined game, Bob is the player with the [math]\displaystyle{ \mathcal{N} }[/math]-positions. In fact, [math]\displaystyle{ \color{blue}S \color{black} + \color{red}S' }[/math] is a [math]\displaystyle{ \mathcal{P} }[/math]-position, which as we will see in Lemma 2, means [math]\displaystyle{ \color{blue} S \color{black} \approx \color{red} S' }[/math].)
First Lemma
As an intermediate step to proving the main theorem, we show that for every position [math]\displaystyle{ G }[/math] and every [math]\displaystyle{ \mathcal{P} }[/math]-position [math]\displaystyle{ A }[/math], the equivalence [math]\displaystyle{ G\approx A+G }[/math] holds. By the above definition of equivalence, this amounts to showing that [math]\displaystyle{ G+H }[/math] and [math]\displaystyle{ A+G+H }[/math] share an outcome class for all [math]\displaystyle{ H }[/math].
Suppose that [math]\displaystyle{ G+H }[/math] is a [math]\displaystyle{ \mathcal{P} }[/math]-position. Then the previous player has a winning strategy for [math]\displaystyle{ A+G+H }[/math]: respond to moves in [math]\displaystyle{ A }[/math] according to their winning strategy for [math]\displaystyle{ A }[/math] (which exists by virtue of [math]\displaystyle{ A }[/math] being a [math]\displaystyle{ \mathcal{P} }[/math]-position), and respond to moves in [math]\displaystyle{ G+H }[/math] according to their winning strategy for [math]\displaystyle{ G+H }[/math] (which exists for the analogous reason). So [math]\displaystyle{ A+G+H }[/math] must also be a [math]\displaystyle{ \mathcal{P} }[/math]-position.
On the other hand, if [math]\displaystyle{ G+H }[/math] is an [math]\displaystyle{ \mathcal{N} }[/math]-position, then [math]\displaystyle{ A+G+H }[/math] is also an [math]\displaystyle{ \mathcal{N} }[/math]-position, because the next player has a winning strategy: choose a [math]\displaystyle{ \mathcal{P} }[/math]-position from among the [math]\displaystyle{ G+H }[/math] options, and we conclude from the previous paragraph that adding [math]\displaystyle{ A }[/math] to that position is still a [math]\displaystyle{ \mathcal{P} }[/math]-position. Thus, in this case, [math]\displaystyle{ A+G+H }[/math] must be a [math]\displaystyle{ \mathcal{N} }[/math]-position, just like [math]\displaystyle{ G+H }[/math].
As these are the only two cases, the lemma holds.
Second Lemma
As a further step, we show that [math]\displaystyle{ G\approx G' }[/math] if and only if [math]\displaystyle{ G+G' }[/math] is a [math]\displaystyle{ \mathcal{P} }[/math]-position.
In the forward direction, suppose that [math]\displaystyle{ G\approx G' }[/math]. Applying the definition of equivalence with [math]\displaystyle{ H=G }[/math], we find that [math]\displaystyle{ G'+G }[/math] (which is equal to [math]\displaystyle{ G+G' }[/math] by commutativity of addition) is in the same outcome class as [math]\displaystyle{ G+G }[/math]. But [math]\displaystyle{ G+G }[/math] must be a [math]\displaystyle{ \mathcal{P} }[/math]-position: for every move made in one copy of [math]\displaystyle{ G }[/math], the previous player can respond with the same move in the other copy, and so always make the last move.
In the reverse direction, since [math]\displaystyle{ A=G+G' }[/math] is a [math]\displaystyle{ \mathcal{P} }[/math]-position by hypothesis, it follows from the first lemma, [math]\displaystyle{ G\approx G+A }[/math], that [math]\displaystyle{ G\approx G+(G+G') }[/math]. Similarly, since [math]\displaystyle{ B=G+G }[/math] is also a [math]\displaystyle{ \mathcal{P} }[/math]-position, it follows from the first lemma in the form [math]\displaystyle{ G'\approx G'+B }[/math] that [math]\displaystyle{ G'\approx G'+(G+G) }[/math]. By associativity and commutativity, the right-hand sides of these results are equal. Furthermore, [math]\displaystyle{ \approx }[/math] is an equivalence relation because equality is an equivalence relation on outcome classes. Via the transitivity of [math]\displaystyle{ \approx }[/math], we can conclude that [math]\displaystyle{ G\approx G' }[/math].
Proof
We prove that all positions are equivalent to a nimber by structural induction. The more specific result, that the given game's initial position must be equivalent to a nimber, shows that the game is itself equivalent to a nimber.
Consider a position [math]\displaystyle{ G = \{G_1, G_2, \ldots, G_k\} }[/math]. By the induction hypothesis, all of the options are equivalent to nimbers, say [math]\displaystyle{ G_i \approx *n_i }[/math]. So let [math]\displaystyle{ G'=\{*n_1, *n_2, \ldots, *n_k\} }[/math]. We will show that [math]\displaystyle{ G \approx *m }[/math], where [math]\displaystyle{ m }[/math] is the mex (minimum exclusion) of the numbers [math]\displaystyle{ n_1, n_2, \ldots, n_k }[/math], that is, the smallest non-negative integer not equal to some [math]\displaystyle{ n_i }[/math].
The first thing we need to note is that [math]\displaystyle{ G \approx G' }[/math], by way of the second lemma. If [math]\displaystyle{ k }[/math] is zero, the claim is trivially true. Otherwise, consider [math]\displaystyle{ G+G' }[/math]. If the next player makes a move to [math]\displaystyle{ G_i }[/math] in [math]\displaystyle{ G }[/math], then the previous player can move to [math]\displaystyle{ *n_i }[/math] in [math]\displaystyle{ G' }[/math], and conversely if the next player makes a move in [math]\displaystyle{ G' }[/math]. After this, the position is a [math]\displaystyle{ \mathcal{P} }[/math]-position by the lemma's forward implication. Therefore, [math]\displaystyle{ G+G' }[/math] is a [math]\displaystyle{ \mathcal{P} }[/math]-position, and, citing the lemma's reverse implication, [math]\displaystyle{ G \approx G' }[/math].
Now let us show that [math]\displaystyle{ G'+*m }[/math] is a [math]\displaystyle{ \mathcal{P} }[/math]-position, which, using the second lemma once again, means that [math]\displaystyle{ G'\approx *m }[/math]. We do so by giving an explicit strategy for the previous player.
Suppose that [math]\displaystyle{ G' }[/math] and [math]\displaystyle{ *m }[/math] are empty. Then [math]\displaystyle{ G'+*m }[/math] is the null set, clearly a [math]\displaystyle{ \mathcal{P} }[/math]-position.
Or consider the case that the next player moves in the component [math]\displaystyle{ *m }[/math] to the option [math]\displaystyle{ *m' }[/math] where [math]\displaystyle{ m'\lt m }[/math]. Because [math]\displaystyle{ m }[/math] was the minimum excluded number, the previous player can move in [math]\displaystyle{ G' }[/math] to [math]\displaystyle{ *m' }[/math]. And, as shown before, any position plus itself is a [math]\displaystyle{ \mathcal{P} }[/math]-position.
Finally, suppose instead that the next player moves in the component [math]\displaystyle{ G' }[/math] to the option [math]\displaystyle{ *n_i }[/math]. If [math]\displaystyle{ n_i \lt m }[/math] then the previous player moves in [math]\displaystyle{ *m }[/math] to [math]\displaystyle{ *n_i }[/math]; otherwise, if [math]\displaystyle{ n_i \gt m }[/math], the previous player moves in [math]\displaystyle{ *n_i }[/math] to [math]\displaystyle{ *m }[/math]; in either case the result is a position plus itself. (It is not possible that [math]\displaystyle{ n_i = m }[/math] because [math]\displaystyle{ m }[/math] was defined to be different from all the [math]\displaystyle{ n_i }[/math].)
In summary, we have [math]\displaystyle{ G\approx G' }[/math] and [math]\displaystyle{ G'\approx *m }[/math]. By transitivity, we conclude that [math]\displaystyle{ G \approx *m }[/math], as desired.
Development
If [math]\displaystyle{ G }[/math] is a position of an impartial game, the unique integer [math]\displaystyle{ m }[/math] such that [math]\displaystyle{ G \approx *m }[/math] is called its Grundy value, or Grundy number, and the function that assigns this value to each such position is called the Sprague–Grundy function. R. L. Sprague and P. M. Grundy independently gave an explicit definition of this function, not based on any concept of equivalence to nim positions, and showed that it had the following properties:
- The Grundy value of a single nim pile of size [math]\displaystyle{ m }[/math] (i.e. of the position [math]\displaystyle{ *m }[/math]) is [math]\displaystyle{ m }[/math];
- A position is a loss for the next player to move (i.e. a [math]\displaystyle{ \mathcal{P} }[/math]-position) if and only if its Grundy value is zero; and
- The Grundy value of the sum of a finite set of positions is just the nim-sum of the Grundy values of its summands.
It follows straightforwardly from these results that if a position [math]\displaystyle{ G }[/math] has a Grundy value of [math]\displaystyle{ m }[/math], then [math]\displaystyle{ G + H }[/math] has the same Grundy value as [math]\displaystyle{ *m + H }[/math], and therefore belongs to the same outcome class, for any position [math]\displaystyle{ H }[/math]. Thus, although Sprague and Grundy never explicitly stated the theorem described in this article, it follows directly from their results and is credited to them.[3][4] These results have subsequently been developed into the field of combinatorial game theory, notably by Richard Guy, Elwyn Berlekamp, John Horton Conway and others, where they are now encapsulated in the Sprague–Grundy theorem and its proof in the form described here. The field is presented in the books Winning Ways for your Mathematical Plays and On Numbers and Games.
See also
References
- ↑ "Über mathematische Kampfspiele" (in de). Tohoku Mathematical Journal 41: 438–444. 1936. http://www.jstage.jst.go.jp/article/tmj1911/41/0/41_0_438/_article.
- ↑ "Mathematics and games". Eureka 2: 6–8. 1939. http://www.archim.org.uk/eureka/27/games.html. Reprinted, 1964, 27: 9–11.
- ↑ Smith, Cedric A.B. (1960), "Patrick Michael Grundy, 1917–1959", Journal of the Royal Statistical Society, Series A 123 (2): 221–22
- ↑ Schleicher, Dierk; Stoll, Michael (2006). "An introduction to Conway's games and numbers". Moscow Mathematical Journal 6 (2): 359–388. doi:10.17323/1609-4514-2006-6-2-359-388.
External links
- Grundy's game at cut-the-knot
- Easily readable, introductory account from the UCLA Math Department
- The Game of Nim at sputsoft.com
- Milvang-Jensen, Brit C. A. (2000), Combinatorial Games, Theory and Applications, http://www.itu.dk/people/brit/Brits%20thesis.pdf
Original source: https://en.wikipedia.org/wiki/Sprague–Grundy theorem.
Read more |