I created a symbolic matrix with sympy:
[1.0*rho00 - 1.79380389039135e-16*rho01 - 1.79380389039135e-16*rho10 + 3.21773239718314e-32*rho11
-1.79380389039135e-16*rho00 + 1.0*rho01 + 3.21773239718314e-32*rho10 - 1.79380389039135e-16*rho11
1.0*rho02 - 3.25176795283269e-17*rho03 - 1.79380389039135e-16*rho12 + 5.83303400444119e-33*rho13
-3.25176795283269e-17*rho02 + 1.0*rho03 + 5.83303400444119e-33*rho12 - 1.79380389039135e-16*rho13
1.0*rho04 + 1.01465363575695e-17*rho05 - 1.79380389039135e-16*rho14 - 1.82008963922055e-33*rho15
1.01465363575695e-17*rho04 + 1.0*rho05 - 1.82008963922055e-33*rho14 - 1.79380389039135e-16*rho15
-3.25176795283269e-17*rho06 + 1.0*rho07 + 5.83303400444119e-33*rho16 - 1.79380389039135e-16*rho17
1.0*rho06 - 3.25176795283269e-17*rho07 - 1.79380389039135e-16*rho16 + 5.83303400444119e-33*rho17]
.....
I did not paste whole result but I do not want to see e-17*rho because it is already small or really small. I want to make them 0
Ideally nsimplfy should do that but it did not change the result
btw, my real matrix is here:
[[ 1. -0. 0. 0. 0. 0. 0. 0.]
[-0. 1. 0. 0. 0. 0. 0. 0.]
[ 0. 0. 1. -0. 0. 0. 0. 0.]
[ 0. 0. -0. 1. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 1. 0. 0. 0.]
[ 0. 0. 0. 0. 0. 1. 0. 0.]
[ 0. 0. 0. 0. 0. 0. -0. 1.]
[ 0. 0. 0. 0. 0. 0. 1. -0.]]
How to do that?
states = [1,2,3,4,5,6,7,8] rho = np.array([[sympy.Symbol("rho{}{}".format(i,j)) for j in range(len(states))] for i in range(len(states))])Here is my matrix
[[rho00 rho01 rho02 rho03 rho04 rho05 rho06 rho07] [rho10 rho11 rho12 rho13 rho14 rho15 rho16 rho17] [rho20 rho21 rho22 rho23 rho24 rho25 rho26 rho27] [rho30 rho31 rho32 rho33 rho34 rho35 rho36 rho37] [rho40 rho41 rho42 rho43 rho44 rho45 rho46 rho47] [rho50 rho51 rho52 rho53 rho54 rho55 rho56 rho57] [rho60 rho61 rho62 rho63 rho64 rho65 rho66 rho67] [rho70 rho71 rho72 rho73 rho74 rho75 rho76 rho77]]Now, I am multiplying my symbolic matrix and real matrix like that;
p_final=np.matmul(realmat,rho) #print(p_final) sympy.nsimplify(p_final,tolerance=1e-10,rational=True)ALthough, I use nsimplyfy, I am getting this result which is quite annoying
[1.0*rho00 - 1.79380389039135e-16*rho01 - 1.79380389039135e-16*rho10 + 3.21773239718314e-32*rho11
-1.79380389039135e-16*rho00 + 1.0*rho01 + 3.21773239718314e-32*rho10 - 1.79380389039135e-16*rho11
1.0*rho02 - 3.25176795283269e-17*rho03 - 1.79380389039135e-16*rho12 + 5.83303400444119e-33*rho13
-3.25176795283269e-17*rho02 + 1.0*rho03 + 5.83303400444119e-33*rho12 - 1.79380389039135e-16*rho13
1.0*rho04 + 1.01465363575695e-17*rho05 - 1.79380389039135e-16*rho14 - 1.82008963922055e-33*rho15
1.01465363575695e-17*rho04 + 1.0*rho05 - 1.82008963922055e-33*rho14 - 1.79380389039135e-16*rho15
-3.25176795283269e-17*rho06 + 1.0*rho07 + 5.83303400444119e-33*rho16 - 1.79380389039135e-16*rho17
1.0*rho06 - 3.25176795283269e-17*rho07 - 1.79380389039135e-16*rho16 + 5.83303400444119e-33*rho17]
.....
I did not paste whole result but I do not want to see e-17*rho because it is already small or really small. I want to make them 0
Ideally nsimplfy should do that but it did not change the result
btw, my real matrix is here:
[[ 1. -0. 0. 0. 0. 0. 0. 0.]
[-0. 1. 0. 0. 0. 0. 0. 0.]
[ 0. 0. 1. -0. 0. 0. 0. 0.]
[ 0. 0. -0. 1. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 1. 0. 0. 0.]
[ 0. 0. 0. 0. 0. 1. 0. 0.]
[ 0. 0. 0. 0. 0. 0. -0. 1.]
[ 0. 0. 0. 0. 0. 0. 1. -0.]]
How to do that?