The speed of light in a medium of index of refraction $n$ is $v=d s / d t=c / n .$ Then the time of transit from $A$ to $B$ is $t=\int_{A}^{B} d t=c^{-1} \int_{A}^{B} n d s .$ By Fermat's principle above, $t$ is stationary. If the path consists of two straight line segments with $n$ constant over each segment, then $\int_{A}^{B} n d s=n_{1} d_{1}+n_{2} d_{2}$ and the problem can be done by ordinary calculus. Thus solve the following problems:
Derive the optical law of reflection. Hint: Let light go from the point $A=\left(x_{1}, y_{1}\right)$ to $B=\left(x_{2}, y_{2}\right)$ via an arbitrary point $P=$ $(x, 0)$ on a mirror along the $x$ axis. Set $d t / d x=(n / c) d D / d x=$
$0,$ where $D=$ distance $A P B,$ and show that then $\theta=\phi$.