Nim - Proof of The Winning Formula

Proof of The Winning Formula

The soundness of the optimal strategy described above was demonstrated by C. Bouton.

Theorem. In a normal Nim game, the player making the first move has a winning strategy if and only if the nim-sum of the sizes of the heaps is nonzero. Otherwise, the second player has a winning strategy.

Proof: Notice that the nim-sum (⊕) obeys the usual associative and commutative laws of addition (+), and also satisfies an additional property, xx = 0 (technically speaking, the nonnegative integers under ⊕ form an Abelian group of exponent 2).

Let x1, ..., xn be the sizes of the heaps before a move, and y1, ..., yn the corresponding sizes after a move. Let s = x1 ⊕ ... ⊕ xn and t = y1 ⊕ ... ⊕ yn. If the move was in heap k, we have xi = yi for all ik, and xk > yk. By the properties of ⊕ mentioned above, we have

t = 0 ⊕ t = sst = s ⊕ (x1 ⊕ ... ⊕ xn) ⊕ (y1 ⊕ ... ⊕ yn) = s ⊕ (x1y1) ⊕ ... ⊕ (xnyn) = s ⊕ 0 ⊕ ... ⊕ 0 ⊕ (xkyk) ⊕ 0 ⊕ ... ⊕ 0 = sxkyk (*) t = sxkyk.

The theorem follows by induction on the length of the game from these two lemmas.

Lemma 1. If s = 0, then t ≠ 0 no matter what move is made.

Proof: If there is no possible move, then the lemma is vacuously true (and the first player loses the normal play game by definition). Otherwise, any move in heap k will produce t = xkyk from (*). This number is nonzero, since xkyk.

Lemma 2. If s ≠ 0, it is possible to make a move so that t = 0.

Proof: Let d be the position of the leftmost (most significant) nonzero bit in the binary representation of s, and choose k such that the dth bit of xk is also nonzero. (Such a k must exist, since otherwise the dth bit of s would be 0.) Then letting yk = sxk, we claim that yk < xk: all bits to the left of d are the same in xk and yk, bit d decreases from 1 to 0 (decreasing the value by 2d), and any change in the remaining bits will amount to at most 2d−1. The first player can thus make a move by taking xkyk objects from heap k, then

t = sxkyk (by (*)) = sxk ⊕ (sxk) = 0.

The modification for misère play is demonstrated by noting that the modification first arises in a position that has only one heap of size 2 or more. Notice that in such a position s ≠ 0, therefore this situation has to arise when it is the turn of the player following the winning strategy. The normal play strategy is for the player to reduce this to size 0 or 1, leaving an even number of heaps with size 1, and the misère strategy is to do the opposite. From that point on, all moves are forced.

Read more about this topic:  Nim

Famous quotes containing the words proof of the, proof of, proof, winning and/or formula:

    From whichever angle one looks at it, the application of racial theories remains a striking proof of the lowered demands of public opinion upon the purity of critical judgment.
    Johan Huizinga (1872–1945)

    A short letter to a distant friend is, in my opinion, an insult like that of a slight bow or cursory salutation—a proof of unwillingness to do much, even where there is a necessity of doing something.
    Samuel Johnson (1709–1784)

    In the reproof of chance
    Lies the true proof of men.
    William Shakespeare (1564–1616)

    ... the most extreme conditions require the most extreme response, and for some individuals, the call to that response is vitality itself.... The integrity and self-esteem gained from winning the battle against extremity are the richest treasures in my life.
    Diana Nyad (b. 1949)

    For the myth is the foundation of life; it is the timeless schema, the pious formula into which life flows when it reproduces its traits out of the unconscious.
    Thomas Mann (1875–1955)