So it turns out that's a relatively simple problem.

The first thing we note is that our optical path length, if you divide

that by z, the speed of light, it gives you the time of the travel.

So this sort of indicates that optical path length is in important quantity.

We can just calculate this optical path length.

We've already stated that the optical path length is the integral of the refractive

index along the path.

In this case, that would simply be n times the distance a,

to the point here where you enter and then n prime along the rest of the ray.

So that's what those two expressions indicate.

That gives us our optical path.

Then we simply let that be stationary.

Formally, Fermat's principle says that the path length over the time is stationary.

Mostly that means minimum, but

there's a couple of rare cases where that's not true.

We'll take the derivative, set it equal to 0.

And when we do that, we get n times this quantity.

And n prime times that quantity equals 0.

Well, if you look at this quantity,

x over the hypotenuse is exactly the sign of theta.

And this quantity here is 1- x.

That's this distance here over the hypotenuse of this triangle.

That's the sign of theta prime.

So what we see popping out of this is Snell's Law.

So what we learned from this is Fermat's principle is consistent with Snell's Law.

You can do the same derivation for the reflected version of Snell's Law.

It's much simpler and you come up with the same answer.

So the point is, is Fermat's principle and Snell's Law are equivalent.

And we're going to use Fermat's principle in certain times to

derive important quantities, for example, about lenses.