08-06-2017, 10:01 PM
(This post was last modified: 08-06-2017, 11:37 PM by MarkHaysHarris777.)
Greetings again; got some more PI fun for you that will literally blow your SoC(s) off using nothing but the Python interpreter and the following two very short scripts -- using integer maths only:
pipipi.py
PI-calc2.sh
Place these two scripts in your working directory; be sure to make the PI-calc2.sh script executable with:
chmod 0754 PI-calc2.sh
To run the integer PI calculation use:
time ./PI-calc2.sh
On the Rock64 board this PI calculation will churn out 10,000+ digits of PI in just over 1/2 second. You can experiment between the Python2 and Python3 interpreter times; or more fun compare the times on the Pinebook vs PineA64+ vs Rock64 !
Because this small routine uses integer maths to get the digits of a never ending transcendental number, obviously the decimal point is going to be missing ! ... but all the digits will be there; experiment by increasing the number of digits in the pipipi.py routine. Its truly amazing to see the power of a tiny computer being used to actually "compute" in that sense of the word.
Note: The Pinebook calculates 10K digits of PI using integer maths on the Python3 interpreter in 3/4 second !
To put this is perspective for the year 2017 the first computer to accurately calculate PI to 10K digits occurred in 1958 (when I was three years old); ... in 1 hour and 40 minutes !
"... in July 1958, an IBM 704 at the Paris Data Processing Center was programmed according to a combination of Machin's formula and the Gregory series; it yielded 10,000 decimal places in 1 hour and 40 minutes."
"A year later, in July 1959, the same program was used on an IBM 704 at the Commissarit à l'Energie Atomique in Paris, and 16,167 places were obtained in 4.3 hours."
I reproduced the above precision using integer math on the Rock64 board (16177) and arrived at the result in a blazing 1.483 seconds on the Python2 interpreter ; running on the xenial minimal image 0.3.7 !
Quotes taken from :
Beckmann, Petr; A History of PI. The Golem Press (NewYork, 1971)
pipipi.py
Code:
digits = 10010
pi = term = 3 * 10 ** (digits+9)
m = 2
while term:
term = term * ((m-1) * (m-1)) // (4 * m * (m+1))
pi += term
m += 2
print(pi // 10 ** 9)
PI-calc2.sh
Code:
#!/usr/bin/python
from pipipi import *
Place these two scripts in your working directory; be sure to make the PI-calc2.sh script executable with:
chmod 0754 PI-calc2.sh
To run the integer PI calculation use:
time ./PI-calc2.sh
On the Rock64 board this PI calculation will churn out 10,000+ digits of PI in just over 1/2 second. You can experiment between the Python2 and Python3 interpreter times; or more fun compare the times on the Pinebook vs PineA64+ vs Rock64 !
Because this small routine uses integer maths to get the digits of a never ending transcendental number, obviously the decimal point is going to be missing ! ... but all the digits will be there; experiment by increasing the number of digits in the pipipi.py routine. Its truly amazing to see the power of a tiny computer being used to actually "compute" in that sense of the word.
Note: The Pinebook calculates 10K digits of PI using integer maths on the Python3 interpreter in 3/4 second !
To put this is perspective for the year 2017 the first computer to accurately calculate PI to 10K digits occurred in 1958 (when I was three years old); ... in 1 hour and 40 minutes !
"... in July 1958, an IBM 704 at the Paris Data Processing Center was programmed according to a combination of Machin's formula and the Gregory series; it yielded 10,000 decimal places in 1 hour and 40 minutes."
"A year later, in July 1959, the same program was used on an IBM 704 at the Commissarit à l'Energie Atomique in Paris, and 16,167 places were obtained in 4.3 hours."
I reproduced the above precision using integer math on the Rock64 board (16177) and arrived at the result in a blazing 1.483 seconds on the Python2 interpreter ; running on the xenial minimal image 0.3.7 !
Quotes taken from :
Beckmann, Petr; A History of PI. The Golem Press (NewYork, 1971)
marcushh777
please join us for a chat @ irc.pine64.xyz:6667 or ssl irc.pine64.xyz:6697
( I regret that I am not able to respond to personal messages; let's meet on irc! )
![Cool Cool](https://forum.pine64.org/images/smilies/cool.png)
please join us for a chat @ irc.pine64.xyz:6667 or ssl irc.pine64.xyz:6697
( I regret that I am not able to respond to personal messages; let's meet on irc! )