mersenneforum.org  

Go Back   mersenneforum.org > Math Stuff > Computer Science & Computational Number Theory > PARI/GP

Reply
 
Thread Tools
Old 2010-09-07, 22:07   #1343
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
Depends on what size primes you store and how you store them, naturally.
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).
science_man_88 is offline   Reply With Quote
Old 2010-09-07, 22:24   #1344
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

597910 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
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).
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.
CRGreathouse is offline   Reply With Quote
Old 2010-09-07, 22:30   #1345
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
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.
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.
science_man_88 is offline   Reply With Quote
Old 2010-09-07, 22:49   #1346
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

175B16 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
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.
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).

Last fiddled with by CRGreathouse on 2010-09-07 at 22:50
CRGreathouse is offline   Reply With Quote
Old 2010-09-07, 23:37   #1347
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Code:
a=0;forallprime(1,2^100,p->a=a+1;if(ispower(p+1),print(ispower(p+1)","p","a)))
this can't be efficient
science_man_88 is offline   Reply With Quote
Old 2010-09-07, 23:55   #1348
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

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 * 1015 numbers instead of 1.267 * 1030.

Edit: 1125910730446094 instead of 1.856(1) * 1028, assuming (wrongly) that you've precalculated primes up to 2100.

Last fiddled with by CRGreathouse on 2010-09-08 at 00:18
CRGreathouse is offline   Reply With Quote
Old 2010-09-08, 00:38   #1349
axn
 
axn's Avatar
 
Jun 2003

5,087 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
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.
Two words. Algebraic factors. Zero clock cycles.
axn is offline   Reply With Quote
Old 2010-09-08, 00:43   #1350
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by axn View Post
Two words. Algebraic factors. Zero clock cycles.
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.
CRGreathouse is offline   Reply With Quote
Old 2010-09-08, 01:12   #1351
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by axn View Post
Two words. Algebraic factors. Zero clock cycles.
I can't even remember the think other than 2kp+1 that anyone told me lol.
science_man_88 is offline   Reply With Quote
Old 2010-09-08, 01:21   #1352
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

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.
CRGreathouse is offline   Reply With Quote
Old 2010-09-08, 01:42   #1353
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

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
science_man_88 is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why do I sometimes see all the <> formatting commands when I quote or edit? cheesehead Forum Feedback 3 2013-05-25 12:56
Passing commands to PARI on Windows James Heinrich Software 2 2012-05-13 19:19
Ubiquity commands Mini-Geek Aliquot Sequences 1 2009-09-22 19:33
64-bit Pari? CRGreathouse Software 2 2009-03-13 04:22
Are these commands correct? jasong Linux 2 2007-10-18 23:40

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


Fri Aug 6 23:12:56 UTC 2021 up 14 days, 17:41, 1 user, load averages: 4.28, 4.23, 4.06

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.