Repository navigation
A matrix is divided, raised to a power and compared as a matrix - #2155
Merged
Rafael-SOWNet merged 2 commits intoOct 27, 2026
Merged
Conversation
Where an operation had no answer of its own for two matrices, or a matrix and a number, ExpandOnTwoArguments applied it entry by entry. That is what addition and subtraction mean, and a matrix over a number, but not division, powers or equality: [[1, 2], [3, 4]] divided by itself was [[1, 1], [1, 1]], [1, 2]^2 was [1, 4], and [1, 2] = [1, 3] was the vector [True, False] while [1, 2] = [1, 2] was True. Simplify writes x * x as x^2, so the undefined product [1, 2] * [1, 2] became [1, 4] too. Dividing by a matrix now multiplies by its inverse, as the wiki says it does, and a divisor with no inverse leaves the quotient written. A number over a matrix is that number times the inverse as well: x / y and x * y^(-1) are rewritten into each other, and y^(-1) of a matrix is its inverse, so reading 1 / M entry by entry disagreed with M^(-1). A version that spread the number over the entries instead turned a singular M^(-1), which Simplify writes as 1 / M, into the reciprocals of its entries. A power of anything but a square matrix stays written, and so does a negative power of a singular one, which threw InvalidDeterminantException from Evaled and Simplify. Two matrices are equal when they have one shape and are equal entry by entry, as one statement. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
Asking Matrix.Inverse from division and from a power made GenericTensor's InvertMatrix, and through Determinant its DeterminantLaplace, reachable from every node. Both are compiled at run time and are not safe in a native build, so every AOT publish failed with IL3053. Whether a matrix may have an inverse is now asked of the exact elimination, which does not touch GenericTensor, and the inverse itself is Pow(-1), which was reachable before. A determinant the elimination cannot write is not known to be zero. The C++ wrapper's native publish and the trimmed and AOT smoke tests pass locally, the latter 45 of 45. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
Rafael-SOWNet
deleted the
a-matrix-is-divided-and-compared-as-a-matrix
branch
October 27, 2026 10:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2141.
Wrong answers about matrices. Where an operation has no answer of its own for two matrices, or for a matrix and a number,
ExpandOnTwoArgumentsapplies it entry by entry. That is right for addition and subtraction, and for a matrix over a number, but not for division, powers or equality.[[1, 2], [3, 4]] / [[1, 2], [3, 4]][[1, 1], [1, 1]][[1, 0], [0, 1]]2 / [[1, 2], [3, 4]][[2, 1], [2/3, 1/2]][[-4, 2], [3, -1]]2 / [1, 2][2, 1]2 / [1, 2][1, 2] ^ 2[1, 4][1, 2] ^ 2([1, 2] * [1, 2]).Simplify()[1, 4][1, 2] ^ 2[1, 2] = [1, 3][True, False]False[a, b] = [c, d][a = c, b = d]a = c and b = d[[1, 2], [2, 4]] ^ (-1)InvalidDeterminantExceptionDivision by a matrix multiplies by its inverse, as the wiki's Matrices page says. A divisor with no inverse, singular or not square, leaves the quotient written.
A number over a matrix is the number times the inverse too. I first spread it over the entries, to match
2 - MandM / 2, and that gave a wrong answer:Simplifyrewritesx^(-1)and1 / xinto each other.M^(-1), which stays written, became1 / M.x / yandx * y^(-1)have to agree, andy^(-1)of a matrix is its inverse.A power of anything but a square matrix stays written. A negative power of a singular matrix stays written too; it used to throw from
EvaledandSimplify. This also fixes[1, 2] * [1, 2], whichSimplifyrewrites as[1, 2]^2.Two matrices are equal when they have one shape and are equal entry by entry. The equality is now one statement, where it was a vector of statements.
Unchanged:
<, which are still elementwise.[1, 2] = 1.Native builds. The first push asked
Matrix.Inverse, and failed every AOT publish with IL3053.Matrix.Inversegoes through GenericTensor'sInvertMatrix, andDeterminantcan fall back to itsDeterminantLaplace; both are compiled at run time, and reaching them from division made them reachable from every node. Whether a matrix may have an inverse is now asked of the exact elimination (PolynomialDeterminant). The inverse isPow(-1), which master already reaches.Checked:
MatrixTest, with all 147 matrix tests passing.Found while reading Modenov's Problems in Geometry for #2131.
🤖 Generated with Claude Code
https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura