Skip to content

saloon: relax eig symmetry/Hermitian asserts to a tolerance#53

Merged
sigilante merged 1 commit into
mainfrom
sigilante/eig-assert-tol
Jun 8, 2026
Merged

saloon: relax eig symmetry/Hermitian asserts to a tolerance#53
sigilante merged 1 commit into
mainfrom
sigilante/eig-assert-tol

Conversation

@sigilante

Copy link
Copy Markdown
Collaborator

P0 fix (Gnome/Angel review)

eig asserted exact symmetry (=) on its input, crashing on two classes of legitimately symmetric matrices:

  1. A Gram matrix MᵀM from Lagoon mmul — symmetric only up to ULP, since [i,j] and [j,i] accumulate in different orders. The obvious way to produce a symmetric matrix tripped the assert.
  2. Under %d/%u rounding, cconj does 0 − Im and IEEE gives 0 − 0 = −0, so conj(a+0i) ≠ a+0i bit-exactly → the Hermitian diagonal check crashed on essentially any Hermitian matrix.

Fix: replace exact = with a relative-tolerance, magnitude-based check (+stol/+near/+cnear): accept inputs symmetric/Hermitian within ~stol, still reject genuinely asymmetric ones (entries differing by O(1)) so they can't silently get the wrong algorithm (that's Phase B's job). Magnitude-based ⇒ ±0.0 conjugate-pair sign differences pass automatically.

Also folds in the agreed P1 doccord surfacing on +eig: rtol must match the component width; the bare-sa default rtol=0x1 is a denormal that always trips the 60-sweep cap + ~& warning (so call +sake); and the result is returned, not silently wrong. Fixes the stray "(skew-)symmetry" wording.

Tests

saloon-eig-tol: near-symmetric (1 ULP off) accepted → eigenvalues {1,3}; clearly asymmetric ([[2,1],[2,2]]) crashes (expect-fail). The 18 symmetric + 5 Hermitian eig regressions stay green.

Note: touches the saloon %linalg helper region, so it'll conflict with the open @ch/@cq PR #50 — whichever merges second rebases.

🤖 Generated with Claude Code

eig asserted EXACT symmetry (=) on the input, which crashed on two classes of
legitimately-(skew-)symmetric matrices the review found:
  - a Gram matrix M^T*M straight out of Lagoon mmul, symmetric only up to ULP
    because [i,j] and [j,i] accumulate in different orders;
  - under %d/%u rounding, conj(a+0i) = a + (-0.0) (IEEE 0-0=-0), so the
    Hermitian diagonal check failed bit-exactly on essentially any matrix.

Replace the exact check with a relative-tolerance, magnitude-based one
(+stol/+near/+cnear): accept inputs symmetric/Hermitian within ~stol, reject
genuinely asymmetric ones (entries differing by O(1)) so they still can't
silently get the wrong algorithm.  Being magnitude-based, +-0.0 conjugate-pair
sign differences pass automatically.

Also surfaces the P1 caller hazards in the +eig doccord: rtol must match the
component width; the bare `sa` default rtol=0x1 is a denormal (always trips the
60-sweep cap + ~& warning) so callers must use +sake; and fixes the stray
"(skew-)symmetry" wording.

New saloon-eig-tol: near-symmetric (1 ULP) accepted -> eigenvalues {1,3};
clearly asymmetric crashes (expect-fail).  18 symmetric + 5 Hermitian
regressions still green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sigilante sigilante merged commit f764eb3 into main Jun 8, 2026
@sigilante sigilante deleted the sigilante/eig-assert-tol branch June 8, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant