[MUSIC] In this video, we're going to talk about logic which is the mathematics that we need for this section of the course. Don't worry, we'll take it nice and easy so it won't get too difficult. Let's get started. Let's talk about Boolean Logic. This a branch of mathematics where everything can take on one of two values, either true or false. There's no in-between, there's no middle ground. Everything has to be either true or false, can't be both, can't be anything else. Now, it's going to get tedious for me if I have to write out the words true and false every time I want to refer to these. So I'm going to abbreviate them with the letters P and R for obvious reasons, okay? So whenever you see the letter P it means true. [LAUGH] All right, hopefully, you're sitting behind your computer scratching your head, going, what on earth is he doing? Why did he pick those letters? They make no sense whatsoever, all right. So, let's try again. [LAUGH] Let's abbreviate them more reasonably as T and F. Okay, now that's interesting in and of itself that everything can either be true or false. But it's much more interesting if we can combine these things in different ways. So let's talk about three of the operators that we have in Boolean Logic, not, or an and. Now you can probably guess what these operators do by their english language definitions. But I want to be more mathematically precise here. I want to say, okay, let's say we have a variable A, I want to figure out what is the value of not A. Now, to do this let's think about all the possible values that A can have. Well, it can either have true or false, so A can be true or A can be false. And the question is what is not A in both of these scenarios? Well, not means negate so if A is true, not A is false. If A is false, then not A is true. This is what's called the truth table and it shows me for all possible values of A, what are the values of not A? And now, I understand completely what not means. Hopefully, this makes sense to you. Now, the or operator's a little more complicated, there has to be two variables involved here. So let's think about this. We've got A and B, and I want to figure out what is the value of A or B, right? Now, there are more cases here. So our truth table is going to be bigger, we can have A is true and B is true. We can have A is true and and B is false, we can have A is false B is true, or A is false, B is false. And those are the four possible values, there are no others. All right and so the question now becomes, what is the value of A or B in these four scenarios? Now, or, if we think about it, means one or the other is true. And actually, in Boolean Logic it means one or both is true, okay? So if A is true and B is true that means A or B is true. A is true, B is false, one of them is true so A or B is true. A is false, B is true, one of them is true, so A or B is true. And the only interesting case here is if they are both false, well then A or B is false. Right now I've completely specified what the or operator means here. Let's just extend this truth table a little bit and do and in the same table A and B, okay. Now and here means hey they're both true, right? So if A is true and B is true, A and B is true. A is true B is false, one of them is false so they're not both true. So this is false, A is false, B is true. One of them is false, so there, this is false, A is false, B is false, neither of them are true, so and is definitely not true here either. So A and B is false and there you have it. That is the mathematical definition of and. So hopefully now you understand the simple operators in Boolean Logic and we can use these to do more complicated things. You don't just have to have one variable or two variables, I can have more. So, as I said, we don't just have to have simple expressions like, A and B. Just like we can compose more complicated arithmetic expressions we can do the same with our logical expressions. We could have something like, A and B or C or D. And just like with our more complicated arithmetic expressions, we probably want to use parentheses to show exactly what we mean. Now, how do you figure out what this means, though? What's the value of this? Well, I can do the exact same thing I did before. I can make a truth table that has all the possible values of A, B, C, and D, and then I can evaluate this. So it would probably be a multistep process where you'd figure out what is the value of B or C? And then what is the value of that with or D, and then and it to A and figure out the value of whole expression. And then you would know for all possible inputs what the output is going to be. In practice, you start to think about how these things work and what your intentions are, and you don't necessarily need to build a truth table every time, but you do have that capability right? You can make the truth table for any arbitrarily complex expression. It might be big but you can do it, and then you can figure out, hey, here's all the values and all the possible circumstances. We are going to use more complicated logical expressions like this in our programs, and we'll see in future videos how to do this in Python. Now you've been introduced to Boolean Logic, a world in which everything is either true or false. And we have logical operators that allow us to compose more complicated expressions. Now we just need to figure out how we're going to use these in our programs.