Showing posts with label Binomial. Show all posts
Showing posts with label Binomial. Show all posts

Friday, 6 June 2025

Binomial Number System

I made a post titled Encoding Secret Numbers only recently on the 8th of May 2025 in which I looked at how the Heinz number and Gray Code could be used to encrypt a number. An article I read today suggested another encryption method that is more arcane than the two previously mentioned. The article states that every non-negative integer n can be written as:$$ \binom{a}{1} + \binom{b}{2} + \binom{c}{3} \text{ where } a \leq b < c $$The article goes on to say that:

You can find \(a\), \(b\) and \(c\) much as you would find the representation in many other number systems: first find the largest possible \(c\), then the largest possible \(b \) for what’s left, and then the remainder is \(a\). 
In order to find \(c\), we start with the observation that the binomial coefficient C(\(k\), 3) is less than \(k^3\)/6 and so \(c\) is less than the cube root of \(6n\). We can use this as an initial lower bound on \(c\) then search incrementally. If we wanted to be more efficient, we could do some sort of binary search.

Figure 1 shows the Python code to find \(a\), \(b\) and \(c\):


Figure 1: permalink

In the article the term \( \textbf{binomial number system} \) is used to describe this approach. Applying the code to the number associated with my diurnal age today (27823) we find that \(a=12\), \(b=14\) and \(c=56\) so that:$$27823= \binom{12}{1} + \binom{14}{2} + \binom{56}{3} $$This encrypted version of 27823 could be represented as 12. 14. 56 with the dots being added to prevent possible ambiguity although commas or dashes or whatever could be used as well. The encrypted number has the same number of digits as the number being encrypted.

Unless someone knew about this "binomial number system" it would be impossible to guess what number was being encrypted. Once the binomial "key" is applied however, we find that:$$12. \,14. \, \,56 \rightarrow 12 + 91 + 27720 = 27823$$What about the number 1? Well, in that case, we \(a=b=0\) and \(c=3\) because:$$1=\binom{0}{1}+\binom{0}{2}+\binom{3}{3} \rightarrow 0. \, 0. \, 3$$What about the number 2. In this case we have \(a=0\), \(b=2\) and \(c=3\) so that:$$2=\binom{0}{1}+\binom{2}{2}+\binom{3}{3} \rightarrow 0. \, 2. \, 3$$Of course for the number 3 we have \(a=1\), \(b=2\) and \(c=3\) so that:$$3=\binom{1}{1}+\binom{2}{2}+\binom{3}{3} \rightarrow 1. \, 2. \, 3$$Interestingly, the final comment that the author of the referenced article makes is that "you could use any number of binomial terms, not just three". One binomial term C(\(a\), 1) just corresponds to the positive integers since:$$ \binom{a}{1}=a$$Two binomial terms work as well of course. For example:$$\binom{2}{1}+\binom{5}{2}=2+10 =12$$Notice that this representation of 12 (and any other number) is unique because even though:$$ \binom{6}{1}+\binom{4}{3}=6 + 6=12$$this representation contravenes the rule that \(a \leq b\) since \(a=6\) and \(b=4\). All very interesting.

27823: An Egg Drop Number

Back on the 7th of May 2021, I made a post titled The Egg Drop Numbers in which I remarked:

On June 6th, 2025 (the anniversary of D-Day by the way), I will enjoy the next egg drop number, \( \textbf{27823} \), which is the maximum number of floors for which someone, armed with 9 eggs, will be able to determine the critical floor with at most 15 trials.

Today is that day and so here is a post regarding the number created using Gemini 2.5 Pro and the following prompt:

Can you explain the mathematics behind the following statement: "the egg drop number, \( \textbf{27823} \), is the maximum number of floors for which someone, armed with 9 eggs, will be able to determine the critical floor with at most 15 trials." This has to do the famous egg breaking problem but can your explanation focus specifically on the \( \textbf{27823}\).

Here is Gemini's response: 

\( \textbf{The Mathematics of the Egg Dropping Puzzle: The Case of 27,823} \)

The solution to the famous egg dropping puzzle, when determining the maximum number of floors that can be tested, can be found using combinatorial mathematics, specifically with binomial coefficients.

\( \textbf{The General Formula} \)

