Post Reply 
Wallis' product exploration
02-11-2020, 10:48 PM (This post was last modified: 02-11-2020 10:49 PM by Gerson W. Barbosa.)
Post: #18
RE: Wallis' product exploration
(02-11-2020 04:11 PM)Gerson W. Barbosa Wrote:  \(\frac{\pi }{2}\approx \left ( \frac{4}{3} \cdot \frac{16}{15}\cdot \frac{36}{35}\cdot\frac{64}{63} \cdots \frac{ 4n ^{2}}{ 4n ^{2}-1}\right )\left ( 1+\frac{1}{4n+\frac{3}{2-\frac{1}{4n+\frac{5}{2-\frac{3}{4n+\frac{7}{2-\frac{5}{4n+\frac{9}{2-\frac{7}{\dots \frac{ \ddots }{2-\frac{n-3}{4n+\frac{n+1}{2}}}}}}}}}}}} \right )\)

That's slightly better:

\[\frac{\pi }{2}\approx \left ( \frac{4}{3} \cdot \frac{16}{15}\cdot \frac{36}{35}\cdot\frac{64}{63} \cdots \frac{ 4n ^{2}}{ 4n ^{2}-1}\right )\left ( 1+\frac{1}{4n+\frac{3}{2-\frac{1}{4n+\frac{5}{2-\frac{3}{4n+\frac{7}{2-\frac{5}{4n+\frac{9}{2-\frac{7}{\dots \frac{ \ddots }{4n+\frac{n+1}{2-\frac{n-1}{4n}}}}}}}}}}}} \right )\]


Here are 1000 digits of \(\pi\), in a reasonable time, courtesy of John Wallis and yours truly :-)

------------------------------------------------------------------------------

n: 842

3.1415926535 8979323846 2643383279 5028841971 6939937510 
  5820974944 5923078164 0628620899 8628034825 3421170679 
  8214808651 3282306647 0938446095 5058223172 5359408128 
  4811174502 8410270193 8521105559 6446229489 5493038196 
  4428810975 6659334461 2847564823 3786783165 2712019091 
  4564856692 3460348610 4543266482 1339360726 0249141273 
  7245870066 0631558817 4881520920 9628292540 9171536436 
  7892590360 0113305305 4882046652 1384146951 9415116094 
  3305727036 5759591953 0921861173 8193261179 3105118548 
  0744623799 6274956735 1885752724 8912279381 8301194912 
  9833673362 4406566430 8602139494 6395224737 1907021798 
  6094370277 0539217176 2931767523 8467481846 7669405132 
  0005681271 4526356082 7785771342 7577896091 7363717872 
  1468440901 2249534301 4654958537 1050792279 6892589235 
  4201995611 2129021960 8640344181 5981362977 4771309960 
  5187072113 4999999837 2978049951 0597317328 1609631859 
  5024459455 3469083026 4252230825 3344685035 2619311881 
  7101000313 7838752886 5875332083 8142061717 7669147303 
  5982534904 2875546873 1159562863 8823537875 9375195778 
  1857780532 1712268066 1300192787 6611195909 216420198 
  
Runtime:   .96 seconds


------------------------------------------------------------------------------

Only linear convergence, but better than waiting forever for a just few digits.

Decimal BASIC program:

Code:


OPTION ARITHMETIC DECIMAL_HIGH
INPUT  PROMPT "n: ":n
LET tm = TIME 
LET nd = 1000
LET pr = 1
LET n1 = n - 1
LET n2 = n1 + 2
LET d = 4*n
LET c = 0
FOR i = 1 TO n/2
   LET np = 4*(2*i - 1)*(2*i - 1)
   LET dp = np - 1
   LET pr = pr*np/dp
   LET np = 16*i*i
   LET dp = np - 1
   LET pr = pr*np/dp
   LET c = n2/(2 - n1/(d + c))
   LET n2 = n2 - 2
   LET n1 = n1 - 2
next i
LET c = 2 + 2/(c + d)
LET p = pr*c
LET r = TIME - tm
LET r$ = STR$(p - INT(p))                           
PRINT
PRINT STR$(INT(p));
PRINT r$(0:1);
FOR i = 2 TO nd + 1
   PRINT r$(i:i);
   IF MOD((i - 1),10) = 0 THEN PRINT " ";
   IF MOD((i - 1),50) = 0 THEN 
      PRINT
      PRINT REPEAT$(" ",1 + LEN(STR$(INT(p))));
   END IF
NEXT i
IF MOD (i - 2,50) <> 0  OR nd = 0 THEN PRINT
PRINT 
PRINT "Runtime: ";
PRINT  USING "##.##": r;
PRINT " seconds"
END
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Wallis' product exploration - pinkman - 02-07-2020, 10:55 PM
RE: Wallis' product exploration - pinkman - 02-08-2020, 02:42 PM
RE: Wallis' product exploration - Allen - 02-08-2020, 07:13 PM
RE: Wallis' product exploration - Allen - 02-08-2020, 08:58 PM
RE: Wallis' product exploration - pinkman - 02-09-2020, 05:44 AM
RE: Wallis' product exploration - Allen - 02-08-2020, 08:13 PM
RE: Wallis' product exploration - Allen - 02-09-2020, 01:08 PM
RE: Wallis' product exploration - Allen - 02-09-2020, 01:57 PM
RE: Wallis' product exploration - Allen - 02-09-2020, 03:08 PM
RE: Wallis' product exploration - pinkman - 02-09-2020, 02:14 PM
RE: Wallis' product exploration - EdS2 - 02-10-2020, 10:35 AM
RE: Wallis' product exploration - pinkman - 02-11-2020, 10:02 AM
RE: Wallis' product exploration - Gerson W. Barbosa - 02-11-2020 10:48 PM
RE: Wallis' product exploration - pinkman - 02-12-2020, 10:01 PM



User(s) browsing this thread: 1 Guest(s)