Sunday, 13 June 2021

The Chi-Square Statistic: \( \chi^{^2}_{_{_c}} \)

While perusing YouTube, the idea of a watching a video about the Chi-Square test popped into my head today and I decided to watch the video with the most views: 1,867,764 views uploaded on November 14th 2011, almost ten years ago.

I thought about how the test might be carried out in SageMath. My initial investigation didn't find anything conclusive so I turned to the trusty spreadsheet, specifically Google Sheets. I've tended to neglect spreadsheets since making use of SageMath and so this was an opportunity to revisit old territory.

What the chi-square statistic looks like is shown in Figure 1:

Figure 1

The \(c\) represents the numbers of degrees of freedom. O represents the observed frequencies and E represents the expected frequencies. For the 36 tosses of a fair die, the expected frequencies are all 6. Figure 2 shows what I came up with in Google Sheets.


Figure 2: link

The chi-square function takes the observed and expected frequencies and returns the probability that the results are due to chance alone. In the example shown in Figure 2, the probability is 0.0853 or a little over 8%. This falls short of the less than 5% that is usually regarded as the minimum requirement. 

In the worksheet, I've added superfluous information for the purpose of showing how things wre done in "the old days". I've calculated the differences between O and E, squared these and then divided by E as per the formula. The total is 9.67 and, looking at the black table in Figure 2, the cut-off point is 11.070 that appears in the 0.05 column with 5 degrees of freedom. 

Figure 3 shows the expected versus the observed results:


Figure 3

It's easy enough to get SageMath cell to carry out the necessary steps to arrive at the 9.67 result. Figure 4 shows a screenshot of the algorithm along with the permalink.


Figure 4: permalink

What I was looking for in SageMath was a function that would take the two lists as input and output the probability in the same way as the spreadsheet did. Perhaps it's possible. I'll keep investigating.

UPDATE on June 21st 2021

I just watched a video on YouTube demonstrating the application of the Chi-Square test using Excel. A manual method is used as well as making use of the built in Chi-Square function. The video does a good job of explaining the statistic using a 3 x 3 table as an example.

Saturday, 12 June 2021

23500: Blast from the Past

One of my earliest posts regarding my diurnal age dates to August 5th 2013 and was uploaded to my Pedagogical Posturing blog. This Mathematical Meandering blog did not exist at that time. This was before I had any notion that OEIS and other resources existed. Rather naively, I wrote in a post titled Reflections on 23500:

Today I'm 23500 days old and I was looking around to see if there was any significance to this number. It's factors are unremarkable (2^2 x 5^3 x 47) but the fact that it's halfway between 23000 and 24000 means that it pops up quite frequently in Internet searches, as would 22500 or 24500 I would imagine. A search reveals that the approximate population of Boston in 1620 was 23500 and there are several towns around the world that are listed as having this population currently e.g. Bishopbriggs in Scotland.

Bishopbriggs grew from a small rural village on the old road from Glasgow to Kirkintilloch and Stirling during the 19th century, eventually growing to incorporate the adjacent villages of Auchinairn, Cadder, Jellyhill and Mavis Valley. It currently has a population of approximately 23,500 people.

Source: http://en.wikipedia.org/wiki/Bishopbriggs

It turns out that Mount Isa has the same population (source):

Mount Isa is located just 200 kilometres from the Northern Territory border and 1,829 kilometres from Queensland’s capital, Brisbane. The nearest major city, Townsville, can be found 883 kilometres from The Isa. Mount Isa covers an area of over 43,310 square kilometres, making it geographically the second largest city in Australia to Kalgoorlie-Boulder, Western Australia ... With a population of approximately 23,500, Mount Isa is a major service centre for north-west Queensland.

Many other examples of towns having populations of about 23500 could be quoted. In addition of populations, the number sometimes comes up as a dollar figure (source):

In its third annual funding cycle, the Black Philanthropy Initiative has pumped $23,500 back into the Winston-Salem area to help African Americans improve their parenting skills.

