MAPLE output for the Gauss-Legendre Method for estimating Pi.
Let's just run the loop one time and see what happens...
> restart; a:=1; b:=1/sqrt(2); t:=1/4; x:=1;
> for i from 1 to 1 do
> y:=a;
> a:=(a+b)/2;
> b:=sqrt(b*y);
> t:=t-x*(y-a)^2;
> x:=2*x;
> od;
> evalf(a); evalf(b); evalf(t); evalf(x);
> evalf(((a+b)^2)/(4*t));
This is not a bad estimate for Pi, but let's run the loop for two iterations (this time I will hide all of the output except the answer):
> restart; a:=1: b:=1/sqrt(2): t:=1/4: x:=1:
> for i from 1 to 2 do
> y:=a:
> a:=(a+b)/2:
> b:=sqrt(b*y):
> t:=t-x*(y-a)^2:
> x:=2*x:
> od:
> evalf(((a+b)^2)/(4*t));
Pretty good, we are correct to 7 places already! Let's iterate three times and check out our error.
> restart; a:=1: b:=1/sqrt(2): t:=1/4: x:=1:
> for i from 1 to 3 do
> y:=a:
> a:=(a+b)/2:
> b:=sqrt(b*y):
> t:=t-x*(y-a)^2:
> x:=2*x:
> od:
> evalf(((a+b)^2)/(4*t)); evalf(Pi-%);
Wow! Look at that precision. Let's see what iterating four times looks like.
> restart; a:=1: b:=1/sqrt(2): t:=1/4: x:=1:
> for i from 1 to 4 do
> y:=a:
> a:=(a+b)/2:
> b:=sqrt(b*y):
> t:=t-x*(y-a)^2:
> x:=2*x:
> od:
> evalf(((a+b)^2)/(4*t));
With this many digits, there is no difference from the last output, let's increase our number of digits and look at our error.
> Digits:=20:
> evalf(((a+b)^2)/(4*t)); evalf(Pi-%);
After only four iterations (and with very minimal computation time) we have Pi correct to 18 places!