mersenneforum.org  

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

Reply
 
Thread Tools
Old 2010-08-24, 12:11   #815
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24·3·5·7 Posts
Default

Nevermind. I answered my own question. Okay: I can mess with the params as I wish? Cool.

Wait: Does it use the F/trial division switch?

Last fiddled with by 3.14159 on 2010-08-24 at 12:26
3.14159 is offline   Reply With Quote
Old 2010-08-24, 15:11   #816
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24·3·5·7 Posts
Default

Also: Found 268 * 4200! + 1 (13399 digits). A prime with a prime number of digits. Excellent.
3.14159 is offline   Reply With Quote
Old 2010-08-24, 15:34   #817
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

100000110000002 Posts
Default

Code:
plength(n) = forstep(x=(10^n)+1,10^(n+1),[2],if(isprime(x),return(x)))
for some reason this isn't working properly. I can get it to work as planned but then it might mess up someone else if they use it.
science_man_88 is offline   Reply With Quote
Old 2010-08-24, 15:55   #818
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

realized why now doh.
science_man_88 is offline   Reply With Quote
Old 2010-08-24, 17:59   #819
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

597910 Posts
Default

sm: It looks good to me. This is A003617(n+1), right?

Faster would be
Code:
plength(n)=nextprime(10^n)
CRGreathouse is offline   Reply With Quote
Old 2010-08-24, 18:49   #820
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
sm: It looks good to me.
well it isn't! and I know why.

Code:
(15:42) gp > plength(n) = forstep(x=(10^n)+1,10^(n+1),[2],if(isprime(x),return(x)))
%471 = (n)->forstep(x=(10^n)+1,10^(n+1),[2],if(isprime(x),return(x)))
(15:43) gp > plength(3)
%472 = 1009
(15:43) gp >
is the original result

Code:
(15:45) gp > plength(n) = forstep(x=(10^(n-1))+1,10^(n),[2],if(isprime(x),return(x)))
%473 = (n)->forstep(x=(10^(n-1))+1,10^(n),[2],if(isprime(x),return(x)))
(15:45) gp > plength(3)
%474 = 101
(15:45) gp >
see the difference the reason the original was working weird is I didn't account for 1-9 so when i put in plength(3) the first on started at 10^3 which already has 4 digits when I compensate I get the correct value.
science_man_88 is offline   Reply With Quote
Old 2010-08-24, 19:16   #821
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

20C016 Posts
Default

I also did this with your knowledge:

Code:
sumdigits(n) = if(n%9!=0,return(n%9),return(n%9+9))
but you might think it's kinda lame.
science_man_88 is offline   Reply With Quote
Old 2010-08-24, 19:47   #822
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
0 1 2 3 4 5 6 7 8 9
1 1 2 3 4 5 6 7 8 9
2 2 4 6 8 1 3 5 7 9
3 3 6 9 3 6 9 3 6 9
4 4 8 3 7 2 6 1 5 9
5 5 1 6 2 7 3 8 4 9
6 6 3 9 6 3 9 6 3 9
7 7 5 3 1 8 6 4 2 9
8 8 7 6 5 4 3 2 1 9
9 9 9 9 9 9 9 9 9 9
if i did my math correct this is the sum of digits multiplication table.

Last fiddled with by science_man_88 on 2010-08-24 at 19:50
science_man_88 is offline   Reply With Quote
Old 2010-08-24, 19:57   #823
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

135338 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
I also did this with your knowledge:

Code:
sumdigits(n) = if(n%9!=0,return(n%9),return(n%9+9))
but you might think it's kinda lame.
This only works for n < 100. For larger numbers, try
Code:
dsum(n,b=10)={
  my(s=0);
  while(n>=b,
    s += n%b;
    n \= b;
  );
  s+n
};
addhelp(dsum, "dsum(n,{b=10}): Sum of the base-b digits of n.");
A more efficient version would work mod 100 or 1000 using a lookup table, and use divrem rather than \ and %. A really efficient version would split the values into two parts of roughly equal length until they became 'small' (say, less than a googol).

Last fiddled with by CRGreathouse on 2010-08-24 at 20:04
CRGreathouse is offline   Reply With Quote
Old 2010-08-24, 20:02   #824
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
see the difference the reason the original was working weird is I didn't account for 1-9 so when i put in plength(3) the first on started at 10^3 which already has 4 digits when I compensate I get the correct value.
Because you didn't explain what the function was supposed to do, you didn't have a help message, and the name wasn't self-explanatory, I couldn't tell that this was an error rather than the intended behavior.
CRGreathouse is offline   Reply With Quote
Old 2010-08-24, 20:11   #825
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

597910 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
Also: Found 268 * 4200! + 1 (13399 digits). A prime with a prime number of digits. Excellent.
Primes with a prime number of digits... hmm. I wonder in what sense this has positive density. Of course it has natural density 0, as a subset of the primes; I don't know what its upper logarithmic density would be. If that's not positive, is there a finer measure? I wonder.

The set is 'weird' because it has huge gaps, then lots of relatively densely packed elements: no members (strictly) between 10^114 - 153 and 10^126 + 679, a gap of length ~10^126, but then > 3.44218 * 10^123 members in the next 10^126.

Last fiddled with by CRGreathouse on 2010-08-24 at 20:16
CRGreathouse 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:09.


Fri Aug 6 23:09:21 UTC 2021 up 14 days, 17:38, 1 user, load averages: 3.98, 3.92, 3.92

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.