Repository navigation
Take a symbolic inverse, adjugate and negative power without a pivot - #2571
Merged
Merged
Conversation
…2564) A matrix to a negative power, and a number over a matrix, went to GenericTensor's inverse, and the adjugate of a matrix past 2 by 2 came from GenericTensor too, so Inverse did as well. Both took determinants by elimination, dividing by the first pivot and multiplying it back, and Simplify read that as a condition that the pivot is not 0: [[a, b], [c, d]]^(-1) at a = 0, b = c = 1, d = 0 was NaN, and so was the adjugate of [[a, 1, 0], [0, b, 1], [1, 0, c]] at a = 0, which is a matrix of polynomials. #2346 had fixed this for Inverse's determinant only. A negative power is now a power of Inverse, and the adjugate of a matrix with an entry that is not a number is built from cofactors, each an exact Determinant. A matrix of numbers keeps GenericTensor's adjugate: it has no pivot that may be 0, and #561's 100-digit decimals near 1e50 are pinned to that order of operations. A singular matrix to a negative power throws the library's InvalidMatrixOperationException instead of GenericTensor's InvalidDeterminantException. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2571 +/- ##
==========================================
+ Coverage 86.71% 86.72% +0.01%
==========================================
Files 344 344
Lines 74833 74857 +24
Branches 21838 21846 +8
==========================================
+ Hits 64894 64923 +29
+ Misses 5372 5364 -8
- Partials 4567 4570 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
… reach Matrix.Pow took a negative power through Inverse, and Inverse's Adjugate takes GenericTensor's adjugate for a matrix of numbers, which compiles an expression tree. A native build analyses that statically, and every node reaches Pow, so the AOT smoke test and the C++ build failed with IL3050 in GenericTensor's ExpressionCompiler. A negative power of a matrix with an entry that is not a number is now the cofactor adjugate over Determinant, both written over the entries, and a matrix of numbers keeps GenericTensor's MatrixPower as before, after a check on its determinant so that a singular one still throws InvalidMatrixOperationException. The answers are unchanged from the previous commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er-by-the-inverse
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 #2564.
Two routes still reached GenericTensor's inverse after #2346 fixed
Matrix.Inverse's determinant: a matrix to a negative power, and a number over a matrix. GenericTensor's adjugate was also behindMatrix.Adjugate, and so behindInverse, for any matrix larger than 2 by 2.Each took determinants by elimination, which divides by the first pivot and multiplies it back.
Simplifyread that as a condition that the pivot is not 0. Where the pivot is 0 the answer wasNaN, though the inverse exists wherever the determinant is not 0, and the adjugate, a matrix of polynomials, exists everywhere. The issue found the power. Following the mechanism found the adjugate.Matrix.Powwith a negative exponent, for a matrix with an entry that is not a number, is a positive power of the cofactor adjugate overDeterminant. It does not go throughInverse:Inverse'sAdjugatetakes GenericTensor's adjugate for a matrix of numbers, which compiles an expression tree. Every node reachesPow, so the native build failed with IL3050 whenPowcalledInverse(the first CI run here). A matrix of numbers keeps GenericTensor'sMatrixPower. A singular matrix throwsInvalidMatrixOperationException, where it threw GenericTensor'sInvalidDeterminantException.Matrix.Adjugateof a matrix with an entry that is not a number is built from cofactors, each the exactDeterminantof a minor. A matrix of numbers keeps GenericTensor's adjugate: it has no pivot that may be 0. Building it from cofactors too changed Incorrect work with large values in the matrix #561's pinned inverse of 100-digit decimals near 1e50, whose products lose digits whichever way they are taken."[[a, b], [c, d]]^(-1)".ToEntity().Simplify()... provided not a = 0a = 0, b = 1, c = 1, d = 0NaN[[0, 1], [1, 0]]"1 / [[a, b], [c, d]]", the sameNaN[[0, 1], [1, 0]]Adjugateof[[a, 1, 0], [0, b, 1], [1, 0, c]]a * c * a / aa * ca = 0NaN[[b * c, -c, 1], [1, 0, 0], [-b, 1, 0]]Inverseof it ata = 0, b = 1, c = 1NaN[[1, -1, 1], [1, 0, 0], [-1, 1, 0]]"[[1, 2], [3, 4]]^(-1)"[[-2, 1], [3/2, -1/2]]Local checks:
AngouriMathPublishAot=true, which is what CI runs and the local AOT check does not;work/matrixcheck: 400 matrices, no findings;🤖 Generated with Claude Code