LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pi Approximation


@altenbach wrote:

@JÞB wrote:
Alternatively, since pi*3 < 10 you could have changed the code you already posted modified by finding the least error to pi-3 instead of pi and then simplifying the mixed fraction 3+N/D) to achieve the same results. And still the trivial approximateion 3 would be ommited as 1/7 is closer to pi-3 than 0/1.

Don't quite understand. Wouldn't that just be more math? My list does not have the trivial approximation because 22/7 is the best approximation with a single digits denominator.


Yes, additional math primitives on the BD. but the identical underlying algorithm.  Easy to switch from digits of N to of D without rewriting the whole loop  ( just change 1 constant from 0 to 3 )  It could even be argued that the pi-0 and 0*D+N are implied in the original code  😀 they simply Rube-Goldburg out when solving the problem for digits of numerator.


"Should be" isn't "Is" -Jay
0 Kudos
Message 21 of 30
(327 Views)

@JÞB wrote:

@altenbach wrote:

@JÞB wrote:
Alternatively, since pi*3 < 10 you could have changed the code you already posted modified by finding the least error to pi-3 instead of pi and then simplifying the mixed fraction 3+N/D) to achieve the same results. And still the trivial approximateion 3 would be ommited as 1/7 is closer to pi-3 than 0/1.

Don't quite understand. Wouldn't that just be more math? My list does not have the trivial approximation because 22/7 is the best approximation with a single digits denominator.


Yes, additional math primitives on the BD. but the identical underlying algorithm.  Easy to switch from digits of N to of D without rewriting the whole loop  ( just change 1 constant from 0 to 3 )  It could even be argued that the pi-0 and 0*D+N are implied in the original code  😀 they simply Rube-Goldburg out when solving the problem for digits of numerator.


I'm assuming that CA is still somewhere near a porcelain fixture after realizing that just a little  Rube-Goldburg code would have reduced the likelihood of a Bug in his second creation of pi.  Honestly,  I don't think I have ever had an opportunity to hit my friend and mentor with a valid reason to intentionally introduce additional functions on a BD that are Rube-Goldburg for original code.  But, CA did suggest solving for Denominator himself!

 

Personally I am torn about the reduceble x/ 1017 fraction.(9×n/9× 113)  

 

There is a 6pi factor in scarcity of prime numbers that suggests to me that the 1017th ratio is an only reducible fraction that could be found with the VI.  I just can't prove it doing the math in my head.


"Should be" isn't "Is" -Jay
0 Kudos
Message 22 of 30
(296 Views)

@JÞB wrote: I'm assuming that CA is still somewhere near a porcelain fixture after realizing that just a little  Rube-Goldburg code <...>  can't prove it doing the math in my head.

I would like to kindly remind all participants that the initial requirement from our dear colleague Yamaeda was “a fraction that approximates π to 2600 digits.

 

Although the provided code can certainly be used as a "getting started" point, it will not solve the original problem at all. The reason is simple: once you reach certain amount of digits, you must work with arbitrary‑precision numbers, which means moving completely away from IEEE‑754 floating‑point representation.

 

In practice, this is usually handled by representing numbers as strings (or arrays of digits) and re‑implementing the basic arithmetic operations from the scratch — add/sub/mul, and so on — using big‑number arithmetic.

 

This can absolutely be done in LabVIEW, for sure, but it involves a significant amount of painstaking work (not sure how to translate German “Fleißarbeit” properly here).

 

For reference, I have attached a pure C implementation as a simple NI LabWindows/CVI project that performs such computations with very large numbers just in few seconds:

 

>pi-approx.exe
22/7
333/106
355/113
103993/33102
104348/33215
208341/66317
312689/99532
833719/265381
1146408/364913
4272943/1360120                                                                           
...
256839923861488782607902790348837497679/81754686931803956266412424933874257924

 

When someone would like to port this mostly AI-generated code to the LabVIEW and fix all minor issues — you're welcome, but not me myself, thank you (makes no sense, because such libraries already available). As "benefit" we can get basic elements of the "Big Numbers" library for LabVIEW (but this is really rarely need in every day programming, may be somewhere in deep physic experiments in the labs).

 

As OffTopic — the most beautiful way to approximate π, in my humble opinion, is the famous Buffon’s needle experiment, introduced by Georges‑Louis Leclerc and Comte de Buffon, in the 18th century (1777, to be exact). In this experiment, you drop a needle or fire matches of length L onto a plane with parallel lines spaced by the same distance L. You then count how many needles cross a line and how many do not. If you throw N needles and C of them cross a line, then π can be approximated as 2N / C. This elegantly connects geometry, probability, and π in a single experiment.

