Skip to content

Commit

Permalink
Rearrange the notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
moble committed Dec 24, 2024
1 parent 9f0bffa commit a0a413d
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 41 deletions.
4 changes: 2 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Run with
# time julia --project=. make.jl && julia --project=. -e 'using LiveServer; serve(dir="build")'
# assuming you are in this `docs` directory (otherwise point the project argument here)
# julia -t 4 --project=. scripts/docs.jl
# assuming you are in this top-level directory

using SphericalFunctions
using Documenter
Expand Down
143 changes: 104 additions & 39 deletions docs/src/notes/conventions.py → docs/notebooks/conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
app = marimo.App(width="medium")


@app.cell
@app.cell(hide_code=True)
def _():
import marimo as mo

import numpy as np
import quaternion
import sympy
return mo, np, quaternion, sympy
# import numpy as np
# import quaternion
return mo, sympy


@app.cell(hide_code=True)
def _(mo):
mo.md(r"""## Three-dimensional space""")
mo.md("""## Three-dimensional space""")
return


Expand All @@ -35,8 +35,25 @@ def three_dimensional_coordinates():


@app.cell
def _(sympy, three_dimensional_coordinates):
def _(mo, sympy, three_dimensional_coordinates):
mo.output.append(mo.md("We define the spherical coordinates in terms of the Cartesian coordinates such that"))
mo.output.append(
[
sympy.Eq(
sympy.Symbol(f"{cartesian}"),
spherical,
evaluate=False
)
for cartesian, spherical in zip(("x", "y", "z"), three_dimensional_coordinates()[0])
]
)
return


@app.cell
def _(mo, three_dimensional_coordinates):
def three_dimensional_metric():
import sympy
(x, y, z), (r, θ, ϕ) = three_dimensional_coordinates()
# The Cartesian metric is just the 3x3 identity matrix
metric_cartesian = sympy.eye(3)
Expand All @@ -46,64 +63,95 @@ def three_dimensional_metric():

return metric_spherical

three_dimensional_metric()
mo.output.append(mo.md("Using the Euclidean metric as the 3x3 identity in Cartesian coordinates, we can transform to spherical to obtain"))
mo.output.append(three_dimensional_metric())
return (three_dimensional_metric,)


@app.cell
def _(sympy, three_dimensional_coordinates):
def _(mo, three_dimensional_coordinates):
def three_dimensional_coordinate_basis():
import sympy
(x, y, z), (r, θ, ϕ) = three_dimensional_coordinates()
basis = [
[sympy.diff(xi, coord) for xi in (x, y, z)]
for coord in (r, θ, ϕ)
]
# Normalize each basis vector
basis = [
[sympy.simplify(comp / sympy.sqrt(sum(b**2 for b in vec))).subs(abs(sympy.sin(θ)), sympy.sin(θ))
for comp in vec]
for vec in basis
sympy.Eq(
sympy.Symbol(rf"\hat{{{symbol}}}"),
sympy.Matrix([
sympy.simplify(comp / sympy.sqrt(sum(b**2 for b in vector))).subs(abs(sympy.sin(θ)), sympy.sin(θ))
for comp in vector
]),
evaluate=False
)
for symbol, vector in zip((r, θ, ϕ), basis)
]

return basis

three_dimensional_coordinate_basis()
mo.output.append(mo.md(
"""
Differentiating the $(x,y,z)$ coordinates with respect to $(r, θ, ϕ)$, we
find the unit spherical coordinate basis vectors to have Cartesian components
"""
))
mo.output.append(three_dimensional_coordinate_basis())
return (three_dimensional_coordinate_basis,)


@app.cell
def _(sympy, three_dimensional_coordinates, three_dimensional_metric):
def _(mo, three_dimensional_coordinates, three_dimensional_metric):
def three_dimensional_volume_element():
import sympy
(x, y, z), (r, θ, ϕ) = three_dimensional_coordinates()
metric_spherical = three_dimensional_metric()
volume_element = sympy.simplify(sympy.sqrt(metric_spherical.det())).subs(abs(sympy.sin(θ)), sympy.sin(θ))

return volume_element

three_dimensional_volume_element()

