Hacker News new | ask | show | jobs
by the_origami_fox 982 days ago
For anyone wondering how they got the approximation sqrt(2)=1+24/60+51/60^2+10/60^3.

It's based on the simple idea that:

     Z = (a + b)^2 = (a^2 + (2a+b)*b)
  => (2a+b)* b < Z-a^2
Given an initial estimate "a", we need to find the largest "b" such that the term on the left is less than the term on the right. Therefore our estimate will always be slightly less than the actual answer and we can repeat the process to get slightly closer.

For the first iteration, Z=2 and a=1. We choose b=x/60:

  (2+x/60)*x/60 < 2-1^2
  120x + x^2 < 3600
  x = 24 ... 3456 < 3600
  x = 25 ... 3625 > 3600
So our first term is 24/60.

Repeat with a=1+24/60 and b=x/60^2:

  (2(1+24/60)+x/60^2)*x/60^2< 2-(1+24/60)^2
  10080x+x^2 < 518_400
  x = 51 ... 516_681 < 518_400
  x = 52 ... 526_864 > 518_400
Repeat multiple times.

Writing this in code I can easily get: 1;24,51,10,7,46,6,4,44,50,28 = 1.4142135623730951

This whole process can be codified into the long division algorithm for square roots which works quite neatly with base 10.

Edit: formatting

2 comments

Why do you choose b=x/60 for the first iteration? That isn't obvious to me, but 60 must be an obvious choice to be chosen.
Base 60 was the number system for the Sumarians/Babylonians.

> Sexagesimal, also known as base 60 or sexagenary, is a numeral system with sixty as its base. It originated with the ancient Sumerians in the 3rd millennium BC, was passed down to the ancient Babylonians, and is still used—in a modified form—for measuring time, angles, and geographic coordinates.

You can choose any integer > 1

For example if you choose 2 you will get the binary expansion.

And if you choose b=x/10, x/100, x/1000 ... then each iteration will add the exact decimal point.
what evidence do you have that this is how they got it?