Saturday 26 September 2020

RATS Sequence

Today I turned 26109 days old and one of the properties of this number is that its a member of OEIS A114613:


A114613

Starting numbers for which the RATS sequence has eventual period 3.



The comments in the OEIS entry offered no explanation but there was a link to Eric Weisstein's World of Mathematics, RATS Sequence

A sequence produced by the instructions "reverse, add to the original, then sort the digits." For example, after 668, the next iteration is given by

668+866=1534

so the next term is 1345.

Applied to 1, the sequence gives: 

1, 2, 4, 8, 16, 77, 145, 668, 1345, 6677, 13444, 55778, 133345, 666677, 1333444, 5567777, 12333445, 66666677, 133333444, 556667777, 1233334444, 5566667777, 12333334444, 55666667777, 123333334444, 556666667777, 1233333334444, ... (OEIS A004000).

Conway conjectured that an initial number leads to a divergent period-two pattern (such as the above in which the numbers of threes and sixes in the middles of alternate terms steadily increase) or to a cycle (Guy 2004, p. 404).

The lengths of the cycles obtained by starting with \(n\)= 1, 2, ... are 0, 0, 8, 0, 0, 8, 0, 0, 2, 0, ... (OEIS A114611), where a 0 indicates that the sequence diverges.

The following table summarizes the first few values of \(n\) leading to a period of length \(k\). There are no other periods of length 50 or less for \(n \leq 5 \times 10^7\).

 (E. W. Weisstein, Dec. 19, 2005). 

\(k\)OEIS\(n\) with period \(k\)
inftyA001651  1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, ...
2A1146129, 18, 27, 36, 45, 54, 63, 69, 72, 78, 81, 87, 90, 96, ...
3A11461320169, 20709, 21159, 22149, 23139, 24129, 25119, 26109, ...
8A1146143, 6, 12, 15, 21, 24, 30, 33, 39, 42, 48, 51, 57, 60, 66, ...
14A1146156999, 7089, 7179, 7269, 7359, 7449, 7539, 7629, ...
18A11461629, 38, 47, 49, 56, 58, 65, 67, 74, 76, 83, 85, 92, 94, ...

In the case of 26109, it can seen from the following SageMath code that the instructions do indeed lead to a period with length 3 (permalink):

number=26109
L=[number]
while len(L)==Set(L).cardinality():
    N=number.digits()
    reversal=0
    for n in range(0, len(N)):
        reversal+=N[n]*10^(len(N)-n-1)
    number=number+reversal
    D=sorted(number.digits())
    index, number=0,0
    for d in D:
        number+=d*10^(len(D)-index-1)
        index+=1
    L.append(number)
print(L)

[26109, 111267, 337788, 1122255, 4446666, 1111113, 2222244, 4446666]

Here is a little more background surrounding this sequence, taken from this site:

Princeton mathematician John Horton Conway calls this the RATS sequence (for “reverse, add, then sort”) and in 1989 conjectured that no matter what number you start with (in base 10), you’ll either enter the divergent pattern above or find yourself in some cycle. Conway’s colleague at Princeton, Curt McMullen, showed that the conjecture is true for all numbers less than a hundred million, and himself conjectured that every RATS sequence in bases smaller than 10 is eventually periodic. Are they right? So far neither conjecture has been disproved. 

There seems to be however, another version of the RATS sequence with members generated using the following rule:

Write down an integer. Remove any zeros and sort the digits in increasing order. Now add this number to its reversal to produce a new number, and perform the same operations on that and so on. Source.

Applying this to 26109, we see that it does produce a loop but its period is 2 (1170 --> 828 --> 1170) not 3 (4446666 --> 1111113 --> 2222244 --> 4446666) as was the case with our original steps:

26109 —> 2619 —> 1269 —> 1269 + 9621 —> 10890

10890 —> 189 —> 189 + 981 —> 1170

1170 —> 117 —> 117 + 711 —> 828

828 —> 288 —> 288 + 882 —> 1170 

 The original instructions are more straightforward and don't require removal of any zeroes. 

Monday 21 September 2020

Magic Squares

This post was inspired by my daily number analysis of my diurnal age. I was struggling to find something of interest about 26102 when I discovered that a \(4 \times 4 \) magic square could be created in which 26102 was the magic constant. This got me thinking about what numbers could be represented in this way as magic squares.

