
Given point $(a,b)$ in the plane, we want to find its (Euclidean) distance to
$$ H := \{ (t,1/t) \mid t \neq 0 \} . $$

The distance from $(a,b)$ to $(t,1/t)$ is
$$ F(t) := (t-a)^2 + (1/t - b)^2 . $$
First-order optimality condition requires the closest point $(t,1/t)$ on $H$ to be given by a root of
$$ Q(t) := t^4 - at^3 + bt - 1 . $$
There are at most four distinct roots, so just try them all.

## Reduction to solving a cubic and quadratics

To use [Ferrari's method](https://proofwiki.org/wiki/Ferrari%27s_Method), note that
$$ 4Q(t) = (2t^2 - at + s)^2 - \left[(a^2 + 4s)t^2 - 2(as + 2b)t + (s^2 + 4)\right] . $$
In order for the square-bracketed term to be a perfect square, its discriminant must vanish, i.e.,
$$ 4(as + 2b)^2 - 4(a^2 + 4s)(s^2 + 4) = 0 . $$
This simplifies to finding a real root of
$$ P(s) := s^3 + (4 - ab)s + (a^2 - b^2) . $$

## Finding the roots of $Q$ given a real root of $P$

Let $s$ be a real root of $P$.
Then
$$ (as + 2b)^2 = (a^2 + 4s)(s^2 + 4) . $$
Define
$$ c := \sqrt{s^2 + 4} > 0 $$
and
$$ r := \frac{as + 2b}{c} . $$
Then we have
$$ r^2 = a^2 + 4s , $$
and hence
$$ (a^2 + 4s)t^2 - 2(as + 2b)t + (s^2 + 4) = (rt - c)^2 . $$
Plugging back into the above expression for $4Q(t)$ gives
$$ 4Q(t) = (2t^2 - at + s)^2 - (rt - c)^2 = (2t^2 - (a+r)t + (s+c))(2t^2 - (a-r)t + (s-c)) . $$
So the roots of $Q$ are given by the roots of the quadratics
$$ 2t^2 - (a+r)t + (s+c) $$
and
$$ 2t^2 - (a-r)t + (s-c) . $$

<!--

## Finding a real root of the cubic $P$

Define
$$ p := 4 - ab $$
and
$$ q := a^2 - b^2 . $$
Then
$$ P(s) = s^3 + ps + q . $$
Define
$$ d := \frac{q^2}{4} + \frac{p^3}{27} . $$
If $d \geq 0$, then a real root of $P$ is
$$ s = \left( -\frac{q}{2} + \sqrt{d} \right)^{1/3} + \left( -\frac{q}{2} - \sqrt{d} \right)^{1/3} . $$
If $d < 0$, then a real root of $P$ is
$$ s = 2\sqrt{-\frac{p}{3}}\cos\left(\frac13 \arccos\left(\frac{-q/2}{(-p/3)^{3/2}}\right)\right) . $$

-->

