Skip to content
← Back to Community
EVEN MORE APPROXIMATIONS OF π!!
Profile icon
LizFoster

I'm back at it again, this time with a compilation of different formulae for approximating π, with surprising accuracy in some cases!

Fascinating stuff!

Voters
Profile icon
ZacharyMalas
Profile icon
AmazingMech2418
Profile icon
PYer
Profile icon
DJWang
Profile icon
catherinebish
Profile icon
buffhorse
Profile icon
AKASomeone
Profile icon
ARJPEG
Profile icon
NecroHacks
Profile icon
HaozheYu
Comments
hotnewtop
Profile icon
CodingCactus

Great and interesting as always!

Profile icon
LizFoster

@CodingCactus Thank you! I try my best (Lol) ^ ^*

Profile icon
luffy223

I have a way of approximating pi but i do not now if it is plausible:
in calculs we know that an integral = area under curve
and from geomtry area of circle = pi*(r)^2
the circle furmula is x^2+y^2=r^2 solve for y :
y=((r^2)-(x^2))^(1/2)
(interrating from -r to r = area of half a circle) *2 = area of circle
then solve for pi :
pi = (area of circle)/(r^2)
to calculate the intergration use riymen's sum or simpson's rule
i know how to solve simpson rule only on desmos
is it plausible

Profile icon
LizFoster

@luffy223 Ah, yes. You can! Like this!

Screenshot 2020-04-01 at 4.29.30 AM

If this is what you meant:

The outcome of the integrated equation is the area under the curve of a semicircle (with r = 1). It is also π/2. Multiply it by two, you get π, which is the area of a circle with (r = 1)!!

Profile icon
LizFoster

@luffy223 Alright, part 2, done!

Screenshot 2020-04-01 at 6.24.27 AM

This uses your typical Riemann Sum formula to calculate the area under the curve. The higher n is the better, but it lags too much to be worth it _ _

The difference between the outcome (a in this case) and π is just about:
0.0000000000032249758419

So yeah, pretty accurate for how low n is ^ ^*

Profile icon
LizFoster

@LizFoster And now, the final addition allows r to equal any integer value (otherwise it returns undefined _ _)

Screenshot 2020-04-01 at 7.02.36 AM

Profile icon
luffy223

yeah like this

here using simpson's rule

WhatsApp Image 2020-04-01 at 1.23.02 PM
@LizFoster

WhatsApp Image 2020-04-01 at 1.23.10 PM

Profile icon
luffy223

but could you make a python program to delet the lag from [email protected]

Profile icon
LizFoster

@luffy223 Interesting! I'm quite fond of these two methods, I may actually add them to "π approximations 3" (which will be coming soon) _ _*

Profile icon
luffy223

cool will wait for it see ya @LizFoster

Profile icon
LizFoster

@luffy223 Sure thing ^ ^

Should I tag you in the post when I do upload it?

Profile icon
luffy223

as you wish @LizFoster

Profile icon
LizFoster

@luffy223 Alright, so I am a bit confused as to how I would go about saying:

*f(-r + (a-b/n) x i)*

or

*f(l_i)*

Obviously, I understand how to do the inner workings, but is there something specific I must do to add in the f() part?

Also, funnily enough, if you multiply the second part of the Riemann sum by (τ x 10^3), it does the same thing as f() does. However, since τ is just , I'd hardly count that that as a win.. (Lol)

Profile icon
luffy223

mmm to be honst i didn't understand your question (hahaha) mybe def F(): @LizFoster

Profile icon
LizFoster

@luffy223 Sorry, ha ha ha!

What I mean is, what is the difference between these two?

(-r + (a-b/n) x i) f(-r + (a-b/n) x i)
Profile icon
luffy223

this is how I undertanded your [email protected]

Profile icon
luffy223

yeah and there are three types of xi :
ri = a+ idelta(x)
li = a+ (i-1)delta(x)
mi = a + (i-0.5)delta(x)
for simpson rule I used to xi typs :
li
and oi = a+ (2i-1)delta(x)@LizFoster

