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/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>