Distance on a great circle

Percentage Accurate: 62.2% → 78.3%
Time: 2.2min
Alternatives: 25
Speedup: 1.1×

Specification

?
\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_0\right) \cdot t_0\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1}}{\sqrt{1 - t_1}}\right) \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_1
         (+
          (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
          (* (* (* (cos phi1) (cos phi2)) t_0) t_0))))
   (* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) / 2.0));
	double t_1 = pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0);
	return R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: t_1
    t_0 = sin(((lambda1 - lambda2) / 2.0d0))
    t_1 = (sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0)
    code = r * (2.0d0 * atan2(sqrt(t_1), sqrt((1.0d0 - t_1))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.sin(((lambda1 - lambda2) / 2.0));
	double t_1 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (((Math.cos(phi1) * Math.cos(phi2)) * t_0) * t_0);
	return R * (2.0 * Math.atan2(Math.sqrt(t_1), Math.sqrt((1.0 - t_1))));
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(((lambda1 - lambda2) / 2.0))
	t_1 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (((math.cos(phi1) * math.cos(phi2)) * t_0) * t_0)
	return R * (2.0 * math.atan2(math.sqrt(t_1), math.sqrt((1.0 - t_1))))
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_0) * t_0))
	return Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1)))))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 2.0));
	t_1 = (sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0);
	tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$1], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_0\right) \cdot t_0\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1}}{\sqrt{1 - t_1}}\right)
\end{array}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 25 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 62.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_0\right) \cdot t_0\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1}}{\sqrt{1 - t_1}}\right) \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_1
         (+
          (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
          (* (* (* (cos phi1) (cos phi2)) t_0) t_0))))
   (* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) / 2.0));
	double t_1 = pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0);
	return R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: t_1
    t_0 = sin(((lambda1 - lambda2) / 2.0d0))
    t_1 = (sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0)
    code = r * (2.0d0 * atan2(sqrt(t_1), sqrt((1.0d0 - t_1))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.sin(((lambda1 - lambda2) / 2.0));
	double t_1 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (((Math.cos(phi1) * Math.cos(phi2)) * t_0) * t_0);
	return R * (2.0 * Math.atan2(Math.sqrt(t_1), Math.sqrt((1.0 - t_1))));
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(((lambda1 - lambda2) / 2.0))
	t_1 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (((math.cos(phi1) * math.cos(phi2)) * t_0) * t_0)
	return R * (2.0 * math.atan2(math.sqrt(t_1), math.sqrt((1.0 - t_1))))
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_0) * t_0))
	return Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1)))))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 2.0));
	t_1 = (sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0);
	tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$1], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_0\right) \cdot t_0\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1}}{\sqrt{1 - t_1}}\right)
\end{array}
\end{array}

Alternative 1: 78.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := \sqrt{\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \left(t_0 \cdot t_0\right), {\left(\mathsf{fma}\left(\sin \left(\frac{\phi_1}{2}\right), \cos \left(\frac{\phi_2}{2}\right), \sin \left(\frac{\phi_2}{2}\right) \cdot \left(-\cos \left(\frac{\phi_1}{2}\right)\right)\right)\right)}^{2}\right)}\\ t_2 := {\left(\sin \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \cos \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)}^{2}\\ \mathbf{if}\;\lambda_2 \leq -4.1 \cdot 10^{-5} \lor \neg \left(\lambda_2 \leq 1.05 \cdot 10^{-5}\right):\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right) + t_2\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{1 - \left(t_2 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_1 \cdot 0.5\right)}^{2}\right)\right)}}\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_1
         (sqrt
          (fma
           (cos phi1)
           (* (cos phi2) (* t_0 t_0))
           (pow
            (fma
             (sin (/ phi1 2.0))
             (cos (/ phi2 2.0))
             (* (sin (/ phi2 2.0)) (- (cos (/ phi1 2.0)))))
            2.0))))
        (t_2
         (pow
          (-
           (* (sin (* phi2 0.5)) (cos (* phi1 0.5)))
           (* (cos (* phi2 0.5)) (sin (* phi1 0.5))))
          2.0)))
   (if (or (<= lambda2 -4.1e-5) (not (<= lambda2 1.05e-5)))
     (*
      R
      (*
       2.0
       (atan2
        t_1
        (sqrt
         (-
          1.0
          (+
           (* (cos phi1) (* (cos phi2) (pow (sin (* lambda2 -0.5)) 2.0)))
           t_2))))))
     (*
      R
      (*
       2.0
       (atan2
        t_1
        (sqrt
         (-
          1.0
          (+
           t_2
           (*
            (cos phi1)
            (* (cos phi2) (pow (sin (* lambda1 0.5)) 2.0))))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) / 2.0));
	double t_1 = sqrt(fma(cos(phi1), (cos(phi2) * (t_0 * t_0)), pow(fma(sin((phi1 / 2.0)), cos((phi2 / 2.0)), (sin((phi2 / 2.0)) * -cos((phi1 / 2.0)))), 2.0)));
	double t_2 = pow(((sin((phi2 * 0.5)) * cos((phi1 * 0.5))) - (cos((phi2 * 0.5)) * sin((phi1 * 0.5)))), 2.0);
	double tmp;
	if ((lambda2 <= -4.1e-5) || !(lambda2 <= 1.05e-5)) {
		tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - ((cos(phi1) * (cos(phi2) * pow(sin((lambda2 * -0.5)), 2.0))) + t_2)))));
	} else {
		tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - (t_2 + (cos(phi1) * (cos(phi2) * pow(sin((lambda1 * 0.5)), 2.0))))))));
	}
	return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = sqrt(fma(cos(phi1), Float64(cos(phi2) * Float64(t_0 * t_0)), (fma(sin(Float64(phi1 / 2.0)), cos(Float64(phi2 / 2.0)), Float64(sin(Float64(phi2 / 2.0)) * Float64(-cos(Float64(phi1 / 2.0))))) ^ 2.0)))
	t_2 = Float64(Float64(sin(Float64(phi2 * 0.5)) * cos(Float64(phi1 * 0.5))) - Float64(cos(Float64(phi2 * 0.5)) * sin(Float64(phi1 * 0.5)))) ^ 2.0
	tmp = 0.0
	if ((lambda2 <= -4.1e-5) || !(lambda2 <= 1.05e-5))
		tmp = Float64(R * Float64(2.0 * atan(t_1, sqrt(Float64(1.0 - Float64(Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(lambda2 * -0.5)) ^ 2.0))) + t_2))))));
	else
		tmp = Float64(R * Float64(2.0 * atan(t_1, sqrt(Float64(1.0 - Float64(t_2 + Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(lambda1 * 0.5)) ^ 2.0)))))))));
	end
	return tmp
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[Sin[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision] + N[(N[Sin[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision] * (-N[Cos[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[(N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]}, If[Or[LessEqual[lambda2, -4.1e-5], N[Not[LessEqual[lambda2, 1.05e-5]], $MachinePrecision]], N[(R * N[(2.0 * N[ArcTan[t$95$1 / N[Sqrt[N[(1.0 - N[(N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(lambda2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[t$95$1 / N[Sqrt[N[(1.0 - N[(t$95$2 + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(lambda1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \sqrt{\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \left(t_0 \cdot t_0\right), {\left(\mathsf{fma}\left(\sin \left(\frac{\phi_1}{2}\right), \cos \left(\frac{\phi_2}{2}\right), \sin \left(\frac{\phi_2}{2}\right) \cdot \left(-\cos \left(\frac{\phi_1}{2}\right)\right)\right)\right)}^{2}\right)}\\
t_2 := {\left(\sin \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \cos \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)}^{2}\\
\mathbf{if}\;\lambda_2 \leq -4.1 \cdot 10^{-5} \lor \neg \left(\lambda_2 \leq 1.05 \cdot 10^{-5}\right):\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right) + t_2\right)}}\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{1 - \left(t_2 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_1 \cdot 0.5\right)}^{2}\right)\right)}}\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 2: 78.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{\phi_1}{2}\right)\\ t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_2 := \cos \left(\frac{\phi_2}{2}\right)\\ t_3 := \sin \left(\frac{\phi_2}{2}\right)\\ t_4 := \sin \left(\frac{\phi_1}{2}\right)\\ t_5 := \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \left(t_1 \cdot t_1\right), {\left(\mathsf{fma}\left(t_4, t_2, t_3 \cdot \left(-t_0\right)\right)\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \left(\log \left(e^{t_5}\right) \cdot \sqrt[3]{{t_5}^{3}}\right), {\left(t_0 \cdot t_3 - t_4 \cdot t_2\right)}^{2}\right)}}\right) \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (cos (/ phi1 2.0)))
        (t_1 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_2 (cos (/ phi2 2.0)))
        (t_3 (sin (/ phi2 2.0)))
        (t_4 (sin (/ phi1 2.0)))
        (t_5 (sin (* (- lambda1 lambda2) 0.5))))
   (*
    R
    (*
     2.0
     (atan2
      (sqrt
       (fma
        (cos phi1)
        (* (cos phi2) (* t_1 t_1))
        (pow (fma t_4 t_2 (* t_3 (- t_0))) 2.0)))
      (sqrt
       (-
        1.0
        (fma
         (cos phi2)
         (* (cos phi1) (* (log (exp t_5)) (cbrt (pow t_5 3.0))))
         (pow (- (* t_0 t_3) (* t_4 t_2)) 2.0)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos((phi1 / 2.0));
	double t_1 = sin(((lambda1 - lambda2) / 2.0));
	double t_2 = cos((phi2 / 2.0));
	double t_3 = sin((phi2 / 2.0));
	double t_4 = sin((phi1 / 2.0));
	double t_5 = sin(((lambda1 - lambda2) * 0.5));
	return R * (2.0 * atan2(sqrt(fma(cos(phi1), (cos(phi2) * (t_1 * t_1)), pow(fma(t_4, t_2, (t_3 * -t_0)), 2.0))), sqrt((1.0 - fma(cos(phi2), (cos(phi1) * (log(exp(t_5)) * cbrt(pow(t_5, 3.0)))), pow(((t_0 * t_3) - (t_4 * t_2)), 2.0))))));
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = cos(Float64(phi1 / 2.0))
	t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_2 = cos(Float64(phi2 / 2.0))
	t_3 = sin(Float64(phi2 / 2.0))
	t_4 = sin(Float64(phi1 / 2.0))
	t_5 = sin(Float64(Float64(lambda1 - lambda2) * 0.5))
	return Float64(R * Float64(2.0 * atan(sqrt(fma(cos(phi1), Float64(cos(phi2) * Float64(t_1 * t_1)), (fma(t_4, t_2, Float64(t_3 * Float64(-t_0))) ^ 2.0))), sqrt(Float64(1.0 - fma(cos(phi2), Float64(cos(phi1) * Float64(log(exp(t_5)) * cbrt((t_5 ^ 3.0)))), (Float64(Float64(t_0 * t_3) - Float64(t_4 * t_2)) ^ 2.0)))))))
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Sin[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[Sin[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$5 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision] + N[Power[N[(t$95$4 * t$95$2 + N[(t$95$3 * (-t$95$0)), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[(N[Log[N[Exp[t$95$5], $MachinePrecision]], $MachinePrecision] * N[Power[N[Power[t$95$5, 3.0], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(t$95$0 * t$95$3), $MachinePrecision] - N[(t$95$4 * t$95$2), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\frac{\phi_1}{2}\right)\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := \cos \left(\frac{\phi_2}{2}\right)\\
t_3 := \sin \left(\frac{\phi_2}{2}\right)\\
t_4 := \sin \left(\frac{\phi_1}{2}\right)\\
t_5 := \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \left(t_1 \cdot t_1\right), {\left(\mathsf{fma}\left(t_4, t_2, t_3 \cdot \left(-t_0\right)\right)\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \left(\log \left(e^{t_5}\right) \cdot \sqrt[3]{{t_5}^{3}}\right), {\left(t_0 \cdot t_3 - t_4 \cdot t_2\right)}^{2}\right)}}\right)
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 3: 78.4% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{\phi_1}{2}\right)\\ t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_2 := t_1 \cdot t_1\\ t_3 := \sin \left(\frac{\phi_1}{2}\right)\\ t_4 := \cos \left(\frac{\phi_2}{2}\right)\\ t_5 := \sin \left(\frac{\phi_2}{2}\right)\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot t_2, {\left(\mathsf{fma}\left(t_3, t_4, t_5 \cdot \left(-t_0\right)\right)\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot t_2, {\left(t_0 \cdot t_5 - t_3 \cdot t_4\right)}^{2}\right)}}\right) \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (cos (/ phi1 2.0)))
        (t_1 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_2 (* t_1 t_1))
        (t_3 (sin (/ phi1 2.0)))
        (t_4 (cos (/ phi2 2.0)))
        (t_5 (sin (/ phi2 2.0))))
   (*
    R
    (*
     2.0
     (atan2
      (sqrt
       (fma
        (cos phi1)
        (* (cos phi2) t_2)
        (pow (fma t_3 t_4 (* t_5 (- t_0))) 2.0)))
      (sqrt
       (-
        1.0
        (fma
         (cos phi2)
         (* (cos phi1) t_2)
         (pow (- (* t_0 t_5) (* t_3 t_4)) 2.0)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos((phi1 / 2.0));
	double t_1 = sin(((lambda1 - lambda2) / 2.0));
	double t_2 = t_1 * t_1;
	double t_3 = sin((phi1 / 2.0));
	double t_4 = cos((phi2 / 2.0));
	double t_5 = sin((phi2 / 2.0));
	return R * (2.0 * atan2(sqrt(fma(cos(phi1), (cos(phi2) * t_2), pow(fma(t_3, t_4, (t_5 * -t_0)), 2.0))), sqrt((1.0 - fma(cos(phi2), (cos(phi1) * t_2), pow(((t_0 * t_5) - (t_3 * t_4)), 2.0))))));
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = cos(Float64(phi1 / 2.0))
	t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_2 = Float64(t_1 * t_1)
	t_3 = sin(Float64(phi1 / 2.0))
	t_4 = cos(Float64(phi2 / 2.0))
	t_5 = sin(Float64(phi2 / 2.0))
	return Float64(R * Float64(2.0 * atan(sqrt(fma(cos(phi1), Float64(cos(phi2) * t_2), (fma(t_3, t_4, Float64(t_5 * Float64(-t_0))) ^ 2.0))), sqrt(Float64(1.0 - fma(cos(phi2), Float64(cos(phi1) * t_2), (Float64(Float64(t_0 * t_5) - Float64(t_3 * t_4)) ^ 2.0)))))))
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[Sin[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[Cos[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$5 = N[Sin[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * t$95$2), $MachinePrecision] + N[Power[N[(t$95$3 * t$95$4 + N[(t$95$5 * (-t$95$0)), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * t$95$2), $MachinePrecision] + N[Power[N[(N[(t$95$0 * t$95$5), $MachinePrecision] - N[(t$95$3 * t$95$4), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\frac{\phi_1}{2}\right)\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := t_1 \cdot t_1\\
t_3 := \sin \left(\frac{\phi_1}{2}\right)\\
t_4 := \cos \left(\frac{\phi_2}{2}\right)\\
t_5 := \sin \left(\frac{\phi_2}{2}\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot t_2, {\left(\mathsf{fma}\left(t_3, t_4, t_5 \cdot \left(-t_0\right)\right)\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot t_2, {\left(t_0 \cdot t_5 - t_3 \cdot t_4\right)}^{2}\right)}}\right)
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 4: 78.4% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := t_0 \cdot t_0\\ t_2 := \sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right)\\ t_3 := \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot t_1, {\left(t_2 - t_3\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot t_1, {\left(t_3 - t_2\right)}^{2}\right)}}\right) \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_1 (* t_0 t_0))
        (t_2 (* (sin (/ phi1 2.0)) (cos (/ phi2 2.0))))
        (t_3 (* (cos (/ phi1 2.0)) (sin (/ phi2 2.0)))))
   (*
    R
    (*
     2.0
     (atan2
      (sqrt (fma (cos phi1) (* (cos phi2) t_1) (pow (- t_2 t_3) 2.0)))
      (sqrt
       (- 1.0 (fma (cos phi2) (* (cos phi1) t_1) (pow (- t_3 t_2) 2.0)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) / 2.0));
	double t_1 = t_0 * t_0;
	double t_2 = sin((phi1 / 2.0)) * cos((phi2 / 2.0));
	double t_3 = cos((phi1 / 2.0)) * sin((phi2 / 2.0));
	return R * (2.0 * atan2(sqrt(fma(cos(phi1), (cos(phi2) * t_1), pow((t_2 - t_3), 2.0))), sqrt((1.0 - fma(cos(phi2), (cos(phi1) * t_1), pow((t_3 - t_2), 2.0))))));
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = Float64(t_0 * t_0)
	t_2 = Float64(sin(Float64(phi1 / 2.0)) * cos(Float64(phi2 / 2.0)))
	t_3 = Float64(cos(Float64(phi1 / 2.0)) * sin(Float64(phi2 / 2.0)))
	return Float64(R * Float64(2.0 * atan(sqrt(fma(cos(phi1), Float64(cos(phi2) * t_1), (Float64(t_2 - t_3) ^ 2.0))), sqrt(Float64(1.0 - fma(cos(phi2), Float64(cos(phi1) * t_1), (Float64(t_3 - t_2) ^ 2.0)))))))
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[Cos[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * t$95$1), $MachinePrecision] + N[Power[N[(t$95$2 - t$95$3), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * t$95$1), $MachinePrecision] + N[Power[N[(t$95$3 - t$95$2), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := t_0 \cdot t_0\\
t_2 := \sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right)\\
t_3 := \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot t_1, {\left(t_2 - t_3\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot t_1, {\left(t_3 - t_2\right)}^{2}\right)}}\right)
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 5: 73.5% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \phi_1 \cdot \cos \phi_2\\ t_1 := \cos \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\\ t_2 := \sin \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right)\\ t_3 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ \mathbf{if}\;\lambda_1 \leq -1.55 \cdot 10^{-7} \lor \neg \left(\lambda_1 \leq 6 \cdot 10^{-12}\right):\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_3 \cdot \left(t_3 \cdot t_0\right)}}{\sqrt{e^{\mathsf{log1p}\left(-\mathsf{fma}\left(t_0, 0.5 + -0.5 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right), {\left(t_1 - t_2\right)}^{2}\right)\right)}}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \left(t_3 \cdot t_3\right), {\left(\mathsf{fma}\left(\sin \left(\frac{\phi_1}{2}\right), \cos \left(\frac{\phi_2}{2}\right), \sin \left(\frac{\phi_2}{2}\right) \cdot \left(-\cos \left(\frac{\phi_1}{2}\right)\right)\right)\right)}^{2}\right)}}{\sqrt{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right) + {\left(t_2 - t_1\right)}^{2}\right)}}\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (cos phi1) (cos phi2)))
        (t_1 (* (cos (* phi2 0.5)) (sin (* phi1 0.5))))
        (t_2 (* (sin (* phi2 0.5)) (cos (* phi1 0.5))))
        (t_3 (sin (/ (- lambda1 lambda2) 2.0))))
   (if (or (<= lambda1 -1.55e-7) (not (<= lambda1 6e-12)))
     (*
      R
      (*
       2.0
       (atan2
        (sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* t_3 (* t_3 t_0))))
        (sqrt
         (exp
          (log1p
           (-
            (fma
             t_0
             (+
              0.5
              (*
               -0.5
               (+
                (* (cos lambda1) (cos lambda2))
                (* (sin lambda1) (sin lambda2)))))
             (pow (- t_1 t_2) 2.0)))))))))
     (*
      R
      (*
       2.0
       (atan2
        (sqrt
         (fma
          (cos phi1)
          (* (cos phi2) (* t_3 t_3))
          (pow
           (fma
            (sin (/ phi1 2.0))
            (cos (/ phi2 2.0))
            (* (sin (/ phi2 2.0)) (- (cos (/ phi1 2.0)))))
           2.0)))
        (sqrt
         (-
          1.0
          (+
           (* (cos phi1) (* (cos phi2) (pow (sin (* lambda2 -0.5)) 2.0)))
           (pow (- t_2 t_1) 2.0))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos(phi1) * cos(phi2);
	double t_1 = cos((phi2 * 0.5)) * sin((phi1 * 0.5));
	double t_2 = sin((phi2 * 0.5)) * cos((phi1 * 0.5));
	double t_3 = sin(((lambda1 - lambda2) / 2.0));
	double tmp;
	if ((lambda1 <= -1.55e-7) || !(lambda1 <= 6e-12)) {
		tmp = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_3 * (t_3 * t_0)))), sqrt(exp(log1p(-fma(t_0, (0.5 + (-0.5 * ((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2))))), pow((t_1 - t_2), 2.0)))))));
	} else {
		tmp = R * (2.0 * atan2(sqrt(fma(cos(phi1), (cos(phi2) * (t_3 * t_3)), pow(fma(sin((phi1 / 2.0)), cos((phi2 / 2.0)), (sin((phi2 / 2.0)) * -cos((phi1 / 2.0)))), 2.0))), sqrt((1.0 - ((cos(phi1) * (cos(phi2) * pow(sin((lambda2 * -0.5)), 2.0))) + pow((t_2 - t_1), 2.0))))));
	}
	return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(cos(phi1) * cos(phi2))
	t_1 = Float64(cos(Float64(phi2 * 0.5)) * sin(Float64(phi1 * 0.5)))
	t_2 = Float64(sin(Float64(phi2 * 0.5)) * cos(Float64(phi1 * 0.5)))
	t_3 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	tmp = 0.0
	if ((lambda1 <= -1.55e-7) || !(lambda1 <= 6e-12))
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_3 * Float64(t_3 * t_0)))), sqrt(exp(log1p(Float64(-fma(t_0, Float64(0.5 + Float64(-0.5 * Float64(Float64(cos(lambda1) * cos(lambda2)) + Float64(sin(lambda1) * sin(lambda2))))), (Float64(t_1 - t_2) ^ 2.0)))))))));
	else
		tmp = Float64(R * Float64(2.0 * atan(sqrt(fma(cos(phi1), Float64(cos(phi2) * Float64(t_3 * t_3)), (fma(sin(Float64(phi1 / 2.0)), cos(Float64(phi2 / 2.0)), Float64(sin(Float64(phi2 / 2.0)) * Float64(-cos(Float64(phi1 / 2.0))))) ^ 2.0))), sqrt(Float64(1.0 - Float64(Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(lambda2 * -0.5)) ^ 2.0))) + (Float64(t_2 - t_1) ^ 2.0)))))));
	end
	return tmp
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[lambda1, -1.55e-7], N[Not[LessEqual[lambda1, 6e-12]], $MachinePrecision]], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$3 * N[(t$95$3 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[Exp[N[Log[1 + (-N[(t$95$0 * N[(0.5 + N[(-0.5 * N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[N[(t$95$1 - t$95$2), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision])], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[(t$95$3 * t$95$3), $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[Sin[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision] + N[(N[Sin[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision] * (-N[Cos[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(lambda2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[N[(t$95$2 - t$95$1), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \phi_1 \cdot \cos \phi_2\\
t_1 := \cos \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\\
t_2 := \sin \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right)\\
t_3 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
\mathbf{if}\;\lambda_1 \leq -1.55 \cdot 10^{-7} \lor \neg \left(\lambda_1 \leq 6 \cdot 10^{-12}\right):\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_3 \cdot \left(t_3 \cdot t_0\right)}}{\sqrt{e^{\mathsf{log1p}\left(-\mathsf{fma}\left(t_0, 0.5 + -0.5 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right), {\left(t_1 - t_2\right)}^{2}\right)\right)}}}\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \left(t_3 \cdot t_3\right), {\left(\mathsf{fma}\left(\sin \left(\frac{\phi_1}{2}\right), \cos \left(\frac{\phi_2}{2}\right), \sin \left(\frac{\phi_2}{2}\right) \cdot \left(-\cos \left(\frac{\phi_1}{2}\right)\right)\right)\right)}^{2}\right)}}{\sqrt{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right) + {\left(t_2 - t_1\right)}^{2}\right)}}\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 6: 63.6% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := \cos \phi_1 \cdot \cos \phi_2\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(t_0 \cdot t_1\right)}}{\sqrt{e^{\mathsf{log1p}\left(-\mathsf{fma}\left(t_1, 0.5 + -0.5 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right), {\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right)\right)}^{2}\right)\right)}}}\right) \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_1 (* (cos phi1) (cos phi2))))
   (*
    R
    (*
     2.0
     (atan2
      (sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* t_0 (* t_0 t_1))))
      (sqrt
       (exp
        (log1p
         (-
          (fma
           t_1
           (+
            0.5
            (*
             -0.5
             (+
              (* (cos lambda1) (cos lambda2))
              (* (sin lambda1) (sin lambda2)))))
           (pow
            (-
             (* (cos (* phi2 0.5)) (sin (* phi1 0.5)))
             (* (sin (* phi2 0.5)) (cos (* phi1 0.5))))
            2.0)))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) / 2.0));
	double t_1 = cos(phi1) * cos(phi2);
	return R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_0 * t_1)))), sqrt(exp(log1p(-fma(t_1, (0.5 + (-0.5 * ((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2))))), pow(((cos((phi2 * 0.5)) * sin((phi1 * 0.5))) - (sin((phi2 * 0.5)) * cos((phi1 * 0.5)))), 2.0)))))));
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = Float64(cos(phi1) * cos(phi2))
	return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_0 * Float64(t_0 * t_1)))), sqrt(exp(log1p(Float64(-fma(t_1, Float64(0.5 + Float64(-0.5 * Float64(Float64(cos(lambda1) * cos(lambda2)) + Float64(sin(lambda1) * sin(lambda2))))), (Float64(Float64(cos(Float64(phi2 * 0.5)) * sin(Float64(phi1 * 0.5))) - Float64(sin(Float64(phi2 * 0.5)) * cos(Float64(phi1 * 0.5)))) ^ 2.0)))))))))
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$0 * N[(t$95$0 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[Exp[N[Log[1 + (-N[(t$95$1 * N[(0.5 + N[(-0.5 * N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision])], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \cos \phi_1 \cdot \cos \phi_2\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(t_0 \cdot t_1\right)}}{\sqrt{e^{\mathsf{log1p}\left(-\mathsf{fma}\left(t_1, 0.5 + -0.5 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right), {\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right)\right)}^{2}\right)\right)}}}\right)
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 7: 63.1% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := t_0 \cdot t_0\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot t_1, {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot t_1, {\left(\cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right) - \sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right)\right)}^{2}\right)}}\right) \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0))) (t_1 (* t_0 t_0)))
   (*
    R
    (*
     2.0
     (atan2
      (sqrt
       (fma
        (cos phi1)
        (* (cos phi2) t_1)
        (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)))
      (sqrt
       (-
        1.0
        (fma
         (cos phi2)
         (* (cos phi1) t_1)
         (pow
          (-
           (* (cos (/ phi1 2.0)) (sin (/ phi2 2.0)))
           (* (sin (/ phi1 2.0)) (cos (/ phi2 2.0))))
          2.0)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) / 2.0));
	double t_1 = t_0 * t_0;
	return R * (2.0 * atan2(sqrt(fma(cos(phi1), (cos(phi2) * t_1), pow(sin(((phi1 - phi2) / 2.0)), 2.0))), sqrt((1.0 - fma(cos(phi2), (cos(phi1) * t_1), pow(((cos((phi1 / 2.0)) * sin((phi2 / 2.0))) - (sin((phi1 / 2.0)) * cos((phi2 / 2.0)))), 2.0))))));
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = Float64(t_0 * t_0)
	return Float64(R * Float64(2.0 * atan(sqrt(fma(cos(phi1), Float64(cos(phi2) * t_1), (sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0))), sqrt(Float64(1.0 - fma(cos(phi2), Float64(cos(phi1) * t_1), (Float64(Float64(cos(Float64(phi1 / 2.0)) * sin(Float64(phi2 / 2.0))) - Float64(sin(Float64(phi1 / 2.0)) * cos(Float64(phi2 / 2.0)))) ^ 2.0)))))))
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * t$95$0), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * t$95$1), $MachinePrecision] + N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * t$95$1), $MachinePrecision] + N[Power[N[(N[(N[Cos[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := t_0 \cdot t_0\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot t_1, {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot t_1, {\left(\cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right) - \sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right)\right)}^{2}\right)}}\right)
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 8: 63.1% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1}}{\sqrt{1 - \left({\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2} + t_1\right)}}\right) \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_1 (* t_0 (* t_0 (* (cos phi1) (cos phi2))))))
   (*
    R
    (*
     2.0
     (atan2
      (sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) t_1))
      (sqrt
       (-
        1.0
        (+
         (pow
          (-
           (* (sin (/ phi1 2.0)) (cos (/ phi2 2.0)))
           (* (cos (/ phi1 2.0)) (sin (/ phi2 2.0))))
          2.0)
         t_1))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) / 2.0));
	double t_1 = t_0 * (t_0 * (cos(phi1) * cos(phi2)));
	return R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)), sqrt((1.0 - (pow(((sin((phi1 / 2.0)) * cos((phi2 / 2.0))) - (cos((phi1 / 2.0)) * sin((phi2 / 2.0)))), 2.0) + t_1)))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: t_1
    t_0 = sin(((lambda1 - lambda2) / 2.0d0))
    t_1 = t_0 * (t_0 * (cos(phi1) * cos(phi2)))
    code = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + t_1)), sqrt((1.0d0 - ((((sin((phi1 / 2.0d0)) * cos((phi2 / 2.0d0))) - (cos((phi1 / 2.0d0)) * sin((phi2 / 2.0d0)))) ** 2.0d0) + t_1)))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.sin(((lambda1 - lambda2) / 2.0));
	double t_1 = t_0 * (t_0 * (Math.cos(phi1) * Math.cos(phi2)));
	return R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)), Math.sqrt((1.0 - (Math.pow(((Math.sin((phi1 / 2.0)) * Math.cos((phi2 / 2.0))) - (Math.cos((phi1 / 2.0)) * Math.sin((phi2 / 2.0)))), 2.0) + t_1)))));
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(((lambda1 - lambda2) / 2.0))
	t_1 = t_0 * (t_0 * (math.cos(phi1) * math.cos(phi2)))
	return R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)), math.sqrt((1.0 - (math.pow(((math.sin((phi1 / 2.0)) * math.cos((phi2 / 2.0))) - (math.cos((phi1 / 2.0)) * math.sin((phi2 / 2.0)))), 2.0) + t_1)))))
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = Float64(t_0 * Float64(t_0 * Float64(cos(phi1) * cos(phi2))))
	return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + t_1)), sqrt(Float64(1.0 - Float64((Float64(Float64(sin(Float64(phi1 / 2.0)) * cos(Float64(phi2 / 2.0))) - Float64(cos(Float64(phi1 / 2.0)) * sin(Float64(phi2 / 2.0)))) ^ 2.0) + t_1))))))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 2.0));
	t_1 = t_0 * (t_0 * (cos(phi1) * cos(phi2)));
	tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + t_1)), sqrt((1.0 - ((((sin((phi1 / 2.0)) * cos((phi2 / 2.0))) - (cos((phi1 / 2.0)) * sin((phi2 / 2.0)))) ^ 2.0) + t_1)))));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(t$95$0 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Power[N[(N[(N[Sin[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1}}{\sqrt{1 - \left({\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2} + t_1\right)}}\right)
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 9: 52.9% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{1 - \left({\sin \left(\phi_1 \cdot 0.5\right)}^{2} + \cos \phi_1 \cdot {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\right)}\\ t_1 := 0.5 - \frac{\cos \left(\phi_1 - \phi_2\right)}{2}\\ t_2 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_3 := t_2 \cdot \left(t_2 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\\ \mathbf{if}\;t_2 \leq -0.01:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1 + t_3}}{t_0}\right)\\ \mathbf{elif}\;t_2 \leq 0.006:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_3}}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \left(t_2 \cdot t_2\right), t_1\right)}}{t_0}\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0
         (sqrt
          (-
           1.0
           (+
            (pow (sin (* phi1 0.5)) 2.0)
            (* (cos phi1) (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))))))
        (t_1 (- 0.5 (/ (cos (- phi1 phi2)) 2.0)))
        (t_2 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_3 (* t_2 (* t_2 (* (cos phi1) (cos phi2))))))
   (if (<= t_2 -0.01)
     (* R (* 2.0 (atan2 (sqrt (+ t_1 t_3)) t_0)))
     (if (<= t_2 0.006)
       (*
        R
        (*
         2.0
         (atan2
          (sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) t_3))
          (sqrt (- 1.0 (pow (sin (* 0.5 (- phi1 phi2))) 2.0))))))
       (*
        R
        (*
         2.0
         (atan2
          (sqrt (fma (cos phi1) (* (cos phi2) (* t_2 t_2)) t_1))
          t_0)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sqrt((1.0 - (pow(sin((phi1 * 0.5)), 2.0) + (cos(phi1) * pow(sin(((lambda1 - lambda2) * 0.5)), 2.0)))));
	double t_1 = 0.5 - (cos((phi1 - phi2)) / 2.0);
	double t_2 = sin(((lambda1 - lambda2) / 2.0));
	double t_3 = t_2 * (t_2 * (cos(phi1) * cos(phi2)));
	double tmp;
	if (t_2 <= -0.01) {
		tmp = R * (2.0 * atan2(sqrt((t_1 + t_3)), t_0));
	} else if (t_2 <= 0.006) {
		tmp = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + t_3)), sqrt((1.0 - pow(sin((0.5 * (phi1 - phi2))), 2.0)))));
	} else {
		tmp = R * (2.0 * atan2(sqrt(fma(cos(phi1), (cos(phi2) * (t_2 * t_2)), t_1)), t_0));
	}
	return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sqrt(Float64(1.0 - Float64((sin(Float64(phi1 * 0.5)) ^ 2.0) + Float64(cos(phi1) * (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0)))))
	t_1 = Float64(0.5 - Float64(cos(Float64(phi1 - phi2)) / 2.0))
	t_2 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_3 = Float64(t_2 * Float64(t_2 * Float64(cos(phi1) * cos(phi2))))
	tmp = 0.0
	if (t_2 <= -0.01)
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_1 + t_3)), t_0)));
	elseif (t_2 <= 0.006)
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + t_3)), sqrt(Float64(1.0 - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0))))));
	else
		tmp = Float64(R * Float64(2.0 * atan(sqrt(fma(cos(phi1), Float64(cos(phi2) * Float64(t_2 * t_2)), t_1)), t_0)));
	end
	return tmp
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sqrt[N[(1.0 - N[(N[Power[N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(0.5 - N[(N[Cos[N[(phi1 - phi2), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 * N[(t$95$2 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -0.01], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$1 + t$95$3), $MachinePrecision]], $MachinePrecision] / t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.006], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + t$95$3), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision] / t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{1 - \left({\sin \left(\phi_1 \cdot 0.5\right)}^{2} + \cos \phi_1 \cdot {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\right)}\\
t_1 := 0.5 - \frac{\cos \left(\phi_1 - \phi_2\right)}{2}\\
t_2 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_3 := t_2 \cdot \left(t_2 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\\
\mathbf{if}\;t_2 \leq -0.01:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1 + t_3}}{t_0}\right)\\

\mathbf{elif}\;t_2 \leq 0.006:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_3}}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \left(t_2 \cdot t_2\right), t_1\right)}}{t_0}\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 10: 62.2% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := \cos \phi_2 \cdot \left(t_0 \cdot t_0\right)\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_1, t_1, {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_1, t_1, 0.5 - \frac{\cos \left(\phi_1 - \phi_2\right)}{2}\right)}}\right) \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_1 (* (cos phi2) (* t_0 t_0))))
   (*
    R
    (*
     2.0
     (atan2
      (sqrt (fma (cos phi1) t_1 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)))
      (sqrt
       (- 1.0 (fma (cos phi1) t_1 (- 0.5 (/ (cos (- phi1 phi2)) 2.0))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) / 2.0));
	double t_1 = cos(phi2) * (t_0 * t_0);
	return R * (2.0 * atan2(sqrt(fma(cos(phi1), t_1, pow(sin(((phi1 - phi2) / 2.0)), 2.0))), sqrt((1.0 - fma(cos(phi1), t_1, (0.5 - (cos((phi1 - phi2)) / 2.0)))))));
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = Float64(cos(phi2) * Float64(t_0 * t_0))
	return Float64(R * Float64(2.0 * atan(sqrt(fma(cos(phi1), t_1, (sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0))), sqrt(Float64(1.0 - fma(cos(phi1), t_1, Float64(0.5 - Float64(cos(Float64(phi1 - phi2)) / 2.0))))))))
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi2], $MachinePrecision] * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Cos[phi1], $MachinePrecision] * t$95$1 + N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Cos[phi1], $MachinePrecision] * t$95$1 + N[(0.5 - N[(N[Cos[N[(phi1 - phi2), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \cos \phi_2 \cdot \left(t_0 \cdot t_0\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_1, t_1, {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_1, t_1, 0.5 - \frac{\cos \left(\phi_1 - \phi_2\right)}{2}\right)}}\right)
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 11: 52.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\\ \mathbf{if}\;t_0 \leq -0.01 \lor \neg \left(t_0 \leq 0.006\right):\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\left(0.5 - \frac{\cos \left(\phi_1 - \phi_2\right)}{2}\right) + t_1}}{\sqrt{1 - \left({\sin \left(\phi_1 \cdot 0.5\right)}^{2} + \cos \phi_1 \cdot {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1}}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_1 (* t_0 (* t_0 (* (cos phi1) (cos phi2))))))
   (if (or (<= t_0 -0.01) (not (<= t_0 0.006)))
     (*
      R
      (*
       2.0
       (atan2
        (sqrt (+ (- 0.5 (/ (cos (- phi1 phi2)) 2.0)) t_1))
        (sqrt
         (-
          1.0
          (+
           (pow (sin (* phi1 0.5)) 2.0)
           (* (cos phi1) (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))))))))
     (*
      R
      (*
       2.0
       (atan2
        (sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) t_1))
        (sqrt (- 1.0 (pow (sin (* 0.5 (- phi1 phi2))) 2.0)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) / 2.0));
	double t_1 = t_0 * (t_0 * (cos(phi1) * cos(phi2)));
	double tmp;
	if ((t_0 <= -0.01) || !(t_0 <= 0.006)) {
		tmp = R * (2.0 * atan2(sqrt(((0.5 - (cos((phi1 - phi2)) / 2.0)) + t_1)), sqrt((1.0 - (pow(sin((phi1 * 0.5)), 2.0) + (cos(phi1) * pow(sin(((lambda1 - lambda2) * 0.5)), 2.0)))))));
	} else {
		tmp = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)), sqrt((1.0 - pow(sin((0.5 * (phi1 - phi2))), 2.0)))));
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = sin(((lambda1 - lambda2) / 2.0d0))
    t_1 = t_0 * (t_0 * (cos(phi1) * cos(phi2)))
    if ((t_0 <= (-0.01d0)) .or. (.not. (t_0 <= 0.006d0))) then
        tmp = r * (2.0d0 * atan2(sqrt(((0.5d0 - (cos((phi1 - phi2)) / 2.0d0)) + t_1)), sqrt((1.0d0 - ((sin((phi1 * 0.5d0)) ** 2.0d0) + (cos(phi1) * (sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0)))))))
    else
        tmp = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + t_1)), sqrt((1.0d0 - (sin((0.5d0 * (phi1 - phi2))) ** 2.0d0)))))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.sin(((lambda1 - lambda2) / 2.0));
	double t_1 = t_0 * (t_0 * (Math.cos(phi1) * Math.cos(phi2)));
	double tmp;
	if ((t_0 <= -0.01) || !(t_0 <= 0.006)) {
		tmp = R * (2.0 * Math.atan2(Math.sqrt(((0.5 - (Math.cos((phi1 - phi2)) / 2.0)) + t_1)), Math.sqrt((1.0 - (Math.pow(Math.sin((phi1 * 0.5)), 2.0) + (Math.cos(phi1) * Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))))));
	} else {
		tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)), Math.sqrt((1.0 - Math.pow(Math.sin((0.5 * (phi1 - phi2))), 2.0)))));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(((lambda1 - lambda2) / 2.0))
	t_1 = t_0 * (t_0 * (math.cos(phi1) * math.cos(phi2)))
	tmp = 0
	if (t_0 <= -0.01) or not (t_0 <= 0.006):
		tmp = R * (2.0 * math.atan2(math.sqrt(((0.5 - (math.cos((phi1 - phi2)) / 2.0)) + t_1)), math.sqrt((1.0 - (math.pow(math.sin((phi1 * 0.5)), 2.0) + (math.cos(phi1) * math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))))))
	else:
		tmp = R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)), math.sqrt((1.0 - math.pow(math.sin((0.5 * (phi1 - phi2))), 2.0)))))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = Float64(t_0 * Float64(t_0 * Float64(cos(phi1) * cos(phi2))))
	tmp = 0.0
	if ((t_0 <= -0.01) || !(t_0 <= 0.006))
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(Float64(0.5 - Float64(cos(Float64(phi1 - phi2)) / 2.0)) + t_1)), sqrt(Float64(1.0 - Float64((sin(Float64(phi1 * 0.5)) ^ 2.0) + Float64(cos(phi1) * (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0))))))));
	else
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + t_1)), sqrt(Float64(1.0 - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0))))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 2.0));
	t_1 = t_0 * (t_0 * (cos(phi1) * cos(phi2)));
	tmp = 0.0;
	if ((t_0 <= -0.01) || ~((t_0 <= 0.006)))
		tmp = R * (2.0 * atan2(sqrt(((0.5 - (cos((phi1 - phi2)) / 2.0)) + t_1)), sqrt((1.0 - ((sin((phi1 * 0.5)) ^ 2.0) + (cos(phi1) * (sin(((lambda1 - lambda2) * 0.5)) ^ 2.0)))))));
	else
		tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + t_1)), sqrt((1.0 - (sin((0.5 * (phi1 - phi2))) ^ 2.0)))));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(t$95$0 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -0.01], N[Not[LessEqual[t$95$0, 0.006]], $MachinePrecision]], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[(0.5 - N[(N[Cos[N[(phi1 - phi2), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Power[N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\\
\mathbf{if}\;t_0 \leq -0.01 \lor \neg \left(t_0 \leq 0.006\right):\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\left(0.5 - \frac{\cos \left(\phi_1 - \phi_2\right)}{2}\right) + t_1}}{\sqrt{1 - \left({\sin \left(\phi_1 \cdot 0.5\right)}^{2} + \cos \phi_1 \cdot {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\right)}}\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1}}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 12: 43.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 - {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\\ t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_2 := \sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1 \cdot \left(t_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)}\\ \mathbf{if}\;t_1 \leq -0.01:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_2}{\sqrt{t_0}}\right)\\ \mathbf{elif}\;t_1 \leq 0.0202:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_2}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_2}{\sqrt{\sqrt[3]{{t_0}^{3}}}}\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (- 1.0 (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0)))
        (t_1 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_2
         (sqrt
          (+
           (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
           (* t_1 (* t_1 (* (cos phi1) (cos phi2))))))))
   (if (<= t_1 -0.01)
     (* R (* 2.0 (atan2 t_2 (sqrt t_0))))
     (if (<= t_1 0.0202)
       (*
        R
        (*
         2.0
         (atan2 t_2 (sqrt (- 1.0 (pow (sin (* 0.5 (- phi1 phi2))) 2.0))))))
       (* R (* 2.0 (atan2 t_2 (sqrt (cbrt (pow t_0 3.0))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = 1.0 - pow(sin(((lambda1 - lambda2) * 0.5)), 2.0);
	double t_1 = sin(((lambda1 - lambda2) / 2.0));
	double t_2 = sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_1 * (t_1 * (cos(phi1) * cos(phi2))))));
	double tmp;
	if (t_1 <= -0.01) {
		tmp = R * (2.0 * atan2(t_2, sqrt(t_0)));
	} else if (t_1 <= 0.0202) {
		tmp = R * (2.0 * atan2(t_2, sqrt((1.0 - pow(sin((0.5 * (phi1 - phi2))), 2.0)))));
	} else {
		tmp = R * (2.0 * atan2(t_2, sqrt(cbrt(pow(t_0, 3.0)))));
	}
	return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = 1.0 - Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0);
	double t_1 = Math.sin(((lambda1 - lambda2) / 2.0));
	double t_2 = Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_1 * (t_1 * (Math.cos(phi1) * Math.cos(phi2))))));
	double tmp;
	if (t_1 <= -0.01) {
		tmp = R * (2.0 * Math.atan2(t_2, Math.sqrt(t_0)));
	} else if (t_1 <= 0.0202) {
		tmp = R * (2.0 * Math.atan2(t_2, Math.sqrt((1.0 - Math.pow(Math.sin((0.5 * (phi1 - phi2))), 2.0)))));
	} else {
		tmp = R * (2.0 * Math.atan2(t_2, Math.sqrt(Math.cbrt(Math.pow(t_0, 3.0)))));
	}
	return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(1.0 - (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0))
	t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_2 = sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_1 * Float64(t_1 * Float64(cos(phi1) * cos(phi2))))))
	tmp = 0.0
	if (t_1 <= -0.01)
		tmp = Float64(R * Float64(2.0 * atan(t_2, sqrt(t_0))));
	elseif (t_1 <= 0.0202)
		tmp = Float64(R * Float64(2.0 * atan(t_2, sqrt(Float64(1.0 - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0))))));
	else
		tmp = Float64(R * Float64(2.0 * atan(t_2, sqrt(cbrt((t_0 ^ 3.0))))));
	end
	return tmp
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(1.0 - N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$1 * N[(t$95$1 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$1, -0.01], N[(R * N[(2.0 * N[ArcTan[t$95$2 / N[Sqrt[t$95$0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.0202], N[(R * N[(2.0 * N[ArcTan[t$95$2 / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[t$95$2 / N[Sqrt[N[Power[N[Power[t$95$0, 3.0], $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 - {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := \sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1 \cdot \left(t_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)}\\
\mathbf{if}\;t_1 \leq -0.01:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_2}{\sqrt{t_0}}\right)\\

\mathbf{elif}\;t_1 \leq 0.0202:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_2}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_2}{\sqrt{\sqrt[3]{{t_0}^{3}}}}\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 13: 43.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 - {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\\ t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_2 := \sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1 \cdot \left(t_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)}\\ \mathbf{if}\;t_1 \leq -0.01:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_2}{\sqrt{\log \left(1 + \mathsf{expm1}\left(t_0\right)\right)}}\right)\\ \mathbf{elif}\;t_1 \leq 0.0202:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_2}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_2}{\sqrt{\sqrt[3]{{t_0}^{3}}}}\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (- 1.0 (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0)))
        (t_1 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_2
         (sqrt
          (+
           (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
           (* t_1 (* t_1 (* (cos phi1) (cos phi2))))))))
   (if (<= t_1 -0.01)
     (* R (* 2.0 (atan2 t_2 (sqrt (log (+ 1.0 (expm1 t_0)))))))
     (if (<= t_1 0.0202)
       (*
        R
        (*
         2.0
         (atan2 t_2 (sqrt (- 1.0 (pow (sin (* 0.5 (- phi1 phi2))) 2.0))))))
       (* R (* 2.0 (atan2 t_2 (sqrt (cbrt (pow t_0 3.0))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = 1.0 - pow(sin(((lambda1 - lambda2) * 0.5)), 2.0);
	double t_1 = sin(((lambda1 - lambda2) / 2.0));
	double t_2 = sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_1 * (t_1 * (cos(phi1) * cos(phi2))))));
	double tmp;
	if (t_1 <= -0.01) {
		tmp = R * (2.0 * atan2(t_2, sqrt(log((1.0 + expm1(t_0))))));
	} else if (t_1 <= 0.0202) {
		tmp = R * (2.0 * atan2(t_2, sqrt((1.0 - pow(sin((0.5 * (phi1 - phi2))), 2.0)))));
	} else {
		tmp = R * (2.0 * atan2(t_2, sqrt(cbrt(pow(t_0, 3.0)))));
	}
	return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = 1.0 - Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0);
	double t_1 = Math.sin(((lambda1 - lambda2) / 2.0));
	double t_2 = Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_1 * (t_1 * (Math.cos(phi1) * Math.cos(phi2))))));
	double tmp;
	if (t_1 <= -0.01) {
		tmp = R * (2.0 * Math.atan2(t_2, Math.sqrt(Math.log((1.0 + Math.expm1(t_0))))));
	} else if (t_1 <= 0.0202) {
		tmp = R * (2.0 * Math.atan2(t_2, Math.sqrt((1.0 - Math.pow(Math.sin((0.5 * (phi1 - phi2))), 2.0)))));
	} else {
		tmp = R * (2.0 * Math.atan2(t_2, Math.sqrt(Math.cbrt(Math.pow(t_0, 3.0)))));
	}
	return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(1.0 - (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0))
	t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_2 = sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_1 * Float64(t_1 * Float64(cos(phi1) * cos(phi2))))))
	tmp = 0.0
	if (t_1 <= -0.01)
		tmp = Float64(R * Float64(2.0 * atan(t_2, sqrt(log(Float64(1.0 + expm1(t_0)))))));
	elseif (t_1 <= 0.0202)
		tmp = Float64(R * Float64(2.0 * atan(t_2, sqrt(Float64(1.0 - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0))))));
	else
		tmp = Float64(R * Float64(2.0 * atan(t_2, sqrt(cbrt((t_0 ^ 3.0))))));
	end
	return tmp
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(1.0 - N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$1 * N[(t$95$1 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$1, -0.01], N[(R * N[(2.0 * N[ArcTan[t$95$2 / N[Sqrt[N[Log[N[(1.0 + N[(Exp[t$95$0] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.0202], N[(R * N[(2.0 * N[ArcTan[t$95$2 / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[t$95$2 / N[Sqrt[N[Power[N[Power[t$95$0, 3.0], $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 - {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := \sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1 \cdot \left(t_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)}\\
\mathbf{if}\;t_1 \leq -0.01:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_2}{\sqrt{\log \left(1 + \mathsf{expm1}\left(t_0\right)\right)}}\right)\\

\mathbf{elif}\;t_1 \leq 0.0202:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_2}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_2}{\sqrt{\sqrt[3]{{t_0}^{3}}}}\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 14: 62.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := \cos \phi_1 \cdot \cos \phi_2\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(t_0 \cdot t_1\right)}}{\sqrt{1 - \mathsf{fma}\left(t_1, 0.5 + -0.5 \cdot \cos \left(\lambda_1 - \lambda_2\right), {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}\right) \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_1 (* (cos phi1) (cos phi2))))
   (*
    R
    (*
     2.0
     (atan2
      (sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* t_0 (* t_0 t_1))))
      (sqrt
       (-
        1.0
        (fma
         t_1
         (+ 0.5 (* -0.5 (cos (- lambda1 lambda2))))
         (pow (sin (* 0.5 (- phi1 phi2))) 2.0)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) / 2.0));
	double t_1 = cos(phi1) * cos(phi2);
	return R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_0 * t_1)))), sqrt((1.0 - fma(t_1, (0.5 + (-0.5 * cos((lambda1 - lambda2)))), pow(sin((0.5 * (phi1 - phi2))), 2.0))))));
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = Float64(cos(phi1) * cos(phi2))
	return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_0 * Float64(t_0 * t_1)))), sqrt(Float64(1.0 - fma(t_1, Float64(0.5 + Float64(-0.5 * cos(Float64(lambda1 - lambda2)))), (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0)))))))
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$0 * N[(t$95$0 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(t$95$1 * N[(0.5 + N[(-0.5 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \cos \phi_1 \cdot \cos \phi_2\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(t_0 \cdot t_1\right)}}{\sqrt{1 - \mathsf{fma}\left(t_1, 0.5 + -0.5 \cdot \cos \left(\lambda_1 - \lambda_2\right), {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}\right)
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 15: 59.6% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\left(0.5 - \frac{\cos \left(\phi_1 - \phi_2\right)}{2}\right) + t_1}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1\right)}}\right) \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_1 (* t_0 (* t_0 (* (cos phi1) (cos phi2))))))
   (*
    R
    (*
     2.0
     (atan2
      (sqrt (+ (- 0.5 (/ (cos (- phi1 phi2)) 2.0)) t_1))
      (sqrt (- 1.0 (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) t_1))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) / 2.0));
	double t_1 = t_0 * (t_0 * (cos(phi1) * cos(phi2)));
	return R * (2.0 * atan2(sqrt(((0.5 - (cos((phi1 - phi2)) / 2.0)) + t_1)), sqrt((1.0 - (pow(sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: t_1
    t_0 = sin(((lambda1 - lambda2) / 2.0d0))
    t_1 = t_0 * (t_0 * (cos(phi1) * cos(phi2)))
    code = r * (2.0d0 * atan2(sqrt(((0.5d0 - (cos((phi1 - phi2)) / 2.0d0)) + t_1)), sqrt((1.0d0 - ((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + t_1)))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.sin(((lambda1 - lambda2) / 2.0));
	double t_1 = t_0 * (t_0 * (Math.cos(phi1) * Math.cos(phi2)));
	return R * (2.0 * Math.atan2(Math.sqrt(((0.5 - (Math.cos((phi1 - phi2)) / 2.0)) + t_1)), Math.sqrt((1.0 - (Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)))));
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(((lambda1 - lambda2) / 2.0))
	t_1 = t_0 * (t_0 * (math.cos(phi1) * math.cos(phi2)))
	return R * (2.0 * math.atan2(math.sqrt(((0.5 - (math.cos((phi1 - phi2)) / 2.0)) + t_1)), math.sqrt((1.0 - (math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)))))
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = Float64(t_0 * Float64(t_0 * Float64(cos(phi1) * cos(phi2))))
	return Float64(R * Float64(2.0 * atan(sqrt(Float64(Float64(0.5 - Float64(cos(Float64(phi1 - phi2)) / 2.0)) + t_1)), sqrt(Float64(1.0 - Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + t_1))))))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 2.0));
	t_1 = t_0 * (t_0 * (cos(phi1) * cos(phi2)));
	tmp = R * (2.0 * atan2(sqrt(((0.5 - (cos((phi1 - phi2)) / 2.0)) + t_1)), sqrt((1.0 - ((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + t_1)))));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(t$95$0 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[(0.5 - N[(N[Cos[N[(phi1 - phi2), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\left(0.5 - \frac{\cos \left(\phi_1 - \phi_2\right)}{2}\right) + t_1}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1\right)}}\right)
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 16: 62.2% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1}}{\sqrt{1 + \left(\left(\frac{\cos \left(\phi_1 - \phi_2\right)}{2} - 0.5\right) - t_1\right)}}\right) \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_1 (* t_0 (* t_0 (* (cos phi1) (cos phi2))))))
   (*
    R
    (*
     2.0
     (atan2
      (sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) t_1))
      (sqrt (+ 1.0 (- (- (/ (cos (- phi1 phi2)) 2.0) 0.5) t_1))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) / 2.0));
	double t_1 = t_0 * (t_0 * (cos(phi1) * cos(phi2)));
	return R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)), sqrt((1.0 + (((cos((phi1 - phi2)) / 2.0) - 0.5) - t_1)))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: t_1
    t_0 = sin(((lambda1 - lambda2) / 2.0d0))
    t_1 = t_0 * (t_0 * (cos(phi1) * cos(phi2)))
    code = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + t_1)), sqrt((1.0d0 + (((cos((phi1 - phi2)) / 2.0d0) - 0.5d0) - t_1)))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.sin(((lambda1 - lambda2) / 2.0));
	double t_1 = t_0 * (t_0 * (Math.cos(phi1) * Math.cos(phi2)));
	return R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)), Math.sqrt((1.0 + (((Math.cos((phi1 - phi2)) / 2.0) - 0.5) - t_1)))));
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(((lambda1 - lambda2) / 2.0))
	t_1 = t_0 * (t_0 * (math.cos(phi1) * math.cos(phi2)))
	return R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)), math.sqrt((1.0 + (((math.cos((phi1 - phi2)) / 2.0) - 0.5) - t_1)))))
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = Float64(t_0 * Float64(t_0 * Float64(cos(phi1) * cos(phi2))))
	return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + t_1)), sqrt(Float64(1.0 + Float64(Float64(Float64(cos(Float64(phi1 - phi2)) / 2.0) - 0.5) - t_1))))))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 2.0));
	t_1 = t_0 * (t_0 * (cos(phi1) * cos(phi2)));
	tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + t_1)), sqrt((1.0 + (((cos((phi1 - phi2)) / 2.0) - 0.5) - t_1)))));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(t$95$0 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 + N[(N[(N[(N[Cos[N[(phi1 - phi2), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision] - 0.5), $MachinePrecision] - t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1}}{\sqrt{1 + \left(\left(\frac{\cos \left(\phi_1 - \phi_2\right)}{2} - 0.5\right) - t_1\right)}}\right)
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 17: 43.6% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\\ t_1 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\ t_2 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_3 := t_2 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\\ t_4 := \sqrt{t_1 + t_2 \cdot t_3}\\ t_5 := \sqrt{1 - {t_0}^{2}}\\ \mathbf{if}\;t_2 \leq -0.01:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_4}{t_5}\right)\\ \mathbf{elif}\;t_2 \leq 0.0202:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_4}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1 + t_3 \cdot \left|t_0\right|}}{t_5}\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (* (- lambda1 lambda2) 0.5)))
        (t_1 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0))
        (t_2 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_3 (* t_2 (* (cos phi1) (cos phi2))))
        (t_4 (sqrt (+ t_1 (* t_2 t_3))))
        (t_5 (sqrt (- 1.0 (pow t_0 2.0)))))
   (if (<= t_2 -0.01)
     (* R (* 2.0 (atan2 t_4 t_5)))
     (if (<= t_2 0.0202)
       (*
        R
        (*
         2.0
         (atan2 t_4 (sqrt (- 1.0 (pow (sin (* 0.5 (- phi1 phi2))) 2.0))))))
       (* R (* 2.0 (atan2 (sqrt (+ t_1 (* t_3 (fabs t_0)))) t_5)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) * 0.5));
	double t_1 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
	double t_2 = sin(((lambda1 - lambda2) / 2.0));
	double t_3 = t_2 * (cos(phi1) * cos(phi2));
	double t_4 = sqrt((t_1 + (t_2 * t_3)));
	double t_5 = sqrt((1.0 - pow(t_0, 2.0)));
	double tmp;
	if (t_2 <= -0.01) {
		tmp = R * (2.0 * atan2(t_4, t_5));
	} else if (t_2 <= 0.0202) {
		tmp = R * (2.0 * atan2(t_4, sqrt((1.0 - pow(sin((0.5 * (phi1 - phi2))), 2.0)))));
	} else {
		tmp = R * (2.0 * atan2(sqrt((t_1 + (t_3 * fabs(t_0)))), t_5));
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: t_4
    real(8) :: t_5
    real(8) :: tmp
    t_0 = sin(((lambda1 - lambda2) * 0.5d0))
    t_1 = sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0
    t_2 = sin(((lambda1 - lambda2) / 2.0d0))
    t_3 = t_2 * (cos(phi1) * cos(phi2))
    t_4 = sqrt((t_1 + (t_2 * t_3)))
    t_5 = sqrt((1.0d0 - (t_0 ** 2.0d0)))
    if (t_2 <= (-0.01d0)) then
        tmp = r * (2.0d0 * atan2(t_4, t_5))
    else if (t_2 <= 0.0202d0) then
        tmp = r * (2.0d0 * atan2(t_4, sqrt((1.0d0 - (sin((0.5d0 * (phi1 - phi2))) ** 2.0d0)))))
    else
        tmp = r * (2.0d0 * atan2(sqrt((t_1 + (t_3 * abs(t_0)))), t_5))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.sin(((lambda1 - lambda2) * 0.5));
	double t_1 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0);
	double t_2 = Math.sin(((lambda1 - lambda2) / 2.0));
	double t_3 = t_2 * (Math.cos(phi1) * Math.cos(phi2));
	double t_4 = Math.sqrt((t_1 + (t_2 * t_3)));
	double t_5 = Math.sqrt((1.0 - Math.pow(t_0, 2.0)));
	double tmp;
	if (t_2 <= -0.01) {
		tmp = R * (2.0 * Math.atan2(t_4, t_5));
	} else if (t_2 <= 0.0202) {
		tmp = R * (2.0 * Math.atan2(t_4, Math.sqrt((1.0 - Math.pow(Math.sin((0.5 * (phi1 - phi2))), 2.0)))));
	} else {
		tmp = R * (2.0 * Math.atan2(Math.sqrt((t_1 + (t_3 * Math.abs(t_0)))), t_5));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(((lambda1 - lambda2) * 0.5))
	t_1 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0)
	t_2 = math.sin(((lambda1 - lambda2) / 2.0))
	t_3 = t_2 * (math.cos(phi1) * math.cos(phi2))
	t_4 = math.sqrt((t_1 + (t_2 * t_3)))
	t_5 = math.sqrt((1.0 - math.pow(t_0, 2.0)))
	tmp = 0
	if t_2 <= -0.01:
		tmp = R * (2.0 * math.atan2(t_4, t_5))
	elif t_2 <= 0.0202:
		tmp = R * (2.0 * math.atan2(t_4, math.sqrt((1.0 - math.pow(math.sin((0.5 * (phi1 - phi2))), 2.0)))))
	else:
		tmp = R * (2.0 * math.atan2(math.sqrt((t_1 + (t_3 * math.fabs(t_0)))), t_5))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) * 0.5))
	t_1 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0
	t_2 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_3 = Float64(t_2 * Float64(cos(phi1) * cos(phi2)))
	t_4 = sqrt(Float64(t_1 + Float64(t_2 * t_3)))
	t_5 = sqrt(Float64(1.0 - (t_0 ^ 2.0)))
	tmp = 0.0
	if (t_2 <= -0.01)
		tmp = Float64(R * Float64(2.0 * atan(t_4, t_5)));
	elseif (t_2 <= 0.0202)
		tmp = Float64(R * Float64(2.0 * atan(t_4, sqrt(Float64(1.0 - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0))))));
	else
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_1 + Float64(t_3 * abs(t_0)))), t_5)));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) * 0.5));
	t_1 = sin(((phi1 - phi2) / 2.0)) ^ 2.0;
	t_2 = sin(((lambda1 - lambda2) / 2.0));
	t_3 = t_2 * (cos(phi1) * cos(phi2));
	t_4 = sqrt((t_1 + (t_2 * t_3)));
	t_5 = sqrt((1.0 - (t_0 ^ 2.0)));
	tmp = 0.0;
	if (t_2 <= -0.01)
		tmp = R * (2.0 * atan2(t_4, t_5));
	elseif (t_2 <= 0.0202)
		tmp = R * (2.0 * atan2(t_4, sqrt((1.0 - (sin((0.5 * (phi1 - phi2))) ^ 2.0)))));
	else
		tmp = R * (2.0 * atan2(sqrt((t_1 + (t_3 * abs(t_0)))), t_5));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[Sqrt[N[(t$95$1 + N[(t$95$2 * t$95$3), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$5 = N[Sqrt[N[(1.0 - N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$2, -0.01], N[(R * N[(2.0 * N[ArcTan[t$95$4 / t$95$5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.0202], N[(R * N[(2.0 * N[ArcTan[t$95$4 / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$1 + N[(t$95$3 * N[Abs[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t$95$5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\\
t_1 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
t_2 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_3 := t_2 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\\
t_4 := \sqrt{t_1 + t_2 \cdot t_3}\\
t_5 := \sqrt{1 - {t_0}^{2}}\\
\mathbf{if}\;t_2 \leq -0.01:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_4}{t_5}\right)\\

\mathbf{elif}\;t_2 \leq 0.0202:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_4}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1 + t_3 \cdot \left|t_0\right|}}{t_5}\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 18: 62.4% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\sin \left(\phi_1 \cdot 0.5\right)}^{2}\\ t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_2 := t_1 \cdot \left(t_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\\ t_3 := \sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_2}\\ t_4 := {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\\ t_5 := \sqrt{1 - \left(t_0 + \cos \phi_1 \cdot t_4\right)}\\ \mathbf{if}\;\phi_1 \leq -6.5 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_0 + t_2}}{t_5}\right)\\ \mathbf{elif}\;\phi_1 \leq 200:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_3}{\sqrt{1 - \left(\cos \phi_2 \cdot t_4 + {\sin \left(\phi_2 \cdot -0.5\right)}^{2}\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_3}{t_5}\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (pow (sin (* phi1 0.5)) 2.0))
        (t_1 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_2 (* t_1 (* t_1 (* (cos phi1) (cos phi2)))))
        (t_3 (sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) t_2)))
        (t_4 (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))
        (t_5 (sqrt (- 1.0 (+ t_0 (* (cos phi1) t_4))))))
   (if (<= phi1 -6.5e-5)
     (* R (* 2.0 (atan2 (sqrt (+ t_0 t_2)) t_5)))
     (if (<= phi1 200.0)
       (*
        R
        (*
         2.0
         (atan2
          t_3
          (sqrt
           (- 1.0 (+ (* (cos phi2) t_4) (pow (sin (* phi2 -0.5)) 2.0)))))))
       (* R (* 2.0 (atan2 t_3 t_5)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = pow(sin((phi1 * 0.5)), 2.0);
	double t_1 = sin(((lambda1 - lambda2) / 2.0));
	double t_2 = t_1 * (t_1 * (cos(phi1) * cos(phi2)));
	double t_3 = sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + t_2));
	double t_4 = pow(sin(((lambda1 - lambda2) * 0.5)), 2.0);
	double t_5 = sqrt((1.0 - (t_0 + (cos(phi1) * t_4))));
	double tmp;
	if (phi1 <= -6.5e-5) {
		tmp = R * (2.0 * atan2(sqrt((t_0 + t_2)), t_5));
	} else if (phi1 <= 200.0) {
		tmp = R * (2.0 * atan2(t_3, sqrt((1.0 - ((cos(phi2) * t_4) + pow(sin((phi2 * -0.5)), 2.0))))));
	} else {
		tmp = R * (2.0 * atan2(t_3, t_5));
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: t_4
    real(8) :: t_5
    real(8) :: tmp
    t_0 = sin((phi1 * 0.5d0)) ** 2.0d0
    t_1 = sin(((lambda1 - lambda2) / 2.0d0))
    t_2 = t_1 * (t_1 * (cos(phi1) * cos(phi2)))
    t_3 = sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + t_2))
    t_4 = sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0
    t_5 = sqrt((1.0d0 - (t_0 + (cos(phi1) * t_4))))
    if (phi1 <= (-6.5d-5)) then
        tmp = r * (2.0d0 * atan2(sqrt((t_0 + t_2)), t_5))
    else if (phi1 <= 200.0d0) then
        tmp = r * (2.0d0 * atan2(t_3, sqrt((1.0d0 - ((cos(phi2) * t_4) + (sin((phi2 * (-0.5d0))) ** 2.0d0))))))
    else
        tmp = r * (2.0d0 * atan2(t_3, t_5))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.pow(Math.sin((phi1 * 0.5)), 2.0);
	double t_1 = Math.sin(((lambda1 - lambda2) / 2.0));
	double t_2 = t_1 * (t_1 * (Math.cos(phi1) * Math.cos(phi2)));
	double t_3 = Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_2));
	double t_4 = Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0);
	double t_5 = Math.sqrt((1.0 - (t_0 + (Math.cos(phi1) * t_4))));
	double tmp;
	if (phi1 <= -6.5e-5) {
		tmp = R * (2.0 * Math.atan2(Math.sqrt((t_0 + t_2)), t_5));
	} else if (phi1 <= 200.0) {
		tmp = R * (2.0 * Math.atan2(t_3, Math.sqrt((1.0 - ((Math.cos(phi2) * t_4) + Math.pow(Math.sin((phi2 * -0.5)), 2.0))))));
	} else {
		tmp = R * (2.0 * Math.atan2(t_3, t_5));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.pow(math.sin((phi1 * 0.5)), 2.0)
	t_1 = math.sin(((lambda1 - lambda2) / 2.0))
	t_2 = t_1 * (t_1 * (math.cos(phi1) * math.cos(phi2)))
	t_3 = math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_2))
	t_4 = math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0)
	t_5 = math.sqrt((1.0 - (t_0 + (math.cos(phi1) * t_4))))
	tmp = 0
	if phi1 <= -6.5e-5:
		tmp = R * (2.0 * math.atan2(math.sqrt((t_0 + t_2)), t_5))
	elif phi1 <= 200.0:
		tmp = R * (2.0 * math.atan2(t_3, math.sqrt((1.0 - ((math.cos(phi2) * t_4) + math.pow(math.sin((phi2 * -0.5)), 2.0))))))
	else:
		tmp = R * (2.0 * math.atan2(t_3, t_5))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(phi1 * 0.5)) ^ 2.0
	t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_2 = Float64(t_1 * Float64(t_1 * Float64(cos(phi1) * cos(phi2))))
	t_3 = sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + t_2))
	t_4 = sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0
	t_5 = sqrt(Float64(1.0 - Float64(t_0 + Float64(cos(phi1) * t_4))))
	tmp = 0.0
	if (phi1 <= -6.5e-5)
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_0 + t_2)), t_5)));
	elseif (phi1 <= 200.0)
		tmp = Float64(R * Float64(2.0 * atan(t_3, sqrt(Float64(1.0 - Float64(Float64(cos(phi2) * t_4) + (sin(Float64(phi2 * -0.5)) ^ 2.0)))))));
	else
		tmp = Float64(R * Float64(2.0 * atan(t_3, t_5)));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin((phi1 * 0.5)) ^ 2.0;
	t_1 = sin(((lambda1 - lambda2) / 2.0));
	t_2 = t_1 * (t_1 * (cos(phi1) * cos(phi2)));
	t_3 = sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + t_2));
	t_4 = sin(((lambda1 - lambda2) * 0.5)) ^ 2.0;
	t_5 = sqrt((1.0 - (t_0 + (cos(phi1) * t_4))));
	tmp = 0.0;
	if (phi1 <= -6.5e-5)
		tmp = R * (2.0 * atan2(sqrt((t_0 + t_2)), t_5));
	elseif (phi1 <= 200.0)
		tmp = R * (2.0 * atan2(t_3, sqrt((1.0 - ((cos(phi2) * t_4) + (sin((phi2 * -0.5)) ^ 2.0))))));
	else
		tmp = R * (2.0 * atan2(t_3, t_5));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * N[(t$95$1 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$5 = N[Sqrt[N[(1.0 - N[(t$95$0 + N[(N[Cos[phi1], $MachinePrecision] * t$95$4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi1, -6.5e-5], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$0 + t$95$2), $MachinePrecision]], $MachinePrecision] / t$95$5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 200.0], N[(R * N[(2.0 * N[ArcTan[t$95$3 / N[Sqrt[N[(1.0 - N[(N[(N[Cos[phi2], $MachinePrecision] * t$95$4), $MachinePrecision] + N[Power[N[Sin[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[t$95$3 / t$95$5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {\sin \left(\phi_1 \cdot 0.5\right)}^{2}\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := t_1 \cdot \left(t_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\\
t_3 := \sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_2}\\
t_4 := {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\\
t_5 := \sqrt{1 - \left(t_0 + \cos \phi_1 \cdot t_4\right)}\\
\mathbf{if}\;\phi_1 \leq -6.5 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_0 + t_2}}{t_5}\right)\\

\mathbf{elif}\;\phi_1 \leq 200:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_3}{\sqrt{1 - \left(\cos \phi_2 \cdot t_4 + {\sin \left(\phi_2 \cdot -0.5\right)}^{2}\right)}}\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_3}{t_5}\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 19: 50.9% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := \sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)}\\ \mathbf{if}\;\phi_2 \leq 3.95:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{1 - \left({\sin \left(\phi_1 \cdot 0.5\right)}^{2} + \cos \phi_1 \cdot {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_1
         (sqrt
          (+
           (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
           (* t_0 (* t_0 (* (cos phi1) (cos phi2))))))))
   (if (<= phi2 3.95)
     (*
      R
      (*
       2.0
       (atan2
        t_1
        (sqrt
         (-
          1.0
          (+
           (pow (sin (* phi1 0.5)) 2.0)
           (* (cos phi1) (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))))))))
     (*
      R
      (*
       2.0
       (atan2 t_1 (sqrt (- 1.0 (pow (sin (* 0.5 (- phi1 phi2))) 2.0)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) / 2.0));
	double t_1 = sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_0 * (cos(phi1) * cos(phi2))))));
	double tmp;
	if (phi2 <= 3.95) {
		tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - (pow(sin((phi1 * 0.5)), 2.0) + (cos(phi1) * pow(sin(((lambda1 - lambda2) * 0.5)), 2.0)))))));
	} else {
		tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - pow(sin((0.5 * (phi1 - phi2))), 2.0)))));
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = sin(((lambda1 - lambda2) / 2.0d0))
    t_1 = sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (t_0 * (t_0 * (cos(phi1) * cos(phi2))))))
    if (phi2 <= 3.95d0) then
        tmp = r * (2.0d0 * atan2(t_1, sqrt((1.0d0 - ((sin((phi1 * 0.5d0)) ** 2.0d0) + (cos(phi1) * (sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0)))))))
    else
        tmp = r * (2.0d0 * atan2(t_1, sqrt((1.0d0 - (sin((0.5d0 * (phi1 - phi2))) ** 2.0d0)))))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.sin(((lambda1 - lambda2) / 2.0));
	double t_1 = Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_0 * (Math.cos(phi1) * Math.cos(phi2))))));
	double tmp;
	if (phi2 <= 3.95) {
		tmp = R * (2.0 * Math.atan2(t_1, Math.sqrt((1.0 - (Math.pow(Math.sin((phi1 * 0.5)), 2.0) + (Math.cos(phi1) * Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))))));
	} else {
		tmp = R * (2.0 * Math.atan2(t_1, Math.sqrt((1.0 - Math.pow(Math.sin((0.5 * (phi1 - phi2))), 2.0)))));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(((lambda1 - lambda2) / 2.0))
	t_1 = math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_0 * (math.cos(phi1) * math.cos(phi2))))))
	tmp = 0
	if phi2 <= 3.95:
		tmp = R * (2.0 * math.atan2(t_1, math.sqrt((1.0 - (math.pow(math.sin((phi1 * 0.5)), 2.0) + (math.cos(phi1) * math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))))))
	else:
		tmp = R * (2.0 * math.atan2(t_1, math.sqrt((1.0 - math.pow(math.sin((0.5 * (phi1 - phi2))), 2.0)))))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_0 * Float64(t_0 * Float64(cos(phi1) * cos(phi2))))))
	tmp = 0.0
	if (phi2 <= 3.95)
		tmp = Float64(R * Float64(2.0 * atan(t_1, sqrt(Float64(1.0 - Float64((sin(Float64(phi1 * 0.5)) ^ 2.0) + Float64(cos(phi1) * (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0))))))));
	else
		tmp = Float64(R * Float64(2.0 * atan(t_1, sqrt(Float64(1.0 - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0))))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 2.0));
	t_1 = sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (t_0 * (t_0 * (cos(phi1) * cos(phi2))))));
	tmp = 0.0;
	if (phi2 <= 3.95)
		tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - ((sin((phi1 * 0.5)) ^ 2.0) + (cos(phi1) * (sin(((lambda1 - lambda2) * 0.5)) ^ 2.0)))))));
	else
		tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - (sin((0.5 * (phi1 - phi2))) ^ 2.0)))));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$0 * N[(t$95$0 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, 3.95], N[(R * N[(2.0 * N[ArcTan[t$95$1 / N[Sqrt[N[(1.0 - N[(N[Power[N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[t$95$1 / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)}\\
\mathbf{if}\;\phi_2 \leq 3.95:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{1 - \left({\sin \left(\phi_1 \cdot 0.5\right)}^{2} + \cos \phi_1 \cdot {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\right)}}\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 20: 43.6% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := \sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)}\\ \mathbf{if}\;t_0 \leq -0.01 \lor \neg \left(t_0 \leq 0.0202\right):\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{1 - {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_1
         (sqrt
          (+
           (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
           (* t_0 (* t_0 (* (cos phi1) (cos phi2))))))))
   (if (or (<= t_0 -0.01) (not (<= t_0 0.0202)))
     (*
      R
      (*
       2.0
       (atan2 t_1 (sqrt (- 1.0 (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))))))
     (*
      R
      (*
       2.0
       (atan2 t_1 (sqrt (- 1.0 (pow (sin (* 0.5 (- phi1 phi2))) 2.0)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) / 2.0));
	double t_1 = sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_0 * (cos(phi1) * cos(phi2))))));
	double tmp;
	if ((t_0 <= -0.01) || !(t_0 <= 0.0202)) {
		tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - pow(sin(((lambda1 - lambda2) * 0.5)), 2.0)))));
	} else {
		tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - pow(sin((0.5 * (phi1 - phi2))), 2.0)))));
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = sin(((lambda1 - lambda2) / 2.0d0))
    t_1 = sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (t_0 * (t_0 * (cos(phi1) * cos(phi2))))))
    if ((t_0 <= (-0.01d0)) .or. (.not. (t_0 <= 0.0202d0))) then
        tmp = r * (2.0d0 * atan2(t_1, sqrt((1.0d0 - (sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0)))))
    else
        tmp = r * (2.0d0 * atan2(t_1, sqrt((1.0d0 - (sin((0.5d0 * (phi1 - phi2))) ** 2.0d0)))))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.sin(((lambda1 - lambda2) / 2.0));
	double t_1 = Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_0 * (Math.cos(phi1) * Math.cos(phi2))))));
	double tmp;
	if ((t_0 <= -0.01) || !(t_0 <= 0.0202)) {
		tmp = R * (2.0 * Math.atan2(t_1, Math.sqrt((1.0 - Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))));
	} else {
		tmp = R * (2.0 * Math.atan2(t_1, Math.sqrt((1.0 - Math.pow(Math.sin((0.5 * (phi1 - phi2))), 2.0)))));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(((lambda1 - lambda2) / 2.0))
	t_1 = math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_0 * (math.cos(phi1) * math.cos(phi2))))))
	tmp = 0
	if (t_0 <= -0.01) or not (t_0 <= 0.0202):
		tmp = R * (2.0 * math.atan2(t_1, math.sqrt((1.0 - math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))))
	else:
		tmp = R * (2.0 * math.atan2(t_1, math.sqrt((1.0 - math.pow(math.sin((0.5 * (phi1 - phi2))), 2.0)))))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_0 * Float64(t_0 * Float64(cos(phi1) * cos(phi2))))))
	tmp = 0.0
	if ((t_0 <= -0.01) || !(t_0 <= 0.0202))
		tmp = Float64(R * Float64(2.0 * atan(t_1, sqrt(Float64(1.0 - (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0))))));
	else
		tmp = Float64(R * Float64(2.0 * atan(t_1, sqrt(Float64(1.0 - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0))))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 2.0));
	t_1 = sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (t_0 * (t_0 * (cos(phi1) * cos(phi2))))));
	tmp = 0.0;
	if ((t_0 <= -0.01) || ~((t_0 <= 0.0202)))
		tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - (sin(((lambda1 - lambda2) * 0.5)) ^ 2.0)))));
	else
		tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - (sin((0.5 * (phi1 - phi2))) ^ 2.0)))));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$0 * N[(t$95$0 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[t$95$0, -0.01], N[Not[LessEqual[t$95$0, 0.0202]], $MachinePrecision]], N[(R * N[(2.0 * N[ArcTan[t$95$1 / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[t$95$1 / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)}\\
\mathbf{if}\;t_0 \leq -0.01 \lor \neg \left(t_0 \leq 0.0202\right):\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{1 - {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}}}\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 21: 34.4% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)}}{\sqrt{1 - {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}}}\right) \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0))))
   (*
    R
    (*
     2.0
     (atan2
      (sqrt
       (+
        (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
        (* t_0 (* t_0 (* (cos phi1) (cos phi2))))))
      (sqrt (- 1.0 (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) / 2.0));
	return R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_0 * (cos(phi1) * cos(phi2)))))), sqrt((1.0 - pow(sin(((lambda1 - lambda2) * 0.5)), 2.0)))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    t_0 = sin(((lambda1 - lambda2) / 2.0d0))
    code = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (t_0 * (t_0 * (cos(phi1) * cos(phi2)))))), sqrt((1.0d0 - (sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0)))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.sin(((lambda1 - lambda2) / 2.0));
	return R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_0 * (Math.cos(phi1) * Math.cos(phi2)))))), Math.sqrt((1.0 - Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))));
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(((lambda1 - lambda2) / 2.0))
	return R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_0 * (math.cos(phi1) * math.cos(phi2)))))), math.sqrt((1.0 - math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))))
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_0 * Float64(t_0 * Float64(cos(phi1) * cos(phi2)))))), sqrt(Float64(1.0 - (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0))))))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 2.0));
	tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (t_0 * (t_0 * (cos(phi1) * cos(phi2)))))), sqrt((1.0 - (sin(((lambda1 - lambda2) * 0.5)) ^ 2.0)))));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$0 * N[(t$95$0 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)}}{\sqrt{1 - {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}}}\right)
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 22: 32.2% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\ t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_2 := \cos \phi_1 \cdot \cos \phi_2\\ \mathbf{if}\;\lambda_1 \leq 0.0029:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_0 + t_1 \cdot \left(t_1 \cdot t_2\right)}}{\sqrt{{\cos \left(\lambda_2 \cdot 0.5\right)}^{2}}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_0 + {\sin \left(\lambda_1 \cdot 0.5\right)}^{2} \cdot t_2}}{\sqrt{{\cos \left(\lambda_1 \cdot 0.5\right)}^{2}}}\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0))
        (t_1 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_2 (* (cos phi1) (cos phi2))))
   (if (<= lambda1 0.0029)
     (*
      R
      (*
       2.0
       (atan2
        (sqrt (+ t_0 (* t_1 (* t_1 t_2))))
        (sqrt (pow (cos (* lambda2 0.5)) 2.0)))))
     (*
      R
      (*
       2.0
       (atan2
        (sqrt (+ t_0 (* (pow (sin (* lambda1 0.5)) 2.0) t_2)))
        (sqrt (pow (cos (* lambda1 0.5)) 2.0))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
	double t_1 = sin(((lambda1 - lambda2) / 2.0));
	double t_2 = cos(phi1) * cos(phi2);
	double tmp;
	if (lambda1 <= 0.0029) {
		tmp = R * (2.0 * atan2(sqrt((t_0 + (t_1 * (t_1 * t_2)))), sqrt(pow(cos((lambda2 * 0.5)), 2.0))));
	} else {
		tmp = R * (2.0 * atan2(sqrt((t_0 + (pow(sin((lambda1 * 0.5)), 2.0) * t_2))), sqrt(pow(cos((lambda1 * 0.5)), 2.0))));
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0
    t_1 = sin(((lambda1 - lambda2) / 2.0d0))
    t_2 = cos(phi1) * cos(phi2)
    if (lambda1 <= 0.0029d0) then
        tmp = r * (2.0d0 * atan2(sqrt((t_0 + (t_1 * (t_1 * t_2)))), sqrt((cos((lambda2 * 0.5d0)) ** 2.0d0))))
    else
        tmp = r * (2.0d0 * atan2(sqrt((t_0 + ((sin((lambda1 * 0.5d0)) ** 2.0d0) * t_2))), sqrt((cos((lambda1 * 0.5d0)) ** 2.0d0))))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0);
	double t_1 = Math.sin(((lambda1 - lambda2) / 2.0));
	double t_2 = Math.cos(phi1) * Math.cos(phi2);
	double tmp;
	if (lambda1 <= 0.0029) {
		tmp = R * (2.0 * Math.atan2(Math.sqrt((t_0 + (t_1 * (t_1 * t_2)))), Math.sqrt(Math.pow(Math.cos((lambda2 * 0.5)), 2.0))));
	} else {
		tmp = R * (2.0 * Math.atan2(Math.sqrt((t_0 + (Math.pow(Math.sin((lambda1 * 0.5)), 2.0) * t_2))), Math.sqrt(Math.pow(Math.cos((lambda1 * 0.5)), 2.0))));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0)
	t_1 = math.sin(((lambda1 - lambda2) / 2.0))
	t_2 = math.cos(phi1) * math.cos(phi2)
	tmp = 0
	if lambda1 <= 0.0029:
		tmp = R * (2.0 * math.atan2(math.sqrt((t_0 + (t_1 * (t_1 * t_2)))), math.sqrt(math.pow(math.cos((lambda2 * 0.5)), 2.0))))
	else:
		tmp = R * (2.0 * math.atan2(math.sqrt((t_0 + (math.pow(math.sin((lambda1 * 0.5)), 2.0) * t_2))), math.sqrt(math.pow(math.cos((lambda1 * 0.5)), 2.0))))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0
	t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_2 = Float64(cos(phi1) * cos(phi2))
	tmp = 0.0
	if (lambda1 <= 0.0029)
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_0 + Float64(t_1 * Float64(t_1 * t_2)))), sqrt((cos(Float64(lambda2 * 0.5)) ^ 2.0)))));
	else
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_0 + Float64((sin(Float64(lambda1 * 0.5)) ^ 2.0) * t_2))), sqrt((cos(Float64(lambda1 * 0.5)) ^ 2.0)))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((phi1 - phi2) / 2.0)) ^ 2.0;
	t_1 = sin(((lambda1 - lambda2) / 2.0));
	t_2 = cos(phi1) * cos(phi2);
	tmp = 0.0;
	if (lambda1 <= 0.0029)
		tmp = R * (2.0 * atan2(sqrt((t_0 + (t_1 * (t_1 * t_2)))), sqrt((cos((lambda2 * 0.5)) ^ 2.0))));
	else
		tmp = R * (2.0 * atan2(sqrt((t_0 + ((sin((lambda1 * 0.5)) ^ 2.0) * t_2))), sqrt((cos((lambda1 * 0.5)) ^ 2.0))));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda1, 0.0029], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$0 + N[(t$95$1 * N[(t$95$1 * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[Power[N[Cos[N[(lambda2 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$0 + N[(N[Power[N[Sin[N[(lambda1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[Power[N[Cos[N[(lambda1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := \cos \phi_1 \cdot \cos \phi_2\\
\mathbf{if}\;\lambda_1 \leq 0.0029:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_0 + t_1 \cdot \left(t_1 \cdot t_2\right)}}{\sqrt{{\cos \left(\lambda_2 \cdot 0.5\right)}^{2}}}\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_0 + {\sin \left(\lambda_1 \cdot 0.5\right)}^{2} \cdot t_2}}{\sqrt{{\cos \left(\lambda_1 \cdot 0.5\right)}^{2}}}\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 23: 29.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)}}{\sqrt{{\cos \left(\lambda_1 \cdot 0.5\right)}^{2}}}\right) \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0))))
   (*
    R
    (*
     2.0
     (atan2
      (sqrt
       (+
        (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
        (* t_0 (* t_0 (* (cos phi1) (cos phi2))))))
      (sqrt (pow (cos (* lambda1 0.5)) 2.0)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) / 2.0));
	return R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_0 * (cos(phi1) * cos(phi2)))))), sqrt(pow(cos((lambda1 * 0.5)), 2.0))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    t_0 = sin(((lambda1 - lambda2) / 2.0d0))
    code = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (t_0 * (t_0 * (cos(phi1) * cos(phi2)))))), sqrt((cos((lambda1 * 0.5d0)) ** 2.0d0))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.sin(((lambda1 - lambda2) / 2.0));
	return R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_0 * (Math.cos(phi1) * Math.cos(phi2)))))), Math.sqrt(Math.pow(Math.cos((lambda1 * 0.5)), 2.0))));
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(((lambda1 - lambda2) / 2.0))
	return R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_0 * (math.cos(phi1) * math.cos(phi2)))))), math.sqrt(math.pow(math.cos((lambda1 * 0.5)), 2.0))))
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_0 * Float64(t_0 * Float64(cos(phi1) * cos(phi2)))))), sqrt((cos(Float64(lambda1 * 0.5)) ^ 2.0)))))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 2.0));
	tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (t_0 * (t_0 * (cos(phi1) * cos(phi2)))))), sqrt((cos((lambda1 * 0.5)) ^ 2.0))));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$0 * N[(t$95$0 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[Power[N[Cos[N[(lambda1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)}}{\sqrt{{\cos \left(\lambda_1 \cdot 0.5\right)}^{2}}}\right)
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 24: 29.7% accurate, 1.5× speedup?

\[\begin{array}{l} \\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \cos \phi_1 \cdot {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}}}{\sqrt{{\cos \left(\lambda_1 \cdot 0.5\right)}^{2}}}\right) \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R
  (*
   2.0
   (atan2
    (sqrt
     (+
      (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
      (* (cos phi1) (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))))
    (sqrt (pow (cos (* lambda1 0.5)) 2.0))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (cos(phi1) * pow(sin(((lambda1 - lambda2) * 0.5)), 2.0)))), sqrt(pow(cos((lambda1 * 0.5)), 2.0))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (cos(phi1) * (sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0)))), sqrt((cos((lambda1 * 0.5d0)) ** 2.0d0))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (Math.cos(phi1) * Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))), Math.sqrt(Math.pow(Math.cos((lambda1 * 0.5)), 2.0))));
}
def code(R, lambda1, lambda2, phi1, phi2):
	return R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (math.cos(phi1) * math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))), math.sqrt(math.pow(math.cos((lambda1 * 0.5)), 2.0))))
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(cos(phi1) * (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0)))), sqrt((cos(Float64(lambda1 * 0.5)) ^ 2.0)))))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (cos(phi1) * (sin(((lambda1 - lambda2) * 0.5)) ^ 2.0)))), sqrt((cos((lambda1 * 0.5)) ^ 2.0))));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[Power[N[Cos[N[(lambda1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \cos \phi_1 \cdot {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}}}{\sqrt{{\cos \left(\lambda_1 \cdot 0.5\right)}^{2}}}\right)
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 25: 29.7% accurate, 1.5× speedup?

\[\begin{array}{l} \\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \cos \phi_2 \cdot {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}}}{\sqrt{{\cos \left(\lambda_1 \cdot 0.5\right)}^{2}}}\right) \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R
  (*
   2.0
   (atan2
    (sqrt
     (+
      (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
      (* (cos phi2) (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))))
    (sqrt (pow (cos (* lambda1 0.5)) 2.0))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (cos(phi2) * pow(sin(((lambda1 - lambda2) * 0.5)), 2.0)))), sqrt(pow(cos((lambda1 * 0.5)), 2.0))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (cos(phi2) * (sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0)))), sqrt((cos((lambda1 * 0.5d0)) ** 2.0d0))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (Math.cos(phi2) * Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))), Math.sqrt(Math.pow(Math.cos((lambda1 * 0.5)), 2.0))));
}
def code(R, lambda1, lambda2, phi1, phi2):
	return R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (math.cos(phi2) * math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))), math.sqrt(math.pow(math.cos((lambda1 * 0.5)), 2.0))))
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(cos(phi2) * (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0)))), sqrt((cos(Float64(lambda1 * 0.5)) ^ 2.0)))))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (cos(phi2) * (sin(((lambda1 - lambda2) * 0.5)) ^ 2.0)))), sqrt((cos((lambda1 * 0.5)) ^ 2.0))));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[Power[N[Cos[N[(lambda1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \cos \phi_2 \cdot {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}}}{\sqrt{{\cos \left(\lambda_1 \cdot 0.5\right)}^{2}}}\right)
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Reproduce

?
herbie shell --seed 2024008 
(FPCore (R lambda1 lambda2 phi1 phi2)
  :name "Distance on a great circle"
  :precision binary64
  (* R (* 2.0 (atan2 (sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0))) (sin (/ (- lambda1 lambda2) 2.0))))) (sqrt (- 1.0 (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0))) (sin (/ (- lambda1 lambda2) 2.0))))))))))