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