Skip to content

Decide a symbolic pivot before choosing it - #2350

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
a-symbolic-pivot-is-simplified-before-it-is-chosen
Nov 3, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
a-symbolic-pivot-is-simplified-before-it-is-chosen

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Closes #2345.

The row echelon forms were GenericTensor's, whose elimination asks whether a pivot is the literal 0. An entry the elimination makes itself, like c + -c / a * a, is 0 without being written so. It was chosen and divided by.

2.6.0 and master now
[[a, b], [2a, 2b]].Rank 2 1
[[a, b, c], [d, f, g], [a + d, b + f, c + g]].Rank 3 2
[[x, x^2], [1, x]].Rank 2 1
[[sin(t)^2 + cos(t)^2, 1], [1, 1]].Rank 2 1
[[a, b], [c, d]].ReducedRowEchelonForm.Simplify() NaN [[1, 0], [0, 1]]
[[a, b], [2a, 2b]].ReducedRowEchelonForm.Simplify() NaN [[1, b / a], [0, 0]]
  • The elimination is written over the entries, as the determinant's Laplace expansion already was (det, dot, cross, transpose and resultant as functions in an expression #2147). It takes GenericTensor's steps: the first entry of a column from the current row down that is not 0 is the pivot, rows are swapped up, and in the reduced form each pivot row is divided by its pivot. So a matrix of numbers comes out as it did. The 177 matrix tests pass unchanged, and matrixcheck is clean on 1200 random matrices (seeds 14–16).
  • Every entry it makes is normalised. A rational function over the rationals goes to RationalFunction's canonical quotient, where 0 is the literal 0. Anything else (sin, pi, more than 8 symbols) is simplified when asked whether it is 0, with a provided on the zero set aside.
  • Rank counts the elimination's pivots, so a symbolic matrix's rank is its rank for general values of its symbols. The issue's "0 where a = b = 0" is not something an int can say, and the doc comment states which rank it is.
  • Conditions. A symbolic pivot divides, so a reduced form holds where its pivots are not 0. Where a simplification can see that, it says so ([[x, x^2], [1, x]] reduces to [[1, x provided not x = 0], [0, 0]]). Whether the reduced form should instead carry the conditions as a whole, or decline, as the issue's second bullet raises, is left open; NaN is gone either way.

Tests: ASymbolicPivotIsDecidedBeforeItIsChosenTest, 13 cases. 11 fail on master; the two independent ranks pass on both. The full suite, AOT and the nine harnesses pass. There is a BREAKING-CHANGES entry, measured on 2.6.0.

🤖 Generated with Claude Code

The row echelon forms were GenericTensor's, whose elimination asked
whether a pivot was the literal 0. An entry the elimination had made
itself, like c + -c / a * a, is 0 without being written so: it was chosen
and divided by, so the reduced form of [[a, b], [c, d]] simplified to NaN,
and the rank of [[a, b], [2a, 2b]], whose second row is twice the first,
was 2. 2.6.0 does the same.

The elimination is written over the entries, with GenericTensor's steps:
the first entry of a column that is not 0, from the current row down, for
its pivot, rows swapped up, and the reduced form's pivot rows divided by
their pivot. Each entry it makes is normalised, a rational function over
the rationals to RationalFunction's canonical quotient, where 0 is the
literal 0, and anything else is simplified when asked whether it is 0. A
symbolic matrix's rank is its rank for general values of its symbols:
[[a, b], [2a, 2b]] has rank 1, and [[a, b, c], [d, f, g], [a + d, b + f,
c + g]] rank 2. Matrices of numbers come out as they did: the 177 matrix
tests pass unchanged, and matrixcheck is clean on 1200 random ones.

Part of #2345

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Rafael-SOWNet Rafael-SOWNet added this to the 2.7.0 milestone Nov 3, 2026
@Rafael-SOWNet Rafael-SOWNet moved this from Todo to In review in AngouriMath Nov 3, 2026
@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.72727% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.79%. Comparing base (0e96927) to head (d574b0b).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...rces/AngouriMath/Core/Entity/Omni/Entity.Matrix.cs 97.72% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2350      +/-   ##
==========================================
- Coverage   86.79%   86.79%   -0.01%     
==========================================
  Files         312      312              
  Lines       68664    68709      +45     
  Branches    19987    20006      +19     
==========================================
+ Hits        59595    59633      +38     
- Misses       4902     4907       +5     
- Partials     4167     4169       +2     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.33% <97.72%> (-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 85.05% <97.72%> (+1.65%) ⬆️

... and 6 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
Rafael-SOWNet merged commit 40dd98f into master Nov 3, 2026
35 checks passed
@Rafael-SOWNet
Rafael-SOWNet deleted the a-symbolic-pivot-is-simplified-before-it-is-chosen branch November 3, 2026 13:54
@github-project-automation github-project-automation Bot moved this from In review to Done in AngouriMath Nov 3, 2026
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 a symbolic matrix is NaN, and the rank of [[a, b], [2a, 2b]] is 2

1 participant