ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:101986] [Ruby master Bug#17521] [Matrix stdlib] Zero matrix to the power of zero
@ 2021-01-08 23:26 kache.hit+ruby-lang
  2021-01-09  0:17 ` [ruby-core:101987] " kache.hit+ruby-lang
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: kache.hit+ruby-lang @ 2021-01-08 23:26 UTC (permalink / raw)
  To: ruby-core

Issue #17521 has been reported by Kache (Kevin Cheng).

----------------------------------------
Bug #17521: [Matrix stdlib] Zero matrix to the power of zero
https://bugs.ruby-lang.org/issues/17521

* Author: Kache (Kevin Cheng)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-msys]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
Just like `0**0 == 1`, `Matrix.zero(n)**0 == Matrix.identity(n)` should be true for all `n`:

https://math.stackexchange.com/questions/699740/zero-matrix-to-the-power-of-0

However:

```
$ ruby -e "require 'matrix'; Matrix.zero(1)**0"
Traceback (most recent call last):
        5: from -e:1:in `<main>'
        4: from /usr/lib/ruby/2.7.0/matrix.rb:1227:in `**'
        3: from /usr/lib/ruby/2.7.0/matrix.rb:1165:in `inverse'
        2: from /usr/lib/ruby/2.7.0/matrix.rb:1173:in `inverse_from'
        1: from /usr/lib/ruby/2.7.0/matrix.rb:1173:in `upto'
/usr/lib/ruby/2.7.0/matrix.rb:1183:in `block in inverse_from': Not Regular Matrix (ExceptionForMatrix::ErrNotRegular)
```

`Matrix.zero(n)**0.0` happens to work properly, but it should work for integers as well.
Wasn't able to test in Ruby 3.0, but its source code suggests it also behaves this way.

For comparison, [Python's numpy](https://numpy.org/doc/stable/reference/generated/numpy.linalg.matrix_power.html):

```
Python 3.8.2 (default, Feb 26 2020, 02:56:10)
>> import numpy as np
>> np.linalg.matrix_power(np.array([[0,0],[0,0]]), 0)
array([[1, 0],
       [0, 1]])
```



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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:101987] [Ruby master Bug#17521] [Matrix stdlib] Zero matrix to the power of zero
  2021-01-08 23:26 [ruby-core:101986] [Ruby master Bug#17521] [Matrix stdlib] Zero matrix to the power of zero kache.hit+ruby-lang
@ 2021-01-09  0:17 ` kache.hit+ruby-lang
  2021-01-09 19:18 ` [ruby-core:101994] " marcandre-ruby-core
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: kache.hit+ruby-lang @ 2021-01-09  0:17 UTC (permalink / raw)
  To: ruby-core

Issue #17521 has been updated by Kache (Kevin Cheng).


Just like `0**0 == 1`, `Matrix.zero(n)**0 == Matrix.identity(n)` should be true for all `n`:

https://math.stackexchange.com/questions/699740/zero-matrix-to-the-power-of-0

However:

```
$ ruby -e "require 'matrix'; Matrix.zero(1)**0"
Traceback (most recent call last):
        5: from -e:1:in `<main>'
        4: from /usr/lib/ruby/2.7.0/matrix.rb:1227:in `**'
        3: from /usr/lib/ruby/2.7.0/matrix.rb:1165:in `inverse'
        2: from /usr/lib/ruby/2.7.0/matrix.rb:1173:in `inverse_from'
        1: from /usr/lib/ruby/2.7.0/matrix.rb:1173:in `upto'
/usr/lib/ruby/2.7.0/matrix.rb:1183:in `block in inverse_from': Not Regular Matrix (ExceptionForMatrix::ErrNotRegular)
```

`Matrix.zero(n)**0.0` happens to work properly, but it should work for integers as well.
Wasn't able to test in Ruby 3.0, but its source code suggests it also behaves this way.

It appears [specs declare this as intended behavior](https://github.com/ruby/ruby/blob/1a3343cfdcb765b94bf63375d45618130d6b92c9/spec/ruby/library/matrix/exponent_spec.rb#L34):

```
      it "raises a ErrDimensionMismatch for irregular matrices" do
        m = Matrix[ [1, 1], [1, 1] ]
        -> { m ** -2 }.should raise_error(Matrix::ErrNotRegular)
        -> { m ** 0 }.should raise_error(Matrix::ErrNotRegular)
      end
```

But I don't see why this should be the case.

For comparison, [Python's numpy](https://numpy.org/doc/stable/reference/generated/numpy.linalg.matrix_power.html):

```
Python 3.8.2 (default, Feb 26 2020, 02:56:10)
>> import numpy as np
>> np.linalg.matrix_power(np.array([[0,0],[0,0]]), 0)
array([[1, 0],
       [0, 1]])
>> np.linalg.matrix_power(np.array([[1,1],[1,1]]), 0)
array([[1, 0],
       [0, 1]])
```



----------------------------------------
Bug #17521: [Matrix stdlib] Zero matrix to the power of zero
https://bugs.ruby-lang.org/issues/17521#change-89837

* Author: Kache (Kevin Cheng)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-msys]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
Just like `0**0 == 1`, `Matrix.zero(n)**0 == Matrix.identity(n)` should be true for all `n`:

https://math.stackexchange.com/questions/699740/zero-matrix-to-the-power-of-0

However:

```
$ ruby -e "require 'matrix'; Matrix.zero(1)**0"
Traceback (most recent call last):
        5: from -e:1:in `<main>'
        4: from /usr/lib/ruby/2.7.0/matrix.rb:1227:in `**'
        3: from /usr/lib/ruby/2.7.0/matrix.rb:1165:in `inverse'
        2: from /usr/lib/ruby/2.7.0/matrix.rb:1173:in `inverse_from'
        1: from /usr/lib/ruby/2.7.0/matrix.rb:1173:in `upto'
/usr/lib/ruby/2.7.0/matrix.rb:1183:in `block in inverse_from': Not Regular Matrix (ExceptionForMatrix::ErrNotRegular)
```

`Matrix.zero(n)**0.0` happens to work properly, but it should work for integers as well.
Wasn't able to test in Ruby 3.0, but its source code suggests it also behaves this way.

For comparison, [Python's numpy](https://numpy.org/doc/stable/reference/generated/numpy.linalg.matrix_power.html):

```
Python 3.8.2 (default, Feb 26 2020, 02:56:10)
>> import numpy as np
>> np.linalg.matrix_power(np.array([[0,0],[0,0]]), 0)
array([[1, 0],
       [0, 1]])
```



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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:101994] [Ruby master Bug#17521] [Matrix stdlib] Zero matrix to the power of zero
  2021-01-08 23:26 [ruby-core:101986] [Ruby master Bug#17521] [Matrix stdlib] Zero matrix to the power of zero kache.hit+ruby-lang
  2021-01-09  0:17 ` [ruby-core:101987] " kache.hit+ruby-lang
@ 2021-01-09 19:18 ` marcandre-ruby-core
  2021-04-15  1:50 ` [ruby-core:103458] " nagachika00
  2021-04-15  3:10 ` [ruby-core:103460] " marcandre-ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: marcandre-ruby-core @ 2021-01-09 19:18 UTC (permalink / raw)
  To: ruby-core

Issue #17521 has been updated by marcandre (Marc-Andre Lafortune).

Assignee set to marcandre (Marc-Andre Lafortune)
Status changed from Open to Assigned

Congratulations on finding the oldest bug in Ruby ever! 🎉

This bug will be 23 years old in a week; it dates from the commit "Initial revision" 3db12e8b23

I should have realized this when I refactored it later on and added the spec though.

----------------------------------------
Bug #17521: [Matrix stdlib] Zero matrix to the power of zero
https://bugs.ruby-lang.org/issues/17521#change-89843

* Author: Kache (Kevin Cheng)
* Status: Assigned
* Priority: Normal
* Assignee: marcandre (Marc-Andre Lafortune)
* ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-msys]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
Just like `0**0 == 1`, `Matrix.zero(n)**0 == Matrix.identity(n)` should be true for all `n`:

https://math.stackexchange.com/questions/699740/zero-matrix-to-the-power-of-0

However:

```
$ ruby -e "require 'matrix'; Matrix.zero(1)**0"
Traceback (most recent call last):
        5: from -e:1:in `<main>'
        4: from /usr/lib/ruby/2.7.0/matrix.rb:1227:in `**'
        3: from /usr/lib/ruby/2.7.0/matrix.rb:1165:in `inverse'
        2: from /usr/lib/ruby/2.7.0/matrix.rb:1173:in `inverse_from'
        1: from /usr/lib/ruby/2.7.0/matrix.rb:1173:in `upto'
/usr/lib/ruby/2.7.0/matrix.rb:1183:in `block in inverse_from': Not Regular Matrix (ExceptionForMatrix::ErrNotRegular)
```

`Matrix.zero(n)**0.0` happens to work properly, but it should work for integers as well.
Wasn't able to test in Ruby 3.0, but its source code suggests it also behaves this way.

For comparison, [Python's numpy](https://numpy.org/doc/stable/reference/generated/numpy.linalg.matrix_power.html):

```
Python 3.8.2 (default, Feb 26 2020, 02:56:10)
>> import numpy as np
>> np.linalg.matrix_power(np.array([[0,0],[0,0]]), 0)
array([[1, 0],
       [0, 1]])
```



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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:103458] [Ruby master Bug#17521] [Matrix stdlib] Zero matrix to the power of zero
  2021-01-08 23:26 [ruby-core:101986] [Ruby master Bug#17521] [Matrix stdlib] Zero matrix to the power of zero kache.hit+ruby-lang
  2021-01-09  0:17 ` [ruby-core:101987] " kache.hit+ruby-lang
  2021-01-09 19:18 ` [ruby-core:101994] " marcandre-ruby-core
@ 2021-04-15  1:50 ` nagachika00
  2021-04-15  3:10 ` [ruby-core:103460] " marcandre-ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: nagachika00 @ 2021-04-15  1:50 UTC (permalink / raw)
  To: ruby-core

Issue #17521 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN to 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: WONTFIX

Even though nobody filled the Backport field yet, I will set "WONTFIX".
Such a long long standing bug could be thought as an spec, and some application could be depended by current behavior.
usa-san, do you have any opinion?

And the related test in rubyspec is failing on ruby_3_0 branch because the test seems expected this change is going to be backported into 3.0.x.
I will send a pull request to ruby/spec repo soon.

----------------------------------------
Bug #17521: [Matrix stdlib] Zero matrix to the power of zero
https://bugs.ruby-lang.org/issues/17521#change-91553

* Author: Kache (Kevin Cheng)
* Status: Closed
* Priority: Normal
* Assignee: marcandre (Marc-Andre Lafortune)
* ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-msys]
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: WONTFIX
----------------------------------------
Just like `0**0 == 1`, `Matrix.zero(n)**0 == Matrix.identity(n)` should be true for all `n`:

https://math.stackexchange.com/questions/699740/zero-matrix-to-the-power-of-0

However:

```
$ ruby -e "require 'matrix'; Matrix.zero(1)**0"
Traceback (most recent call last):
        5: from -e:1:in `<main>'
        4: from /usr/lib/ruby/2.7.0/matrix.rb:1227:in `**'
        3: from /usr/lib/ruby/2.7.0/matrix.rb:1165:in `inverse'
        2: from /usr/lib/ruby/2.7.0/matrix.rb:1173:in `inverse_from'
        1: from /usr/lib/ruby/2.7.0/matrix.rb:1173:in `upto'
/usr/lib/ruby/2.7.0/matrix.rb:1183:in `block in inverse_from': Not Regular Matrix (ExceptionForMatrix::ErrNotRegular)
```

`Matrix.zero(n)**0.0` happens to work properly, but it should work for integers as well.
Wasn't able to test in Ruby 3.0, but its source code suggests it also behaves this way.

For comparison, [Python's numpy](https://numpy.org/doc/stable/reference/generated/numpy.linalg.matrix_power.html):

```
Python 3.8.2 (default, Feb 26 2020, 02:56:10)
>> import numpy as np
>> np.linalg.matrix_power(np.array([[0,0],[0,0]]), 0)
array([[1, 0],
       [0, 1]])
```



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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:103460] [Ruby master Bug#17521] [Matrix stdlib] Zero matrix to the power of zero
  2021-01-08 23:26 [ruby-core:101986] [Ruby master Bug#17521] [Matrix stdlib] Zero matrix to the power of zero kache.hit+ruby-lang
                   ` (2 preceding siblings ...)
  2021-04-15  1:50 ` [ruby-core:103458] " nagachika00
@ 2021-04-15  3:10 ` marcandre-ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: marcandre-ruby-core @ 2021-04-15  3:10 UTC (permalink / raw)
  To: ruby-core

Issue #17521 has been updated by marcandre (Marc-Andre Lafortune).


Since `matrix` is a gem that can be updated independently from Ruby, I think backports are not required. In addition, this bug is very minor.

----------------------------------------
Bug #17521: [Matrix stdlib] Zero matrix to the power of zero
https://bugs.ruby-lang.org/issues/17521#change-91555

* Author: Kache (Kevin Cheng)
* Status: Closed
* Priority: Normal
* Assignee: marcandre (Marc-Andre Lafortune)
* ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-msys]
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: WONTFIX
----------------------------------------
Just like `0**0 == 1`, `Matrix.zero(n)**0 == Matrix.identity(n)` should be true for all `n`:

