Skip to content

Take a symbolic inverse, adjugate and negative power without a pivot - #2571

Merged
Rafael-SOWNet merged 3 commits into
masterfrom
matrix-negative-power-by-the-inverse
Nov 27, 2026
Merged

Rafael-SOWNet merged 3 commits into
masterfrom
matrix-negative-power-by-the-inverse

Conversation

@Rafael-SOWNet

@Rafael-SOWNet Rafael-SOWNet commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

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 behind Matrix.Adjugate, and so behind Inverse, for any matrix larger than 2 by 2.

Each took determinants by elimination, which divides by the first pivot and multiplies it back. Simplify read that as a condition that the pivot is not 0. Where the pivot is 0 the answer was NaN, 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.Pow with a negative exponent, for a matrix with an entry that is not a number, is a positive power of the cofactor adjugate over Determinant. It does not go through Inverse: Inverse's Adjugate takes GenericTensor's adjugate for a matrix of numbers, which compiles an expression tree. Every node reaches Pow, so the native build failed with IL3050 when Pow called Inverse (the first CI run here). A matrix of numbers keeps GenericTensor's MatrixPower. A singular matrix throws InvalidMatrixOperationException, where it threw GenericTensor's InvalidDeterminantException.
  • Matrix.Adjugate of a matrix with an entry that is not a number is built from cofactors, each the exact Determinant of 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.
2.9.0 this branch
"[[a, b], [c, d]]^(-1)".ToEntity().Simplify() each entry ... provided not a = 0 no condition
the same at a = 0, b = 1, c = 1, d = 0 NaN [[0, 1], [1, 0]]
"1 / [[a, b], [c, d]]", the same NaN [[0, 1], [1, 0]]
Adjugate of [[a, 1, 0], [0, b, 1], [1, 0, c]] an entry a * c * a / a a * c
the same at a = 0 NaN [[b * c, -c, 1], [1, 0, 0], [-b, 1, 0]]
Inverse of it at a = 0, b = 1, c = 1 NaN [[1, -1, 1], [1, 0, 0], [-1, 1, 0]]
"[[1, 2], [3, 4]]^(-1)" [[-2, 1], [3/2, -1/2]] unchanged

Local checks:

  • the suite: 21,510 passed;
  • the MCP, Terminal, Interactive and F# suites;
  • AOT: 83 passed, and the smoke test published with AngouriMathPublishAot=true, which is what CI runs and the local AOT check does not;
  • all nine harnesses, with canoncheck, confluence and the Modenov corpus matching their baselines;
  • work/matrixcheck: 400 matrices, no findings;
  • the solver cross-checks and scalecheck: identical to master except timings.

🤖 Generated with Claude Code

…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

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.87879% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.72%. Comparing base (4faf113) to head (b7eb12a).

Files with missing lines Patch % Lines
...rces/AngouriMath/Core/Entity/Omni/Entity.Matrix.cs 87.87% 2 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.23% <87.87%> (+0.01%) ⬆️
fsharp 32.79% <ø> (ø)
interactive 40.09% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...rces/AngouriMath/Core/Entity/Omni/Entity.Matrix.cs 85.09% <87.87%> (-0.16%) ⬇️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Rafael-SOWNet and others added 2 commits November 26, 2026 22:52
… 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>
@Rafael-SOWNet
Rafael-SOWNet merged commit f277e97 into master Nov 27, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Nov 27, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the matrix-negative-power-by-the-inverse branch November 27, 2026 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

A symbolic matrix to the power -1 has no value where its first pivot is zero: [[a, b], [c, d]]^(-1) at a = 0 is NaN

1 participant