The Maths Behind Bitcoin: Let's get geometrical
February 24, 2019 - 19 min
This article is part of a series exploring the maths behind Bitcoin and it will not mention any cryptography, any cryptocurrency or anything cryptic at all (okay, maybe just a bit of maths — but that’s what you’re here for, aren’t you?). If you missed the introductory article, please go check it out.
Photo by Alex Holyoake on Unsplash
The goal here is for you to understand enough geometry to feel comfortable reading the next articles about elliptic curves. You will learn about coordinate systems or how to record a Chess game; you will discover the commitment that any two points make to each other (not so exclusive, huh?), namely lines. You will touch on a bit of set theory to realise what a curve is. We will go on a tangent, and end this article with a bit of fun with squares.
Recording a Chess game
Chess is this game that relies on moving pieces on a 8x8 board and the goal is to capture the opponent’s king to win the game. There are pawns, kings, queens, bishops, knights and towers. Sounds more exciting than Battle Royale, don’t you think? Computers also know how to play and they can even beat the best human chess players!
This what a board looks like at the start of the game:
Initial chess board configuration
The opening move could be any of the light pawns going one square or two squares towards the dark pawns. Let’s say the first player moves the pawn in front of their king two squares towards the dark pawns. The second player replies with a well-known opening called French defense, by also moving the pawn in front of their king one square towards the light pawns.
Imagine now you are in charge of recording a chess game for posterity (there could be some really interesting strategies or tactics): do you think there could be a better way of describing the moves? We could record every piece’s move with →, ←, ↑ and ↓. For example
light pawn in front of king ↑↑ dark pawn in front of king ↓ ... light knight ↑↑→ ...
However, some questions quickly arise:
- is a knight going ↑↑→ or →↑↑?
- is a bishop going ↑→↑→ or →↑→↑?
If we have different ways of representing the same thing, it might quickly become hard to read if we do not follow one convention.
Enter coordinate systems
We can do better than that and write the previous moves as:
meaning the piece at location moves to , and the other piece at moves to .
If we agree on some common context to reason about these moves, this system is enough to describe all chess moves. We will agree that the vertical axis of the board is labeled by letters A, B, C, D, E, F, G, H and the horizontal axis of the board is label with numbers 1, 2, 3, 4, 5, 6, 7, 8. Each square of the board now has a name, eg. , and we can forget about up-up-right or right-up-up to mean the same move as to .
As an aside, we also need to consider that the moves are recorded in an orderly fashion; otherwise, how do we know this move is allowed if we cannot verify what piece we are talking about? If you’re interested, you can check out the numerous ways to record chess moves.
Well, the same is true for geometry. If we want to reason about points, lines, curves, circles, triangles, we need to agree on some context or way to represent this information somewhat accurately and without ambiguity. In the context (get it?) of this article, we will use the Cartesian coordinate system.
The horizontal axis is commonly called the -axis and the vertical axis the -axis. The points will be labelled under the form , just like before we had E3 to mean ; is the horizontal coordinate and is the vertical coordinate. In our case, and can be any number, like but also like , , , . Of course, there are other ways to represent a point:
The blue point has polar coordinates and Cartesian coordinates
We will however stick to coordinates to talk about points on the plane.
Any two points commit through a line
We’ve all learnt at school that for any 2 points on the plane, there exists a line passing through them. But let me ask you: what is a line exactly? Pause for a moment and try to define what it is in your own words.
This is not a line,
When you really look at it and zoom in, you might just see that you just drew a collection of points and they are all so close to each other that what you see is a line.
This is actually how you would write it with mathematical symbols:
Let’s go through these notations:
- : the line passing through points A and B;
- : the set of things with these properties;
- : all the pairs of (real) numbers;
So mathematical expression above means: the line passing through points and is the set of points such that is point or is point , or dot-dot-dot. We need to determine this dot-dot-dot to get the full picture.
Algebra to the rescue
Don’t leave just yet, we are getting started! Algebra is where the juice is, you do not want to miss it. Saying that there is a line joining any two points means that any two points have a relationship, namely that is related to in some way. Algebra will help us understand that relationship more precisely.
Algebraically, a line is indeed an equation:
which expresses the value of depending on the value of , given parameters and . Parameter is called the slope and parameter is called at the origin.
Let’s have a look at a few examples to understand better what and mean.
On the line , since it is not depending on we have , and so must be . We obtain that not depending on means has a constant value and this translates into a horizontal line geometrically.
On the line , we have and . We can see that the point with coordinates is also being passed through.
Specifying is the same as saying that the line must pass through the point with coordinates .
(That’s incidentally why is called y at the origin.)
Finally, on the line , we can see the line passes through , which means , and we also have . Note that the slope of the line is steeper than the line .
Joining algebra and geometry, we can write that a line is a set of points satisfying the equation . Going back to the idea that there is a line passing through any two points, we can rephrase it by saying: there are numbers and such that and , for any two points and . The following equations must be true simultaneously
which we could rewrite
which means in particular
so that finally
Now that we know , we can find :
To summarise, we found:
Let us use these formulae to obtain the equation for the line passing through points and :
and thus and .
The line passing through and has equation
Before moving on to curvy lines, let us understand why is called the slope.
From the equation we obtained for number , we can visually identify the quantities and :
- corresponds to the distance along the -axis to go from to , and
- corresponds to the distance along the -axis to go from to ;
In some sense, measures how much grows/shrinks as grows, and it could be expressed in percents like on road signs.
A slope , Photo by WikimediaImages on Pixabay
Rewriting once again our representation of a line as
with , we see that we are using a very specific function of . We could change it to
and obtain the set . This set corresponds to the parabola:
To generalise further, we could write as . That means we can consider functions of and to describe other sets of points:
It is for example useful to describe a circle. A circle is defined as the set of all the points lying at the same distance , called the radius, of another point , called the centre of the circle.
Taking the centre to be and the radius to be 1, can then be expressed as
This form of expressing sets of points will be useful when talking about elliptic curves in the next article.
(Spoiler alert: for Bitcoin!)
Let’s go on a tangent
Now that we understand lines and curves a bit better, let’s discuss this special kind of lines called tangents at a point to a curve. These lines will be necessary for us to define a group structure on elliptic curves, which will be the subject of the next article.
Let’s go over the intuition behind them first.
Let’s say you went for a run and your smart watch collected your GPS position. You would like to know your average speed and also your instantaneous speed at some specific point in time.
To compute your speed, you would typically divide the total distance by the time it took.
Computing your instantaneous speed is somewhat similar: you divide the total distance done at that point in time by the time it took.
How long is an instant? Pretty much zero seconds.
How can we divide by zero then?
To go around this problem, let us relax our requirements a little. What if you instead take two points really close to that point in time and you divide the distance by the time?
Imagine that the red curve below describes the distance you covered versus time. (Okay, it’s not strictly increasing but let’s assume it is.) We are interested in your instantaneous speed at .
As mentioned in the previous paragraph, we could take the points at and , compute parameter of the line passing through the corresponding points on the red curve:
and we would obtain an idea of the velocity around this time.
However, we would like to know the velocity at that precise moment when
So let’s move the two points along the red curve closer and closer to the point on the curve where . Compute the slope of the resulting line passing through these two points and you obtain an even more accurate estimate. Eventually, the two points would be so close to the point of interest that the resulting line would only intersect the curve at that point (at least locally).
This is the whole idea behind tangents.
More precisely a tangent to a curve at a point is a line which intersects this curve at exactly that one point locally. The way to compute the equation of the tangent follows exactly that intuition.
If we take to be a small positive number, we can then consider points and and compute the slope of the line passing through them:
Note that if , they are the same points.
But does not make sense in our previous formula as we would otherwise be dividing by zero.
To give you a more concrete example, for the parabola, the previous formula becomes
so that evaluating makes sense and yields
The corresponding line equations looks like
Since the tangent should pass through the point , we obtain:
and thus .
If , we obtain the line equation , which is in blue on this graph. It is tangent to the parabola at point (1,1)
More to a square than meets the 👀
To finish off this article, I will try and convince you that there is more to a square than meets the eyes.
Consider this square. We name the opposite edges respectively 1 and 2 and give them a direction. Let’s imagine our square is made of a very elastic material and that we can deform it freely.
Stick together the two vertical edges, namely edges with label 1. We obtain in this way a tube or hollow cylinder: edges labelled 2 have now become circles.
What if we continued on this path and identified these two circles together?
We indeed obtain a doughnut, or torus.
I will let you ponder on life’s meaning for a few seconds after this amazing realization. (btw, the answer is 42)
But if we made one slight modification to this previous drawing, you would get a very different mathematical object; that’s because we identified corresponding edges with matching direction.
I think it is time for you to get a bit more involved in this. Grab a piece of paper and trim it to be rectangular (it will be easier to fold as paper is not so elastic). Assume that the direction of one of the edges labelled 1 is reversed and try to repeat the construction with the narrow edges of your rectangle labelled as 1. Does it make sense to identify the other two edges? Make sure to post your best pictures of the obtained mathematical object on Twitter using the hashtag #squaresgonerogue.
That’s all folks. Thank you for reading this far. I hope you enjoyed it. If you have any questions or comments, please drop me a line on Twitter. I shall reply as soon as possible.
The content of this article was for the most part presented at the Learning By Doing Meetup in Prague, Czech Republic, on February, 18th, 2019. You can find the slides here.
Stay tuned for the next article in which we’ll explore group theory and elliptic curves.
Personal blog written by Robin Cussol
I like math and I like code. Oh, and writing too.