From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 0926B1F4B4 for ; Fri, 8 Jan 2021 23:27:01 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 17625120A42; Sat, 9 Jan 2021 08:26:08 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 66297120A3B for ; Sat, 9 Jan 2021 08:26:06 +0900 (JST) Received: by filterdrecv-p3mdw1-7474cd8bfd-78xpj with SMTP id filterdrecv-p3mdw1-7474cd8bfd-78xpj-21-5FF8EA3D-6 2021-01-08 23:26:53.03183739 +0000 UTC m=+2507075.555011398 Received: from herokuapp.com (unknown) by ismtpd0089p1mdw1.sendgrid.net (SG) with ESMTP id 22Jmp7YgRbWB1IXX493kLw for ; Fri, 08 Jan 2021 23:26:52.983 +0000 (UTC) Date: Fri, 08 Jan 2021 23:26:53 +0000 (UTC) From: kache.hit+ruby-lang@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 77892 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 17521 X-Redmine-Issue-Author: Kache X-Redmine-Sender: Kache X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?W=2F33OQYU6ud8oOFTHE13vJsM6NOCmzxm4EPmjM+p=2F00xMajds+YvU0QAy9Bd3h?= =?us-ascii?Q?eVKsKBz4YE+w8kePpavs+4AxEIHrz2Qp+vnlPlg?= =?us-ascii?Q?omnGIuxaKdDgFAoSB+DGZDfSjX2pc86mCc8NgRJ?= =?us-ascii?Q?L0FEkwIoWDD42pDy5XYTenURL8C2GW=2F8gPcXR1J?= =?us-ascii?Q?J=2FSXl7nDdeLOMOk769eCeiOVwuQjaSnafenxGJH?= =?us-ascii?Q?ifkDnTKmncAcr+ksw=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 101986 Subject: [ruby-core:101986] [Ruby master Bug#17521] [Matrix stdlib] Zero matrix to the power of zero X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "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 `
' 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/