Pi approximation games

Calculate pi using "infinite precision" numbers, and you get it to infinite precision. Obviously you can't print out the whole answer - but you can print out as much of the answer as you want, until the machine runs out of memory or time.

An "infinite precision number" is usually held as a list of digits, along with a method for calculating more digits. You can then write functions that can add, subtract, multiply and divide such numbers. It is particularly convenient to use a functional programming language for such tasks, as they are good at working with unlimited lists, and with manipulating functions (such as the digit generator function).

To calculate pi, the easiest way is to note that atan(1) = pi/4, and atan(x) = x - x^3 / 3 + x^5 / 5 - x^7 / 7 + ... Once you have the individual parts in place, the rest is easy. Of course, you end up with lots of unlimited lists of unlimited lists, etc.

Mathematically speaking, what you have is precise representation of /all/ the digits of pi. You can't display them all, as you have limited ram and time - but it /is/ precise and contains /all/ the digits - just as "0.33..." is a precise decimal representation of /all/ the digits of

1/3 (the "..." gives the method of producing any digits you want).
Reply to
David Brown
Loading thread data ...

But that isn't how the trick was done. There is a cute expression for the Nth hexadecimal digit representation of pi detailed at:

formatting link

No-one in their right mind would start from that crude series today - its convergence for x=1 is absolutely hopeless. See for example:

formatting link

The algorithm that can supply the Nth digits of pi lazily *only* works for hexadecimal digits (or base 2^N for certain N).

It doesn't work at all for the *decimal* representation of pi.

--
Regards,
Martin Brown
Reply to
Martin Brown

I have in my hands an "Nelson's Encyclopedia" printed in 1951 (12 years before the international inch) it says the metre (then defined by scratches on a bar in Paris) is is about 1.0936143 yards (then defined by scratches on a bar in London)

1 / 36 / 1.0936143 comes to .025399977m

so, yes the American inch was the bigger of the two.

--
?? 100% natural

--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net
Reply to
Jasen Betts

I think you missed the earlier post in which I said that I /did/ do this, as a project at university. There may be other ways to calculate pi that are more efficient in base 16 - but that's a different matter entirely.

As I said, it was a university project. The aim was not to calculate pi, but to understand the usage of infinite lists, infinite precision numbers, ways to manipulate them, and ways to prove that the code to do so is correct. The rate of convergence is utterly irrelevant.

Just for fun, I figured out an alternative series that was faster to converge (possibly (atan(1/2) + atan(1/3)), though I can't remember for sure).

Nonsense. I did it, and I didn't find it particularly hard.

Perhaps you misunderstand what "lazy evaluation" actually is. The algorithm you reference is a way to calculate a hexadecimal digit of pi without having to calculate the previous digits - no such method is known for calculating the decimal digits (though that does not mean one does not exist). But that has nothing at all to do with lazy evaluation, which simply means that the relevant numbers are calculated when needed rather than in advance. It means you can work with an unlimited list, and treat it as though it were a fully calculated infinite list, without the computer actually having to calculate anything until the last minute.

Reply to
David Brown

We just have to slightly increase the value of 1, so pi will equal 3. :-)

-jm

Reply to
Jukka Marin

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?

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)?

Reply to
xpzzzz

I just copied and pasted from a web page, and didn't notice "Gott" vs. "Gatt".

I'm very much afraid to look up what "Gatt" might be in German.

DTA

Reply to
David T. Ashley

Hey Sinner,

I was just messing with you to throw in a quote from a number theorist indicating that God approves of the integers only ...

Floating point is trash for the masses (and for prototypes and student projects). It has no place in serious embedded systems.

Issues:

a)Far slower on low-end micros.

b)Hard to analytically bound the error that arises from calculations (integers are more friendly in that regard--most errors can be reduced to the floor() function).

c)God does not approve (see the quote in German above).

DTA

Reply to
David T. Ashley

Proving properties of numbers, such as whether they are rational, irrational, transcendental, normal, etc., is generally very difficult. And many of their properties probably have no better explanation than coincidence.

Pi is known to be "normal", meaning that if you write out its "decimal expansion" in any base, the digits will be evenly distributed amongst all possible digits.

Reply to
David Brown

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.

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.

--
Regards,
Martin Brown
Reply to
Martin Brown

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 :-)

Reply to
Ignacio G.T.

Interesting!

Taylor Maclaurin expansions are great for getting insight into nonlinear stuff.

formatting link

Of course MATLAB and such like will do this, but they don't work for free.

Reply to
Spehro Pefhany

I only seem to be using ARMs now, Cortex M3 or M4 in new projects.

It is also hard to work with integer representations of real-world quantities. You have to scale everything to fit, keep track of units and scaling factors. Keep track of overflows and underflows, loss of precision. Decide what register width to use for each step of the calculation, and use the correct types to achieve this. Rewrite the calculation so as to minimise the dynamic range of intermediate values. With floats you can usually just convert to standard units at the start of the calculation, and not worry too much about it. If you really need high precision then there are doubles.

Also there is worrying about floating point registers in context switches, non-atomic operations and inconsistent or ambiguous data formats.

I do still keep most things integer until they are "used" - an array of ADC values say. But it is kind of a load off to be able to just work directly in the applications natural units when I want to.

--

John Devereux
Reply to
John Devereux

formatting link

Scilab is free...

Reply to
Andre

I've some Canadian relatives who were very vocal on their right to be called American.

Reply to
Richard Owlett

Yeah, but you'd have an irrational number of fingers.

Jeroen Belleman

Reply to
Jeroen Belleman

And I would not be surprised that floating-point numbers were also an ABOMINATION UNTO NUGGAN.

--------------------------------------- Posted through

formatting link

Reply to
RCIngham

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.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Reply to
Jerry Avins

Mac, you clearly haven't learned about the continual march of technological progress.

It won't get better if you Pickett.

--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
Reply to
Rob Gaddi

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)

formatting link

formatting link

Reply to
Robert Wessel

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.