Showing posts with label base 2. Show all posts
Showing posts with label base 2. Show all posts

Thursday, 10 October 2024

The Prime Constant And Beyond

A recent Numberphile video informed me of the prime constant which firstly incodes all the primes within an infinitely long sequence of 0's and 1's as shown below:$$01101010001010001010001000001010000010001010001 \dots$$The leading zero corresponds to 1 which is not prime and the next two 1's correspond to 2 and 3 that are prime and so on. The next step is to add a decimal point in front of the leading zero to get:$$0.01101010001010001010001000001010000010001010001 \dots$$This represents a number between 0 and 1 and if we interpret this as a number in base 2 we have a constant that can be expressed as (permalink):$$ \begin{align} \text{Prime Constant } &= \frac{0}{2^1}+\frac{1}{2^2}+\frac{1}{2^3}+\frac{1}{2^4} + \dots \\ \\&\approx 0.414682509851112 \dots \end{align}$$Of course, we could equally well create the non-prime constant by representing every non-prime by a 1 and every prime as a 0. This gives:$$ \text{Non-Prime Constant } \approx 0.585317490148888 \dots$$The prime constant and the non-prime constant of course add to 1. The same idea can be applied to create other constants, for example a Fibonacci constant. The Fibonacci numbers are:$$1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, \dots $$This generates a series of 0's and 1's as follows:$$ 11101001000010000000100000000000010000 \dots$$It can be seen that the three leading 1's are there because 1, 2 and 3 are Fibonacci numbers whereas 4 is not and so it represented by a 0 etc. This gives (permalink):$$ \text{Fibonacci Constant } \approx 0.910278797207866 \dots$$It can thus be seen that all monotonically increasing sequences like the sequence of prime numbers and the sequence of Fibonacci numbers can be represented by a constant between 0 and 1. The base 2 representation is arbitrary but simple but other bases could be used especially to represent more than one sequence. For example, base 4 could be used to represent primes, square-free semiprimes and sphenic numbers. So a 3 could represent a square-free semiprime, a 2 could represent a sphenic number, a 1 could represent a prime and 0 could represent a number that is none of these. This leads to another constant, let's call it the 1-2-3 Factor Constant, where we have a series of 0's, 1's, 2's and 3's:$$011012100210122010102210020013102220 \dots$$These again are converted to a number between 0 and 1:$$0.011012100210122010102210020013102220 \dots$$Interpreting this as a number in base 4 leads to (permalink):$$ \begin{align} \text{1-2-3 Factor Constant } &= \frac{0}{4^1}+\frac{1}{4^2}+\frac{1}{4^3} + \dots \\  \\ &\approx 0.0796530489502776 \dots \end{align}$$There is endless fun to be had in generating these sorts of constants from multiple sequences.

Monday, 15 May 2023

Base-2 Harshad Numbers

I've written explicitly about Harshad numbers in two previous posts: Harshad Numbers on Saturday, 11 February 2017 and Harshad Numbers Revisited on Saturday, 30 June 2018. However, I've only mentioned Base-\(n\) Harshad numbers in passing and so this post will be about them, although the focus will be on the value of \(n=2\).

I was reminded of them because the number associated with my diurnal age today, 27070, has a property that affords it membership in OEIS A330932. Let's remember that Niven numbers are another name for Harshad numbers.


  A330932

Starts of runs of 3 consecutive Niven numbers in base 2 (A049445).          


What characterises a Harshad or Niven number is that it's divisible by the sum of its digits. For example, 12 has a sum of digits of 3 and 3 divides evenly into 12. Hence 12 is a Harshad number in base 10 but what about in base 2? The binary representation of 12 is 1100 and its sum of digits is then 2 which also divides 12 and thus 12 is also a Harshad number in base 2. 

As it turns out, 12 is a Harshad number in all bases but octal where it is represented as 14. The sum of digits, 5, does not divide into 12. There are only four all-harshad numbers and they are 1, 2, 4, and 6. However, let's get back to  27070, 27071 and 27072 and check that they are indeed Harshad numbers:$$\begin{align} 27070 &= 110100110111110_2\\ \text{sum of digits }&=10\\ \frac{27070}{10} &= 2707 \\ \\27071 &= 110100110111111_2\\ \text{sum of digits }&=11\\ \frac{27071 }{11}&=2461 \\ \\ 27072 &= 110100111000000_2\\ \text{sum of digits } &= 6\\ \frac{27072}{6} &= 4512 \end{align}$$So sure enough, 27070 does begin a run of three Harshad numbers in base 2. The other members of the sequence, up to 40000, are (permalink): 623, 846, 2358, 4206, 4878, 6127, 6222, 6223, 12438, 16974, 21006, 27070, 31295, 33102, 33103, 35343, 37134, 37630, 37638.

To quote from Wikipedia:
Cooper and Kennedy proved in 1993 that no 21 consecutive integers are all harshad numbers in base 10. They also constructed infinitely many 20-tuples of consecutive integers that are all 10-harshad numbers, the smallest of which exceeds \(10^{44363342786} \).

H. G. Grundman (1994) extended the Cooper and Kennedy result to show that there are \(2b\) but not \(2b + 1\) consecutive \(b\)-harshad numbers for any base \(b\). This result was strengthened to show that there are infinitely many runs of \(2b\) consecutive b-harshad numbers for \(b = 2\) or \(3\) by T. Cai (1996) and for arbitrary b by Brad Wilson in 1997.

In binary, there are thus infinitely many runs of four consecutive Harshad numbers and in ternary infinitely many runs of six.

Runs of four consecutive base-2 Harshad numbers occur for very large numbers. I checked and there were none in the range up to one million and, I suspect, far beyond this.

Thursday, 7 January 2016

22, Reverse and Add

24384 is a member of OEIS A061561: Trajectory of 22 under the Reverse and Add! operation carried out in base 2. The terms of the sequence, up to and including 24384, are 22, 35, 84, 105, 180, 225, 360, 405, 744, 837, 1488, 1581, 3024, 3213, 6048, 6237, 12192, 12573, 24384. Even though the operations are carried out in base 2, the numbers of this sequence are shown in denary form. The actual base 2 sequence (OEIS A058042: Trajectory of binary number 10110 under the operation 'Reverse and Add!' carried out in base 2) looks like this: 

10110, 100011, 1010100, 1101001, 10110100, 11100001, 101101000, 110010101, 1011101000, 1101000101, 10111010000, 11000101101, 101111010000, 110010001101, 1011110100000, 1100001011101, 10111110100000 and on and on it goes ...

22 or 10110 is chosen as the first term because it is the smallest number whose base 2 trajectory does not contain a palindrome. So starting with 10110, the reverse is 01101 and 10110 + 11101 = 100011 and so it goes.

The equivalent sequence in base 10 starts with 196 because, according to this comment for OEIS A006960, 196 is conjectured to be the smallest initial term which does not lead to a palindrome. John Walker, Tim Irvin and others have extended the trajectory of 196 to millions of digits without finding a palindrome.

The Reverse and Add! sequence starting with 196 looks like this: 

196, 887, 1675, 7436, 13783, 52514, 94039, 187088, 1067869, 10755470, 18211171, 35322452, 60744805, 111589511, 227574622, 454050344, 897100798, 1794102596, 8746117567, 16403234045, 70446464506, 130992928913, 450822227944, 900544455998, 1800098901007 and on and on it goes ...

ADDENDUM (added 1st June 2019):
Most numbers do become palindromes fairly quickly under the reverse and add algorithm. OEIS A023109 shows the smallest number that requires exactly \(n\) iterations of Reverse and Add to reach a palindrome. The initial terms, up to \(n=55\) and starting with \(n=0\) are:

0, 10, 19, 59, 69, 166, 79, 188, 193, 1397, 829, 167, 2069, 1797, 849, 177, 1496, 739, 1798, 10777, 6999, 1297, 869, 187, 89, 10797, 10853, 10921, 10971, 13297, 10548, 13293, 17793, 20889, 700269, 106977, 108933, 80359, 13697, 10794, 15891, 1009227, 1007619, 1009246, 1008628, 600259, 131996, 70759, 1007377, 1001699, 600279, 141996, 70269, 10677, 10833, 10911


More information at this later blog post.