In [1]:
from sympy import *

In [2]:
from sympy.matrices import Matrix

In [3]:
init_printing()

In this worksheet, we represent the dependency of different variables with functions.

Thus, when one variable changes, those depending on it will be changed simultaneously.

However, the disadvantage is that the method slow down the speed of calculation obviously.


In [4]:
#In the first section, all variables are symbols. The transformation and relationship are ignored
Theta = var('Theta')  #Theta is the angle between the direction vector and its projection on xOy plane
phi = var('phi')#phi denote the angle between the projection mentioned above and the direction of +x axis, which is also the direction of the speed
Theta_prime = var('Theta_prime')
phi_prime = var('phi_prime')

psi = var('psi')
theta = var('theta')
psi_prime = var('psi_prime')
theta_prime = var('theta_prime')

cos_theta = lambda : cos(theta)
sin_theta = lambda : sin(theta)
cos_psi = lambda : cos(psi)
sin_psi = lambda : sin(psi)
cos_theta_prime = lambda : cos(theta_prime)
sin_theta_prime = lambda : sin(theta_prime)
cos_psi_prime = lambda : cos(psi_prime)
sin_psi_prime = lambda : sin(psi_prime)
c = var('c')  #light speed
B = var('B')  #the strength of magnetic field during the period in which the particle passes through the segment
beta = var('beta')
v = lambda : beta * c  #the speed of the particle during the period
gamma = var('gamma')
#func_gamma = lambda : gamma
E_prime = var('E_prime')  #the strength of electric field in the S' frame
#func_E_prime = lambda : E_prime
B_prime = var('B_prime')
#func_B_prime = lambda : B_prime
vector_epsilon_prime_in = Matrix([[S(0), -S(1), S(0)]])
#in S frame
def vector_n():
    return Matrix([[cos_theta(), sin_theta() * cos_psi(), sin_theta() * sin_psi()]])  #the vector of observor's direction
def vector_epsilon_out_1():
    return Matrix([[-sin_theta() * sin_psi() * cos_theta() / sqrt(S(1) - sin_theta()**2 * sin_psi()**2), -sin_theta() * sin_psi() * sin_theta() * cos_psi() / sqrt(S(1) - sin_theta()**2 * sin_psi()**2), sqrt(1 - sin_theta()**2 * sin_psi()**2)]]) #the out vector which lies in the xOy plane
def vector_epsilon_out_2():
    return vector_epsilon_out_1().cross(vector_n()) #the other out vector
#in S' frame
def vector_n_prime():
    return Matrix([[cos_theta_prime(), sin_theta_prime() * cos_psi_prime(), sin_theta_prime() * sin_psi_prime()]])
def vector_epsilon_prime_out_1():
    return Matrix([[-sin_theta_prime() * sin_psi_prime() * cos_theta_prime() / sqrt(S(1) - sin_theta_prime()**2 * sin_psi_prime()**2), -sin_theta_prime() * sin_psi_prime() * sin_theta_prime() * cos_psi_prime() / sqrt(S(1) - sin_theta_prime()**2 * sin_psi_prime()**2), sqrt(S(1) - sin_theta_prime()**2 * sin_psi_prime()**2)]]) #the out vector which lies in the xOy plane
def vector_epsilon_prime_out_2():
    return vector_epsilon_prime_out_1().cross(vector_n_prime())
r_e = var('r_e')  #classical electron radius
def E_prime_out_1():
    return r_e * E_prime * vector_epsilon_prime_out_1().dot(vector_epsilon_prime_in)
def E_prime_out_2():
    return r_e * E_prime * vector_epsilon_prime_out_2().dot(vector_epsilon_prime_in)
def vector_E_prime_out():
    return E_prime_out_1() * vector_epsilon_prime_out_1() + E_prime_out_2() * vector_epsilon_prime_out_2()
def vector_B_prime_out():
    return S(1) / c * vector_n_prime().cross(vector_E_prime_out())
vector_x = Matrix([[S(1), S(0), S(0)]])
def vector_E_out():
    return gamma * (vector_E_prime_out() - v() * vector_x.cross(vector_B_prime_out())) - (gamma - 1) * vector_E_prime_out().dot(vector_x) * vector_x
def factor_vector(vector_instance):
    return Matrix([[factor(vector_instance[i]) for i in range(len(vector_instance))]])

In [5]:
factor_vector(vector_E_out())


Out[5]:
$$\left[\begin{smallmatrix}{}E_{prime} r_{e} \sin{\left (\theta_{prime} \right )} \cos{\left (\psi_{prime} \right )} \cos{\left (\theta_{prime} \right )} & \frac{E_{prime} \gamma r_{e} \left(\beta \sin^{2}{\left (\theta_{prime} \right )} \cos^{2}{\left (\psi_{prime} \right )} \cos{\left (\theta_{prime} \right )} + \beta \cos^{3}{\left (\theta_{prime} \right )} + \sin^{2}{\left (\psi_{prime} \right )} \sin^{4}{\left (\theta_{prime} \right )} \cos^{2}{\left (\psi_{prime} \right )} + \cos^{2}{\left (\theta_{prime} \right )}\right)}{\left(\sin{\left (\psi_{prime} \right )} \sin{\left (\theta_{prime} \right )} - 1\right) \left(\sin{\left (\psi_{prime} \right )} \sin{\left (\theta_{prime} \right )} + 1\right)} & E_{prime} \gamma r_{e} \sin{\left (\psi_{prime} \right )} \sin^{2}{\left (\theta_{prime} \right )} \cos{\left (\psi_{prime} \right )}\end{smallmatrix}\right]$$

In [6]:
factor(vector_E_out()[0])


Out[6]:
$$E_{prime} r_{e} \sin{\left (\theta_{prime} \right )} \cos{\left (\psi_{prime} \right )} \cos{\left (\theta_{prime} \right )}$$

In [7]:
factor(vector_E_out()[1])


Out[7]:
$$\frac{E_{prime} \gamma r_{e} \left(\beta \sin^{2}{\left (\theta_{prime} \right )} \cos^{2}{\left (\psi_{prime} \right )} \cos{\left (\theta_{prime} \right )} + \beta \cos^{3}{\left (\theta_{prime} \right )} + \sin^{2}{\left (\psi_{prime} \right )} \sin^{4}{\left (\theta_{prime} \right )} \cos^{2}{\left (\psi_{prime} \right )} + \cos^{2}{\left (\theta_{prime} \right )}\right)}{\left(\sin{\left (\psi_{prime} \right )} \sin{\left (\theta_{prime} \right )} - 1\right) \left(\sin{\left (\psi_{prime} \right )} \sin{\left (\theta_{prime} \right )} + 1\right)}$$

In [8]:
factor(vector_E_out()[2])


Out[8]:
$$E_{prime} \gamma r_{e} \sin{\left (\psi_{prime} \right )} \sin^{2}{\left (\theta_{prime} \right )} \cos{\left (\psi_{prime} \right )}$$
#

Consider the transformation between quantities:

#

In [9]:
cos_theta = lambda : cos(Theta) * cos(phi)
sin_theta = lambda : sqrt(S(1) - cos_theta()**2)
cos_psi = lambda : cos(Theta) * sin(phi) / sin_theta()
sin_psi = lambda : sqrt(S(1) - cos_psi()**2)
sin_theta_prime = lambda : sin_theta() / (gamma * (S(1) - beta * cos_theta()))
cos_theta_prime = lambda : (cos_theta() - beta) / (S(1) - beta * cos_theta())
sin_psi_prime = lambda : sin_psi()
cos_psi_prime = lambda : cos_psi()
#sin_phi_prime = lambda : sin_theta_prime() * cos_psi_prime() / sqrt(1 - sin_theta_prime()^2 * sin_psi_prime()^2)
#cos_phi_prime = lambda : sqrt(1 - sin_phi_prime()^2)
#sin_Theta_prime = lambda : sin_theta_prime() * sin_psi_prime()
#cos_Theta_prime = lambda : sqrt(1 - sin_Theta_prime()^2)
gamma = S(1) / sqrt(S(1) - beta ** 2)

