mersenneforum.org  

Go Back   mersenneforum.org > Great Internet Mersenne Prime Search > Software

Reply
 
Thread Tools
Old 2008-09-03, 11:24   #23
R.D. Silverman
 
R.D. Silverman's Avatar
 
Nov 2003

22×5×373 Posts
Default

Quote:
Originally Posted by drew View Post
What about those of us who already know how to perform the calculation? Should we not use software to make it simpler for us? Should I derive my own logarithm tables myself?
What's the matter? Is a hand calculator too complicated a tool for you?
If you know how to do the calculation, then a specialized program
is not needed. Nor is it any faster.
R.D. Silverman is offline   Reply With Quote
Old 2008-09-03, 15:51   #24
Jeff Gilchrist
 
Jeff Gilchrist's Avatar
 
Jun 2003
Ottawa, Canada

3·17·23 Posts
Lightbulb

Quote:
Originally Posted by R. Gerbicz View Post
There are numbers less than 2^64 for which your program is bad:
for example: p=28505944177 (this p is prime)
or for p=198096465 (this p is composite) gives bad number of digits for 2^p-1
You are absolutely right. It seems there were some rounding errors which I have now fixed so hopefully everything will be accurate now. Thank you for finding those problems so I could fix them.

I have now released v1.1 available from:
http://gilchrist.ca/jeff/MprimeDigits

New in v1.1:
  • Fixed rounding errors reported by R. Gerbicz.
  • Command line version now accepts multiple p values on the command line (ie: mprimedigits 32582657 25964951)
  • Now displays formula used to calculate # of digits so people can better understand how to calculate it themselves if they wish.

As for Dr. Silverman's comments, I originally wrote this program for myself just to make it easier to calculate with 1 button push instead of several, but I figured others on the Internet in general would be interested as well so it is now available for anyone to use. In order to help people learn if they wish, I have now included the formula the program uses as a starting point for them instead of it being a complete black hole.
Attached Thumbnails
Click image for larger version

Name:	MprimeDigits.gif
Views:	112
Size:	13.8 KB
ID:	2666  
Jeff Gilchrist is offline   Reply With Quote
Old 2008-09-03, 15:53   #25
Jeff Gilchrist
 
Jeff Gilchrist's Avatar
 
Jun 2003
Ottawa, Canada

3·17·23 Posts
Default

Quote:
Originally Posted by R.D. Silverman View Post
What's the matter? Is a hand calculator too complicated a tool for you?
If you know how to do the calculation, then a specialized program
is not needed. Nor is it any faster.
Well it is faster in the sense that with my program you can use a script to pass it multiple values to calculate at once, giving you all the results in probably the same amount of time it would take to use a hand calculator for one number.
Jeff Gilchrist is offline   Reply With Quote
Old 2008-09-03, 16:10   #26
ewmayer
2ω=0
 
ewmayer's Avatar
 
Sep 2002
República de California

19×613 Posts
Default

Using the unix/linux bc utility [or a decent electronic calculator with any form of a "log" function], it's trivial: start "bc -l" [the -l flag invokes floating-point mode], then

[your exponent here]*l(2)/l(10)

..and round up. The -1 subtracted from the 2^p in the real Mersenne number is nearly always ignorable if the the digit count is large - you'd only need to include it if the above result is really, really close to a whole number. ["How close" makes for a nice homework assignment.]

Example: for p = 32582657, the above gives 9808357.095430986538..., which is not close to a whole number in the relevant sense, so we round confidently up and get 9808358 decimal digits for M44.
ewmayer is offline   Reply With Quote
Old 2008-09-03, 17:27   #27
lavalamp
 
lavalamp's Avatar
 
Oct 2007
Manchester, UK

23×59 Posts
Default

Quote:
Originally Posted by ewmayer View Post
The -1 subtracted from the 2^p in the real Mersenne number is nearly always ignorable
For a Mersenne number it is always ignorable, since 2^n mod 10 can only equal 2, 4, 6 or 8.

Edit: When finding the number of digits for a number such as 5^n*2^n - 1 though, the minus one does matter.

Last fiddled with by lavalamp on 2008-09-03 at 17:30
lavalamp is offline   Reply With Quote
Old 2008-09-03, 23:49   #28
R. Gerbicz
 
R. Gerbicz's Avatar
 
"Robert Gerbicz"
Oct 2005
Hungary

2·743 Posts
Default

Quote:
Originally Posted by Jeff Gilchrist View Post
I have now released v1.1
For large inputs your program is still bad (see the picture).

My c solution for the problem, no trick, not using built in large math libraries:
( it should be good for p<10^40 )
Code:
#include <stdio.h>
#include <string.h>


