Understanding BlockDAGs and GHOSTDAG
My WebsiteSupport My Work
  • Welcome!
  • Preface
  • Introduction
  • Part 1: BlockChains and BlockDAGs
    • Introduction
    • Chapter 1: From BFT to PoW
      • Byzantine Fault Tolerance
      • Proof-of-Work (PoW)
      • How PoW Works*
      • PoS Vs. PoW
      • Exercises
    • Chapter 2: the Block Chain Paradigm
      • A Graph Theory Primer
      • The Paradigm
      • Honesty and Rationality
      • Three Chain Selection Rules
      • Security Notions
      • A Security Model for Blockchain Consensus
      • Selfish Mining in Bitcoin
      • Safety
      • Liveness
      • Confirmation Times
      • Proving Bitcoin's Security*
      • Exercises
  • Part 2: The GHOSTDAG Protocol
    • Page 2
  • Supplementary Material
    • Math
      • Stuff You Should Know
        • Asymptotics, Growth, and Decay
        • Binomial Coefficients
        • The Binomial Formula
        • Geometric Sums and Series
      • Probability Theory
        • Probability Spaces
        • Random Variables
        • The Math of Block Creation
    • Computer Science
      • Stuff you Should Know
        • Asymptotic Notation
        • Negligible Functions
      • Cryptography
        • Random Oracles
        • Merkle Trees
        • One Time Pads
Powered by GitBook
On this page
  • Pascal's Triangle
  • Example: High Dimensional Cubes
  1. Supplementary Material
  2. Math
  3. Stuff You Should Know

Binomial Coefficients

How many ways are there to pick five out of seventeen different toppings for your pizza? But it has to be exactly five, because you haven't eaten all day.

Well, you have seventeen ways to choose the first topping, right? And then you have sixteen ways to choose the second topping and so on, until the last topping you choose, for which you have thirteen choices, so it seems that the answer should be 17⋅16⋅…⋅1317\cdot 16\cdot\ldots\cdot 1317⋅16⋅…⋅13, but that's not quite the case.

Why isn't it? Because we overcounted. Say instead of five toppings we didn't choose five, but just two toppings. The first is pepperoni because all pizzas deserve meat, and the second is pineapples because no one is going to tell you what to do! However, what if you ask for the pineapple first and the pepperoni second? Huh? In this case you would get the same pizza, which means we counted pepperoni-pineapple pizza twice, on account of our failure to realize that a pepperoni-pineapple pizza and a pineapple-pepperoni pizza is the same thing.

Fortunately, we counted each kind of pizza the same amount of times. And how much is that? The number of different ways we can any given list of five toppings and shuffle it around.

So how many ways are there to arrange a list of five toppings? Well, we have five ways to choose the first one, four ways to choose the second, you see where this is going. There are 5⋅4⋅3⋅2⋅15\cdot 4 \cdot 3\cdot 2\cdot 15⋅4⋅3⋅2⋅1 ways to shuffle around the list of topping, which means that this is the number of times we counted each possible pizza. The upshot is that there is a total of 17⋅16⋅…⋅135⋅4⋅3⋅2⋅1=6188\frac{17\cdot 16\cdot\ldots\cdot 13}{5\cdot 4 \cdot 3\cdot 2\cdot 1}=61885⋅4⋅3⋅2⋅117⋅16⋅…⋅13​=6188 different pizzas you can put together.

Going abstract we can now consider choosing kkk out of nnn toppings for some 0≤k≤n0\le k\le n0≤k≤n. To do so, we will introduce a nice notation: given a number kkk, the number kkk factorial is denoted and defined as

k!=k⋅…⋅1k! = k\cdot\ldots\cdot 1k!=k⋅…⋅1

So the number of ways to shuffle kkk toppings would be k!k!k!, but what about the number of ways to choose them? Well, as before there are nnn possible ways to choose the first, n−1n-1n−1 possible ways to choose the second, and so on. When we choose the kkkth and final topping, we have already picked k−1k-1k−1 toppings, so there are (n−(k−1))(n-(k-1))(n−(k−1)) choices remaining. How can we write this nicely? We do a trick, and write the total number of combinations with overcounting as:

n⋅(n−1)⋅…⋅(n−(k−1))=n⋅(n−1)⋅…⋅(n−(k−1))(n−k)⋅(n−(k+1))⋅…⋅1(n−k)⋅(n−(k+1))⋅…⋅1=n⋅(n−1)⋅…⋅(n−(k−1))(n−k)⋅(n−(k+1))⋅…⋅1(n−k)⋅(n−(k+1))⋅…⋅1=n!(n−k)!\begin{aligned} & n\cdot\left(n-1\right)\cdot\ldots\cdot\left(n-\left(k-1\right)\right)\\ = & n\cdot\left(n-1\right)\cdot\ldots\cdot\left(n-\left(k-1\right)\right)\frac{\left(n-k\right)\cdot\left(n-\left(k+1\right)\right)\cdot\ldots\cdot1}{\left(n-k\right)\cdot\left(n-\left(k+1\right)\right)\cdot\ldots\cdot1}\\ = & \frac{n\cdot\left(n-1\right)\cdot\ldots\cdot\left(n-\left(k-1\right)\right)\left(n-k\right)\cdot\left(n-\left(k+1\right)\right)\cdot\ldots\cdot1}{\left(n-k\right)\cdot\left(n-\left(k+1\right)\right)\cdot\ldots\cdot1}\\ = & \frac{n!}{(n-k)!} \end{aligned} ===​n⋅(n−1)⋅…⋅(n−(k−1))n⋅(n−1)⋅…⋅(n−(k−1))(n−k)⋅(n−(k+1))⋅…⋅1(n−k)⋅(n−(k+1))⋅…⋅1​(n−k)⋅(n−(k+1))⋅…⋅1n⋅(n−1)⋅…⋅(n−(k−1))(n−k)⋅(n−(k+1))⋅…⋅1​(n−k)!n!​​

and now we just divide out the overcounting to get that the number of ways to choose kkk out of nnn toppings is n!k!(n−k)!\frac{n!}{k!\left(n-k\right)!}k!(n−k)!n!​.

This expression is so useful that it has a name and a notation, it is denoted (nk){n \choose k}(kn​) which is pronounced "nnn choose kkk". These numbers, are also called the binomial coefficients.

Note that this expression has a nice symmetry to it between kkk and n−kn-kn−k, and that makes sense because choosing kkk toppings to put on your pizza is exactly the same as choosing n−kn-kn−k topping not to put on your pizza. An observation easily stated and verified as the equation (nk)=(nn−k){n \choose k} = {n \choose n-k}(kn​)=(n−kn​).

Exercise: Show that if 0≤k≤r≤n0\le k \le r \le n0≤k≤r≤n then (nr)⋅(rk)=(nk)⋅(n−kr−k){n \choose r} \cdot {r \choose k} = {n \choose k} \cdot {n - k \choose r - k}(rn​)⋅(kr​)=(kn​)⋅(r−kn−k​). Hint: you don't really need math to solve this, you just need to tell yourself the right story.

Binomial coefficients come up everywhere, and have very nice properties to them.

Pascal's Triangle

There is actually a really cool way to represent the binomial coefficients called Pascal's triangle. To draw the triangle, follow these rules. First, write the number 111 at the middle of the top line of the paper, and then write it again twice, like so:

In the next line we write three numbers. The first and last would be 111, and the middle number will be the sum of two numbers above it:

We can keep going, following this pattern, the next few lines will look like this:

What does this have to do with everything? Well, remarkably, if we number the lines, starting with zero, then the kkkth number if the nnnth line is exactly (nk){n \choose k}(kn​).

Exercise: Assuming that Pascal's triangle satisfy this property, prove that for any n,kn,kn,k it holds that (nk)=(n−1k)+(n−1k−1){n \choose k} = {n-1 \choose k} + {n-1 \choose k-1}(kn​)=(kn−1​)+(k−1n−1​).

Example: High Dimensional Cubes

A three dimensional cube has eight vertices (corners), twelve edges, and six faces. In mathematese, we call these all faces. The vertices are just points, so they are the zero dimensional faces, the edges are one-dimensional lines, so we call them the one-dimensional faces, and what we used to call faces we will now call two-dimensional faces. Following this logic, a cube has a single three-dimensional face: the cube itself.

In this terminology, a two-dimensional cube is just a square. It has four zero-dimensional faces, four one-dimensional faces, and one two-dimentsonal face. Cool? Cool.

So how many eight-dimensional faces does a seventeen-dimensional cube have? Turns out we can compute this using binomial coefficients! We will actually find a formula for the number of kkk-dimensional edges in an nnn-dimensional cube for all k≤nk\le nk≤n!

To do this, we will need a better way to encode what "a cube" and "a face" is, one that can easily encode the information we need without forcing us to imagine shapes in more than three dimensions.

Consider a three dimensional cube. Each corner can be represented by three numbers, each being either 0 or 1. The first number represents if we are "left or right", the second if we are "back or front", and the third if we are "up or down".

This allows us to comfortably encode the corners. Note that two corners are connected if and only iff they differ in exactly one coordinate. So this gives as an indication of what a one-dimensional face, and edge, looks like: two coordinates are locked, and we are only allowed to move in the third. The "free coordinate" tells us where we can move along the edge. For example, a "back to front" edge will have the second coordinate free, since this coordinate represents "back to front":

Considering the corners of the marked edge we see that in both of them the first coordinate is 111 to indicate that the edge is on the right, and the third coordinate is 000 to indicate that the edge is on the bottom, but the second coordinate varies between them, to indicate that the edge goes "from back to front", namely, one of it's vertices, (1,0,0)(1,0,0)(1,0,0), is in the front while the other (1,1,0)(1,1,0)(1,1,0) is in the back.

We can do the same for edges:

Here we see that only one coordinate is fixed. The third coordinate is set to 111 in all edges, indicating that the edge is on top. Other than that, all coordinates can be set either way. It makes sense that a two dimensional shape, like the face of a cube, will have two degrees of freedom. Even without knowing exactly what two-dimensional means formally, it makes sense that a two dimensional shape would have exactly two directions to move around.

Note that the three dimensional cube drawn above has exactly eight corners, corresponding to the eight different strings of three bits. This is the property we extend to higher dimension. When thinking of an nnn-dimensional cube, we just think of all sequences of bits (zeros and ones) of length nnn. We think of each coordinate as "a direction" (though unfortunately, in more than three dimensions these directions don't have common names like "width", "depth" and "height", so we just call them "the first coordinate", "the second coordinate", etc.), and of its value as either being "close" or "far" in that direction from the point (0,…,0)(0,\ldots,0)(0,…,0).

So how would we define a kkk-dimensional face of this nnn-dimensional hypercube? Well, we said that a kkk-dimensional face must have kkk free dimensions. The way to form such a face is hence to choose the kkk free directions and fix the remaining coordinates. For example, when we consider all the possible one-dimensional faces (edges) of a two-dimensional cube (square), we choose one free dimension, and fix the other dimension. Say we choose the free dimension to be the first one, and fix the second dimension to 000, then we get the two corners (0,0)(0,0)(0,0) and (1,0)(1,0)(1,0) corresponding to the left edge:

There are two ways to choose the free direction (either first coordinate or second coordinate), and then two possible values to fix in the remaining direction (either 000 or 111), so in total we have 2â‹…2=42\cdot 2 = 42â‹…2=4 options, which checks out as a square indeed has four edges!

Extending this logic, when considering a kkk-dimensional face of an nnn-dimensional cube, we first choose the kkk free coordinates. There are of course (nk){n \choose k}(kn​) ways to do so. We then fix the remaining n−kn-kn−k coordinates. We set each of them to either 000 or 111, so there is a total of 2n−k2^{n-k}2n−k ways to fix the coordinates. We have proved:

Theorem: an nnn-dimensional cube has exactly 2n−k⋅(nk)2^{n-k}\cdot{n \choose k}2n−k⋅(kn​) kkk-dimensional edges.

So for example, for the cube we have n=3n=3n=3, and indeed the number of k=2k=2k=2-dimensional faces is exactly 23−2⋅(32)=2⋅3=62^{3-2}\cdot {3 \choose 2} = 2\cdot 3 = 623−2⋅(23​)=2⋅3=6, and the number of k=1k=1k=1-dimensional faces is exactly 23−1⋅(31)=22⋅3=122^{3-1}\cdot {3 \choose 1} = 2^2 \cdot 3 = 1223−1⋅(13​)=22⋅3=12. And as for the question above? In a seventeen-dimensional cube, the number of eight dimensional edges is 217−8⋅(178)=12,446,7202^{17-8}\cdot {17 \choose 8} = 12,446,720217−8⋅(817​)=12,446,720.

Exercise: Prove that the number of kkk-dimensional faces of an nnn dimensional cube is θ(2n−k⋅nk)\theta\left(2^{n-k}\cdot n^k\right)θ(2n−k⋅nk)

Another way to interpret the discussion above is that there are (nk){n \choose k}(kn​) ways to choose an orientation for a kkk-dimensional side of an $n$-cube, and given an orientation, there are 2n−k2^{n-k}2n−k possible positions/shifts for the same orientation.

PreviousAsymptotics, Growth, and DecayNextThe Binomial Formula

Last updated 2 months ago