print AGM(1, 1 / sqrt(2)) end sub AGM(a, g) repeat ta = (a + g) / 2 g = sqrt(a * g) x = a a = ta ta = x until a = ta return a end sub