 Welcome back. In this session we discuss another combinatorial game called NIM game. So, what is this NIM game? We discuss this NIM game. So, what is the NIM game? So, there is typically there is a pile of coins maybe let us say there are two piles of coins. The players the blue player or red player in their turn they can pick any number of players can pick any number of coins from one pile. So, that means the players first they have to decide on which pile where they should take the coins from and then they decide on how many to choose any number they can do it. So, whoever picks the last coin is the winner this is the normal player which I have mentioned. So, what if if there is a single pile? That means the player one can pick all the coins and then can win. So, single pile is not interesting. So, that is why this is where the take away game plays a role. In a take away game the there is a single pile and you are you have to pick only one or two or three coins or sticks in the previous. So, this is a trivial setup in this case. So, now we need to understand how this how people play in NIM game. Let us look at it. So, as I start using we start using this N and P positions now. So, recall what is N? N is next player to make wins and P means previous players to make move wins. So, we start using this and then to prove this to see who is going to be the winner we require what is called number arithmetic. We need number. So, let us let me tell you what it is. So, let us say we want to add 5 and 6. Let us take 2 numbers. So, I define we define an operation number arithmetic operation. Let me use this symbol for this. So, what exactly mean by 5 and 6? What is this? So, the way to do this one is that we convert we convert these numbers to binary. So, 5 is going to be 101 and 6 is going to be 110. So, I want this number arithmetic. So, what it is that suppose when you are adding 1 and 0 of course, let us do the binary addition 1 and 0, 1 and 0 and 1, 1 and then 1 and 1, 0. So, this is nothing but 3. So, answer here is 3. The number NIM sum of 5 and 6 is going to be 3 and there is some small thing that I should tell you here. What happened to the carry? So, we do not take this this carry is not forwarded. So, we always exclude this carry in a sense we are actually looking at the here when I am adding these 2 things we are using this exclusive R operation XR operation. So, what it means is that so 1 plus 1 is going to be 0 which is same as 0 plus 0 whereas 1 plus 0 is 1 which is also 0 plus 1. Again to check what is 1 plus 1 plus 1 this will be there are odd number of 1s. So, therefore it becomes 1 that is the easiest way if there are even number of 1s this becomes 0 here there are even number of 1s and whereas here odd number of 1s. So, this is the number arithmetic. This number arithmetic is a very, very useful thing in providing the solution to the NIM game. So, we use this NIM game. So, let us look at this thing NIM sum helps in providing strategy in NIM game. So, let us look at it how this is done. So, one thing I would like to point out is that for any number X for any number X X NIM sum X is always 0. This is a very important point we should remember. So, let me look at this thing theorem. The theorem is that winning strategy in normal play NIM is to finish every move with NIM sum of 0. So, what exactly are we really doing here? When I say that the NIM sum is 0 suppose you have a 2 pairs of coins here let us say there are M coins and here N coins the NIM sum of M and N. If you recall what is the terminal position here is 0 and 0. So, the NIM sum of this is so in a terminal position before that it is possible that there may be some K here and K 0 here. So, he removes all the K and then he made 0 0 the NIM sum of that is 0. So, the idea here is that, idea is that pick coins in such a way that NIM sum becomes 0. Is it really possible or not? That is what we will check it how to do it. Let us say this proof depends on 2 lemmas. So, let me start with the 2 lemmas. So, first lemma is if the NIM sum is 0 after a player is turned then the next player to make a move must change it to non-zero. What this lemma says that for example, if the NIM sum is 0 after a player is turned the next player whenever whatever move he makes it he will change the NIM sum to a non-zero number. So, that essentially gives you the idea. So, what it says that initially the NIM sum is something. So, let us say I am a player 1 and you are player 2, I have changed then I have chosen some certain number of coins and removed them so that the NIM sum became 0. Now, when you make a move you will alter the NIM sum to a non-zero thing and in my turn again I will change it to 0 and then it goes on and like a typical property of combinatorial games is that they end in a finite time, finite turn, finitely many turns. So, because I am always keeping the NIM sum 0 eventually it should come to 0, 0 at when I make a move. So, therefore I become winner. So, this is the idea. So, the first we this proof consists of 2 steps. In the first step we need to prove that if the NIM sum is 0 after a player is turned the next player is next players move changes it to a non-zero. The second thing is that how can I make a NIM sum to 0? So, we will see these 2 things. So, first let us prove this one. So, remember even though in the example I have showed you only 2 heaps there could be multiple heaps. Let us say we are assuming that there are N heaps. So, and let us say the psi x1, x2, xn is basically the NIM sizes. The first heaps size second heaps this is the Nth heap. So, let us take S to be the NIM sum x1. Now, let us say after the player has made a move after a move let us say let the heap sizes y1, y2, yn and T is y1, yn. Now, remember if x1, x2, xn is the heap sizes and from there after the move it became y1, y2, yn. Remember the rules is that the player will pick some, remove some coins from only one of the this thing. That means all it must be true that yi is equals to xi for all i except for 1. So, therefore let us check this one. Now, this T is nothing but 0 NIM sum T which is obvious. This is same as S NIM sum S, NIM sum T which is same as S NIM sum x1, NIM sum x2, NIM sum xn, NIM sum y1, NIM sum y2, NIM sum yn. Look at the things. So, we already have said in this thing that all xi's and yi's are same except for 1. Therefore, here x1 and y1 may be same x2 and y2 may be same except for one of them. Now, by the definition of the NIM sum we know that if xn, yn, x1 and y1 are same their NIM sum will be 0. And remember before going further look at the definition of a NIM sum. The NIM sum is nothing but you are summing these two things. In a sense, you can see that this is a this holds the associative property holds true. So, what I mean to say is that let us say a is a number and a NIM sum b, NIM sum c is same as a NIM sum b, NIM sum c. This can be proved. So, here using that associative property what we can really say is that this is same as S. So, these look at these things all of them are 0 except one of them. So, therefore, this should be same as S, NIM sum may be xl, NIM sum yl. So, what happens? xl and yl are different. So, if S is equals to 0, if S is equals to 0 then t has to be different from 0. Why is this? So, this is a very interesting exercise for us to see it is that if S is 0 then t cannot be 0 because any two different numbers if we take it the NIM sum cannot be the same thing here. So, I will leave this as an exercise and you can see that this if S is equals to 0 then t cannot be 0. This immediately proves this lemma. What is this? If the let us say after a player's time the NIM sum is 0, the next player is making the NIM sum to be non-zero. So, that is exactly this thing. So, S is the NIM sum after a player makes a move and then t is the NIM sum after the next player's move. And what we are saying that if S is 0, t has to be non-zero that comes from this fact because t is equals to if S is 0 then t has to be xl NIM sum yl and xl NIM sum yl when is xl the exercise is that if x NIM sum y is equals to 0 then x and y is same. So, this is an exercise and one should try solving this one. It is not very hard to do it. In fact, of course, it is very simple y should be leave it as an exercise. So, if x let us say x NIM sum y is equals to 0 therefore x NIM sum of x NIM sum of y is same as x NIM sum of 0 which is x. Now, this is nothing but 0 NIM sum y which is y therefore y is equals to x that is it. So, this proves this fact. So, now this proves this lemma what this lemma says to recall if the NIM sum is 0 after a player's turn the next player is making he is changing the NIM sum to a nonzero thing. Now, the next question that comes is that when a player is making a turn suppose if the NIM sum is not 0 can he make a move so that the NIM sum becomes 0. So, let us do that lemma. It is always possible to make the NIM sum 0 on your turn if it was not already 0 at the beginning of your turn. So, when I let us say when I need to make a move if the NIM sum is not 0 already then I can turn it to 0 by making move wisely. So, that is the content of this lemma. So, let us prove. So, what is s? So, let us say s is basically the NIM size the NIM x 1, x 2 and so s is the NIM sum of x 1, x 2, x n which is the current NIMs if I need to make a move assume that we are assuming that s is not equals to 0. If s is not equals to 0 let us say there will be the NIM sum will have one of the bits remember all these numbers are in the binary numbers look at the D be the most significant basically position of the most significant bit in s what do you mean by that? So, s is not equals to 0 therefore let us say as an example suppose s is equals to 3 that means it is 1, 1 the most significant bit is this a position is 2 second position. Suppose if s is equals to 6 it is 1, 0, 1 and this is going to be the most significant sorry 1, 1, 0. So, this is the most. So, we take this D is the basically the position of this number. So, what you do is that we choose a heap x k one of the heap x k such that its most significant bit is also in position D. So, what I am saying here D is basically the most significant position. So, if s is non equals to 0 D is the position most significant position. So, if let us say if the D position of s in the binary number is 1 then one of these x 1, x 2, x n must also have 1 in that position. This is because if none of them are 1 the NIM sum of that particular position 0 plus 0 plus 0 that will be 1. So, there must be odd number of 1s if odd number of 1s are not there then it cannot be 1. So, therefore by this simple logic there will be one heap where the most significant bit is also in the position D. So, look at that position D and look at that particular heap x k. So, we look at that heap kth heap x k and then we choose that heap choose the heap x k and we want to remove we remove from this heap. So, that the heap contains y k coins where y k is equals to x k NIM sum s. So, we are removing basically x k minus y k we remove. So, remember x k also has a significant bit in the deep position s also has this thing and it may have y k may be 0 but x k minus y we are removing either all x k certainly non-0. So, and this is not same as x k that is y k is x k minus y k cannot be same as 0 x k minus y k is certainly not equals to 0. So, why? So, you can apply the NIM sum rules and you can get this fact. So, you can check this one and we are removing x k minus y k coins and the number of coins remaining there are this match. So, now the new heaps the new heap size now is or of course x 1 x 2 x k minus 1 and then y k and then x k plus 1 and x n these are the new sizes after this move. So, what is the NIM sum of this? The NIM sum basically x 1 plus x k minus 1 plus and here y k then x k plus 1 x n. Remember y k is nothing but let us go back is x k plus s this is nothing but x k plus s. Now, look at the x 1 plus x k minus 1 x k and then x k plus 1 on all this thing that is nothing but s and this one is s. So, this is 0 the NIM sum after removing this x k minus y k coin the NIM sum becomes 0. So, this is the proof for this lemma. So, now what we have proved is that if the currently if the NIM sum is not 0 I have a move which makes the NIM sum 0 and in the previous lemma which we have proved is that if the NIM sum is 0 after a player's turn the other player has to change the NIM sum to a non-zero lemma. So, what is the strategy? How do we play this game? At any position let us say player 1 as a player 1 I will always choose if the NIM sum is 0 immediately I cannot win the game because I will turn it to a so how we use let us look at the strategy. If let us say currently if the NIM sum is 0 if the NIM sum is 0 that means I am actually whatever I do it I will actually turn the NIM sum to be a non-zero. That means this position is basically a P position and if NIM sum is not 0 this is a N position that means the player to make a move he can convert the NIM sum into 0. So, therefore we have identified the positions in this NIM game just by using this NIM sum. If the NIM sum is 0 it is a P position NIM sum is not 0 N position. Now, when we are playing this game we look at what is the NIM sum of the heap sizes. If it is non-zero if I am the first player I know that I am going to lose if it is 0 then I will be turning it and then I will be losing it if the NIM sum is not 0 then I will turn it to 0 and I can win this one. So, this NIM sum clearly gives you a winning strategy for the players. So, who will win depends on whether the current NIM size is NIM sum is 0 or not. So, this particular game is analyzed by Bowton what we have discussed is his argument to show that the NIM sum game is solvable. So, before concluding I would like to concluding this session I would like to say that the games that we have been seeing these are known as impartial games. These are known as impartial games. So, what an impartial game is that the positions are not specific to a player the positions are same. If whether the player one is in that position or player two is in that position it does not matter the moves available to them are same. Whereas, there are also games where the position depends on the player a classical example is a chess game. So, we will discuss this those games later they are known as a partisan game. In the next sessions we will go little deeper into this impartial games and then we will study what is known as a Sprague Grundy theorem. So, we will discuss this theorem in the next session and we continue the this thing and for the for today we will stop in this session.