Fermat's principle : " The actual path of propagation o flight (trajectory of a light ray) is the path which can be followed by light with inb the lest time, in comparison with all other hypothetical paths between the same two points.''
''Above statement is the original wordings of Fermat (A famous French scienitst of `17th` century)''
Deduction of the law of refraction from Femat's principle
Let the plane `S` be the interface between medium `1` and medium `2` with the refractive indices `n_(1) = c//v_(1)` and `n_(2) = c//v_(2)` Fig. Assumne, as usual, that `n_(1) lt n_(2)`. two points are given-one above the plane `S` (point `A`), the other under plane `S` (point `B`). the various distance are :
`AA_(1) = h_(1), BB_(1) = h_(2), A_(1)B_(1) = l`. We must find the path from `A` to `B` which can be covered by light faster than it can cover any other hypothetical path. Clearly, this path consist `S` has to be found.
First of all, it follows from Fermat's principle that the point `O` must lie on the intersection of `S` and a plane `P`, which is perpendicualr to `S` and passed thorugh `A` and `B`.

Indeed, let us assume that his point does not lie in the plane `P`, let this be point `O_(1)` in Fig. Drop the perpendicular `O_(1)O_(2)` from `O_(1)` onto `P`. Since `AO_(2) lt AO_(1)` and `BO_(1)`, it is clear that the time required to traverse `AO_(2)` is less than that needed to cover tha path `AO_(1)B`. Thus, using Fermat's principle, we see that the first law of refraction is observed : the incident and the refracted rays lie in the same plane as the perpendicualr to the interface at the point
where the ray is refracted. This plane is the plane `P` in Fig. it is called the plane of incidence.
Now let us consider light rays in the plane of incidence Fig. Designate `A_(1)O` as `x` and `OB_(1) = l - x`. The time it takes a ray to travel from `A` to `O` and then from `O` to `B` is
`T = (AO)/(v_(1)) + (OB)/(v_(2)) = sqrt(h_(1)^(2) + x^(2))/(v_(1)) + sqrt(h_(2)^(2) + (l -x)^(2))/(v_(2))` (1)
The time depends on the value of `x`. According to Fermat's principle, the value of `x` must minimize the time `T`. At this value of `x` the derivative `dT//dx` equals zero :
`(dT)/(dx) = (x)/(v_(1)sqrt(h_(1)^(2) + x^(2))) - (l-x)/(v_(2)sqrt(h_(2)^(2) + (l - x)^(2))) =0`. (2)
Now,
`(x)/(sqrt(h_(1)^(2) + x^(2))) sin alpha`, and `(l - x)/(sqrt(h_(2)^(2) + (l - x)^(2))) sin beta`,
Consequently,
`(sin alpha)/(v_(1)) - (sin beta)/(v_(2)) = 0`, or `(sin alpha)/(sin beta) = (v_(1))/(v_(2))`
So, `(sin alpha)/(sin beta) = (c//n_(1))/(c//n_(2)) = (n_(2))/(n_(1))`
Note : Fermat himself could not use Eqn.2 as matghematical anaysis was developed later by Newton and leibniz. To deduce the law of the refraction of light, Fermat used his own maximum and minimum method of calculs, which in fact, correcponded to the subsequently developed method of finding the minimum (maximum) of a function by differentiating it and equating the derivative to zero.