Dear Mike.

I gratefully accept the rebuke.

I disagree with you, when you write, that you'll get slow in Mathematica if 
you step outside the standard library.
I've shown several times that it is absolutely possible to beat built-ins. 
If I had to come up with my own DivisorSigma,
I'd go with something like:

divsigma = Compile[{{lim, _Integer}}, Module[{dsum}, dsum = Table[1, {lim}];
    Do[dsum[[k]] += n, {n, 2, lim}, {k, n, lim, n}];
    dsum], RuntimeOptions -> "Speed", CompilationTarget -> "C"];


This is already faster than the built-in. 

preallocating an array of divisor sums up to e.g. 9999 an rewriting 
AmicableQ:

ds = divsigma[9999];

 

AmicableQ[n_Integer] := Block[{sum = ds[[n]] - n},
  sum != n && ds[[sum]] - sum == n
  ] 


and selecting those numbers from the range:

Plus @@ Select[Range[2, 9999], AmicableQ] // Timing


yields the correct result in 0.68s  and memory usage of 238464B, although
this can be very misleading, since it is not absolutely clear how much 
memory
really was needed, since the notebook may've introduced new stuff 
during calculation (I consider this as another weak point of Mathematica).

What I take away from this thread is, that Julia is very impressing indeed 
and I'm very
glad that from now on I do have the opportunity to switch over from 
Mathematica,
especially when it is driving me mad, which happens quite oftenly ;)

I do not have a problem with the fact, that the standard library is not 
filled with everything I may
need at some particular point.

Once again.

Thank you all for the replies, that was rather enlightening.

Cheers

Stefan

Reply via email to