[#2367] Standard libraries — Dave Thomas <dave@...>

From ruby-dev summary:

60 messages 2004/02/11

[#2397] PATCH: deprecate cgi-lib, getopts, importenv, parsearg from standard library — Gavin Sinclair <gsinclair@...>

Index: cgi-lib.rb

15 messages 2004/02/12

[#2465] PATCH: OpenStruct#initialize to yield self — Gavin Sinclair <gsinclair@...>

This is a common approach I use to object initialization; I don't know

24 messages 2004/02/19

Re: Problems in mathn, rational, complex, matrix

From: Mathieu Bouchard <matju@...>
Date: 2004-02-01 08:02:31 UTC
List: ruby-core #2321
On Sun, 1 Feb 2004, Gavin Sinclair wrote:

> The stdlib documentation drew my attention with the Matrix
> class example for determinant.
> http://www.ruby-doc.org/stdlib/libdoc/matrix/rdoc/classes/Matrix.html#M000064
>   Matrix[[7,6], [3,9]].determinant
>     => 63
> Call me a geek, but I instantly saw that this was the wrong
> answer.

You have to do Matrix[[7.0,6.0],[3.0,9.0]], or the equivalent thing with
Rationals. For the determinant to be meaningful, the Matrix must not be
filled with Integers.

Call me a geek, but Integers are not a Field, though they are a Ring and
even an Integral Domain. You cannot make a Vector Space on mere Integers.
You can, however, make a Vector Space on Rationals, since Rationals are a
Field. ;-)

Back to Ruby: the Integer class has a #/ that is not the inverse of #*
simply because Integer#* is not invertible. Making it so would require
that #/ return non-Integers, which might be frowned upon because it is not
clean, or because it introduces (undesirable) dependencies, or because it
breaks backwards compatibility.

If "mathn" modifies Integer#/, then it surely breaks other libraries that
rely on Integer#/ returning an Integer or at least rounding down.

So the only solution I really recommend is to not use integers in
matrices.

________________________________________________________________
Mathieu Bouchard                       http://artengine.ca/matju


In This Thread