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

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 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.

French defense opening French defense opening

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:

E2-E4
E7-E6

meaning the piece at location E2E2 moves to E4E4, and the other piece at E7E7 moves to E6E6.

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. E3E3, and we can forget about up-up-right or right-up-up to mean the same move as E3E3 to C4C4.

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.

Cartesian coordinate system Cartesian coordinate system

The horizontal axis is commonly called the xx-axis and the vertical axis the yy-axis. The points will be labelled under the form (x,y)(x, y), just like before we had E3 to mean (E,3)(E, 3); xx is the horizontal coordinate and yy is the vertical coordinate. In our case, xx and yy can be any number, like 1,3,5,1, -3, 5, but also like 2/32/3, 17\sqrt{17}, π\pi, ee. Of course, there are other ways to represent a point:

Polar coordinate system The blue point has polar coordinates (r,θ)=(2,60°)(r, \theta) = (2,60°) and Cartesian coordinates (x,y)=(1,3)(x,y) = (1,\sqrt{3} )

We will however stick to (x,y)(x, y) 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.

picture of a straight line This is not a line, René Magritte

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:

(AB)={(x,y)R×R(x,y)=(xA,yA) OR (x,y)=(xB,yB) OR ...}(1)\tag{1} (AB) = \{ (x,y) \in \mathbb{R} \times \mathbb{R} | (x, y)=(x_A ,y_A) \text{ OR } (x, y)=(x_B, y_B) \text{ OR } ...\}

Let’s go through these notations:

  • (AB)(AB): the line passing through points A and B;
  • { things  properties}\{ \text{ things } | \text{ properties} \}: the set of things with these properties;
  • R×R\mathbb{R} \times \mathbb{R}: all the pairs of (real) numbers;

So mathematical expression (1)(1) above means: the line passing through points AA and BB is the set of points (x,y)(x,y) such that (x,y)(x,y) is point AA or (x,y)(x,y) is point BB, 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 (xA,yA)(x_A, y_A) is related to (xB,yB)(x_B, y_B) in some way. Algebra will help us understand that relationship more precisely.

Algebraically, a line is indeed an equation:

y=ax+by=ax+b

which expresses the value of yy depending on the value of xx, given parameters aa and bb. Parameter aa is called the slope and parameter bb is called yy at the origin.

Let’s have a look at a few examples to understand better what aa and bb mean.

Graph y=3 Graph y=3y=3

On the line y=3y = 3, since it is not depending on xx we have a=0a = 0, and so bb must be 33. We obtain that not depending on xx means yy has a constant value and this translates into a horizontal line geometrically.

Graph y=x+3 Graph y=x+3y=x+3

On the line y=x+3y=x+3, we have a=1a=1 and b=3b=3. We can see that the point with coordinates (0,3)(0,3) is also being passed through.

Specifying bb is the same as saying that the line must pass through the point with coordinates (0,b)(0,b).

(That’s incidentally why bb is called y at the origin.)

Graph y=2x Graph y=2xy=2x

Finally, on the line y=2xy=2x, we can see the line passes through (0,0)(0,0), which means b=0b=0, and we also have a=2a=2. Note that the slope of the line is steeper than the line y=x+3y=x+3.

Joining algebra and geometry, we can write that a line is a set of points (x,y)(x,y) satisfying the equation y=ax+by=ax + b. Going back to the idea that there is a line passing through any two points, we can rephrase it by saying: there are numbers aa and bb such that yA=axA+by_A = ax_A + b and yB=axB+by_B = ax_B+b, for any two points A(xA,yA)A(x_A, y_A) and B(xB,yB)B(x_B,y_B). The following equations must be true simultaneously

