Processing math: 100%
Ask Your Question
0

Simplify a matrix with symbolic variables

asked 1 year ago

endomorphisme59 gravatar image

updated 1 year ago

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 !

Preview: (hide)

Comments

I fail to understant how a 4×4 matrix can be equal to a 3×3 matrix...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 1 year ago )

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

endomorphisme59 gravatar imageendomorphisme59 ( 1 year ago )

1 Answer

Sort by » oldest newest most voted
0

answered 1 year ago

Max Alekseyev gravatar image

updated 1 year ago

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.

Preview: (hide)
link

Comments

Thank you !

endomorphisme59 gravatar imageendomorphisme59 ( 1 year ago )

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: 1 year ago

Seen: 247 times

Last updated: Oct 24 '23