The maximum number of floors, $N$, that can be determined with a given number of eggs, $e$, and a maximum number of trials, $t$, is given by the following summation:$$N(e, t) = \sum_{i=1}^{e} \binom{t}{i}$$In this formula, the term $\binom{t}{i}$ represents the binomial coefficient "t choose i", which calculates the number of unique ways to choose $i$ items from a larger set of $t$ items. The formula for the binomial coefficient is:$$\binom{t}{i} = \frac{t!}{i!(t-i)!}$$Each term in the summation represents the number of possible outcomes for a given number of egg breaks within the allowed trials.

\( \textbf{Calculating for 9 Eggs and 15 Trials} \)

We are given the specific parameters:

  • Number of eggs, \(e = 9\)
  • Maximum number of trials, \(t = 15\)

Substituting these values into the general formula, we get:

$$N(9, 15) = \sum_{i=1}^{9} \binom{15}{i}$$This expands to the following sum:$$ \begin{align} N(9, 15) = &\binom{15}{1} + \binom{15}{2} + \binom{15}{3} + \binom{15}{4} + \binom{15}{5} + \\ &\binom{15}{6} + \binom{15}{7} + \binom{15}{8} + \binom{15}{9} \end{align}$$Next, we calculate the value of each individual binomial coefficient:

  • \( \displaystyle \binom{15}{1} =   15\)
  • \( \displaystyle \binom{15}{2} = \frac{15!}{2! \,13!} = 105\)
  • \( \displaystyle \binom{15}{3} = \frac{15!}{3! \, 12!} = 455\)
  •  \( \displaystyle \binom{15}{4} = \frac{15!}{4! \, 11!} = 1,365\)
  • \( \displaystyle \binom{15}{5} = \frac{15!}{5! \, 10!} = 3,003\)
  • \( \displaystyle \binom{15}{6} = \frac{15!}{6! \, 9!} = 5,005\)
  • \( \displaystyle \binom{15}{7} = \frac{15!}{7! \, 8!} = 6,435\)
  • \( \displaystyle \binom{15}{8} = \frac{15!}{8! \, 7!} = 6,435\)
  •  \( \displaystyle \binom{15}{9} = \frac{15!}{9! \, 6!} = 5,005\)

Finally, we sum these values to find the total number of floors:$$ 15 + 105 + 455 + 1,365 + 3,003 + 5,005 + 6,435 + 6,435 + 5,005 = 27,823$$Thus, the maximum number of floors for which one can determine the critical floor with 9 eggs and at most 15 trials is precisely \( \textbf{27,823} \).

Thursday, 18 July 2024

Binomial Expansion Using Modular Arithmetic

 1

1    1

1    2    1

1    3    3    1

1    4    6    4    1

1    5    10    10    5    1

1    6    15    20    15    6    1

1    7    21    35    35    21    7    1

Above we see the beginning of Pascal's Triangle, that is of great assistance is working out the coefficients of the terms in the binomial expansion of \( (a+b)^n \) for various positive integer values of \(n\). The first line corresponds to \(n=0\), then \(n=1\), \(n=2\) and so on. For example:$$(a+b)^4=a^4+4a^3b+6a^2b^2+4ab^3+b^4$$A common mistake that's made by beginner's is to write the following:$$(a+b)^n=a^n+b^n$$What is regarded as a mistake actually turns out to true for certain values of \(n\) when modular arithmetic is involved.

Let's consider mod 2 where only two numbers exist: 0 and 1. Any numbers larger than 1 reduce to either 0 or 1. Thus \(2 \equiv 0 \, mod \, 2\) and \(3 \equiv 1 \, mod \, 2\) etc. Let's look at the expansion of \( (a+b)^2 \) in this light. We have:$$ \begin{align} (a+b)^2 &=a^2+2ab+b^2\\ &=a^2+b^2 \end{align}$$In the case of mod 2, the \(2ab\) term must equal zero What about mod 3? The only numbers here are 0, 1 and 2 with \(3 \equiv 0 \,mod \,3 \). The binomial expansion for the case of \(n=3\) becomes:$$ \begin{align} (a+b)^3 &=a^3+3a^3b+3ab^2+b^3\\ &=a^3+b^3 \end{align}$$Here the \(3a^2b\) and \(3ab^2\) terms equal zero. We seem to on a roll. Let's consider the case of \(n=4\) or mod 4. Here the only numbers are 0, 1, 2 and 3 with \(4 \equiv 0 \, mod \, 4\), \(5 \equiv 1 \, mod \, 4\), \(6 \equiv 2 \, mod \, 4\) and so on. Thus we have:$$ \begin{align} (a+b)^4 &= a^4 + 4a^3b+6a^2b^2+4ab^3+b^4\\ &=a^4 + 2a^2b^2+b^4 \end{align}$$In this case, things don't quite work out because the middle term \(6a^2b^2\) after conversion to \(2a^2b^2\).

