import sympy as sp
import numpy as np
from IPython.display import display, Math, HTML
delta, J, g = sp.symbols('delta J g')
A_1 = sp.Matrix([[J, 0, 0, g],
[0, J, 0, g],
[0, 0, J, g],
[g, g, g, 0]])
eigVals = A_1.eigenvals()
eigVecs = A_1.eigenvects()
P = sp.Matrix.hstack(*[vec for eig in eigVecs for vec in eig[2]])
display(Math(sp.latex(P)))
rows, cols = P.shape
# normalized transformation
normalized_columns = []
for i in range(cols):
col_new = P[:, i] / sp.sqrt(P[:, i].dot(P[:, i]))
# print(col_new)
normalized_columns.append(col_new)
P_norm = sp.Matrix.hstack(*normalized_columns)
display(Math(sp.latex(P_norm)))
A_1_val = A_1.subs({J: 66.14, g: 20 * np.sqrt(2)})
U_chk = P_norm.subs({J: 66.14, g: 20 * np.sqrt(2)})
res_mat = U_chk.transpose() @ A_1_val @ U_chk
display(Math(sp.latex(res_mat)))