[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:30:05
Message-ID: 7033c8c3-2c2d-4e98-b96f-0d129020adaa () s21g2000prm ! googlegroups ! com
[Download RAW message or body]

On Nov 19, 1:35 am, Aldric Giacomoni <ald...@trevoke.net> wrote:
> Has anyone written a gem for exact calculations? The kind one would find
> on a LISP REPL, or when using your average HP scientific calculator?
>
> >> 3 / 4
> => 3/4
> >> 3 / 6
> => 1/2
> >> sqrt(2)
> => sqrt(2)
> >> sqrt(4)
> >> 2
>
> I couldn't find anything on gemcutter or rubyforge, but maybe I missed
> it..
> I don't ask because I need it.. I ask because of an idealistic desire
> for exact calculations :)

That "idealistic desire" would only be needed in very special cases in
real programming, so it's not surprising not to find a Ruby library
for it.

Essentially, you're looking for the capabilities provided by a
Computer Algebra System (CAS) like Mathematica, as mentioned, or
Maxima (open source, IIRC).  You may be able to find an open source
CAS that has Ruby bindings, or for which (if you're sufficiently
motivated) you can write some bindings.

Or you can give it a go!

  > sqrt(2) * sqrt(3)
  --> sqrt(6)

  > sqrt(8)
  --> 2 * sqrt(2)

  > 2 * PI * 3.5
  --> 7 * PI

Not my idea of fun, though.  The beauty of Mathematics is best
appreciated in the mind, for it's only there that sqrt(2) exists.

--
Gavin Sinclair


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

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