Wednesday, 24 June 2020

The Omega Constant and the Lambert W Function

I first encountered the Omega constant in the following video by blackpenredpen:


In this video, he looks at the function \(y=xe^x-1\) and finds where the \(y\) value is zero. He does this using Newton's Method which relies on the iteration:$$x_{n+1}=x_n-\frac{f(x)}{f'(x)} \text{ for any function } f(x)$$Figure 1 shows the SageMath code and permalink that I used to generate the digits of this constant, beginning with a value of \(x=0.5\) since we know the zero lies somewhere between 0 and 1 because:$$y=-1<0\ \text{ when } x=0 \text{ and } y=e-1>0 \text{ when } x=1$$:
Figure 1: permalink

As can be seen, the constant works out to be \( 0.5671432904 \text{ ... } \) and it is this constant that is given the name Omega constant and the symbol \( \Omega \). It is a transcendental number and has the property that \( \Omega e^{\Omega}=1\). Thus \( \Omega \) is the value of \(x\) in \(x \, e^x\) that makes it equal to 1. Figure 2 shows the graph of \(y=x \, e^x\) with key points on the graph noted.

Figure 2

The minimum turning point occurs when \(y'=(1+x) \, e^x=0\ \) and this occurs when \(x=-1 \). The point of inflexion occurs when \( y''=(2+x) \, e^x=0\) and this occurs when \(x=-2 \). \( \Omega \) is shown with its corresponding \(y\) value of 1 noted.

The Lambert W function is simply the inverse function for \(y=x \, e^x \) and is thus \(x=y \, e^y \) but needs to be broken into two parts to conform to the requirement that a single \(x\) value cannot be associated with more than one \(y\) value. It is the same graph as in Figure 2 but reflected about the line \(y=x\). See Figure 3 (source). The Lambert W function is also called the omega function and the product logarithm function.


Figure 3: The graph of
 y = W(x) for real x < 6 and y > −4

The upper branch (blue) with y ≥ −1 is the graph of the function W0 (principal branch).

The lower branch (red) with y ≤ −1 is the graph of the function W−1

The minimum value of x is at {-1/e,-1}

So the solution to the equation \(x \, e^x=2\) is W(2) \( \approx 0.852605502013726\) and so on. We can also solve \(x^x=2\) because$$ \log(x^x)=x \, \log(x)=\log(2)\\ \text{ let } u=\log(x) \text{ and so }u \, e^u= \log(2)\\ u=W(\log(2)) \text{ and so } \log(x)=W(\log(2))\\ \therefore x=e^{W(\log(2))} \approx 1.55961046946... $$Here are links to blackpenredpen's videos on:
The last mentioned video I'll cover in detail here because the solutions to the two equations are very satisfying. The first equation is \(x^2 \, e^x=2\) and the second is \(x+e^x=2\). Let's solve each in turn:$$ x^2 \, e^x=2\\ \text{Take the square root of both sides}\\x \,e^{\frac{x}{2}}=\pm \sqrt{2}\\ x \text{ must be } \geq -1/e \text{ (see Figure 3)}\\ \therefore x \,e^{\frac{x}{2}}=\sqrt{2}\\ \frac{x}{2} \,e^{\frac{x}{2}}= \frac{\sqrt{2}}{2}\\W \bigg ( \frac{x}{2} \,e^{\frac{x}{2}} \bigg )= W \bigg (  \frac{\sqrt{2}}{2} \bigg )\\ \frac{x}{2}=W \bigg (  \frac{\sqrt{2}}{2} \bigg )\\x=2 \times W \bigg (  \frac{\sqrt{2}}{2} \bigg ) \approx 0.90120$$Figure 4 shows the graphical situation:

Figure 4

Now for the second equation:$$x+e^x=2\\ e^x=2-x\\ \frac{e^x}{e^x}=\frac{2-x}{e^x}\\1=(2-x) \, e^{-x}\\e^2=(2-x) \, e^{2-x}\\W  (e^2 )=W  ( (2-x) \, e^{2-x}  )\\W  (e^2  )=2-x\\x=2-W  (e^2  ) \approx 0.44285$$Figure 5 shows the graphical situation:

Figure 5

Saturday, 20 June 2020

Prouhet-Thue-Morse Sequence

I was reminded of this sequence when I rewatched a Numberphile YouTube video that related the sequence to the game of chess.


The Prouhet-Thue-Morse is a simple enough sequence but one with many practical applications. It can be described using formal mathematical notation but it can be described in so-called layman's terms as well. This gif from Wikipedia is an example of the latter:


A close look at this gif and it's clear enough how the sequence is being constructed. My last two posts have focussed on recurrence relations and the Prouhet-Thue-Morse sequence can be described more formally as a recurrence relation:$$ \begin{align} t_0 &= 0\\ t_{2n} &= t_n\\ t_{2n+1} &= 1 - t_n \end{align}$$wikiHow has a variety of algorithms for creating the sequence. One uses the recurrence relation as shown in Figure 1:

Figure 1

I incorporated this approach into SageMathCell as shown in Figure 2 (permalink):

Figure 2: permalink

Another approach, what wikiHow calls the Direct Definition, uses the binary form of the natural (decimal) numbers, calculates their binary sum and then uses the modulus 2 of this sum as the output. What's happening is that decimal numbers with an even number of 1's in their binary form are assigned a ZERO and those with an odd number of 1's are assigned a ONE.

\(t_0 = 0 \text{ and } t_n \equiv s_n \bmod{2} \text{ where }s_n \text{ is the binary sum of }n\)

This algorithm is even easier to implement in SageMathCell. See Figure 3 where the output is shown, for variety, as a string rather than a list of elements (permalink):

Figure 2: permalink

The following is an excellent video that I came across from a mathematician who, unconsciously, used the Thue-Morse sequence (sometimes the Prouhet part of the name is omitted) as a child to cope with his obsessive compulsive disorder. Later he describes how he unwittingly used the sequence to solve the Mathematics problem described in Figure 3:

Figure 3



Of course the sequence can be represented with elements other than 0's and 1's. For example, suppose that two persons want to divide an even number of items of equal value between themselves. If the choosing sequence goes ABABABAB ... or BABABABA ... then the person choosing second will always be behind 50% of the time in terms of what they've accumulated. However, using the Thus-Morse sequence, the lead will alternate and in fact represents the fairest way to share things:

ABBABAABBAABABBABAABABBAABBABAABBAABABBAABBABAABABB

Finally, here is a video on the sequence that Stand-up Maths did some years ago:

Tuesday, 16 June 2020

Solving Linear Recurrence Relations

This article follows on from my previous post of June 10th 2020 titled Fibonacci-like Sequences. I owe a debt of gratitude to Niloufar Shafiei who has posted an excellent PDF about solving linear recurrence relations. He treats both linear homogeneous recurrences and linear non-homogeneous recurrences but it is only the former that I'll concern myself with in this post.

With a linear recurrence, each term of a sequence is a linear function of earlier
terms in the sequence. An example would be:$$a_n=a_{n-1}+a_{n-2}+1$$However, this is not homogenous, because the last term, 1, does not involve an earlier term of the sequence. An example of a linear homogenous recurrence would be:$$a_n=a_{n-1}+2a_{n-2} \text{ with }a_0=1 \text{ and }a_1=5$$This corresponds to the quadratic:$$x^2=x+2 \text{ so that }x^2-x-2 = (x-2)(x+1)$$This equals 0 when \(x=2\) or \(x=-1\).

The PDF referred to earlier shows that the \(n\)-th term can be written in a form that is a linear combination of the two solutions:$$ \alpha_1(2^n)+\alpha_2(-1)^n \text{ where } \alpha_1 \text{ and } \alpha_2 \text{ are constants to be determined}$$The values of \(\alpha_1 \text{ and } \alpha_2 \) can be determined from the initial conditions. When we substitute for \(n=0\) and \(n=1\), this means that:$$\alpha_1+\alpha_2=1 \text{ and } 2 \alpha_1-\alpha_2=5$$Solving this pair of equations, we find \( \alpha_1=2\) and \( \alpha_2=-1\) and thus \(a_n\) can be written as:$$a_n=2^{n+1}-(-1)^n \text{ for } n \ge 0$$The dominant term of course is \(2^n\) and so:$$\lim_{n -> \infty}\frac{a_{n+1}}{a_n}=2$$The first ten terms of this sequence are (SageMathCell permalink):

1, 5, 7, 17, 31, 65, 127, 257, 511, 1025, 2047, 4097

If the quadratic associated with the recurrence relation has a repeated root, then a slightly different approach is required. For example, let's consider the recurrence:$$a_n=6a_{n-1}-9a_{n-2} \text{ with } a_0=1 \text{ and } a_1=9$$The quadratic that arises is:$$x^2=6x-9 \text{ or } x^2-6x+9=(x-3)^2$$The repeated root here is \(x=3\) and Niloufar Shafiei in his PDF shows that in this case, the solution is:$$\alpha_1(3)^n+\alpha_2 n(3)^n \text{ or } 3^n(\alpha_1+\alpha_2n)$$Again, we get two equation in two unknowns and in this case, after applying the initial conditions, the solution is \(\alpha_1=1\) and \(\alpha_2=2\). Thus \(a_n\) can be written as:$$a_n=3^n(1+2n) \text{ for } n \ge 0$$The dominant term is \(3^n\) and so:$$\lim_{n -> \infty}\frac{a_{n+1}}{a_n}=3$$The first ten elements of the sequence are (SageMathCell permalink):

1, 9, 45, 189, 729, 2673, 9477, 32805, 111537, 373977, 1240029, 4074381

So this is the essential idea. Niloufar Shafiei in his PDF has plenty more examples that are easy to understand and well-presented. There is a lot more to delve into regarding recurrence equations and I'm sure I'll be writing more about them in the future.

Wednesday, 10 June 2020

Fibonacci-like Sequences

I've posted a lot about Fibonacci numbers over the years:
The Fibonacci sequence is the most famous example of a generalised sequence that begins with two seed numbers \( a \) and \( b \) and then proceeds as follows:$$ a_n=\begin{cases}a&\mbox{if }n=0;\\b&\mbox{if }n=1;\\a_{n-1}+a_{n-2}&\mbox{otherwise.}\end{cases} $$No matter what the values of the seed numbers, the ratio of one term to its predecessor always approaches \( \phi \), the golden ration. This ratio is equal to: $$ \frac{1+\sqrt{5}}{2}$$There is an even more generalised sequence that also begins with two seed numbers \( a \) and \( b \) but then proceeds as follows:$$ a_n=\begin{cases}a&\mbox{if }n=0;\\b&\mbox{if }n=1;\\A \, a_{n-1}+ B \, a_{n-2}&\mbox{otherwise.}\end{cases} $$Here \(A\) and \(B\) are constants and in the case where \(A=1\) and \(B=1\), we have the earlier sequence. The ratio of one term to its predecessor however, is no longer the golden ratio. The \(n\)-th term for such a sequence is given by:$$\frac{ \alpha^n- \beta^n}{\alpha-\beta}$$Here \( \alpha \) and \( \beta \) are the roots of the quadratic \(x^2=Ax+B\). Let's take a specific example where \(A=3\) and \(B=3\) and so \(x^2=3x+3\). The solution to this is:$$\alpha=\frac{3+\sqrt{21}}{2} \text{ and } \beta=\frac{3-\sqrt{21}}{2}$$Thus the \(n\)-th term approaches:$$\frac{(3+\sqrt{21})^n- (3-\sqrt{21})^n}{2^n \times \sqrt{21}}$$This simplifies to:$$\frac{1}{\sqrt{21}}\, \left(\frac{3+\sqrt{21}}{2}\right)^n$$Thus the ratio between successive terms will tend to \( \displaystyle \frac{3+\sqrt{21}}{2}\)

In the case where \(A=1\) and \(B=1\), the ratio is  \( \displaystyle \frac{1+\sqrt{5}}{2}=\phi\) and so different surds will appear depending on the values of \(A\) and \(B\).

As we've seen in the case of \(A=3\) and \(B=3\), the surd turns out to be \( \sqrt{21} \). Here is an example of an OEIS sequence with seed numbers \(a_0=1\) and \(a_1=2\) that has both constants equal to 3:



a(n) = 3*a(n-1) + 3*a(n-2) with a(0)=1 and a(1)=2           


The first terms of the sequence are 1, 2, 9, 33, 126, 477, 1809, 6858, 26001, 98577, 373734, 1416933, ... Naturally the terms get larger far more quickly than the Fibonacci sequence. Note that the ratio of the last two terms is getting close to the predicted value:$$\frac{1416933}{373734} \approx 3.79128738621586 \text{ and } \frac{3+\sqrt{21}}{2} \approx 3.79128784747792$$A further point to note is that the formula: $$\frac{ \alpha^n- \beta^n}{\alpha-\beta}$$only produces the correct terms of the sequence when a(0)=0 and a(1)=1 and the result is rounded to the nearest whole number. See permalink. However, no matter what the seed numbers, the ratio of terms for a particular sequence always approaches the same limit.

Saturday, 6 June 2020

The Catalan Constant

Today I turned 25977 days old and this number is prime. One of its claims to fame is that it is a member of OEIS A104919:


A104919

Primes from merging of 5 successive digits in decimal expansion of Catalan's constant.


I was familiar with Catalan numbers and in fact posted about them in this post from the 30th of September 2015 and another post from the 15th of April 2018. These numbers, and the eponymous constant, are named in honour of the Belgium mathematician Eugène Catalan. So what is the Catalan constant? It is defined as follows:$$\sum_{n=0}^{\infty} \frac{(-1)^{n}}{(2n+1)^3} = \frac{1}{1^3} - \frac{1}{3^3} + \frac{1}{5^3} - \frac{1}{7^3} + \frac{1}{9^3} - \cdots$$It is equal to 0.915965594177219015054603514932384110774 ... but the interesting thing is that no one knows whether it is irrational and, if it is, whether it is transcendental. This is odd because a similar looking sequence is known to be transcendental viz.:$$\sum_{n=0}^{\infty} \frac{(-1)^{n}}{(2n+1)^3} = \frac{1}{1^3} - \frac{1}{3^3} + \frac{1}{5^3} - \frac{1}{7^3} + \frac{1}{9^3} - \cdots = \frac{\pi^3}{32}$$As of July 16th 2019, the Catalan constant is known to 600,000,000,100 decimal places. This site lists the constant to 300,000 decimal places with the introduction:
Catalan constant to 300000 digits computed on September 29, 1996 by using a Sun Ultra-Sparc in 1 day 8 hour 15 min 15 sec 55 hsec. The algorithm used is the standard series for Catalan, accelerated by an Euler transform. The algorithm was implemented using the LiDIA library for computational number theory and it is part of the multiprecision floating-point arithmetic of the package.
This number of decimal places was the record for 1996 and it was more than sufficient for me to generate the OEIS sequence A104919 up to and including 25997. I simply copied a few thousand of the first few digits into a list and applied the SageMath algorithm shown in this permalink.

Of course, the digits can be generated using a wide variety of formulae. One of the best is the following: $$\frac{\pi}{8}\log\left(2 + \sqrt{3}\right) + \frac{3}{8}\sum_{n=0}^\infty \frac{1}{(2n+1)^2 \binom{2n}{n}}$$I tried this but wasn't successful in generating more than the first two members of the sequence so I abandoned this approach and copied and pasted instead! I'm always fascinated by these types of sequences because of their similarity to the famous Riemann zeta function:$$\zeta(s) =\sum_{n=1}^\infty\frac{1}{n^s}$$In fact the summation that generates the Catalan constant is the Dirichlet beta function (also known as the Catalan beta function) and it is closely related to the Riemann zeta function. It is defined as:$$\beta(s) = \sum_{n=0}^\infty \frac{(-1)^n} {(2n+1)^s}$$When \(s=2\), \( \beta(2)\) gives the Catalan constant. You can read more here about the Dirichlet beta function.

Friday, 5 June 2020

The Plastic Number

One of the delights of investigating the number of one's diurnal age, as I'm addicted to doing, is that every so often something fascinating pops up. Today, day number 25996, was one such day. The Online Encyclopedia of Integer Sequences (OEIS) didn't throw up much of interest. However, my newly discovered Sequence Database did reveal an interesting looking sequence, although one with an unprepossessing name: Sequence vbihjo41hob4e. It runs thus, up to 25996:
0, 3, 5, 2, 7, 6, 8, 12, 13, 19, 24, 31, 42, 54, 72, 95, 125, 166, 219, 290, 384, 508, 673, 891, 1180, 1563, 2070, 2742, 3632, 4811, 6373, 8442, 11183, 14814, 19624, 25996, ...
It arises from the recurrence relationship:$$a_n=a_{n-2}+a_{n-3}-1 \text{ where } a_0=0, a_1=3, a_2=5 \text { and } n \geq 3$$Of course, it's reminiscent of the Fibonacci sequence in that it adds two previous terms to get the next one, although it skips the immediately preceding term and also subtracts 1. I knew that the ratio of one term to the preceding term in the Fibonacci sequence approaches the Golden Ratio and so I investigated the ratio for this sequence. I found that:$$a_{101}:a_{100} \approx 1.32471795724460$$This intrigued me and I wondered if this number could be an approximation to some mathematical constant. Fortunately, I have a link to a website called Mathematical Constants and Sequences and it didn't take me long to discover what this constant was. See Figure 1 (click to enlarge).

Figure 1

As can be seen, 1.324717957244746025960908 ... is referred to as the plastic number \( \rho \) or silver constant. It's the solution to the polynomial equation \(x^3=x+1\) which has the following real solution:$$\sqrt[\leftroot{-2} \uproot{10} 3]{\frac{9 + \sqrt{69}}{18}} + \sqrt[\leftroot{-2} \uproot{10} 3]{\frac{9 - \sqrt{69}}{18}}$$The essential recurrence relationship is that of:$$a_n=a_{n-2}+a_{n-3} \text{ with } n \geq 3$$If we set \(a_0=a_1=a_2=1\), then we have the Padovan sequence: 1, 1, 1, 2, 2, 3, 4, 5, 7, 9, 12, 16, 21, 28, 37, 49, 65, 86, 114, 151, 200, 265, ... which is OEIS A000931.

My Sequence vbihjo41hob4e is essentially the Padovan sequence with different starting values \(a_0=0, a_1=3, a_2=5\) versus \(a_0=a_1=a_2=1\) and with 1 subtracted. The subtraction just means that it takes the numbers longer to get larger but addends or subtrahends and different starting values don't alter the long term behaviour. The ratio of one term to its predecessor always approaches the plastic number or silver constant. Subtracting integers greater than 1 leads to negative terms but the ratio still holds. Here is a permalink to SageMathCell that allows you experiment with the effect of different values.

The plastic number occurs in a variety of situations. Figure 2 shows one of them.

Figure 2: Three partitions of a square into similar rectangles

There are precisely three ways of partitioning a square into three similar rectangles:
The trivial solution given by three congruent rectangles with aspect ratio 3:1. The solution in which two of the three rectangles are congruent with the third one of twice the linear dimension of the congruent pair and where the rectangles have aspect ratio 3:2. The solution in which the three rectangles are mutually non congruent (all of different sizes) and where they have aspect ratio \( \rho^2 \). The ratios of the linear sizes of the three rectangles are: \( \rho \) (large : medium); \( \rho^2 \)(medium : small); and \( \rho^3 \) (large : small). The internal, long edge of the largest rectangle (the square's fault line) divides two of the square's four edges into two segments each that stand to one another in the ratio \( \rho \). The internal, coincident short edge of the medium rectangle and long edge of the small rectangle divides one of the square's other, two edges into two segments that stand to one another in the ratio \( \rho^4 \). Wikipedia
The  term "silver constant" should not be confused with the "silver ratio" of 1 + √2, which is one of the ratios from the family of metallic means. I posted about metallic means on Sunday, 3rd of March 2019. 

on January 22nd 2021
The changes were cosmetic and largely LaTeX-related, focused on improving the appearance of the cube root
symbol by raising the position of the 3 from its original default position using \leftroot {} and \uproot{}

Wednesday, 3 June 2020

Birth Year Magic

Everybody currently living was born in a year that contains four digits. I was born in 1949. My granddaughter was born in 2002. Let's take her year of birth and arrange the digits into ascending and descending order to form two new numbers: 2200 and 0022 (or simply 22). Let's subtract the smaller from the larger. The result is 2178. Let's repeat that process to from 8721 and 1278. Subtraction yields 7443. Continuing this process we get 3996, 6264, 4176 and finally 6174. Why finally? Because subtracting 7641 and 1467 leads us back to 6174! So for 2002, the progression is 2178, 7443, 3996, 6264, 4176, 6174.

Remarkably, all birth years lead to this very same number. Let's take my year of birth: the progression is 1949, 8442, 5994, 5355, 1998, 8082, 8532, 6174. The number 6174 is known as Kaprekar's constant and because it involves four digit numbers with at least two digits different, it's ideally suited to current birth years. You're not going to find someone who was born in 1111 or 2222 who will spoil the trick and so it's an ideal party trick. Everyone has their smartphone near at hand and, if not, one can always be borrowed. Using a calculator app or simply the Chrome browser, the necessary calculations can be quickly and easily carried out.

Figure 1: Google Chrome's Calculator

So Kaprekar's constant connects everybody alive today and in fact everybody born, or still to be born, between the years 1111 and 2222 with those two limits excluded.


There is no other four digit number that returns itself under the operation of subtract digits in ascending order from digits in descending order. There is a nice proof of why this is so on this site that also alerted me to the fact that for three digit numbers there is a constant that is reached as well, namely 495.

Suppose we have four digits \(a,b,c,d\) such that \(9 \geq a>b>c>d \geq 0\). If we can get the same digits (in any order) arising after the subtraction of \(dcba\) from \(abcd\), then we have an unchanging constant. It turns out that that only \(abcd-dcba=bdac\) satisfies and when this is the case \(a=7, b=6, c=4, d=1\). It's the same for the three digit situation \(abc\) and \(cba\) where \(9 \geq a>b>c \geq 0\). Here only \(abc-cba=cab\) satisfies and \(a=9,b=5,c=4\).

A table is also provided showing the situation for numbers of lengths other than 3 and 4. It can be seen that only three and four digit numbers lead to a unique constant. See Figure 1.

Figure 1: source

The site also shows the frequencies of the number of iterations required for four digit numbers to reach 6174. See Figure 2.

Figure 2: source

Here a permalink to some SageMath code that will display, for four digit numbers, the progression in reaching 6174 and count the number of iterations required. Here is another permalink, this time for three digit numbers.

Kaprekar is an interesting mathematician (biography link) and he is also associated with:
  • Kaprekar numbers (Wikipedia link)
  • Harshad numbers (see my blog posts: here and here)
  • Self numbers and Junction numbers (see my blog post here)
Finally we should say a little about the number 6174 and some of its properties. One interesting property is that it can be written as the sum of the first three degrees of 18:$$18^3 + 18^2 + 18^1 = 5832 + 324 + 18 = 6174$$This relationship also means that 6174 is a Harshad number because it is divisible by the sum of its digits (18).