In [10]:
factor_vector(vector_E_out())


Out[10]:
$$\left[\begin{smallmatrix}{}- \frac{E_{prime} r_{e} \sqrt{- \left(\beta - 1\right) \left(\beta + 1\right)} \sin{\left (\phi \right )} \cos{\left (\Theta \right )}}{\left(\beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} - 1\right)^{2}} \left(\beta - \cos{\left (\Theta \right )} \cos{\left (\phi \right )}\right) & - \frac{E_{prime} r_{e} \left(\beta - 1\right) \left(\beta + 1\right) \left(\beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} + \sin^{2}{\left (\phi \right )} \cos^{2}{\left (\Theta \right )} - 1\right)}{\sqrt{- \left(\beta - 1\right) \left(\beta + 1\right)} \left(\beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} - 1\right)^{2}} & \frac{E_{prime} r_{e} \sqrt{- \left(\beta - 1\right) \left(\beta + 1\right)} \sin{\left (\phi \right )} \cos{\left (\Theta \right )}}{\left(\beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} - 1\right)^{2}} \sqrt{- \left(\cos{\left (\Theta \right )} \cos{\left (\phi \right )} - 1\right) \left(\cos{\left (\Theta \right )} \cos{\left (\phi \right )} + 1\right)} \sqrt{- \frac{\sin^{2}{\left (\phi \right )} \cos^{2}{\left (\Theta \right )} + \cos^{2}{\left (\Theta \right )} \cos^{2}{\left (\phi \right )} - 1}{- \cos^{2}{\left (\Theta \right )} \cos^{2}{\left (\phi \right )} + 1}}\end{smallmatrix}\right]$$

In [11]:
factor(vector_E_out()[0])


Out[11]:
$$- \frac{E_{prime} r_{e} \sqrt{- \left(\beta - 1\right) \left(\beta + 1\right)} \sin{\left (\phi \right )} \cos{\left (\Theta \right )}}{\left(\beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} - 1\right)^{2}} \left(\beta - \cos{\left (\Theta \right )} \cos{\left (\phi \right )}\right)$$

In [12]:
factor(vector_E_out()[1])


Out[12]:
$$- \frac{E_{prime} r_{e} \left(\beta - 1\right) \left(\beta + 1\right) \left(\beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} + \sin^{2}{\left (\phi \right )} \cos^{2}{\left (\Theta \right )} - 1\right)}{\sqrt{- \left(\beta - 1\right) \left(\beta + 1\right)} \left(\beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} - 1\right)^{2}}$$

In [13]:
factor(vector_E_out()[2])


Out[13]:
$$\frac{E_{prime} r_{e} \sqrt{- \left(\beta - 1\right) \left(\beta + 1\right)} \sin{\left (\phi \right )} \cos{\left (\Theta \right )}}{\left(\beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} - 1\right)^{2}} \sqrt{- \left(\cos{\left (\Theta \right )} \cos{\left (\phi \right )} - 1\right) \left(\cos{\left (\Theta \right )} \cos{\left (\phi \right )} + 1\right)} \sqrt{- \frac{\sin^{2}{\left (\phi \right )} \cos^{2}{\left (\Theta \right )} + \cos^{2}{\left (\Theta \right )} \cos^{2}{\left (\phi \right )} - 1}{- \cos^{2}{\left (\Theta \right )} \cos^{2}{\left (\phi \right )} + 1}}$$

In [14]:
factor(vector_E_out().dot(vector_E_out()))


Out[14]:
$$- \frac{E_{prime}^{2} r_{e}^{2}}{\left(\beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} - 1\right)^{4}} \left(\beta - 1\right) \left(\beta + 1\right) \left(\beta^{2} \sin^{2}{\left (\phi \right )} \cos^{2}{\left (\Theta \right )} + \beta^{2} \cos^{2}{\left (\Theta \right )} \cos^{2}{\left (\phi \right )} - 2 \beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} - \sin^{2}{\left (\phi \right )} \cos^{2}{\left (\Theta \right )} + 1\right)$$

