%22%22%22Electromagnetism%20with%20Derive%3A%20Maxwell%20Equations%20and%20Gauge%20Theory%22%22%22%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.19.4%22%0Aapp%20%3D%20marimo.App()%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20from%20derive%20import%20(%0A%20%20%20%20%20%20%20%20Symbol%2C%20symbols%2C%20Function%2C%20Matrix%2C%20Rational%2C%20Sqrt%2C%20R%2C%0A%20%20%20%20%20%20%20%20D%2C%20Integrate%2C%20Simplify%2C%20Expand%2C%20Sin%2C%20Cos%2C%20Exp%2C%20Pi%2C%20I%2C%20Array%2C%0A%20%20%20%20%20%20%20%20Series%2C%20Limit%2C%20Eq%2C%20Solve%2C%0A%20%20%20%20%20%20%20%20FourierTransform%2C%20InverseFourierTransform%2C%20LaplaceTransform%2C%0A%20%20%20%20%20%20%20%20Nest%2C%20NestList%2C%0A%20%20%20%20%20%20%20%20Table%2C%20Map%2C%20Total%2C%0A%20%20%20%20)%0A%20%20%20%20from%20derive.diffgeo%20import%20(%0A%20%20%20%20%20%20%20%20Metric%2C%20minkowski_metric%2C%20Einsum%2C%20Contract%2C%0A%20%20%20%20%20%20%20%20LeviCivita%2C%20levi_civita_tensor%2C%0A%20%20%20%20)%0A%20%20%20%20from%20derive.ode%20import%20DSolve%0A%20%20%20%20from%20derive.plotting%20import%20Plot%2C%20ListPlot%2C%20ListLinePlot%0A%20%20%20%20from%20derive.calculus%20import%20EulerLagrangeEquation%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20Cos%2C%0A%20%20%20%20%20%20%20%20D%2C%0A%20%20%20%20%20%20%20%20Eq%2C%0A%20%20%20%20%20%20%20%20EulerLagrangeEquation%2C%0A%20%20%20%20%20%20%20%20Exp%2C%0A%20%20%20%20%20%20%20%20Expand%2C%0A%20%20%20%20%20%20%20%20FourierTransform%2C%0A%20%20%20%20%20%20%20%20Function%2C%0A%20%20%20%20%20%20%20%20LeviCivita%2C%0A%20%20%20%20%20%20%20%20Matrix%2C%0A%20%20%20%20%20%20%20%20Plot%2C%0A%20%20%20%20%20%20%20%20R%2C%0A%20%20%20%20%20%20%20%20Series%2C%0A%20%20%20%20%20%20%20%20Simplify%2C%0A%20%20%20%20%20%20%20%20Sqrt%2C%0A%20%20%20%20%20%20%20%20Symbol%2C%0A%20%20%20%20%20%20%20%20mo%2C%0A%20%20%20%20%20%20%20%20symbols%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Electromagnetism%20with%20Derive%0A%0A%20%20%20%20This%20notebook%20explores%20classical%20electromagnetism%20using%20symderive's%20full%20symbolic%0A%20%20%20%20computation%20capabilities%2C%20including%20Maxwell's%20equations%2C%20gauge%20theory%2C%20and%20waves.%0A%0A%20%20%20%20%23%23%20Overview%0A%0A%20%20%20%20We%20showcase%20symderive's%20capabilities%3A%0A%20%20%20%201.%20**Matrix%2FTensor**%3A%20Field%20strength%20tensor%20%24F_%7B%5Cmu%5Cnu%7D%24%0A%20%20%20%202.%20**D**%3A%20Covariant%20derivatives%20and%20field%20equations%0A%20%20%20%203.%20**DSolve**%3A%20Solve%20the%20wave%20equation%0A%20%20%20%204.%20**FourierTransform**%3A%20Momentum%20space%20analysis%0A%20%20%20%205.%20**Series**%3A%20Multipole%20expansions%0A%20%20%20%206.%20**Plot**%3A%20Field%20visualizations%0A%20%20%20%207.%20**EulerLagrangeEquation**%3A%20Field%20theory%20Lagrangians%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%201.%20The%20Electromagnetic%20Potential%0A%0A%20%20%20%20The%204-potential%20combines%20scalar%20and%20vector%20potentials%3A%0A%0A%20%20%20%20%24%24A%5E%5Cmu%20%3D%20(%5Cphi%2Fc%2C%20%5Cmathbf%7BA%7D)%24%24%0A%0A%20%20%20%20Electric%20and%20magnetic%20fields%3A%0A%0A%20%20%20%20%24%24%5Cmathbf%7BE%7D%20%3D%20-%5Cnabla%5Cphi%20-%20%5Cfrac%7B%5Cpartial%20%5Cmathbf%7BA%7D%7D%7B%5Cpartial%20t%7D%2C%20%5Cquad%20%5Cmathbf%7BB%7D%20%3D%20%5Cnabla%20%5Ctimes%20%5Cmathbf%7BA%7D%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Function%2C%20symbols)%3A%0A%20%20%20%20%23%20Spacetime%20coordinates%20(c%20%3D%201%20units)%0A%20%20%20%20t%2C%20x%2C%20y%2C%20z%20%3D%20symbols('t%20x%20y%20z'%2C%20real%3DTrue)%0A%20%20%20%20coords%20%3D%20%5Bt%2C%20x%2C%20y%2C%20z%5D%0A%0A%20%20%20%20%23%204-potential%20as%20functions%0A%20%20%20%20phi%20%3D%20Function('phi')(t%2C%20x%2C%20y%2C%20z)%0A%20%20%20%20Ax%20%3D%20Function('A_x')(t%2C%20x%2C%20y%2C%20z)%0A%20%20%20%20Ay%20%3D%20Function('A_y')(t%2C%20x%2C%20y%2C%20z)%0A%20%20%20%20Az%20%3D%20Function('A_z')(t%2C%20x%2C%20y%2C%20z)%0A%0A%20%20%20%20A_mu%20%3D%20%5Bphi%2C%20Ax%2C%20Ay%2C%20Az%5D%0A%20%20%20%20return%20A_mu%2C%20coords%2C%20t%2C%20x%2C%20y%2C%20z%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%202.%20The%20Field%20Strength%20Tensor%0A%0A%20%20%20%20The%20electromagnetic%20field%20tensor%20is%20the%20exterior%20derivative%20of%20the%20potential%3A%0A%0A%20%20%20%20%24%24F_%7B%5Cmu%5Cnu%7D%20%3D%20%5Cpartial_%5Cmu%20A_%5Cnu%20-%20%5Cpartial_%5Cnu%20A_%5Cmu%24%24%0A%0A%20%20%20%20This%20antisymmetric%20tensor%20encodes%20both%20%24%5Cmathbf%7BE%7D%24%20and%20%24%5Cmathbf%7BB%7D%24%3A%0A%0A%20%20%20%20%24%24F_%7B%5Cmu%5Cnu%7D%20%3D%20%5Cbegin%7Bpmatrix%7D%0A%20%20%20%200%20%26%20-E_x%20%26%20-E_y%20%26%20-E_z%20%5C%5C%0A%20%20%20%20E_x%20%26%200%20%26%20-B_z%20%26%20B_y%20%5C%5C%0A%20%20%20%20E_y%20%26%20B_z%20%26%200%20%26%20-B_x%20%5C%5C%0A%20%20%20%20E_z%20%26%20-B_y%20%26%20B_x%20%26%200%0A%20%20%20%20%5Cend%7Bpmatrix%7D%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(A_mu%2C%20D%2C%20Matrix%2C%20Simplify%2C%20coords)%3A%0A%20%20%20%20def%20compute_F_tensor(A%2C%20coord_list)%3A%0A%20%20%20%20%20%20%20%20%22%22%22Compute%20the%20field%20strength%20tensor%20F_%7Bmu%20nu%7D.%22%22%22%0A%20%20%20%20%20%20%20%20n%20%3D%20len(coord_list)%0A%20%20%20%20%20%20%20%20F%20%3D%20%5B%5B0%20for%20_%20in%20range(n)%5D%20for%20_%20in%20range(n)%5D%0A%20%20%20%20%20%20%20%20for%20mu%20in%20range(n)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20nu%20in%20range(n)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20F%5Bmu%5D%5Bnu%5D%20%3D%20Simplify(D(A%5Bnu%5D%2C%20coord_list%5Bmu%5D)%20-%20D(A%5Bmu%5D%2C%20coord_list%5Bnu%5D))%0A%20%20%20%20%20%20%20%20return%20Matrix(F)%0A%0A%20%20%20%20F_munu%20%3D%20compute_F_tensor(A_mu%2C%20coords)%0A%20%20%20%20F_munu%0A%20%20%20%20return%20F_munu%2C%20compute_F_tensor%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%203.%20Maxwell's%20Equations%20in%20Covariant%20Form%0A%0A%20%20%20%20**Inhomogeneous%20equations**%20(with%20sources)%3A%0A%20%20%20%20%24%24%5Cpartial_%5Cmu%20F%5E%7B%5Cmu%5Cnu%7D%20%3D%20%5Cmu_0%20J%5E%5Cnu%24%24%0A%0A%20%20%20%20**Homogeneous%20equations**%20(Bianchi%20identity)%3A%0A%20%20%20%20%24%24%5Cpartial_%5Clambda%20F_%7B%5Cmu%5Cnu%7D%20%2B%20%5Cpartial_%5Cmu%20F_%7B%5Cnu%5Clambda%7D%20%2B%20%5Cpartial_%5Cnu%20F_%7B%5Clambda%5Cmu%7D%20%3D%200%24%24%0A%0A%20%20%20%20The%20Bianchi%20identity%20is%20automatically%20satisfied%20because%20%24F%20%3D%20dA%24.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(D%2C%20F_munu%2C%20Simplify%2C%20coords)%3A%0A%20%20%20%20%23%20Check%20the%20Bianchi%20identity%0A%20%20%20%20def%20bianchi_check(F%2C%20coord_list%2C%20lam%2C%20mu%2C%20nu)%3A%0A%20%20%20%20%20%20%20%20%22%22%22Check%20Bianchi%20identity%20for%20given%20indices.%22%22%22%0A%20%20%20%20%20%20%20%20term1%20%3D%20D(F%5Bmu%2C%20nu%5D%2C%20coord_list%5Blam%5D)%0A%20%20%20%20%20%20%20%20term2%20%3D%20D(F%5Bnu%2C%20lam%5D%2C%20coord_list%5Bmu%5D)%0A%20%20%20%20%20%20%20%20term3%20%3D%20D(F%5Blam%2C%20mu%5D%2C%20coord_list%5Bnu%5D)%0A%20%20%20%20%20%20%20%20return%20Simplify(term1%20%2B%20term2%20%2B%20term3)%0A%0A%20%20%20%20%23%20Verify%20for%20indices%20(0%2C1%2C2)%0A%20%20%20%20bianchi_012%20%3D%20bianchi_check(F_munu%2C%20coords%2C%200%2C%201%2C%202)%0A%20%20%20%20bianchi_012%20%20%23%20Should%20be%200%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%204.%20Gauge%20Invariance%0A%0A%20%20%20%20Under%20gauge%20transformation%20%24A_%5Cmu%20%5Cto%20A_%5Cmu%20%2B%20%5Cpartial_%5Cmu%20%5CLambda%24%2C%0A%20%20%20%20the%20field%20tensor%20is%20invariant%3A%20%24F_%7B%5Cmu%5Cnu%7D%20%5Cto%20F_%7B%5Cmu%5Cnu%7D%24.%0A%0A%20%20%20%20The%20**Lorenz%20gauge**%20condition%3A%20%24%5Cpartial_%5Cmu%20A%5E%5Cmu%20%3D%200%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(A_mu%2C%20D%2C%20Function%2C%20coords%2C%20t%2C%20x%2C%20y%2C%20z)%3A%0A%20%20%20%20%23%20Gauge%20transformation%0A%20%20%20%20Lambda%20%3D%20Function('Lambda')(t%2C%20x%2C%20y%2C%20z)%0A%0A%20%20%20%20%23%20Transformed%20potential%0A%20%20%20%20A_prime%20%3D%20%5BA_mu%5Bi%5D%20%2B%20D(Lambda%2C%20coords%5Bi%5D)%20for%20i%20in%20range(4)%5D%0A%20%20%20%20A_prime%0A%20%20%20%20return%20(A_prime%2C)%0A%0A%0A%40app.cell%0Adef%20_(A_prime%2C%20Expand%2C%20F_munu%2C%20Simplify%2C%20compute_F_tensor%2C%20coords)%3A%0A%20%20%20%20%23%20Verify%20gauge%20invariance%20of%20F%0A%20%20%20%20F_prime%20%3D%20compute_F_tensor(A_prime%2C%20coords)%0A%0A%20%20%20%20%23%20Check%20F'_%7B01%7D%20-%20F_%7B01%7D%0A%20%20%20%20diff_01%20%3D%20Simplify(Expand(F_prime%5B0%2C%201%5D%20-%20F_munu%5B0%2C%201%5D))%0A%20%20%20%20diff_01%20%20%23%20Should%20be%200%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%205.%20Electromagnetic%20Waves%20via%20DSolve%0A%0A%20%20%20%20In%20vacuum%20and%20Lorenz%20gauge%2C%20Maxwell's%20equations%20give%20the%20wave%20equation%3A%0A%0A%20%20%20%20%24%24%5CBox%20A%5E%5Cmu%20%3D%200%24%24%0A%0A%20%20%20%20Let's%20solve%20this%20using%20**DSolve**.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(D%2C%20Eq%2C%20Function%2C%20Symbol)%3A%0A%20%20%20%20%23%201D%20wave%20equation%20for%20scalar%20component%0A%20%20%20%20x_wave%20%3D%20Symbol('x'%2C%20real%3DTrue)%0A%20%20%20%20t_wave%20%3D%20Symbol('t'%2C%20real%3DTrue)%0A%20%20%20%20c%20%3D%20Symbol('c'%2C%20positive%3DTrue)%0A%0A%20%20%20%20A_wave%20%3D%20Function('A')(x_wave%2C%20t_wave)%0A%0A%20%20%20%20%23%20Wave%20equation%3A%20A_tt%20-%20c%C2%B2%20A_xx%20%3D%200%0A%20%20%20%20wave_eq%20%3D%20Eq(D(A_wave%2C%20(t_wave%2C%202))%20-%20c**2%20*%20D(A_wave%2C%20(x_wave%2C%202))%2C%200)%0A%0A%20%20%20%20%23%20DSolve%20for%20PDEs%20returns%20d'Alembert%20solution%0A%20%20%20%20%23%20A%20%3D%20f(x%20-%20ct)%20%2B%20g(x%20%2B%20ct)%0A%20%20%20%20wave_eq%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Cos%2C%20D%2C%20Simplify%2C%20Symbol)%3A%0A%20%20%20%20%23%20Verify%20plane%20wave%20is%20a%20solution%0A%20%20%20%20omega%20%3D%20Symbol('omega'%2C%20positive%3DTrue)%0A%20%20%20%20k%20%3D%20Symbol('k'%2C%20positive%3DTrue)%0A%20%20%20%20A0%20%3D%20Symbol('A_0'%2C%20real%3DTrue)%0A%20%20%20%20x_pw%20%3D%20Symbol('x'%2C%20real%3DTrue)%0A%20%20%20%20t_pw%20%3D%20Symbol('t'%2C%20real%3DTrue)%0A%0A%20%20%20%20%23%20Plane%20wave%3A%20A%20%3D%20A0%20*%20cos(kx%20-%20%CF%89t)%0A%20%20%20%20phase%20%3D%20k%20*%20x_pw%20-%20omega%20*%20t_pw%0A%20%20%20%20A_plane%20%3D%20A0%20*%20Cos(phase)%0A%0A%20%20%20%20%23%20Check%20wave%20equation%3A%20A_tt%20-%20A_xx%20%3D%200%20when%20%CF%89%20%3D%20k%20(c%20%3D%201)%0A%20%20%20%20wave_residual%20%3D%20D(A_plane%2C%20(t_pw%2C%202))%20-%20D(A_plane%2C%20(x_pw%2C%202))%0A%20%20%20%20Simplify(wave_residual)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20result%20%24A_0(%5Comega%5E2%20-%20k%5E2)%5Ccos(%5Cphi)%20%3D%200%24%20when%20%24%5Comega%20%3D%20k%24%20(dispersion%20relation).%0A%0A%20%20%20%20%23%23%23%20Plotting%20the%20Wave%20Solution%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Cos%2C%20Plot%2C%20Symbol)%3A%0A%20%20%20%20%23%20Plot%20electromagnetic%20wave%0A%20%20%20%20x_plot%20%3D%20Symbol('x'%2C%20real%3DTrue)%0A%0A%20%20%20%20%23%20E%20and%20B%20fields%20for%20plane%20wave%20(at%20t%3D0)%0A%20%20%20%20E_field%20%3D%20Cos(x_plot)%0A%20%20%20%20B_field%20%3D%20Cos(x_plot)%20%20%23%20Same%20magnitude%2C%20perpendicular%0A%0A%20%20%20%20Plot(%0A%20%20%20%20%20%20%20%20%5BE_field%2C%20B_field%5D%2C%0A%20%20%20%20%20%20%20%20(x_plot%2C%200%2C%204%20*%203.14159)%2C%0A%20%20%20%20%20%20%20%20PlotLabel%3D%22Electromagnetic%20Plane%20Wave%22%2C%0A%20%20%20%20%20%20%20%20AxesLabel%3D%5B%22x%22%2C%20%22Field%20amplitude%22%5D%2C%0A%20%20%20%20%20%20%20%20PlotLegends%3D%5B%22E_y%22%2C%20%22B_z%22%5D%2C%0A%20%20%20%20%20%20%20%20GridLines%3DTrue%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%206.%20Fourier%20Analysis%20of%20Fields%0A%0A%20%20%20%20In%20momentum%20space%2C%20the%20wave%20equation%20becomes%20algebraic.%0A%20%20%20%20The%20**FourierTransform**%20converts%20%24%5CBox%20A%20%3D%200%24%20to%20%24k%5E2%20%5Ctilde%7BA%7D%20%3D%200%24.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Exp%2C%20FourierTransform%2C%20Simplify%2C%20Symbol)%3A%0A%20%20%20%20%23%20Gaussian%20pulse%20in%20position%20space%0A%20%20%20%20x_ft%20%3D%20Symbol('x'%2C%20real%3DTrue)%0A%20%20%20%20k_ft%20%3D%20Symbol('k'%2C%20real%3DTrue)%0A%20%20%20%20sigma%20%3D%20Symbol('sigma'%2C%20positive%3DTrue)%0A%0A%20%20%20%20%23%20Gaussian%20wave%20packet%0A%20%20%20%20A_gauss%20%3D%20Exp(-x_ft**2%20%2F%20(2*sigma**2))%0A%0A%20%20%20%20%23%20Fourier%20transform%20to%20momentum%20space%0A%20%20%20%20A_k%20%3D%20FourierTransform(A_gauss%2C%20x_ft%2C%20k_ft)%0A%20%20%20%20A_k_simplified%20%3D%20Simplify(A_k)%0A%0A%20%20%20%20%7B%22position_space%22%3A%20A_gauss%2C%20%22momentum_space%22%3A%20A_k_simplified%7D%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20Fourier%20transform%20shows%20%24%5Ctilde%7BA%7D(k)%20%5Cpropto%20e%5E%7B-k%5E2%5Csigma%5E2%2F2%7D%24%20-%20another%20Gaussian%20with%20inverse%20width.%0A%0A%20%20%20%20This%20demonstrates%20the%20**uncertainty%20relation**%3A%20%24%5CDelta%20x%20%5Ccdot%20%5CDelta%20k%20%5Cgeq%201%2F2%24.%0A%0A%20%20%20%20%23%23%207.%20Multipole%20Expansion%20via%20Series%0A%0A%20%20%20%20Far%20from%20a%20charge%20distribution%2C%20the%20potential%20has%20a%20multipole%20expansion%3A%0A%0A%20%20%20%20%24%24%5Cphi(r)%20%3D%20%5Cfrac%7Bq%7D%7B4%5Cpi%5Cepsilon_0%20r%7D%20%2B%20%5Cfrac%7B%5Cmathbf%7Bp%7D%5Ccdot%5Chat%7Br%7D%7D%7B4%5Cpi%5Cepsilon_0%20r%5E2%7D%20%2B%20O(r%5E%7B-3%7D)%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Series%2C%20Sqrt%2C%20Symbol)%3A%0A%20%20%20%20%23%20Expand%201%2F%7Cr%20-%20r'%7C%20for%20r%20%3E%3E%20r'%0A%20%20%20%20r%20%3D%20Symbol('r'%2C%20positive%3DTrue)%0A%20%20%20%20rp%20%3D%20Symbol(%22r'%22%2C%20positive%3DTrue)%20%20%23%20r'%20%3C%3C%20r%0A%20%20%20%20cos_theta%20%3D%20Symbol('cos_theta'%2C%20real%3DTrue)%0A%0A%20%20%20%20%23%20%7Cr%20-%20r'%7C%C2%B2%20%3D%20r%C2%B2%20-%202r%C2%B7r'%20%2B%20r'%C2%B2%20%3D%20r%C2%B2(1%20-%202(r'%2Fr)cos(%CE%B8)%20%2B%20(r'%2Fr)%C2%B2)%0A%20%20%20%20%23%20Let%20%CE%B5%20%3D%20r'%2Fr%20%3C%3C%201%0A%20%20%20%20eps%20%3D%20Symbol('epsilon'%2C%20positive%3DTrue)%0A%0A%20%20%20%20%23%201%2F%7Cr-r'%7C%20%3D%20(1%2Fr)%20*%201%2Fsqrt(1%20-%202%CE%B5*cos(%CE%B8)%20%2B%20%CE%B5%C2%B2)%0A%20%20%20%20inv_dist%20%3D%201%20%2F%20Sqrt(1%20-%202*eps*cos_theta%20%2B%20eps**2)%0A%0A%20%20%20%20%23%20Series%20expansion%20in%20%CE%B5%0A%20%20%20%20multipole_series%20%3D%20Series(inv_dist%2C%20(eps%2C%200%2C%203))%0A%20%20%20%20multipole_series%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20expansion%20gives%20Legendre%20polynomials%3A%0A%20%20%20%20-%20%24%5Cell%3D0%24%3A%20Monopole%20(charge)%0A%20%20%20%20-%20%24%5Cell%3D1%24%3A%20Dipole%0A%20%20%20%20-%20%24%5Cell%3D2%24%3A%20Quadrupole%0A%0A%20%20%20%20%23%23%208.%20Stress-Energy%20Tensor%0A%0A%20%20%20%20The%20electromagnetic%20stress-energy%20tensor%3A%0A%0A%20%20%20%20%24%24T%5E%7B%5Cmu%5Cnu%7D%20%3D%20%5Cfrac%7B1%7D%7B%5Cmu_0%7D%5Cleft(F%5E%7B%5Cmu%5Calpha%7DF%5E%5Cnu%7B%7D_%5Calpha%20-%20%5Cfrac%7B1%7D%7B4%7D%5Ceta%5E%7B%5Cmu%5Cnu%7DF_%7B%5Calpha%5Cbeta%7DF%5E%7B%5Calpha%5Cbeta%7D%5Cright)%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Matrix%2C%20R%2C%20Symbol)%3A%0A%20%20%20%20%23%20For%20uniform%20E%20field%20in%20x-direction%0A%20%20%20%20E0%20%3D%20Symbol('E_0'%2C%20real%3DTrue)%0A%0A%20%20%20%20%23%20F%20tensor%20for%20uniform%20E_x%20field%0A%20%20%20%20F_uniform%20%3D%20Matrix(%5B%0A%20%20%20%20%20%20%20%20%5B0%2C%20-E0%2C%200%2C%200%5D%2C%0A%20%20%20%20%20%20%20%20%5BE0%2C%200%2C%200%2C%200%5D%2C%0A%20%20%20%20%20%20%20%20%5B0%2C%200%2C%200%2C%200%5D%2C%0A%20%20%20%20%20%20%20%20%5B0%2C%200%2C%200%2C%200%5D%0A%20%20%20%20%5D)%0A%0A%20%20%20%20%23%20Energy%20density%3A%20T%5E00%20%3D%20(1%2F2)(E%C2%B2%20%2B%20B%C2%B2)%0A%20%20%20%20%23%20For%20E_x%20%3D%20E0%2C%20B%20%3D%200%3A%0A%20%20%20%20energy_density%20%3D%20R(1%2C%202)%20*%20E0**2%0A%20%20%20%20energy_density%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Exp%2C%20Plot%2C%20Symbol)%3A%0A%20%20%20%20%23%20Plot%20energy%20density%20of%20a%20Gaussian%20pulse%0A%20%20%20%20x_energy%20%3D%20Symbol('x'%2C%20real%3DTrue)%0A%0A%20%20%20%20%23%20E%20field%20of%20Gaussian%20pulse%0A%20%20%20%20E_pulse%20%3D%20Exp(-x_energy**2)%0A%0A%20%20%20%20%23%20Energy%20density%20%E2%88%9D%20E%C2%B2%0A%20%20%20%20u_energy%20%3D%20E_pulse**2%0A%0A%20%20%20%20Plot(%0A%20%20%20%20%20%20%20%20%5BE_pulse%2C%20u_energy%5D%2C%0A%20%20%20%20%20%20%20%20(x_energy%2C%20-3%2C%203)%2C%0A%20%20%20%20%20%20%20%20PlotLabel%3D%22Electric%20Field%20and%20Energy%20Density%22%2C%0A%20%20%20%20%20%20%20%20AxesLabel%3D%5B%22x%22%2C%20%22Amplitude%22%5D%2C%0A%20%20%20%20%20%20%20%20PlotLegends%3D%5B%22E(x)%22%2C%20%22u(x)%20%E2%88%9D%20E%C2%B2%22%5D%2C%0A%20%20%20%20%20%20%20%20GridLines%3DTrue%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%209.%20Lagrangian%20Formulation%0A%0A%20%20%20%20The%20electromagnetic%20Lagrangian%20density%3A%0A%0A%20%20%20%20%24%24%5Cmathcal%7BL%7D%20%3D%20-%5Cfrac%7B1%7D%7B4%5Cmu_0%7D%20F_%7B%5Cmu%5Cnu%7DF%5E%7B%5Cmu%5Cnu%7D%20-%20J%5E%5Cmu%20A_%5Cmu%24%24%0A%0A%20%20%20%20Using%20**EulerLagrangeEquation**%20on%20a%20simplified%20scalar%20analog%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(D%2C%20EulerLagrangeEquation%2C%20Function%2C%20R%2C%20Simplify%2C%20Symbol)%3A%0A%20%20%20%20%23%20Simplified%3A%20massless%20Klein-Gordon%20as%20EM%20analog%0A%20%20%20%20x_lag%20%3D%20Symbol('x'%2C%20real%3DTrue)%0A%20%20%20%20t_lag%20%3D%20Symbol('t'%2C%20real%3DTrue)%0A%20%20%20%20A_scalar%20%3D%20Function('A')(x_lag%2C%20t_lag)%0A%20%20%20%20J%20%3D%20Function('J')(x_lag%2C%20t_lag)%0A%0A%20%20%20%20%23%20L%20%3D%20(1%2F2)(%E2%88%82_t%20A)%C2%B2%20-%20(1%2F2)(%E2%88%82_x%20A)%C2%B2%20-%20J*A%0A%20%20%20%20L_em%20%3D%20R(1%2C%202)%20*%20D(A_scalar%2C%20t_lag)**2%20-%20R(1%2C%202)%20*%20D(A_scalar%2C%20x_lag)**2%20-%20J%20*%20A_scalar%0A%0A%20%20%20%20%23%20Euler-Lagrange%20gives%20wave%20equation%20with%20source%0A%20%20%20%20eq_A%20%3D%20EulerLagrangeEquation(L_em%2C%20A_scalar%2C%20%5Bx_lag%2C%20t_lag%5D)%0A%20%20%20%20Simplify(eq_A)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20result%20is%20the%20inhomogeneous%20wave%20equation%3A%20%24%5CBox%20A%20%3D%20J%24%0A%0A%20%20%20%20%23%23%2010.%20Levi-Civita%20and%20Dual%20Tensor%0A%0A%20%20%20%20The%20dual%20field%20tensor%3A%0A%0A%20%20%20%20%24%24%5Ctilde%7BF%7D%5E%7B%5Cmu%5Cnu%7D%20%3D%20%5Cfrac%7B1%7D%7B2%7D%5Cepsilon%5E%7B%5Cmu%5Cnu%5Crho%5Csigma%7DF_%7B%5Crho%5Csigma%7D%24%24%0A%0A%20%20%20%20Maxwell's%20homogeneous%20equations%20become%3A%20%24%5Cpartial_%5Cmu%20%5Ctilde%7BF%7D%5E%7B%5Cmu%5Cnu%7D%20%3D%200%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(LeviCivita)%3A%0A%20%20%20%20%23%20Levi-Civita%20symbol%20values%0A%20%20%20%20eps_0123%20%3D%20LeviCivita(0%2C%201%2C%202%2C%203)%20%20%23%20%2B1%0A%20%20%20%20eps_1023%20%3D%20LeviCivita(1%2C%200%2C%202%2C%203)%20%20%23%20-1%20(odd%20permutation)%0A%20%20%20%20eps_0012%20%3D%20LeviCivita(0%2C%200%2C%201%2C%202)%20%20%23%200%20(repeated%20index)%0A%0A%20%20%20%20(eps_0123%2C%20eps_1023%2C%20eps_0012)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Summary%0A%0A%20%20%20%20We%20demonstrated%20symderive's%20electromagnetism%20capabilities%3A%0A%0A%20%20%20%20%7C%20Feature%20%7C%20Usage%20%7C%0A%20%20%20%20%7C---------%7C-------%7C%0A%20%20%20%20%7C%20**Matrix**%20%7C%20Field%20strength%20tensor%20%24F_%7B%5Cmu%5Cnu%7D%24%20%7C%0A%20%20%20%20%7C%20**D**%20%7C%20Derivatives%20for%20Maxwell%20equations%20%7C%0A%20%20%20%20%7C%20**DSolve**%20%7C%20Wave%20equation%20solutions%20%7C%0A%20%20%20%20%7C%20**FourierTransform**%20%7C%20Momentum%20space%20analysis%20%7C%0A%20%20%20%20%7C%20**Series**%20%7C%20Multipole%20expansion%20%7C%0A%20%20%20%20%7C%20**Plot**%20%7C%20Field%20visualizations%20%7C%0A%20%20%20%20%7C%20**EulerLagrangeEquation**%20%7C%20Field%20theory%20Lagrangians%20%7C%0A%20%20%20%20%7C%20**LeviCivita**%20%7C%20Dual%20tensor%2C%20Levi-Civita%20symbol%20%7C%0A%0A%20%20%20%20Derive%20provides%20comprehensive%20tools%20for%20electromagnetism%20and%20gauge%20theory!%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
aa4dad6e8436d46bfb743493b05ed80f