{yA=axA+byB=axB+b\begin{cases} y_A = ax_A + b \\ y_B = ax_B + b \end{cases}

which we could rewrite

{b=yAaxAb=yBaxB\begin{cases} b = y_A - ax_A\\ b = y_B - ax_B \end{cases}

which means in particular

yAaxA=yBaxBaxBaxA=yByAa(xBxA)=yByA\begin{aligned} y_A - ax_A &= y_B - ax_B \\ ax_B - ax_A &= y_B - y_A \\ a(x_B - x_A) &= y_B - y_A \end{aligned}

so that finally

a=yByAxBxAa = \frac{y_B - y_A}{x_B - x_A}

Now that we know aa, we can find bb:

b=yAaxA=yAyByAxBxAxA=yA(xBxA)xA(yByA)xBxA=yAxBxAyBxBxA\begin{aligned} b &= y_A - ax_A \\ \\ &= y_A - \frac{y_B - y_A}{x_B - x_A}x_A \\ &= \frac{y_A(x_B - x_A) - x_A(y_B - y_A)}{x_B - x_A} \\ &= \frac{y_Ax_B - x_Ay_B}{x_B - x_A} \\ \end{aligned}

To summarise, we found:

a=yByAxBxA and b=yAxBxAyBxBxAa = \frac{y_B - y_A}{x_B - x_A} \text{ and } b= \frac{y_Ax_B - x_Ay_B}{x_B - x_A}

Let us use these formulae to obtain the equation for the line passing through points A(0,3)A(0,3) and B(5,8)B(5,8):

a=yByAxBxA, and b=yAxBxAyBxBxA=8350=3×50×850\begin{alignedat}{2} a &= \frac{y_B - y_A}{x_B - x_A} \text{, and } &b = \frac{y_Ax_B - x_Ay_B}{x_B - x_A} \\ &= \frac{8 - 3}{5 - 0} &= \frac{3\times 5 - 0 \times 8}{5 - 0} \end{alignedat}

and thus a=55=1a= \frac{5}{5} = 1 and b=155=3b= \frac{15}{5} = 3.

The line passing through A(0,3)A(0,3) and B(5,8)B(5,8) has equation

y=x+3y = x + 3

Looks familiar?


Before moving on to curvy lines, let us understand why aa is called the slope.

Slope of a line passing through A and B

From the equation we obtained for number aa, we can visually identify the quantities xBxAx_B-x_A and yByAy_B - y_A:

  • xBxAx_B-x_A corresponds to the distance along the xx-axis to go from AA to BB, and
  • yByAy_B-y_A corresponds to the distance along the yy-axis to go from AA to BB;

In some sense, aa measures how much yy grows/shrinks as xx grows, and it could be expressed in percents like on road signs.

Photo by WikimediaImages on Pixabay

A slope a=0.1a = -0.1, Photo by WikimediaImages on Pixabay

Curvy lines

Rewriting once again our representation of a line as

{(x,y)R2y=f(x)},\{ (x,y) \in \mathbb{R}^2 | y = f(x) \},

with f(x)=ax+bf(x) = a x + b, we see that we are using a very specific function of xx. We could change it to

f(x)=x2f(x) = x^2

and obtain the set {(x,y)R2y=x2}\{ (x,y) \in \mathbb{R}^2 | y = x^2 \}. This set corresponds to the parabola:

The parabola The parabola, aka y=x2y=x^2

To generalise further, we could write y=x2y = x^2 as yx2=0y - x^2 = 0. That means we can consider functions of xx and yy to describe other sets of points:

{(x,y)R2f(x,y)=0}.\{ (x,y) \in \mathbb{R}^2 | f(x,y) = 0 \}.

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 rr, called the radius, of another point CC, called the centre of the circle.

Taking the centre to be C(0,0)C(0,0) and the radius rr to be 1, f(x,y)f(x,y) can then be expressed as

f(x,y)=x2+y21f(x,y) = x^2 + y^2 -1

This form of expressing sets of points will be useful when talking about elliptic curves in the next article.

(Spoiler alert: f(x,y)=y2x37f(x,y)= y^2-x^3-7 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.

velocity=distancetimevelocity = \frac{distance}{time}

Computing your instantaneous speed is somewhat similar: you divide the total distance done at that point in time by the time it took.

Oh wait.

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 t=0.7st=0.7s.

Graph showing different approximations of instantaneous velocity at t=0.7s

As mentioned in the previous paragraph, we could take the points at t0=0.6st_0 = 0.6s and t1=0.8st_1 = 0.8s, compute parameter aa of the line passing through the corresponding points on the red curve:

a=d1d0t1t0a = \frac{d_1-d_0}{t_1-t_0}

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 t=0.7s.t=0.7s.

So let’s move the two points along the red curve closer and closer to the point on the curve where t=0.7st=0.7s. 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 ϵ>0\epsilon > 0 to be a small positive number, we can then consider points (x0,f(x0))(x_0, f(x_0)) and (x0+ϵ,f(x0+ϵ))(x_0+\epsilon, f(x_0+\epsilon)) and compute the slope of the line passing through them:

a=f(x0+ϵ)f(x0)(x0+ϵ)x0=f(x0+ϵ)f(x0)ϵϵ=0a = \left. \frac{f(x_0+\epsilon) - f(x_0)}{(x_0+\epsilon) -x_0} = \frac{f(x_0+\epsilon) - f(x_0)}{\epsilon} \right|_{\epsilon = 0}

Note that if ϵ=0\epsilon=0, they are the same points.

But ϵ=0\epsilon=0 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

a=(x0+ϵ)2x02ϵ=(x02+2x0ϵ+ϵ2)x02ϵ=2x0ϵ+ϵ2ϵ=2x0+ϵa = \frac{(x_0+\epsilon)^2 - x_0^2}{\epsilon} = \frac{(x_0^2 + 2x_0\epsilon + \epsilon^2) - x_0^2}{\epsilon} = \frac{2x_0\epsilon + \epsilon^2}{\epsilon} = 2x_0 + \epsilon

so that evaluating ϵ=0\epsilon=0 makes sense and yields

a=2x0a = 2x_0

The corresponding line equations looks like

y=(2x0)x+by =(2x_0)x +b

Since the tangent should pass through the point (x0,f(x0))(x_0, f(x_0)), we obtain:

x02=2(x0)×x0+bx_0^2 = 2(x_0)\times x_0 + b

and thus b=x02b = -x_0^2.

Tangent at (1,1) to the parabola with equation y=2x-1

If x0=1x_0=1, we obtain the line equation y=2x1y=2x-1, 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.

. The construction of a torus from the unit square.

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.


Robin Cussol

Personal blog written by Robin Cussol
I like math and I like code. Oh, and writing too.