mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   PARI/GP (https://www.mersenneforum.org/forumdisplay.php?f=155)
-   -   PARI's commands (https://www.mersenneforum.org/showthread.php?t=13636)

science_man_88 2010-09-07 22:07

[QUOTE=CRGreathouse;228940]Depends on what size primes you store and how you store them, naturally.[/QUOTE]

well if we encode it as characters for each digit it gets inefficient real quick (almost like BCD in ASM I think), I don't know the best way to encode them efficiently unless maybe we convert them to hex to take less room than the decimal and hex or another power of 2 base is easier for me to convert to binary(yes I've learned that part lol).

CRGreathouse 2010-09-07 22:24

[QUOTE=science_man_88;228942]well if we encode it as characters for each digit it gets inefficient real quick (almost like BCD in ASM I think), I don't know the best way to encode them efficiently unless maybe we convert them to hex to take less room than the decimal and hex or another power of 2 base is easier for me to convert to binary(yes I've learned that part lol).[/QUOTE]

So store them natively in binary, taking k bits to store (naturally!) a k-bit prime. You can even do better: store all but the last bit, unless the prime is 2, in which case store it as 0.

You'll need some way to delimit the primes, though.

science_man_88 2010-09-07 22:30

[QUOTE=CRGreathouse;228946]So store them natively in binary, taking k bits to store (naturally!) a k-bit prime. You can even do better: store all but the last bit, unless the prime is 2, in which case store it as 0.

You'll need some way to delimit the primes, though.[/QUOTE]

let me guess the last bit won't matter as it will always be one except when the decimal representation of the prime is 2. yeah what to separate them in storage with.

CRGreathouse 2010-09-07 22:49

[QUOTE=science_man_88;228948]let me guess the last bit won't matter as it will always be one except when the decimal representation of the prime is 2. yeah what to separate them in storage with.[/QUOTE]

One way would be to used fixed width. Store only 65-bit primes, so every 64 bits is a new prime. There are 412246861431389469 65-bit primes, so you shouldn't run out... unless you have more than 206123 TB.

You could even left-pad with 0s and include primes of up to 65 bits. This gives you 837903145466607212 to work with (and moves the storage for all of them to 418951 TB).

science_man_88 2010-09-07 23:37

[CODE]a=0;forallprime(1,2^100,p->a=a+1;if(ispower(p+1),print(ispower(p+1)","p","a)))[/CODE]

this can't be efficient

CRGreathouse 2010-09-07 23:55

There are many more primes than (proper) powers, and as it happens ispower is a lot slower than isprime. So if you're able, set up the loop the other way: loop over powers and check the the primality of n-1.

This way you're checking something like 1.126 * 10[SUP]15[/SUP] numbers instead of 1.267 * 10[SUP]30[/SUP].

Edit: 1125910730446094 instead of 1.856(1) * 10[SUP]28[/SUP], assuming (wrongly) that you've precalculated primes up to 2[SUP]100[/SUP].

axn 2010-09-08 00:38

[QUOTE=CRGreathouse;228962]There are many more primes than (proper) powers, and as it happens ispower is a lot slower than isprime. So if you're able, set up the loop the other way: loop over powers and check the the primality of n-1.[/QUOTE]

Two words. Algebraic factors. Zero clock cycles.

CRGreathouse 2010-09-08 00:43

[QUOTE=axn;228965]Two words. Algebraic factors. Zero clock cycles.[/QUOTE]

I was actually more interested in the general issue of looping over primes and powers than the specific one of finding primes one less than a power.

science_man_88 2010-09-08 01:12

[QUOTE=axn;228965]Two words. Algebraic factors. Zero clock cycles.[/QUOTE]

I can't even remember the think other than 2kp+1 that anyone told me lol.

CRGreathouse 2010-09-08 01:21

The suggestion was that b - 1 is a factor of b^k - 1, so unless b = 2 this cannot be a prime. If b = 2 then you're just looking for Mersenne primes.

science_man_88 2010-09-08 01:42

best I can do of summing up the LL test is:

s=2*y*(2*k*p+1) s=4*y*k*p+(2*y)

but this is useless obviously


All times are UTC. The time now is 23:15.

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