int main()  {

    int A[40],B[100],R[141],carry,valid,i,j,L;
    char input[64],w[101]="3010299956639811952137388947244930267681898814621085413104274611271081892744245094869272521181861720";
    
    while(1)  {
          printf("Please input an exponent (at most 40 digits) : ");
          scanf("%s",input);
          L=strlen(input);
          valid=1;
          for(i=0;i<L;i++)
              if((input[i]<'0')||(input[i]>'9'))  valid=0;
          if((valid==0)||(L>40))  printf("Invalid input!\n");
          else break;
    }
    
    for(i=0;i<L;i++)    A[i]=input[L-1-i]-'0';
    for(i=0;i<100;i++)  B[i]=w[99-i]-'0';
    for(i=0;i<141;i++)  R[i]=0;
    // grammar school multiplication
    for(i=0;i<L;i++)
        for(j=0;j<100;j++)  R[i+j]+=A[i]*B[j];
    
    R[100]++;
    carry=0;
    for(i=0;i<=140;i++)  {
        carry+=R[i];
        R[i]=carry%10;
        carry/=10;
    }
    
    i=140;
    while(R[i]==0)  i--;
    printf("The number of decimal digits of 2%c%s%c1 is ",'^',input,'-');
    while(i>=100)  printf("%d",R[i]),i--;
    printf("\n");
    return 0;
}
Attached Thumbnails
Click image for larger version

Name:	a.gif
Views:	136
Size:	9.4 KB
ID:	2667  

Last fiddled with by R. Gerbicz on 2008-09-03 at 23:55
R. Gerbicz is online now   Reply With Quote
Old 2008-09-04, 02:03   #29
jrk
 
jrk's Avatar
 
May 2008

3·5·73 Posts
Default

Quote:
Originally Posted by R. Gerbicz View Post
Code:
char input[64]
Code:
scanf("%s",input);
Careful with that. You don't want to write more than 64 bytes to "input".
jrk is offline   Reply With Quote
Old 2008-09-04, 10:10   #30
akruppa
 
akruppa's Avatar
 
"Nancy"
Aug 2002
Alexandria

2,467 Posts
Default

On a side note, if you want to do the (approximate) conversion with pencil and paper, a useful fact to remember is that
F12 has 1234 decimal digits.

Conveniently, the leading digits of F12 are 104..., so 2^4096 is pretty close to 10^1233, and the estimate
log(10)/log(2) ~= 4096/1233 = 3.3219...
is reasonably accurate. From the continued fraction expansion the better fraction 2136/643 = 3.321928... can be found, but it's not as easy to remember.

Alex
akruppa is offline   Reply With Quote
Old 2008-09-04, 12:03   #31
R.D. Silverman
 
R.D. Silverman's Avatar
 
Nov 2003

22×5×373 Posts
Default

Quote:
Originally Posted by akruppa View Post
On a side note, if you want to do the (approximate) conversion with pencil and paper, a useful fact to remember is that
F12 has 1234 decimal digits.

Conveniently, the leading digits of F12 are 104..., so 2^4096 is pretty close to 10^1233, and the estimate
log(10)/log(2) ~= 4096/1233 = 3.3219...
is reasonably accurate. From the continued fraction expansion the better fraction 2136/643 = 3.321928... can be found, but it's not as easy to remember.

Alex
Also, the utility of this tool somehow eludes me. Why would someone
who doesn't know how to do the calculation need to know how many
digits 2^p-1 has?
R.D. Silverman is offline   Reply With Quote
Old 2008-09-04, 12:14   #32
xilman
Bamboozled!
 
xilman's Avatar
 
"𒉺𒌌𒇷𒆷𒀭"
May 2003
Down not across

2×5,393 Posts
Default

Quote:
Originally Posted by R.D. Silverman View Post
Also, the utility of this tool somehow eludes me. Why would someone
who doesn't know how to do the calculation need to know how many
digits 2^p-1 has?
You are confusing "need" and "want".

An adequate justification for wanting to know is idle curiosity.


Paul
xilman is offline   Reply With Quote
Old 2008-09-04, 12:27   #33
R.D. Silverman
 
R.D. Silverman's Avatar
 
Nov 2003

164448 Posts
Default

Quote:
Originally Posted by xilman View Post
You are confusing "need" and "want".

An adequate justification for wanting to know is idle curiosity.


Paul
Not where I work.............
R.D. Silverman is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ten Billion Digits Mersenne Numbers aketilander Operation Billion Digits 14 2021-02-27 07:14
Mersenne Digits Curiosity davar55 Lounge 11 2013-02-08 15:19
Program to TF Mersenne numbers with more than 1 sextillion digits? Stargate38 Factoring 24 2011-11-03 00:34
Who is LL-ing a mersenne number > 100M digits? joblack LMH > 100M 1 2009-10-08 12:31
Digits of Pi in Mersenne Prime? Unregistered Miscellaneous Math 3 2004-04-09 15:31

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


Fri Aug 6 23:28:35 UTC 2021 up 14 days, 17:57, 1 user, load averages: 3.33, 3.80, 3.94

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.