Profile icon
AgastyaSandhuja

niiicccceee

Profile icon
LizFoster

@AgastyaSandhuja Thank you!

Profile icon
AgastyaSandhuja

ok this is unrelated but that response was FAST @LizFoster

Profile icon
LizFoster

@AgastyaSandhuja Lol (^ ^ )

I was active at that second.

Profile icon
AgastyaSandhuja

BTW did you get the value of φ
from
ΔΔG D-N < 1.7 ?
@LizFoster

Profile icon
LizFoster

@AgastyaSandhuja How interesting. No, I did not use that; I merely calculated it via the formula (√5 + 1) / 2. However, this looks intriguing, and I'll do some reading on that!

Profile icon
AgastyaSandhuja

Yes it's interesting! It is in equa6 in your code, but whatever you say :p @LizFoster

Profile icon
LizFoster

@AgastyaSandhuja What I meant is, I have not heard it in that context ^ ^*

Profile icon
AgastyaSandhuja

oh. gotcha. @LizFoster

Profile icon
LizFoster
Profile icon
Highwayman

Lines 5 and 6 are scaring me why do you need to know the amount of days in a week and amount of days in a year?

Edit: oh. Um.

Profile icon
LizFoster

@Highwayman Ha ha ha! For the sixth equation, it uses weeks and year as units (which in my opinion is incredible. Why do units of time produce π?!).

Profile icon
Highwayman

@LizFoster my first(reasonable) thoughts were about how the earth circles the sun, creating such schedules..?

Profile icon
LizFoster

@Highwayman Ooh, that's a good point! I can see it now..

Profile icon
Highwayman

@LizFoster :P that would be so cool if there is an actual correlation.

Profile icon
LizFoster

@Highwayman Yes, it would be!

Profile icon
AgastyaSandhuja

Actually, a lot of methods of pi do include the earths orbit and time.
https://mathworld.wolfram.com/images/equations/PiApproximations/NumberedEquation34.gif
@Highwayman
@LizFoster

Profile icon
AgastyaSandhuja

oh wait that's in your program xD

Profile icon
Highwayman

AgastyaSandhuja like yeet

Profile icon
LizFoster

@Highwayman @AgastyaSandhuja Ha ha ha! I am still interested as to why it is used (and why it works..)!

Profile icon
AgastyaSandhuja

Me too! Again. fast response. (2 seconds) how do you type so fast?
@LizFoster

Profile icon
LizFoster

@AgastyaSandhuja Lol

I'm just active at the moment, and I see the notifications pretty fast.

Profile icon
xxpertHacker

JS https://repl.it/@StudentFires/pJS,
C++ https://repl.it/@StudentFires/pC
That is the result of a tutorial on memoization, hours of work on converting loops to recursion, converting mathematical summation and product notation to code, then to recursion, and plenty of Desmos graphing and more.
I'll be back on Repl in about 5 hours.

Profile icon
LizFoster

@StudentFires Sorry, had to take care of something ^ ^*

Nice! Looking good

Profile icon
xxpertHacker

@LizFoster Eh, I wasn't on Repl. Also back when I did this I removed plenty of redundancies from the Riemann Sum formula that you posted earlier.
Screenshot 2020-04-03 at 6.40.24 AM - Edited
Screenshot 2020-04-03 at 6.40.27 AM - Edited

Profile icon
LizFoster

@StudentFires Oh, huh. I can see what you mean, those would vastly improve the formula aesthetically. Is it any faster?

Profile icon
xxpertHacker

@LizFoster Never implemented it, but I'm pretty sure r-(-r) is probably slower than 2r.

Profile icon
LizFoster

@StudentFires Hm. I'm not fully sure what is going on there, can you write it out on Desmos?

(In response to your other post about a different algorithm)

Profile icon
xxpertHacker

@LizFoster That algorithm was wrong, I did it in JavaScript a few minutes ago, so I deleted it.

Profile icon
LizFoster

@StudentFires Ah, okay (Lol)

