Ask Your Question

Revision history [back]

Simplify a matrix with symbolic variables

Hello,

I've tried the following code in SageMath, but I don't succeed in getting a simplified expression (even using the method simplify_full() :

var('w_2, w_3, w_4', domain='complex')
a_2=sqrt(1-norm(w_2))*sqrt(1-norm(w_3))
a_3=sqrt(1-norm(w_3))*sqrt(1-norm(w_4))
b_2=-conjugate(w_3)*sqrt(1-norm(w_2))*sqrt(1-norm(w_4))
C=Matrix([[0, w_2, a_2, b_2], [0,0,w_3,a_3], [0,0,0,w_4], [0,0,0,0]])
Id=matrix.identity(4)
T=Id-C*(C.H)
T.simplify_full()

I get the "awfull" outcome

[-sqrt(-w_2*conjugate(w_2) + 1)*sqrt(-w_4*conjugate(w_4) + 1)*w_3*conjugate(sqrt(-w_2*conjugate(w_2) + 1))*conjugate(sqrt(-w_4*conjugate(w_4) + 1))*conjugate(w_3) - sqrt(-w_2*conjugate(w_2) + 1)*sqrt(-w_3*conjugate(w_3) + 1)*conjugate(sqrt(-w_2*conjugate(w_2) + 1))*conjugate(sqrt(-w_3*conjugate(w_3) + 1)) - w_2*conjugate(w_2) + 1                                                                                                  sqrt(-w_2*conjugate(w_2) + 1)*sqrt(-w_4*conjugate(w_4) + 1)*conjugate(sqrt(-w_3*conjugate(w_3) + 1))*conjugate(sqrt(-w_4*conjugate(w_4) + 1))*conjugate(w_3) - sqrt(-w_2*conjugate(w_2) + 1)*sqrt(-w_3*conjugate(w_3) + 1)*conjugate(w_3)                                                                                                                                                                                                                                                  sqrt(-w_2*conjugate(w_2) + 1)*sqrt(-w_4*conjugate(w_4) + 1)*conjugate(w_3)*conjugate(w_4)                                                                                                                                                                                                                                                                                                                                          0]
[                                                                                                 sqrt(-w_3*conjugate(w_3) + 1)*sqrt(-w_4*conjugate(w_4) + 1)*w_3*conjugate(sqrt(-w_2*conjugate(w_2) + 1))*conjugate(sqrt(-w_4*conjugate(w_4) + 1)) - w_3*conjugate(sqrt(-w_2*conjugate(w_2) + 1))*conjugate(sqrt(-w_3*conjugate(w_3) + 1))                                                                                                                                                                    -sqrt(-w_3*conjugate(w_3) + 1)*sqrt(-w_4*conjugate(w_4) + 1)*conjugate(sqrt(-w_3*conjugate(w_3) + 1))*conjugate(sqrt(-w_4*conjugate(w_4) + 1)) - w_3*conjugate(w_3) + 1                                                                                                                                                                                                                                                                -sqrt(-w_3*conjugate(w_3) + 1)*sqrt(-w_4*conjugate(w_4) + 1)*conjugate(w_4)                                                                                                                                                                                                                                                                                                                                          0]

[                                                                                                                                                                                                                                                 w_3*w_4*conjugate(sqrt(-w_2*conjugate(w_2) + 1))*conjugate(sqrt(-w_4*conjugate(w_4) + 1))                                                                                                                                                                                                                                                     -w_4*conjugate(sqrt(-w_3*conjugate(w_3) + 1))*conjugate(sqrt(-w_4*conjugate(w_4) + 1))                                                                                                                                                                                                                                                                                                                    -w_4*conjugate(w_4) + 1                                                                                                                                                                                                                                                                                                                                          0]
[                                                                                                                                                                                                                                                                                                                                         0                                                                                                                                                                                                                                                                                                                                          0                                                                                                                                                                                                                                                                                                                                          0                                                                                                                                                                                                                                                                                                                                      1]

whereas when we compute this "by hand", we can show that

T= [[norm(w_3*w_4)*(1-norm(w_2)), -conjugate(w_3)*sqrt(1-norm(w_2))*sqrt(1-norm(w_3))*norm(w_4), conjugate(w_3*w_4)*sqrt(1-norm(w_2))*sqrt(1-norm(w_4))],
     [-w_3*sqrt(1-norm(w_2))*sqrt(1-norm(w_3))*norm(w_4), norm(w_4)*(1-norm(w_3)), -conjugate(w_4)*sqrt(1-norm(w_3))*sqrt(1-norm(w_4))],
     [w_3*w_4*sqrt(1-norm(w_2))*sqrt(1-norm(w_4)), -w_4*sqrt(1-norm(w_3))*sqrt(1-norm(w_4)), 1-norm(w_4)]]

Thus, when I want to diagonalize T using the T.eigenvalues() and T.eigenvectors_right(), I get something really complicated... whereas we can show "by hand" that the eigenvalues are just 0 and 1-norm(w_2*w_3*w_4)...

How could we manage to get those simple expressions with Sage Math ?

Thanks in advance for your help !

Simplify a matrix with symbolic variables

Hello,

I've tried the following code in SageMath, but I don't succeed in getting a simplified expression (even using the method simplify_full().simplify_full() ) :

var('w_2, w_3, w_4', domain='complex')
a_2=sqrt(1-norm(w_2))*sqrt(1-norm(w_3))
a_3=sqrt(1-norm(w_3))*sqrt(1-norm(w_4))
b_2=-conjugate(w_3)*sqrt(1-norm(w_2))*sqrt(1-norm(w_4))
C=Matrix([[0, w_2, a_2, b_2], [0,0,w_3,a_3], [0,0,0,w_4], [0,0,0,0]])
Id=matrix.identity(4)
T=Id-C*(C.H)
T.simplify_full()

I get the "awfull" outcome

[-sqrt(-w_2*conjugate(w_2) + 1)*sqrt(-w_4*conjugate(w_4) + 1)*w_3*conjugate(sqrt(-w_2*conjugate(w_2) + 1))*conjugate(sqrt(-w_4*conjugate(w_4) + 1))*conjugate(w_3) - sqrt(-w_2*conjugate(w_2) + 1)*sqrt(-w_3*conjugate(w_3) + 1)*conjugate(sqrt(-w_2*conjugate(w_2) + 1))*conjugate(sqrt(-w_3*conjugate(w_3) + 1)) - w_2*conjugate(w_2) + 1                                                                                                  sqrt(-w_2*conjugate(w_2) + 1)*sqrt(-w_4*conjugate(w_4) + 1)*conjugate(sqrt(-w_3*conjugate(w_3) + 1))*conjugate(sqrt(-w_4*conjugate(w_4) + 1))*conjugate(w_3) - sqrt(-w_2*conjugate(w_2) + 1)*sqrt(-w_3*conjugate(w_3) + 1)*conjugate(w_3)                                                                                                                                                                                                                                                  sqrt(-w_2*conjugate(w_2) + 1)*sqrt(-w_4*conjugate(w_4) + 1)*conjugate(w_3)*conjugate(w_4)                                                                                                                                                                                                                                                                                                                                          0]
[                                                                                                 sqrt(-w_3*conjugate(w_3) + 1)*sqrt(-w_4*conjugate(w_4) + 1)*w_3*conjugate(sqrt(-w_2*conjugate(w_2) + 1))*conjugate(sqrt(-w_4*conjugate(w_4) + 1)) - w_3*conjugate(sqrt(-w_2*conjugate(w_2) + 1))*conjugate(sqrt(-w_3*conjugate(w_3) + 1))                                                                                                                                                                    -sqrt(-w_3*conjugate(w_3) + 1)*sqrt(-w_4*conjugate(w_4) + 1)*conjugate(sqrt(-w_3*conjugate(w_3) + 1))*conjugate(sqrt(-w_4*conjugate(w_4) + 1)) - w_3*conjugate(w_3) + 1                                                                                                                                                                                                                                                                -sqrt(-w_3*conjugate(w_3) + 1)*sqrt(-w_4*conjugate(w_4) + 1)*conjugate(w_4)                                                                                                                                                                                                                                                                                                                                          0]

[                                                                                                                                                                                                                                                 w_3*w_4*conjugate(sqrt(-w_2*conjugate(w_2) + 1))*conjugate(sqrt(-w_4*conjugate(w_4) + 1))                                                                                                                                                                                                                                                     -w_4*conjugate(sqrt(-w_3*conjugate(w_3) + 1))*conjugate(sqrt(-w_4*conjugate(w_4) + 1))                                                                                                                                                                                                                                                                                                                    -w_4*conjugate(w_4) + 1                                                                                                                                                                                                                                                                                                                                          0]
[                                                                                                                                                                                                                                                                                                                                         0                                                                                                                                                                                                                                                                                                                                          0                                                                                                                                                                                                                                                                                                                                          0                                                                                                                                                                                                                                                                                                                                      1]

whereas when we compute this "by hand", we can show that

T= [[norm(w_3*w_4)*(1-norm(w_2)), -conjugate(w_3)*sqrt(1-norm(w_2))*sqrt(1-norm(w_3))*norm(w_4), conjugate(w_3*w_4)*sqrt(1-norm(w_2))*sqrt(1-norm(w_4))],
     [-w_3*sqrt(1-norm(w_2))*sqrt(1-norm(w_3))*norm(w_4), norm(w_4)*(1-norm(w_3)), -conjugate(w_4)*sqrt(1-norm(w_3))*sqrt(1-norm(w_4))],
     [w_3*w_4*sqrt(1-norm(w_2))*sqrt(1-norm(w_4)), -w_4*sqrt(1-norm(w_3))*sqrt(1-norm(w_4)), 1-norm(w_4)]]

Thus, when I want to diagonalize T using the T.eigenvalues() and T.eigenvectors_right(), I get something really complicated... whereas we can show "by hand" that the eigenvalues are just 0 and 1-norm(w_2*w_3*w_4)...

How could we manage to get those simple expressions with Sage Math ?

Thanks in advance for your help !