Talk:Primorial numbers: Difference between revisions

no edit summary
No edit summary
 
(6 intermediate revisions by 3 users not shown)
Line 3:
say "First ten primorials: ", join ", ", map { pn_primorial($_) } 0..9;</lang> and all is done ;-)
[[user#Horsth|Horsth]]
: I just added a version using the new vecprod command. It is quite a bit faster. It uses a product tree for efficient large vector products -- the old comment was misleading about using a factor tree. [[User:Danaj|Danaj]] ([[User talk:Danaj|talk]]) 16:50, 9 October 2018 (UTC)
::Once I figured out what a "product tree" is, simply multiplying in pairs (technically adjacent, not that my Phix entry does that) I was positively ''shocked'' to see a better than 50-fold performance improvement (6 mins => 6 secs). --[[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|talk]]) 04:28, 22 March 2020 (UTC)
 
== a faster-than-exponential growth rate in CPU time stated by dinosaur ==
===Story===
 
school - multiplication ist quadratic in runtime O(count of digits) ~ (count of digits)^2
<pre>Prime(100000) = 1299709, Primorial(100000) ~ 0.1909604E+563921 121.547 seconds.
Line 20 ⟶ 22:
The implementation of primorial I am using, running on this laptop, took 0.002909 seconds for primorial 100000 and 0.049093 seconds for primorial 1000000. With digit counts, that became 0.004267 seconds and 0.04369 seconds. I guess that's faster than exponential growth rate if by fast you mean the execution time... but ... actually, I'm not sure where I'm going with this. I am mildly surprised that digit count could be faster than the raw primorial but that might just be random variation --[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 20:41, 8 April 2016 (UTC) Edit: System Info claims I'm working with an i7: 2.8GHz clock, 256KB L2, 6MB L3 - no mention of L1. --[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 09:26, 9 April 2016 (UTC)
 
:According to System Info, the computer has 64KB of L1 I-cache, 16KB L1 D-cache, and 2048KB of L2 cache, with further jargon about 2 way set associative, 64 byte line size, etc. and no mention of L3. Later, I see that the GIMP calculation gives 8MB for L3 on this AMD k10. However, I have no idea how much of each resource is devoted to the various activities such as running the GIMP crunch and windows itself. This is why experimental timings are tricky to perform as well as being a load on the patience. I am however surprised by the speeds quoted by some contributors, given that towards the end the number has millions of digits.
:As for the standard multiplication procedure of n digits by m digits consuming time proportional to n.m, remember that my version cheats by using a one digit multiplicand (err, the second number in a*b) even though it is much larger than the base of arithmetic. Computer crunching of integers is unaffected by whether x is multiplied by 12 or 1234567, except for overflows. Thus, its running time should be proportional to n, the number of digits in the big number. In principle, and ignoring caches. If successive primorials were attained by multiplying by a constant, then that number of digits would increase linearly, but of course the multiplicand is increasing in size itself. If that increase was the same as with factorials then the number of digits would increase according to log(x!) which is proportional to x*log(x) via Stirling's approximation, which is to say a linear growth (the x) multiplied by a factor that grows ever more slowly (the log(x))
:But Primorial(x) grows even faster than x! However, I didn't look and think long about the cpu timings before making the remark about "faster than exponential". I shall twiddle the prog. to produce more reports on timing... [[User:Dinosaur|Dinosaur]] ([[User talk:Dinosaur|talk]]) 08:51, 9 April 2016 (UTC)
Line 36 ⟶ 38:
:These were for data only up to n = 800,000 because there was a change in slope subsequently, probably because I stopped using the computer for other minor activity and thus didn't disrupt its various buffers. The Mersenne prime calculations continued. The points wobble above and below the fitted line across the span, and there is a bend visible at the start where the overall line is too low. That is, at the start the calculation is going a little faster and presumably, one could talk about not yet overflowing some on-chip memory buffer as another reason for non-linearity. Similarly, at the high end the points start to rise above the fitted line, and one could talk about a growth factor such as log(n) rather than a constant. This is obscured by the greater speed later on when I had walked away from the toiling computer. Nevertheless, one can see that a slight curve is being approximated by a straight line over a limited span, which means that using the start to attempt to identify the effect of a cpu buffer size will be tricky. Even so, a log(n) vs. log(t) plot shows a change of slope at the start - except that is for only the first few points. Alas, with "only" a few thousand digits to the big number, the resolution of the CPU timing function is insufficient to show finer details, and repeating the calculation a hundred times (say) will require auxiliary storage to enable the repetition and this will change the workings of the presumed buffering processes away from what was intended to be investigated. A frustrating business.
:Unfortunately, there is no provision for posting images, and anyway I've had a lot of trouble with Octave producing damaged plot files (.svg, .png, etc.) having to resort to screen image captures, so instead, here are the data:
 
:: You should be able to post images now. Look for an "Upload File" link at the bottom of the page. Also, you might want to look at where the time is going in your implementation - I am going to guess that it's in your code to generate the prime numbers. --[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 03:00, 10 April 2016 (UTC)
 
:::Pox! I have just created file Primorial.cpuTime.svg, but, "Error creating thumbnail: /bin/bash: rsvg-convert: command not found" results. Inkscape however draws the plot without difficulty, though at 657KB the file is a bit large for just a thousand points, a line, and some annotation. And now that it is uploaded, I can't see how to delete it. I shall attempt to replace it by a screen capture. As for Octave, it won't "Print" the plot as either a .png nor a .jpg due to some complaint of its own "'C:\Program' is not recognized as an internal or external command, operable program or batch file." so a tar pit there.
:::The calculation of the primes is not a problem, because all million are prepared in array PRIME before any Primorial attempts are made, and the time for this is somewhere in the blink of starting the run and the first Primorial results appearing even as the screen window manifests. [[User:Dinosaur|Dinosaur]] ([[User talk:Dinosaur|talk]]) 06:30, 10 April 2016 (UTC)
 
::::And I can't replace the .svg file by a .jpg because I can't change the name of the file. So, a new file (only 38KB in this format), and damnit, I forgot to give the name the prefix "Primorial.cpu" [[File:Time.jpg]]
And here is a plot of cpu time against the number of digits in the big number, which is successively being multiplied by a ''single'' digit value. [[File:Primorial.CPUtime.digits.jpg]]
 
:::::Only admins are allowed to delete files. I've removed "Primorial.cpuTime.svg". --[[User:AndiPersti|Andreas Perstinger]] ([[User talk:AndiPersti|talk]]) 18:36, 10 April 2016 (UTC)
 
===Grist===
<pre>
7,803

edits