from sympy import *
import waveorder as wo
# input electric field
E_0x, E_0y, E_0z = symbols('E_0x, E_0y, E_0z')
# scattering potential tensor component
f_0, f_1c, f_1s, f_2c, f_2s, f_3 = symbols('f_0, f_1c, f_1s, f_2c, f_2s, f_3')
# Green's tensor
G_xx, G_xy, G_xz, G_yx, G_yy, G_yz, G_zx, G_zy, G_zz = symbols('G_xx, G_xy, G_xz, G_yx, G_yy, G_yz, G_zx, G_zy, G_zz')
# input electric field (matrix)
E_0 = Matrix([[E_0x],[E_0y],[E_0z]])
# scattering potential tensor component (matrix)
f_scat = Matrix([[f_0 + f_1c, f_1s, f_2c],[f_1s, f_0-f_1c, f_2s],[f_2c, f_2s, f_0+f_3]])
# Green's tensor (matrix)
G_tensor = Matrix([[G_xx, G_xy, G_xz],[G_yx, G_yy, G_yz],[G_zx, G_zy, G_zz]])
E_out = E_0 + G_tensor*f_scat*E_0
factor(E_out)
E_out[0]
S0 = (E_out[0]-E_0x)*conjugate(E_0x) + E_0x*conjugate(E_out[0]-E_0x) + (E_out[1]-E_0y)*conjugate(E_0y) + E_0y*conjugate(E_out[1]-E_0y)
collect(expand(S0), [f_0, f_1c, f_1s, f_2c, f_2s, f_3,
conjugate(f_0),conjugate(f_1c),conjugate(f_1s),conjugate(f_2c),conjugate(f_2s),conjugate(f_3)])
S1 = (E_out[0]-E_0x)*conjugate(E_0x) + E_0x*conjugate(E_out[0]-E_0x) - (E_out[1]-E_0y)*conjugate(E_0y) - E_0y*conjugate(E_out[1]-E_0y)
collect(expand(S1), [f_0, f_1c, f_1s, f_2c, f_2s, f_3,
conjugate(f_0),conjugate(f_1c),conjugate(f_1s),conjugate(f_2c),conjugate(f_2s),conjugate(f_3)])
S2 = (E_out[0]-E_0x)*conjugate(E_0y) + E_0x*conjugate(E_out[1]-E_0y) + (E_out[1]-E_0y)*conjugate(E_0x) + E_0y*conjugate(E_out[0]-E_0x)
collect(expand(S2), [f_0, f_1c, f_1s, f_2c, f_2s, f_3,
conjugate(f_0),conjugate(f_1c),conjugate(f_1s),conjugate(f_2c),conjugate(f_2s),conjugate(f_3)])