inverse of a non-square matrix returns a matrix instead of erroring
Nobody has claimed this yet.
- Dominant language
- Macaulay2
- Stars
- 435
- Forks
- 297
- Avg merge
- 4d 20h
- Merged PRs (30d)
- 11
Description
This issue was triaged from bugs/dan/0-inverse-matrix, one of the 857 files removed from the pre-GitHub bugs/ tree by d2c8d27826 and catalogued in #36. The commentary below was written by Claude (Claude Opus 5, via Claude Code), not by @d-torrance, whose account posted it -- please weigh it accordingly.
The original file, verbatim
all of these should give errors:
o34 = new HashTable from {asdf => foo}
i35 : inverse matrix {{1,2}}
o35 = | 1 |
| 0 |
2 1
o35 : Matrix ZZ <--- ZZ
i36 : ( matrix {{1,2}} )^-1
o36 = | 1 |
| 0 |
2 1
o36 : Matrix ZZ <--- ZZ
i39 : ( matrix {{1},{2}} )^-1
stdio:39:21:(3):[0]: error: matrix not invertible
i40 : inverse matrix {{1},{2}}
stdio:40:1:(3):[0]: error: matrix not invertible
Where it stands today
Still reproduces. A non-square matrix gets an "inverse" instead of an error:
i1 : inverse matrix {{1,2}}
o1 = | 1 |
| 0 |
2 1
o1 : Matrix ZZ <--- ZZ
i2 : (matrix {{1,2}})^-1 -- same answer by the other spelling
while the transpose is diagnosed correctly:
i3 : inverse matrix {{1},{2}}
stdio:3:1:(3): error: matrix not invertible
So one orientation errors and the other returns a matrix that is not an inverse of anything —
matrix {{1,2}} * matrix {{1},{0}} is the 1×1 identity, but the product the other way is not the 2×2
identity, which is what "inverse" claims.
Why the two orientations differ
The computation is a solve rather than an inversion: for a wide matrix a right inverse exists and is
found, for a tall one nothing satisfies the system and the error fires. The bug is that inverse does
not first insist on a square matrix, so a one-sided solution is returned under a name that promises a
two-sided one.
Related
#3738 reaches a wrong inverse by a different path, so the two are worth reading together but are
not the same defect.
open · disposition issue · source of truth: bug-triage/catalog.tsv
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the two cases using the inverse matrix and ^-1 entry points described here, and compare them with the transpose case. Trace the inverse implementation and the historical bugs/dan/0-inverse-matrix report, then add regression coverage showing that non-square matrices error in both orientations while square inverses still work.
Written by the indexing model from the issue text.
Assessment
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100