%Let
%\begin{align}
%&f_i \equiv {\left(x_i -a \right)}^2 + {\left(y_i -b\right)}^2 -R^2 \label{eqn:f_i}
%\end{align}
%be the algebraic distance from the experimental point $\left( x_i,y_i \right)$ to the circle ${\left(x_i -a \right)}^2 + {\left(y_i -b\right)}^2 +R^2 = 0$.
Let us define
\begin{align}
&f_i \equiv {\left(x_i -a \right)}^2 + {\left(y_i -b\right)}^2 -R^2 \label{eqn:f_i}
\end{align}
%be the algebraic distance from the experimental point $\left( x_i,y_i \right)$ to the circle ${\left(x_i -a \right)}^2 + {\left(y_i -b\right)}^2 +R^2 = 0$.
The simplest algebraic model to fit a circle ${\left(x_i -a \right)}^2 + {\left(y_i -b\right)}^2 +R^2 = 0$ to a set of points would minimize the algebraic expression \cite{chernov,bullock}
\begin{align}
&\mathcal{F}_1 = \sum_i f_i^2 \label{eqn:kasa_0}
\end{align}
Note that $f_i$ does \textit{not} represent the square orthogonal distance to the circle of the point $(x_i,y_i)$ defined in Eqn.~\ref{eqn:ortho-dist}. However, $f_i$ is small if and only if the point lies near to the circle: for this reason, some authors \cite{Pratt:1987:DLF:37402.37420} call $f_i$ the \textit{algebraic distance} from $(x_i,y_i)$ to the circle. This approach is also the base for the K\r{a}sa, Pratt, and Taubin algorithms.\\

The change of parameters described in Eqns.~\ref{eqn:geom-alg-conv-0} and~\ref{eqn:geom-alg-conv} with the choice $A\equiv 1$ linearises the derivatives of the objective function $\mathcal{F}_1$:
\begin{align}
&\mathcal{F}_1 = \sum_i { \left( x_i^2 + y_i^2 + B x_i + C y_i + D \right) }^2
\end{align}
Now differentiating $\mathcal{F}_1$ with respect to the parameters $B,C,D$ yields a system of linear equations, by solving which we can compute $B,C,D$ and, finally, convert them back to the geometrical parameters $a,b,R$ \cite{chernov}.


\subsection{Implementation of the ``math'' algorithm}
We will solve the problem in a suitable $(u,v)$ coordinate system, and then transform the solutions back to the laboratory frame $(x,y)$ \cite{bullock}. Writing
\begin{align}
\bar{x} &= \frac{1}{n}\sum_i x_i  &\bar{y} &= \frac{1}{n}\sum_i y_i \qquad\qquad\\
u_i &\equiv x_i -\bar{x}  &v_i &\equiv y_i -\bar{y} \qquad\qquad\label{eqn:math_change_coord}
\end{align}
we obtain:
\begin{align}
&{\mathcal{F}_1}' = \sum_i g_i^2\\
&g_i = {\left(u_i - u_c \right)}^2 + {\left(v_i - v_c \right)}^2 -R^2 \label{eqn:g_i}
\end{align}
where $(u_c,v_c)$ are the coordinates of the centre of the circle, as computed in the $(u,v)$ frame:
\begin{align}
&u_c = a - \bar{x}\\
&v_c = b - \bar{y}
\end{align}

In order to minimize ${\mathcal{F}_1}'$ we compute its derivatives with respect to the parameters $u_c$, $v_c$ and $R^2$:
\begin{align}
&\frac{\partial {\mathcal{F}_1}'}{\partial R^2} = 2 \sum_i g_i \,\frac{\partial g_i}{\partial R^2} = -2 \sum_i g_i\\
&\frac{\partial {\mathcal{F}_1}'}{\partial u_c} =  2 \sum_i g_i \,\frac{\partial g_i}{\partial u_c} = -4 \sum_i u_i\, g_i + 4 u_c \sum_i g_i\\
&\frac{\partial {\mathcal{F}_1}'}{\partial v_c} =  2 \sum_i g_i \,\frac{\partial g_i}{\partial v_c} = -4 \sum_i v_i\, g_i + 4 u_c \sum_i g_i
\end{align}
and then set them to zero. This system gives the unique solution
\begin{align}
&\sum_i g_i = 0 \qquad \sum_i u_i\, g_i = 0 \qquad \sum_i v_i\, g_i = 0\label{eqn:math_0}
\end{align}
Now let
\begin{align}
&S_u \equiv \sum_i u_i \qquad S_{uu} \equiv \sum_i u_i^2 \qquad S_{uuu} \equiv \sum_i u_i^3 \quad \mbox{etc.}
\end{align}
and similarly for $S_v, S_{uv}$ and so on, where $S_u = S_v = 0$ by definition.
Adopting this notation, if we expand Eqns.~\ref{eqn:math_0} we obtain the system
\begin{align}
&u_c S_{uu} + v_c S_{uv} = \frac{1}{2} \left(S_{uuu} + S_{uvv}\right)\\
&u_c S_{uv} + v_c S_{vv} = \frac{1}{2} \left(S_{vvv} + S_{uuv}\right)\\
&n \left( u_c^2 + v_c^2 - R^2 \right) + S_{uu} + S_{vv} = 0
\end{align}
which in turn yelds the solutions
\begin{align}
&u_c = \frac{\frac{S_{uv}}{2} \left(S_{vvv} + S_{uuv}\right) - \frac{S_{vv}}{2} \left(S_{uuu} + S_{uvv}\right)}{ S_{uv}^2 - S_{vv}^2 }\\
&v_c = \frac{\frac{1}{2}\left(S_{uuu} + S_{uvv}\right) - u_cS_{uu}}{S_{uv}}\\
&R^2 = u_c^2 + v_c^2 + \frac{S_{uu} + S_{vv}}{n}
\end{align}
The centre of the circle in the original coordinate system will be $(a,b) = (u_c,v_c) + (\bar{x},\bar{y})$.