https://math.stackexchange.com/questions/699740/zero-matrix-to-the-power-of-0

However:

```
$ ruby -e "require 'matrix'; Matrix.zero(1)**0"
Traceback (most recent call last):
        5: from -e:1:in `<main>'
        4: from /usr/lib/ruby/2.7.0/matrix.rb:1227:in `**'
        3: from /usr/lib/ruby/2.7.0/matrix.rb:1165:in `inverse'
        2: from /usr/lib/ruby/2.7.0/matrix.rb:1173:in `inverse_from'
        1: from /usr/lib/ruby/2.7.0/matrix.rb:1173:in `upto'
/usr/lib/ruby/2.7.0/matrix.rb:1183:in `block in inverse_from': Not Regular Matrix (ExceptionForMatrix::ErrNotRegular)
```

`Matrix.zero(n)**0.0` happens to work properly, but it should work for integers as well.
Wasn't able to test in Ruby 3.0, but its source code suggests it also behaves this way.

For comparison, [Python's numpy](https://numpy.org/doc/stable/reference/generated/numpy.linalg.matrix_power.html):

```
Python 3.8.2 (default, Feb 26 2020, 02:56:10)
>> import numpy as np
>> np.linalg.matrix_power(np.array([[0,0],[0,0]]), 0)
array([[1, 0],
       [0, 1]])
```



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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-04-15  3:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-08 23:26 [ruby-core:101986] [Ruby master Bug#17521] [Matrix stdlib] Zero matrix to the power of zero kache.hit+ruby-lang
2021-01-09  0:17 ` [ruby-core:101987] " kache.hit+ruby-lang
2021-01-09 19:18 ` [ruby-core:101994] " marcandre-ruby-core
2021-04-15  1:50 ` [ruby-core:103458] " nagachika00
2021-04-15  3:10 ` [ruby-core:103460] " marcandre-ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).