Skip to content

test failure in matrix/special.py #37426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 tasks done
collares opened this issue Feb 22, 2024 · 3 comments
Open
2 tasks done

test failure in matrix/special.py #37426

collares opened this issue Feb 22, 2024 · 3 comments

Comments

@collares
Copy link
Contributor

collares commented Feb 22, 2024

Steps To Reproduce

sage -t --long --random-seed=214483688537001353062577859282581597229 /nix/store/0yv879ir56m3zyd95hdfw0yr4vznrk75-sage-src-10.2/src/sage/matrix/special.py
**********************************************************************
File "/nix/store/0yv879ir56m3zyd95hdfw0yr4vznrk75-sage-src-10.2/src/sage/matrix/special.py", line 3107, in sage.matrix.special.random_diagonalizable_matrix
Failed example:
    all(x in ZZ for x in (B-(6*identity_matrix(6))).rref().list())
Expected:
    True
Got:
    False

Environment

- **OS**: Linux (NixOS 23.11)
- **Sage Version**: 10.2

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide
@fchapoton
Copy link
Contributor

Here is the problematic matrix, as a reproducible failing test:

B = matrix(QQ, [[-12, -36, 12, 24, -84, 108], [18, -12, 18, 0, 72, 36], [18, 0, -6, -24, 12, 0], [-18, -24, 12, 30, -60, 72], [0, 6, 0, 0, 18, -18], [6, 0, 6, 0, 36, 0]])
[x for x in (B-(6*identity_matrix(6))).rref().list() if x not in ZZ]

@tornaria
Copy link
Contributor

tornaria commented Apr 2, 2024

A simpler reproducer that may shed some more light:

sage: set_random_seed(42)
sage: B = sage.matrix.special.random_diagonalizable_matrix(MatrixSpace(QQ,4),eigenvalues=[0,0,1],dimensions=[1,1,2])
sage: B.rref()
[   1    0  2/3  1/3]
[   0    1 -5/3 -4/3]
[   0    0    0    0]
[   0    0    0    0]

The doctest claims that all those should be integers. This fails not always but quite often (in the doctest, the three eigenvalues are taken at random, and we only loose when there are two eigenvalues that are both 4, both 6, or both -12, that's much less likely to happen).

@tornaria
Copy link
Contributor

tornaria commented Apr 3, 2024

Original test (92837ca):

        sage: B=random_matrix(QQ, 6, algorithm='diagonalizable', eigenvalues=[-12,4,6],dimensions=[2,3,1]); B # random
        [ -52   32  240 -464  -96 -520]
        [   6    4  -48   72   36   90]
        [  46  -32 -108  296  -12  274]
        [  24  -16  -64  164    0  152]
        [  18  -16    0   72  -48   30]
        [   2    0  -16   24   12   34]
        sage: all([x in ZZ for x in (B-(-12*identity_matrix(6))).rref().list()])
        True
        sage: all([x in ZZ for x in (B-(4*identity_matrix(6))).rref().list()])
        True
        sage: all([x in ZZ for x in (B-(6*identity_matrix(6))).rref().list()])
        True
        sage: S=B.right_eigenmatrix()[1]; S_inverse=S.inverse(); S_inverse*B*S # random
        [  6   0   0   0   0   0]
        [  0 -12   0   0   0   0]
        [  0   0 -12   0   0   0]
        [  0   0   0   4   0   0]
        [  0   0   0   0   4   0]
        [  0   0   0   0   0   4]

Current test (c1c315c)

        sage: eigenvalues = [ZZ.random_element() for _ in range(3)]
        sage: B = random_matrix(QQ, 6, algorithm='diagonalizable',
        ....:                   eigenvalues=eigenvalues, dimensions=[2,3,1])
        sage: all(x in ZZ for x in (B-(-12*identity_matrix(6))).rref().list())
        True
        sage: all(x in ZZ for x in (B-(4*identity_matrix(6))).rref().list())
        True
        sage: all(x in ZZ for x in (B-(6*identity_matrix(6))).rref().list())
        True

I'm not sure this makes sense since the .rref() will be the identity most of the time. We really want to subtract the eigenvalues here, don't we?

Still there seems to be a bug when the eigenvalues argument has repeated values. Either it should raise a value error, or return a matrix which has integral rref.

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

No branches or pull requests

4 participants