19
$\begingroup$

Bug introduced in 9 and fixed in 11.1


I get a hit on performance with the Exp function depending on the range of my inputs. for example, with:

w1 = RandomComplex[-20000 I, {10000000}];
Exp[w1]; // Timing

w2 = RandomComplex[-20 I, {10000000}];
Exp[w2]; // Timing

Results in 2.4 and 0.4 sec respectively. What mystifies me is that the involved numbers are not in a numerically "interesting" range.

The transition to slower times starts gradually at about -500 I and asymptotically stabilizes by about -10000 I. Past these ranges the timings are stable:

w = RandomComplex[-I, {1000000}];
t = Table[{10^n, Timing[Exp[10^n w]][[1]]}, {n, 1.5, 5, .01}];
ListLogLinearPlot[t, AxesLabel -> {"Scaling", "Time"}]

Any ideas what might be happening here? Any simple fixes to get faster performance with high scaling factors?

$\endgroup$
16
  • $\begingroup$ You could try writing it explicitly in terms of Sin/Cos. $\endgroup$
    – Szabolcs
    Commented May 16, 2014 at 17:56
  • 1
    $\begingroup$ I do not see this effect in version 8.0.4 on OS X. Both timings are about the same (to within three digits), and the timing plot shows just an increase in the variance of the timings, not really a trend. All times in the plot are below .066 on my computer. $\endgroup$
    – Jens
    Commented May 16, 2014 at 18:20
  • 1
    $\begingroup$ I do see this on OS X/M9.0.1 to a great extent on one computer, to a smaller one on another. I don't see it on OSX/M8.0.4. I do see it on Windows8/M9.0.1. I do see it on Ubuntu 14.04/M9.0.1. Performance is much better on Windows (despite running in VirtualBox) than on Mac/Linux (nearly 3x better) despite running on the same machine. CPU is "Intel(R) Core(TM) i7-3720QM CPU @ 2.60GHz". $\endgroup$
    – Szabolcs
    Commented May 16, 2014 at 18:48
  • 1
    $\begingroup$ It appears that Exp[I x] slows down for Abs[x] >= 512. The transition is clearer like this: w = ConstantArray[N[I], {5000000}]; t = Table[{n, Timing[Exp[n w]][[1]]}, {n, 510, 514, 0.1}] $\endgroup$ Commented May 17, 2014 at 13:14
  • 2
    $\begingroup$ @SimonWoods:Interesting find! A similar step then happens at 2^30 (and then not until 2^100 where I stopped measuring). I suppose that's where Mathematica "shifts gears" – takes on a different algorithm. With the OP's case it can then be seen that for 10^n < 512, all the random numbers are within the safe interval. For larger n, some of them overflow 512 I and the new algorithm is only used for those. For a much larger value, almost all of them are higher than 512 so MMA is using the slower approach for almost each of the 10^7 numbers, resulting in levelling of the time at a new value. $\endgroup$
    – The Vee
    Commented Jun 12, 2016 at 0:33

1 Answer 1

4
$\begingroup$

This bug has been fixed in the just released Mathematica 11.1.

w1 = RandomComplex[-20000 I, {10000000}];
AbsoluteTiming[Exp[w1];]

w2 = RandomComplex[-20 I, {10000000}];
AbsoluteTiming[Exp[w2];]

(* {0.126897, Null} *)
(* {0.123388, Null} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.