 some applications of the principle of inclusion and exclusion now first let us look at this example which is based on the sieve of ira stoethanis now the greek mathematician ira stoethanis developed a technique of listing all the prime numbers between one and any positive integer n so our goal is to list all the prime numbers between the number 1 and a positive integer n the procedure is as follows one remove all the multiples of other than the first remaining integer exceeding to is the prime number third step remove all the multiples of 3 except 3 itself for remaining integer exceeding 3 which will be the prime number then remove all the multiples of 5 except 5 we have to continue in this way what happens is that if we take a positive integer n let us say n equal to 1000 so we are looking at positive integers from 1 to 1000 and if we keep on repeating this process then ultimately we will we will be left with the prime numbers between 1 to 1000 now our problem is derived from this method which is called the sieve of ira stoethanis so let us look at the problem count the number of integers between 1 and 1000 are not divisible by 235 and 7 in order to solve this problem we consider certain sets first let you be the set of integers x such that 1 less than or equal to x less than or equal to 1000 now we define some subsets of you a1 equal to the set of elements of you divisible by 2 a2 the set of elements of you divisible by 3 a3 the set of elements of you divisible by 5 a4 the set of elements of you divisible by 7 now we are looking at the set of integers between 1 and 1000 which are not divisible by 235 and 7 we have in the beginning constructed four sets which are in fact subsets of you the integers between 1 and 1000 namely a1 a2 a3 a4 where a1 consist of all the elements which are divisible by 2 a2 the set of elements divisible by 3 a3 elements divisible by 5 and a4 elements divisible by 7 now if we consider the set a1 complement this is the set of all the elements in you which are not divisible by 2 a2 complement is a set of all elements of you not divisible by 3 a3 complement is a set of all elements of you not divisible by 5 and a4 complement set of all elements of you not divisible by 7 now that means that our set under consideration is intersection of all these complements and this gives me the set of all elements in you which are not divisible by 2357 now we can process this a little further by considering this is in fact a1 union a2 union a3 union a4 and the complement this is by using de morgan's law so the cardinality of a1 complement intersection a2 complement intersection a3 complement intersection a4 complement is the cardinality of the complement of a1 union a2 union a3 union a4 which in turn is equal to the cardinality of you which is the universal set minus the cardinality of a1 union a2 union a3 union a4 now we will quickly calculate the cardinality is of a1 a2 a3 a4 and the cardinality is of ai ai's intersections of ai's taken 2 at a time 3 at a time and all at a time and then use principle of inclusion and exclusion to get the cardinality of the union of a1 a2 a3 a4 we start our process by checking the cardinality of a1 which is 1000 divided by 2 500 a2 which is floor of 1000 divided by 3 which is equal to 333 by the way floor of a real number is the largest integer less than that real number then a3 1000 divided by 5 which is 200 and a4 which is the floor of 1000 divided by 7 which gives us 142 then we take intersections of ai's for distinct i's taken 2 at a time so we get a1 intersection a2 is equal to floor of 1000 divided by 6 if a positive integer is divisible by both 2 and 3 then of course it is divisible by 6 and the converse therefore we will have 166 a1 intersection a3 this gives me 1000 divided by 10 which is 100 and a1 intersection a4 which is floor of 1000 divided by 14 which is equal to 71 then a2 intersection a3 a2 intersection a4 and lastly a3 intersection a4 which is floor of 1000 divided by 35 which is equal to 28 then we have to take the intersections taking 3 at a time so I will have a1 intersection a2 intersection a3 so these are PCI is little elements which are divisible by 2 3 and 5 therefore divisible by 30 so therefore it will be 1000 divisible by 30 divided by 30 floor of that which is 33 then I have got a1 a3 a4 which is 1000 divided by 70 which is equal to 14 and we have a1 a2 a4 which is 1000 divided by 42 which is equal to 23 and finally a1 this will be a2 a3 and a4 which is floor of 1000 divided by 105 so it is 9 and the last one taking 4 at a time is and we can check that this is just the number 4 now if we remember all these things then we can see that the cardinality of a1 complement intersection a2 complement intersection a3 complement intersection a4 complement is cardinality of EU this one which is of course 1000 minus cardinality of a1 500 plus cardinality of a2 333 plus 200 plus 142 these are the cardinality of a1 a2 a3 a4 from this one the cardinality of a1 intersection a2 which is 166 minus 100 minus 71 minus 66 minus 47 minus 28 and then we start adding we add 33 add 14 add 9 so and add 23 and then again subtract the last expression that is 4 if I do this then the number that I get is 222 and this is the number of integers between 1 and 1000 which are not divisible by 235 and 7 thus in this example we see how we are using the principle of inclusion and exclusion to count some number of some things we move on to more serious examples and this example involves Euler's phi function now the first question is what is Euler's phi function for that first of all we have to know what do we mean when we say that two positive integers are relatively prime to one another let me write the definition first positive integers are said to be relatively prime the number one is the only common divisor that they have now suppose n is a positive integer phi n is defined as the number of positive integers greater than or equal to 1 and less than or equal to n relatively prime to n so in simple words we take a positive integer n and we count the number of positive integers between 1 and n which are relatively prime to n and this number is called the phi n now what we are interested here is to get a get an expression of phi n which does not seem to be very easy if we start checking some small examples then we see that phi 1 is of course 1 phi 2 is also 1 phi 3 is 2 phi 4 is also 2 because the positive integers less than 4 is 1 2 3 and 4 here 1 is of course relatively prime to 4 2 is not relatively prime to 4 and 3 is relatively prime to 4 and of course 4 is not relatively prime to 4 so we have got we say 5 4 is 2 then 5 5 is 4 and so on so as such there is no direct pattern that that is obvious so we have to find out an expression of phi if at all it exists incidentally this function is called the Euler's phi function now suppose p1 p2 up to pk the distinct prime divisors of n we consider the universal set 1 2 up to n and denoted by u we also consider a set like this a sub i which is the subset of u consisting of those integers divisible by p i so we are looking for integers which are in u and not divisible by any of the p is therefore phi n is equal to cardinality of a1 complement intersection a2 complement intersection and continued in this way up to ak complement we can manipulate and get this equal to u minus cardinality of u minus a1 union a2 union and so on up to ak now again we see that the expression that we are getting is almost similar to the expression that we got in the last example only thing is that we have to know how to count the cardinalities of ai's and intersections of different ai's we base this on an observation if d divides n then there are n by d multiples of g in u this can be verified and I leave it as an exercise but if we take it to be true which of course we can verify then we will get ai equal to n by p i a i intersection aj where i is not equal to j equal to n divided by p i p j and proceeding in this way finally we will get a1 intersection and so on up to intersection a k is equal to n divided by p1 dot dot dot pk and therefore considering all this we will get ? n equal to n which is the cardinality of u and then minus ? i equal to 1 to k n by p i this is essentially ? i equal to 1 to k cardinality of ai and I put a minus over here to obtain i equal to 1 to k n I have to put i equal to 1 to k and j also equal to 1 to k with a condition that i is always less than j so this is p i p j and we will proceed in this way to ultimately the last expression this is the cardinality of ai I am sorry a1 intersection and up to a k and this intermediate second entry is essentially i less than j intersection ai intersection aj cardinality thus we have basically used the pigeonhole I am sorry we have basically used the principle of inclusion exclusion in the last part of the right hand side to obtain an expression now we can process this further and write n minus ? i equal to 1 to k n p i plus ? i less than j n p i into p j minus and so on at the end its minus 1 raise to the power k n p 1 up to p k and a careful analysis shows that this is equal to n into 1 minus 1 by p 1 1 minus 1 by p 2 and so on up to n into 1 minus 1 by p k and thus finally we have got an expression for ? n which is ? n equal to n into 1 minus 1 by p 1 1 minus 1 by p 2 and so on up to 1 minus 1 by p k where n is equal to p 1 raise to the power a1 p 2 raise to the power a2 and p k raise to the power a k where a i's are greater than or equal to 1 and p i's are distinct prime numbers Euler's phi function plays an important role in number theory and many other applications of number theory this example gives us a gives us a an instance where the principle of inclusion exclusion gets used in finding out a very fundamental function a of number theory which is the Euler's phi function next we will talk about counting permutations by using the principle of inclusion and exclusion now these permutations that we are going to study are called derangements let me start by defining derangements among the permutations of the numbers from 1 to n there are some permutations in which none of the n integers appears in its natural place now these permutations are called derangements now what we would like to do is to count the number of derangements of n numbers from 1 to n suppose dn is equal to the total number of derangements on the set 1 to up to n now just like the previous examples we are going to define some sets so in general we define a i equal to the set of all the permutations on 1 to up to n which keeps the ith element namely i in its natural place and of course I will move i from 1 to up to n let u denote the set of all permutations on 1 to up to n just to recall that this means that u is a set of all 1 to 1 on to functions from 1 to up to n to 1 to up to n now from the discussions that we have done before it is now clear that dn is equal to a1 complement intersection a2 complement intersection and so on up to n complement and which again in exactly similar way as before can be written as cardinality of u- cardinality of a1 union a2 union and so on up to n we know that the cardinality of u is factorial n and therefore we have to just find the cardinality of a1 union and so on up to cardinality of n for that we will start checking the cardinality of a1 which is factorial n-1 the reason is that when I am counting the number of permutations or the number of arrangements that I can make out of elements from 1 to n where first element is in the first position then I can move around the other n-1 elements in any way I like so I can do that in factorial n-1 ways therefore cardinality of a1 is factorial n and the question is that how many ai's are there there are n choose one many that is n many ai's so cardinality of a2 is going to be also n-1 and so on up to cardinality of an is equal to n choose n-1 therefore if I am considering the cardinality of the union a1 union an the first term which is sigma i equal to 1 to n cardinality of ai this will be n choose 1 n-1 that is n into cardinality of n-1 because all the ai's have the same cardinality the second term is going to be i less than j ai intersection aj the question is that how many times I can choose these two distinct ai's from n distinct ai so that number of times is n choose 2 then the question is that what is the cardinality of ai intersection aj and that happens to be n-2 factorial because after all I am fixing the ith element to the ith place and jth element to the jth place so I have got n-2 many elements left which we can move around anywhere like therefore we will get n choose 2 into factorial n-2 and then further on I will have n choose 3 factorial n-3 and so on and at the very end I am going to get-1 raise to the power n-1 into n choose n of 1 now if we go back to the expression that we started writing of dn we wrote that dn is equal to cardinality of u- the cardinality of a1 union and so on up to an which means that dn is factorial n- n choose 1 factorial n-1- n choose 2 factorial n-2- n choose 3 factorial n-3 plus which is equal to factorial n- n choose 1 and if we process it further we will get the final result as factorial n into within bracket 1-1 choose 1 plus 1 choose factorial 2-1 choose sorry 1-1 by factorial 1 plus 1 by factorial 2 1 by factorial 3 and so on and at the end we will have-1 to the power n factorial n this is the final result for the number of derangements that we have on n positive integers from 1 to n in this lectures we have studied three examples in which principle of inclusion and exclusion has been used to solve certain counting problems and some of these problems are very fundamental to combinatorics and number theory we stop the lecture now thank you.