What about the case of \(n=5\) or mod 5? Here the numbers are 0, 1, 2, 3 and 4 and the expansion of \( (a+b)^5\) works out as follows:$$ \begin{align} (a+b)^5 &= a^5 + 5a^4b + 10a^3b^2+10a^2b^3+5ab^4+b^5 \\ &=a^5+b^5 \end{align}$$The central terms all disappear because \(5 \equiv 0 \, mod \,5\) and \(10 \equiv 0 \, mod \, 5\). If we consider the case of mod 6, the simplification fails but works again for mod 7. The generalisation from all of this is that if \(p\) is prime and we are working with mod \(p\) then the following always holds true:$$(a+b)^p=a^p+b^p$$I'm thankful to this YouTube video for informing me of this interesting twist on the binomial expansion.

Thursday, 23 March 2023

Motzkin Numbers

I recently came upon a class of numbers known as Motzkin numbers. They are defined as follows:

In mathematics, the n-th Motzkin number is the number of different ways of drawing non-intersecting chords between n points on a circle. Source.

Figures 1 and 2 are illustrations showing two of the numbers (9 and 21) using the same source:

Figure 1: there are 9 ways to draw non-intersecting chords
between 4 points on a circle (M(4)= 9)

Figure 2: there are 21 ways to draw non-intersecting chords
between 5 points on a circle (M(5) = 21)

The Motzkin numbers satisfy the following recurrence relation:$$M_n = \frac{2n+1}{n+2} M_{n-1}+\frac{3n-3}{n+2} M_{n-2}$$The Motzkin numbers can be expressed in terms of binomial coefficients and Catalan numbers:$$M_n=\sum_{k=0}^{\lfloor n/2 \rfloor} \binom{n}{2k} C_k\\ C_{n+1}=\sum_{k=0}^n \binom{n}{k} M_k$$The generating function for the Motzkin numbers is given by:$$ \frac{1-x-\sqrt{1-2x-3x^2} }{2x^2}$$I asked ChatGPT about them.

Q: Can you explain what Motzkin numbers are and give some simple examples of their usefulness.

A: Motzkin numbers, named after the mathematician Theodor Motzkin, are a sequence of numbers that count the number of ways to draw non-intersecting chords between n points on a circle. They are denoted by M(n).

The first few Motzkin numbers are:

M(0) = 1, M(1) = 1, M(2) = 2, M(3) = 4, M(4) = 9, M(5) = 21, M(6) = 51, M(7) = 127, M(8) = 323, M(9) = 835, M(10) = 2188

Motzkin numbers have a variety of applications in combinatorics, algebraic geometry, and physics. Here are some simple examples of their usefulness:

  • Counting lattice paths: A lattice path is a path on a grid of integer points. The number of lattice paths from (0, 0) to (n, k) that only move up, down, or diagonally up and to the right, and never below the x-axis, is given by the Motzkin number M(k). 

  • Counting RNA structures: RNA is a molecule that plays a key role in protein synthesis. The number of possible secondary structures for an RNA molecule of length n is given by the Motzkin number M(n -1). 

  • Counting balanced chemical reactions: The number of balanced chemical reactions involving n molecules is given by the Motzkin number M(n -1). This can be useful in chemistry and chemical engineering. 

  • Counting irreducible algebraic curves: An irreducible algebraic curve is a curve that cannot be expressed as the union of two smaller curves. The number of irreducible algebraic curves of degree n in projective space is given by the Motzkin number M(n -1). 

  • Counting diagrams in knot theory: Knot theory is the study of mathematical knots. The number of diagrams that represent a knot with n crossings is given by the Motzkin number M(n -2).

These are just a few examples of the many applications of Motzkin numbers in various fields of mathematics and science.

The Motzkin numbers constitute OEIS A001006:


 A001006

Motzkin
 numbers: number of ways of drawing any number of non-intersecting chords joining \(n\) (labeled) points on a circle.



The first few members, up to one million, are:

1, 1, 2, 4, 9, 21, 51, 127, 323, 835, 2188, 5798, 15511, 41835, 113634, 310572, 853467

The problem from the perspective of my diurnal age is that the last member occurred when I was 15511 days old and the next will occur if I were to reach 41835 days old, which is highly unlikely. I'm currently 27017 days old and a few days away from my 74th birthday. However, if reflections and rotations are allowed since, returning to Figures 1 and 2, the number 9 becomes 4 and the number 21 becomes 5. These are noticeably smaller.

These unlabeled Motzkin numbers constitute OEIS A175954:


 A175954

Unlabeled (cyclic) Motzkin numbers: number of ways of drawing any number of nonintersecting chords joining n unlabeled points equally spaced on a circle, up to rotations of the circle.


The initial members, up to one million, are:

1, 1, 2, 2, 4, 5, 12, 19, 46, 95, 230, 528, 1320, 3219, 8172, 20714, 53478, 138635, 363486, 957858

However, these numbers again miss my possible forthcoming diurnal ages as there is a jump from 20714 to 53478. Ah well.

Monday, 8 February 2021

Cunningham Numbers

I've come across Cunningham Chains before and written about them in several posts. However, I've not written about Cunningham Numbers before. These numbers always occur in pairs and the previous such pair was 25920 and 25922 that can be represented as \(161^2-1\) and \(161^2+1\) respectively. Today I turned 26243 days old and this is equal to \(162^2-1\) and the other member of the pair is 26245 equal to \(162^2+1\). So what defines such numbers. 

Here is a definition: Cunningham numbers are a simple type of binomial number, they are of the form$$b^n\pm1 \text{ where }b \text{ and } n \text{ are integers and }\\b \text{ is not a perfect power. They are denoted by }C^±(b,n)$$

Establishing whether or not a given Cunningham number is prime has been the main focus of research around this type of number. Two particularly famous families of Cunningham numbers in this respect are the Fermat numbers, which are those of the form \(C^+(2,2m) \), and the Mersenne numbers, which are of the form \( C^−(2,n) \).

Primes of the form \(C^±(b,n)\) are very rare. To quote from WolframAlphaMathWorld:

A necessary (but not sufficient) condition for \( C^+(2,n)=2^n+1\) to be prime is that \(n\) be of the form \(n=2^m\). Numbers of the form \(F_m=C^+(2,2^m)=2^{2^m}+1\) are called Fermat numbers, and the only known primes occur for:

  • \(C^+(2,1)=3\)
  • \(C^+(2,2)=5\) 
  • \(C^+(2,4)=17\) 
  • \(C^+(2,8)=257\)
  • \(C^+(2,16)=65537\)

In other words for \(m=0, 1, 2, 3, 4 \). The only other primes \(C^+(b, n)\) for nontrivial \(b \leq 11\) and \(2 \leq n\leq 1000\) are:

  • \(C^+(6,2)=37\) 
  • \(C^+(6,4)=1297\) 
  • \(C^+(10,2)=101\) 

\(C^+(2,n)=2^n+1\) is always divisible by 3 when \(n\) is odd. The Mersenne numbers \(M_n=C^-(2,n)=2^{n}-1\) are known to be prime only for 44 values, the first few of which are \(n=2, 3, 5, 7, 13, 17, 19, ... \) (OEIS A000043). Such numbers are known as Mersenne primes. There are no other primes \(C^-(b,n)\) for nontrivial \(b \leq 20\) and \(2\leq n\leq 1000\).

If primes are rare amongst the Cunningham numbers, then most are composite and thus factorable which leads us into the Cunningham Project:

The Cunningham project is a project, started in 1925, to factor numbers of the form \(b^n ± 1\) for \(b\) = 2, 3, 5, 6, 7, 10, 11, 12 and large \(n\). The project is named after Allan Joseph Champneys Cunningham, who published the first version of the table together with Herbert J. Woodall. There are three printed versions of the table, the most recent published in 2002, as well as an online version.

Figure 1 shows the current limits of the exponents:

Figure 1
Two types of factors can be derived from a Cunningham number without having to use a factorisation algorithm: algebraic factors, which depend on the exponent, and Aurifeuillian factors, which depend on both the base and the exponent.
Perhaps, I'll explore the topic of factorisation of Cunningham numbers in more detail at a later date. For the moment, it can be noted that:

Once the algebraic and Aurifeuillian factors are removed, the other factors of \(b^n ± 1\) are always of the form \(2kn + 1\), since they are all factors of \(\displaystyle \Phi _{n}(b) \). 
When \(n\) is prime, both algebraic and Aurifeuillian factors are not possible, except the trivial factors \(b − 1\) for \(b^n − 1\) and \(b + 1\) for \(b^n + 1\).
In general, all factors of $$ \frac{b^n − 1}{b − 1}$$ are of the form \(2kn + 1\), where \(b ≥ 2\) and \(n\) is prime, except when \(n\) divides \(b − 1\), in which case $$ \frac{b^n − 1}{b − 1}$$ is divisible by \(n\) itself.

Of course, for the pairs of Cunningham numbers mentioned earlier ((25920, 25922) and (26243, 26245)), the value of \(n\) is 2 and hence prime. This means that there are no algebraic or Aurifeuillian factors, only the trivial factors and factors to the form \(4k+1\). The factorisations are:

  • \(25920 =161^2-1=160 \times 162=2^6 \times 3^4 \times 5\) 
  • \(25922 =161^2+1=2 \times 13 \times 997\) 
  • \(26243 = 162^2-1=161 \times 163=7 \times 23 \times 163 \)
  • \(26245 = 162^2+1=5 \times 29 \times 181\)

Thursday, 22 August 2019

Binomial Transforms

My diurnal age today was 25706 and one of the properties of this number, as listed in the Online Encyclopaedia of Integer Sequences (OEIS), is that it belongs to OEIS A101509:  binomial transform of tau(n) (see A000005). Now \( \tau (n) \) is the divisor function and returns the number of divisors for any given number \(n\). OEIS A000005 gives the members of this sequence, beginning with \(n=1\):
1, 2, 2, 3, 2, 4, 2, 4, 3, 4, 2, 6, 2, 4, 4, 5, 2, 6, 2, 6, 4, 4, 2, 8, 3, 4, 4, 6, 2, 8, 2, 6, 4, 4, 4, 9, 2, 4, 4, 8, 2, 8, 2, 6, 6, 4, 2, 10, 3, 6, 4, 6, 2, 8, 4, 8, 4, 4, 2, 12, 2, 4, 6, 7, 4, 8, 2, 6, 4, 8, 2, 12, 2, 4, 6, 6, 4, 8, 2, 10, 5, 4, 2, 12, 4, 4, 4, 8, 2, 12, 4, 6, 4, 4, 4, 12, 2, 6, 6, 9, 2, 8, 2, 8, ...
The binomial transform when applied to OEIS A000005 produces OEIS A101509:
1, 3, 7, 16, 35, 75, 159, 334, 696, 1442, 2976, 6123, 12562, 25706, 52492, 107014, 217877, 443061, 899957, 1826078, 3701783, 7498261, 15178255, 30706320, 62085915, 125465715, 253415981, 511608490, 1032427637, 2082680887, 4199956101, 8467124805, 17064784905, 34382825363, 69256687719, 139465867773, ...
As can be seen, the terms of the second sequence get large fairly quickly as each term in the first sequence is mapped an increasingly larger term in the second. In particular, the 13th term (2) in the first gets mapped to 25706 in the second. But what is a binomial transform?

To quote from Wikipedia:
In combinatorics, the binomial transform is a sequence transformation (i.e., a transform of a sequence) that computes its forward differences. It is closely related to the Euler transform, which is the result of applying the binomial transform to the sequence associated with its ordinary generating function.

The binomial transform, \(T\), of a sequence, {\(a_n\)}, is the sequence {\(s_n\)} defined by:$$s_n = \sum_{k=0}^n {n\choose k} a_k$$ 
Figure 1 shows some SageMath code that accepts the terms of a sequence as input and outputs the terms arising from the binomial transform of the input terms:

Figure 1: source

Figure 2 shows the above code applied to two different sequences, firstly the sequence of divisors of the natural numbers and then the sequence consisting only of 1's.

Figure 2

I'd like to find some practical applications of binomial transforms and also investigate the Euler transform in more depth.

Wednesday, 7 August 2019

Lines and Triangles

Consider the following problem as shown in Figure 1.


Figure 1

I just stumbled upon this problem, or rather a generalisation of this problem, and thought its solution was worthy of a mention. The solution was quite simple once I read it. Let's first review what the diagram shows. There are three parallel lines (labelled 1, 2 and 3) and another five non-parallel lines (labelled 4 to 8) that intersect with each other and also with the parallel lines. No three lines pass through a single point. How many triangles are formed?

Let's break the problem into two parts. Firstly let's deal with the five non-parallel lines. It takes three lines to make a triangle and so there are$$ \binom 5 3 = \binom 5 2 =\frac{5 \times 4}{2 \times 1}= 10 \text { possible combinations}$$So the five non-parallel lines form 10 triangles with each other. The three parallel lines can each be linked to a pair of non-parallel lines. This becomes:$$ \binom 5 2 \times 3 = 10 \times 3 = 30 \text{ possible combinations}$$So in total there are \(10 + 30 = 40\) triangles formed.

Generalising this, if there are \( n \) non-parallel lines and \(m\) parallel lines then:$$\text {The number of triangles formed is given by } \binom n 3 + \binom n 2 \times m$$Of course if none of the lines are parallel then \(m=0\) and the expression simplifies accordingly. It's interesting to count the number of points as well (shown in Figure 2):


Figure 2

The intersection of the lines produces 25 points, which I dutifully counted and labelled. If the points are taken in pairs, then each pair will generate a line with the result that there will be \( \binom {25} 2 = \frac {25 \times 24}{2 \times 1}=300\) lines which is clearly not the case because many of the lines are the same as others due to the large number of collinear points. 

However it can be noted that when two lines intersect, a point is created and so the following expression arises:$$ \binom 5 2 + 5 \times 3 = 10 + 15 =25 \text { which confirms my manual count}$$This can be generalised to:$$ \text {The number of points is given by }\binom n 2 + n \times m$$

Thursday, 6 July 2017

From Binomial to Poisson

There's nothing special about this post. Once again, I'm practising my LaTeX skills and reminding myself at the same time of the connection between the Binomial and Poisson probability distributions. Let's start with a binomial distribution with number of trials \( n \) and probability of success \( \lambda/n \). Let's say that \( n \) is the number of equal intervals into which a unit of time has been divided. The unit of time might be one hour and this interval is divided into 10 equal intervals each of 6 minutes duration. Suppose that there are on average 7 calls during the hour. The probability of a call being received during any one of the intervals is thus 7/10 or 0.7.

Suppose X is a random variable that is binomially distributed with probability of success \( \lambda/n \) and number of trials \( n \), that is \(X \sim B(n, \lambda/n) \). The probability that X takes a special value \( x \) is then given by:\[ P(X=x)=\binom{n}{x} \left( \frac{ \lambda}{n} \right)^x \left( 1-\frac{\lambda}{n} \right)^{n-x} \]This can be written as:\[ P(X=x)=\frac{n(n-1)(n-2) ... (n-x+1)}{x!} \times \frac{\lambda^x}{n^x}\left(1-\frac{\lambda}{n} \right)^{n-x} \]Again, this can be rearranged to:\[ P(X=x)=\frac{\lambda^x}{x!} \times \frac{n-1}{n} \times \frac{n-2}{n} \times ... \times \frac{n-x+1}{n} \times \left(1-\frac{\lambda}{n} \right)^{n-x} \]An \( n  \to \infty \), the expression becomes: \[P(X=x)=\frac{\lambda^x}{x!}e^{-\lambda} \]This formula then represents the Poisson distribution, a suitable model for events which:

  • occur randomly in space or time
  • occur singly, that is events cannot occur simultaneously
  • occur independently
  • occur at a constant rate, that is a mean number of events in a given time interval is proportional to the size of the interval

A discrete random variable that follows a Poisson distribution with parameter \( \lambda \) is written as \(X \sim Po(\lambda) \) and the mean of this distribution is \( \lambda \) and the variance is also \( \lambda \). Thus the mean and variance of a Poisson distribution are equal.

In Google Sheets, the syntax for the Poisson distribution function is shown below: