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.

No comments:

Post a Comment