Skip to content

Keep a transpose or a vector product beside a written matrix a matrix - #2560

Merged
Rafael-SOWNet merged 2 commits into
masterfrom
transpose-beside-a-written-matrix
Nov 26, 2026
Merged

Rafael-SOWNet merged 2 commits into
masterfrom
transpose-beside-a-written-matrix

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Closes #2557.

InnerSimplified and Evaled read a transpose that is not yet carried out as a number, so they multiplied it into the written vectors around it: [1, 0]T * transpose(A) * [0, 1] was 0, where it is the entry A[2, 1]. Simplify kept that product, but read a transpose inside a sum as a number, so [1, 0]T * (transpose(A) + B) * [0, 1] was 0 there too.

What was wrong

Measured with A = [[5, 6], [7, 8]], B = [[10, 20], [30, 40]] and x = 2 substituted where a value is shown:

2.9.0 and master this PR
[1, 0]T * transpose(A) * [0, 1], InnerSimplified 0 kept as written; 7 once A is substituted
[1, 0]T * transpose(A + [[1, 2], [3, 4]]) * [0, 1], InnerSimplified 0 kept as written; 10 once A is substituted
[1, 0]T * transpose(x * [[1, 2], [3, 4]]) * [0, 1], InnerSimplified 0 kept as written; 6 at x = 2
[1, 0]T * (transpose(A) + B) * [0, 1], Simplify 0 kept as written; 23 once both are substituted
[1, 0] + transpose(A), Simplify spread over the entries kept as written

The full table, measured on the 2.9.0 package and on this branch, is the new BREAKING-CHANGES entry.

Why

InnerSimplified and Evaled go through ExpandOnTwoArguments, which multiplies an operand that is not a written matrix into a written matrix's entries, so [1, 0]T * transpose(A) became [[transpose(A), 0]]. A vector product not yet carried out was read the same way. Simplify sets a product with a bare transpose in it aside (#1237, #2147), but took only a bare transpose or vector product for a matrix, so a transpose inside a sum or a product was sorted as if it commuted.

How

  • One test, ProductsOfMatrices.IsAMatrixNotWrittenOut. An expression is a matrix when it contains a transpose or a vector product that cannot be carried out yet. Occurrences inside a written matrix, a det, a trace, an entry, a dot, a norm, a statement or a set do not count.
  • ExpandOnTwoArguments leaves such an operand beside a written matrix as written.
  • The three places in Simplify that decide whether a product's factors may be reordered or set aside use the same test.
  • A bare name is still read as a number (x * [1, 2] is [x, 2 x], Typed variables #1237), so [1, 0]T * A * [0, 1] is still 0. That is the older decision about names, which carry no type, and this PR does not change it.

Tested

  • 20 new tests in MatrixOperationNodesTest and DotAndCrossNodesTest, each compared with the value after substituting the matrices. They fail on master and pass here.
  • The failures in a full unit-test run are the same on master: cases that depend on the culture (a decimal comma under a Dutch culture, a documented example printing 0,4) and a timeout inside the full parallel run that passes alone. F# wrapper tests: 135 of 135. CanonCheck and Confluence match their committed baselines.
  • Syntax.md gained a sentence: a transpose beside a written matrix is not multiplied into its entries.

Not in this PR

  • [1, 0]T * derivative(transpose(x * A), x) * [0, 1], with A = [[1, 2], [3, 4]] substituted, was a wrong 0 from Evaled. It is now left unevaluated, where the answer is 3: the derivative leaves [[0, 0], [0, 0]] * x inside the transpose, and the caution about a name beside a written matrix keeps the transpose from being carried out.
  • transpose(A) * 0 is still the number 0 rather than a zero matrix, an older convention.

Merging with the compiler PR for dot and cross: both add an entry at the end of "Unreleased" in BREAKING-CHANGES; keep both. Nothing else overlaps.

🤖 Generated with Claude Code

InnerSimplified and Evaled share ExpandOnTwoArguments, which spread any
operand that was not a written matrix over a written matrix's entries.
A transpose or a vector product not yet carried out was read as a
number that way: [1, 0]T * transpose(A) * [0, 1] became
[[transpose(A), 0]] * [0, 1] and so 0, where it is the entry A[2, 1],
and [0, 0, 1]T * cross(a, b) became [[0, 0, cross(a, b)]], a row with
a vector for an entry. Simplify set the plain product aside and kept
it, but it sorted a product whose factor was a sum with a transpose in
it as though matrices commuted, so [1, 0]T * (transpose(A) + B) * [0, 1]
was 0 there too, and it spread [1, 0] + transpose(A) over the entries.

ProductsOfMatrices.IsAMatrixNotWrittenOut now says what is such a
matrix: a transpose or a vector product that simplification cannot
carry out, or anything with one in it other than inside a determinant,
a trace, an entry, a scalar product or a norm, a statement or a set.
A function of one counts, since not knowing it to be a number is reason
enough not to read it as one; abs is a vector's length and is taken
entry by entry over a larger matrix. ExpandOnTwoArguments leaves such
an operand beside a written matrix as written, and the three places
that decide whether a product's factors may be sorted or set aside ask
the same question, where each asked only about a bare transpose or
vector product.

A bare name is not counted: beside a written matrix it is read as a
number, as x * [1, 2] is [x, 2 x], and [1, 0]T * A * [0, 1] is still 0.
That is an older decision about names, which carry no type (#1237).

Measured on v2.9.0 and on this branch; the table is in
BREAKING-CHANGES. The 20 new tests fail on master and pass here. The
whole UnitTests run: 21442 passed, 4 failed, and those 4 fail the same
way on master on this Dutch-culture machine (two read 0,5 as two
arguments, a documented example prints 0,4) or time out only inside the
full parallel run (ln(x) * erf(x), which passes alone on both). F#
wrapper tests 135/135. CanonCheck and Confluence match their baselines.

Part of #2557.

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 91.30435% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.72%. Comparing base (5a08e12) to head (246098a).

Files with missing lines Patch % Lines
...ath/Functions/Simplification/ProductsOfMatrices.cs 89.47% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2560      +/-   ##
==========================================
+ Coverage   86.71%   86.72%   +0.01%     
==========================================
  Files         344      344              
  Lines       74809    74836      +27     
  Branches    21821    21837      +16     
==========================================
+ Hits        64868    64904      +36     
+ Misses       5372     5363       -9     
  Partials     4569     4569              
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.23% <91.30%> (+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 Δ
...uriMath/Functions/Evaluation/Evaluation.Classes.cs 84.57% <100.00%> (+0.14%) ⬆️
...Math/Functions/Simplification/Patterns/Patterns.cs 92.30% <100.00%> (-0.20%) ⬇️
...ouriMath/Functions/Simplification/Simplificator.cs 95.96% <100.00%> (ø)
...ath/Functions/Simplification/ProductsOfMatrices.cs 95.89% <89.47%> (+2.78%) ⬆️

... 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.

…NGES entries

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Rafael-SOWNet
Rafael-SOWNet merged commit 6165a84 into master Nov 26, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Nov 26, 2026
Rafael-SOWNet added a commit that referenced this pull request Nov 26, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	BREAKING-CHANGES.md
@Rafael-SOWNet
Rafael-SOWNet deleted the transpose-beside-a-written-matrix branch November 26, 2026 15:31
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.

InnerSimplified reads transpose(A) as a number: [1, 0]T * transpose(A) * [0, 1] is 0

1 participant