That would explain why I could not comment on it wwwww

Profile icon
xxpertHacker

Do you know if this an effective way to calculate π?
I believe I'd need p(n)/n to calculate for π after the function.

p(z) = ProductNotation(n=1, (2n/(2n-1))^2, z);
π = p(∞)/∞
PI

Update:
Screenshot 2020-04-02 at 3.16.39 PM - Edited

Profile icon
LizFoster

@StudentFires Yes, actually! That formula is incredibly similar the Wallis Product (the second part of the product has a '+ 1', not a '- 1')!

Screenshot 2020-04-03 at 7.21.15 AM

Profile icon
xxpertHacker

@LizFoster Well, since it works, I’ve converted it to a recursive function, thus I can memoize it... That or I’ll do it C++.
Also what has a +1?

Profile icon
LizFoster

@StudentFires
(Also I just remembered, the Wallis Product results in π/2, and this results in approximately π when multiplied by some large number, m, which is the number of iterations)

Sweet! I can't wait to see it!

Profile icon
xxpertHacker

@LizFoster That’s why your example divided by m, and I divided by z. Also, 2π is more important that π itself, but I forgot its name. Also, usually i or k are used as the counters in Product Notation and Summation, so I should fix my examples.

Profile icon
LizFoster

@StudentFires Oh, it is called τ (tau)!

Profile icon
xxpertHacker

@LizFoster Yeah that... “Tau”. That’s far more important that Pi itself.

Profile icon
LizFoster

@StudentFires Yes, it certainly is. However I haven't done much reading on it as I'm quite fond of π (as you can tell wwwww)..

Profile icon
xxpertHacker

@LizFoster I assume you don’t know JavaScript? I'm failing miserably right now.

Profile icon
LizFoster

@StudentFires Ah, alas, I do not. I've been considering learning it though..

If you need help you should try your luck on Stack Overflow, or just post on the Ask forum. ^ ^*

Profile icon
xxpertHacker

@LizFoster The Ask forum here isn't really active, and yesterday I asked two questions on StackOverflow, no one answered either of them, not even a comment.

Profile icon
LizFoster

@StudentFires Oh, that's weird. Normally you get at least one comment... Maybe it was a really active/really inactive moment? Your questions might have drowned in a sea of other questions, but I don't go on there too often, so I wouldn't know.

Profile icon
xxpertHacker

@LizFoster It was drowned fast, yeah.

Profile icon
LizFoster

@StudentFires Darn, that sucks, I am sorry T~T

Profile icon
xxpertHacker

@LizFoster Update, actually my code was perfectly formed... but I forgot to put a semicolon. https://repl.it/@StudentFires/PreciousAssuredPi, And what a coincidence, I haven't even renamed the Repl yet.

Profile icon
LizFoster