mo.output.append(mo.md("The volume form in spherical coordinates is"))
mo.output.append(three_dimensional_volume_element())
return (three_dimensional_volume_element,)


@app.cell
def _(mo, three_dimensional_coordinates, three_dimensional_volume_element):
def S2_normalized_volume_element():
import sympy
(x, y, z), (r, θ, ϕ) = three_dimensional_coordinates()
volume_element = three_dimensional_volume_element().subs(r, 1)
# Integrate over the unit sphere
integral = sympy.integrate(sympy.sin(θ), (ϕ, 0, 2*sympy.pi), (θ, 0, sympy.pi))

return volume_element / integral


mo.output.append(mo.md(
"""
Restricting to the unit sphere and normalizing so that the integral
over the sphere is 1, we have the normalized volume element:
"""
))
mo.output.append(S2_normalized_volume_element())
return (S2_normalized_volume_element,)


@app.cell(hide_code=True)
def _(mo):
mo.md(r"""## Four-dimensional space""")
mo.md("""## Four-dimensional space""")
return


@app.cell(hide_code=True)
def _(mo):
mo.md(r"""### Geometric algebra""")
mo.md("""### Geometric algebra""")
return


@app.cell
def _():
import galgebra

from galgebra.ga import Ga
return Ga, galgebra


@app.cell
def _():
def three_dimensional_geometric_algebra():
Expand Down Expand Up @@ -217,43 +265,60 @@ def four_dimensional_volume_element():


@app.cell
def _(four_dimensional_coordinates, four_dimensional_volume_element):
def Spin3_integral():
def _(four_dimensional_coordinates, four_dimensional_volume_element, mo):
def Spin3_normalized_volume_element():
import sympy
(W, X, Y, Z), (R, α, β, γ) = four_dimensional_coordinates()
volume_element = four_dimensional_volume_element()
volume_element = four_dimensional_volume_element().subs(R, 1)
# Integrate over the unit sphere
integral = (1/(16*sympy.pi**2)) * sympy.integrate(abs(sympy.sin(β)), (α, 0, 2*sympy.pi), (β, 0, 2*sympy.pi), (γ, 0, 2*sympy.pi))
integral = sympy.integrate(volume_element, (α, 0, 2*sympy.pi), (β, 0, 2*sympy.pi), (γ, 0, 2*sympy.pi))

return volume_element / integral

return integral

Spin3_integral()
return (Spin3_integral,)
mo.output.append(mo.md(
r"""
Restricting to the unit three-sphere, $\mathrm{Spin}(3)$, and normalizing so that the integral
over the sphere is 1, we have the normalized volume element:
"""
))
mo.output.append(Spin3_normalized_volume_element())
return (Spin3_normalized_volume_element,)


@app.cell
def _(four_dimensional_coordinates, four_dimensional_volume_element):
def SO3_integral():
def _(four_dimensional_coordinates, four_dimensional_volume_element, mo):
def SO3_normalized_volume_element():
import sympy
(W, X, Y, Z), (R, α, β, γ) = four_dimensional_coordinates()
volume_element = four_dimensional_volume_element()
volume_element = four_dimensional_volume_element().subs(R, 1)
# Integrate over the unit sphere
integral = (1/(8*sympy.pi**2)) * sympy.integrate(sympy.sin(β), (α, 0, 2*sympy.pi), (β, 0, sympy.pi), (γ, 0, 2*sympy.pi))
integral = sympy.integrate(volume_element, (α, 0, 2*sympy.pi), (β, 0, sympy.pi), (γ, 0, 2*sympy.pi))

return integral
return volume_element / integral

SO3_integral()
return (SO3_integral,)

mo.output.append(mo.md(
r"""
Restricting to $\mathrm{SO}(3)$ and normalizing so that the integral
over the sphere is 1, we have the normalized volume element:
"""
))
mo.output.append(SO3_normalized_volume_element())
return (SO3_normalized_volume_element,)


@app.cell(hide_code=True)
def _(mo):
mo.md(r"""## Rotations""")
mo.md("""## Rotations""")
return


@app.cell
def _():
# Check that Euler angles (α, β, γ) rotate the basis vectors onto (r, \theta, \phi)


return


Expand Down

0 comments on commit a0a413d

Please sign in to comment.