More about Exact Slow k-Nim
Nikolay Chikin, Vladimir Gurvich, Konstantin Knop, Mike Paterson, Michael Vyalyi
aa r X i v : . [ m a t h . C O ] F e b More about Exact Slow k - Nim
Nikolay Chikin ∗ Vladimir Gurvich † Konstantin Knop ‡ Mike Paterson § Michael Vyalyi ¶ February 9, 2021
Abstract
Given n piles of tokens and a positive integer k ≤ n , the game Nim n, = k of exact slow k - Nim is played as follows. Two players move alternately.In each move, a player chooses exactly k non-empty piles and removes onetoken from each of them. A player whose turn it is to move but has no moveloses (if the normal version of the game is played, and wins if it is the mis´ereversion). In Integers 20 (2020) 1–19, Gurvich et al gave an explicit formulafor the Sprague-Grundy function of Nim , =2 , for both its normal and mis´ereversion. Here we extend this result and obtain an explicit formula for theP-positions of the normal version of Nim , =2 and Nim , =2 . Key words:
Exact
Nim , normal and mis´ere versions, P-positions,Sprague-Grundy function.MSC classes: 91A46, 91A05
Games
Nim n, = k and Nim n, ≤ k of Exact and Moore’s Slow k - Nim were in-troduced in 2015 [3]. The present paper extends some results obtained in[4] for
Nim , =2 to Nim , =2 and Nim , =2 . All basic definitions (impartial ∗ National Research University Higher School of Economics (HSE), Moscow, Russia;e-mail: [email protected] † National Research University Higher School of Economics (HSE), Moscow, Russia;e-mail: [email protected] and [email protected] ‡ HIL company (Horis International Limited); e-mail: [email protected] § Department of Computer Science, University of Warwick, UK; e-mail:[email protected] ¶ National Research University Higher School of Economics, Moscow, Russia; Instituteof Physics and Technology, Dolgorpudnyi, Russia; Dorodnicyn Computing Centre, FRCCSC RAS, Moscow, Russia; e-mail: [email protected]
Nim n, = k .Positions of Nim n, = k are represented by nonnegative integer n -vectors x = ( x , . . . , x n ). An n -vector x is called nondecreasing if x ≤ . . . ≤ x n . We will always assume that positions of Nim n, = k are represented bynondecreasing vectors, yet this assumption may hold for x but fail for x ′ after a move x → x ′ . In this case we reorder coordinates of x ′ to maintainthe assumption; see more details in [4].Note that Nim n ′ , = k is a subgame of Nim n, = k whenever n ′ ≤ n . Indeed,the set of n -vectors x = ( x , . . . , x n ) (which are positions of Nim n, = k ) whosefirst n − n ′ coordinates are zeros is in an obvious one-to-one correspondencewith the set of n ′ -vectors (which are the positions of Nim n ′ , = k ). Thus,a formula for the P-positions or the Sprague-Grundy function of Nim n, = k works for Nim n ′ , = k as well.By definition, any move x → x ′ in Nim n, = k reduces exactly k coordinatesof x by exactly one each; hence, P ni =1 x i = P ni =1 x ′ i mod k . Thus Nim n, = k is split into k disjoint subgames Nim n, = k [ j ] for j = 0 , . . . , k − P ni =1 x i = j mod k .Explicit formulas were obtained in [4] for the Sprague-Grundy functionof both the normal and mis´ere versions of Nim , =2 . Here we extend thisresult and give explicit formulas for the P-positions of the normal versionsof Nim , =2 and Nim , =2 . We will assume that Nim n, = k and Nim n, = k [ j ] referto the normal version of the game unless it is explicitly said otherwise.Given x = ( x , . . . , x n ), its parity vector p ( x ) = ( p ( x , . . . , p ( x n )) is de-fined as follows: p ( x ) has n coordinates taking values p ( x i ) = e if x i is evenand p ( x i ) = o if x i is odd, for i = 1 , . . . , n . Theorem 1.
The P-positions of
Nim , =2 [0] are characterized by the parityvectors: ( e, e, o, o, o, o ) , ( o, o, e, e, o, o ) , ( o, o, o, o, e, e ) , ( e, e, e, e, e, e ) . (1) Remark 1.
Somewhat surprisingly, the same characterization holds for theP-positions of Moore’s Slow
Nim , ≤ ; see part (5) of Theorem 2 in [4].2he set of P-positions of Nim , =2 [0] can be defined by a system of linearequations modulo 2 and the nondecreasing condition. More specifically, thesystem of equations is x − x ≡ ,x − x ≡ ,x − x − x ≡ . (2)Note that Eq. (2) implies x − x ≡ x − x + ( x − x ) + ( x − x ) ≡ x + x + x + x + x + x ≡ x ≡ x (mod 2).The following concept will play an important role. Given a Nim n, = k or Nim n, = k [ j ], a nonnegative nondecreasing n -vector y is called a P-shift if for any nondecreasing n -vector x we have: either both x and x + y areP-positions of the considered game, or both are not. Obviously, if y ′ and y ′′ are P-shifts then y = y ′ + y ′′ is a P-shift too.By Theorem 1, the nonnegative nondecreasing 6-vectors with even co-ordinates and also vectors (0 , , , , ,
1) and (1 , , , , ,
2) are P-shifts in
Nim , =2 [0]. (Eq. (2) helps to check this claim.)As for Nim , =2 [1], the set of P-positions has a more complicated struc-ture. To describe it, we introduce several conditions on a nondecreasing6-vector ( x , x , x , x , x , x ).Define E ( x ) to be true if Eq. (2) is satisfied by x ; F ( x ) to be true if x − x is even; and K ( x ) to be true if the total number of tokens N ( x ) hasresidue 1 modulo 4, i.e. N ( x ) = x + x + x + x + x + x ≡ . We define the functions r ( x ) = x + x − x ,s ( x ) = x − x + x − x − x + x ,u ( x ) = s ( x ) − r ( x ) + 1 . Note that since N ( x ) is odd, s ( x ) is also odd, and u ( x ) is even. Using thesefunctions we define T ( x ) = min( s ( x ) , u ( x )) and identify three regions asfollows: A = { x : T ( x ) > } , B = { x : T ( x ) = 0 } , C = { x : T ( x ) < } . heorem 2. The P-positions of
Nim , =2 [1] coincide with the set P = { x : (cid:0) E ( x ) ∧ ( x ∈ A ) (cid:1) ∨ (cid:0) K ( x ) ∧ F ( x ) ∧ ( x ∈ B ) (cid:1) ∨ (cid:0) K ( x ) ∧ ( x ∈ C ) (cid:1) } . To get a description of P-positions for
Nim , =2 one should set x = 0 inTheorems 1 and 2 and shift indices by 1. This gives two corollaries. Corollary 1.
The P-positions of
Nim , =2 [0] are characterized by the parityvectors: ( e, o, o, o, o ) , ( e, e, e, e, e ) . (3) Proof.
The two other parity vectors correspond to odd values of x inEq. (1).If y = ( y , y , y , y , y ) and x = (0 , y , y , y , y , y ), then define r ′ ( y ) = r ( x ) = y − y ,s ′ ( y ) = s ( x ) = − y + y − y − y + y ,u ′ ( y ) = u ( x ) = s ′ ( y ) − r ′ ( y ) + 1 ,E ′ ( y ) = E ( x ) = ( y ≡ y − y ≡ y − y ≡ ,K ′ ( y ) = K ( x ) = y + y + y + y + y ≡ . Since the components of x and y are in sorted order, r ′ ( y ) ≤ u ′ ( y ) >s ′ ( y ), and so T ′ ( y ) = min( s ′ ( y ) , u ′ ( y )) = s ′ ( y ). Corollary 2.
The P-positions of
Nim , =2 [1] are characterized by the formula ( T ′ < K ′ ∨ ( T ′ > E ′ . Proof.
The conditions of this corollary are obtained from the conditions ofTheorem 2 by setting x = (0 , y , y , y , y , y ) as in the definitions above.Since T ′ ( y ) = s ′ ( y ) ≡ y + y + y + y + y ≡ T ′ ( y ) = 0,corresponding to x ∈ B , is impossible. The correspondence x ∈ A if T ′ ( y ) > x ∈ C if T ′ ( y ) < Nim , =2 [1].There are fewer invariant shifts in Nim , =2 [1] than in Nim , =2 [0]. Proposition 1.
Shifts by vectors y (1) = (0 , , , , , , y (2) = (1 , , , , , ,y (3) = (0 , , , , , , y (4) = (0 , , , , , preserve the sets described in Theorems and . Nim , =2 . Proof.
As mentioned above, shifts by these vectors preserve the set describedin Theorem 1. It remains to prove that they preserve the set described inTheorem 2.A shift by a vector y ( i ) , 1 ≤ i ≤
4, preserves the parities of x − x , x − x , x − x − x . So the conditions E and F are invariant under theshifts.A shift by y ( i ) , 1 ≤ i ≤
4, changes the total number of tokens by amultiple of 4. So the condition K is also invariant under the shifts.Note that y ( i )1 + y ( i )4 − y ( i )5 = 0 ,y ( i )1 − y ( i )2 + y ( i )3 − y ( i )4 − y ( i )5 + y ( i )6 = 0 . for 1 ≤ i ≤
4. Thus the shifts preserve the values of each of the functions r , s , u and T .The rest of the paper is organized as follows. In Section 2 we studyP-shifts (as well as some “stronger” concepts). In Section 3.1 we proveTheorem 1, and in Section 3.2. we prove Theorem 2. Note that vector (0 , , , ,
2) is a P-shift in
Nim , =2 assuming Corollaries 1and 2. The shift by this vector preserves the set described by Eq. (3). Itchanges the total number of tokens by a multiple of 4 and it preserves thecondition E ′ and the function T ′ . Thus it preserves the set described inCorollaries 1 and 2.There are more examples: (1 , , ,
1) and (1 , , , , ,
1) are P-shifts for
Nim , =2 and Nim , =3 , respectively; (0 , , , ,
1) and (0 , , , , , ,
1) are P-shifts for
Nim , =2 and Nim , =3 , respectively; (0 , , ,
2) and (0 , , , ,
2) areP-shifts for
Nim , =3 and Nim , =4 , respectively.Our next statement, generalizing all six examples, will require the fol-lowing definitions and notation.Given a game Nim n, = k or Nim n, = k [ j ], a nonnegative nondecreasing n -vector y will be called a g -shift, or g − -shift, or g ± -shift if adding y to anyposition x of the considered game preserves the Sprague-Grundy (SG) value,mis`ere SG value, or both values, respectively; in other words, if for any5onnegative nondecreasing n -vector x we have g ( x ) = g ( x + y ), or g − ( x ) = g − ( x + y ), or both equalities hold, respectively.The reader may recall the definitions of the normal and mis`ere SG func-tions from the introduction of [4]. As usual, by a ℓ we denote a symbol (inparticular, a number) a repeated ℓ times. Theorem 3.
Vectors (1 k ) , (0 , k ) , and (0 , k )) are g ± -shifts for the exact k - Nim games:
Nim k, = k , Nim k +1 , = k , and Nim k +1 , = k , respectively. Also, vector (2 k ) is a g ± -shift in Nim k, = k . However, this game is trivial: g ( x ) = 1 − g − ( x ) = x mod 2.The support , supp( z ), of a nonnegative n -vector z is defined as the setof its positive coordinates.Note also that in each of the three games considered in Theorem 3, forthe corresponding shift y and any position x we have:(i) the set-difference supp( x ) \ supp( y ) contains at most one element;(ii) the sum of the coordinates of y equals 2 k .Both observations will be essential in the proof. Proof.
We have to show that g ( x ) = g ( x + y ) and g − ( x ) = g − ( x + y ) forevery position x in each of the three games considered. We will prove allthree claims simultaneously by induction on the height h ( x ) of a position x . Recall that h ( x ) is defined as the maximum number of successive movesthat can be made from x .To a move x → x ′ we assign the move from x + y → x ′′ that reduces thesame coordinates. Then, g ( x ′ ) = g ( x ′′ ) holds by the induction hypothesis,implying that g ( x + y ) ≥ g ( x ). Assume for contradiction that g ( x + y ) > g ( x ).Then there is a move x + y → z ′ such that g ( z ′ ) = g ( x ). If there exists a move x → z ′′ reducing the same coordinates then the previous arguments workand by induction we obtain that g ( z ′ ) = g ( z ′′ ). Hence, g ( z ′ ) = g ( x ), becauseotherwise g ( x ) = g ( z ′′ ), while x → z ′′ is a move, which is a contradiction.However, the required move x → z ′′ may fail to exist. Obviously, in thiscase x = 0 must hold in all three cases. For Nim k +1 , = k and Nim k +1 , = k wealso have y = 0 and hence, move x + y → z ′ cannot reduce x + y = 0. Butthen, in all three cases there exists a move z ′ → x . Indeed, in Nim k +1 , = k we just repeat the previous move reducing the same piles. In contrast, in Nim k, = k and in Nim k +1 , = k we make the “complementary” move, reducingthe k piles that were not touched by the previous move. Note that in the6econd case we also do not touch the first pile, because it is empty. (Notealso that both of the above conditions (i,ii) are essential in all three cases.)Finally, the existence of the move z ′ → x implies that g ( x ) = g ( z ′ ),Thus, no move from x + y can reach the SG value g ( x ), implying thatequality g ( x ) = g ( x + y ) still holds.The same arguments work in the mis`ere case as well, since the mis`ereSG function g − is defined by the same recursion as g , differing from it onlyby the initialization.It remains to verify the base of induction for both g and g − and forall three games considered. Note that all terminal positions (from whichthere are no moves), not only (0 , . . . , Nim k, = k , Nim k +1 , = k , and Nim k +1 , = k are exactly the positions with at least k + 1 , k + 2 , and 2 zero coordinates,respectively. For each game we have to verify that g ( x + y ) = g ( x ) = 0and g − ( x + y ) = g − ( x ) = 1 for the corresponding shift y and any terminalposition x of the game. It is enough to check that • there is no move x + y → x ; • for any move x + y → z ′ there exists a move z ′ → x to a terminalposition x ; • there exists a move x + y → z ′′ such that each move from z ′′ results ina terminal position.We leave this tedious but simple case analysis to the careful reader.Note that Theorem 3 may simplify the analysis of the three games con-sidered. Without loss of generality, we can restrict ourselves to the positions x such that • x = 0 in Nim k, = k ; in other words, we reduce Nim k, = k to Nim k − , = k ;(for k = 2 see Theorem 4 and Corollary 1 in [4]); • x = x in Nim k +1 , = k ; • x ≤ x + 1 for Nim k +1 , = k .Let us mention a few more observations related to P-shifts.Vector (0 , , , ,
2) is not a P-shift in the mis`ere version of
Nim , =2 . Forexample, direct computations show that (3 , , , ,
8) is a P-position, while(3 , , , ,
10) is not. We have no explicit formula for the P-positions in thiscase. 7ector (0 , , , ,
4) is not a P-shift in
Nim , =2 . For example, x ′ =(2 , , , ,
6) is a P-position, while x ′′ = (2 , , , ,
10) is not, by Corol-lary 2. Indeed, T ′ ( x ′ ) < − − − <
0) and K ′ ( x ′ ) is true(2 + 2 + 3 + 4 + 6 = 17 ≡ T ( x ′′ ) > − − − > E ( x ′′ − x ′′ ) is false. Thus, in accordance withCorollary 2, x ′ is a P-position, while x ′′ is not.Finally, let us consider shift (0 , , , , ,
2) in
Nim , =3 . Our computationssuggest the conjecture that it is a P-shift in the subgames Nim , =3 [0] and Nim , =3 [1]. Yet, it is not a g -shift in these games, for example,3 = g (1 , , , , , = g (1 , , , , ,
6) = 5;1 = g (1 , , , , , = g (1 , , , , ,
6) = 3.Also, it is not a P-shift in
Nim , =3 [2]; for example,0 = g (0 , , , , , = g (0 , , , , ,
12) = 3.Finally, it is not a g − -shift, and not even a P-shift in the mis´ere version of Nim , =3 [ j ] for all j = 0 , ,
2. For example,0 = g − (1 , , , , , = g − (1 , , , , ,
5) = 1;0 = g − (1 , , , , , = g − (1 , , , , ,
6) = 3;0 = g − (0 , , , , , = g − (0 , , , , ,
6) = 3.
We have to prove that the set of P-positions of
Nim , =2 [0] coincides with theset P satisfying (1). It is enough to show that (I) there is no move x → x ′ such that x, x ′ ∈ P and (II) for any x
6∈ P there is a move x → x ′ such that x ′ ∈ P .(I). By (1), the Hamming distance between any two parity vectors ofdistinct positions of P is exactly 4, while for any move x → x ′ the Hammingdistance between p ( x ) and p ( x ′ ) is exactly 2, in accordance with the rulesof the game.(II). Fix a position x = ( x , . . . , x )
6∈ P in Nim , =2 [0]. Since P i =1 x i is even, the number j of odd coordinates of x is even too and we have toconsider the following three cases. j = 6, that is, all six piles are odd, p ( x ) = ( o, o, o, o, o, o ). In this case wecan reduce x and x , getting a move x → x ′ such that p ( x ′ ) = ( e, e, o, o, o, o ). j = 2, that is, there are exactly two odd piles. Reducing them we get amove x → x ′ such that p ( x ′ ) = ( e, e, e, e, e, e ).8 = 4, that is, there are four odd piles and two even. Let us matchcoordinates 1 and 2, 3 and 4, 5 and 6. Make the (unique) move x → x ′ reducing in x the smaller even pile and the odd one that is matched withthe larger even pile. If the two even piles are of the same size, x i = x i +1 ,then we agree that pile i is smaller than pile i + 1.It is easy to verify that in all the above cases the chosen move x → x ′ is possible, because it reduces (by one token) two non-empty piles; further-more, in all cases x ′ ∈ P , by (1). It is convenient to change coordinates for positions. We adopt ‘differentialcoordinates’: q = x , q = x − x , q = x − x ,q = x − x , q = x − x , q = x − x . Recall that x is assumed to be nondecreasing. Thus q i ≥ i .We define a move, reducing two piles by one token each, to be legal ifthe resulting piles are still in nondecreasing order of size. For a move i, j ,where i < j this condition is that q i >
0, and if i < j − q j > r ( q ) = q − q ; s ( q ) = − q − q + q ; u ( q ) = − q − q − q +2 q + q +1;and T ( q ) = min( s ( q ) , u ( q )). The three polyhedral regions are as before: A = { q : T ( q ) > } ,B = { q : T ( q ) = 0 } ,C = { q : T ( q ) < } . (4)The set described in the theorem is expressed in the differential coordinatesas P = { q : (cid:0) E ( q ) ∧ ( q ∈ A ) (cid:1) ∨ (cid:0) K ( q ) ∧ F ( q ) ∧ ( q ∈ B ) (cid:1) ∨ (cid:0) K ( q ) ∧ ( q ∈ C ) (cid:1) } , (5)where E ( q ) := ( q ≡ q ≡ q − q ≡ ,F ( q ) := ( q ≡ ,K ( q ) := ( N ( q ) ≡ − q + q − q + 2 q + q ≡ . We have to prove that the set of P-positions of
Nim , =2 [1] coincides withthe set P . The parity condition x + x + x + x + x + x ≡ q + q + q ≡ s ( q ) is odd and u ( q ) is even.We will use several simple observations on the conditions (5) before andafter a move. Proposition 2.
Let q → q ′ be a move in Nim , =2 [1] . Then K ( q ) ⊕ K ( q ′ ) = 1 .Proof. The total number of tokens N decreases by 2 after each move. So,the (odd) residue of N modulo 4 alternates between 1 and 3. Proposition 3.
Let q → q ′ be a move in Nim , =2 [1] . Then E ( q ) is trueimplies that E ( q ′ ) is false.Proof. We repeat the argument from the proof of Theorem 1, case (I). If thetotal number of tokens is odd and E ( q ) is true, then the parities of vector x have the form ( a, a, b, b, c, ¯ c ) where c = a ⊕ b . This implies that the Hammingdistance between any two parity vectors of distinct positions of P is exactly4, while for any move x → x ′ the Hamming distance between p ( x ) and p ( x ′ )is exactly 2.In the case analysis below, Table 1 is helpful. It shows, for each move,the changes of q -coordinates, s ( q ), and u ( q ).As in the proof of Theorem 1, it is enough to show that (I) there is nomove q → q ′ such that q, q ′ ∈ P and (II) for any q
6∈ P there is a move q → q ′ such that q ′ ∈ P .We prove (I) by contradiction. Suppose that q, q ′ ∈ P for a move q → q ′ .Propositions 2 and 3 imply that either (i) K ( q )& ¬ E ( q )& ¬ K ( q ′ )& E ( q ′ ) or(ii) ¬ K ( q )& E ( q )& K ( q ′ )& ¬ E ( q ′ ). Case (i): K ( q )& ¬ E ( q )& ¬ K ( q ′ )& E ( q ′ ).In this case, T ( q ′ ) > E ( q ′ ), and either ( T ( q ) = 0)& F ( q ) or T ( q ) < T ( q ) = 0)& F ( q ) then from K ( q ) and T ( q ) = u ( q ) = 0, we have − q + q − q + 2 q + q ≡ , and − q − q − q + 2 q + q + 1 = 0 , which implies that q is odd. Since F ( q ) (i.e., q is even) and E ( q ′ ), anymove taking q to q ′ must have ∆ q even and ∆ q odd. From Table 1 wesee that there are just four moves with this property but all of these have∆ u = 0, which contradicts the required increase in T .10able 1: Results of moves q → q ′ in ‘differential coordinates’, ∆ q i = q ′ i − q i ,∆ r = r ( q ′ ) − r ( q ), ∆ s = s ( q ′ ) − s ( q ), ∆ u = u ( q ′ ) − u ( q ).Moves ∆ q ∆ q ∆ q ∆ q ∆ q ∆ q ∆ r ∆ s ∆ u { , } − − { , } − − − − { , } − − − { , } − − { , } − − − − { , } − { , } − − − { , } − − { , } − − { , } − − { , } − − − { , } − − − − { , } − { , } − − − { , } − − T ( q ) <
0, so u ( q ) ≤ − s ( q ) ≤ − u ( q ′ ) ≥ s ( q ′ ) ≥
1. Since ∆ u ≤ s ≤ u ( q ′ ) = 2 or s ( q ′ ) = 1. From ¬ K ( q ′ )& E ( q ′ ), we have N ( q ′ ) ≡ − q ′ + q ′ − q ′ + 2 q ′ + q ′ ≡ q ′ ≡ q ′ ≡ q ′ − q ′ ≡ . Note that3 ≡ N ( q ′ ) ≡ u ( q ′ ) + 2 q ′ − ≡ N ( q ′ ) ≡ s ( q ′ ) + 2 q ′ − r ( q ′ ) − , so u ( q ′ ) = 2 implies q ′ odd, and s ( q ′ ) = 1 implies q ′ − r ( q ′ ) odd. Either ofthese contradict E ( q ′ ) which has q ′ and r ( q ′ ) both even. Case (ii): ¬ K ( q )& E ( q )& K ( q ′ )& ¬ E ( q ′ ).In this case, T ( q ) > E ( q ), and either ( T ( q ′ ) = 0)& F ( q ′ ) or T ( q ′ ) < q ′ for q , replacing“‘increase” by “decrease”, and similar.Now we prove (II). Thus, q / ∈ P and we are going to indicate a move q → q ′ such that q ′ ∈ P . Case q ∈ C . This implies ¬ K ( q ). By Proposition 2, q ′ ∈ P for anymove q → q ′ preserving region C .Table 1 shows many moves that preserve region C , including { , } , { , } ,and { , } . If q > q > { , } or { , } is legal and we are done.Now we assume q = q = 0.If q > { , } is legal provided that q >
0. If q = 0 then u ( q ) = − q + q + 1 > s ( q ) = − q + q = T ( q ) <
0. Move { , } is legal since q > q > s = 0 from Table 1. Therefore s ( q ′ ) = s ( q ) < q ′ ∈ P .Otherwise, if q = 0 then s ( q ) = − q < u ( q ) = − q − q + 1 < q > { , } is legal and gives ∆ s = 0, thus preserving region C .However, if q = 0 then u ( q ) = − q + 1 <
0. Since u is always even, thisimplies q ≥
3. Move { , } is legal and gives ∆ s = 2, so s ( q ′ ) = s ( q ) + 2 = − q + 2 < C is preserved. Case q ∈ B . In this case T ( q ) = 0 and, since this is even, s ( q ) > u ( q ) = T ( q ) = 0.Therefore r ( q ) >
0, i.e., q > q ≥
0, and q ≥ s ( q ) > Subcase q ∈ B and ¬ K ( q ) . K ( q ′ ). Since 2 q ≡ N ( q ) ≡ q is even.We will show that at least one of the moves { , } , { , } or { , } gives q ′ ∈ P .(i) If q is even, we use { , } , which is legal since q > q > q = 0 and ∆ T ≤
0, therefore K ( q ′ )& F ( q ′ )&( q ′ ∈ B ∪ C ) and so q ′ ∈ P .(ii) If q is odd, then q > { , } and { , } are legal. If r ( q )is even, then we see from Table 1 that { , } gives ∆ q = 0, ∆ q = − r = 0, ∆ T = 2, so E ( q ′ )&( T ( q ′ ) = 2) and therefore q ′ ∈ P . Otherwise, if r ( q ) is odd then { , } ensures in a similar way that E ( q ′ )&( T ( q ′ ) >
0) andtherefore q ′ ∈ P . Subcase q ∈ B and K ( q ) . Since 2 q ≡ N ( q ) ≡ q is odd, and since q / ∈ P , F is false,i.e., q is odd. Also s ( q ) = − q − q + q is always odd, so q is odd too. Wehave q > q and q odd, so moves { , } and { , } are legal.Since q ∈ B , s ( q ) > u ( q ) = 0 and so Table 1 shows that each of these movesgives T ( q ′ ) = min( s ( q ′ ) , u ( q ′ )) >
0, i.e., q ′ ∈ A . To prove q ′ ∈ P we haveonly to show E ( q ′ ).If r ( q ) is even then { , } gives ∆ q = +1, ∆ q = −
1, ∆ r = −
2, so E ( q ′ ).If r ( q ) is odd then { , } gives ∆ q = −
1, ∆ q = −
1, ∆ r = −
1, so E ( q ′ ). Case q ∈ A . In this case E ( q ) is false. For the positions in this case, we are going toindicate a move q → q ′ such that q ′ ∈ A and E ( q ′ ) is true, so q ′ ∈ P .Depending on the parities of q , q , r ( q ), suitable moves are listed in Table 2.It is easy to check using Table 1 that the listed moves make q , q and r ( q )even, ensuring E ( q ′ ), and furthermore they also satisfy ∆ T ≥
0, preserving A . We now need to check that these moves are legal.In the subcase A the move { , } is always legal, since q >
0. Similarly,for the move { , } in the subcase A and for the move { , } in the subcase A . Other subcases require a more detailed analysis. Subcase A . If q > { , } is legal, otherwise q = 0. This impliesthat q > r ( q ) = q − q is odd in this subcase. Therefore move { , } is legal and changes the parities to q ′ = q ≡ q ′ = q ≡ ( q ′ − q ′ ) = q − − q ≡ E ( q ′ ) is true, but we still need to provethat q ′ ∈ A . In general, this move does not preserve the region A : ∆ s = 0but ∆ u = −
2. Since r ( q ) = q − q ≤ − T ( q ) = s ( q ) ≥
1, we have u ( q ) = s ( q ) − r ( q ) + 1 ≥
4, and so T ( q ′ ) > q ′ ∈ A .13able 2: Winning moves in the case q ∈ A Subcase q mod 2 q mod 2 r ( q ) mod 2 moves to P A { , } A { , } A { , } A { , } A { , } A { , } A { , } Subcase A . Since s ( q ) ≥ q is odd, q > { , } is legal. Subcase A . Again, since s ( q ) ≥ q is odd, q > { , } is legal. Subcase A . If { , } is legal then we are done. Otherwise, q = 0, since q is odd in this case. This implies that q > r ( q ) = q − q is odd.Again, q > q is odd and s ( q ) ≥
0. Thus, the move { , } is legaland it changes the parities to q ′ = q + 1 ≡ q ′ = q ≡ r ( q ′ ) = r ( q ) − ≡ E ( q ′ ) is true. For { , } , ∆ s = − u = 0. From u ( q ) = s ( q ) − r ( q ) + 1 ≥ r ( q ) > s ( q ) ≥ s ( q ′ ) ≥
1. Therefore T ( q ′ ) > q ′ ∈ A . P-positions of
Nim , =2 are characterized by the explicit formulas of Theo-rems 1 and 2. Although they look complicated, they immediately providea polynomial time algorithm to solve the following problem: given a non-negative integer vector ( x , x , x , x , x , x ), whose coordinates x i are rep-resented in binary, check whether ( x , x , x , x , x , x ) is a P-position in Nim , =2 .Note that the set of P-positions of Nim , =2 is semilinear. Recall thata semilinear set is a set of vectors from N d that can be expressed in Pres-14urger arithmetic; see, e.g., [6]. Presburger arithmetic admits quantifierelimination. So, a semilinear set can be expressed as a finite union of so-lutions of systems of linear inequalities and equations modulo some integer(they are fixed for the set).This observation leads to a natural conjecture. Conjecture 1.
For any n , k P-positions of
Nim n, = k form a semilinear set. Conjecture 1 implies that there exists a polynomial time algorithm de-ciding P-positions of
Nim n, = k for all n , k .It is well-known that evaluating formulas in Presburger arithmetic isa very hard problem. The first doubly exponential time bounds for thisproblem were established by Fischer and Rabin [2]. Berman proved that theproblem requires doubly exponential space [1].But these hardness results are irrelevant for our needs. In solving Nim n, = k we deal with sets of dimension O (1) and may hardwire the description ofthe set of P-positions in an algorithm solving the game. Verifying a linearinequality takes polynomial time as well as verifying an equation modulo aninteger. Thus, any semilinear set of dimension O (1) can be recognized by apolynomial time algorithm.Note that for a wider class of games, so-called multidimensional subtrac-tion games with a fixed difference set, P-positions can be not semilinear.Moreover, it was recently proven that there is no polynomial time algorithmsolving a specific game of this sort [5].In the game from [5] it is allowed to add tokens to some piles by a move,provided that the total number of tokens is strictly decreasing. We considerthis feature crucial for hardness results.To put it more formally, we need to make formal definitions. A gamefrom the class FDG is specified by a finite set D ⊂ Z d which is called the difference set . We require that d X i =1 a i > a , . . . , a d ) ∈ D .Positions of the game are vectors x = ( x , . . . , x d ) with nonnegativecoordinates. A move from x to y is possible if x − y ∈ D .It is proven in [5] that for some constant d there exists a set D suchthat there is no algorithm solving the game with the difference set D andrunning in time O (2 n/ ), where n is the input size (the length of the binaryrepresentation of the position ( x , . . . , x d )).15lso, it was proved by Larsson and W¨astlund [7] that the equivalenceproblem for FDG is undecidable. The existence of difference vectors withnegative coordinates is essential for both results. Nim n, = k belongs to the class FDG: difference vectors are (0,1)-vectorswith exactly k coordinates equal to 1. The solution of Nim , =2 encouragesus to suggest a stronger conjecture. Conjecture 2.
For any FDG game such that a i ≥ for each ( a , . . . , a d ) ∈D , the set of P-positions is semilinear. Conjecture 2 also implies that the equivalence problem for FDG withnonnegative difference vectors is decidable, since Presburger arithmetic isdecidable.Why do we believe in Conjecture 2 in spite of results from [7] and [5]?The first idea is to apply inductive arguments in the case of nonnegativedifference vectors. Note that Conjecture 2 holds for a 1-dimensional FDG.If a coordinate becomes zero it remains zero during the rest of the game (ifall difference vectors are nonnegative). So to prove Conjecture 2 one needsto provide a reduction in dimension of a game.This idea does not work in a straightforward manner. It can be shownthat arbitrary semilinear boundary conditions do not imply semilinearity ofthe solution for the recurrence determining the set of P-positions [8]. Forthe boundary conditions determined by FDG games the question is openand we still have a hope to develop a dimension reducing technique.In any case, characterization of FDG games with semilinear P-positionswould be an important problem for future research.
Acknowledgements
The paper was prepared within the framework of the HSE University BasicResearch Program; the fifth author were funded partially by the RFBR grant20-01-00645.