However, this is not related to the problem discussed above, although it can be easily implemented in LabVIEW as a beginner exercise.

Message 23 of 30
(260 Views)

@Andrey_Dmitriev wrote:

@JÞB wrote: I'm assuming that CA is still somewhere near a porcelain fixture after realizing that just a little  Rube-Goldburg code <...>  can't prove it doing the math in my head.

I would like to kindly remind all participants that the initial requirement from our dear colleague Yamaeda was “a fraction that approximates π to 2600 digits.


It wasn't a requirement, it was a fun meme that inspired me. 🙂 This one. Apparently correct to 2612 digits!

Yamaeda_0-1780405035039.png

 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 24 of 30
(238 Views)

@Andrey_Dmitriev wrote:

@JÞB wrote: I'm assuming that CA is still somewhere near a porcelain fixture after realizing that just a little  Rube-Goldburg code <...>  can't prove it doing the math in my head.

I would like to kindly remind all participants that the initial requirement from our dear colleague Yamaeda was “a fraction that approximates π to 2600 digits.

 

Although the provided code can certainly be used as a "getting started" point, it will not solve the original problem at all. The reason is simple: once you reach certain amount of digits, you must work with arbitrary‑precision numbers, which means moving completely away from IEEE‑754 floating‑point representation.

 

In practice, this is usually handled by representing numbers as strings (or arrays of digits) and re‑implementing the basic arithmetic operations from the scratch — add/sub/mul, and so on — using big‑number arithmetic.

 

This can absolutely be done in LabVIEW, for sure, but it involves a significant amount of painstaking work (not sure how to translate German “Fleißarbeit” properly here).

 

For reference, I have attached a pure C implementation as a simple NI LabWindows/CVI project that performs such computations with very large numbers just in few seconds:

 

>pi-approx.exe
22/7
333/106
355/113
103993/33102
104348/33215
208341/66317
312689/99532
833719/265381
1146408/364913
4272943/1360120                                                                           
...
256839923861488782607902790348837497679/81754686931803956266412424933874257924

 

When someone would like to port this mostly AI-generated code to the LabVIEW and fix all minor issues — you're welcome, but not me myself, thank you (makes no sense, because such libraries already available). As "benefit" we can get basic elements of the "Big Numbers" library for LabVIEW (but this is really rarely need in every day programming, may be somewhere in deep physic experiments in the labs).

 

As OffTopic — the most beautiful way to approximate π, in my humble opinion, is the famous Buffon’s needle experiment, introduced by Georges‑Louis Leclerc and Comte de Buffon, in the 18th century (1777, to be exact). In this experiment, you drop a needle or fire matches of length L onto a plane with parallel lines spaced by the same distance L. You then count how many needles cross a line and how many do not. If you throw N needles and C of them cross a line, then π can be approximated as 2N / C. This elegantly connects geometry, probability, and π in a single experiment.

However, this is not related to the problem discussed above, although it can be easily implemented in LabVIEW as a beginner exercise.


Continuing OT:  Andrey is both correct and less than accurate.  He expressed almost everything important in mathematics by describing the physical experiment!  In fact, mathematics would be useless unless it could describe something physical. 

 

So what did Andray and Buffon miss when approximating pi?  More to the point, WHY IS IT TRUE?   To be concise and accurate the experiment provides no evidence that the null hypothesis, e^(i*pi)+1≠0. So we assume e^(i*pi)+1=0 is true.  The experiment itself provides the random error which, might have been used in cryptography long ago.(maybe, circa 1776 in and around Philadelphia, PA).   This is another "Self Evident" Truth, even a month shy of the 250th anniversary of the date on my country's founding document. 


"Should be" isn't "Is" -Jay
0 Kudos
Message 25 of 30
(194 Views)

@Andrey_Dmitriev wrote:
I would like to kindly remind all participants that the initial requirement from our dear colleague Yamaeda was “a fraction that approximates π to 2600 digits.

The actual quote was:

"I just saw a funny meme about a fraction that approximated PI to 2600 digits. That got me thinking of trying to find some, and this was my result!"

 

So the meme was the inspiration to find "some" simple rational approximations. The intent was obvious from the implemented math and the resulting list of simple approximations given by the sample code.

 

It would be fun to implement some bignum math entirely in G, we just need to make sure we find Pi with N (large!) decimal digits for comparison somewhere on the web and trust that there are no typos. 😄

 

Of course the complexity of the current algorithm (dumb linear search) would be insufficient and better algorithms would need to be implemented.

 

Message 26 of 30
(197 Views)

Yamada wrote


The actual quote was:

 

"I just saw a funny meme about a fraction that approximated PI to 2600 digits. That got me thinking of trying to find some, and this was my result!"


Response:

"You can learn more by accident than intention." -Joe Soucheray. Garage Logic.


 

 


"Should be" isn't "Is" -Jay
0 Kudos
Message 27 of 30
(187 Views)

@altenbach wrote:

@Andrey_Dmitriev wrote:
I would like to kindly remind all participants that the initial requirement from our dear colleague Yamaeda was “a fraction that approximates π to 2600 digits.

The actual quote was:

"I just saw a funny meme about a fraction that approximated PI to 2600 digits. That got me thinking of trying to find some, and this was my result!"

 

So the meme was the inspiration to find "some" simple rational approximations....

 


If I have "misinterpreted" the requirements, I apologize. I simply saw “2600 digits” and understood the final task is LabVIEW code that can reproduce at least that many digits (or, ideally, even more).

 

In general, the problem is solvable. Since we need to find integers a and b such that the decimal expansion of a/b matches π in its first 2600 digits, it suffices to construct a fraction satisfying

 

image-20260602171827369.png

which is obviously always possible based on Dirichlet's approximation theorem. So, the BigNum math itself is most interesting part of this task.

0 Kudos
Message 28 of 30
(170 Views)

@JÞB wrote: Continuing OT:  Andrey is both correct and less than accurate.  He expressed almost everything important in mathematics by describing the physical experiment!  In fact, mathematics would be useless unless it could describe something physical. 

 

So what did Andray and Buffon miss when approximating pi?  More to the point, WHY IS IT TRUE?   To be concise and accurate the experiment provides no evidence that the null hypothesis, e^(i*pi)+1≠0. So we assume e^(i*pi)+1=0 is true.  The experiment itself provides the random error which, might have been used in cryptography long ago.(maybe, circa 1776 in and around Philadelphia, PA).   This is another "Self Evident" Truth, even a month shy of the 250th anniversary of the date on my country's founding document. 


This is quite a "philosophical" question (I suppose we are more or less done with the Pi exercises), so I should think about it more. I have never gone deeply into theoretical physics; my background has always been more practical and experimental, trusting what I can observe with my own eyes and measurement devices.

 

A funny point: just today evening a colleague came into my office and noticed that I am studying high geometry, and he raised almost the same question. This area does have practical applications in computer tomography and in the use of Plücker coordinates (they represent a lines in 3D as a points in a 6-dimensional projective space, my brain nearly exploded), so I am learning it from scratch by reading Foundations of Projective Geometry by Robin Hartshorne (we did not have such a course at university). I am really impressed by Desargues’s theorem (from the 17th century, by the way).

 

The fascinating fact is that the points V, U, and W are always lie on a straight line:

image-20260602163907149.png

It looks simple, but a proof in Euclidean geometry is not so easy. In projective geometry, however, it becomes very natural. In fact, one can interpret lines as intersections of planes in three-dimensional space, which makes the theorem almost intuitive, once we adjust geometric mind a little bit.

 

The real beauty of Desargues’s theorem is not in computation or proof — it lies in a deep symmetry between dual aspects of geometry. In the associated Desargues configuration, there are 10 points and 10 lines, with each line containing 3 points and each point lying on 3 lines. This creates a perfectly symmetric geometric structure in which points and lines become essentially interchangeable. Moreover, this simple configuration has a rich automorphism group, isomorphic to the symmetric group on five elements. Mathematically speaking, this identifies the full symmetry group of the configuration with all permutations of a set of five elements, which are fully abstract objects, at least for me. This high degree of symmetry is one of the main reasons the configuration is considered so beautiful.

 

At this point, I do not know whether the mathematical sentence above is really “useful” or not. It feels as if I am moving closer and closer to the foundations of Galois groups theory and even Grothendieck’s morphisms viewpoint — and farther and farther away from physical reality, although the connection still exists, but becoming increasingly subtle...

Message 29 of 30
(157 Views)

@Andrey_Dmitriev wrote:
As OffTopic — the most beautiful way to approximate π, in my humble opinion, is the famous Buffon’s needle experiment, introduced by Georges‑Louis Leclerc and Comte de Buffon, in the 18th century (1777, to be exact). In this experiment, you drop a needle or fire matches of length L onto a plane with parallel lines spaced by the same distance L. .

I would strongly advise against using needles because they could have some residual magnetization that would interact with the earth magnetic field during the drop, thus biasing the orientation. 😄

Message 30 of 30
(148 Views)