How to calculate pi

Jul 10, 2021 Last reply: 5 years ago 64 Replies

I would prefer something that Euclid dreamed up.

355/113 is much more accurate (by 4 orders of magnitude). Unfortunate that 355 doesn't fit into an 8-bit byte as well as 22.

The one real use case I've seen is precision optics, especially for things like LIGO, where one is tracking optical lengths to 0.01 wavelength precision over optical paths in the kilometers, with cavity Qs in the many millions, so one traces the rays as they bounce back and forth many many times. (Don't recall the number of bounces, but it is very large.)

Mathematics also can suffer from mismatched brackets, and so it has evolved a number of tools to debug bracket nesting.

The student/hobbyist versions of MMA isn't all that expensive, and run on Windows, Mac, and Linux.

.

formatting link

.

formatting link

Joe Gwinn

Mathcad - now that is a blast from the past! Does it still work on Win7? More of a scratchpad but pretty good for trying out engineering ideas.

I found Maxima with the GUI much less difficult to get to grips with than the text interface even though it was less powerful that way. I'm using the Windows port but Linux and Mac iOS is also supported.

G = 1, c = 1, h_bar = 1, k = 1, Q_e = whatever.

I don't think Euclid had a modern understanding of pi being a meaningful number, even, it's not mentioned in _Elements_.

He proved that the ratio of a circle to the square on its radius is constant, which is effectively the same thing as proving pi is constant.

formatting link

It's still sold by PTC, I think. Mine is version 2001i, which is Win32, so it works fine on Win 7 and under Wine in Linux. (You do need a few native DLLs for Wine.)

I mostly use Mathcad for what I call 'photon budgets', which are actually first-principles feasibility calculations for instruments or measurement schemes in general. If you don't do the theory, there's no way of knowing how good your gizmo _could_ be, so you have no idea how well you're doing.

I need to be able to make nice printed documents with a lot of properly-formatted text and plots to send to clients. Mathcad is nice that way because they can all be 'live' for me, but few of my clients use it, so they get the PDFs.

Cheers

Phil

I thought I needed 64-bit division to calculate frequency delta words for the AD9959 DDS chip, but wound up implementing reciprocal division. If done correctly, you get better than PPB accuracy using only a

32x32->64 multiply:
formatting link
formatting link

Yes, I know, Arduino, urk. But that's what was called-for in this case.

Even the little AVR can do "64-bit division" in about 70us using this method.

Indeed. One wonders what business they think they're in.

Clifford Heath.

We had to grunt out the math for the LMX2571 synthesizer chip. It's a matter of finding the best N/M to scale the clock to the target frequency, with a bunch of other divisors somewhere, and some rules about selecting VCOs and spurs and stuff.

Once it's working, it's very good.

If what you have now will do what you want well enough then I would recommend sticking with it until you run into something that forces a change to solve a problem. The learning curve to make full use of Maxima is pretty steep and it does have some rough edges here and there.

I only jumped ship because I had a horrible expression that I needed to differentiate and it defied my existing tools and all manual efforts. Maxima got it and could solve the resulting quartic to a closed form. - incredibly ugly messy expression but to my surprise it could do it.

I was reading a paper not that long ago with pi = 1

It was most confusing...

Although it's possible that some sequences never occur.

It's interesting to note that sequences do repeat but, even if the sequence is a gogolplex long, the next digit will be different each time.

Maybe the latter disproves the former.

This would be integer division, not IEEE floating-point (which can do integer arithmetic only to 52 bits)..

Most modern instruction set architectures support multi precision integer arithmetic in (assembly code) software.

Joe Gwinn

Depends really. The most common x87 implementation can do a 64 bit mantissa and 16 bit exponent in hardware but MS C/C++ no longer supports it and makes a hash of consistent rounding to 53 bits for good measure.

I haven't tried it but I expect the chip can handle 64 bit integer loads and arithmetic perfectly well but the compiler will only let you store a

53 bit mantissa and 11 bit exponent result (unless you knobble it).

ISTR MSC v6.0 was the last with proper long double support included.

High precision integer arithmetic isn't all that hard.

No -- and need not be implemented in ASM.

But, it is considerably slower. And, things like transcendental functions get *really* expensive (as there is no hardware assist).

OTOH, you often don't need that sort of range/precision for run-of-the-mill calculations.

PowerBasic allows quad integer and extended float (10 byte) variables.

We've used that when c was not good enough, or too slow.

Roundabout way of showing pi is a constant, an n-ball in an n-dimensional Euclidean space is a set of points equidistant from a central point. A circle is a 2-ball. Without assuming pi is a constant you can derive a recurrence relation:

formatting link

and use the functional equation for the gamma function to derive an expression for the volume of an n-ball, and take the factor of gamma(1/2) to be some unknown constant.

Then pi is defined by the value of gamma(1/2) needing to be sqrt(pi), the unique constant such that the volume of the n-ball V_n(R) is always maximal with respect to its surface area for all permutations of n, R from the set of reals (Euler-Lagrange equations.)

I think...

GCC can do quad FP precision OK. It is the MickeySoft compiler that has had its extended floating point support almost completely hobbled.

BITD the Intel C++ compiler could do that too, and plugged into Visual Studio.

Cheers

Phil Hobbs

Join the Discussion

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

Didn't find your answer?

Ask the community — no account required