![]() |
|
|
#133 | |
|
"Rashid Naimi"
Oct 2015
Remote to Here/There
1000000100002 Posts |
Quote:
![]() *I consider the time to calculate the factorial/primorial irrelevant at this smallish n point, because: ** It is not my immediate bottleneck ** The Prime-Candidate has a range of n<p<n^2 per any given n!/Pn#, hence each calculation can be used for more than 1 Prime-Candidate As per factorials vs. primorials, primorials are much smaller and of course they are faster as long as it is practical to calculate them. However they have the disadvantage of being much harder to recognize patterns in their form than factorials, which I am (most probably naively) hoping to utilize. As per the "other" software, I installed it on ubuntu according to the command here: http://www.mersenneforum.org/showthread.php?t=21219 but can't find any reference to how to initiate the interface. Please provide this information as well. I have vague memories of Pari-gp style floating point errors from the Cobol days, but haven't encountered them since, but then again haven't been doing much low level programming since either (which Pari-gp is not). Thank you very much for your input. |
|
|
|
|
|
|
#134 | |
|
Aug 2006
10111010110112 Posts |
Quote:
Fun fact: It's not really a 0 but the special value gnil which is what void functions return in GP. |
|
|
|
|
|
|
#135 | |
|
"Rashid Naimi"
Oct 2015
Remote to Here/There
24·3·43 Posts |
Quote:
Code:
/* Factorial - BAT-110-C - by Rashid Naimi */
n=10000000199999979;
factorialDigits(n)=if(n>3,ceil(lngamma(n+1)/log(10)),1);\\Credits CRGreathouse
theNumberOfFollowing0(x)=
{
theCount=0;
i=1;
while(5^i<=x,theCount+=x\(5^i);i++;);
return(theCount);
}
oracle(n)=print("** ",n,"! has ",theNumberOfFollowing0(n)," following 0s and ",factorialDigits(n)," decimal digits.";);
Str(oracle(n));
|
|
|
|
|
|
|
#136 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
Quote:
in every 10 you have z5*even = 10* something and y0 =10*y that's two per 10 then for every 100 you have 200*500 = 100,000 adding one so in each 10 of 10^i you have an extra pairing added that adds a 0 on the end. |
|
|
|
|
|
|
#137 | |
|
"Forget I exist"
Jul 2009
Dumbassville
838410 Posts |
Quote:
|
|
|
|
|
|
|
#138 | |
|
"Rashid Naimi"
Oct 2015
Remote to Here/There
24·3·43 Posts |
Quote:
ran a for loop comparing the code to valuation values and breaking in case of mismatch. Worked fine till 10k, figured it's correct. I was expecting a \10 too, but didn't seem to be the case. Last fiddled with by a1call on 2016-04-26 at 22:17 |
|
|
|
|
|
|
#139 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Quote:
per ten the last digits are: 0-> will create a multiple of ten when the last digit of a number 1 2 3 4 5 -> multiplied by even is a multiple of 10 6 7 8 9 but then within the 10's digit that pattern repeats there are two tens digits that when multiplied add another 0 to things etc. |
|
|
|
|
|
|
#140 | |
|
"Rashid Naimi"
Oct 2015
Remote to Here/There
24×3×43 Posts |
Quote:
It takes a 2 and a 5. Way too many 2s in any factorial, far more than 5s. Every 5 multiplied will guarantee a 0 addition, every 25 counts you multiply two 5s rather than one, so it adds two 0s and so on. Doesn't matter how many 2's you have(you always have to many and more than you need). It takes a 5 to complete one of the 2s. |
|
|
|
|
|
|
#141 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
Quote:
|
|
|
|
|
|
|
#142 | |
|
"Rashid Naimi"
Oct 2015
Remote to Here/There
24×3×43 Posts |
So, here is an attempt at getting msd Most-Significant-Digits of a factorial returned.
Code:
/* Factorial - BAT-110-E - by Rashid Naimi */
n=100001;
msd=19;\\Number of Most-Significant-Digits to return
\p 100000;
\\
\\
factorialDigits(n)=if(n>3,ceil(lngamma(n+1)/log(10)),1);\\Credits CRGreathouse
\\
theNumberOfFollowing0(x)=
{
theCount=0;
i=1;
while(5^i<=x,theCount+=x\(5^i);i++;);
return(theCount);
}
\\
mostSignificantDigits(n,msd)=
{
b=floor(lngamma(n+1)/log(10))-msd+1;
a=(10^(lngamma(n+1)/log(10)));
a=a/(10^b);
a=round(a);
return(a);
}
\\
oracle(n,msd)=
{
a=factorialDigits(n);
print("** ",n,"! has ",theNumberOfFollowing0(n)," following 0s and ",a," decimal digits.");
if(msd>a,msd=a);
mostSignificantDigits(n,msd);
}
\\
\\
theFactorial=oracle(n,msd)
#digits(theFactorial)
Quote:
Thank you in advance. |
|
|
|
|
|
|
#143 | ||
|
Aug 2006
3·1,993 Posts |
You should really write definitions for what your functions do. So
Code:
factorialDigits(n)=if(n>3,ceil(lngamma(n+1)/log(10)),1); addhelp(factorialDigits, "factorialDigits(n): Given an integer n >= 0, return the number of decimal digits of n!. Same as #digits(n!,10) but faster and with less memory used."); For example, it's not at all clear to me what the second argument of mostSignificantDigits is supposed to mean. Quote:
Code:
mostSignificantDigits(n,msd)=
{
my(a,b,t); \\ always define your variables using my() or bad things can happen
t = lngamma(n+1)/log(10); \\ Why compute this twice?
b = floor(t) - msd + 1;
a = 10^t;
round(a / 10^b); \\ no need for return() at the end of a function
}
addhelp(mostSignificantDigits, "mostSignificantDigits(n,msd): Do something or other with n and msd, then return something else.");
Code:
mostSignificantDigits(n,msd)=
{
my(b,t);
t = lngamma(n+1)/log(10);
b = floor(t) - msd + 1;
round(10^(t-b));
}
Code:
mostSignificantDigits(n,msd)=
{
my(t = lngamma(n+1)/log(10));
round(10^(frac(t) - msd + 1));
}
Quote:
Code:
default(realprecision, x) Last fiddled with by CRGreathouse on 2016-04-28 at 03:48 |
||
|
|
|
![]() |
| Thread Tools | |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How long will it be until MM61 is within practical reach of PRP/primality testing? | Stargate38 | Operazione Doppi Mersennes | 14 | 2020-01-29 20:35 |
| GQQ: a "deterministic" "primality" test in O(ln n)^2 | Chair Zhuang | Miscellaneous Math | 21 | 2018-03-26 22:33 |
| Modifying the Lucas Lehmer Primality Test into a fast test of nothing | Trilo | Miscellaneous Math | 25 | 2018-03-11 23:20 |
| a new Deterministic primality testing | wsc812 | Computer Science & Computational Number Theory | 36 | 2013-03-04 06:25 |
| maximum theoretical speed of LL test w/o bandwidth limitations? | ixfd64 | Hardware | 30 | 2012-03-05 06:16 |