Skip to content

About

Fermat's principle in action: finding the least-time path of light through n layers of media. The 2-layer case is solved exactly (a quartic, via SymPy); the general case via Lagrange multipliers and Newton's method to 50 digits (mpmath). Jupyter notebooks, reusable Python solver, and LaTeX paper with figures. A Python edition of my 2006 paper.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multi-Layer Refraction Problem

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.

4-layer least-time path

Contents

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.

The mathematics in one paragraph

Minimizing the total travel time $f(x_1,\dots,x_n)=\sum_i \sqrt{x_i^2+y_i^2},/,v_i$ subject to $\sum_i x_i = d$ via Lagrange multipliers yields $x_i = y_i\left(\lambda^{-2}v_i^{-2}-1\right)^{-1/2}$, where the multiplier $\lambda$ — which turns out to be exactly the constant $\sin\theta_i / v_i$ of Snell's law — is the unique root of $\psi(\lambda)=\sum_i y_i\left(\lambda^{-2}v_i^{-2}-1\right)^{-1/2} - d$ on $\left(0,\ 1/\max_i v_i\right)$. Newton's method finds it to 50 decimal places in a handful of iterations.

Getting started

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 lab

Then open the notebooks in notebooks/ (run notebook 01 first — it is self-contained, as is 02).

Rebuilding the paper

cd paper/figures && python make_figures.py    # regenerate the figures
cd .. && pdflatex multilayer_refraction.tex && pdflatex multilayer_refraction.tex

Publishing this repo to GitHub

cd 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.)

License

MIT — see LICENSE.

About

Fermat's principle in action: finding the least-time path of light through n layers of media. The 2-layer case is solved exactly (a quartic, via SymPy); the general case via Lagrange multipliers and Newton's method to 50 digits (mpmath). Jupyter notebooks, reusable Python solver, and LaTeX paper with figures. A Python edition of my 2006 paper.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages