[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: Exact (LISP-ish) calculations in Ruby?
From:       Gavin Sinclair <gsinclair () gmail ! com>
Date:       2009-11-19 9:25:09
Message-ID: 152c3ed2-9318-4a78-a480-cfb3dcf359d7 () g10g2000pri ! googlegroups ! com
[Download RAW message or body]

On Nov 19, 6:04 am, Aldric Giacomoni <ald...@trevoke.net> 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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic