mersenneforum.org  

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

Reply
 
Thread Tools
Old 2010-08-24, 20:14   #826
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

20C016 Posts
Default

I tried it on 2047 it works when did you get an error ?
science_man_88 is offline   Reply With Quote
Old 2010-08-24, 20:20   #827
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

175B16 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
I tried it on 2047 it works when did you get an error ?
Oh I see: you don't want the sum of the digits but rather the digital sum of the number. In that case your code is fine. (Use addhelp, that way this sort of thing won't happen so much!)

Last fiddled with by CRGreathouse on 2010-08-24 at 20:21
CRGreathouse is offline   Reply With Quote
Old 2010-08-24, 20:26   #828
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

100000110000002 Posts
Default

I figured you'd know as it's your advice about it earlier in this thread that I made it with by the way I was able to do:

Code:
(17:21) gp > sumdigits(2^20470000-1)
%550 = 6
(17:21) gp > ##
  ***   last result computed in 47 ms.
your gave me this:

Code:
(17:21) gp > dsum(2^20470-1)
%549 = 27762
(17:21) gp > ##
  ***   last result computed in 94 ms.
if we can loop your code until it's a one digit number and speed it up it's okay. but if each step took as long as this one. my code would be 6 times the speed at least.

Last fiddled with by science_man_88 on 2010-08-24 at 20:29
science_man_88 is offline   Reply With Quote
Old 2010-08-24, 20:35   #829
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24·3·5·7 Posts
Default

Quote:
Originally Posted by CRGreathouse
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.
Is it as weird as the subset of primes that have a square number of digits? (2, 3, 5, 7, 1009, 1013, 1019, 1021, 1031, 1033, 1039.. 9973, 100000007, ..)

Last fiddled with by 3.14159 on 2010-08-24 at 20:36
3.14159 is offline   Reply With Quote
Old 2010-08-24, 20:37   #830
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
if we can loop your code until it's a one digit number and speed it up it's okay. but if each step took as long as this one. my code would be 6 times the speed at least.
We're computing essentially different things. If all you need is the digital root, then by all means compute that! If you need the sum of the digits, it's a much harder task.

Similarly, factoring an integer is harder than just testing for primality; if you can get away with the latter, do that.


For what it's worth, your code could be modified to be roughly twice as fast. Two possibilities for n > 0 spring to mind:
Code:
droot(n)={
  my(k=n%9);
  if(k,k,9)
};

droot1(n)={
  ((n-1)%9)+1
};
I'm not sure which is faster, probably the former. Test them and see!

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

3×1,993 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
Is it as weird as the subset of primes that have a square number of digits? (2, 3, 5, 7, 1009, 1013, 1019, 1021, 1031, 1033, 1039.. 9973, 100000007, ..)
It's weird in a similar way, yes. Of course things having to do with decimal digits are usually unnatural.

Last fiddled with by CRGreathouse on 2010-08-24 at 20:38
CRGreathouse is offline   Reply With Quote
Old 2010-08-24, 20:46   #832
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
I'm not sure which is faster, probably the former. Test them and see!
by 3 test each the first is ahead by one test as the other 2 match the time for the second. lowest time so far is 16 ms.
science_man_88 is offline   Reply With Quote
Old 2010-08-24, 20:53   #833
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

175B16 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
by 3 test each the first is ahead by one test as the other 2 match the time for the second. lowest time so far is 16 ms.
The timer isn't really accurate for very small times. Test a lot of numbers to check:
Code:
for(i=1,1e5,droot(i))
or something like that.

Looks to me like droot1 is better, at least for small numbers. For big numbers, let's do
Code:
v=vector(10^5,unused,random(10^1000));
for(i=1,#v,droot(v[i]))
Looks like the winner is still droot1, which is faster than droot, which is faster than sumdigits.

Last fiddled with by CRGreathouse on 2010-08-24 at 20:56
CRGreathouse is offline   Reply With Quote
Old 2010-08-24, 21:00   #834
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24×3×5×7 Posts
Default

Quote:
Originally Posted by CRGreathouse
It's weird in a similar way, yes. Of course things having to do with decimal digits are usually unnatural.
Ah well: Random prime of the day:
9845575878878960828055703578149239033062029198602060374047309547974126063126741251854204515517297810571460660189707205143591982239643 (133 digits)
3.14159 is offline   Reply With Quote
Old 2010-08-24, 21:09   #835
kar_bon
 
kar_bon's Avatar
 
Mar 2006
Germany

22·727 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
Ah well: Random prime of the day:
Code:
9845575878878960828055703578149239033062029198602060374047309547974126063126741251854204515517297810571460660189707205143591982239643 (133 digits)
...and
Code:
98455758788789608280557035781492390330620291986020603740473095479741260631267412518542045155172978105714606601897072051435919822396433
(134 digits), too!
kar_bon is offline   Reply With Quote
Old 2010-08-24, 21:22   #836
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24·3·5·7 Posts
Default

Quote:
Originally Posted by Karsten
...and

Code:
98455758788789608280557035781492390330620291986020603740473095479741260631267412518542045155172978105714606601897072051435919822396433
(134 digits), too!
Code:
160074594123956794219458402545764711419701756584167638068329365693034831201396939643913504262352130745852290381939420288140978693341478528259387657797580376902986395224408345354821071590949525350364018649578862749297255505837416439606095853836355923951566526457673735312339184330365326723420347366112675200713878660771081227364603472040699601553789595479339960277304318254798850917751885704667910151149091532150905626179048799036700679933820859845365985390911277048117168671365128451668210581621327277787092273718680191991994664786587234396792965881059281805213980760310898060678555989602303590308736441654087832242397146458759717551025723008092342436218853265799505252096172021953238850043510060599858403400384570222716416699106818277439891613536333361593153540409685328569171314344686601795619300473375554423332099932225456784121921559118525805374656294079430382561204188488274552102452626811652972822901469815861523877416162913528086735710854833100692524526048253371898482177626664655396682221293652089791416114579511127188674154339902564205267260071373223290668469512503977940823503507668484572724611665887674632905471958304064277923482051286050072649
1155 digits! Ha!

Last fiddled with by 3.14159 on 2010-08-24 at 21:22
3.14159 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:22 UTC 2021 up 14 days, 17:38, 1 user, load averages: 4.22, 3.97, 3.93

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.