%22%22%22Differential%20Geometry%20with%20Derive%3A%20Manifolds%2C%20Curvature%2C%20and%20Connections%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%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%20Eigenvalues%2C%20Eigenvectors%2C%20Det%2C%20Tr%2C%0A%20%20%20%20%20%20%20%20Nest%2C%20NestList%2C%20FixedPoint%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%20Tensor%2C%20CovariantDerivative%2C%0A%20%20%20%20%20%20%20%20minkowski_metric%2C%20schwarzschild_metric%2C%20flrw_metric%2C%20spherical_metric_3d%2C%0A%20%20%20%20%20%20%20%20CoordinateTransformation%2C%20cartesian_to_spherical_3d%2C%0A%20%20%20%20%20%20%20%20symmetric_index_pairs%2C%20SymmetricMatrix%2C%20SymmetricChristoffel%2C%0A%20%20%20%20%20%20%20%20LeviCivita%2C%20levi_civita_tensor%2C%0A%20%20%20%20%20%20%20%20Einsum%2C%20Contract%2C%20OuterProduct%2C%20InnerProduct%2C%20Trace%2C%0A%20%20%20%20)%0A%20%20%20%20from%20derive.plotting%20import%20Plot%2C%20ListPlot%2C%20ListLinePlot%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20Eigenvalues%2C%0A%20%20%20%20%20%20%20%20Einsum%2C%0A%20%20%20%20%20%20%20%20ListLinePlot%2C%0A%20%20%20%20%20%20%20%20Matrix%2C%0A%20%20%20%20%20%20%20%20Metric%2C%0A%20%20%20%20%20%20%20%20NestList%2C%0A%20%20%20%20%20%20%20%20Plot%2C%0A%20%20%20%20%20%20%20%20Simplify%2C%0A%20%20%20%20%20%20%20%20Sin%2C%0A%20%20%20%20%20%20%20%20Symbol%2C%0A%20%20%20%20%20%20%20%20SymmetricChristoffel%2C%0A%20%20%20%20%20%20%20%20cartesian_to_spherical_3d%2C%0A%20%20%20%20%20%20%20%20minkowski_metric%2C%0A%20%20%20%20%20%20%20%20mo%2C%0A%20%20%20%20%20%20%20%20schwarzschild_metric%2C%0A%20%20%20%20%20%20%20%20symbols%2C%0A%20%20%20%20%20%20%20%20symmetric_index_pairs%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%20Differential%20Geometry%20with%20Derive%0A%0A%20%20%20%20This%20notebook%20explores%20differential%20geometry%20using%20symderive's%20full%20suite%20of%0A%20%20%20%20tools%20for%20metrics%2C%20curvature%2C%20and%20tensor%20calculus.%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**Metric**%3A%20Define%20curved%20spaces%20and%20spacetimes%0A%20%20%20%202.%20**Christoffel%20symbols**%3A%20Connection%20coefficients%0A%20%20%20%203.%20**Riemann%2FRicci%2FScalar**%3A%20Curvature%20tensors%0A%20%20%20%204.%20**Eigenvalues**%3A%20Principal%20curvatures%0A%20%20%20%205.%20**Series**%3A%20Geodesic%20deviation%20expansions%0A%20%20%20%206.%20**Plot**%3A%20Curvature%20visualizations%0A%20%20%20%207.%20**NestList**%3A%20Geodesic%20iteration%0A%20%20%20%208.%20**Einsum**%3A%20Einstein%20summation%20convention%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.%20Metrics%20and%20Line%20Elements%0A%0A%20%20%20%20A%20metric%20tensor%20%24g_%7B%5Cmu%5Cnu%7D%24%20defines%20geometry%20through%20the%20line%20element%3A%0A%0A%20%20%20%20%24%24ds%5E2%20%3D%20g_%7B%5Cmu%5Cnu%7D%20dx%5E%5Cmu%20dx%5E%5Cnu%24%24%0A%0A%20%20%20%20%23%23%23%20The%202-Sphere%0A%0A%20%20%20%20%24%24ds%5E2%20%3D%20d%5Ctheta%5E2%20%2B%20%5Csin%5E2%5Ctheta%20%5C%2C%20d%5Cphi%5E2%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Metric%2C%20Sin%2C%20symbols)%3A%0A%20%20%20%20theta%2C%20phi%20%3D%20symbols('theta%20phi'%2C%20real%3DTrue%2C%20positive%3DTrue)%0A%0A%20%20%20%20sphere%20%3D%20Metric(%0A%20%20%20%20%20%20%20%20coords%3D%5Btheta%2C%20phi%5D%2C%0A%20%20%20%20%20%20%20%20components%3D%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%5B1%2C%200%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%5B0%2C%20Sin(theta)**2%5D%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%0A%20%20%20%20sphere.g%0A%20%20%20%20return%20(sphere%2C)%0A%0A%0A%40app.cell%0Adef%20_(Simplify%2C%20sphere)%3A%0A%20%20%20%20%23%20Inverse%20metric%0A%20%20%20%20g_inv%20%3D%20sphere.inverse%0A%20%20%20%20Simplify(g_inv)%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%202.%20Christoffel%20Symbols%0A%0A%20%20%20%20The%20Christoffel%20symbols%20(connection%20coefficients)%3A%0A%0A%20%20%20%20%24%24%5CGamma%5E%5Crho_%7B%5Cmu%5Cnu%7D%20%3D%20%5Cfrac%7B1%7D%7B2%7Dg%5E%7B%5Crho%5Csigma%7D%5Cleft(%5Cpartial_%5Cmu%20g_%7B%5Csigma%5Cnu%7D%20%2B%20%5Cpartial_%5Cnu%20g_%7B%5Csigma%5Cmu%7D%20-%20%5Cpartial_%5Csigma%20g_%7B%5Cmu%5Cnu%7D%5Cright)%24%24%0A%0A%20%20%20%20They%20determine%20parallel%20transport%20on%20the%20manifold.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Simplify%2C%20sphere)%3A%0A%20%20%20%20christoffel%20%3D%20sphere.christoffel_second_kind()%0A%0A%20%20%20%20%23%20Non-zero%20components%0A%20%20%20%20Gamma_theta_phi_phi%20%3D%20Simplify(christoffel%5B0%2C%201%2C%201%5D)%20%20%23%20%CE%93%5E%CE%B8_%CF%86%CF%86%0A%20%20%20%20Gamma_phi_theta_phi%20%3D%20Simplify(christoffel%5B1%2C%200%2C%201%5D)%20%20%23%20%CE%93%5E%CF%86_%CE%B8%CF%86%0A%0A%20%20%20%20(Gamma_theta_phi_phi%2C%20Gamma_phi_theta_phi)%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%20For%20the%202-sphere%3A%0A%20%20%20%20-%20%24%5CGamma%5E%5Ctheta_%7B%5Cphi%5Cphi%7D%20%3D%20-%5Csin%5Ctheta%5Ccos%5Ctheta%24%0A%20%20%20%20-%20%24%5CGamma%5E%5Cphi_%7B%5Ctheta%5Cphi%7D%20%3D%20%5Ccot%5Ctheta%24%0A%0A%20%20%20%20%23%23%203.%20Riemann%20Curvature%20Tensor%0A%0A%20%20%20%20The%20Riemann%20tensor%20measures%20curvature%3A%0A%0A%20%20%20%20%24%24R%5E%5Crho_%7B%5C%3B%5Csigma%5Cmu%5Cnu%7D%20%3D%20%5Cpartial_%5Cmu%5CGamma%5E%5Crho_%7B%5Cnu%5Csigma%7D%20-%20%5Cpartial_%5Cnu%5CGamma%5E%5Crho_%7B%5Cmu%5Csigma%7D%20%2B%20%5CGamma%5E%5Crho_%7B%5Cmu%5Clambda%7D%5CGamma%5E%5Clambda_%7B%5Cnu%5Csigma%7D%20-%20%5CGamma%5E%5Crho_%7B%5Cnu%5Clambda%7D%5CGamma%5E%5Clambda_%7B%5Cmu%5Csigma%7D%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Simplify%2C%20sphere)%3A%0A%20%20%20%20riemann%20%3D%20sphere.riemann_tensor()%0A%0A%20%20%20%20%23%20Non-trivial%20component%20R%5E%CE%B8_%CF%86%CE%B8%CF%86%0A%20%20%20%20R_theta_phi_theta_phi%20%3D%20Simplify(riemann%5B0%2C%201%2C%200%2C%201%5D)%0A%20%20%20%20R_theta_phi_theta_phi%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.%20Ricci%20Tensor%20and%20Scalar%20Curvature%0A%0A%20%20%20%20%24%24R_%7B%5Cmu%5Cnu%7D%20%3D%20R%5E%5Crho_%7B%5C%3B%5Cmu%5Crho%5Cnu%7D%2C%20%5Cquad%20R%20%3D%20g%5E%7B%5Cmu%5Cnu%7DR_%7B%5Cmu%5Cnu%7D%24%24%0A%0A%20%20%20%20For%20a%20unit%202-sphere%2C%20%24R%20%3D%202%24%20(constant%20positive%20curvature).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Simplify%2C%20sphere)%3A%0A%20%20%20%20ricci%20%3D%20sphere.ricci_tensor()%0A%20%20%20%20Simplify(ricci)%0A%20%20%20%20return%20(ricci%2C)%0A%0A%0A%40app.cell%0Adef%20_(Simplify%2C%20sphere)%3A%0A%20%20%20%20R_scalar%20%3D%20sphere.ricci_scalar()%0A%20%20%20%20Simplify(R_scalar)%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.%20Einstein%20Tensor%0A%0A%20%20%20%20The%20Einstein%20tensor%20for%20general%20relativity%3A%0A%0A%20%20%20%20%24%24G_%7B%5Cmu%5Cnu%7D%20%3D%20R_%7B%5Cmu%5Cnu%7D%20-%20%5Cfrac%7B1%7D%7B2%7Dg_%7B%5Cmu%5Cnu%7DR%24%24%0A%0A%20%20%20%20Einstein's%20equations%3A%20%24G_%7B%5Cmu%5Cnu%7D%20%3D%208%5Cpi%20G%20T_%7B%5Cmu%5Cnu%7D%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Simplify%2C%20sphere)%3A%0A%20%20%20%20einstein%20%3D%20sphere.einstein_tensor()%0A%20%20%20%20Simplify(einstein)%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.%20Gaussian%20Curvature%20and%20Visualization%0A%0A%20%20%20%20The%20**Gaussian%20curvature**%20%24K%20%3D%20R%2F2%24%20for%20a%202D%20surface.%0A%20%20%20%20For%20a%202-sphere%2C%20%24K%20%3D%201%24%20everywhere.%0A%0A%20%20%20%20Let's%20plot%20how%20%24g_%7B%5Cphi%5Cphi%7D%20%3D%20%5Csin%5E2%5Ctheta%24%20varies%20with%20latitude.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Plot%2C%20Sin%2C%20Symbol)%3A%0A%20%20%20%20%23%20Plot%20metric%20component%20g_%CF%86%CF%86%20%3D%20sin%C2%B2%CE%B8%0A%20%20%20%20theta_plot%20%3D%20Symbol('theta'%2C%20real%3DTrue)%0A%0A%20%20%20%20g_phi_phi%20%3D%20Sin(theta_plot)**2%0A%0A%20%20%20%20Plot(%0A%20%20%20%20%20%20%20%20g_phi_phi%2C%0A%20%20%20%20%20%20%20%20(theta_plot%2C%200%2C%203.14159)%2C%0A%20%20%20%20%20%20%20%20PlotLabel%3D%22Metric%20Component%20g_%CF%86%CF%86%20on%202-Sphere%22%2C%0A%20%20%20%20%20%20%20%20AxesLabel%3D%5B%22%CE%B8%20(latitude)%22%2C%20%22g_%CF%86%CF%86%20%3D%20sin%C2%B2%CE%B8%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%20At%20the%20equator%20(%24%5Ctheta%20%3D%20%5Cpi%2F2%24)%2C%20%24g_%7B%5Cphi%5Cphi%7D%20%3D%201%24%20(maximum).%0A%20%20%20%20At%20the%20poles%20(%24%5Ctheta%20%3D%200%2C%20%5Cpi%24)%2C%20%24g_%7B%5Cphi%5Cphi%7D%20%3D%200%24%20(coordinate%20singularity).%0A%0A%20%20%20%20%23%23%207.%20Spacetime%20Metrics%0A%0A%20%20%20%20%23%23%23%20Minkowski%20(Flat%20Spacetime)%0A%0A%20%20%20%20%24%24ds%5E2%20%3D%20-dt%5E2%20%2B%20dx%5E2%20%2B%20dy%5E2%20%2B%20dz%5E2%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(minkowski_metric)%3A%0A%20%20%20%20eta%20%3D%20minkowski_metric(4)%0A%20%20%20%20eta.g%0A%20%20%20%20return%20(eta%2C)%0A%0A%0A%40app.cell%0Adef%20_(Simplify%2C%20eta)%3A%0A%20%20%20%20R_minkowski%20%3D%20eta.ricci_scalar()%0A%20%20%20%20Simplify(R_minkowski)%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%23%20Schwarzschild%20(Black%20Hole)%0A%0A%20%20%20%20%24%24ds%5E2%20%3D%20-%5Cleft(1-%5Cfrac%7B2M%7D%7Br%7D%5Cright)dt%5E2%20%2B%20%5Cfrac%7Bdr%5E2%7D%7B1-2M%2Fr%7D%20%2B%20r%5E2%20d%5COmega%5E2%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(schwarzschild_metric)%3A%0A%20%20%20%20g_schw%20%3D%20schwarzschild_metric()%0A%20%20%20%20g_schw.g%0A%20%20%20%20return%20(g_schw%2C)%0A%0A%0A%40app.cell%0Adef%20_(Simplify%2C%20g_schw)%3A%0A%20%20%20%20R_schw%20%3D%20g_schw.ricci_scalar()%0A%20%20%20%20Simplify(R_schw)%20%20%23%200%20(vacuum%20solution)%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%23%20Plotting%20Schwarzschild%20Metric%20Components%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Plot%2C%20Symbol)%3A%0A%20%20%20%20r_plot%20%3D%20Symbol('r'%2C%20positive%3DTrue)%0A%20%20%20%20M_plot%20%3D%20Symbol('M'%2C%20positive%3DTrue)%0A%0A%20%20%20%20%23%20g_tt%20%3D%20-(1%20-%202M%2Fr)%20with%20M%3D1%0A%20%20%20%20g_tt%20%3D%20-(1%20-%202%2Fr_plot)%0A%0A%20%20%20%20%23%20g_rr%20%3D%201%2F(1%20-%202M%2Fr)%0A%20%20%20%20g_rr%20%3D%201%2F(1%20-%202%2Fr_plot)%0A%0A%20%20%20%20Plot(%0A%20%20%20%20%20%20%20%20%5Bg_tt%5D%2C%0A%20%20%20%20%20%20%20%20(r_plot%2C%202.1%2C%2010)%2C%0A%20%20%20%20%20%20%20%20PlotLabel%3D%22Schwarzschild%20g_tt%20(M%3D1)%22%2C%0A%20%20%20%20%20%20%20%20AxesLabel%3D%5B%22r%22%2C%20%22g_tt%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%20At%20the%20event%20horizon%20%24r%20%3D%202M%24%2C%20%24g_%7Btt%7D%20%5Cto%200%24%20and%20%24g_%7Brr%7D%20%5Cto%20%5Cinfty%24%0A%20%20%20%20(coordinate%20singularity).%0A%0A%20%20%20%20%23%23%208.%20Geodesics%20via%20NestList%0A%0A%20%20%20%20Geodesics%20satisfy%3A%0A%0A%20%20%20%20%24%24%5Cfrac%7Bd%5E2%20x%5E%5Cmu%7D%7Bd%5Ctau%5E2%7D%20%2B%20%5CGamma%5E%5Cmu_%7B%5Crho%5Csigma%7D%5Cfrac%7Bdx%5E%5Crho%7D%7Bd%5Ctau%7D%5Cfrac%7Bdx%5E%5Csigma%7D%7Bd%5Ctau%7D%20%3D%200%24%24%0A%0A%20%20%20%20We%20can%20iterate%20the%20geodesic%20equation%20using%20**NestList**.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(NestList)%3A%0A%20%20%20%20import%20numpy%20as%20np%0A%0A%20%20%20%20%23%20Numerical%20geodesic%20on%202-sphere%0A%20%20%20%20%23%20State%3A%20(theta%2C%20phi%2C%20dtheta%2Fdlambda%2C%20dphi%2Fdlambda)%0A%0A%20%20%20%20def%20geodesic_step_sphere(state%2C%20dlambda%3D0.05)%3A%0A%20%20%20%20%20%20%20%20%22%22%22One%20step%20of%20geodesic%20integration%20on%20unit%202-sphere.%22%22%22%0A%20%20%20%20%20%20%20%20theta_g%2C%20phi_g%2C%20dtheta%2C%20dphi%20%3D%20state%0A%0A%20%20%20%20%20%20%20%20%23%20Christoffel%20symbols%3A%20%CE%93%5E%CE%B8_%CF%86%CF%86%20%3D%20-sin(%CE%B8)cos(%CE%B8)%2C%20%CE%93%5E%CF%86_%CE%B8%CF%86%20%3D%20cot(%CE%B8)%0A%20%20%20%20%20%20%20%20sin_theta%20%3D%20np.sin(theta_g)%0A%20%20%20%20%20%20%20%20cos_theta%20%3D%20np.cos(theta_g)%0A%0A%20%20%20%20%20%20%20%20%23%20Geodesic%20equations%0A%20%20%20%20%20%20%20%20d2theta%20%3D%20sin_theta%20*%20cos_theta%20*%20dphi**2%0A%20%20%20%20%20%20%20%20d2phi%20%3D%20-2%20*%20(cos_theta%20%2F%20sin_theta)%20*%20dtheta%20*%20dphi%20if%20sin_theta%20%3E%200.01%20else%200%0A%0A%20%20%20%20%20%20%20%20%23%20Euler%20step%0A%20%20%20%20%20%20%20%20new_theta%20%3D%20theta_g%20%2B%20dtheta%20*%20dlambda%0A%20%20%20%20%20%20%20%20new_phi%20%3D%20phi_g%20%2B%20dphi%20*%20dlambda%0A%20%20%20%20%20%20%20%20new_dtheta%20%3D%20dtheta%20%2B%20d2theta%20*%20dlambda%0A%20%20%20%20%20%20%20%20new_dphi%20%3D%20dphi%20%2B%20d2phi%20*%20dlambda%0A%0A%20%20%20%20%20%20%20%20return%20(new_theta%2C%20new_phi%2C%20new_dtheta%2C%20new_dphi)%0A%0A%20%20%20%20%23%20Initial%20condition%3A%20start%20at%20%CE%B8%3D%CF%80%2F2%2C%20%CF%86%3D0%2C%20moving%20in%20%CF%86%20direction%0A%20%20%20%20initial%20%3D%20(np.pi%2F2%2C%200.0%2C%200.0%2C%201.0)%0A%0A%20%20%20%20%23%20Iterate%20100%20steps%0A%20%20%20%20geodesic_path%20%3D%20NestList(geodesic_step_sphere%2C%20initial%2C%20100)%0A%0A%20%20%20%20%23%20Extract%20positions%0A%20%20%20%20theta_path%20%3D%20%5Bs%5B0%5D%20for%20s%20in%20geodesic_path%5D%0A%20%20%20%20phi_path%20%3D%20%5Bs%5B1%5D%20for%20s%20in%20geodesic_path%5D%0A%20%20%20%20return%20phi_path%2C%20theta_path%0A%0A%0A%40app.cell%0Adef%20_(ListLinePlot%2C%20phi_path%2C%20theta_path)%3A%0A%20%20%20%20%23%20Plot%20geodesic%20on%20sphere%20(great%20circle%20at%20equator)%0A%20%20%20%20geodesic_data%20%3D%20list(zip(phi_path%2C%20theta_path))%0A%0A%20%20%20%20ListLinePlot(%0A%20%20%20%20%20%20%20%20geodesic_data%2C%0A%20%20%20%20%20%20%20%20PlotLabel%3D%22Geodesic%20on%202-Sphere%20(equatorial)%22%2C%0A%20%20%20%20%20%20%20%20AxesLabel%3D%5B%22%CF%86%22%2C%20%22%CE%B8%22%5D%2C%0A%20%20%20%20%20%20%20%20PlotStyle%3D%22Blue%22%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%20The%20geodesic%20at%20the%20equator%20(%24%5Ctheta%20%3D%20%5Cpi%2F2%24)%20stays%20at%20constant%20%24%5Ctheta%24%20-%0A%20%20%20%20it's%20a%20great%20circle!%0A%0A%20%20%20%20%23%23%209.%20Curvature%20of%20Different%20Surfaces%0A%0A%20%20%20%20Let's%20compare%20curvature%20scalars%20using%20**Eigenvalues**%20of%20the%20Ricci%20tensor.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Eigenvalues%2C%20ricci)%3A%0A%20%20%20%20%23%20Eigenvalues%20of%20Ricci%20tensor%20(principal%20curvatures%20scaled)%0A%20%20%20%20ricci_eigenvalues%20%3D%20Eigenvalues(ricci)%0A%20%20%20%20ricci_eigenvalues%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%2010.%20Coordinate%20Transformations%0A%0A%20%20%20%20The%20Jacobian%20determines%20how%20tensors%20transform%20between%20coordinate%20systems.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(cartesian_to_spherical_3d)%3A%0A%20%20%20%20transform%20%3D%20cartesian_to_spherical_3d()%0A%0A%20%20%20%20%23%20Jacobian%20matrix%0A%20%20%20%20J%20%3D%20transform.jacobian%0A%20%20%20%20J%0A%20%20%20%20return%20(transform%2C)%0A%0A%0A%40app.cell%0Adef%20_(Simplify%2C%20transform)%3A%0A%20%20%20%20%23%20Jacobian%20determinant%20(volume%20element)%0A%20%20%20%20det_J%20%3D%20transform.jacobian_determinant%0A%20%20%20%20Simplify(det_J)%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%20volume%20element%20factor%20%24r%5E2%5Csin%5Ctheta%24%20gives%3A%0A%0A%20%20%20%20%24%24dV%20%3D%20r%5E2%5Csin%5Ctheta%5C%2Cdr%5C%2Cd%5Ctheta%5C%2Cd%5Cphi%24%24%0A%0A%20%20%20%20%23%23%2011.%20Einstein%20Summation%20with%20Einsum%0A%0A%20%20%20%20The%20**Einsum**%20function%20implements%20Einstein%20notation%20for%20tensor%20contractions.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Einsum%2C%20Matrix)%3A%0A%20%20%20%20%23%20Matrix%20multiplication%20via%20Einsum%0A%20%20%20%20A%20%3D%20Matrix(%5B%5B1%2C%202%5D%2C%20%5B3%2C%204%5D%5D)%0A%20%20%20%20B%20%3D%20Matrix(%5B%5B5%2C%206%5D%2C%20%5B7%2C%208%5D%5D)%0A%0A%20%20%20%20%23%20C_ik%20%3D%20A_ij%20B_jk%0A%20%20%20%20C%20%3D%20Einsum(%22ij%2Cjk-%3Eik%22%2C%20A%2C%20B)%0A%20%20%20%20C%0A%20%20%20%20return%20(A%2C)%0A%0A%0A%40app.cell%0Adef%20_(A%2C%20Einsum)%3A%0A%20%20%20%20%23%20Trace%20via%20Einsum%0A%20%20%20%20tr_A%20%3D%20Einsum(%22ii-%3E%22%2C%20A)%0A%20%20%20%20tr_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%20%23%23%2012.%20Symmetry%20Optimization%0A%0A%20%20%20%20Derive%20exploits%20tensor%20symmetries%20for%20efficient%20computation.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(SymmetricChristoffel%2C%20symmetric_index_pairs)%3A%0A%20%20%20%20%23%20Unique%20index%20pairs%20for%20symmetric%204%C3%974%20tensor%0A%20%20%20%20pairs%20%3D%20symmetric_index_pairs(4)%0A%20%20%20%20n_unique_metric%20%3D%20len(pairs)%0A%0A%20%20%20%20%23%20Christoffel%20symmetry%20savings%0A%20%20%20%20sc%20%3D%20SymmetricChristoffel(4)%0A%0A%20%20%20%20(n_unique_metric%2C%20sc.num_unique%2C%20sc.num_total%2C%20sc.savings_ratio)%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%20metric%20has%2010%20unique%20components%20(from%2016).%0A%20%20%20%20Christoffel%20symbols%20have%2040%20unique%20values%20(from%2064)%20due%20to%20%24%5CGamma%5E%5Crho_%7B%5Cmu%5Cnu%7D%20%3D%20%5CGamma%5E%5Crho_%7B%5Cnu%5Cmu%7D%24.%0A%0A%20%20%20%20%23%23%20Summary%0A%0A%20%20%20%20We%20demonstrated%20symderive's%20differential%20geometry%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**Metric**%20%7C%20Define%20curved%20spaces%20and%20spacetimes%20%7C%0A%20%20%20%20%7C%20**christoffel_second_kind**%20%7C%20Connection%20coefficients%20%7C%0A%20%20%20%20%7C%20**riemann_tensor**%20%7C%20Riemann%20curvature%20%7C%0A%20%20%20%20%7C%20**ricci_tensor%2Fricci_scalar**%20%7C%20Ricci%20contraction%20%7C%0A%20%20%20%20%7C%20**einstein_tensor**%20%7C%20General%20relativity%20%7C%0A%20%20%20%20%7C%20**Eigenvalues**%20%7C%20Principal%20curvatures%20%7C%0A%20%20%20%20%7C%20**Plot**%20%7C%20Metric%20component%20visualization%20%7C%0A%20%20%20%20%7C%20**NestList**%20%7C%20Geodesic%20iteration%20%7C%0A%20%20%20%20%7C%20**Einsum**%20%7C%20Einstein%20summation%20convention%20%7C%0A%20%20%20%20%7C%20**CoordinateTransformation**%20%7C%20Jacobians%20%7C%0A%0A%20%20%20%20Derive%20provides%20comprehensive%20tools%20for%20differential%20geometry%20and%20general%20relativity!%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
abe8a49789cb418b25ee6ae44c20f71b