In [26]:
from sympy import *

import waveorder as wo
In [2]:
# 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')
In [18]:
# 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]])
In [20]:
E_out = E_0 + G_tensor*f_scat*E_0
In [22]:
factor(E_out)
Out[22]:
$\displaystyle \left[\begin{matrix}E_{0x} \left(G_{xx} f_{0} + G_{xx} f_{1c} + G_{xy} f_{1s} + G_{xz} f_{2c}\right) + E_{0x} + E_{0y} \left(G_{xx} f_{1s} + G_{xy} f_{0} - G_{xy} f_{1c} + G_{xz} f_{2s}\right) + E_{0z} \left(G_{xx} f_{2c} + G_{xy} f_{2s} + G_{xz} f_{0} + G_{xz} f_{3}\right)\\E_{0x} \left(G_{yx} f_{0} + G_{yx} f_{1c} + G_{yy} f_{1s} + G_{yz} f_{2c}\right) + E_{0y} \left(G_{yx} f_{1s} + G_{yy} f_{0} - G_{yy} f_{1c} + G_{yz} f_{2s}\right) + E_{0y} + E_{0z} \left(G_{yx} f_{2c} + G_{yy} f_{2s} + G_{yz} f_{0} + G_{yz} f_{3}\right)\\E_{0x} \left(G_{zx} f_{0} + G_{zx} f_{1c} + G_{zy} f_{1s} + G_{zz} f_{2c}\right) + E_{0y} \left(G_{zx} f_{1s} + G_{zy} f_{0} - G_{zy} f_{1c} + G_{zz} f_{2s}\right) + E_{0z} \left(G_{zx} f_{2c} + G_{zy} f_{2s} + G_{zz} f_{0} + G_{zz} f_{3}\right) + E_{0z}\end{matrix}\right]$
In [25]:
E_out[0]
Out[25]:
$\displaystyle E_{0x} \left(G_{xx} \left(f_{0} + f_{1c}\right) + G_{xy} f_{1s} + G_{xz} f_{2c}\right) + E_{0x} + E_{0y} \left(G_{xx} f_{1s} + G_{xy} \left(f_{0} - f_{1c}\right) + G_{xz} f_{2s}\right) + E_{0z} \left(G_{xx} f_{2c} + G_{xy} f_{2s} + G_{xz} \left(f_{0} + f_{3}\right)\right)$
In [57]:
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)
In [60]:
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)])
Out[60]:
$\displaystyle f_{0} \left(E_{0x} G_{xx} \overline{E_{0x}} + E_{0x} G_{yx} \overline{E_{0y}} + E_{0y} G_{xy} \overline{E_{0x}} + E_{0y} G_{yy} \overline{E_{0y}} + E_{0z} G_{xz} \overline{E_{0x}} + E_{0z} G_{yz} \overline{E_{0y}}\right) + f_{1c} \left(E_{0x} G_{xx} \overline{E_{0x}} + E_{0x} G_{yx} \overline{E_{0y}} - E_{0y} G_{xy} \overline{E_{0x}} - E_{0y} G_{yy} \overline{E_{0y}}\right) + f_{1s} \left(E_{0x} G_{xy} \overline{E_{0x}} + E_{0x} G_{yy} \overline{E_{0y}} + E_{0y} G_{xx} \overline{E_{0x}} + E_{0y} G_{yx} \overline{E_{0y}}\right) + f_{2c} \left(E_{0x} G_{xz} \overline{E_{0x}} + E_{0x} G_{yz} \overline{E_{0y}} + E_{0z} G_{xx} \overline{E_{0x}} + E_{0z} G_{yx} \overline{E_{0y}}\right) + f_{2s} \left(E_{0y} G_{xz} \overline{E_{0x}} + E_{0y} G_{yz} \overline{E_{0y}} + E_{0z} G_{xy} \overline{E_{0x}} + E_{0z} G_{yy} \overline{E_{0y}}\right) + f_{3} \left(E_{0z} G_{xz} \overline{E_{0x}} + E_{0z} G_{yz} \overline{E_{0y}}\right) + \left(E_{0x} \overline{E_{0z}} \overline{G_{xz}} + E_{0y} \overline{E_{0z}} \overline{G_{yz}}\right) \overline{f_{3}} + \left(E_{0x} \overline{E_{0x}} \overline{G_{xx}} - E_{0x} \overline{E_{0y}} \overline{G_{xy}} + E_{0y} \overline{E_{0x}} \overline{G_{yx}} - E_{0y} \overline{E_{0y}} \overline{G_{yy}}\right) \overline{f_{1c}} + \left(E_{0x} \overline{E_{0x}} \overline{G_{xy}} + E_{0x} \overline{E_{0y}} \overline{G_{xx}} + E_{0y} \overline{E_{0x}} \overline{G_{yy}} + E_{0y} \overline{E_{0y}} \overline{G_{yx}}\right) \overline{f_{1s}} + \left(E_{0x} \overline{E_{0x}} \overline{G_{xz}} + E_{0x} \overline{E_{0z}} \overline{G_{xx}} + E_{0y} \overline{E_{0x}} \overline{G_{yz}} + E_{0y} \overline{E_{0z}} \overline{G_{yx}}\right) \overline{f_{2c}} + \left(E_{0x} \overline{E_{0y}} \overline{G_{xz}} + E_{0x} \overline{E_{0z}} \overline{G_{xy}} + E_{0y} \overline{E_{0y}} \overline{G_{yz}} + E_{0y} \overline{E_{0z}} \overline{G_{yy}}\right) \overline{f_{2s}} + \left(E_{0x} \overline{E_{0x}} \overline{G_{xx}} + E_{0x} \overline{E_{0y}} \overline{G_{xy}} + E_{0x} \overline{E_{0z}} \overline{G_{xz}} + E_{0y} \overline{E_{0x}} \overline{G_{yx}} + E_{0y} \overline{E_{0y}} \overline{G_{yy}} + E_{0y} \overline{E_{0z}} \overline{G_{yz}}\right) \overline{f_{0}}$
In [62]:
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)
In [63]:
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)])
Out[63]:
$\displaystyle f_{0} \left(E_{0x} G_{xx} \overline{E_{0x}} - E_{0x} G_{yx} \overline{E_{0y}} + E_{0y} G_{xy} \overline{E_{0x}} - E_{0y} G_{yy} \overline{E_{0y}} + E_{0z} G_{xz} \overline{E_{0x}} - E_{0z} G_{yz} \overline{E_{0y}}\right) + f_{1c} \left(E_{0x} G_{xx} \overline{E_{0x}} - E_{0x} G_{yx} \overline{E_{0y}} - E_{0y} G_{xy} \overline{E_{0x}} + E_{0y} G_{yy} \overline{E_{0y}}\right) + f_{1s} \left(E_{0x} G_{xy} \overline{E_{0x}} - E_{0x} G_{yy} \overline{E_{0y}} + E_{0y} G_{xx} \overline{E_{0x}} - E_{0y} G_{yx} \overline{E_{0y}}\right) + f_{2c} \left(E_{0x} G_{xz} \overline{E_{0x}} - E_{0x} G_{yz} \overline{E_{0y}} + E_{0z} G_{xx} \overline{E_{0x}} - E_{0z} G_{yx} \overline{E_{0y}}\right) + f_{2s} \left(E_{0y} G_{xz} \overline{E_{0x}} - E_{0y} G_{yz} \overline{E_{0y}} + E_{0z} G_{xy} \overline{E_{0x}} - E_{0z} G_{yy} \overline{E_{0y}}\right) + f_{3} \left(E_{0z} G_{xz} \overline{E_{0x}} - E_{0z} G_{yz} \overline{E_{0y}}\right) + \left(E_{0x} \overline{E_{0z}} \overline{G_{xz}} - E_{0y} \overline{E_{0z}} \overline{G_{yz}}\right) \overline{f_{3}} + \left(E_{0x} \overline{E_{0x}} \overline{G_{xx}} - E_{0x} \overline{E_{0y}} \overline{G_{xy}} - E_{0y} \overline{E_{0x}} \overline{G_{yx}} + E_{0y} \overline{E_{0y}} \overline{G_{yy}}\right) \overline{f_{1c}} + \left(E_{0x} \overline{E_{0x}} \overline{G_{xy}} + E_{0x} \overline{E_{0y}} \overline{G_{xx}} - E_{0y} \overline{E_{0x}} \overline{G_{yy}} - E_{0y} \overline{E_{0y}} \overline{G_{yx}}\right) \overline{f_{1s}} + \left(E_{0x} \overline{E_{0x}} \overline{G_{xz}} + E_{0x} \overline{E_{0z}} \overline{G_{xx}} - E_{0y} \overline{E_{0x}} \overline{G_{yz}} - E_{0y} \overline{E_{0z}} \overline{G_{yx}}\right) \overline{f_{2c}} + \left(E_{0x} \overline{E_{0y}} \overline{G_{xz}} + E_{0x} \overline{E_{0z}} \overline{G_{xy}} - E_{0y} \overline{E_{0y}} \overline{G_{yz}} - E_{0y} \overline{E_{0z}} \overline{G_{yy}}\right) \overline{f_{2s}} + \left(E_{0x} \overline{E_{0x}} \overline{G_{xx}} + E_{0x} \overline{E_{0y}} \overline{G_{xy}} + E_{0x} \overline{E_{0z}} \overline{G_{xz}} - E_{0y} \overline{E_{0x}} \overline{G_{yx}} - E_{0y} \overline{E_{0y}} \overline{G_{yy}} - E_{0y} \overline{E_{0z}} \overline{G_{yz}}\right) \overline{f_{0}}$
In [64]:
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)
In [65]:
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)])
Out[65]:
$\displaystyle f_{0} \left(E_{0x} G_{xx} \overline{E_{0y}} + E_{0x} G_{yx} \overline{E_{0x}} + E_{0y} G_{xy} \overline{E_{0y}} + E_{0y} G_{yy} \overline{E_{0x}} + E_{0z} G_{xz} \overline{E_{0y}} + E_{0z} G_{yz} \overline{E_{0x}}\right) + f_{1c} \left(E_{0x} G_{xx} \overline{E_{0y}} + E_{0x} G_{yx} \overline{E_{0x}} - E_{0y} G_{xy} \overline{E_{0y}} - E_{0y} G_{yy} \overline{E_{0x}}\right) + f_{1s} \left(E_{0x} G_{xy} \overline{E_{0y}} + E_{0x} G_{yy} \overline{E_{0x}} + E_{0y} G_{xx} \overline{E_{0y}} + E_{0y} G_{yx} \overline{E_{0x}}\right) + f_{2c} \left(E_{0x} G_{xz} \overline{E_{0y}} + E_{0x} G_{yz} \overline{E_{0x}} + E_{0z} G_{xx} \overline{E_{0y}} + E_{0z} G_{yx} \overline{E_{0x}}\right) + f_{2s} \left(E_{0y} G_{xz} \overline{E_{0y}} + E_{0y} G_{yz} \overline{E_{0x}} + E_{0z} G_{xy} \overline{E_{0y}} + E_{0z} G_{yy} \overline{E_{0x}}\right) + f_{3} \left(E_{0z} G_{xz} \overline{E_{0y}} + E_{0z} G_{yz} \overline{E_{0x}}\right) + \left(E_{0x} \overline{E_{0z}} \overline{G_{yz}} + E_{0y} \overline{E_{0z}} \overline{G_{xz}}\right) \overline{f_{3}} + \left(E_{0x} \overline{E_{0x}} \overline{G_{yx}} - E_{0x} \overline{E_{0y}} \overline{G_{yy}} + E_{0y} \overline{E_{0x}} \overline{G_{xx}} - E_{0y} \overline{E_{0y}} \overline{G_{xy}}\right) \overline{f_{1c}} + \left(E_{0x} \overline{E_{0x}} \overline{G_{yy}} + E_{0x} \overline{E_{0y}} \overline{G_{yx}} + E_{0y} \overline{E_{0x}} \overline{G_{xy}} + E_{0y} \overline{E_{0y}} \overline{G_{xx}}\right) \overline{f_{1s}} + \left(E_{0x} \overline{E_{0x}} \overline{G_{yz}} + E_{0x} \overline{E_{0z}} \overline{G_{yx}} + E_{0y} \overline{E_{0x}} \overline{G_{xz}} + E_{0y} \overline{E_{0z}} \overline{G_{xx}}\right) \overline{f_{2c}} + \left(E_{0x} \overline{E_{0y}} \overline{G_{yz}} + E_{0x} \overline{E_{0z}} \overline{G_{yy}} + E_{0y} \overline{E_{0y}} \overline{G_{xz}} + E_{0y} \overline{E_{0z}} \overline{G_{xy}}\right) \overline{f_{2s}} + \left(E_{0x} \overline{E_{0x}} \overline{G_{yx}} + E_{0x} \overline{E_{0y}} \overline{G_{yy}} + E_{0x} \overline{E_{0z}} \overline{G_{yz}} + E_{0y} \overline{E_{0x}} \overline{G_{xx}} + E_{0y} \overline{E_{0y}} \overline{G_{xy}} + E_{0y} \overline{E_{0z}} \overline{G_{xz}}\right) \overline{f_{0}}$
In [ ]: