Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

Very neat! Just one comment: For square root of 1.47 you don't need to take the log, half it, and exp it again. It's just sqrt(147/100), or a bit more than sqrt(144/100) = 12/10 = 1.2.

(If you like mental math you can then run an iteration of Newton's method: you take the remainder between the number and the square of your guess, 1.47-1.44 = 0.03, and divide it by twice your current guess, and add it to the current guess: 0.03 /(2x1.2) = 3/2.4 / 100 = 1.25 / 100 = 0.0125, so the next guess would be 1.2 + 0.0125 =1.2125. And the actual sqrt of 1.47 is 1.2124355653..., so that's pretty close. Newton's method roughly doubles the number of accurate digits at each iteration.)



Oh. That's actually very helpful. I hadn't realised Newton--Raphson could be that easy to use in practice. The closeness between 1.47 and 144 did strike me.


I did this in high school when we weren't allowed a calculator during tests and got into an argument with a teacher who told me that it is impossible to do this in your head so I must have cheated. A short demonstration on random numbers sufficed. I've taught my kids the method and they are now set up for similar arguments ;)

The hardest part if you want to generate more digits is to keep track of the intermediary sum during the multiplication, that's why I never got past three significant digits. That would be an interesting little contest though!


Indeed - taking the square root of numbers iteratively is very satisfying, because of the super fast convergence.

Sqrt 10: Guess 3, then residual is 10 - 33 = 1, so next guess add 1/(23) = 1/6, so now we're at 3.166..., and the square of that is 10.0277..., so you're very close already.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: