From: Gavin Sinclair Date: 2009-11-19T18:25:09+09:00 Subject: Re: Exact (LISP-ish) calculations in Ruby? On Nov 19, 6:04 am, Aldric Giacomoni wrote: > Aldric Giacomoni wrote: > > > In all fairness, I just fired up SLIME to check, and LISP's (sqrt 2) > > does come out to be an approximation, so I guess I want something cool > > like the HP-48 and HP-49's factoring power.. > > And I just read up on the process of 'continuing fractions' which can be > used find fractions / estimates of irrational numbers down to the nth > decimal. I wonder how we can know that, for instance, 1.41421 (etc) is > sqrt(2) ... ? There's an algorithm for calculating square roots, similar (in appearance, not in process) to the algorithm for long division. One or more generations ago, school students would have done it with pen and paper, I think. Furthermore, there's a Calculus-based algorithm (Newton's method, it's called in my syllabus, but I think it's properly called the Newton- Raphson method) for calculating square/cube/fourth/... roots to any desired accuracy. Thirdly, you can estimate any root you like by trial multiplication! (Exercise: write a Ruby program to do this; shouldn't take more than 10 lines.) -- Gavin Sinclair