mersenneforum.org (https://www.mersenneforum.org/index.php)
-   Math (https://www.mersenneforum.org/forumdisplay.php?f=8)
-   -   Question about selection of a in the P-1 algorithm (https://www.mersenneforum.org/showthread.php?t=26308)

 ZFR 2020-12-14 21:05

Question about selection of a in the P-1 algorithm

From [URL]https://www.mersenne.org/various/math.php[/URL]

[QUOTE]
The P-1 method is quite simple. In stage 1 we pick a bound B1. P-1 factoring will find the factor q as long as all factors of k are less than B1 (k is called B1-smooth). We compute E – the product of all primes less than B1. Then we compute x = 3[SUP]E*2*P[/SUP]. Finally, we check the GCD (x-1, 2[SUP]P[/SUP]-1) to see if a factor was found.
[/QUOTE]When computing x, why are we taking 3[SUP]E*2*P[/SUP] instead of 2[SUP]E*2*P[/SUP]?

Wouldn't any coprime number do? If so, why not choose the smaller one?

 R. Gerbicz 2020-12-15 00:53

The reason: 2^(E*2*p)==1 mod 2^p-1.

 kriesel 2020-12-15 01:30

[QUOTE=ZFR;566179]From [URL]https://www.mersenne.org/various/math.php[/URL]

When computing x, why are we taking 3[SUP]E*2*P[/SUP] instead of 2[SUP]E*2*P[/SUP]?

Wouldn't any coprime number do? If so, why not choose the smaller one?[/QUOTE]
E is not just the product of the primes < B1, it's the product of maximum integral powers of each prime fitting < B1 individually, called powersmooth.
The exponentiation [B]a[/B][SUP]E*2*p[/SUP] is done mod Mp. So smaller [B]a[/B] doesn't really save run time, or operand size after relatively few operations. In practice the exponentiation is done with a full length fft transform from the start, so it saves no run time to use a smaller base.
[URL="https://en.wikipedia.org/wiki/Pollard%27s_p_%E2%88%92_1_algorithm"]https://en.wikipedia.org/wiki/Pollard%27s_p_%E2%88%92_1_algorithm[/URL]
As to why not 2 instead of 3, there's a small-numbers example early in [URL]https://magazine.odroid.com/article/prime-number-discovery-use-odroid-c2-make-mathematical-history/[/URL] Later on, this same source includes, also in the context of primality testing, rather than P-1 factoring, the following:
[CODE]In the more general context of testing numbers of arbitrary size, however,
it is important to realize that there are certain classes of numbers, all
of which are Fermat base-2 pseudoprimes, irrespective of whether they are
prime or composite. The two best-known such classes are, firstly, the
Mersenne numbers M(p) = 2[SUP]p[/SUP]−1 (for which we restrict the definition to prime
exponents since that is required for a number of this form to have a chance
of being prime); for example, 2[SUP]11[/SUP]−1 passes the test even though it factors as
23 × 89. The second class of such numbers is the Fermat numbers[/CODE]

 LaurV 2020-12-15 08:44

[QUOTE=kriesel;566200] the product of maximum integral powers of each prime fitting < B1 individually[/QUOTE]
Haha, so complicate said. E is the LCM(x such as x<=B1). The "power trick" just happens to be the fastest known way to calculate it.

 ZFR 2020-12-15 09:36

Ah, OK. So for base a=2 we'll have pseudoprimes only because 2^(E*2*p) is always 1 mod 2^p-1

Thanks, everyone.

Thanks for the article link, kriesel.

 kriesel 2020-12-15 21:28

[QUOTE=LaurV;566239]Haha, so complicate said. E is the LCM(x such as x<=B1). The "power trick" just happens to be the fastest known way to calculate it.[/QUOTE]Instead of criticizing from the stands, try entering the arena. "It is not the critic who counts; not the man who points out how the strong man stumbles, or where the doer of deeds could have done them better. The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood; who strives valiantly; who errs, who comes short again and again, because there is no effort without error and shortcoming; but who does actually strive to do the deeds; who knows great enthusiasms, the great devotions; who spends himself in a worthy cause; who at the best knows in the end the triumph of high achievement, and who at the worst, if he fails, at least fails while daring greatly, so that his place shall never be with those cold and timid souls who neither know victory nor defeat."
[url]https://www.mentalfloss.com/article/63389/roosevelts-man-arena[/url]

 ewmayer 2020-12-15 23:30

@OP: Suggest you try a tiny M(p) example: n = M(11) = 2^11-1 = 23*89. The 2 prime factors have p-1 decompositions:

p = 23: p-1 = 2*11
q = 89: q-1 = 2^3*11

So taking E = 2*11 in p-1 stage 1 should turn up the smaller factor, i.e. in this case we don't even need any of the other smaller primes, just the 2*p bit, in E. Try it to the 2 bases in question and see what happens.

 jnml 2020-12-16 10:29

[QUOTE=kriesel;566313]Instead of criticizing from the stands, try entering the arena. "It is not the critic who counts; not the man who points out how the strong man stumbles, or where the doer of deeds could have done them better. The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood; who strives valiantly; who errs, who comes short again and again, because there is no effort without error and shortcoming; but who does actually strive to do the deeds; who knows great enthusiasms, the great devotions; who spends himself in a worthy cause; who at the best knows in the end the triumph of high achievement, and who at the worst, if he fails, at least fails while daring greatly, so that his place shall never be with those cold and timid souls who neither know victory nor defeat."
[url]https://www.mentalfloss.com/article/63389/roosevelts-man-arena[/url][/QUOTE]

Please don't overreact. AFAICS, LaurV's comment talked about no _person_ at all and
I believe having opinions about _ideas_ is always fine.

 ZFR 2020-12-16 10:32

[QUOTE=ewmayer;566325]@OP: Suggest you try a tiny M(p) example: n = M(11) = 2^11-1 = 23*89. The 2 prime factors have p-1 decompositions:

p = 23: p-1 = 2*11
q = 89: q-1 = 2^3*11

So taking E = 2*11 in p-1 stage 1 should turn up the smaller factor, i.e. in this case we don't even need any of the other smaller primes, just the 2*p bit, in E. Try it to the 2 bases in question and see what happens.[/QUOTE]

Thanks.

gcd(4194303, 2047) = 2047
gcd(31381059608, 2047) = 23

So using base 2 gives us n, while using base 3 gives us the right answer.

I played around with some other Mersenne numbers. The gcd always returns n.

I might be overlooking something very obvious here, but I'm still missing one step.

How does
2^(E*2*p)==1 mod 2^p-1.
imply that
gcd(2^(E*2*p)-1, 2^p-1) = 2^p -1

 axn 2020-12-16 10:37

[QUOTE=ZFR;566363]How does
2^(E*2*p)==1 mod 2^p-1.
imply that
gcd(2^(E*2*p)-1, 2^p-1) = 2^p -1[/QUOTE]

2^(E*2*p)==1 mod 2^p-1
==>
2^(E*2*p)-1 == 0 mod 2^p-1

Therefore gcd(2^(E*2*p)-1, 2^p-1) = gcd(0, 2^p-1) = 2^p-1

 ZFR 2020-12-16 10:53

[QUOTE=axn;566364]2^(E*2*p)==1 mod 2^p-1
==>
2^(E*2*p)-1 == 0 mod 2^p-1

Therefore gcd(2^(E*2*p)-1, 2^p-1) = gcd(0, 2^p-1) = 2^p-1[/QUOTE]

OK, thanks for explaining. Yeah, it's pretty basic, I can be blind at times.

One last question: when Prime95 does the P-1 algorithm, that time-consuming part of it would be the exponentiation of 3 (and modulo n)? The gcd itself is pretty fast comparatively, right?

All times are UTC. The time now is 13:54.