So let's go back to this thing that we just simplified here, right?
We're going to talk about something called a truth table now, which is going to let us map out all
the possible combinations of true and false we can have and whether it would lead to this result.
So our goal is to find out whether this evaluates to true based on all the things that could be either
true or false, whether this event evaluates to true based on all the things that C, D and E could
be.
So we're going to look at each variable and think of all the combinations of like, true, false, true,
true, true, true for each one of these variables and see if it would get us to a conclusion where
this is true and this is true, then it would lead to this.
Piece of code right here where we say B is now false.
Bob doesn't get the bananas right.
Bob gets bananas is false.
Because that would be was.
So first thing, we're going to look at the not right, so we have, if not not up here, we're going
to look at even a similar kind of situation of this.
So a is our variable.
And then so we have a here, and we're going to think about what happens when air is false, what will
not be.
You probably can figure out this out on your own.
It's pretty straightforward, but basically when you say not something, all you do is flip it or take
the inverse of it.
It's the opposite.
So.
You can think of all these words are actually very important in computer science, so envious and flipping
of a bit, you know, remember the zeros and ones are bits.
If you go back to that lecture, where we were talking about with Patricia was talking about the numbers
in computer science, the number of systems we have zeros and ones for binary right and their bits.
So if we flip a bit, that means that we turn it into the opposite.
So if it's a zero goes to a one, if it's a one, it goes to a zero.
So thinking about it in that sense, if we take the inverse or flip this for not a it's going to be
one.
If a is one, then not a will be zero.
Right?
So now let's expand it, so our sentence or our little sub statement up here, which is also a condition
because of this if.
Says, if not, not a.
So let's figure out what not not as in each one of these conditions in which a is zero and a is one.
Right.
So we've already figured out what not a would be, but what would not, not a B.
And even more than that, we'll go further just for the heck of it and say what is not not not a which
seems kind of crazy, but I just want to really like beat it into the mind that.
You just keep flipping.
You know, it just flips, flips, flips, no matter how many knots you have.
So with that, what do you think will be right here if a is zero, not a is one?
What is it?
Not, not a you can basically look right here and see what it would be if you just flipped it again.
Right?
So it is zero.
A zero, not a was one.
Now, we only have two options, zero one, so we put another notch in front of this, all it does is
just flip it back to zero.
Same thing for this, it's going to be a one, right?
Because not a zero.
So not not as one.
With that, you should be able to figure out this as well, so what happens if we just throw another
knot in front of this?
It's just going to flip it back again.
So not not not a will be one when not none is zero.
Same thing with this flips again goes from one to zero.
If you put another knot, it would be zero and one another.
Not it would be one in zero.
Another, not a zero and one just over and over again, you know, one zero zero one one zero zero one
one zero zero one, you can just keep feeling this forever.
So that is something I really want to point out, it is a big concept in computer science.
You know, when you say something is not, it means that you are taking the inverse of it, you're flipping
the bit, you're flipping it from false to true, true to false like that.
All right.
So let's move on to a bigger example.
So we're really going through it now, this whole thing.
So we have this, if not, not a now.
We're moving on to this next portion right here.
So if C and D or E, so this is where we get into a real truth table.
So the truth tables are something where we want to think of every possible combination that each one
of these variables could be.
And then we are going to figure out what this statement is based on each one of these potential values.
So each one of these rows, we will evaluate these D or E right here in C and D or E.
So this specific side, we start out with this or which is an important topic in computer science,
the OR means that if either side is true, then the result will be true.
So an either or type of thing.
So if this is true, then it doesn't even matter what it is because the whole thing, the Ori will be
true because we said one or the other has to be true, right?
So if this is true, then the story is true.
If it is true, then the Ori is true.
All right.
So this truth table, just to kind of point out again, you notice a we only had one variable to consider.
So that's why we only have two rows because a can be either zero or one.
But for this, C can be zero or one.
D can be zero or one.
And E can be zero one.
So we've got to think of all the possible combinations that we could have between these three variables
in the way and easy way to get all of the combinations filled out in your truth table, which is this
whole table is to count in binary.
So if you have, you know, three binary places here for a binary number, just remember that the fact
that you have two choices for it.
Notice how many rows we here have here.
One two three four five six seven eight.
The reason that we have eight is because we're actually having two to the third power row is because
that's how many combinations we can have of zero on one, because we have two.
The two is for the fact that there's zero in one.
There's two choices.
The three is because there's three variables, so you can put either a zero or one for three different
variables, that's why we have to go to the third power, which is eight rows, because that's how many
combinations we have.
So I just want to point that out.
So that's a good way to double check, to make sure that you're filling this to truth table correctly.
You may or may not ever be using truth tables.
If you are a student doing a computer science major, you will definitely encounter a truth table at
some point, most likely in discrete structures, discrete mathematics or something like that.
Maybe just a logic class in general.
But this is a good way to double check on your truth tables regardless if you're going to end up doing
this or using it.
So, you know, how many rows there are a good way to fill it out to is just to start with zero and
you notice I just kind of am like counting up here.
So.
Yeah, I just, you know, I have one.
And then, you know, this is two zero one and then I have this two one is two and then I have three.
And you know, I'm just I'm just counting up in binary here, basically, and that's how I filled all
the rows.
So you should remember that from the lecture where we went over a number of systems and in particular
went over that.
So if you're still confused on that and this is confusing you right now, you can go back to that and
kind of brush up on how to count up in binary.
So with that enough of me talking kind of on a tangent about this part, let's get started with this.
So we talked about the or meaning either or one of these has to be true for this whole sub statement
to be true.
So let's tell you this first row, we're looking at Dear E. So we don't really, really need to look
at Si column, right?
Because we don't care about that.
We only care about you.
So let's look at these two columns here and go row by row this first row.
What is going to be the answer here is zero and is zero zero means false, so we have false and false.
What did we say about the order here?
So before I say any more, see if you're going to figure out on your own.
OK, so false or false, we said that one of them either or has to be true for the whole thing to be
true.
Right?
So if either side is true, then result would be true, except neither.
Neither side is true.
Neither side is true, so it's false or false, that means that we have a zero, which is false.
OK?
Because neither side was true.
Let's look at the next one.
The next one is zero four D and E is one.
So we have a zero, which is false.
And then we have a one, which is true over here.
Since if either side is true, then the result is true, that means that it will be true because it
is true.
And that's one side, right?
Same thing, D or E is so D is one e is zero.
I'm just going to go ahead and fill this out, but if you want, it would be great for you to pause
the video and just see if you can fill it this whole column.
I'm sure that at this point, you should be able to to figure that out.
So it's going to be true for this one.
I look at the next row, I notice they're both true.
So since we're either or, it's going to be true.
The next row we have another, you know, D and E is zero.
It's pretty much the same as up here.
He knows this all three one zero here, but this had a one.
That's the difference.
So we're only looking at these two.
So it's false because neither side is true, then we have another one.
And pretty much wherever you see a one on either one of these columns, it's going to be a one in this
dear column.
So we're in for the one in a one.
OK, so let's move on to this part here.
We already know what the order is and we already know about.
But now we factor see into it.
And so we're looking at not just this part.
But we're actually looking at the whole shebang here.
So this whole line, so we've kind of been progressing our way up.
To get to this column right since we did dear, we can use this column now and combine it with it and
in this.
So what is the and mean and means that both sides must be true for the result to be true?
So you basically have to have a true and true for the whole thing to be true.
If you had if you had, let's say you had a and B, both A and B would have to be true for the statement
A and B to be true.
So let's go ahead and look at this.
So we're going to be looking at this column.
Of course you have.
You're like o d or e i need to resolve or do you even know you don't actually, because you've already
solved for all of the degrees right here in this column.
So this whole section circling right here is taken care of.
So now all you have to do is pretend this degree is one thing you can almost like replace D or E with
a new variable like F.
You could just say C and F and F is going to be all of these things in here.
You don't have to imagine like that.
If it's confusing, just know that there is this whole thing that I'm circling with.
My mouse is already taken care of here, so you'll be able to replace it with a zero.
Like, for example, when we start on this first row here, we're going to take a zero and replace this
whole thing.
I'm circling with a zero.
And then we're going to say C and zero for this first one.
So what is that?
C zero, if we have a zero and zero, that's false and false.
We said that and means both sides must be true.
The result to be true.
So therefore, neither of them are true.
That's false, right?
So if you think you already got a grip on this, go ahead and pause the video and see if you can fill
out this column by yourself.
All right, so I'm going to go through it.
The next one we have dear, he is one and C is zero.
But both sides got to be true, so that's false.
Same thing on the next one.
Both sides have to be true, which they're not only one side's true false false again.
This next one, we have a false over here in a two here, so that's false.
This one, however, both are true.
We have see as one and deary as one.
So that's true.
Then the next one is the same, I see a one and a one here, so that's true and the last one of the
all ones all the way across the board.
So that is true as well.
OK, so hopefully that was pretty straightforward for you.
Now we're kind of going to look at the last little thing, which is the fact that this is a if something.
And then inside of it kind of here we have another if something.
But really, if you think about it.
These are two separate conditions that need to be fulfilled.
For this to happen.
So technically, we don't need to just put this if this whole thing here, if C and E and I'm circling.
That doesn't necessarily need to be like indented inside of this if.
Up here in that, if not, not a it could instead all be in the same continuous line like one statement,
because you really have to do this has to be true and this has to be true.
For Beagles falls to happen, notice the and I said there, this has to be true and this has to be true.
For this to happen, that means that we could just instead put it all on one line and put an end in
between like this.
So if not, not a and.
If C and D or E then B is false.
So I want to point that out as well.
That is some things, something that you can do a lot of times to condense your code and simplify it.
So a nice thing to know is kind of look for these kind of logical simplifications that you can do.
You don't necessarily need to put some type of if condition inside of another condition for it to work
out.
If you notice that they could, if they both need to be fulfilled or something happen, you can to put
an end to their.
So something to think about.
And now that we have all of this kind of in one line, we don't necessarily we didn't have to put it
on one line to really think about it as one line, but now it's easier for us to see we actually could
like majorly expand this truth table and and really go all out.
You notice I put a red arrow here because we would need more rows for this.
What you can do is add a into the equation kind of literal equation, but you factor that into this
whole table here.
So you have a column and then you can do the have a not not a.
And then the whole thing over here in this column, you know, not not A and C and D or E.
So you could fill this out.
You're going to have more rows, of course, because you just added another variable in here.
So that's actually going to be two to the four amount of combinations you can do, right, because you
have four things now.
So I'm not going to fill this out, but if you would like to, this would be a good exercise to fill
out if truth tables are something that you are interested in practicing.
You will not need to use truth tables so much in the future.
I am guessing a lot of times you just kind of handle this logic on the spot mentally in your brain.
Although they are useful, I'm sure some people have to use them sometimes.
So you never know when it'll come up, so it might be might come in handy.
I'm not going to fill it out, but if you'd like to, you definitely can.
So we just learned a decent amount of stuff, but I don't want to stuff your brains too much with this
logic and go straight into the cold like immediately.
So maybe a review kind of what you've looked over here, but in the next lecture, we're going to discuss
how to implement all this stuff we just talked about in code.
A big thing I'm kind of jumping down to here is the if I didn't explain that a ton, but you might have
already heard that if something, then something else has a lot to do with code.
And so we are able to use this if that we saw in those statements in code as well, and we're going
to cover that.
They are called conditional statements.
And it's not just in if we have some other things that go along with it like else, if and else stuff
like that.
We're also going to go over operators, so today we talked about the and the OR and and not.
But we've got more than that that we can put in code and I'm going to go over that as well in the next
lecture.
So hopefully this was all understandable for you and try to break it down.
The truth tables really good to practice.
And also just remembering the whole thing about each variable that we are talking about.
There was something that was either true or false.
This logic we're talking about is Boolean logic.
You can get deeper into this topic and look up stuff on Boolean algebra, and that gives a little more
theoretical.
I kind of just combined a lot of things here into one lecture where I was doing it in kind of a casual
pseudo code way, using the word, not in the word or in a word.
And but if you look in a Boolean algebra, they have symbols to represent all these just like we will
in code, but a little bit different.
You know, there's a whole theoretical representation to this Boolean true or false algebra stuff.
So if you're interested and you'd like to learn more about that instead of just enough to be able to
start writing code with it, then you can go ahead and look up a Boolean algebra.
Of course, if you're on a computer science major, you're most likely going to have to do a lot of
this in discrete mathematics or discrete structures or whatever.
The corresponding class that relates to that is in your major.
So with that, I'm going to let you go and I will see you in the next lecture where we kind of turn
this all into code.