1.2 Logic Part 2 - IP

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

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