Pi approximation games

May 01, 2012 134 Replies

Instead of doing productive work, I just spent a few enjoyable minutes with Scilab finding approximations to pi of the form m/n.



Because I'm posting to a couple of nerd groups, I can be confident that most of you probably know 22/7 off the tops of your heads.



What interested me is how spotty things are -- after 22/7, the error drops for a bit until you get down to 355/113 (which, if you're at an equal level of nerdiness to me will ring a bell, but not have been swimming around in your brain to be found).



But what's _really_ interesting, is that the next better fit isn't found until you get up to 52163/16604. Then things get steadily better until you hit 104348/33215 -- at which point the next lowest ratio which improves anything is 208341/66317, then 312689/99532. At this point I decided that I would post my answers for your amusement, and get back to being productive.



Discrete math is so fun. And these newfangled chips are just destroying the joy, by making floating point efficient and cheap enough that you don't need to know little tricks like pi = (almost) 355/113.


My liberal friends think I'm a conservative kook. My conservative friends think I'm a liberal kook. Why am I not happy that they have found common ground? Tim Wescott, Communications, Control, Circuits & Software http://www.wescottdesign.com

I like the idea that both 22 and 7 each fit into a byte whereas 355 does not. And, 22/7 is hi by only .04%. Beautiful!

John S

245/78. It's only a bit better than twice as good as 22/7 -- then along comes 355/113, which is over 1000 times better than 245/78.
My liberal friends think I'm a conservative kook. My conservative friends think I'm a liberal kook. Why am I not happy that they have found common ground? Tim Wescott, Communications, Control, Circuits & Software http://www.wescottdesign.com

-->

formatting link

:-)

Jack Crenshaw's book, "Math Toolkit for Real-Time Programming"

formatting link
spends a lot of time discussing how to make "good enough" approximations of various, e.g., transcendental functions... and how to know when "good enough" really is. It's quite handy for this sort of thing...

Suppose you do the same thing with the fine structure constant -- let me know what you discover.

Steve

I once knew pi to 100 places, but now I've forgotten everything past

19.
John Larkin Highland Technology, Inc jlarkin at highlandtechnology dot com http://www.highlandtechnology.com Precision electronic instrumentation Picosecond-resolution Digital Delay and Pulse generators Custom laser drivers and controllers Photonics and fiberoptic TTL data links VME thermocouple, LVDT, synchro acquisition and simulation

My old HP35 calculators have a key for pi. The newer ones hide it, a tiny pastel shift key thing. So I just key in 3.14. Rob down the hall uses 3.

We are increasingly using floats in embedded stuff. Our ARM LPC3250 has SIMD hardware FP operations.

John Larkin Highland Technology, Inc jlarkin at highlandtechnology dot com http://www.highlandtechnology.com Precision electronic instrumentation Picosecond-resolution Digital Delay and Pulse generators Custom laser drivers and controllers Photonics and fiberoptic TTL data links VME thermocouple, LVDT, synchro acquisition and simulation

245/78 is more easily forgotten.

I learned to twin the first 3 odd digits - 113355. Then divide the first 3 into the last 3. Easily remembered. Art

but highly mnenomic - it's 2345678 with the 3 dropped and the 6 turned into a divide sign...

-- Les Cargill

Now you mention it :-)

You can always declare a constant or use pi=4*arctan(1) although I seldomly see the latter.

Failure does not prove something is impossible, failure simply indicates you are not using the right tools... nico@nctdevpuntnl (punt=.) --------------------------------------------------------------

Off the subject, but this one is really funny...

formatting link

That's mean - at the end "not all these are wrong" - several looked close (at least in my head).

Randy Yates DSP/Firmware Engineer 919-577-9882 (H) 919-720-2916 (C)

Yes. It was the first problem in the book for the HP 25C calculator that I got many years ago.

There is an algorithm that some calculators use for converting a decimal result to a fraction. If I remember, that one easily finds successively better fractions approximating any given value.

I don't remember the details, but I do remember how funny it is, in that at one point it takes two fractions, and adds their numerators and denominators, before goint to the next step.

I believe it is described in the manual for one of the HP calculators that does that conversion.

Otherwise, I have the TI-92, which will generate fraction (rational) results, then you ask for an approximate result. Some calculations will give a symbolic pi result.

-- glen

...

not quite m/n but

alpha = cos(pi*137)/137 * tan(pi*(29*137))/(pi*(29*137))

actually i think that sqrt(4*pi*alpha) = 0.30282212 is the more fundamental number than the fine-structure constant. the fine-structure constant should be thought of as a consequence of this number.

r b-j rbj@audioimagination.com "Imagination is more important than knowledge."

i've sent him some series that were simpler and better than his (at least those that were published at the time). i have no idea what rules of optimization he was using.

he wrote back. didn't see anything happen about it since.

r b-j rbj@audioimagination.com "Imagination is more important than knowledge."

We had a teacher that insisted it was exactly equal!

John Devereux

I recall the time when you couldn't consider 25.4 mm to be exactly one inch. But, they fudged enough standards so that it is now exact.

Prior to that, neither the British inch nor the American inch measures 25.4 ... and they deviated from that value in opposite direction!

S.

Even the integer-only cortex M3s we use take less than a microsecond for most things. On a 72MHz STM32F2:

Double Precision: 0.415us / 49.852 cycles /multiply 0.378us / 45.403 cycles /add 2.414us / 289.702 cycles /divide Single Precision: 0.194us / 23.350 cycles /multiply 0.250us / 30.052 cycles /add 0.610us / 73.202 cycles / divide

John Devereux

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required