Skip to content

Fix Duplicate Eigenvalues in random_diagonalizable_matrix#42170

Open
cxzhong wants to merge 1 commit into
sagemath:developfrom
cxzhong:fix/duplicate-eiegnvalues
Open

Fix Duplicate Eigenvalues in random_diagonalizable_matrix#42170
cxzhong wants to merge 1 commit into
sagemath:developfrom
cxzhong:fix/duplicate-eiegnvalues

Conversation

@cxzhong
Copy link
Copy Markdown
Contributor

@cxzhong cxzhong commented May 13, 2026

random_diagonalizable_matrix accepted parallel lists of eigenvalues and
eigenspace dimensions. When the eigenvalue list contained duplicates, the
algorithm treated each occurrence as a separate eigenspace.

For example:

eigenvalues = [-5, 4, 4]
dimensions = [2, 3, 1]

was handled as three eigenspaces, even though the two entries for eigenvalue
4 should describe one eigenspace of dimension 4.

This caused the doctest failure under the specified random seed because the
randomly generated eigenvalues included a duplicate. The shifted matrix
B - 4*I could then have a reduced row echelon form with non-integral rational
entries, violating the documented teaching-oriented property of the constructor.

Fix

The algorithm now merges repeated eigenvalues before constructing the diagonal
matrix and eigenvector matrix.

The input:

eigenvalues = [-5, 4, 4]
dimensions = [2, 3, 1]

is normalized to:

eigenvalues = [-5, 4]
dimensions = [2, 4]

This matches the mathematical interpretation of eigenspaces for a
diagonalizable matrix.

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

@github-actions
Copy link
Copy Markdown

Documentation preview for this PR (built with commit 3d87a02; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant