Rafael Espericueta — Professor of Mathematics Emeritus, Bakersfield College
Light travels at different speeds through different media, but refracts at layer boundaries in order to traverse the least-time path (Fermat's principle). This project plays light's game: finding the least-time path through any number of layers of media, where each medium induces a different speed.
This is a Python edition of my November 2006 paper Multi-Layer Refraction Problem, in which the numerical examples were originally computed with Maple 11. All computations are reproduced here — to the same 50 significant digits — using SymPy and mpmath, with Jupyter notebooks that walk the reader through every step.
| Path | Description |
|---|---|
notebooks/01_two_layer_problem.ipynb |
The 2-layer case, solved exactly: derive the quartic with SymPy, extract the closed-form root, verify Snell's law, plot the path. |
notebooks/02_n_layer_problem.ipynb |
The general n-layer case: Lagrange multipliers reduce the problem to a single equation ψ(λ) = 0, solved by Newton's method to 50 digits. Reproduces the paper's 3-layer and 4-layer examples digit for digit, plus a 12-layer bonus example. |
src/multilayer.py |
Reusable solver module (safeguarded Newton iteration, arbitrary precision via mpmath). |
src/plotting.py |
Matplotlib helpers that draw layered media and least-time paths in the style of the original figures. |
paper/multilayer_refraction.tex |
LaTeX source of the paper (Python edition). |
paper/multilayer_refraction.pdf |
Compiled PDF. |
paper/figures/make_figures.py |
Regenerates every figure in the paper. |
Minimizing the total travel time
git clone https://github.com/<your-username>/multilayer-refraction.git
cd multilayer-refraction
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
jupyter labThen open the notebooks in notebooks/ (run notebook 01 first — it is
self-contained, as is 02).
cd paper/figures && python make_figures.py # regenerate the figures
cd .. && pdflatex multilayer_refraction.tex && pdflatex multilayer_refraction.texcd multilayer-refraction
git init
git add .
git commit -m "Multi-layer refraction problem: notebooks, solver, and paper"
git branch -M main
git remote add origin https://github.com/<your-username>/multilayer-refraction.git
git push -u origin main(GitHub renders both notebooks — including all output, figures, and LaTeX math — directly in the browser.)
MIT — see LICENSE.
