mersenneforum.org (https://www.mersenneforum.org/index.php)
-   Software (https://www.mersenneforum.org/forumdisplay.php?f=10)
-   -   Is Mathematica really slow? (https://www.mersenneforum.org/showthread.php?t=3694)

 wakko 2005-02-10 14:32

Is Mathematica really slow?

M[p_]:=2^p-1

LL[p_]:=Module[{s,c,counter},
If[PrimeQ[p]==False,Print["The exponent must be prime"]];
s=4;
c=M[p];
counter=0;
iter=p-1;

Print["Iteration : 0 "," / ",iter];

For[i=1,i<iter,i++,
s=Mod[s^2-2,c];
counter++;
If[Mod[counter,10^3]==0,Print["Iteration : ",counter," / ",iter]]
]

If[s==0,Print["is prime"],Print["is not prime"]]

]

'---- Test run -----'
----------------------------------------------
LL[11119]//Timing

Iteration : 0 / 11118
Iteration : 1000 / 11118
Iteration : 2000 / 11118
Iteration : 3000 / 11118
Iteration : 4000 / 11118
Iteration : 5000 / 11118
Iteration : 6000 / 11118
Iteration : 7000 / 11118
Iteration : 8000 / 11118
Iteration : 9000 / 11118
Iteration : 10000 / 11118
Iteration : 11000 / 11118

" is not prime"

{15.112 Second,Null}

Hello,

I was experimenting with [I]Mathematica v5.0[/I] about the Lucas_Lehmer test.
As you can see above the code is extremely slow. It needs [B]15+[/B] sec
to test the exponent where as Prime95 only takes about [B]0.5[/B] sec.

Can someone explain why is this happening because as far as I am concerned Mathematica is believed to be one of the fastest numerical computing platforms.

Any help would be grateful.

 Mystwalker 2005-02-10 14:49

I remember that Louis Helm (one of the creators of SoB - which uses the same algorithmic implementation as Prime95) once said that an implementation in Java would be roughly 30 times slower.
I think the reason here is similar: The speed difference (incidently 30 times as well) supposely comes from the fact that Mathematica's routines are not hand-optimized for this exact purpose and architecture (does Mathematica use SSE2/FFTs/IBDWT?). In addition, I believe some "tricks" prime95 uses can only be applied due to special properties of mersenne numbers. Mathematica can't take that into account, I guess.

 jinydu 2005-02-10 20:51

Mathematica is slow in other things too. It took Mathematica hours to compute just 25,000 digits of Zeta(3). Other programs can do it in a fraction of a second on the same computer.

 grandpascorpion 2005-02-10 23:16

Is Maple faster in general?

 wakko 2005-02-11 01:45

I am trying to comprehent the deeper things apon LL, that experiment showed me a lot.

Mayber I'll try something hand-optimized..

CU later sievers

 mattprim 2021-02-09 16:46

I excluded giant Mersenne with Mathematica

I managed to exclude a giant Mersennes with Mathematica [url]https://www.mersenneforum.org/showthread.php?t=26477&highlight=Mathematica[/url] Pity I later learned they were both known but with Monte Carlo it worked below a Ghz x Minute and they are both above the biggest 2021 Mersenne prime known.

 VBCurtis 2021-02-09 16:52

"excluded" = trial-factored. Trial-factoring is not at all related to a primality test, and comparing the speed of those two things is akin to someone asking what the 99th power of 99 is, and you answering "Well, I added 99 and 99 really fast!"

 All times are UTC. The time now is 14:28.