A \(n \times n \) magic square has its \(n^2\) cells filled with the numbers from \(1 \text{ to } n^2 \) in such a way that the sums of all rows, columns and main diagonals are the same. This sum is called the magic constant:$$ \frac{n(n^2+1)}{2}$$The \(3 \times 3 \) magic square contains the numbers from 1 to 9 and all rows, columns and main diagonals add up to 15. Thus the magic constant is 15.$$


\begin{array}{|c|c|c|}

\hline 8 & 1 & 6 \\

\hline 3 & 5 & 7\\

\hline 4 & 9 & 2 \\

\hline

\end{array}

$$If we add 1 to each element of the above magic square, we get the next magic square and this has a magic constant of 18:$$\begin{array}{|c|c|c|}

\hline 9 & 2 & 7 \\

\hline 4 & 6 & 8\\

\hline 5 & 10 & 3 \\

\hline

\end{array}$$All subsequent \(3 \times 3 \) magic squares will have magic constants that are multiples of 3. Thus the number 26097 = 3 x 8699 can be represented as:$$\begin{array}{|c|c|c|}

\hline 8702 & 8695 & 8700 \\

\hline 8697 & 8699 & 8701\\

\hline 58698 & 8703 & 8696 \\

\hline

\end{array}$$We could represent the various matrices in terms of a subscript for their size and a superscript for their magic sum. This is purely my own invention but it means we would have: M\(_3^{15}\)M\(_3^{18}\) and M\(_3^{26097} \) where M is any matrix that satisfies the condition of being magic and having a particular size and magic sum. The \(4 \times 4\) magic square containing the numbers 1 to 15 has a magic sum of 34:$$\begin{array}{|c|c|c|c|}

\hline 16 & 2 & 3 & 13 \\

\hline 5 & 11 & 10 & 8\\

\hline 9 & 7 & 6 & 12 \\


\hline 4 & 14 & 15 & 1 \\

\hline

\end{array}$$It would be designated as M\(_4^{34}\) in my system. The subsequent magic sums that are possible are 38, 42, 46, 50 and so on. To test whether a number can be the magic constant for a \(4 \times 4\) magic square, simply subtract 34 from the number and test whether the result is divisible by 4. In the case of 26102, it is and so we have:$$\begin{array}{|c|c|c|c|}\hline 6533 & 6519 & 6520 & 6530 \\


\hline 6522 & 6528 & 6527 & 6525\\

\hline 6526 & 6524 & 6523 & 6529 \\


\hline 6521 & 6531 & 6532 & 6518 \\

\hline

\end{array}$$This magic square can be designated M\(_4^{26102}\). Figures 1 and 2 shows the magic squares together with their magic sums and associated planet or luminary.

Figure 1: source


Figure 2: source

The \(5 \times 5 \) magic square has a constant of 65 and so any subsequent multiples of 5 will be representable as \(5 \times 5 \) magic squares. The \(6 \times 6 \) magic square has a constant of 111 which is 3 x 37. This means that 117, 123, 129 etc. can be represented as \(6 \times 6 \) magic squares but these numbers are not multiples of 6. To determine whether a number can be the magic constant for a \(6 \times 6 \) magic square, the 111 must first be subtracted and the result tested for divisibility by 6. This is like the \(4 \times 4 \) case.

For the \(7 \times 7 \) magic square, the constant is 175 = 7 x 25 and so any multiple of 7 can be represented by a \(7 \times 7 \) magic square. For the \(8 \times 8 \) magic square, the constant is 260 = 4 x 65 which is not divisible by 8 and the situation is as the same as with 4 and 6. For the \(9 \times 9 \) magic square, the constant is 369 = 9 x 41 so all multiples of 9 above 369 qualify.

Figure 3 shows the magic constants for larger magic squares:


Figure 3: source

So generally, excluding 2, the prime factorisation of a number will quickly tell us what magic squares it can serve as a constant for. For example, 910 = 2 * 5 * 7 * 13 and so it can be represented by magic squares of side 5, 7 and 13. It can also be represented as a magic square with a composite number of sides but a little testing is required. For example, it can be represented as a \(4 \times 4 \) magic square but not \(8 \times 8 \). This site is great for such testing.

on May 14th 2021

Saturday 12 September 2020

Root-Mean-Square And Other Means

Today I turned 26095 days old and this number happens to be a so-called RMS number where RMS stands for Root-Mean-Square. Such numbers are defined by OEIS A140480 as numbers \(n\) such that root mean square of divisors of \(n\) is an integer. Now the root mean square of divisors is defined by MathWorld as:

For a set of \(n\) numbers or values of a discrete distribution \(x_i, ..., x_n\), the root-mean-square (abbreviated "RMS" and sometimes called the quadratic mean), is the square root of mean of the values \(x_i^2\), namely:$$x_{RMS}=\sqrt{\frac{x_1^2+x_2^2+...+x_n^2}{n}}=\sqrt{\dfrac{\sum \limits_{i=1}^n x_i^2}{n}}$$For a variate \(\chi\) from a continuous distribution \(P(x)\), we have:$$x_{RMS}=\sqrt{ \frac{\int[P(x)]^2 dx}{\int P(x) \,dx}}$$where the integrals are taken over the domain of the distribution. Similarly, for a function \(f(t)\) periodic over the interval \([T_1,T_2]\), the root-mean-square is defined as:$$f_{RMS}=\sqrt{\frac{1}{T_2-T_1}\int_{T_1}^{T_2} [f(t)]^2 dt}$$

The sequence to which 26095 belongs runs 1, 7, 41, 239, 287, 1673, 3055, 6665, 9545, 9799, 9855, 21385, 26095, ... with 7, 41 and 239 being prime and the next prime being 9369319. Such primes are known as NSW primes, after Newman, Shanks, and Williams (the authors of a paper on the subject back in 1981). If we designate \(n\) to be such a prime number, then \(n\) has 2 divisors \([1, n]\) and we have to solve Pell's equation \(n^2 = 2*C^2 - 1\) where \(C\) is a positive integer. The solution is a prime \(n\) of the form \(u_i = 6u_{i-1} - u_{i-2} \), where \(i \geq 2, u_0=1, u_1=7\). These primes are listed in OEIS A088165.

There are of course many other types of means including arithmetic, geometric, harmonic, Pythagorean, power, Heronian, Identric, population, Chisini, Stolarsky, Lehmer, weighted and so on. The arithmetic mean is certainly the best known and most widely used but the root-mean-square has many applications in scientific circles. I've encountered the root-mean-square before in the context of the root-mean-square-error (see Figure 1).


Figure 1

A regression line is a line drawn such that the RMSE is minimised (see Figure 2).

Figure 2

The root-mean-square is a particular instance of a more generalised power mean defined as:$$M_p(a_1, a_2, ..., a_n) \equiv \bigg( \frac{1}{n} \sum_{k=1}^n a_k^{\,p} \bigg)^{1/p} $$where the parameter \(p\) is an affinely extended real number and all \(a_k \geq 0\). A power mean is also known as a generalized mean, Hölder mean, or mean of degree (or order or power) \(p\). The case of \(p=1\) is the arithmetic mean and the case of \(p=2\) is the root-mean-square. 

Figure 3 shows a summary of a few particular values of \(p\) that yield special cases with their own names (source):

Figure 3

The three "classic" means \(A\) (the arithmetic mean), \(G\) (the geometric mean), and \(H\) (the harmonic mean) are sometimes known as the Pythagorean means. Figure 4 shows how these means on two elements \(a\) and \(b\) could be constructed geometrically, and also demonstrates that \(H \leq G \leq A\).


Figure 4: source

Wednesday 2 September 2020

Factorial Number System

I've titled this post Factorial Number System because I made a post titled Factorial Number Base on 31st March 2018. Strictly speaking, the factorials do not form a number base. This is explained in Wikipedia:

In combinatorics, the factorial number system, also called factoradic, is a mixed radix numeral system adapted to numbering permutations. It is also called factorial base, although factorials do not function as base, but as place value of digits. By converting a number less than n! to factorial representation, one obtains a sequence of \(n\) digits that can be converted to a permutation of \(n\) in a straightforward way, either using them as Lehmer code or as inversion table representation; in the former case the resulting map from integers to permutations of \(n\) lists them in lexicographical order. General mixed radix systems were studied by Georg Cantor. The term "factorial number system" is used by Knuth, while the French equivalent "numération factorielle" was first used in 1888. The term "factoradic", which is a portmanteau of factorial and mixed radix, appears to be of more recent date.

