Showing posts with label subsets. Show all posts
Showing posts with label subsets. Show all posts

Sunday, 20 November 2022

Jupyter Notebook

I finally got around to installing SageMath on my laptop that is running Linux Mint. The installation was quite easy via this LInux Community website. I regularly use SageMathCell which is a free online instance of SageMath. It's quick and responsive but it will timeout if the calculations take too long.

Such was the case when I set out to calculate the weird numbers up to 40,000 using SageMathCell. The algorithm that I had written timed out. Figure 1 shows the algorithm that I wrote:

Figure 1

In reference to the algorithm, it's known that only abundant numbers can be weird and so I rule them out from the start. After that I simply look at all the proper subsets of the set of divisors to see if any of them sum to the number. If one of them does, then the number is pseudoperfect and we move on. It's the time taken to sum of all the elements in the subsets that is causing the algorithm to time out.

I hoped that by setting up the Jupyter notebook I wouldn't run into this timing out problem. The algorithm would use my computer's resources for as long as it took. As of writing this post, the algorithm has been chugging away for over six and a half hours. My laptop has four cores and one of them is always at 100%, though not always the same one. Figure 2 shows the situation.


Figure 2

Figure 3 shows the algorithm in the Jupyter worksheet. The black dot to the right of SageMath 9.0 at the top of the page indicates that the program is running. I find it hard to believe that the calculations haven't yet completed but I'll leave it running in the hope that it does eventually terminate.


Figure 3

There are of course ways to make this algorithm more efficient. As this source states:

All the known weird numbers are even ... a weird number multiplied by a prime larger than its sum of divisors is again weird, so there are infinitely many weird numbers. Primitive weird numbers are those which do not have a weird proper divisor. The initial ones are:

70, 836, 4030, 5830, 7192, 7912, 9272, 10792, 17272, 45356, 73616, 83312, 91388, 113072, 243892, 254012, 338572, 343876, 388076, 519712, 539744, 555616, 682592, 786208, 1188256, 1229152, 1713592, 1901728, 2081824, 2189024, 3963968, 4128448, ...

As I read this, I realised that there was no need to include odd numbers and so the processing time could be halved simply by excluding them. Furthermore, all weird numbers must have at least three distinct prime factors and so this condition could be included as well to speed up calculations. I've adjusted the algorithm in the Jupyter notebook  accordingly and restarted the calculation. See Figure 4. 


Figure 4

Actually, looking at the number of subsets involved, it's not surprising that the calculations are taking forever. Here are some examples of the numbers of subsets involved for certain numbers involved:

120 --> 32768

180 --> 131072

240 --> 524288

360 --> 8388608

720 --> 536870912

840 --> 2147483648

I had no idea that the numbers were of that magnitude.

Of course, the advantage of the notebook is that it accommodates input of data which is not possible in SageMathCell. See Figure 5.


Figure 5

Now that I have SageMath installed on my laptop I'm sure that I'll make more use of it.

Wednesday, 21 November 2018

Zumkellar Numbers, Half Zumkellar Numbers and Pseudoperfect Numbers

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 Zumkellar number. Of course \( \sigma(20) \), the sum of the divisors of 20, is 42 and so each subset sums to half of that.

If \( n \) is a Zumkeller number, then \( \sigma(n) \) is even and \(n\) is perfect or abundant. A number is abundant if the sum of its proper divisors is greater than the number. All the practical numbers \( n \), with \( \sigma(n) \) even, are also Zumkeller numbers. Here is a link to my blog post on practical numbers.

Bhakara Rao & Peng have proved several results on Zumkeller numbers such as the fact that \(n!\) is a Zumkeller numbers for \(n\ge 3 \). For example, 5! =120 and the set of divisors is {1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24, 30, 40, 60, 120}. This set can be divided into {60, 120} and {1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24, 30, 40}, both of which total 180. For what it's worth, the following YouTube video features Bhakara Rao introducing the paper that he wrote with Peng.


OEIS A083207 lists the initial Zumkeller numbers:
6, 12, 20, 24, 28, 30, 40, 42, 48, 54, 56, 60, 66, 70, 78, 80, 84, 88, 90, 96, 102, 104, 108, 112, 114, 120, 126, 132, 138, 140, 150, 156, 160, 168, 174, 176, 180, 186, 192, 198, 204, 208, 210, 216, 220, 222, 224, 228, 234, 240, 246, 252, 258, 260, 264, 270, 272, ...
In the OEIS comments for this sequence, it's stated that:
The 229026 Zumkeller numbers less than one million have a maximum difference of 12. This leads to the conjecture that any 12 consecutive numbers include at least one Zumkeller number. There are 1989 odd Zumkeller numbers less than one million; they are exactly the odd abundant numbers that have even abundance. 
Today, my diurnal age is 25434, which is a Zumkellar number, and the next one is 25440. This is a difference of only six. From the earlier statistics, it can be seen that Zumkeller numbers occur with a frequency of about 22.9% for the first one million natural numbers.

Now OEIS A246198 defines half-Zumkeller numbers as numbers whose proper positive divisors can be partitioned into two disjoint sets whose sums are equal. The comment is made that all even half-Zumkeller numbers are in OEIS A083207, i.e. they are Zumkeller numbers. The first 47 terms coincide with A083207. 225 is the first number in the sequence that is not a Zumkeller number. The set of proper divisors of 225 is {1, 3, 5, 9, 15, 25, 45, 75} and this can be divided into two disjoint sets, {9, 75, 5} and {25, 3, 1, 45, 15} both totalling 89.

OEIS A005835 describes the pseudoperfect (or semiperfect) numbers as those in which some subset of the proper divisors of n sums to n. It's noted in the comments that deficient numbers cannot be pseudoperfect and that the first odd pseudoperfect number is 945. In the case of 945, the proper divisors are {1, 3, 5, 7, 9, 15, 21, 27, 35, 45, 63, 105, 135, 189, 315} and there are five subsets of these divisors that add to 945. Here is the list:
  • {1, 9, 21, 27, 35, 45, 63, 105, 135, 189, 315}
  • {3, 7, 21, 27, 35, 45, 63, 105, 135, 189, 315}
  • {7, 9, 15, 27, 35, 45, 63, 105, 135, 189, 315}
  • {1, 3, 5, 7, 15, 27, 35, 45, 63, 105, 135, 189, 315} 
  • {1, 5, 7, 9, 15, 21, 35, 45, 63, 105, 135, 189, 315} 
While nearly all abundant numbers are pseudoperfect, some aren't. These numbers are termed weird and comprise OEIS A006037: weird numbers - abundant (A005101) but not pseudoperfect (A005835). From the comments to this sequence in the OEIS, we find:
Deléglise (1998) shows that abundant numbers have asymptotic density < 0.2480, resolving the question which he attributes to Henri Cohen of whether the abundant numbers have density greater or less than 1/4. The density of pseudoperfect numbers is the difference between the densities of abundant numbers (A005101) and weird numbers (A006037), since the remaining integers are perfect numbers (A000396), which have density 0. Using the first 22 primitive pseudoperfect numbers (A006036) and the fact that every multiple of a pseudoperfect number is pseudoperfect it can be shown that the density of pseudoperfect numbers is > 0.23790.
There are other interesting facts mentioned in the comments, including:
  • The first weird number that has more than one decomposition of its divisors set into two subsets with equal sum (and thus is not a member of A083209) is 10430:
  1+5+7+10+14+35+298+10430 = 2+70+149+745+1043+1490+2086+5215
  2+70+298+10430 = 1+5+7+10+14+35+149+745+1043+1490+2086+5215.
  • A weird number n multiplied with a prime \( p > \sigma(n) \) is again weird. Primitive weird numbers (A002975) are those which are not a multiple of a smaller term, i.e., don't have a weird proper divisor.
  • No odd weird number exists below \(10^{21}\).
One thing to bear in mind about all the types of numbers mentioned above is that they are independent of the number system base used to depict the numbers. Other types of numbers are dependent on the number base. For example, a d-powerful number in base 10 is not necessarily a d-powerful number in another base.

Neil Sloane, the originator of the OEIS, has this to say about Reinhard Zumkellar, after whom the numbers are named:
I am deeply sorry to have to report that Reinhard Zumkeller passed away at the end of March 2016. He suffered from pancreatic cancer, which had already progressed to an advanced stage when it was diagnosed. He was a long-time contributor to the OEIS, and was later an editor and then a diligent and dedicated editor-in-chief. Between 2000 and 2016 he contributed over 23000 items to the OEIS. Reinhard was a great Haskell expert, and he was always ready to write a Haskell program and compute 10000 terms when I was studying a new sequence and wanted to see a graph. He will be greatly missed. Neil Sloane, July 3, 2016.