As I mentioned in the history of geometrical optics, you could first notice that light seem to travel in straight lines. But it wasn't soon after that, that the concept that somehow the time it took to get light between A and B was important. And as a matter of fact, light seems to find the path that takes the least time to get between two points. It turns out that's an equivalent principle to Snell's Law. And when you're just tracing rays, you want Snell's Law. But often when deriving properties of lenses, when doing something that might require you to understand the system, the principle of least time is actually much more powerful and a much quicker way to get to answers. So we want to understand that too. The basic setup is let's say we launch some light from A and we don't know what direction it's going to go in. That's what Fermat's principle tell us. But we're in medium n, there's a boundary and the second material n prime. So there's a change in the speed of light on that boundary and we want the light to get to B. So the question is what direction that's consistent with physics should the light go? And eventually, of course, we're going to use that to figure out theta and theta prime are. But let's at first characterize it in a slightly different way. Which is at what point on the boundary, which we'll express by some distance x along the boundary, should the light hit the boundary, such that when it goes on from that point and now a new distance, 1- x to get to B, the time it takes to get from A to B is a minimum? And a good analogy to this is the lifeguard problem. There is a lifeguard at A. There's a drowning swimmer at B. The lifeguard can run quickly on sand. But once the lifeguard has to swim, she slows down. And so then the question is, what point should she choose to enter the water? You might think, well, maybe she should go all the way along the beach and then swim straight out. And you'll find that, that is actually slower than entering the water at some intermediate point. It turns out that's exactly the same problem. So if you're ever saving a drowning swimmer, you can use your optics knowledge. 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.