My interest in the subject was rekindled when I came across this OEIS entry for 26085 (I turned 26085 days old today):

A286590: Numbers that are divisible by the product of their factorial base digits (A208575).

In my 2018 post, I treated this number system rather narrowly so I am broadening my scope in this current post. Figure 1 shows an easy way to convert from a decimal number to its factorial representation:


Using this method, the following SageMath code will carry out the conversion (input is shown in blue and output in red):

# -------------------------------------------------------
# decimal to factorial base conversion with trailing zero
# -------------------------------------------------------
number=26085
entry=number
L,n,dividend=[],1,1
while dividend!=0:
    dividend=int(number/n)
    remainder=number%n
    L.append(remainder)
    number=dividend
    n+=1
L.reverse()
print(entry,"has factorial base of",L, "with trailing zero")
# ----------------------------------------------------------
# decimal to factorial base conversion without trailing zero
# ----------------------------------------------------------
number=26085
L,n,dividend=[],2,1
while dividend!=0:
    dividend=int(number/n)
    remainder=number%n
    L.append(remainder)
    number=dividend
    n+=1
L.reverse()
print(entry,"has factorial base of",L, "without trailing zero")  
 
26085 has factorial base of [5, 1, 1, 1, 3, 1, 1, 0] with trailing zero
26085 has factorial base of [5, 1, 1, 1, 3, 1, 1] without trailing zero

Here is the permalink to SageMathCell. Notice the two possible representations: \(51113110_!\) and   \(5111311_!\). This is because "The factorial number system is sometimes defined with the 0! place omitted because it is always zero" (Wikipedia). The conversion from factorial representation to decimal is quite straightforward. Here is the SageMath code (permalink):

# ---------------------------------------------------------
# factorial base (with trailing zero) to decimal conversion 
# ---------------------------------------------------------
number=51113110
D=number.digits()
decimal,n=0,0
for d in D:
    decimal+=d*factorial(n)
    n+=1
print(decimal)
# ------------------------------------------------------------
# factorial base (without trailing zero) to decimal conversion 
# ------------------------------------------------------------
number=5111311
D=number.digits()
decimal,n=0,1
for d in D:
    decimal+=d*factorial(n)
    n+=1
print(decimal)

26085
26085

Wikipedia goes on to say:
The factorial number system provides a unique representation for each natural number, with the given restriction on the "digits" used. No number can be represented in more than one way because the sum of consecutive factorials multiplied by their index is always the next factorial minus one:$$\sum_{i=0}^n i \times i!=(n+1)!-1$$
This can be easily proved with mathematical induction, or simply by noticing that :$$\forall i,i \times i!=(i+1-1) \times i!=(i+1)!-i!$$where subsequent terms cancel each other, leaving the first and last term (see Telescoping series).
However, when using Arabic numerals to write the digits (and not including the subscripts as in the above examples), their simple concatenation becomes ambiguous for numbers having a "digit" greater than 9. The smallest such example is the number 10 × 10! = 36,288,00010, which may be written A0000000000!=10:0:0:0:0:0:0:0:0:0:0!, but not 100000000000! = 1:0:0:0:0:0:0:0:0:0:0:0! which denotes 11! = 39,916,80010. Thus using letters A–Z to denote digits 10, 11, 12, ..., 35 as in other base-N make the largest representable number 36 × 36! − 1. 
For arbitrarily greater numbers one has to choose a base for representing individual digits, say decimal, and provide a separating mark between them (for instance by subscripting each digit by its base, also given in decimal, like 24031201, this number also can be written as 2:0:1:0!). In fact the factorial number system itself is not truly a numeral system in the sense of providing a representation for all natural numbers using only a finite alphabet of symbols, as it requires an additional separation mark.

There's a lot more that could be said about this topic and I may add to it in the future. In conclusion, DCODE provides a quick conversion tool from decimal to factorial base and back again. It's an interesting site that I've used before but had forgotten about. It's a site well worth exploring.