Repository navigation
Take the norm of a vector as the root of its components' moduli squared - #2431
Merged
Merged
Conversation
|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 Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2423.
|v|of a column vector wassqrt(sum v_k^2). That is the norm only where every component is real. A complex component gaveNaN, a different number, or 0, and a symbol, which may take a complex value, was squared as though it could not. The norm is nowsqrt(sum |v_k|^2):Complexnumber contributesre^2 + im^2, so an exact norm stays exact;domain(x, RR), is squared as it is, since that is the same value;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.InnerSimplifyis the only place that turns abs of a vector into a norm.EvaledandSimplifyboth reach it, and the LINQ compiler compiles the simplified form, so the compiled norm overComplexfollows. FastExpression refuses a matrix, as before.abs([1 + i, 2]).EvaledNaNNaN2.449489742783178…sqrt(6)abs([1 + i, 2]).Simplify()NaNNaNsqrt(6)sqrt(6)abs([3 * i, 4]).Simplify()sqrt(7)sqrt(7)55abs([1 + i, 1 - i]).Simplify()0022abs([x, y]).Simplify()sqrt(x^2 + y^2)sqrt(abs(x)^2 + abs(y)^2)sqrt(|x|^2 + |y|^2)abs([x, y])atx = i, y = 0, evaluated / LINQ overComplexNaN/i1/11abs([1 + i, 2]T).Simplify(), a row vector[[abs(1 + i), 2]]sqrt(6)sqrt(6)abs([3, 4]),abs([sqrt(2), -1]), LINQ overdoubleThe rows are in BREAKING-CHANGES.md, measured on the 2.6.0 package.
Checked on this branch:
Evaled,Simplifyand LINQ overComplexanddouble, and components declared real.🤖 Generated with Claude Code