mersenneforum.org  

Go Back   mersenneforum.org > Great Internet Mersenne Prime Search > Math

Reply
 
Thread Tools
Old 2012-08-13, 13:16   #1
alpertron
 
alpertron's Avatar
 
Aug 2002
Buenos Aires, Argentina

2×683 Posts
Default Possible optimization for GIMPS

Please correct me if I'm wrong, because I have not programmed FFT.

The main loop of LL proceeds by squaring the number and subtracting 2 mod 2p-1. The square is done by peforming two transforms, a convolution and an inverse transform using IBDWT.

I think that by using Fermat tests (in base 3 for example), where only exponentiations are needed, we could eliminate the need for transforms and inverse transforms. So only convolutions are done in the main loop which are a lot faster.

Then we could perform LL only for the pseudoprimes (a tiny fraction of the tests).

Is this approach correct?
alpertron is offline   Reply With Quote
Old 2012-08-13, 13:35   #2
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

1C3516 Posts
Default

I'm assuming you mean this: http://en.wikipedia.org/wiki/Fermat_primality_test

Note two things: First, you must take a^(x-1), where x itself is 2^p-1 for large p. Not a smart idea.

Second: How do you do an exponentiation?
Quote:
Originally Posted by Fermat test article
Using fast algorithms for modular exponentiation, the running time of this algorithm is O(k × log2 n × log log n × log log log n), where k is the number of times we test a random a, and n is the value we want to test for primality.
Note that we are testing n=2^p-1, so log n~p.
The LL test with FFT muls has complexity O(p2 × log p × log log p), which is about the same as the same as the Fermat test once you substitute log n~p (and the LLT is deterministic).

You do exponentiation with lots of squaring and multiplication. After all, exponentiation is repeated multiplications by definition, and the LL test is already down to the relatively cheap p-2 squarings per test.

Quote:
Originally Posted by exp by square
A brief analysis shows that such an algorithm uses log n squarings and at most log n multiplications.
Substituting log n ~ p, then we have p squarings plus some other multiplications, up to p of them. So p-2 squarings is really as low as we can get.

(I'm not confident of this last part, but it's possible that the LL test can be derived from the Fermat test with base 2 or something, and some of the specific algorithms for exponentiation.)

PS "only convolutions" is meaningless with respect to multiplication without doing a transform. It's like saying 6235*4865 == 6*4 2*8 3*6 5*5 == 24 16 18 25 == (with carrying) 25805, which is patently not the actual product of 30333275.

Last fiddled with by Dubslow on 2012-08-13 at 13:38
Dubslow is offline   Reply With Quote
Old 2012-08-13, 13:52   #3
alpertron
 
alpertron's Avatar
 
Aug 2002
Buenos Aires, Argentina

25268 Posts
Default

My idea is to perform one transform at the beginning, then perform the convolutions for each loop and then the inverse transform at the end. I do not want to reduce the number of multiplications but the timing for each multiplication.

Since multiple convolutions will generate very big numbers, we could separate the exponent from the mantissa.

Edit: I do not know if this approach would work because of floating point approximation errors. Maybe we could do inverse and direct transforms every few iterations.

Last fiddled with by alpertron on 2012-08-13 at 14:25
alpertron is offline   Reply With Quote
Old 2012-08-13, 16:08   #4
axn
 
axn's Avatar
 
Jun 2003

2·3·7·112 Posts
Default

Quote:
Originally Posted by alpertron View Post
Is this approach correct?
Short answer: no.

Long answer: You should program DFT (which is mathematically same as FFT, but much less efficient) and observe how things work.
axn is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
gcc optimization/intrinsics R.D. Silverman Factoring 12 2015-09-15 08:51
Program optimization henryzz Programming 17 2012-09-26 13:21
Size optimization Sleepy Msieve 14 2011-10-20 10:27
NFS Optimization R.D. Silverman Factoring 91 2010-01-24 20:48
ASM Optimization Cyclamen Persicum Hardware 4 2004-05-26 07:51

All times are UTC. The time now is 17:07.


Mon Aug 2 17:07:21 UTC 2021 up 10 days, 11:36, 0 users, load averages: 2.35, 2.29, 2.24

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.