[#53944] [ruby-trunk - Bug #8210][Open] Multibyte character interfering with end-line character within a regex — "sawa (Tsuyoshi Sawada)" <sawadatsuyoshi@...>

14 messages 2013/04/03

[#53974] [ruby-trunk - Feature #8215][Open] Support accessing Fiber-locals and backtraces for a Fiber — "halorgium (Tim Carey-Smith)" <ruby-lang-bugs@...>

14 messages 2013/04/03

[#54095] [ruby-trunk - Feature #8237][Open] Logical method chaining via inferred receiver — "wardrop (Tom Wardrop)" <tom@...>

34 messages 2013/04/08

[#54138] [ruby-trunk - Bug #8241][Open] If uri host-part has underscore ( '_' ), 'URI#parse' raise 'URI::InvalidURIError' — "neocoin (Sangmin Ryu)" <neocoin@...>

9 messages 2013/04/09

[#54185] [CommonRuby - Feature #8257][Open] Exception#cause to carry originating exception along with new one — "headius (Charles Nutter)" <headius@...>

43 messages 2013/04/11

[#54196] Encouraging use of CommonRuby — Charles Oliver Nutter <headius@...>

I think we need to do more to encourage the use of the CommonRuby

20 messages 2013/04/11
[#54200] Re: Encouraging use of CommonRuby — Marc-Andre Lafortune <ruby-core-mailing-list@...> 2013/04/11

Hi,

[#54211] Re: Encouraging use of CommonRuby — "NARUSE, Yui" <naruse@...> 2013/04/12

As far as I understand, what is CommonRuby and the process over CommonRuby

[#54207] [CommonRuby - Feature #8258][Open] Dir#escape_glob — "steveklabnik (Steve Klabnik)" <steve@...>

15 messages 2013/04/12

[#54218] [CommonRuby - Feature #8259][Open] Atomic attributes accessors — "funny_falcon (Yura Sokolov)" <funny.falcon@...>

43 messages 2013/04/12

[#54288] [CommonRuby - Feature #8271][Open] Proposal for moving to a more visible, formal process for feature requests — "headius (Charles Nutter)" <headius@...>

15 messages 2013/04/15

[#54333] Requesting Commit Access — Aman Gupta <ruby@...1.net>

Hello ruby-core,

16 messages 2013/04/16

[#54473] [Backport 200 - Backport #8299][Open] Minor error in float parsing — "bobjalex (Bob Alexander)" <bobjalex@...>

27 messages 2013/04/19

[#54532] [ruby-trunk - Bug #8315][Open] mkmf does not include include paths from pkg_config anymore — "Hanmac (Hans Mackowiak)" <hanmac@...>

11 messages 2013/04/23

[#54621] [ruby-trunk - Feature #8339][Open] Introducing Geneartional Garbage Collection for CRuby/MRI — "ko1 (Koichi Sasada)" <redmine@...>

43 messages 2013/04/27
[#54643] [ruby-trunk - Feature #8339] Introducing Geneartional Garbage Collection for CRuby/MRI — "authorNari (Narihiro Nakamura)" <authorNari@...> 2013/04/28

[#54649] Re: [ruby-trunk - Feature #8339] Introducing Geneartional Garbage Collection for CRuby/MRI — SASADA Koichi <ko1@...> 2013/04/28

(2013/04/28 9:23), authorNari (Narihiro Nakamura) wrote:

[#54657] Re: [ruby-trunk - Feature #8339][Open] Introducing Geneartional Garbage Collection for CRuby/MRI — Magnus Holm <judofyr@...> 2013/04/28

On Sat, Apr 27, 2013 at 8:19 PM, ko1 (Koichi Sasada)

[#54665] [ruby-trunk - Bug #8344][Open] Status of Psych and Syck — "Eregon (Benoit Daloze)" <redmine@...>

18 messages 2013/04/28

[ruby-core:54107] [ruby-trunk - Feature #8223] Make Matrix more omnivorous.

From: "boris_stitnicky (Boris Stitnicky)" <boris@...>
Date: 2013-04-08 15:23:11 UTC
List: ruby-core #54107
Issue #8223 has been updated by boris_stitnicky (Boris Stitnicky).


@Marc-Andre:

> Summary: I could consider injecting nothing instead of 0,
> but can not consider a generic `SomeClass.zero`. I don't feel
> your example is a good justification of a need of not injecting 0. 
> ...
> Shouldn't 0 be specially allowed, i.e 1.m + 0 == 1.m?

I tried that in desperation long ago, but it fails: Due to 0 + 1.m, 0 has to
be treated specially also in #coerce. But 1.m.coerce( 0 ) can't return
[0.m, 1.m], or 0 * 1.m would return 0.mツイ (zero square metres) instead of
expected 0.m. It is theoretically possible to make coerce return an object
that distinguishes between operators, but that's a lot of work. I'd like to
work on that with Ilya, http://bugs.ruby-lang.org/issues/7604

> ...
> This is not the way to define `coerce`. I'm sorry there are not precise specs for coercion...

Obviously, simply reversing order will fail upon any noncommutative operation (eg. 0 / 1.m
will fail instead of returning expected 0.m竅サツケ). In the real gem, I have it figured, I'll
put it on Github soon. I just wanted to give a simple example here.

> Check how the Matrix class does it (by using an intermediary Scalar class).

I read it once, but it takes some time to get into everything. I definitely plan to read it
more, I consider it one of the crucial libraries which I have to be fluent in.

> But I'm not convinced you have the right approach with the Metre class. Have you tried
> defining instead a class `MeasureWithPhysicalUnit` (feel free to shorten the name :-)).
> You'll need a class "PhysicalUnit" too.

Again, this was a toy example. I wrote a big fat physical units gem for my simulator, I'll
put it on Github soon. Dimension, Quantity, Magnitude, Unit, mixin for Numerics, dimensional
analysis, everything works, with the distinction that I had to patch Matrix.

> ...
> If this really was a problem for you, it would be easy to inject the first term in the
> summation instead (and handle the empty matrix case another way).

I've been sucking it up for a long time. I didn't want to be a bother. but I gradually gained
an impression, that it might be a concern for others. So could you make the solution you
suggest official, pretty please? Not injecting 0 saves one addition per row for non-empty
matrices, am I right?

> In no case could a Metre.zero be used, because there is Meter to get in case of zero matrices...

One would have to specify of what - zero matrix of what does one want. Imagining:

    a = Matrix.empty 3, 0, over: Float # new syntax proposal, :over option
    b = Matrix.empty 0, 1 # while regular syntax still works
    a * b
    #=> Matrix[[0.0], [0,0], [0,0]]

or

    a = Matrix.empty 3, 0, over: Metre
    a * b
    #=> Matrix[[0.m], [0.m], [0.m]]

On one hand, I as the user can implement this myself in a subclass, without needing
to bother you the StdLib maintainer. On the other hand, I wanted to publicly discuss
the fact, that for matrix multiplication, matrix need to be defined over an algebraic
ring, and by definition, rings must have an additive identity element and a
multiplicative identity element defined. Multiplicative identity would come into
use in methods such as

    Matrix.identity( n, options )
      if options[:of] then
        Matrix.scalar( n, options[:of].multiplicative_identity )
      else
        Matrix.scalar( n, 1 )
      end
    end

I have an itch to try to write a subclass MatrixOverAlgebraicRing (or AlgebraicField?).
If I get that far, I'll ask you what will you think about it.

----------------------------------------
Feature #8223: Make Matrix more omnivorous.
https://bugs.ruby-lang.org/issues/8223#change-38358

Author: boris_stitnicky (Boris Stitnicky)
Status: Open
Priority: Low
Assignee: marcandre (Marc-Andre Lafortune)
Category: lib
Target version: 


Let's imagine a class Metre, whose instances represent physical magnitudes in metres.

    class Metre
      attr_reader :magnitude
      def initialize magnitude; @magnitude = magnitude end
      def to_s; magnitude.to_s + ".m" end
    end

Let's say that metres can be multiplied by a number:

    class Metre
      def * multiplicand
        case multiplicand
        when Numeric then Metre.new( magnitude * multiplicand )
        else
          raise "Metres can only be multiplied by numbers, multiplication by #{multiplicand.class} attempted!"
        end
      end
    end

And that they can be summed up with other magnitudes in metres, but, as a feature,
not with numbers (apples, pears, seconds, kelvins...).

    class Metre
      def + summand
        case summand
        when Metre then Metre.new( magnitude + summand.magnitude )
        else
          raise "Metres can only be summed with metres, summation with #{summand.class} attempted!"
        end
      end
    end

Now with one more convenience constructor Numeric#m:

    class Numeric
      def m; Metre.new self end
    end

We can write expressions such as

    3.m + 5.m
    #=> 8.m
    3.m * 2
    #=> 6.m

And with defined #coerce:

    class Metre
      def coerce other; [ self, other ] end
    end

Also this expression is valid:

    2 * 3.m
    #=> 6.m

Before long, the user will want to make a matrix of magnitudes:

    require 'matrix'
    mx = Matrix.build 2, 2 do 1.m end
    #=> Matrix[[1.m, 1.m], [1.m, 1.m]]

It works, but the joy does not last long. The user will fail miserably if ze wants to perform matrix multiplication:

    cv = Matrix.column_vector [1, 1]
    mx * cv
    #=> RuntimeError: Metres can only be summed with metres, summation with Fixnum attempted!
    # where 2.m would be expected

In theory, everything should be O.K., since Metre class has both metre summation and multiplication by a number defined. The failure happens due to the internal workings of the Matrix class, which assumes that the elements can be summed together with numeric 0. But it is a feature of metres, that they are picky and allow themselves to be summed only with other Metre instances.

In my real physical units library that I have written, I have solved this problem by
defining an テシber zero object that produces the expected result, when summed with objects, that would otherwise not lend themselves to summation with ordinary numeric 0,
and patching the Matrix class so that it uses this テシber zero instead of the ordinary one.

But this is not a very systematic solution. Actually, I think that the Matrix class would be more flexible, if, instead of simply using 0, it asked the elements of the matrix what their zero is, as in:

    class << Metre
      def zero; new 0 end
    end

But of course, that would also require that ordinary numeric classes can tell what their zero is, as in:

    def Integer.zero; 0 end
    def Float.zero; 0.0 end
    def Complex.zero; Complex 0.0, 0.0 end
    # etc.

I think that this way of doing things (that is, having #zero methods in numeric classes and making Matrix actually require the class of the objects in it to have public class method #zero defined) would make everything more consistent and more algebra-like. I am having this problem for already almost half a year, but I only gathered courage today to encumber you guys with this proposal. Please don't judge me harshly for it. I have actually already seen something like this, in particular with bigdecimal's Jacobian (http://ruby-doc.org/stdlib-2.0/libdoc/bigdecimal/rdoc/Jacobian.html), which requires that the object from which the Jacobian is computed implements methods #zero, #one, #two etc. Sorry again.


-- 
http://bugs.ruby-lang.org/

In This Thread