>> Hello everyone, and welcome back to intro to
Python here on Cybrary On Demand.
As always, I'm your instructor, Joe Perry,
and today we're here talking
about the programming basics,
specifically focusing on logic.
This is part 2 of Lesson 1.
In part 2, we're going to be discussing
the laws of logic.
Here's our first one, the law of idempotence.
Now the law of idempotence or the law of idempotence,
depending on the accent of
the person who taught it to you,
is very similar to the law of identity in arithmetic.
Basically, all it's saying is that when you
perform an operation with only one input,
A or A, A and A,
the output is just going to be whatever the input was.
The obvious exception from that is
the inverse operation or the logical inversion operation,
which will flip the input.
But with Or and And,
it will just be whatever the input was.
This may seem obvious,
but it is actually one of the fundamental parts
of Boolean logic,
the way that one equals one
is actually a fundamental proof of mathematics.
The law of association.
The law of association is a trickier one.
I don't really like any of
the verbal definitions that are given,
which is why I just use the equations in
a truth table here to help you understand it.
Basically what the law of association
is that if all other things are equal,
if you're performing the same operation
with all of your inputs,
it doesn't matter the order in which it's done.
Normally order matters,
and in logic,
you're going to do it very similarly with mathematics.
Inversion is going to come first,
and then you're going to do whatever is in parentheses.
You're going to do whatever is in
parentheses and then inversion.
Parentheses will always come first,
of course, with mathematics.
Here you can see this is just an easy demonstration
that nothing changes in these types
of equations when you move the parentheses
around because all other things are equal.
The law of commutation is simply
saying that the order of operations,
the order of inputs to a single operation don't matter.
A and B is the same as B and A.
You don't really have the case
like with subtraction in math,
where if the order is off,
you're going to get a different answer.
It doesn't matter about the order with
a single operation.
The law of distribution is a pretty interesting law here.
What it's saying is that if you perform an operation
against the results of a sub-function,
something like B or C in parenthesis,
performing and against that is the same as
performing and against both of
those separate values and/or in the result of that.
That's a tricky thing to understand.
Here I have this truth table built out.
The law of distribution you're not going
to use terribly often.
A lot of these logical laws you're really
going to use just conceptually,
not really applying them very rigorously.
But having this truth table here is very helpful because
it helps you understand the way the laws work,
even if trying to come up with
a good verbal definition is challenging.
You can see A and B or C is going to evaluate to 1110,
and then the rest are all zeros.
Then the same way with A and B or A and C,
it's going to evaluate to the exact same thing.
That's like I said,
that's the great thing about truth tables.
I know a lot of people don't really like them
because of bad experiences.
When you're using a truth table you can put all
of the possible inputs and outputs in front of you,
and really get a good sense of
what the equation is and how it works,
and be able to identify relationships
you would otherwise potentially miss.
The last law we're going to talk about is
a law called De Morgan's law.
It's my personal favorite because I
think it's absolutely fascinating.
The idea of De Morgan's law is,
the inverse of A and B equals inverse A or inverse B.
As well, the inverse of A or
B equals inverse A and inverse B.
You can see that on the truth table.
I find this absolutely fascinating personally,
and hopefully, you find it interesting as well.
The idea that because
of the structure of logical inversion,
and I alluded in the first video that Or and And have
a theoretical inversion in
terms of the number of true values they have.
Here you can see that when you break it out,
it's represented again on the truth table.
Even if it seems weird or hard to understand,
you can see that it just is
true by examining the inputs and the outputs here.
Now there's a third operation
that I want to talk about here,
not a third operation, but a new operation
rather called XOR.
XOR is the concept of logical exclusion,
which is to say one
and only one of the inputs can be true.
Or as you might hear it more often,
the inputs must be different.
If A is 1, B must be 0.
If B is 1, A must be 0.
Now, XOR is extremely important to computing.
In fact, XOR physical gates
are the most common gates along with NAND.
XOR is used for encryption and
all sorts of other programmatic functions.
It's actually fascinating all the places
that XOR can show up.
But that operation is not actually
its own fundamental operation.
As I said in the last video, there are only the three.
Instead, XOR is a derivation
of the three operations combined.
Now what I want to do now is I want to give you a chance
to try and figure out what that operation is.
I'm just going to pause. I'm going to give you
the chance to pause the video here,
so go ahead and pause.
Either you figured it out or you've come back to
find the answer, and it looks like that.
Now that obviously is a pretty complex equation.
It's more complex than anything we've looked at so far,
A or B and the inverse of A and B.
The reason why I put this up here is just because I
think it's absolutely fascinating.
With just those three gates,
you're able to derive a completely different process.
Not only derive a completely different process,
but one of the processes that makes computing possible.
All of computer science is born
just from these three operations, these two values.
When I say all of computing,
I mean everything that you're
currently doing on your screen,
the video you're watching,
the images on it,
all of me talking into this camera and being recorded,
all of that is a product of
just two values of three operations.
That is absolutely fantastic and mind-blowing to me.
If it's not to you, I'm sorry that
the joy and excitement is gone from your life,
but it's super cool,
and you should take a
second and consider how fascinating that is.
In that last slide,
I showed you a complex operation.
In this one, I want to give you an idea.
This slide, and the next one, I'm going to
show you how to break that down,
how to think about logic problems like this.
It's really important to take
a big problem and break it down into its component parts.
You're going to see that a lot
throughout the course of this video.
Throughout the course of this lesson and
this actual course and the next two Python courses,
you're really going to want to be able to
break problems down into their component parts.
It's just a fundamental thing that you want to know
how to do in computer science.
Here you can see that I have this operation,
inverse A or B,
in parentheses, and inverse A and B.
You can see here that instead of trying to do
that very difficult complex equation,
I just broke it up into pieces.
I said, inverse A or B can be turned into its own input,
which is going to be called N,
and that we will derive from the previous values.
We're also going to put an inverse A in
its own column just to make it easier to use.
Also with M, we're going to do inverse A and B.
Then in the last column is just going to be
ending those two columns together.
We're not going to worry about trying to
remember which value we put where and who's doing what.
We're going to break this into its constituent pieces
and solve them individually.
You can see here that that's going to make
the process just so much easier.
That's true not only in this class,
not only in programming, but really in life.
Finding a way to break down your problems into
their component pieces, their simplest,
most fundamental level, solve them individually,
and then use that to solve the whole.
Knowledge check; what do we go over in this video?
The following are examples of which laws?
A and B or C is the same as A and B,
or A and C. That's distribution.
A or A equals A,
that's the law of idempotents or identity is
generally what I refer to it as.
A and B equals B and A,
that's the law of commutation.
Of course, A or B in parentheses,
or C is the same as moving the parentheses around,
which is the law of association.
Which super common logical gate
is derived from the three core operations?
If you remember from before I
rant about how cool computers are,
you'll remember that that is XOR.
In this video, we talked about the laws of
logic, derived operations,
and I break down complex problems
into their constituent pieces.
Hopefully, you learned a little bit, and hopefully,
it's inspired you to come back for the next lesson,
Lesson 2, which is going to be programming basics.
We're going to learn about how to
use variables in programming.
I, as always, I'm your instructor,
Joe Perry and as always,
I'm very excited to have you here,
and I hope to see you in our next class.