Solving Pi for delicious fun

For fans of all other kinds of logic puzzles

Solving Pi for delicious fun

Postby StrmCkr » Tue Oct 16, 2018 5:42 am

Solving Pi:

some mathematics has always bothered me with pi.

Circumference = C
Diameter = D
Radius = r = (1/2 D) or 2R = D

Pi is a ratio of
C/D

area of a circle:
Area = Pi x r^2 =>> A= (C/D) * r^2 =>> A = (C/(2R)) * (R^2)

Circumference of a circle
C = Pi * D =>> C = C/d * D =>> C = C

how could we solve circumference with out first knowing the circumference ?
a bit of a conundrum.

knowing the circumference we can have an answer for what is PI.
we need a way to solve for circumference that doesn't involve knowing its circumference.

imagine we have a circle with a diameter of 1, which occupies both x and y direction of the circle

x and y directions are both 180 degree lines that intersect at 90 degrees, fold the circle exactly in half on the Y axis of the grid which 1/2s the x axis.
we have x= 1/2 the diameter.

label the edge of the circle as point A on the x axis
label the edge of the circle as point b of the y axis

connect point a and b together with another line label this C

using Pythagorean theory
C^2 = A^2 + B^2
c = sqrt (1/2^2) + 1/2^2)

C = sqrt(1/2)

from here we can also solve the area of the triangle but I'm going to skip that for now.

we can see there is area still uncounted above the triangle, so what is the cord length of the triangle ABC ?
to find that divide the triangle in half

C^2 = A^2 +B^2
(1/2)^2 = (1/2 (sqrt(1/2)) ^2 + B^2
B = sqrt (2) /4

we know the cord length {label it E) = B and the total length of the radius= 1/2,

this tells me
the real question is how many folds(n) does it take for the C length to = 0 distance between points a & B , and E = R
and can they?

the answer is no and its pretty simple to see

we started with 180 degree angle for each fold we are left with 180/(2^n) degrees. this number is infinity increase in smaller scale.
which means E infinity grows by infinity shrinking numbers but never reaches the length of R,
and the space between A & B lines also shrinks infinity but never reaches zero as a & b always have a divergent angle between them
which means Pi is an infinite number as its a area summation of infinity shirking triangles.

we can gain degrees of accuracy the more folds we do and have a
E/R as a % indicator for accuracy.

the best we can do is approximate ratio to the nth decimal place as Pi is an infinite irrational number.

find the area of the circle using some other fun math that allows us to have a high accuracy reading of the pi ratio:

for every fold{n} we do on the circle we make
( 2 * (2^n)) segments {labeled s) with C as its length and has a cord length of E to the center.

Area of a polygon is defined as
A = 1/2 PnR
where:
n = segment count
P = length of the segment
R = cord length of N to the center of the polygon.

translate that to the stuff we solved above

Area of a circle:
A = 1/2 * S * C * E

once we have the area we can solve
pi = area / R^2

paper copy of proving the above method and math

i wrote a short easy program in pascal that does this however, the accuracy is limited by the floating point of pascal real numbers:

{i also included a way to do it with laws of cosine however that is already defined by pi and i solving area and pi..so i cant prove pi while using it lol. }

3.141592653589793238

is the most accurate my program can go do to rounding errors and it terminates on the 34th fold {3.4359738368*10^10 sided polygon} as the length of E reaches the length of R

Hidden Text: Show
Code: Select all
program pi;
uses
crt,windows,sysutils,math;

Var
area,d,r,a,b,s,c,e,f,o,i: extended
n:integer;
k:char;
begin
clrscr;

D:=1;
R:= 1/2 * d;
A:=R;
B:= R;

for

N:= 1 to 28 do
begin

o:= 180 / (power(2,n));  {angle of partitions}

S:= 2*power(2,n); {partitions}

c:= sqrt( power(a,2) + power(b,2));

F:= 1/2 * c;

E:= sqrt (power(r,2) - power(f,2));

Area:=1/2 *(C*s)*E;

A:=F;
B:= R - e;

{these remarked sections use the law of cosine as a test function }
//H:= sqrt(power(R,2)+power(R,2) - (2*R*R*cos (c * (3.141592653589793285/ 180) )) ); 

//I:=sqrt (( power(r,2) - (power( (1/2*h),2) ) ));

//Area:= (1/2 * (H*s)  * I);


gotoxy(2,1);
write('Number of folds := ',N);

gotoxy(2,3);
write('Diamter := ',d);

gotoxy(2,5);
write('radius := ',r);

gotoxy(2,7);
write('Angle of inicdence := ',o);

gotoxy(2,9);
write('# of Sides := ',s);

gotoxy(2,11);
write('Side length := ',c);

gotoxy(2,13);
write('cord length:= ',e);

gotoxy(2,15);
write('Area := ',area);

gotoxy(2,17);
write('acuracy := ',e/r);

gotoxy(2,19);
write('Pi := ',area/(R*R));


if E/R = 1 then break;

//delay(1500);

end;

k:=readkey;

end.
Some do, some teach, the rest look it up.
User avatar
StrmCkr
 
Posts: 889
Joined: 05 September 2006

Re: Solving Pi for delicious fun

Postby rjamil » Tue Oct 16, 2018 6:56 pm

Adding some interesting facts about pi:

According to Archimedes, the value of pi between a couple of very close fractions, i.e., between 223/71 and 22/7.

According to John Parker, pi is precisely 20612/6561. Source

An incredibly close to pi, within a third of a millionth of the exact value is 355/113. Source

Most approximate to date fraction is 245850922/78256779. Source

R. Jamil
_______________________________________________
An approximate number of days per year is 365.24225.
pi, sqrt (2), iota and Euler's identity are some of the examples of mathematical beauty.
rjamil
 
Posts: 253
Joined: 15 October 2014
Location: Karachi, Pakistan

Re: Solving Pi for delicious fun

Postby m_b_metcalf » Fri Oct 19, 2018 7:48 am

StrmCkr wrote:i wrote a short easy program in pascal that does this however, the accuracy is limited by the floating point of pascal real numbers:

Also for fun, I translated your program into Modern Fortran using quadruple precision. It gave the value 3.14159265358979323846264338327950 after 57 iterations:
Code: Select all
 Number of folds :=           57
 Diameter :=    1.00000000000000000000000000000000     
 radius :=   0.500000000000000000000000000000000     
 Angle of incidence :=   1.249000902703301107976585626602173E-0015
 # of Sides :=    288230376151711744.000000000000000     
 Side length :=   1.089958905627697468587262782685304E-0017
 cord length:=   0.500000000000000000000000000000000     
 Area :=   0.785398163397448309615660845819876     
 accuracy :=    1.00000000000000000000000000000000     
 Pi :=    3.14159265358979323846264338327950     


The program is below.

Regards,

Mike Metcalf

Hidden Text: Show
Code: Select all
program pi

integer, parameter:: sp = kind(1.0), dp = selected_real_kind(2*precision(1.0_sp)), &   
                                     qp = selected_real_kind(2*precision(1.0_dp))
real(kind = qp) :: area, d, r, a, b, s, c, e, f, o, i
integer  :: n = 0

D = 1._qp
R = 1._qp/2._qp * d
A = R
B = R

do
   n = n + 1
   o = 180.0_qp / 2._qp**n  ! angle of partitions

   S = 2._qp*2._qp**n      ! partitions

   c = sqrt( a**2 + b**2)

   F = 1._qp/2._qp * c

   E = sqrt (r**2 - f**2)

   Area = 1._qp/2._qp *(C*s)*E

   A = F
   B = R - e

   write(7, *)
   write(7, *) 'Number of folds := ', N
   write(7, *) 'Diameter := ', d
   write(7, *) 'radius := ', r
   write(7, *) 'Angle of inicdence := ', o
   write(7, *) '# of Sides := ', s
   write(7, *) 'Side length := ', c
   write(7, *) 'cord length:= ', e
   write(7, *) 'Area := ', area
   write(7, *) 'accuracy := ', e/r
   write(7, *) 'Pi := ', area/(R*R)

   if (abs(E/R - 1._qp) <= epsilon(e)) exit

end do

write(*, *) 'Number of folds := ', N
write(*, *) 'Pi := ', area/(R*R)

end program pi
User avatar
m_b_metcalf
2017 Supporter
 
Posts: 9395
Joined: 15 May 2006
Location: Berlin

Re: Solving Pi for delicious fun

Postby Leren » Sat Oct 20, 2018 12:03 am

I got seriously into calculating digits of Pi many years ago. The attached file can calculate PI digits up to more than 1 million, which takes about 34 seconds on my PC today.

The program uses the Chudnovsky forumula, binary splitting and Strassen multiplication using a radix 2-4-8 Fast Fourier Transform.

I've put a small number of required digits in cell F1 to keep the file size down so I could upload it. If you want to see it calculate a million digits put 1000008 in F6 and click on the PI button.

The millionth digit (999,999th after the decimal point) will be the first digit in cell D55112 (it's a 5).

Happy Pi digit calculating ! Leren

<edit>

PS. The number of simple but amazingly accurate approximations to PI is absolutely huge. A sample of them can be found, for example, here.

The ones by Rumanujan are incredible. He also had the second best power series converging to Pi, I think 8 digits per term, but not as good as the Chudnovsky power series which converges by an amazing 14 digits per term.

Leren
Attachments
PI.zip
Digits of PI Calculator
(153.22 KiB) Downloaded 8 times
Leren
 
Posts: 3319
Joined: 03 June 2012

Re: Solving Pi for delicious fun

Postby 999_Springs » Sat Oct 20, 2018 11:39 pm

so a couple of things. what you're doing is intuitive but from a mathematical perspective you don't have a definition of the length of an arc and you're assuming that the lengths of your chords tend to the length of an arc. in this case you can do it but if you're not careful you can get something like this

Image
image and further discussion can be found here

one thing you could do is calculate pi by approximating it with the area of a regular polygon (as opposed to the perimeter, which you're doing here) and do the same thing you're doing in the first post doubling the number of sides each time, and in fact if i remember this right this was how archimedes obtained his initial approximation of pi

rjamil wrote:According to Archimedes, the value of pi between a couple of very close fractions, i.e., between 223/71 and 22/7.

archimedes got this by starting with 2 hexagons, one surrounding the circle and one inside the circle, and did the same thing doubling the number of sides to get to 96, from which he worked that out. for instance if you have a hexagon inside a circle of radius 1 it has an area of 1.5sqrt3 and if you have a hexagon outside it it has an area of 2sqrt3, so pi has to lie in between those numbers

Most approximate to date fraction is 245850922/78256779.

that can't be right, you can get arbitrarily good best rational approximations to pi by getting the convergents of its continued fraction and finding out what numbers they represent, and you can easily get the continued fraction from wolfram alpha or wherever

it begins [3; 7,15,1,292,1,1,1,2 etc]
and you can work out the convergents directly or by using the recurrence relation which gives you 3, then 22/7, then 333/106, then 355/113

the fact that the next number in the continued fraction expansion is so big (292) means that 355/113 is a stunningly good approximation for how small the numbers are, but you can keep going to get better and better approximations

edit: i agree pie is delicious
Once upon a time I was a teenager who was active on here 2007-2011
ocean and eleven should have paired up to make a sudoku-solving duo called Ocean's Eleven
999_Springs
 
Posts: 440
Joined: 27 January 2007
Location: In the toilet, flushing down springs, one by one.

Re: Solving Pi for delicious fun

Postby Leren » Sun Oct 21, 2018 3:31 am

It may be of interest that formulae exist for calculating the nth digit of PI, where n is any finite integer, without computing any of the prior digits !!! Sounds unbelievable but it's true. You can read about this, for example, here.

The main use of these formulae are that their computational complexity is lower than for calculating all the digits of Pi up to n, so they can be used as a spot check that your 1 - n computation is probably correct.

Another, seemingly impossible, thing I learn't about when writing the above program was that, if you multiply an m digit number by an n digit number, you can do it in less than m x n steps. Sounds impossible, right ? We all learnt at school that you carry out m x n digit products and add up all the results to get the product. Experts in the field of large digit computations patronisingly refer to this as "schoolperson multiliplcation". The Strassen multiplication I referred to in my previous post has a complexity less than m x n, although for small values of m and n, its better in practice to use good old schoolperson multiplication.

Leren
Leren
 
Posts: 3319
Joined: 03 June 2012

Re: Solving Pi for delicious fun

Postby StrmCkr » Sun Oct 21, 2018 3:20 pm

Yes I know you can do shortcuts like ( m = last number) (n = number of digits +1)
(m x(n+1)) /2 and arrive at a sum of all previous steps (sum digits of 1-9) = 45 => ((9*10/)2)

if you can show me a way of fining the nth cord length of my polygon from a starting lenght of sqrt 1/2 to a max length of r and its section length at the nth step, with only math that dosen't involve law of sins, cos. Then this program wouldn't need to be itterative

As I can do that already that and have an accurate summation of pi using the laws of cosin version didn't need previous step calculations and was 3 lines but its based on laws of cos which uses pi to begin with...

only problem for me is getting around rounding errors in code for displaying accuracy. My language only displays 18 digits max.
Some do, some teach, the rest look it up.
User avatar
StrmCkr
 
Posts: 889
Joined: 05 September 2006

Re: Solving Pi for delicious fun

Postby Leren » Sun Oct 21, 2018 8:27 pm

StrmCkr wrote : My language only displays 18 digits max.

Wow ! You are lucky, Excel integers only display 10 digits max. The obvious way to get around this problem is to set up a multi-precision arithmetic environment.

All you have to do is to define a large precision number as an array of it's digits in the cells. So, suppose you have a 150 digit number. You divide the digits into lots of, say, 15 and you have an array of ten 15 digit numbers.

All you have to do then is to write a set of simple routines to add, subtract, multiply and divide, just like you were taught to at school. When you use these routines you are effectively carrying out arithmetic in base 10^15.

Took me about 5 seconds to figure this out all those years ago when I wrote my PI program. The reason you can't use the maximum precision of your language in the cells is that when you multiply two numbers (as in schoolperson multiplication) you will have an array element with more than 15 digits, before you implement the carries.

Leren
Leren
 
Posts: 3319
Joined: 03 June 2012

Re: Solving Pi for delicious fun

Postby StrmCkr » Tue Oct 23, 2018 8:34 am

the other problem with rounding points occurs here:

if we know the "side length" of the first sector{n=1}
= 3 then the radius of the sides(A,B) = ( 3 sqrt (2) )/ 2

but

plugging those numbers back into my code spits out an error when solve for
C^2 = a^2 + B^2
then
C = 2.99999999999999999978
which should equal to 3.

even worse
is if i define R as: sqrt( power(18,1/4)
then
C = 2.02966358981340440066
which should equal to 3.

the power function cannot compute fractions.
couple that with squaring problems I end up with a program that fails everything.
Some do, some teach, the rest look it up.
User avatar
StrmCkr
 
Posts: 889
Joined: 05 September 2006

Re: Solving Pi for delicious fun

Postby dobrichev » Tue Oct 23, 2018 1:46 pm

StrmCkr wrote:area of a circle:
Area = Pi x r^2


Hi StrmCkr,

Your formula is quite incorrect because it is based on a hidden assumption.
If you choose to measure the area in "round meter" units instead of square meters, Pi disappears from the formula. :D
dobrichev
2016 Supporter
 
Posts: 1622
Joined: 24 May 2010

Re: Solving Pi for delicious fun

Postby StrmCkr » Tue Oct 23, 2018 8:52 pm

Well the funny part is for every circle we have 1 square and 2 Elipses left.
and every elipse we have 1 square and 2 Elipses left....

That and c is infite with a fixed Diamater or Diamater is infinite if c is fixed, problem is both are fixed.
Need some new circle based mathatics

This just seems pi eyed.
Some do, some teach, the rest look it up.
User avatar
StrmCkr
 
Posts: 889
Joined: 05 September 2006

Re: Solving Pi for delicious fun

Postby StrmCkr » Tue Nov 13, 2018 12:46 am

more random thoughts:

Circumference isn't actually a correctly calculated as a Circle shape is created by multiple instances of point of reference as a fix object rotates around an axle.

ie a circles shape only appears when all start to finished points are considered as it isn't created in reference space but through space coupled with time. {we only see the final product of the after effect}

think of drawing a circle with a compass we can see nothing, and the arc forming slowly {by adding dots at each interval of time passing}

For example:

a Man is tied to a stick that is 15 meters away from a fixed pivot point, he runs at 18 m/s from start to returning to the starting point it takes him 30 seconds to run.

what is the length of his path.
D = V * T
D = 540 M
{hint this make a circumference}


pi and Circumference calculations are taking frequency snap shots of the time line start to Finnish and drawing connecting points from each interval.
like the first phase of the step takes 1/4 of the time making a square progress report. all the way up to the 2^37 inference before my rounding errors produce errors.


now if we know the fixed distance away from the central hub. the rotation speed of the object and corresponding full cycle period.
we can accurately calculate distance moved of a fixed object = circumference.

the problem is this:
a Man is tied to a stick that is 5 meters away from a fixed pivot point, he runs at 18 m/s from start to returning to the starting point it takes him 30 seconds to run.

what is the length of his path.
D = V * T
D = 540 M

he ran in 2 circles both with 2 different diameters but the same rotational speed.

then the co-efficient of the two circles can never be equal to fixed ratio.

the circumference to diameter changed but the path length stayed the same

how would a path length change? think 3d space one on a flat surface the other undulating.

a viewed in a top down aspect would see two circles drawn but with different radius: and smaller/ larger circumference

even though their paths lengths are the same {thanks to a 3rd dimension undulating edge} in essence the smaller circle would appear to be moving slower overall, as it would appear to have less space to cover.
and we would be none the wiser.
Some do, some teach, the rest look it up.
User avatar
StrmCkr
 
Posts: 889
Joined: 05 September 2006

Re: Solving Pi for delicious fun

Postby RSW » Thu Dec 06, 2018 4:36 am

Leren wrote:
StrmCkr wrote : My language only displays 18 digits max.

Wow ! You are lucky, Excel integers only display 10 digits max. The obvious way to get around this problem is to set up a multi-precision arithmetic environment.

Excel should give you 15 digits if you set the number format correctly.

For doing fun things like this, I wrote an extended precision spreadsheet program that allows the user to set any precision. Using the AGM (Arithmetic-Geometric Mean) method for calculating pi, the number of significant digits approximately doubles on each iteration. It takes 7 iterations to get 150 significant digits, while 8 iterations will give 300 digits. Here is the result from my spreadsheet showing 150 digit accuracy:

Code: Select all
1. 3.18767264271210862720192997052536923265105357185936922648763398627512283252812233011472861066016179741144439569247119659991409834954369967159328171097
2. 3.1416802932976532939180704245600093827957194388154028326441894631956630010102553193888894275152646103100982115309637533583291907644555135861860603001
3. 3.14159265389544649600291475881804348610887923726131158965110135768465307950308650177409758628986315704057648227405289005868017794653767032056788846312
4. 3.14159265358979323846636060270663132175770241134242935648684601523841094860692775826806220073327621308337662659353722320789991657839457080775689013676
5. 3.14159265358979323846264338327950288419716994916472660583469612594874800609532900585185157593171019387107025658586810588075987493527991581955887251656
6. 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280468522286541150274560755807812519362431343785210091281280497733
7. 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940813
RSW
 
Posts: 16
Joined: 01 December 2018
Location: Western Canada

Re: Solving Pi for delicious fun

Postby Mathimagics » Thu Dec 06, 2018 2:29 pm

RSW wrote:Using the AGM (Arithmetic-Geometric Mean) method for calculating pi, the number of significant digits approximately doubles on each iteration.


Some years back I did some research for Prof. Richard Brent (ANU). I worked on writing software to provide arbitrary-precision (eg. millions of dec places) suppport for the "elementary functions" (sin(x), log(x), exp(x), etc).

For some considerable time my sin() function was arguably the fastest one going. The MPFR people eventually did get theirs up to comparable speed! 8-)

Anyway, I remember the AGM method well, it remains (I believe) the fastest way to compute the log() function. The Taylor series for log(x) has notoriously slow convergence, but AGM-log method really kicks ass ...
User avatar
Mathimagics
2017 Supporter
 
Posts: 793
Joined: 27 May 2015

Re: Solving Pi for delicious fun

Postby RSW » Thu Dec 06, 2018 11:35 pm

I can't take credit for the extended precision math in my spreadsheet. I used a freeware extended precision library, and wrote the spreadsheet app around it.
For my research work I use elliptic integrals quite a bit, and the AGM method calculates these extremely quickly.

If anyone wants to try the AGM method with a regular spreadsheet, Excel or LibreOffice, etc., then enter the following values/formulas in cells A1 through E2:

A1: 1
B1: 1
C1: =1/SQRT(2)
D1: 0
E1: blank
A2: =1+A1
B2: =(B1+C1)/2
C2: =SQRT(B1*C1)
D2: =D1+2^A2*(B2^2-C2^2)
E2: =4*B2^2/(1-D2)

Now select the cells of the second row and fill down for as many rows as you wish. Column E gives the improving value of pi after each iteration. Four rows will be sufficient for the maximum precision of the spreadsheet.
RSW
 
Posts: 16
Joined: 01 December 2018
Location: Western Canada

Next

Return to Other logic puzzles