Skip to content

The row echelon forms divide exactly - #2279

Merged
Rafael-SOWNet merged 3 commits into
masterfrom
the-reduced-row-echelon-form-divides-exactly
Oct 31, 2026
Merged

Rafael-SOWNet merged 3 commits into
masterfrom
the-reduced-row-echelon-form-divides-exactly

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

The reduced row echelon form of an invertible 4x4 of small rationals had NaN entries, and its Rank threw InvalidCastException. Both forms used GenericTensor's SafeDivision elimination. It keeps every entry as a numerator and a denominator that are never reduced against each other, which suits element types whose division truncates; an Entity divides exactly. Unreduced, the pairs grow with every row operation, and the back substitution squares them. The issue's matrix ended with a denominator near 1e-246, and 0 divided by that is NaN, which is #2277. One 7x7 of small entries took 112 seconds, with 42 NaN entries, and an 8x8 did not return.

Both forms now use the Simple elimination, which divides as it goes.

Input 2.6.0 Now
the issue's 4x4, .Rank throws InvalidCastException 4
the same, .ReducedRowEchelonForm throws InvalidCastException the identity
[[a, b], [c, d]], .RowEchelonForm [[a, b], [(c * a + -c * a) / a, (d * a + -c * b) / a]] [[a, b], [c + -c / a * a, d + -c / a * b]]

MatrixTest reduces the issue's matrix, and two more from a random sweep, to the identity with rank 4. It also reduces an 8x8 with determinant -5598, bounded at a minute. All four cases fail on master, the 8x8 by not returning. The suite (18,233), the trio, F#, AOT and the eight harnesses pass locally.

The subagent that traced this ran a sweep against an exact Gauss–Jordan reference. Master gave NaN on 13 of 600 4x4s and on 38 of 200 5x5s; this branch gave none. Symbolic forms change shape but not value: on 13 symbolic matrices it judged, the verdicts were the same on both routes, and 10 of them are wrong on both, because InnerSimplified does not collapse x + -x before taking it as a pivot. That is a separate problem.

This edits the same two lines as #2272, so whichever merges second will need one conflict resolved.

Fixes #2270.

🤖 Generated with Claude Code

Rafael-SOWNet and others added 2 commits October 30, 2026 20:58
The reduced row echelon form of an invertible 4x4 of small rationals
had NaN entries, and its Rank threw InvalidCastException. Both forms
were GenericTensor's SafeDivision elimination, which keeps every entry
as a numerator and a denominator that are never reduced against each
other. That is for element types whose division truncates, and an
Entity divides exactly. Unreduced, the pairs grew with every row
operation and the back substitution squared them: the issue's matrix
ended with a denominator near 1e-246, and 0 over it is NaN (#2277). A
7x7 took nine seconds and an 8x8 did not return.

Both forms now use the Simple elimination, which divides as it goes.

MatrixTest takes the issue's matrix and two more of a random sweep to
the identity with rank 4, and an 8x8 with determinant -5598, bounded at
a minute. All four fail on master, the 8x8 by not returning. The
suite, the trio, F#, AOT and the eight harnesses pass. Symbolic forms
are written otherwise, [[a, b], [c, d]]'s row echelon form among them.

Traced, with GenericTensor's elimination written out step by step, by
a subagent.

Fixes #2270.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
One 7x7 of small entries took 112 seconds through the SafeDivision
elimination, with 42 NaN entries. Nine seconds was another matrix's.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Rafael-SOWNet Rafael-SOWNet added this to the 2.7.0 milestone Oct 30, 2026
@Rafael-SOWNet Rafael-SOWNet moved this from Todo to In review in AngouriMath Oct 30, 2026
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.71%. Comparing base (f570b35) to head (6f0e3b2).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2279      +/-   ##
==========================================
+ Coverage   86.70%   86.71%   +0.01%     
==========================================
  Files         310      310              
  Lines       67869    67869              
  Branches    19701    19701              
==========================================
+ Hits        58843    58854      +11     
+ Misses       4903     4892      -11     
  Partials     4123     4123              
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.26% <100.00%> (+0.01%) ⬆️
fsharp 32.97% <ø> (ø)
interactive 40.72% <ø> (ø)

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 83.40% <100.00%> (ø)

... and 10 files with indirect coverage changes

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

#2272 wraps both forms' simplified matrix in OfTheShapeOf, and this
branch moves both to the Simple elimination; each form now does both.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Rafael-SOWNet
Rafael-SOWNet merged commit d1c57bb into master Oct 31, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in AngouriMath Oct 31, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the the-reduced-row-echelon-form-divides-exactly branch October 31, 2026 02:03
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.

The reduced row echelon form of an invertible 4x4 matrix has NaN entries

1 participant