DSPRelated.com
Forums

Pi approximation games

Started by Tim Wescott May 1, 2012
On 5/1/2012 7:16 PM, Tim Wescott wrote:
> 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.
Try sqrt(2). 7/5 is fair. 17/12 is good enough for carpentry. 41/29 has less than one fifth of that error, but 99/70 is much better yet. In fact, the best (in terms of accuracy per bit expended) have an odd numerator and an even denominator. Jerry -- Engineering is the art of making what you want from things you can get. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
On Thu, 03 May 2012 14:00:51 +0100, Martin Brown
<|||newspam|||@nezumi.demon.co.uk> wrote:

>On 03/05/2012 12:50, xpzzzz wrote: >> On Thu, 03 May 2012 12:53:39 +0200, David Brown wrote: >> >>>> The algorithm that can supply the Nth digits of pi lazily *only* works >>>> for hexadecimal digits (or base 2^N for certain N). >>>> >> >> An YES answer to a question that I have had rattling around for a while, >> to wit - >> >> Are there properties (aside from trivial ones) of base-n numbers not >> shared by base-a-different-n numbers. >> >> *Why* can you skip ahead to a hex digit of pi but not a dec digit? > >Because an infinite series expansion for PI is known where all the >components being summed together are of the form sum ( 1/16^k.f(k) ) > >It is therefore possible to start from a chosen digit position and >compute just the digits of interest from there on. The URL I posted >describes a bit more of the details of the algorithm. > >> Is this unique to pi and base 2^x, or is it true for certain irrational >> numbers, or all? If only some, are there similar (lack of) algorithms >> for other combinations of base and irrational number(s)? > >It is entirely possible that some other irrationals may have an elegant >series expression in some base or other, but off hand I don't know of >any other commonly known examples of this. A quick back of the envelope >playing around suggests that the golden ratio phi may well have an >expansion base 8 that is amenable to the same sort of trick. > >phi = (1 + sqrt(5))/2 = 1/2 + sqrt(1 + 1/4) > >series expansion for sqrt(1+x) with x = 1/4 > >1/2 + 1 + x/2 - x^2/2!/4 + 3x^3/3!/8 - ... > >1 + 1/2 + 1/8 - sum[k=2,inf]{ 1/(-4^k) ((2k-3)!/((k-2)!k!) } > >as ever subject to mistakes, typos and algebra errors.
BBP's original paper (link below) lists a number of other examples, including log(2), log (9/10), pi**2, many base 2 logs, ... Others have computed other constants (see Wiki article for links) http://www.ams.org/journals/mcom/1997-66-218/S0025-5718-97-00856-9/home.html http://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_formula
Tim Wescott wrote:
> On Wed, 02 May 2012 15:29:19 -0500, David Drumm wrote: > >> I wonder if there's a theorem that states: given a small positive number >> epsilon, there exists a rational number that is within epsilon to pi. > > There is -- or at least there's a theorem that states that there exists a > rational number that's within epsilon of _any_ irrational number, be it > pi, e, or the precise length, in inches, of your left foot. > > In fact, in some mathematical circles that theorem is used to provide > proof that the irrational numbers are, indeed, real -- and therefore to > prove that the real numbers (which is the union of the sets of all > rational numbers and all irrational numbers) is, indeed, real and > continuous. >
I see a circle in there... I thought the irrationals were *by definition* in the reals? SFA that goes, there's mostly Cantors diagonalization and that's all you need... (it is always interesting to talk to people who came to this sort of thing in a different way ). -- Les Cargill
Spehro Pefhany wrote:
> On Wed, 2 May 2012 23:38:26 -0700 (PDT), Robert Adams > <robert.adams@analog.com> wrote: > >> >> I've recently discovered a program called Wolfram Alpha. If you have >> an obsessive interest in series expansions, you can spend hours with >> this program. >> >> Bob > > Interesting! > > Taylor Maclaurin expansions are great for getting insight into > nonlinear stuff. > > http://www.wolframalpha.com/entities/calculators/taylor_series_calculator/ew/pd/4g/ > > Of course MATLAB and such like will do this, but they don't work for > free. >
Octave is... -- Les Cragill
On Thu, 03 May 2012 12:32:12 -0500, Les Cargill
<lcargill99@comcast.com> wrote:

>Spehro Pefhany wrote: >> On Wed, 2 May 2012 23:38:26 -0700 (PDT), Robert Adams >> <robert.adams@analog.com> wrote: >> >>> >>> I've recently discovered a program called Wolfram Alpha. If you have >>> an obsessive interest in series expansions, you can spend hours with >>> this program. >>> >>> Bob >> >> Interesting! >> >> Taylor Maclaurin expansions are great for getting insight into >> nonlinear stuff. >> >> http://www.wolframalpha.com/entities/calculators/taylor_series_calculator/ew/pd/4g/ >> >> Of course MATLAB and such like will do this, but they don't work for >> free. >> > >Octave is...
Yup, Octave and Scilab. But not Mathematica, MathCAD, MATLAB etc.
On 2012-05-03, Jeroen Belleman <jeroen@nospam.please> wrote:
> On 2012-05-03 13:32, Jukka Marin wrote: >> On 2012-05-02, John Devereux<john@devereux.me.uk> wrote: >>>> 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. >>> >>> Aha, good idea, we should standardize pi to a more convenient value! :) >> >> We just have to slightly increase the value of 1, so pi will equal 3. :-) >> >> -jm > > Yeah, but you'd have an irrational number of fingers.
Hmm.. true, but I think I ned pi more often than the number of my fingers, so I think it would be a win. -jm
On Thu, 03 May 2012 09:56:24 -0500, Richard Owlett
<rowlett@pcnetinc.com> wrote:

>> You surely mean inhabitants of the United States of America. Mexicans, >> Argentinians and Cubans, though Americans themselves, don't confuse >> English and British. Another common mistake made by yankees :-) > >I've some Canadian relatives who were very vocal on their >right to be called American.
I thought that the PC term for "Murricans" is "USAnians". Stephen -- Stephen Pelc, stephenXXX@mpeforth.com MicroProcessor Engineering Ltd - More Real, Less Time 133 Hill Lane, Southampton SO15 5AF, England tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691 web: http://www.mpeforth.com - free VFX Forth downloads
On 5/3/12 1:31 PM, Les Cargill wrote:
> Tim Wescott wrote: >> On Wed, 02 May 2012 15:29:19 -0500, David Drumm wrote: >> >>> I wonder if there's a theorem that states: given a small positive number >>> epsilon, there exists a rational number that is within epsilon to pi. >> >> There is -- or at least there's a theorem that states that there exists a >> rational number that's within epsilon of _any_ irrational number, be it >> pi, e, or the precise length, in inches, of your left foot.
i thought that i said the same thing, but without the left foot.
>> >> In fact, in some mathematical circles that theorem is used to provide >> proof that the irrational numbers are, indeed, real -- and therefore to >> prove that the real numbers (which is the union of the sets of all >> rational numbers and all irrational numbers) is, indeed, real and >> continuous. >> > > I see a circle in there... > > I thought the irrationals were *by definition* in the reals?
i think so. it's a dichotomy. the rationals are real numbers that can be expressed as m/n (for integers m & n) and the irrationals are the real numbers that remain after removing the rationals. and there are a helluva lot more irrationals (uncountably infinite) than there are rationals (countably infinite). -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
John Larkin <jjlarkin@highNOTlandTHIStechnologyPART.com> writes:

> On Wed, 02 May 2012 11:10:53 +0200, David Brown > <david@westcontrol.removethisbit.com> wrote: > >>On 02/05/2012 01:16, Tim Wescott wrote: >>> 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. >>> >> >>Wikipedia is often a great starting point for these sorts of things. It >>typically has enough information to give you some hints - but not so >>much that you can't have fun finding out more: >> >><http://en.wikipedia.org/wiki/Pi#Continued_fractions> >> >> >>At university I remember a project that involved calculating all the >>digits of pi. It was written using a functional programming language >>(similar to Haskell) - the result was an unending list of the digits of >>pi. But since the language used lazy evaluation, it didn't bother >>calculating the entries until you tried to print them out. I used >>polynomial expansions of arctan() to do the sums. > > There was a short PDP-8 assembly program that printed the digits of e > forever.
Yes, it is pretty easy to write a program to calculate e. e has the value 2.11111111... in factorial radix. The first digit after the radix point is in the 1/2 place, the next is in the 1/6 place, and so on. All you have to do to print out the value of e is convert to base 10. Scott -- Scott Hemphill hemphill@alumni.caltech.edu "This isn't flying. This is falling, with style." -- Buzz Lightyear
In article <jnulba$4q0$1@dont-email.me>, rbj@audioimagination.com says...
> On 5/3/12 1:31 PM, Les Cargill wrote: > > Tim Wescott wrote: > >> On Wed, 02 May 2012 15:29:19 -0500, David Drumm wrote: > >> > >>> I wonder if there's a theorem that states: given a small positive number > >>> epsilon, there exists a rational number that is within epsilon to pi. > >> > >> There is -- or at least there's a theorem that states that there exists a > >> rational number that's within epsilon of _any_ irrational number, be it > >> pi, e, or the precise length, in inches, of your left foot. > > i thought that i said the same thing, but without the left foot. > > >> > >> In fact, in some mathematical circles that theorem is used to provide > >> proof that the irrational numbers are, indeed, real -- and therefore to > >> prove that the real numbers (which is the union of the sets of all > >> rational numbers and all irrational numbers) is, indeed, real and > >> continuous. > >> > > > > I see a circle in there... > > > > I thought the irrationals were *by definition* in the reals? > > i think so. it's a dichotomy. the rationals are real numbers that can > be expressed as m/n (for integers m & n) and the irrationals are the > real numbers that remain after removing the rationals. > > and there are a helluva lot more irrationals (uncountably infinite) than > there are rationals (countably infinite). > >
Aleph1 = 2**Aleph0 Gerardus