Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does calculating 1/(n * log(n) - n) break the computer?

Recently I stumbled on the problem Wolfram says sum diverges, but Mathematica gives a numerical value. It says that 1/(n * log(n) - n) is not summable (or does not converge mathematically to be correct). The interesting point is that we can still try to calculate the sum numerically, despite the fact that it is 'not summable'. Mathematica gives ~ 6.1 as the numerical answer.

OK. I think, let's try to reproduce that number (or something similar) in a PHP script of that series summation. My code was:

$formula = function ($n) {return 1/($n * log($n) - $n);};
$n=2;
$sum=0;

while(true) {
    $term_n = $formula($n);
    $sum += $term_n;
    if ($n++ % 100000 == 0) {
        if ($sum > 5.8)
            usleep(1000);
        echo "n=".number_format($n-1)."; sum={$sum}; error={$term_n}\n";
    }
}

My algorithm computed the answer till 5.866 and then one of two things was happening:

  1. either Ubuntu was crashing / freezing
  2. Or Linux killed my computation script process

This happened after approximately 34 million iterations.

Later I inspected how the CPU load was changing in relation to calculating more series terms.

Now, the interesting part: at approximately 22 million iterations the cores showed difficulty switching tasks between themselves: enter image description here

Later on, at approximately 33 million iterations, the cores reached a point of no return - they refused to work at all: enter image description here

The question is - What's so special about sum 5.866 that it crashes a computer? - given the fact that neither is the iteration number N very huge (just 34 million), nor the N-th term very small (just 1.7E-9) - so no reasons for a singularity.

like image 637
Agnius Vasiliauskas Avatar asked Nov 05 '18 21:11

Agnius Vasiliauskas


1 Answers

Just a guess, but it sounds like the computer is running out of memory. Your script doesn't explicitly allocate any memory, but perhaps your version of PHP has a bug and is leaking memory somehow.

If free memory were exhausted, that could indeed cause the running OS to break down, or prompt it to kill your script to protect itself.

If the system started heavily using swap space to compensate, that would stall your script momentarily, causing the fluctuations in the CPU graphs that you observe.

like image 144
Boann Avatar answered Nov 07 '22 05:11

Boann