Exemple #1
0
def run_eighe(A, verbose=False):
    if verbose:
        print("original matrix:\n", str(A))

    D, Q = mp.eighe(A)
    B = Q * mp.diag(D) * Q.transpose_conj()
    C = A - B
    E = Q * Q.transpose_conj() - mp.eye(A.rows)

    if verbose:
        print("eigenvalues:\n", D)
        print("eigenvectors:\n", Q)

    NC = mp.mnorm(C)
    NE = mp.mnorm(E)

    if verbose:
        print("difference:", NC, "\n", C, "\n")
        print("difference:", NE, "\n", E, "\n")

    eps = mp.exp(0.8 * mp.log(mp.eps))

    assert NC < eps
    assert NE < eps

    return NC
def run_eighe(A, verbose = False):
    if verbose:
        print("original matrix:\n", str(A))

    D, Q = mp.eighe(A)
    B = Q * mp.diag(D) * Q.transpose_conj()
    C = A - B
    E = Q * Q.transpose_conj() - mp.eye(A.rows)

    if verbose:
        print("eigenvalues:\n", D)
        print("eigenvectors:\n", Q)

    NC = mp.mnorm(C)
    NE = mp.mnorm(E)

    if verbose:
        print("difference:", NC, "\n", C, "\n")
        print("difference:", NE, "\n", E, "\n")

    eps = mp.exp( 0.8 * mp.log(mp.eps))

    assert NC < eps
    assert NE < eps

    return NC
Exemple #3
0
def conjugator_into_SL2R(SL2C_matrices):
    """
    Returns a matrix C in SL(2, C) so that C^-1 * M * C is
    (essentially) in SL(2, R) for all the input matrices M.
    """
    ans, sig, form = preserves_hermitian_form(SL2C_matrices)
    if ans is None:
        raise ValueError('No invariant hermitian form found')
    if sig == 'definite':
        raise ValueError('Conjugate into SU(2), not SL(2, R)')
    if sig == 'both':
        raise ValueError('This degnerate case not implemented')
    assert sig == 'indefinite'
    J = sage_matrix_to_mpmath(form)
    eigs, U = mp.eighe(J)
    C = U * mp.diag([1 / mp.sqrt(abs(e)) for e in eigs])
    sq_two = mp.sqrt(2)
    sq_two_i = mp.mpc(imag=sq_two)
    S = mp.matrix([[1 / sq_two_i, 1 / sq_two_i], [-1 / sq_two, 1 / sq_two]])
    C = C * S.H
    C = (1 / mp.sqrt(mp.det(C))) * C
    return mpmath_matrix_to_sage(C)