Interestingly, it turns out that the centre of the Sun is about 23500 times more distant from us than the centre of the Earth (source).

The sun is far enough away (about 23,500 earth radii) that it took a long time before people knew accurately how far away the sun was. Certainly the ancient Greeks had calculated the distance, but they also knew that their results could be off. 

Many countries in the world have five digit postal codes or zip codes as they are sometimes known. These codes identify particular locations within the country e.g. Muang Prachinburi, Prachinburi, Thailand has a postcode of 23500. The United States uses a five digit system but apparently there is no location corresponding to 23500, although there is for 23499 and 23501. 

I've improved the formatting somewhat but that post was made almost eight years ago and is testimony to how little I knew about number properties at the time. With my current skill set, what more can I uncover about 23500? It turns out that it has 18 entries in the OEIS and a couple of them are interesting enough for comment.

The first is its membership of OEIS A133524:


 A133524

Sum of squares of four consecutive primes.                           


The members of the sequence, up to 23500, are:
87, 204, 364, 628, 940, 1348, 2020, 2692, 3700, 4852, 5860, 7108, 8548, 10348, 12220, 14500, 16732, 18580, 21100, 23500

Nowadays I'd write a program in SageMath to generate this sequence. Here is a permalink to that program in SageMathCell.

The second is its membership of OEIS A035959 where \(n=42\):


 A035959



Number of partitions of \(n\) in which no parts are multiples of 5.        


The members of the sequence, up to 23500, are:
1, 1, 2, 3, 5, 6, 10, 13, 19, 25, 34, 44, 60, 76, 100, 127, 164, 205, 262, 325, 409, 505, 628, 769, 950, 1156, 1414, 1713, 2081, 2505, 3026, 3625, 4352, 5192, 6200, 7364, 8756, 10357, 12258, 14450, 17034, 20006, 23500

Here is the permalink to the algorithm in SageMathCell that will generate this sequence. 

As we turn to Numbers Aplenty, my other major source of information about numbers, we discover that it is a Harshad number as well as an abundant, practical, pseudoperfect and Zumkeller number. There's lots more information there as well. See Figure 1.


Figure 1: link

Over the years, I've developed programs related to practical, pseudoperfect and Zumkeller numbers. I've stored these as a Google Document accessible via this link.

For example, here is a permalink to a program that will determine all the practical numbers in a given range. Remember a practical number has the property that each smaller number is the sum of distinct divisors of that number. Between 23450 and 23550, there are the following practical numbers:
23450, 23452, 23460, 23472, 23474, 23478, 23484, 23490, 23496, 23500, 23504, 23506, 23520, 23528, 23530, 23532, 23540, 23542, 23544, 23548, 23550
A pseudoperfect number, sometimes called a semiperfect number, is a number in which a subset of its proper divisors sum to the number itself. Nearly all abundant numbers are pseudoperfect and the ones that aren't are called weird. In the case of 23500, there are many such subsets that can be formed from its proper divisors of 1, 2, 4, 5, 10, 20, 25, 47, 50, 94, 100, 125, 188, 235, 250, 470, 500, 940, 1175, 2350, 4700, 5875 and 11750. One such subset is 1175, 4700, 5875 and 11750. Here is permalink to SageMathCell and a program that will display all of the possible subsets.

Zumkeller numbers are related to perfect numbers such as 6, the divisors of which can be written as the set {1, 2, 3, 6}. There are two mutually exclusive subsets of this set, {1, 2, 3}  and {6}, whose union is the original set and both of whose elements add to 6. Zumkeller numbers are similar in that there are two mutually exclusive subsets of this set of divisors, whose union is the original set but with the difference that both of the elements in each subset add to a number other than the originating number. For example, 20 has the set of divisors {1, 2, 4, 5, 10, 20} and there are two subsets {1, 20} and {2, 4, 5, 10} that both total 21. Thus 20 is a Zumkeller number. In the case of 23500, there are many such pairs of subsets. Here is one example:

[4, 10, 94, 250, 2350, 23500] and [1, 2, 5, 20, 25, 47, 50, 100, 125, 188, 235, 470, 500, 940, 1175, 4700, 5875, 11750] which both sum to 26208.

Here is a permalink to a SageMathCell program that will display all the pairs of subsets.

Harshad or Niven numbers are divisible by the sum of their digits. Here is a permalink to a SageMathCell program that displays all such numbers in the range from 23450 to 23550. These numbers are:

23450, 23454, 23457, 23460, 23472, 23490, 23496, 23500, 23505, 23508, 23520, 23526, 23530, 23544, 23550

23500 is formed from a concatenation of the first three prime numbers (2, 3 and 5), followed by two zeroes. It's interesting to note that 23500 written in scientific notation as \(2.35 \times 10^4\) features all the digits from 0 to 5. Earth's axial tilt is close to 23.5° and, as mentioned in my original post, there is this most interesting astronomical detail regarding 23500: 

Distance to Sun = 1.5 x 10^13 cm = 23500 Earth radii = 1 Astronomical Unit (AU) 

So nothing mathematically Earth-shattering in this post but just a reflection on the differences in my mathematical knowledge between now and then. 

Friday, 11 June 2021

Solutions to \( \phi(x)=k\)

Having turned 26367 days old today, I noticed that this number is a member of OEIS A289364:


  A289364

Numbers n such that \( \phi(x) = 12 \times n+2\) is solvable, where \( \phi\) is Euler's totient.  


Up to 26367, the members of this sequence are:
0, 9, 42, 180, 285, 414, 567, 945, 1109, 1419, 2310, 2655, 3024, 4275, 4740, 5229, 5742, 8034, 10005, 10710, 12192, 14595, 15444, 16317, 18135, 19080, 20049, 21042, 22306, 26367

Clearly, the numbers \(x\) satisfying this equation are not numerous. However, I thought so what? Well, fortunately a link provided in the OEIS entry comments shed some light on the matter. I've taken a screenshot of the relevant part of the paper and this is shown in Figure 1.


Figure 1

So it turns out that \( \phi(x)=k \) does not have many solutions if \(n \equiv  2 \! \! \! \mod \! \! 12 \) and those solutions appear in OEIS A289364. Moreover, Carmichael's conjecture states that the equation is never uniquely satisfied for any positive integer \(k\). This was certainly the case when I checked it out for 26367:$$\begin{align}\text{if } \phi(x)&=2 \times 26367+2\\x&=316969
\text{ or }633938 \end{align}$$The paper delves into why there are so few solutions when \(n \equiv  2 \! \! \! \mod \! \! 12 \) but I've not gone into that here. Perhaps I can cover that in a later post.

Concatenations

Today I turned 26366 days old and yesterday, of course, I was 26365 days old. Each of these numbers have the property that the leading two digits (26) represent the number of fortnights in a year while the final three digits (365 and 366) represents the number of days in non-leap years and a leap years respectively. Incidentally, 26 fortnights represent 26 x 14 = 364 days and so 26364 encodes that fact. Similar pairs of numbers include:

  • 12365 and 12366 where 12 represents the number of months in a calendar year
  • 13365 and 13366 where 13 represents the number of lunar months in a calendar year
  • 52365 and 52366 where 52 represents the number of full weeks in a calendar year
The concatenation of numbers, according to WolframMathWorld, is represented by the symbol \( \parallel \) and thus 26\( \parallel \)366 = 26366. The formula for the concatenation in base \(b\) of two numbers, \(p\) and \(q\), is given by:$$p \parallel q=p \, b^{f(q)} + q \text{ where } f(q)=\left \lfloor \log_b{q} \right \rfloor + 1$$$$ \text{where }f(q) \text{ represents the length of } q$$Let's test this formula out in the case of 26366. We have \(p=26\) and \(q=366\). Clearly the length of \(q\) is 3 but let's check using \( \left \lfloor \log_{10}366 \right \rfloor + 1\). The value of this is indeed 3 so all is good.

When constructing an algorithm, the formula is useful as a way of accomplishing the concatenation without resorting to strings. Figure 1 shows the relevant SageMath code.


Figure 1: permalink

26365 and 26366 have some interesting shared properties. They are both semiprimes and emirpimes :
  • 26365 = 5 * 5273 and 56362 = 2 * 28181
  • 26366 = 2 * 13183 and 66362 = 2 * 33181
In recreational mathematics, there are some interesting applications of concatenation. One of these involves so-called home primes. These are primes obtained by repeatedly factoring the increasing concatenation of prime factors of a given number. I've written about these in an eponymous post on May 2nd 2021. Let's work out the home primes for 26364, 26365 and 26366.

For 26364, we find ten steps are required to reach the home prime: 
 
26364
223131313
792824447
10113956473
21147933443
713589739409
4059117579999
31353039193333
1113305413717887
313175353597790561

For 26365, only six steps are required:

26365
55273
311783
734271
3311787
31764937

For 26366, seven steps are required:

26366
213183
3323687
17195511
35731837
196728069
365576023

The Smarandache–Wellin numbers involve the concatenations of the first prime numbers. These numbers form OEIS A019518:


 A019518

Smarandache-Wellin numbers: a(n) is the concatenation of first n primes (written in base 10).


The sequence begins:

2
23
235
2357
235711
23571113
2357111317
235711131719
23571113171923
2357111317192329
235711131719232931
23571113171923293137
2357111317192329313741
235711131719232931374143
23571113171923293137414347

Of the numbers listed here only 2, 23 and 2357 are prime. The next such number that is prime has 355 digits!

If we concatenate the integers, we create the Champernowne constant, a transcendental real constant whose decimal expansion has important properties. It is named after economist and mathematician D. G. Champernowne, who published it as an undergraduate in 1933. I've written about this constant in an eponymous post on March 22nd 2019. The constant begins 12345678910111213141516 ... 

The Copeland–ErdÅ‘s constant is formed by the concatenation of "0." with the base 10 representations of the prime numbers in order. Its value, using the modern definition of prime, is approximately 0.235711131719232931374143…

There is a reverse integer sequence that comprises OEIS A000422:


 A000422

Concatenation of numbers from n down to 1.             


The sequence begins:

1
21
321
4321
54321
654321
7654321
87654321
987654321
10987654321
1110987654321
121110987654321
13121110987654321
1413121110987654321
151413121110987654321
16151413121110987654321
1716151413121110987654321
181716151413121110987654321

Interestingly, this sequence produces very few primes with the first being when \(n=82\) and the next being \(n=37765\).

We can concatenate the odd, even, triangular, square, cubic and Fibonacci numbers and all of these have associated OEIS sequences. Follow this link for more information.

Sunday, 6 June 2021

26362: Another Special Palindrome

The day that I turned 26262 days old I dedicated a post to the number and titled it 26262: A Special Palindrome. That was on February 21st 2021. Today I'm enjoying the next successive palindromic day, having turned 26362 days old. 

Now this is a somewhat unusual palindrome in that it is not a member of OEIS A067030


A067030



Numbers \(n\) that are of the form \(k\) + reverse(\(k\)) for at least one \(k\).



Let's be clear firstly that such numbers are not common. The 1000th such number is 38772 which translates to a percentage density of less than 2.6%. The first such numbers are:
0, 2, 4, 6, 8, 10, 11, 12, 14, 16, 18, 22, 33, 44, 55, 66, 77, 88, 99, 101, 110, 121, 132, 141, 143, 154, 161, 165, 176, 181, 187, 198, 201, 202, 221, 222, 241, 242, 261, 262, 281, 282, 302, 303, 322, 323, 342, 343, 362, 363, 382, 383, 403, 404, 423, 424, 443 
Of these first 56 members of the sequence, 29 (more than 50%) are palindromic. This is not surprising because most numbers, under the repeated Reverse and Add operation, lead to a palindrome. 196 is the first number that apparently does not. Let's look at the palindromes not belonging to this sequence: 

