Re: Exact (LISP-ish) calculations in Ruby?



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



Relevant Pages

  • Re: Exact (LISP-ish) calculations in Ruby?
    ... Raphson method) for calculating square/cube/fourth/... ... finding roots (zeros) ... _estimating_ roots (to any desired accuracy) ...
    (comp.lang.ruby)
  • Re: Comparision of C Sharp and C performance
    ...  Very few people could define an N^2 algorithm for calculating ... you perform 19 multiplications and 19 calls for the recursive ... Since I can look up factorials in seconds, ...
    (comp.lang.c)
  • Re: Lehmer-Schur pseudocode?
    ... the Lehmer-Schur algorithm. ... A Google Groups search shows a single mention in the history of Usenet, ... If anyone can suggest a better algorithm ... choice for finding the roots of a black-box analytic function, ...
    (comp.programming)
  • Re: sparse linear algebra
    ... > very good gaussian elimination algorithm. ... Do you try to implement Faugeres algorithm for Singular? ... "At a time when so many scholars in the world are calculating, ...
    (sci.math.symbolic)
  • Re: Fast integer distance formula
    ... stored back into an array of 16-bit integers, since the distance formula can ... this is part of calculating the power spectrum at the end of an FFT. ... It is likely more accurate than you need, but I think you can simply truncate the algorithm sooner for less precision. ...
    (comp.dsp)