Ask Your Question
0

Simplify a matrix with symbolic variables

asked 2023-10-19 16:27:00 +0100

endomorphisme59 gravatar image

updated 2023-10-19 16:27:33 +0100

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 !

edit retag flag offensive close merge delete

Comments

I fail to understant how a $4\times 4$ matrix can be equal to a $3\times 3$ matrix...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2023-10-20 08:16:47 +0100 )edit

Of course... I've forgotten the last row (but this row is quite trivial...).

endomorphisme59 gravatar imageendomorphisme59 ( 2023-10-25 14:59:47 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-10-24 18:23:11 +0100

Max Alekseyev gravatar image

updated 2023-10-24 18:31:48 +0100

This issue is not really about matrices but about how Sage not being able to figure out that sqrt() here are real numbers that are invariant with respect to conjugate(). It may be possible to help Sage understand this with a set of assumptions, but I do not know how to do so (I've tried assume(norm(w_2) < 1) and alike, but it did not help).

Below I present an alternative solution, using the following function that manually looks for patterns conjugate(sqrt(...)) in a given expression, replaces them with just sqrt(...), and simplifies the result:

def simplify_conjugate_of_sqrt(f):
    x = SR.wild(0)
    return f.subs({conjugate(sqrt(x)):sqrt(x)}).full_simplify()

It amounts only to replacing T.simplify_full() in OP's code with T.apply_map(simplify_conjugate_of_sqrt) to get a much simpler matrix:

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

Basically it matches the OP's expected matrix, with just each norm(z) replaced with z * conjugate(z), but this is how Sage handles the norm(z) function.

edit flag offensive delete link more

Comments

Thank you !

endomorphisme59 gravatar imageendomorphisme59 ( 2023-10-25 15:00:26 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-10-19 16:27:00 +0100

Seen: 179 times

Last updated: Oct 24 '23