@StudentFires Ha ha ha! Happens to the best of us (I say from experience, I've gotten hung up on things, only to find that it was failing from a basic syntactical error)..

Looks good! Can you allow it to take a user input for the iterations? It is fairly inaccurate in its current state.

Really fast either way!

Profile icon
xxpertHacker

@LizFoster Yeah, I updated it to be interactive a minute after I told you.

Profile icon
LizFoster

@StudentFires Sorry for the late response, had to eat breakfast ^ ^*

Ah, nice! It actually takes about as long to calculate
1 000 000 000 as Desmos does, so it's REALLY fast. Wow.

Profile icon
xxpertHacker

@LizFoster Don't worry, I wasn't even on Repl.it for a few hours, so I'm sorry for the late response. I updated it to C++ and never finished it, it has plenty of room to be faster and more precise, I'm getting on it right now!

Wait... breakfast, what continent are on?

Profile icon
LizFoster

@StudentFires Ah, all good. I'm excited to see how fast it is once you finish it (#w#)

Oh, nowhere wwwwww

Profile icon
xxpertHacker

@LizFoster I'm all the way in the redacted. Is the virus bad where you are?

Profile icon
LizFoster

@StudentFires Not too bad (well, as 'not bad' as it can get with COVID-19) luckily. Is it bad where you are?

Profile icon
xxpertHacker

@LizFoster Hasn't even touched my city... yet. But it will, unfortunately, as it's very close.

But back to that formula I'm using, I thought about it and 2x/(2x-1) can be simplified to x/(x-.5), dunno why he didn't do this himself.

Profile icon
LizFoster

@StudentFires Wouldn't that just give half the result though?

Profile icon
LizFoster

@StudentFires Oh, shoot, nevermind. I am dumb _ _

You're right, that would work as well.

Profile icon
xxpertHacker

@LizFoster You aren’t dumb, now if you didn’t catch your own err, maybe.
But I’m pretty sure you’ve been taught a higher level of Mathematics than I’ve been taught, since I’ not even in pre-Calculus yet.

Profile icon
LizFoster

@StudentFires I re-consolidated the equation, so it looks a lot more clean now.

Screenshot 2020-04-03 at 12.21.40 AM

Profile icon
xxpertHacker

@LizFoster Bit late, I already have that. In to code too.

Profile icon
LizFoster

@StudentFires I suppose you're right.. ^ ^*

Trust me, calculus is a lot of fun; it is just that, most calculus teachers are really boring. You should watch 3Blue1Brown's "Essence Of Calculus" series if you are interested in that stuff. He explains it in an easy to understand way, and it's entertaining too (which cannot be said of most calculus teachers)!

Profile icon
LizFoster

@StudentFires Aaaaaa darn it! I felt cool for a second there T~T

Profile icon
xxpertHacker

@LizFoster Go look at the very top of this message chain. Carefully look at the first images I posted. I had the squared version in the very beginning.
Always 1 step ahead

Profile icon
LizFoster

@StudentFires T~T Rest in peace

Profile icon
codeitfast

Nice! You could also use sin and cos!

Profile icon
LizFoster

@codeitfast Thank you so much!

Yes, I could, but apparently they are based on π themselves.. I don't want to use things derived from π to find π

Profile icon
codeitfast

@LizFoster true. However, if you know calculus, you can also use it to find the area and then, when you have the area, since you have the radius, find pi.

Profile icon
LizFoster

@codeitfast Ooh, good point. As luck would have it, I do know calculus! (Lol)

Profile icon
LizFoster

@codeitfast Now, how exactly would I use sin for that? It has something to do with internal angles (at least, I would assume so), but otherwise I am in the dark..

Profile icon
codeitfast

@LizFoster you actually could just change x by something like .00000001 until you get 180, then use the Pythagorean theorem during each interval to find the circumference, and you could get pi.

Profile icon
LizFoster

@codeitfast Good point, though could you explain that a bit more? what is x an argument to? tan(x)?

Profile icon
[deleted]

Oh wow. It took 10 minutes to calculate the numbers.

Profile icon
LizFoster

@CodeABC123 What do you mean? It takes less than 3 seconds..?

Profile icon
[deleted]

Not for me. @LizFoster

Profile icon
[deleted]

Maybe you have a fast computer. @LizFoster

Profile icon
LizFoster

@CodeABC123 Oh, how weird. That's surprising, as I am on a fairly low-end chromebook (Lol)

Profile icon
[deleted]

I’m on an iPad. @LizFoster

Profile icon
LizFoster

@CodeABC123 Ah, I see, that probably explains it ^ ^*

Sorry it takes so long..

Profile icon
AphixDev

wow

Profile icon
LizFoster

@nt998302 Lol

What do you think?

Profile icon
cs906941

Im not a great programmer, but maybe you could use the leibniz formula? Where you start with an approximation of pi at 1, and then subtract 1/3, add 1/5, subtract 1/7. add 1/9, etc. That times four is pi. I have a repl for this on my profile if you're interested.

Profile icon
LizFoster

@cs906941 Funnily enough, I have that as well! You can find it here: https://repl.it/@LizFoster/140

One of the first approximations I made, actually, ha ha ha!

Profile icon
finlay44111

for equation 7 you are using sine, which is based on pi itself. You should look into some infinite sums, there are some really simple ones, like 1 + 1/4 + 1/9 + 1/16 + 1/25 + 1/36 (reciprocals of square numbers) and that infinite sum tends to ((pi)^2)/6

Profile icon
LizFoster

@finlay44111 Oh, I see, I did not remember that sin was based on π.

Is that series (the reciprocals of square numbers) by chance related to ζ(2)? I am not sure if they are related, but here is the equation I refer to (from the Wikipedia on ζ):

Screenshot 2020-03-31 at 11.45.00 PM

If not, what is that infinite sum called? It looks to be the same as the Basel Problem, which I think I have done.. (might be wrong though, Lol)

Profile icon
finlay44111

@LizFoster yeah that is exactly the series it is, it is riemann zeta function, you can actually get pi from any even value you pass into the riemann zeta function, eg, riemann-zeta(4) == (pi^4)/90

Profile icon
finlay44111

@LizFoster also the Basel problem is the same as the riemann-zeta(2)

Profile icon
LizFoster

@finlay44111 How interesting, I never thought about that!

Profile icon
LizFoster

@finlay44111 Okay, I thought so, but wasn't fully sure (Lol)

Profile icon
xxpertHacker

@LizFoster
I remembered someone who loved big numbers, so I thought you might like to see this: https://repl.it/talk/share/Using-Memoization-to-Speed-Up-Code/31937.

Profile icon
LizFoster

@StudentFires Oh wow, that's awesome! I'll try to puzzle my way through the code (^ ^**) (Lol)

Profile icon
xxpertHacker

@LizFoster The only problem is, I'm not sure if Python can return functions, so this might not be possible in Python, but I might be able to find a way to calculate π quickly.

Profile icon
LizFoster

@StudentFires Wait, do you mean printing functions that return a value? Python can do that if so.

Profile icon
xxpertHacker

@LizFoster Well then, perfect! The idea can be implemented in Python. Sorry, I don't know Python... yet.

Profile icon
LizFoster

@StudentFires That's perfectly fine, don't worry about it!

Ha ha ha.

I'll see what I can do about getting one written for python... Right after I finish writing a code for finding all Pythagorean Triples with side c being 50 or less

I am going to have a long night.... T~T

Profile icon
xxpertHacker

@LizFoster Unless you're trying to challenge yourself on purpose, I suggest leveraging the internet to reduce your workload. Just maybe your night won't be as long.

Profile icon
LizFoster

@StudentFires Yeah, you're right... ( ̄ヘ ̄); It would make things a lot easier, ha ha ha

I do not even have to do this tonight, I just hate having to take more than a day to finish stuff like this. (Lol)

Profile icon
MrEconomical

1004 decimal places get on my level

Profile icon
LizFoster
Profile icon
[deleted]

Those Unicode character variable names are astonishing.

Profile icon
LizFoster

@IreoluwaRaufu Really? (Lol)

Profile icon
[deleted]

@LizFoster Yeah, they inspired me to experiment with variable identifiers, and there's actually a wide range of characters you can use to name a variable, list, or other data structure in Python3. (The more ya know.)

Profile icon
LizFoster

@IreoluwaRaufu Yeah! Although, I still need to check if Japanese symbols are valid. Probably not ^ ^*

Profile icon
[deleted]

They can be more accurate. Also, more a more precise value of "year," use 365.25, or find a more accurate decimal.

Profile icon
staticvoidliam7

how did i know this would happen lol

Profile icon
LizFoster

@LiamDonohue Expect more to come (^)

Profile icon
staticvoidliam7

yup next thing i know u will be doing quantum physics lol @LizFoster

Profile icon
LizFoster

@LiamDonohue Don't even get me started... (Lol)

Profile icon
UzayAnil

noooooooooooooooooiiiiiiiiiiiiiiiccccccccccccce!

(noice)

Profile icon
LizFoster

@UzayAnil Thank you!!

Profile icon
Roar123

Amazing, I've never seen this many pi approximations in one program in my life!