Problem of minimum in physics. 
It is necessary to go from a point $A(0,0)$ to a point $B(a,b)$ walking from A to $P(x,0)$ with a speed $v_1$ and then until the point B with a speed $v_2$.
Find where is the point in which it is necessary to abandon x axis in order to have the minimum time to complete the path.
I've called $x$ the distance of A from P.
The function is $$t(x)=\frac{x}{v_1}+\frac{\sqrt{(a-x)^2+b^2}}{v_2}$$
$$\frac{dt}{dx}=\frac{1}{v_1}+\frac{(a-x)*(-1)}{v_2* \sqrt{(a-x)^2+b^2}}=0 \Rightarrow v_2*\sqrt{(a-x)^2+b^2}=v_1*(a-x) \Rightarrow x^2(v_2^2-v_1^2)+x(-2av_2^2+2av_1^2)+(a^2v_2^2+b^2v_2^2-v_1^2a^2)=0$$
The solutions of this equation are $x_{1/2}  =a \pm \frac{v_2 b}{\sqrt{v_1^2-v_2^2}}  $
Putting $\frac{dt}{dx}>0$ it is verified for $0<x<a - \frac{v_2 b}{\sqrt{v_1^2-v_2^2}}$ and for $x>a + \frac{v_2 b}{\sqrt{v_1^2-v_2^2}}$.
So the minimum point is for $a + \frac{v_2 b}{\sqrt{v_1^2-v_2^2}}$
and  the minimum time is
$$t(a + \frac{v_2 b}{\sqrt{v_1^2-v_2^2}})= \frac{b (v_1^2+v_2^2)}{v_1v_2 \sqrt{v_1^2-v_2^2}}+\frac{a}{v_1}$$
I'm not sure that I haven't done mistakes, because in the solution on the book it indicates
$a  - \frac{v_2 b}{\sqrt{v_1^2-v_2^2}}  $  as the solution of minimum.
and  the minimum time
$$t(a - \frac{v_2 b}{\sqrt{v_1^2-v_2^2}})= \frac{b\sqrt{v_1^2-v_2^2}}{v_1v_2}+\frac{a}{v_1}$$
but, in particular , it distinguishes the case of $\frac{v_2^2}{v_1^2}\ge \frac{a^2}{a^2+b^2}$
in which the minimum time is possible walking from A to B directly.

You are correct that
$$ \frac{dt}{dx} = \frac{1}{v_1} - \frac{a-x}{v_2 \sqrt{(a-x)^2+b^2}} \tag1$$
and that $\frac{dt}{dx} = 0$ implies
$$ v_2 \sqrt{(a-x)^2+b^2} = v_1 (a-x), \tag2$$
which (I think--I did not check your arithmetic here) implies
$$ x^2(v_2^2-v_1^2)+x(-2av_2^2+2av_1^2)+(a^2v_2^2+b^2v_2^2-v_1^2a^2) = 0. \tag3$$
But you seem to be assuming (incorrectly) that Equation $(3)$ implies Equation $(2)$.
It does not. Equation $(3)$ does imply
$$ v_2 \sqrt{(a-x)^2+b^2} = \pm v_1 (a-x), $$
but this is not the same thing.
Also, the region where the left side of Equation $(3)$ is positive does not correspond to the region where $\frac{dt}{dx}$ is positive.
What Equation $(3)$ gives you is two possible points at which $\frac{dt}{dx}$ might be zero. To determine which points are actual zeros, compare each of them against Equation $(2)$.
Assuming that $v_1$ and $v_2$ both are positive,
in Equation $(2)$ we see that the left side is positive and that
therefore $a - x$ must also be positive.
That is, $x < a.$ Hence of the two roots of Equation $(3)$, the only one that can be a zero of $\frac{dt}{dx}$ is the one that is less than $a,$ namely
$$ x_0 = a - \frac{v_2 b}{\sqrt{v_1^2-v_2^2}}. $$
To determine whether this is a local minimum or a local maximum,
you must examine the sign of $\frac{dt}{dx}$ for values of $x$
less than $x_0$ or greater than $x_0$,
not the values of the left-hand side of Equation $(3).$