In [15]:
#Below is the canonical calculation of electrodynamics
canonical_vector_E_out = lambda : vector_n().cross((vector_n() - beta * vector_x).cross(vector_epsilon_prime_in)) / (S(1) - beta * vector_x.dot(vector_n()))**2

In [16]:
factor_vector(canonical_vector_E_out())


Out[16]:
$$\left[\begin{smallmatrix}{}\frac{\left(\beta - \cos{\left (\Theta \right )} \cos{\left (\phi \right )}\right) \sin{\left (\phi \right )} \cos{\left (\Theta \right )}}{\left(\beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} - 1\right)^{2}} & - \frac{\beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} + \sin^{2}{\left (\phi \right )} \cos^{2}{\left (\Theta \right )} - 1}{\left(\beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} - 1\right)^{2}} & - \frac{\sqrt{- \left(\cos{\left (\Theta \right )} \cos{\left (\phi \right )} - 1\right) \left(\cos{\left (\Theta \right )} \cos{\left (\phi \right )} + 1\right)}}{\left(\beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} - 1\right)^{2}} \sqrt{- \frac{\sin^{2}{\left (\phi \right )} \cos^{2}{\left (\Theta \right )} + \cos^{2}{\left (\Theta \right )} \cos^{2}{\left (\phi \right )} - 1}{- \cos^{2}{\left (\Theta \right )} \cos^{2}{\left (\phi \right )} + 1}} \sin{\left (\phi \right )} \cos{\left (\Theta \right )}\end{smallmatrix}\right]$$

In [17]:
factor(canonical_vector_E_out()[0])


Out[17]:
$$\frac{\left(\beta - \cos{\left (\Theta \right )} \cos{\left (\phi \right )}\right) \sin{\left (\phi \right )} \cos{\left (\Theta \right )}}{\left(\beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} - 1\right)^{2}}$$

In [18]:
factor(canonical_vector_E_out()[1])


Out[18]:
$$- \frac{\beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} + \sin^{2}{\left (\phi \right )} \cos^{2}{\left (\Theta \right )} - 1}{\left(\beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} - 1\right)^{2}}$$

In [19]:
factor(canonical_vector_E_out()[2])


Out[19]:
$$- \frac{\sqrt{- \left(\cos{\left (\Theta \right )} \cos{\left (\phi \right )} - 1\right) \left(\cos{\left (\Theta \right )} \cos{\left (\phi \right )} + 1\right)}}{\left(\beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} - 1\right)^{2}} \sqrt{- \frac{\sin^{2}{\left (\phi \right )} \cos^{2}{\left (\Theta \right )} + \cos^{2}{\left (\Theta \right )} \cos^{2}{\left (\phi \right )} - 1}{- \cos^{2}{\left (\Theta \right )} \cos^{2}{\left (\phi \right )} + 1}} \sin{\left (\phi \right )} \cos{\left (\Theta \right )}$$

In [20]:
factor(canonical_vector_E_out().dot(canonical_vector_E_out()))


Out[20]:
$$\frac{1}{\left(\beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} - 1\right)^{4}} \left(\beta^{2} \sin^{2}{\left (\phi \right )} \cos^{2}{\left (\Theta \right )} + \beta^{2} \cos^{2}{\left (\Theta \right )} \cos^{2}{\left (\phi \right )} - 2 \beta \cos{\left (\Theta \right )} \cos{\left (\phi \right )} - \sin^{2}{\left (\phi \right )} \cos^{2}{\left (\Theta \right )} + 1\right)$$
#

Compare the result of two different method:

#

In [25]:
factor_vector(vector_E_out() - (-E_prime * r_e / gamma * canonical_vector_E_out()))


Out[25]:
$$\left[\begin{smallmatrix}{}0 & 0 & 0\end{smallmatrix}\right]$$

In [24]:
factor(vector_E_out().dot(vector_E_out()) - E_prime**2 * r_e**2 / gamma**2 * canonical_vector_E_out().dot(canonical_vector_E_out()))


Out[24]:
$$0$$

In [22]: