Skip to content

Take the norm of a vector as the root of its components' moduli squared - #2431

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
feature/the-norm-of-a-complex-vector
Nov 13, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
feature/the-norm-of-a-complex-vector

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Closes #2423.

|v| of a column vector was sqrt(sum v_k^2). That is the norm only where every component is real. A complex component gave NaN, a different number, or 0, and a symbol, which may take a complex value, was squared as though it could not. The norm is now sqrt(sum |v_k|^2):

  • a Complex number contributes re^2 + im^2, so an exact norm stays exact;
  • a component whose codomain is real, such as domain(x, RR), is squared as it is, since that is the same value;
  • anything else contributes abs(v)^2.

A row vector is now a vector too. abs([1 + i, 2]T) was taken entry by entry, [[abs(1 + i), 2]], where the column gives its norm. A general matrix is still taken entry by entry.

Absf.InnerSimplify is the only place that turns abs of a vector into a norm. Evaled and Simplify both reach it, and the LINQ compiler compiles the simplified form, so the compiled norm over Complex follows. FastExpression refuses a matrix, as before.

Expression 2.6.0 master this branch true
abs([1 + i, 2]).Evaled NaN NaN 2.449489742783178… sqrt(6)
abs([1 + i, 2]).Simplify() NaN NaN sqrt(6) sqrt(6)
abs([3 * i, 4]).Simplify() sqrt(7) sqrt(7) 5 5
abs([1 + i, 1 - i]).Simplify() 0 0 2 2
abs([x, y]).Simplify() sqrt(x^2 + y^2) same sqrt(abs(x)^2 + abs(y)^2) sqrt(|x|^2 + |y|^2)
abs([x, y]) at x = i, y = 0, evaluated / LINQ over Complex NaN / i same 1 / 1 1
abs([1 + i, 2]T).Simplify(), a row vector [[abs(1 + i), 2]] same sqrt(6) sqrt(6)
abs([3, 4]), abs([sqrt(2), -1]), LINQ over double right right unchanged

The rows are in BREAKING-CHANGES.md, measured on the 2.6.0 package.

Checked on this branch:

  • Tests: UnitTests 19382 passed, plus the MCP, Terminal, InteractiveWrapper and F# wrapper suites, and the AOT smoke test. A new test checks norms worked out by hand at real, negative and complex points, through Evaled, Simplify and LINQ over Complex and double, and components declared real.
  • Harnesses: BoundCheck, RootCheck, CasBench, PropCheck, SimpSweep, RuleCheck, CanonCheck and Confluence all pass.

🤖 Generated with Claude Code

|v| of a column vector was sqrt(sum v_k^2), the norm only where every
component is real: abs([1 + i, 2]) was NaN, abs([1 + i, 1 - i]) was 0, and
abs([x, y]) simplified to sqrt(x^2 + y^2), which is 0 at x = i, y = 0. Each
component now contributes |v_k|^2 -- re^2 + im^2 for a number, kept exact,
and v_k^2 where the node's codomain is real, which is the same value.

The LINQ compiler simplifies an expression with a matrix in it before
compiling, so the compiled norm over Complex is right with no change to the
compiler. FastExpression refuses a matrix, as before.

A row vector is a vector too: abs([1 + i, 2]T) was taken entry by entry,
[[abs(1 + i), 2]], where the column gives its norm. Both are the norm now.

Closes #2423.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.81%. Comparing base (2eea2e9) to head (faa575d).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2431      +/-   ##
==========================================
- Coverage   86.81%   86.81%   -0.01%     
==========================================
  Files         312      312              
  Lines       69551    69561      +10     
  Branches    20316    20320       +4     
==========================================
+ Hits        60383    60389       +6     
- Misses       4932     4935       +3     
- Partials     4236     4237       +1     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.35% <100.00%> (-0.01%) ⬇️
fsharp 32.97% <ø> (ø)
interactive 39.81% <ø> (ø)

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

Files with missing lines Coverage Δ
...nuous/Evaluation.Continuous.Arithmetics.Classes.cs 88.13% <100.00%> (+0.12%) ⬆️

... and 1 file 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 131c718 into master Nov 13, 2026
38 of 41 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Nov 13, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the feature/the-norm-of-a-complex-vector branch November 13, 2026 19:59
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 norm of a vector with complex entries is NaN when evaluated and wrong when simplified

1 participant