131, 151, 171, 191, 212, 232, 252, 272, 292, 313, 333, 353, 373, 393, 434

All of them lead to palindromes under Reverse and Add, as shown below:

131 requires 1 steps to reach the palindrome 262
151 requires 2 steps to reach the palindrome 505
171 requires 2 steps to reach the palindrome 585
191 requires 4 steps to reach the palindrome 2552
212 requires 1 steps to reach the palindrome 424
232 requires 1 steps to reach the palindrome 464
252 requires 2 steps to reach the palindrome 909
272 requires 2 steps to reach the palindrome 989
292 requires 8 steps to reach the palindrome 233332
313 requires 1 steps to reach the palindrome 626
333 requires 1 steps to reach the palindrome 666
353 requires 3 steps to reach the palindrome 4444
373 requires 4 steps to reach the palindrome 9559
393 requires 4 steps to reach the palindrome 9339
434 requires 1 steps to reach the palindrome 868

26362 as it turns out is a member of OEIS A070001:


 A070001

Palindromes whose 'Reverse and Add' trajectory (presumably) does not lead to another palindrome.

 The initial members of this sequence are:

4994, 8778, 9999, 11811, 19591, 22822, 23532, 23632, 23932, 24542, 24742, 24842, 24942, 26362, 27372, 29792, 29892, 33933, 34543, 34743, 34943, 39493, 44744, 46064, 46164, 46364, 46564, 46964, 47274, 47574, 48284, 48584, 48684, 48884

These palindromes are not regarded as potential Lychrel numbers because they are already palindromes and some of them are the result or end point of \(k\) + reverse(\(k)\) iterations. However, some are not and these, I think, deserve special consideration:

19591, 23532, 23932, 24542, 24742, 24942, 26362, 27372, 29792, 33933, 34543, 34743, 34943, 39493, 44744, 46164, 46364, 46564, 46964, 47574, 48584

So 26362 is only the 7th palindrome to have the simultaneous property that:

  • it cannot be derived from \(k\) + reverse(\(k\)) for one or more values of \(k\)
  • its Reverse and Add trajectory (presumably) does not lead to another palindrome
There already two sevens associated with the number because \(7^2\) is a factor, so we have a lucky triple 7.


This is not the first time that I've written about palindromic numbers. Apart from my 26262: A Special Palindrome post, I've written about:
In researching this post, I came across a category of primes known as Palindromic Wing Primes or PMPs defined as "numbers that are primes, palindromic in base 10, and consisting of one central digit surrounded by two wings having an equal amount of identical digits and different from the central one". Examples are:

101
99999199999
333333313333333
7777777777772777777777777
11111111111111111111111111111111411111111111111111111111111111111

Some of these primes are regarded as potential Lychrel candidates and are listed in OEIS A320516 (with the rule that palindromes are ineligible being relaxed):


 A320516

Palindromic wing primes that are also Lychrel candidates.        
    

Initial members are:
7774777, 777767777, 77777677777, 99999199999, 1111118111111, 7777774777777, 111111181111111, 333333373333333, 77777777677777777, 99999999299999999, 9999999992999999999, 33333333333733333333333, 77777777777677777777777, 333333333333373333333333333

More information about PWPs can be found here. Palindromes and any numbers can be tested for Lychrel candidature using SageMathCell. A permalink is attached to the screenshoot in Figure 1.

Figure 1: permalink 

Saturday, 5 June 2021

Hands On With The Integral Calculator

I watched a YouTube video today featuring the following integration result:$$\int_0^{2\pi} \frac{1}{3+2\sin(x)} \mathrm{d}x=\frac{2\pi}{\sqrt{5}}$$The method of solving it involved complex analysis involving contour integrals, L'Hospital's Rule, and the Residue Theorem. Here is a link to the video. It is well explained but I was left wondering if there is a way to solve it that does not require the use of complex numbers.

I decided to use a recently discovered resource:


I entered this result and then copied the result, which is shown below:

Problem:
12sin(x)+3dx
Prepare for tangent half-angle substitution (Weierstrass substitution):
=14tan(x2)tan2(x2)+1+3dx
Substitute u=tan(x2)  dudx=sec2(x2)2 (steps)  dx=2sec2(x2)du =2u2+1du:
=213u2+4u+3 du

Now solving:
13u2+4u+3du
Complete the square:
=1(3u+23)2+53du
Substitute v=3u+25  dvdu=35 (steps)  du=53dv:
=53(5v23+53)dv
Simplify:
=151v2+1dv

Now solving:
1v2+1dv
This is a standard integral:
=arctan(v)

Plug in solved integrals:
151v2+1dv
=arctan(v)5
Undo substitution v=3u+25:
=arctan(3u+25)5

Plug in solved integrals:
213u2+4u+3 du
=2arctan(3u+25)5
Undo substitution u=tan(x2):
=2arctan(3tan(x2)+25)5

The problem is solved:
12sin(x)+3 dx
=2arctan(3tan(x2)+25)5+C

*****************************************

The definite integral result is then given in LaTeX format: \( \dfrac{2{\pi}}{\sqrt{5}} \). 

Unfortunately, it doesn't appear possible to export the actual steps in LaTex but the copy and paste operation seems to have worked well enough, the elements are editable and the provided links are functional. However, the HTML is an absolute nightmare. It makes the page slow to load and there's no way to remove the coloured vertical bars on the left.

The site also provides a graph of the integral. See Figure 1.


Figure 1

There is a Derivative Calculator as well. I wasn't familiar with the Weierstrass substitution but I won't go into that in this post. It deserves a post of its own which I'll hopefully get around to doing in the near future. 

I thought I'd experiment with applying the MathPix Snipping Tool to the Integral Calculator. I wrote about the former in an eponymous post on March 31st 2021. Here are the results for the initial snipping (with a little tinkering to remove excessive white space):$$\int \frac{1}{2 \sin (x)+3} \mathrm{~d} x$$Prepare for tangent half-angle substitution (Weierstrass substitution):$$\begin{aligned}&=\int \frac{1}{\frac{4 \tan \left(\frac{x}{2}\right)}{\tan ^{2}\left(\frac{x}{2}\right)+1}+3} \mathrm{~d} x \\\text { Substitute } u=\tan \left(\frac{x}{2}\right) \longrightarrow \frac{\mathrm{d} u}{\mathrm{~d} x} &=\frac{\sec ^{2}\left(\frac{x}{2}\right)}{2}(\text { steps }) \longrightarrow \mathrm{d} x=\frac{2}{\sec ^{2}\left(\frac{x}{2}\right)} \mathrm{d} u=\frac{2}{u^{2}+1} \mathrm{~d} u: \\
&=2 \int \frac{1}{3 u^{2}+4 u+3} \mathrm{~d} u
\end{aligned}$$Now solving:$$\int \frac{1}{3 u^{2}+4 u+3} \mathrm{~d} u$$Complete the square:$$\begin{array}{c}
=\int \frac{1}{\left(\sqrt{3} u+\frac{2}{\sqrt{3}}\right)^{2}+\frac{5}{3}} \mathrm{~d} u \\
\text { Substitute } v=\frac{3 u+2}{\sqrt{5}} \longrightarrow \frac{\mathrm{d} v}{\mathrm{~d} u}=\frac{3}{\sqrt{5}}(\text { steps }) \longrightarrow \mathrm{d} u=\frac{\sqrt{5}}{3} \mathrm{~d} v \text { : }


\end{array}$$I only snipped the initial part of the steps. The reproduction from the original page is perfect but I would have set the initial LaTeX out differently. However, the result is editable and thus can be tweaked if desired. An alternative is to produce a PNG but that of course is not then editable. I'm currently using the free version of MathPix Snipping Tool that allows for 50 snips per month which is more than sufficient for casual personal use.