mersenneforum.org  

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

Reply
 
Thread Tools
Old 2010-08-11, 15:48   #243
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

100000110000002 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
@Sm88: Did you define what the Mersennes are? (Or at least Mersenne_Primes(n)?)
the code for it will figure it out so the best I can do right now(off the top of my head) is:

Code:
a=0;for(p=1,x,if(isprime(p) && isprime(2^p-1),a=a+1;print(p);if(a==n,break();))
but I haven't figured out how to do my method suggested earlier involving indexes of A002450 or A121290.
science_man_88 is offline   Reply With Quote
Old 2010-08-11, 15:48   #244
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24×3×5×7 Posts
Default

Quote:
Originally Posted by CRGreathouse
The naive method would test all ~4e97 bases. Each base would require the calculation of b^(n-1) mod n. These take about a millisecond each, for a total of ~4e94 seconds or ~1e85 lifetimes. Factoring n, if it wasn't written as above, could be done in a few hours. Big win for 'my' method.
Okay. But it would be rendered useless for any number larger than about 90-105 or so digits. I was right about it being unnecessary for larger integers.

Also: @Sm88: Isn't it supposed to be
Code:
a=0;forprime(p=1,x,if(isprime(p) && isprime(2^p-1),a=a+1;print(p);if(a==n,break();))
?

(My emphasis in red.)

Last fiddled with by 3.14159 on 2010-08-11 at 15:51
3.14159 is offline   Reply With Quote
Old 2010-08-11, 15:54   #245
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

100000110000002 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
Also: @Sm88: Isn't it supposed to be
Code:
a=0;forprime(p=1,x,if(isprime(p) && isprime(2^p-1),a=a+1;print(p);if(a==n,break();))
?
only if you know before hand x is under primelimit if it isn't forprime may not work as it uses primes[i] last I checked. so if you don't already have all the primes needed calculated it must calculate them on the fly and the isprime(p) would need to be eliminated if you use forprime as it's not needed until after exhausting primelimit.

Last fiddled with by science_man_88 on 2010-08-11 at 15:57
science_man_88 is offline   Reply With Quote
Old 2010-08-11, 15:57   #246
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
Okay. But it would be rendered useless for any number larger than about 90-105 or so digits. I was right about it being unnecessary for larger integers.
When I said larger integers, I meant integers larger than 2^32, since anything larger will cause problems at word precision for 32-bit computers. If you're using a 64-bit Linux system (the Windows version is 32-bit even on 64-bit computers) then the problem crops up above 2^64 or so. Since those ranges are quite factorable, it *is* relevant.

But even if you were concerned only about numbers below 2^32 ~ 4e9, I still wouldn't recommend using a complicated inelegant method.

Last fiddled with by CRGreathouse on 2010-08-11 at 15:58
CRGreathouse is offline   Reply With Quote
Old 2010-08-11, 15:59   #247
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

10111010110112 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
only if you know before hand x is under primelimit if it isn't forprime may not work as it uses primes[i] last I checked. so if you don't already have all the primes needed calculated it must calculate them on the fly and the isprime(p) would need to be eliminated if you use forprime as it's not needed until after exhausting primelimit.
It uses the list of primes, yes. It doesn't call prime(i) which is actually pretty inefficient 'under the hood' as I recall.

And if you did use forprime, you wouldn't need to have isprime(p), just isprime(2^p-1).
CRGreathouse is offline   Reply With Quote
Old 2010-08-11, 16:02   #248
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
It uses the list of primes, yes. It doesn't call prime(i) which is actually pretty inefficient 'under the hood' as I recall.

And if you did use forprime, you wouldn't need to have isprime(p), just isprime(2^p-1).
yes and if x> primelimit it would hand out :not enough primes precomputed or what ever it says. so if x>primelimit the isprime(p) is needed.

this is something the code creating script would have to figure out to give the most efficient codes.

Last fiddled with by science_man_88 on 2010-08-11 at 16:03
science_man_88 is offline   Reply With Quote
Old 2010-08-11, 16:07   #249
axn
 
axn's Avatar
 
Jun 2003

5,087 Posts
Default

An interesting aside:
Code:
nu=valuation(f[1]-1,2);
for(i=2,#f,nu=min(nu,valuation(f[i]-1,2))
can be replaced by
Code:
nu=valuation(f-vectorv(#f,X,1),2)
vectorv, because f is a column vector (and because PARI doesn't support vector/scalar addition).
axn is offline   Reply With Quote
Old 2010-08-11, 16:10   #250
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Code:
(12:03) gp > nu=valuation(f-vectorv(#f,X,1),2)
  *** _-_: forbidden addition t_POL + t_COL.
doesn't look like it.

and your first one came back syntax errors then I fixed it and :

Code:
(13:10) gp > for(i=2,#f,nu=min(nu,valuation(f[i]-1,2)))
  *** for: _[_]: not a vector.
sorry forgot one thing.

Code:
(13:12) gp > nu=valuation(f[1]-1,2);for(i=2,#f,nu=min(nu,valuation(f[i]-1,2)))
  ***   _[_]: not a vector.

Last fiddled with by science_man_88 on 2010-08-11 at 16:47
science_man_88 is offline   Reply With Quote
Old 2010-08-11, 17:42   #251
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

838410 Posts
Default

so

1)read(post)
2)dissect the post into parts we can search addhelp() with for a function that it will solve it
3) post it on the forum ?
science_man_88 is offline   Reply With Quote
Old 2010-08-11, 17:52   #252
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24×3×5×7 Posts
Default

Excellent.

A small inconvenience:

Here is a code snippet that allows me to search for 2nd kind Cunningham semiprimes (Of the form 2p2-p that are pseudoprime to base 2):

Code:
modbmpsp(x,n,m)=if(isPRP(modbm(x,n,m),b=2),print(modbm(x,n,m))
After it runs partially: Pari says:

Code:
***Mod: division by zero.
Here is my PRP code:

Code:
isPRP(n,b=2)={
	my(s=valuation(n-1,2),d=n>>s);
	n=Mod(b,n)^d;
	if(n==1,return(1));
	while(s--,
		if(n==-1,return(1));
		n=n^2
	);
	n==-1
};
Sorry for the question, but: Where is the code asking for a division by zero?

Last fiddled with by 3.14159 on 2010-08-11 at 17:54
3.14159 is offline   Reply With Quote
Old 2010-08-11, 18:02   #253
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
Excellent.

A small inconvenience:

Here is a code snippet that allows me to search for 2nd kind Cunningham semiprimes (Of the form 2p2-p that are pseudoprime to base 2):

Code:
modbmpsp(x,n,m)=if(isPRP(modbm(x,n,m),b=2),print(modbm(x,n,m))
After it runs partially: Pari says:

Code:
***Mod: division by zero.
Here is my PRP code:

Code:
isPRP(n,b=2)={
	my(s=valuation(n-1,2),d=n>>s);
	n=Mod(b,n)^d;
	if(n==1,return(1));
	while(s--,
		if(n==-1,return(1));
		n=n^2
	);
	n==-1
};
Sorry for the question, but: Where is the code asking for a division by zero?
my guess is since n is not initiated, it is taken as 0 in which case I'm guessing Mod(b,n)^d comes to 0 but I'm unsure.

Last fiddled with by science_man_88 on 2010-08-11 at 18:04
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 21:14.


Fri Aug 6 21:14:59 UTC 2021 up 14 days, 15:43, 1 user, load averages: 2.70, 2.55, 2.53

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.