1.1 Logic Part 1 - 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 »

Video Transcription
00:00
>> Hello everyone and welcome back to
00:00
Intro to Python here on Cybrary on-demand.
00:00
I am your instructor as always, Joe Perry.
00:00
Today we're going to begin Lesson 1,
00:00
programming basics logic.
00:00
In this lesson, we're going to learn about
00:00
Boolean logic and logical operations.
00:00
Those operations are going to be AND,
00:00
OR and NOT and we're going to learn to
00:00
implement those logical operations in Part 2,
00:00
by learning what the logical laws
00:00
and the derived operations,
00:00
most specifically XOR is going to be
00:00
the one that really focus on.
00:00
What is Boolean logic?
00:00
I've used that term in a couple of these videos already
00:00
and it's important to understand
00:00
what it is and where it comes from.
00:00
Boolean logic was published by a man named
00:00
George Boole in the book and
00:00
the mathematical analysis of logic,
00:00
which is a page turner,
00:00
I assure you. [LAUGHTER] It's not.
00:00
It's an incredibly dry and extremely boring book.
00:00
It was published in 1847 and
00:00
like most things, it's terrible.
00:00
That was mean to say,
00:00
but I'm going to stick to it.
00:00
Stick to my guns. [LAUGHTER] More seriously though,
00:00
is influenced by a Sanskrit philologist, Panini.
00:00
I think that's how you pronounce that name,
00:00
but honestly, my Sanskrit is rusty.
00:00
I haven't taken it since high school.
00:00
You know how it goes?
00:00
Panini was a philologist,
00:00
is a person who is a grammarian.
00:00
They study the evolution in
00:00
the design of languages and grammar and how
00:00
they function and he
00:00
was quite possibly the first person to
00:00
apply formal logic to
00:00
the concept of linguistics and grammar.
00:00
Over the course of creating
00:00
that work and over the course of documenting that,
00:00
Panini developed the concepts
00:00
of truth and falsity that were then
00:00
adopted to create Boolean algebra and Boolean logic.
00:00
There are only two values in Boolean logic.
00:00
It's not like normal math where there's
00:00
an infinite number of
00:00
numbers and arrays and things like that.
00:00
In Boolean algebra and Boolean logic,
00:00
there are only two possible values,
00:00
one and zero,
00:00
and then there are only three possible operations.
00:00
There's AND, which is
00:00
represented in formal logic by a period
00:00
and usually in shorthand or informal or programming,
00:00
it's represented by an ampersand.
00:00
There's OR, which is represented by
00:00
the plus sign or by the pipe.
00:00
That's the straight line, up and down.
00:00
Usually it's going to be on
00:00
the same place as your forward
00:00
slash and then NOT,
00:00
which is usually represented by a tilde.
00:00
So those are the only two values and
00:00
the only three fundamental operations of Boolean logic.
00:00
But from those very simple concepts,
00:00
were actually able to derive all
00:00
of modern computer science,
00:00
all Turing complete machines,
00:00
and a pretty substantial chunk of mathematics.
00:00
Now, there is, for those of you who are really
00:00
excited about the most modern technology,
00:00
quantum computing does play with that a little bit and
00:00
introduces a relativistic and probabilistic states.
00:00
But fortunately, this is an intro to
00:00
Python video and not a quantum computing video.
00:00
So save your hate mail for when I earn it later.
00:00
[NOISE] In this lesson,
00:00
we're going to spend a lot of time on truth tables.
00:00
If you've never had the joy of
00:00
going through a CS101 class,
00:00
a truth table is exactly what you see in front of you.
00:00
It's a table of some number of values and
00:00
statements which is used to
00:00
represent every possible state of the equation.
00:00
In this case we have two inputs,
00:00
A and B, and you'll see those use pretty often.
00:00
With A and B, we represent every possible combination of
00:00
those two Boolean factors
00:00
or Boolean values, true or false.
00:00
By the way, in computer science,
00:00
when I talk about true and false,
00:00
that's the ones and the zeros of binary.
00:00
Binary is an implementation of that Boolean logic.
00:00
We're going to use one or zero instead of
00:00
true and false in most of these places.
00:00
Don't let that trip you up too much.
00:00
So here you can see we have two ones
00:00
and two zeros under A.
00:00
If we just had A in this table,
00:00
it would just be two lines of one and zero.
00:00
But because we have two factors,
00:00
we have to represent every possible
00:00
combination and for those of you
00:00
who know binary and understand how to read binary,
00:00
you know that with two digits you're
00:00
capable of representing four numbers,
00:00
0, 1, 2 and 3.
00:00
In a useful equation when you're building
00:00
your truth tables is however many inputs you have,
00:00
it'll be that power of two number of rows,
00:00
which is to say, well, that power
00:00
of two number of possible combinations.
00:00
So that many rows, which is to say,
00:00
for example, if you have three
00:00
inputs is going to be eight.
00:00
If you have four, it will be 16.
00:00
If you have five, it'll be 32,
00:00
on and on and on and on.
00:00
If you have five inputs,
00:00
I generally don't recommend
00:00
building a single truth table.
00:00
We're not going to deal with any truth tables larger than
00:00
three inputs and two or three statements at a time.
00:00
Your statement is going to have
00:00
the same number of rows as
00:00
your inputs and that's just
00:00
going to be whatever equation you're doing.
00:00
We'll see that it'll make a little more sense,
00:00
I think in the next couple of slides,
00:00
we'll see that play out.
00:00
But your statement is going to be just all of
00:00
the solutions with those inputs.
00:00
As an example here, we have the first logical operation.
00:00
We see that we have true
00:00
and false represented with A and B the same way
00:00
we do in this previous slide with ones and
00:00
zeros and we see that and evaluates to true,
00:00
that is, and evaluates to one if and only if so,
00:00
only in the case that all of
00:00
its input values are also true or one.
00:00
On this table you can see that on our first row,
00:00
A is one and B is one.
00:00
So that's representing the binary number 3.
00:00
The AND, A and B we're going to
00:00
represent here, [NOISE] is one.
00:00
Because of the fact that both of the inputs were true.
00:00
The output of AND is true, pretty straightforward.
00:00
The next row we have A is one which,
00:00
helps us to evaluate this,
00:00
but B is zero.
00:00
Now, I'll say again and evaluates to true
00:00
only in the case that all input values are true.
00:00
Which means that with B being zero,
00:00
A and B is also zero.
00:00
As you can see on the next row,
00:00
A is zero, B is one,
00:00
still have a zero in it and on the final one,
00:00
of course both of them are zero,
00:00
therefore AND is zero.
00:00
A useful shorthand is that generally speaking,
00:00
if you add all of your inputs together in a truth table,
00:00
you're generally only ever going to have
00:00
one row evaluate to true.
00:00
It's not 100 percent the case,
00:00
there are complex inputs that can mess with that.
00:00
But as a basic rule,
00:00
you can generally trust
00:00
that and I want to mention real fast.
00:00
I always skipped it, AND is often referred to as
00:00
the logical conjunction in formal logic classes.
00:00
So if you hear that, that's what that's referencing.
00:00
Now, OR logical disjunction OR is similar to
00:00
AND in that it evaluates to
00:00
true based on whether or not an input is true.
00:00
It's different in the sense that if any of the inputs to
00:00
OR are true OR will evaluate to true.
00:00
So not exactly the inverse of AND,
00:00
to some extent it feels that way and it
00:00
looks that way on the truth table as well.
00:00
For example, on our first row
00:00
we have A and B both equaling one.
00:00
Now, it doesn't matter if both of them are true,
00:00
so long as one of them is true.
00:00
So A or B evaluates to true.
00:00
On the next row, we see that A is one and B is zero.
00:00
Now with, and you'll remember that evaluated to
00:00
zero because one of the inputs was false.
00:00
However, because one of the inputs is true for OR,
00:00
it evaluates to true.
00:00
The next row, same thing with B being
00:00
true instead of A and then the final row,
00:00
because none of its inputs are
00:00
true or will evaluate to false.
00:00
The third and final fundamental logical operation
00:00
of Boolean logic is NOT,
00:00
or the logical inversion.
00:00
NOT evaluates to true if and only if,
00:00
only in the case that it's input is false.
00:00
NAND is generally used for single inputs or it is
00:00
used for the results of an equation.
00:00
For example, you can see here that I have NAND and NOR,
00:00
which are two very commonly used gates in logic.
00:00
Gates and operations are differentiated in
00:00
that a gate is something that
00:00
is actually physically constructable.
00:00
Even though the AND,
00:00
OR and NOT are the fundamental operations,
00:00
NAND and, NOR are the two most commonly
00:00
used fundamental physical gates of logic.
00:00
Don't get wrapped around the axle with that,
00:00
you aren't going to need to learn how to create
00:00
a circuit board or a circuit diagram.
00:00
Don't worry about that at all in this class.
00:00
Point is, NAND and NOR are
00:00
two very commonly used logical operations
00:00
which are derived from the three fundamental.
00:00
So here you can see that NAND,
00:00
which is NOT AND,
00:00
is going to be evaluated based on the input from AND.
00:00
So, AND we already established is
00:00
going to be 1, 0, 0, 0.
00:00
NAND is just the logical inversion of that.
00:00
We have 0, 1, 1, and 1.
00:00
Very straightforward, very easy
00:00
to wrap your head around once you've
00:00
seen it a couple of times,
00:00
A or B, you can probably guess because it's 1,
00:00
1, 1, 0 and NOR is the logical inversion of that.
00:00
We're going to have 0, 0, 0 and 1.
00:00
At the next lesson, we're going to do some math.
00:00
We're going to jump in and really start
00:00
learning about some computational logic.
00:00
We're going to learn about some
00:00
>> fundamental laws of logic.
00:00
>> Here I've included a comic from the inimitable XKCD.
00:00
There are going to be a lot of
00:00
XKCD throughout this course.
00:00
Because Randall Munroe is frankly
00:00
a genius who has made the world a better place.
00:00
That's said before we go onto the next lesson,
00:00
we're going to take a second,
00:00
we're going to do a knowledge check.
00:00
We're going to break these videos upload
00:00
or the next part of this lesson.
00:00
Break these videos up a
00:00
little bit just so you have time to
00:00
digest it and make sure you've learned
00:00
the actual material.
00:00
Which operation is the logical inversion of AND?
00:00
What is derived from the combination of AND and NOT?
00:00
The answer is NAND.
00:00
[NOISE] What are
00:00
the two possible values of Boolean logic?
00:00
There are only two, [NOISE] true and false.
00:00
What are the three fundamental operations
00:00
of Boolean logic?
00:00
There are lots of possible operations.
00:00
There are only three that are fundamental.
00:00
AND logical conjunction,
00:00
OR logical disjunction, NOT logical inversion.
00:00
Summary in this video we cover basically
00:00
what you just checked out on that last slide,
00:00
the two possible values,
00:00
the three possible operations,
00:00
and discuss some of the derivations from those.
00:00
Again, in the next video, we're going to come back.
00:00
We're going to learn about the laws of
00:00
logic or we're going to apply them.
00:00
Until then, I am as
00:00
always thrilled to have you here and
00:00
hope to see you back in our next video.
00:00
I'm your instructor Joe Perry,
00:00
and this has been intro to Python.
Up Next
Similar Content