Though this is another video we're going to be describing a little bit about distance in order that
we can touch on Hamming distance and eventually get the Hamming codes in our quest to understand error
correcting codes and error detection codes.
Over here this number line starts at 0 1 2 3 4 and goes on to infinity.
The way that we would measure the distance between maybe 0 1 and 2 in this area right here is that we
would just simply say how far is one from the other.
Well you have two points it's called X and Y.
Just make the bigger an X and the second one y.
Well the formula is that it's X minus Y and they take the absolute value.
Now it's not a formula as was kind of logical which is subtract you subtract on from.
That tells you how far something is.
So we're trying to understand the concept of distance a little bit.
There are ways that we could kind of misunderstand distance but we we also have to kind of describe
what we mean when we say things about this.
And because if you ask how far is it.
If I were to have a point right there and I were to travel in a big circle and come right back there.
Have I moved.
Yes.
But have I gone any distance.
Well maybe yes maybe no.
So we do have to define that.
And in physics these types of things are defined.
I'm just trying to get out these questions you know to measure and figure out what we mean.
OK.
So that type of distance is not unreasonable to kind of describe that.
You subtract one from the other two minus one that gives you the distance between x and y.
What if we had to if it was 2 D instead of 1 D and we were looking at the points A and B.
And we wanted to get from one to the other.
We wanted to go from one to the other.
Well if we started this X and ended this x then we know how far that is one to the other because that's
just the change in x.
In other words x x y and minus x 2 because that's how far we went just like before.
One minus the other that's the change in the X separately.
We can mention the change in the Y which is this distance.
So this distance right here is the change in the Y on that one.
So we could have y one and we can have y two.
And we would have to figure out what those distances are.
Now how do we compare.
Because granted you went this far in the X and this far in the y but how does this.
Well if you remember a little bit about triangles it is a 90 degree angle.
And so we could say this is a and this is B and this is C and we could say a great be critical to square.
So we could know so how far is this distance from X on to x to.
That's one minus the other.
How far is the Y.
That's one minus the other so therefore we know that a because X X one man is x 2.
We know to B.
And then we can figure out what the C is by using triangles so we could call it X or Y or we could call
it a and b and we would take a script plus B squared.
Then we take the square root that would give us C because it has no secrets or take the square root.
So I'm just going to rewrite it so that it looks like this extra place where I scared to that to the
half.
OK.
But that's one notion of distance and that's not unreasonable.
And that's maybe how our world works.
Not really but it's possibility.
Another distance that we could discuss is this picture right here which is this is a grid.
We'll call it Manhattan distance and we will pretend that it's a perfect creator and that the height
and the length of the same I could change this but it doesn't matter.
We want to get from the start over here to the end how do we measure the distance.
Well you could go straight but that doesn't really make any sense right.
If you want to get from here to here how do we get there.
Well we said well we do a straight line but what if it's a road.
Like I can go that way and this is the only way that I could go to get to that point.
Maybe so we want to understand a little bit about different types of distances because it's meaningful
in different ways.
If we had a grid like in Manhattan so this would be Manhattan distance and Hampton and distance.
We could say oh just follow the grid and get to the point as quickly as you can.
Now the nice thing about this is you'd say well there's a lot of different paths can take the yellow
path that a green path.
But the truth is though that if you take this that that's one two three four five six seven eight nine
10 11 12 13 14 that's 14 that's take a different path.
One two three four five six seven eight nine 10 11 12 13 14.
It's not going to matter which path you take.
Assuming you are directly going there and you always hit in this case 14 OK this is one two three four
five.
And this is one two three four five six seven eight nine over there.
So nine and five.
The minimum is 40 there's a matter which path you take now would be Manhattan distance you can get across
a building.
You can go through the grid.
But again another type of distance and we want to quantify qualify this.
Here is a different type of distance that we can measure.
Imagine you're on a donut.
This is not a very good drawing but if you have a donut right and we'll just clarify that you got like
that.
This is a donut or a bagel or whatever anyone to get from one point to another.
You can't just jump from this point to this point as to why you actually have to go like that to get
there.
Imagine that we want to get below it again if we want to get if we're on this if.
For instance where on where.
Right here on it we have to go all the way around to get to there.
We can just go straight.
So all of a sudden our notions of distance are a little bit different.
Now I can travel like this.
Kind of like a circle I could travel like this kind of like a circle.
But what's going on when we travel around the circle if we were going to go in a loop like this.
We are traveling in a circle we can't go straight.
Perhaps we could go a little bit quicker perhaps I could go like give this to travel.
Why is that any quicker.
It's a good question.
We have to have a notion of how we're going to measure what it means to go from one place to another.
And quantify this distance so let's say I'm here and I'm going to travel from x to y should I go here.
Not so bad.
Should I go here.
Now remember this is a bagel a donut.
So when you go down this is really going down.
It's not straight.
This is really going down then it's going here and then it's going back up.
So we would.
There are ways to measure this but let's just pretend we're walking along this week and think that all
of a sudden distance is very very different than what we expected.
Because if you want to go from some point to some point let's say over here that's not so bad.
But if you want to go down below that's going to that's going to be quite long so it's going to take
much longer than you expect we could imagine walking along this in the same sense as we would along
this shape over here.
This shape you can imagine is really just cut off.
But this is the bagle.
This is the big I can draw a circle over there I can draw the outside circle.
But here you get a little bit measure better measure of depth.
If I want to go from one point to another over here I have to go down that straight if I want to go
up again.
This is the quickest routes not to go straight because it's it's doesn't make sense I guess you can
see it from the picture.
But we can go along this and set it up this way.
So this would be more of a hyperbolic space which means that triangles in this space have less than
180 degrees.
So if we had if we lived in this type of space we could have we could have triangles and they would
have they would look like this instead and they'd have less than 180 degrees no longer that a work like
that and we could also have a different type of distance that we might discuss.
And that distance is.
Let me just come over here and we could have a imagine instead of work walking on a bagel which may
or may not be one of your favorite pastimes but imagine instead of walking on a big wall what we're
going to do is walk along a sphere.
OK so let's walk along a sphere I will draw it even though my drawing isn't perfect but a atmosphere
if we can draw a triangle on this is going to look like this.
These are the points you may not realize it but those are the points.
OK.
You have to go like this along a sphere like this along a sphere like this along a sphere so here that
the where there is Anglo's quote unquote.
This is going to be greater that when doing down there is less than 180 if it's hyperbolic which is
on a bagel if it's spherical
it's going to be greater than 180 k.
So spherical greater than 180 hyperbolic less than 180 for triangles.
Now you can imagine when you fly in a plane you don't go straight along the world like that simply because
it would make no sense it would take too long.
Instead you got up around if you're going from New York to to Taiwan you go through Alaska.
So hopefully you understand now what we'd like to do is develop this just a little bit and quantify
that.
So how do I do distance from A to B let's say and point three come for three coming four is that in
six comma six is B.
So I put X and Y but we could just put A and B doesn't.
Or same thing.
OK.
Now when I do that I take the difference in X's because that's from here to here.
That's a different set X as the difference in Y's that's from here to here and then I do my Pythagorean
Theorem square at the last.
Now that was if that would work out to this and there's an Excel formula just to tell you that says
some m x and y 2 and you take the 2 points 3 4 6 6 and it tells you what it is before the square root.
It says you're summing the x's minus the Y squared.
That's what that strange thing is.
And then you take this very you get 3.6 0 5.
I just filled in the whole formula myself over here just to show you.
But that would be that would be hey do it now over here.
I did it instead of taking squares.
Make this bigger so we can see it.
OK.
I did the same formula but instead of taking squares I did it when this number and this number and this
number are instead of 2 it's 1.
And then I can do it for 3 3 3 1 over 3 4 4 1 over 4 5 5 1 over 5.
OK.
So in other words what I'm doing is I'm making a formula that says I'm making a formula that says I'm
going to just say the difference in X's.
OK the difference in Access I'll say Delta X with the difference in X as to K plus the difference in
Y's I'm just saying that is the difference in ys to K and then I'm doing this to the one over K All
right so that's the general form
of distance.
Now that would help.
Now if I'm going to do it to the case here's K when it's one you get five that's the manhattan distance
from three four to six six.
Now that makes sense because you have to that a the let me draw this.
Here is a grid and I want to get from 3 4 to 4 2 4 6 6 6.
So here I go for I go 1 2 3 and here I go 1 2.
So therefore I can see that that all together would be five because that's three and two was five.
So that's the distance that I would travel if I were just doing one and this formula works for two.
I tested that already and that's the triangle.
And that formula works.
And we could then figure out if let's just say that I can keep doing this for different letters.
So this would be the same formula with 20.
So that would be the difference in is how fire driving the x to the 20 plus I drive how far you're traveling
in the Y to the 20.
Add those together in the end due to the power one over 20.
Now you'll notice just something kind of obvious here it comes out that if you were to keep going it
just gets closer to three and it keeps getting less or less till it's close to three.
So in other words if I were to come all the way down here and I want to say how much did I travel in
X that means how much should I travel in.
And I do this to the Infiniti and then I add how much I travel then why would I do that to the infinity.
And I do that.
And then I do one over infinity over here pretending that those are a legal limit.
You know this but pretending that it's and I I don't mean real infinity I mean no limit but that if
I go to 30 instead of 30 I go to infinity then I'll just get three.
So if I do that over here this is what's going to come out to presumably.
We can see that it keeps getting closer and closer or maybe it'll get less.
We don't know but we could test it actually and see and figure this out.
But we can see that it seems to be getting close to something.
So as is we can now measure distance in a different way.
Now let's talk about another type of distance.
OK.
How far is this number.
From other numbers let's find the way to measure this number from other numbers.
I'm going to take this number and I'm going to say how far is it from other numbers.
Well I could think of it as if you flip one bit make that does that make it flip that that's a distance
of one.
What else can I do.
I could flip the middle bit.
That's a distance of one and I can also flip the first.
Those would each be 1 away because in my system you could be one away and that's the neck.
That's how far you are you're one away now the next thing that I could do was I could ask how far this
is from anybody.
Well I already know that it's close to that.
It could also say it's close to this and you can also say it's close to this and there one way because
there's one difference in the numbers.
OK what about this one.
Well it's close to that.
It's also close to this and it's also close to this.
But this one I already used up here.
So let's just draw this so that it actually connects Instead we're just going to draw it so that it
connects OK.
OK.
Now let's go over here.
How far is this from anybody.
Well 1 0 1 would be right there.
So it connects to that and then 1 1 0 would be over here.
So it connects to that.
All right.
This you can see we could continue with this because this needs to connect to 1 1 1 which I'll just
roll over there and I'll connect that and then that's going to connect to 1 1 1.
And this is going to kick them 1 1 1 and we have something that beautifully hit this incredibly unclear
picture would tell us how far each number is from each other.
Now thankfully we actually have something that's a little bit easier to understand than this picture.
By the way though before I get there you could do something called the gray code which would be counting
instead of binary you count where you only change one thing.
So this would be changing one thing and the next number is normally thought of as 2 which is 1 0 1.
But instead of going to do this.
And that's the next number because I'm trying to count in a way when everybody is only 1 away from the
next from the next one meaning this changes one bit to get here.
This changes one bit to get there.
Etc..
OK.
So you could count this way.
There's variations I'm just trying to show you that.
Think about this.
Now let's take these numbers that are in here.
And let's try and see if we could get a more logical way of understanding this.
In other words a better structure really nothing more than that.
Well here it is the better structure here is all nine numbers that are three digits.
And this is how this is a cube that shows me the distance each distance is the same.
This is hamming distance.
OK.
So let's start at 0 0 I am 1 away from this.
I'm 1 away from this one way from this the max distance I could get would be 1 to 3.
That's how far I am from that number and then I can tell how likely errors would be etc. because if
it having this means of one then it's more likely that an error having this is a three.
Less likely to have an error.
OK let's take these two cubes this cube and I'm going to put one right here.
You can see that's a Cuban that need it.
This is another clue.
OK.
Now this cube is going instead of just having three digits is going to have a zero in front of each
digit.
And that's it I have read here.
This cube instead of having three digits is going to have a 1 in front of each digit.
OK.
Now there's a connection that this 0 0 1 1 0 could become 1 1 1 0.
OK.
So there's a connection.
So in other words how does the 1 0 1 0 connect it connects to 0 1 0 1 in other words when that zero
changes to a 1.
This would be for four bits.
And this is the picture that would be.
And we can measure distance or how does 000 go.
Well it's one way from this one away from this one away from that's one way from bet.
So you can have a max distance of four over here because there's no other way.
There's nothing further than that I could go one two three four.
I could do it a lot of ways but the minimum distance is for one to three up.
So here I see that instead perhaps I could do one two three but four would be over there.
And can I get there a different way.
One two three four.
Mm hmm.
One two three.
It seems to me that if we just check this out that oddly enough that I can take this number and I can
get to any number 1 2 3 1 2 3 1.
Let's see if we can get to 1 1 1 1 2 3 4 that's 4.
Let's see if we can get to 1 1 1 and a different way.
Is there anything faster.
1 2 3 4 No.
1 2 3 4.
No.
So if we want to get the maximum this this is forbit so presumed so reasonably.
So it's four to get there because you need to change 0.
You need to change four of these to get there.
So hopefully you get the counting and if it's three the max and this this would be three.
So this would be a Hamming distance and this is our picture and this explains to us how to get from
one digit to another and then have distance how we think about distance and how we would in a computer
to think about distance that we would go further now and discuss hammering coats.