Let us use Python to study conditional probabilities of events that are given as subsets of sample space. To do so, we first have to introduce the sample space itself. That is the set of all outcomes. Let us consider an example of when we toss a coin several times. The corresponding set of all outcomes is a set of all possible sequences of heads and tails. To create such a set, we can use etertools model that allows us to find a Cartesian product of some sets. To do so, we have to import itertools, and we will use our function product which is Cartesian product, and let me show you how it works. We can find a list of product. For example, we have two sets or two lists, for example 1, 2, and another one is a,b,c. We see that this function product makes an iterator that is converted to list by this list function, and this list consists of several layers of elements in each pair, which is a two element tuple. First element is from our first list, and second element, a, is from second list, and our all possible combinations are enumerated. So let us assume that I want to toss a coin several times. For example, three times. This is number of coin tossings. Then I can create my sample space. Let me denote it by Omega, and it is a set of a product of [inaudible] of this list of two elements. So we can use option repeat which creates a Cartesian product of several copies of the same list. So here Omega is just this set, and we can check that all outcomes are included in this set. So as you see, the number of elements in this Omega is eight which is indeed the correct number. Now let us introduce several events. For example, we can introduce event A that corresponds to condition that at first tossings, we have tail. So we can define these events, this set using set comprehension. We just enumerate all items from our set Omega. I denote one outcome by om that satisfy the condition that om of 0, so it is the result of the first tossing is tail. So first tossings is tail. We can introduce another event for example, that we have exactly two tails. This can be done in the following way; om.count T equals to 2. So we can check outcomes that satisfy A's. So we see that we have four outcomes here and we have three outcomes that satisfies B. Now we can find their probabilities, and we can find their conditional probability. To do so, let me introduce a couple of function. First function calculates probability of some event X, and it works if we assume that all outcomes have the same probability, and in this case, probability of X is just number of elements in X divided by number of elements in Omega, and we can also introduce conditional probability of two events. So this is conditional probability of event X provided that Y occurred, and it can be calculated in a similar way. We just have to find number of elements in their intersection which is denoted by this ampersand, and divide it by number of elements in Y. So we have this thing, and now we can find some probabilities. For example, probability of event A is one-half which we expected, and the probability of event B is a little bit less, and we can also find conditional probability. For example, conditional probability of A provided that B happened. So if we know that the overall number of tails equals to 2, does it make it more probable for A, which its first tossing is tail, to be more probable or less probable? Let us check. We see that the corresponding conditional probability is two-thirds, and it is higher than probability of A. It means that these events, A and B are not independent. We actually can check it also by considering probability of their intersection, and comparing this probability with product of probabilities of A and B. Again you see that these two numbers do not coincide, and it also means that these two events, A and B are not independent of each other. So we can construct a function that checks is it true that two events are independent? We can do it in different ways, for example, in this way. Now let me introduce some event that is independent of A. For example, we can consider event C for which we test is it true that at the second tossings we get head, and this can be done in the following way. Now we check is it true that A and C are independent? We see that the result is true. This approach allows us to find probabilities of events when they are given explicitly as a subsets of a sample space or as a condition that allows us to find the corresponding subsets. But in practice, in most of cases, we will do a little bit different thing. We will simulate some random experiments with computer, and we will ask the computer for example to give us some random value, and use them to study properties of random variables. We'll discuss random variables at the next week.