News for hackers. Stuff that matters.
Re:A Million Digits of Pi in 9 Lines of JavaScript by AdmiralAsshat on Thursday September 12, 2019 @04:29PM (#20956092)
Can someone explain the logic behind the evolution of the fractions at each stage? I see that (1/4) becomes (1/4^2) and (1/4^3), but it's not obvious to me how (1/3)->(1/5)->(1/7) flows (odds? primes?), or (1/2) -> (13/24) -> (135/246).

EDIT: I understand now, the numerator on the first term is ascending odds and the denominator is ascending evens. Thanks for everyone's help!

Re:A Million Digits of Pi in 9 Lines of JavaScript by kromem on Thursday September 12, 2019 @04:59PM (#20956393)
If you look at the Taylor series link, you can see the sum representations of trigonometric functions.

So for instance, the 3/5/7 is just the (2n+1) value.

The other looks like the sum of the product of (2n-1)/(2n) for values 1 to n.

Re:A Million Digits of Pi in 9 Lines of JavaScript by joeyrideout on Thursday September 12, 2019 @04:50PM (#20956306)
Remove the leading 3 and the trailing term of 1/4 increasing in power.

You are left with this (in the 4th line):

1 3 5 1

- - - -

2 4 6 7

The pattern I see is that, starting from the top left and reading numerator, denominator, numerator, denominator and so on gives: 1 2 3 4 5 6 7 if you ignore the last numerator.

I may have it wrong, but that looks like the pattern.

Re:A Million Digits of Pi in 9 Lines of JavaScript by mef51 on Thursday September 12, 2019 @04:54PM (#20956340)
4th step is 1357/2468
Re:A Million Digits of Pi in 9 Lines of JavaScript by joeyrideout on Thursday September 12, 2019 @04:55PM (#20956353)
Is that simplified? I'm just going off of this image: http://ajennings.net/blog/images/formula.png
Re:A Million Digits of Pi in 9 Lines of JavaScript by mef51 on Thursday September 12, 2019 @04:58PM (#20956380)
me too, the pattern to me is odds on the numerator and evens in the denominator, and the second fraction goes 1/3, 1/5, 1/7, 1/9...

i think we're saying the same thing i misunderstood your comment. 1357/2468 is the first fraction of the NEXT line that isnt in the image

Re:A Million Digits of Pi in 9 Lines of JavaScript by joeyrideout on Thursday September 12, 2019 @05:04PM (#20956437)
Aha, yes, I edited my post now to say 4th line not 4th step. Leave it to HN to get an off-by-one error :)
Re:A Million Digits of Pi in 9 Lines of JavaScript by ajennings on Thursday September 12, 2019 @05:08PM (#20956477)
odds, not primes.

And I'm sorry if it looks like 13 over 24. It's supposed to look like 1/2 times 3/4. (The next term adds 5/6, and so on.)

Re:A Million Digits of Pi in 9 Lines of JavaScript by mef51 on Thursday September 12, 2019 @04:49PM (#20956289)
odds to get the 1/3, 1/5, 1/7, 1/9, etc. term and count by alternating digits on the numerator and denominator up to the next even number to get 1/2, 13/24, 135/246, 1357/2468, etc for the first term.

equivalently you just list odds on the numerator and evens in the denominator