Distance on a great circle

Percentage Accurate: 62.0% → 78.0%
Time: 2.4min
Alternatives: 32
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 32 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.0% 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.0% 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_2 \cdot \cos \phi_1\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, t_1, {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2}\right)}}{\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_0 \cdot \left(t_1 \cdot t_0\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 phi2) (cos phi1))))
   (*
    R
    (*
     2.0
     (atan2
      (sqrt
       (fma
        (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0)
        t_1
        (pow
         (-
          (* (cos (* 0.5 phi2)) (sin (* 0.5 phi1)))
          (* (cos (* 0.5 phi1)) (sin (* 0.5 phi2))))
         2.0)))
      (sqrt
       (-
        1.0
        (+
         (pow
          (-
           (* (sin (/ phi1 2.0)) (cos (/ phi2 2.0)))
           (* (cos (/ phi1 2.0)) (sin (/ phi2 2.0))))
          2.0)
         (* t_0 (* t_1 t_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) * cos(phi1);
	return R * (2.0 * atan2(sqrt(fma(pow(sin((0.5 * (lambda1 - lambda2))), 2.0), t_1, pow(((cos((0.5 * phi2)) * sin((0.5 * phi1))) - (cos((0.5 * phi1)) * sin((0.5 * phi2)))), 2.0))), sqrt((1.0 - (pow(((sin((phi1 / 2.0)) * cos((phi2 / 2.0))) - (cos((phi1 / 2.0)) * sin((phi2 / 2.0)))), 2.0) + (t_0 * (t_1 * t_0)))))));
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = Float64(cos(phi2) * cos(phi1))
	return Float64(R * Float64(2.0 * atan(sqrt(fma((sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0), t_1, (Float64(Float64(cos(Float64(0.5 * phi2)) * sin(Float64(0.5 * phi1))) - Float64(cos(Float64(0.5 * phi1)) * sin(Float64(0.5 * phi2)))) ^ 2.0))), 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) + Float64(t_0 * Float64(t_1 * t_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[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * t$95$1 + N[Power[N[(N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $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] + N[(t$95$0 * N[(t$95$1 * t$95$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 \cos \phi_1\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, t_1, {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2}\right)}}{\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_0 \cdot \left(t_1 \cdot t_0\right)\right)}}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 62.3%

    \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  2. Step-by-step derivation
    1. div-sub62.3%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. sin-diff63.4%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  3. Applied egg-rr63.4%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  4. Step-by-step derivation
    1. div-sub62.3%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. sin-diff63.4%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  5. Applied egg-rr77.3%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  6. Taylor expanded in phi1 around inf 77.3%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right) + {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2}}}}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  7. Simplified77.3%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\mathsf{fma}\left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, \cos \phi_2 \cdot \cos \phi_1, {\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}^{2}\right)}}}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  8. Final simplification77.3%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, \cos \phi_2 \cdot \cos \phi_1, {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2}\right)}}{\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} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}\right) \]

Alternative 2: 78.0% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := {\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_0 \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_0\right)\\ 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 2.0)) (cos (/ phi2 2.0)))
            (* (cos (/ phi1 2.0)) (sin (/ phi2 2.0))))
           2.0)
          (* t_0 (* (* (cos phi2) (cos phi1)) 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 / 2.0)) * cos((phi2 / 2.0))) - (cos((phi1 / 2.0)) * sin((phi2 / 2.0)))), 2.0) + (t_0 * ((cos(phi2) * cos(phi1)) * 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 / 2.0d0)) * cos((phi2 / 2.0d0))) - (cos((phi1 / 2.0d0)) * sin((phi2 / 2.0d0)))) ** 2.0d0) + (t_0 * ((cos(phi2) * cos(phi1)) * 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 / 2.0)) * Math.cos((phi2 / 2.0))) - (Math.cos((phi1 / 2.0)) * Math.sin((phi2 / 2.0)))), 2.0) + (t_0 * ((Math.cos(phi2) * Math.cos(phi1)) * 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 / 2.0)) * math.cos((phi2 / 2.0))) - (math.cos((phi1 / 2.0)) * math.sin((phi2 / 2.0)))), 2.0) + (t_0 * ((math.cos(phi2) * math.cos(phi1)) * 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((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) + Float64(t_0 * Float64(Float64(cos(phi2) * cos(phi1)) * 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 / 2.0)) * cos((phi2 / 2.0))) - (cos((phi1 / 2.0)) * sin((phi2 / 2.0)))) ^ 2.0) + (t_0 * ((cos(phi2) * cos(phi1)) * 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[(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] + N[(t$95$0 * N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $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 := {\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_0 \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_0\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1}}{\sqrt{1 - t_1}}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 62.3%

    \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  2. Step-by-step derivation
    1. div-sub62.3%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. sin-diff63.4%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  3. Applied egg-rr63.4%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  4. Step-by-step derivation
    1. div-sub62.3%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. sin-diff63.4%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  5. Applied egg-rr77.3%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  6. Final simplification77.3%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\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} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}{\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} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}\right) \]

Alternative 3: 64.0% 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 \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_0\right)\\ t_2 := \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)}\\ \mathbf{if}\;\lambda_1 \leq -4.8 \cdot 10^{-43}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1 + {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}}}{t_2}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2} + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right)}}{t_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 (* (* (cos phi2) (cos phi1)) t_0)))
        (t_2
         (sqrt
          (-
           1.0
           (+
            (pow
             (-
              (* (sin (/ phi1 2.0)) (cos (/ phi2 2.0)))
              (* (cos (/ phi1 2.0)) (sin (/ phi2 2.0))))
             2.0)
            t_1)))))
   (if (<= lambda1 -4.8e-43)
     (*
      R
      (* 2.0 (atan2 (sqrt (+ t_1 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0))) t_2)))
     (*
      R
      (*
       2.0
       (atan2
        (sqrt
         (+
          (pow
           (-
            (* (cos (* 0.5 phi2)) (sin (* 0.5 phi1)))
            (* (cos (* 0.5 phi1)) (sin (* 0.5 phi2))))
           2.0)
          (* (cos phi1) (* (cos phi2) (pow (sin (* lambda2 -0.5)) 2.0)))))
        t_2))))))
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 * ((cos(phi2) * cos(phi1)) * t_0);
	double t_2 = 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 tmp;
	if (lambda1 <= -4.8e-43) {
		tmp = R * (2.0 * atan2(sqrt((t_1 + pow(sin(((phi1 - phi2) / 2.0)), 2.0))), t_2));
	} else {
		tmp = R * (2.0 * atan2(sqrt((pow(((cos((0.5 * phi2)) * sin((0.5 * phi1))) - (cos((0.5 * phi1)) * sin((0.5 * phi2)))), 2.0) + (cos(phi1) * (cos(phi2) * pow(sin((lambda2 * -0.5)), 2.0))))), t_2));
	}
	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(((lambda1 - lambda2) / 2.0d0))
    t_1 = t_0 * ((cos(phi2) * cos(phi1)) * t_0)
    t_2 = sqrt((1.0d0 - ((((sin((phi1 / 2.0d0)) * cos((phi2 / 2.0d0))) - (cos((phi1 / 2.0d0)) * sin((phi2 / 2.0d0)))) ** 2.0d0) + t_1)))
    if (lambda1 <= (-4.8d-43)) then
        tmp = r * (2.0d0 * atan2(sqrt((t_1 + (sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0))), t_2))
    else
        tmp = r * (2.0d0 * atan2(sqrt(((((cos((0.5d0 * phi2)) * sin((0.5d0 * phi1))) - (cos((0.5d0 * phi1)) * sin((0.5d0 * phi2)))) ** 2.0d0) + (cos(phi1) * (cos(phi2) * (sin((lambda2 * (-0.5d0))) ** 2.0d0))))), t_2))
    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 * ((Math.cos(phi2) * Math.cos(phi1)) * t_0);
	double t_2 = 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)));
	double tmp;
	if (lambda1 <= -4.8e-43) {
		tmp = R * (2.0 * Math.atan2(Math.sqrt((t_1 + Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0))), t_2));
	} else {
		tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(((Math.cos((0.5 * phi2)) * Math.sin((0.5 * phi1))) - (Math.cos((0.5 * phi1)) * Math.sin((0.5 * phi2)))), 2.0) + (Math.cos(phi1) * (Math.cos(phi2) * Math.pow(Math.sin((lambda2 * -0.5)), 2.0))))), t_2));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(((lambda1 - lambda2) / 2.0))
	t_1 = t_0 * ((math.cos(phi2) * math.cos(phi1)) * t_0)
	t_2 = 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)))
	tmp = 0
	if lambda1 <= -4.8e-43:
		tmp = R * (2.0 * math.atan2(math.sqrt((t_1 + math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0))), t_2))
	else:
		tmp = R * (2.0 * math.atan2(math.sqrt((math.pow(((math.cos((0.5 * phi2)) * math.sin((0.5 * phi1))) - (math.cos((0.5 * phi1)) * math.sin((0.5 * phi2)))), 2.0) + (math.cos(phi1) * (math.cos(phi2) * math.pow(math.sin((lambda2 * -0.5)), 2.0))))), t_2))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = Float64(t_0 * Float64(Float64(cos(phi2) * cos(phi1)) * t_0))
	t_2 = 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)))
	tmp = 0.0
	if (lambda1 <= -4.8e-43)
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_1 + (sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0))), t_2)));
	else
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((Float64(Float64(cos(Float64(0.5 * phi2)) * sin(Float64(0.5 * phi1))) - Float64(cos(Float64(0.5 * phi1)) * sin(Float64(0.5 * phi2)))) ^ 2.0) + Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(lambda2 * -0.5)) ^ 2.0))))), t_2)));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 2.0));
	t_1 = t_0 * ((cos(phi2) * cos(phi1)) * t_0);
	t_2 = sqrt((1.0 - ((((sin((phi1 / 2.0)) * cos((phi2 / 2.0))) - (cos((phi1 / 2.0)) * sin((phi2 / 2.0)))) ^ 2.0) + t_1)));
	tmp = 0.0;
	if (lambda1 <= -4.8e-43)
		tmp = R * (2.0 * atan2(sqrt((t_1 + (sin(((phi1 - phi2) / 2.0)) ^ 2.0))), t_2));
	else
		tmp = R * (2.0 * atan2(sqrt(((((cos((0.5 * phi2)) * sin((0.5 * phi1))) - (cos((0.5 * phi1)) * sin((0.5 * phi2)))) ^ 2.0) + (cos(phi1) * (cos(phi2) * (sin((lambda2 * -0.5)) ^ 2.0))))), t_2));
	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[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = 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]}, If[LessEqual[lambda1, -4.8e-43], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$1 + N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t$95$2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[(N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + 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]), $MachinePrecision]], $MachinePrecision] / t$95$2], $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(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_0\right)\\
t_2 := \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)}\\
\mathbf{if}\;\lambda_1 \leq -4.8 \cdot 10^{-43}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1 + {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}}}{t_2}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda1 < -4.8000000000000004e-43

    1. Initial program 50.5%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Step-by-step derivation
      1. div-sub50.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
      2. sin-diff51.8%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    3. Applied egg-rr51.8%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]

    if -4.8000000000000004e-43 < lambda1

    1. Initial program 66.6%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Step-by-step derivation
      1. div-sub66.6%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
      2. sin-diff67.6%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    3. Applied egg-rr67.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    4. Step-by-step derivation
      1. div-sub66.6%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
      2. sin-diff67.6%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    5. Applied egg-rr82.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    6. Taylor expanded in lambda1 around 0 69.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2}}}}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification64.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -4.8 \cdot 10^{-43}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) + {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}}}{\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} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2} + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right)}}{\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} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}\right)\\ \end{array} \]

Alternative 4: 66.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ 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_0 \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_0\right)\right)}\\ t_2 := {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2}\\ \mathbf{if}\;\lambda_1 \leq -8 \cdot 10^{-43}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + t_2}}{t_1}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_2 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right)}}{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
         (sqrt
          (-
           1.0
           (+
            (pow
             (-
              (* (sin (/ phi1 2.0)) (cos (/ phi2 2.0)))
              (* (cos (/ phi1 2.0)) (sin (/ phi2 2.0))))
             2.0)
            (* t_0 (* (* (cos phi2) (cos phi1)) t_0))))))
        (t_2
         (pow
          (-
           (* (cos (* 0.5 phi2)) (sin (* 0.5 phi1)))
           (* (cos (* 0.5 phi1)) (sin (* 0.5 phi2))))
          2.0)))
   (if (<= lambda1 -8e-43)
     (*
      R
      (*
       2.0
       (atan2
        (sqrt
         (+ (* (cos phi1) (* (cos phi2) (pow (sin (* 0.5 lambda1)) 2.0))) t_2))
        t_1)))
     (*
      R
      (*
       2.0
       (atan2
        (sqrt
         (+
          t_2
          (* (cos phi1) (* (cos phi2) (pow (sin (* lambda2 -0.5)) 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 = sqrt((1.0 - (pow(((sin((phi1 / 2.0)) * cos((phi2 / 2.0))) - (cos((phi1 / 2.0)) * sin((phi2 / 2.0)))), 2.0) + (t_0 * ((cos(phi2) * cos(phi1)) * t_0)))));
	double t_2 = pow(((cos((0.5 * phi2)) * sin((0.5 * phi1))) - (cos((0.5 * phi1)) * sin((0.5 * phi2)))), 2.0);
	double tmp;
	if (lambda1 <= -8e-43) {
		tmp = R * (2.0 * atan2(sqrt(((cos(phi1) * (cos(phi2) * pow(sin((0.5 * lambda1)), 2.0))) + t_2)), t_1));
	} else {
		tmp = R * (2.0 * atan2(sqrt((t_2 + (cos(phi1) * (cos(phi2) * pow(sin((lambda2 * -0.5)), 2.0))))), t_1));
	}
	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(((lambda1 - lambda2) / 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_0 * ((cos(phi2) * cos(phi1)) * t_0)))))
    t_2 = ((cos((0.5d0 * phi2)) * sin((0.5d0 * phi1))) - (cos((0.5d0 * phi1)) * sin((0.5d0 * phi2)))) ** 2.0d0
    if (lambda1 <= (-8d-43)) then
        tmp = r * (2.0d0 * atan2(sqrt(((cos(phi1) * (cos(phi2) * (sin((0.5d0 * lambda1)) ** 2.0d0))) + t_2)), t_1))
    else
        tmp = r * (2.0d0 * atan2(sqrt((t_2 + (cos(phi1) * (cos(phi2) * (sin((lambda2 * (-0.5d0))) ** 2.0d0))))), t_1))
    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((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_0 * ((Math.cos(phi2) * Math.cos(phi1)) * t_0)))));
	double t_2 = Math.pow(((Math.cos((0.5 * phi2)) * Math.sin((0.5 * phi1))) - (Math.cos((0.5 * phi1)) * Math.sin((0.5 * phi2)))), 2.0);
	double tmp;
	if (lambda1 <= -8e-43) {
		tmp = R * (2.0 * Math.atan2(Math.sqrt(((Math.cos(phi1) * (Math.cos(phi2) * Math.pow(Math.sin((0.5 * lambda1)), 2.0))) + t_2)), t_1));
	} else {
		tmp = R * (2.0 * Math.atan2(Math.sqrt((t_2 + (Math.cos(phi1) * (Math.cos(phi2) * Math.pow(Math.sin((lambda2 * -0.5)), 2.0))))), t_1));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(((lambda1 - lambda2) / 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_0 * ((math.cos(phi2) * math.cos(phi1)) * t_0)))))
	t_2 = math.pow(((math.cos((0.5 * phi2)) * math.sin((0.5 * phi1))) - (math.cos((0.5 * phi1)) * math.sin((0.5 * phi2)))), 2.0)
	tmp = 0
	if lambda1 <= -8e-43:
		tmp = R * (2.0 * math.atan2(math.sqrt(((math.cos(phi1) * (math.cos(phi2) * math.pow(math.sin((0.5 * lambda1)), 2.0))) + t_2)), t_1))
	else:
		tmp = R * (2.0 * math.atan2(math.sqrt((t_2 + (math.cos(phi1) * (math.cos(phi2) * math.pow(math.sin((lambda2 * -0.5)), 2.0))))), t_1))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 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) + Float64(t_0 * Float64(Float64(cos(phi2) * cos(phi1)) * t_0)))))
	t_2 = Float64(Float64(cos(Float64(0.5 * phi2)) * sin(Float64(0.5 * phi1))) - Float64(cos(Float64(0.5 * phi1)) * sin(Float64(0.5 * phi2)))) ^ 2.0
	tmp = 0.0
	if (lambda1 <= -8e-43)
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(0.5 * lambda1)) ^ 2.0))) + t_2)), t_1)));
	else
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_2 + Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(lambda2 * -0.5)) ^ 2.0))))), t_1)));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 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_0 * ((cos(phi2) * cos(phi1)) * t_0)))));
	t_2 = ((cos((0.5 * phi2)) * sin((0.5 * phi1))) - (cos((0.5 * phi1)) * sin((0.5 * phi2)))) ^ 2.0;
	tmp = 0.0;
	if (lambda1 <= -8e-43)
		tmp = R * (2.0 * atan2(sqrt(((cos(phi1) * (cos(phi2) * (sin((0.5 * lambda1)) ^ 2.0))) + t_2)), t_1));
	else
		tmp = R * (2.0 * atan2(sqrt((t_2 + (cos(phi1) * (cos(phi2) * (sin((lambda2 * -0.5)) ^ 2.0))))), t_1));
	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[(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] + N[(t$95$0 * N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[(N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[lambda1, -8e-43], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(0.5 * lambda1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision] / t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$2 + 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]), $MachinePrecision]], $MachinePrecision] / t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
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_0 \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_0\right)\right)}\\
t_2 := {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2}\\
\mathbf{if}\;\lambda_1 \leq -8 \cdot 10^{-43}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + t_2}}{t_1}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda1 < -8.00000000000000062e-43

    1. Initial program 50.5%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Step-by-step derivation
      1. div-sub50.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
      2. sin-diff51.8%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    3. Applied egg-rr51.8%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    4. Step-by-step derivation
      1. div-sub50.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
      2. sin-diff51.8%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    5. Applied egg-rr62.8%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    6. Taylor expanded in lambda2 around 0 56.5%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2}}}}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]

    if -8.00000000000000062e-43 < lambda1

    1. Initial program 66.6%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Step-by-step derivation
      1. div-sub66.6%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
      2. sin-diff67.6%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    3. Applied egg-rr67.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    4. Step-by-step derivation
      1. div-sub66.6%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
      2. sin-diff67.6%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    5. Applied egg-rr82.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    6. Taylor expanded in lambda1 around 0 69.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2}}}}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification66.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -8 \cdot 10^{-43}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2}}}{\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} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2} + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right)}}{\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} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}\right)\\ \end{array} \]

Alternative 5: 69.0% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := {\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_0 \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_0\right)\\ t_2 := {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2}\\ \mathbf{if}\;\lambda_2 \leq 3.6 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1}}{\sqrt{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + t_2\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_2 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right)}}{\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 2.0)) (cos (/ phi2 2.0)))
            (* (cos (/ phi1 2.0)) (sin (/ phi2 2.0))))
           2.0)
          (* t_0 (* (* (cos phi2) (cos phi1)) t_0))))
        (t_2
         (pow
          (-
           (* (cos (* 0.5 phi2)) (sin (* 0.5 phi1)))
           (* (cos (* 0.5 phi1)) (sin (* 0.5 phi2))))
          2.0)))
   (if (<= lambda2 3.6e-9)
     (*
      R
      (*
       2.0
       (atan2
        (sqrt t_1)
        (sqrt
         (-
          1.0
          (+
           (* (cos phi1) (* (cos phi2) (pow (sin (* 0.5 lambda1)) 2.0)))
           t_2))))))
     (*
      R
      (*
       2.0
       (atan2
        (sqrt
         (+
          t_2
          (* (cos phi1) (* (cos phi2) (pow (sin (* lambda2 -0.5)) 2.0)))))
        (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 / 2.0)) * cos((phi2 / 2.0))) - (cos((phi1 / 2.0)) * sin((phi2 / 2.0)))), 2.0) + (t_0 * ((cos(phi2) * cos(phi1)) * t_0));
	double t_2 = pow(((cos((0.5 * phi2)) * sin((0.5 * phi1))) - (cos((0.5 * phi1)) * sin((0.5 * phi2)))), 2.0);
	double tmp;
	if (lambda2 <= 3.6e-9) {
		tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - ((cos(phi1) * (cos(phi2) * pow(sin((0.5 * lambda1)), 2.0))) + t_2)))));
	} else {
		tmp = R * (2.0 * atan2(sqrt((t_2 + (cos(phi1) * (cos(phi2) * pow(sin((lambda2 * -0.5)), 2.0))))), sqrt((1.0 - t_1))));
	}
	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(((lambda1 - lambda2) / 2.0d0))
    t_1 = (((sin((phi1 / 2.0d0)) * cos((phi2 / 2.0d0))) - (cos((phi1 / 2.0d0)) * sin((phi2 / 2.0d0)))) ** 2.0d0) + (t_0 * ((cos(phi2) * cos(phi1)) * t_0))
    t_2 = ((cos((0.5d0 * phi2)) * sin((0.5d0 * phi1))) - (cos((0.5d0 * phi1)) * sin((0.5d0 * phi2)))) ** 2.0d0
    if (lambda2 <= 3.6d-9) then
        tmp = r * (2.0d0 * atan2(sqrt(t_1), sqrt((1.0d0 - ((cos(phi1) * (cos(phi2) * (sin((0.5d0 * lambda1)) ** 2.0d0))) + t_2)))))
    else
        tmp = r * (2.0d0 * atan2(sqrt((t_2 + (cos(phi1) * (cos(phi2) * (sin((lambda2 * (-0.5d0))) ** 2.0d0))))), sqrt((1.0d0 - t_1))))
    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.pow(((Math.sin((phi1 / 2.0)) * Math.cos((phi2 / 2.0))) - (Math.cos((phi1 / 2.0)) * Math.sin((phi2 / 2.0)))), 2.0) + (t_0 * ((Math.cos(phi2) * Math.cos(phi1)) * t_0));
	double t_2 = Math.pow(((Math.cos((0.5 * phi2)) * Math.sin((0.5 * phi1))) - (Math.cos((0.5 * phi1)) * Math.sin((0.5 * phi2)))), 2.0);
	double tmp;
	if (lambda2 <= 3.6e-9) {
		tmp = R * (2.0 * Math.atan2(Math.sqrt(t_1), Math.sqrt((1.0 - ((Math.cos(phi1) * (Math.cos(phi2) * Math.pow(Math.sin((0.5 * lambda1)), 2.0))) + t_2)))));
	} else {
		tmp = R * (2.0 * Math.atan2(Math.sqrt((t_2 + (Math.cos(phi1) * (Math.cos(phi2) * Math.pow(Math.sin((lambda2 * -0.5)), 2.0))))), Math.sqrt((1.0 - t_1))));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(((lambda1 - lambda2) / 2.0))
	t_1 = 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_0 * ((math.cos(phi2) * math.cos(phi1)) * t_0))
	t_2 = math.pow(((math.cos((0.5 * phi2)) * math.sin((0.5 * phi1))) - (math.cos((0.5 * phi1)) * math.sin((0.5 * phi2)))), 2.0)
	tmp = 0
	if lambda2 <= 3.6e-9:
		tmp = R * (2.0 * math.atan2(math.sqrt(t_1), math.sqrt((1.0 - ((math.cos(phi1) * (math.cos(phi2) * math.pow(math.sin((0.5 * lambda1)), 2.0))) + t_2)))))
	else:
		tmp = R * (2.0 * math.atan2(math.sqrt((t_2 + (math.cos(phi1) * (math.cos(phi2) * math.pow(math.sin((lambda2 * -0.5)), 2.0))))), math.sqrt((1.0 - t_1))))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = 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) + Float64(t_0 * Float64(Float64(cos(phi2) * cos(phi1)) * t_0)))
	t_2 = Float64(Float64(cos(Float64(0.5 * phi2)) * sin(Float64(0.5 * phi1))) - Float64(cos(Float64(0.5 * phi1)) * sin(Float64(0.5 * phi2)))) ^ 2.0
	tmp = 0.0
	if (lambda2 <= 3.6e-9)
		tmp = Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - Float64(Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(0.5 * lambda1)) ^ 2.0))) + t_2))))));
	else
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_2 + Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(lambda2 * -0.5)) ^ 2.0))))), sqrt(Float64(1.0 - t_1)))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 2.0));
	t_1 = (((sin((phi1 / 2.0)) * cos((phi2 / 2.0))) - (cos((phi1 / 2.0)) * sin((phi2 / 2.0)))) ^ 2.0) + (t_0 * ((cos(phi2) * cos(phi1)) * t_0));
	t_2 = ((cos((0.5 * phi2)) * sin((0.5 * phi1))) - (cos((0.5 * phi1)) * sin((0.5 * phi2)))) ^ 2.0;
	tmp = 0.0;
	if (lambda2 <= 3.6e-9)
		tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - ((cos(phi1) * (cos(phi2) * (sin((0.5 * lambda1)) ^ 2.0))) + t_2)))));
	else
		tmp = R * (2.0 * atan2(sqrt((t_2 + (cos(phi1) * (cos(phi2) * (sin((lambda2 * -0.5)) ^ 2.0))))), sqrt((1.0 - t_1))));
	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[(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] + N[(t$95$0 * N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[(N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[lambda2, 3.6e-9], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$1], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(0.5 * lambda1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$2 + 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]), $MachinePrecision]], $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 := {\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_0 \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_0\right)\\
t_2 := {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2}\\
\mathbf{if}\;\lambda_2 \leq 3.6 \cdot 10^{-9}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1}}{\sqrt{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + t_2\right)}}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda2 < 3.6e-9

    1. Initial program 68.2%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Step-by-step derivation
      1. div-sub68.2%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
      2. sin-diff69.2%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    3. Applied egg-rr69.2%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    4. Step-by-step derivation
      1. div-sub68.2%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
      2. sin-diff69.2%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    5. Applied egg-rr85.9%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    6. Taylor expanded in lambda2 around 0 72.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{\color{blue}{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2}\right)}}}\right) \]

    if 3.6e-9 < lambda2

    1. Initial program 48.6%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Step-by-step derivation
      1. div-sub48.6%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
      2. sin-diff49.8%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    3. Applied egg-rr49.8%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    4. Step-by-step derivation
      1. div-sub48.6%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
      2. sin-diff49.8%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    5. Applied egg-rr57.4%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    6. Taylor expanded in lambda1 around 0 57.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2}}}}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification67.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 3.6 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\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} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}{\sqrt{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2}\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2} + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right)}}{\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} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}\right)\\ \end{array} \]

Alternative 6: 63.0% 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(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_0\right)\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1 + {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}}}{\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 (* (* (cos phi2) (cos phi1)) t_0))))
   (*
    R
    (*
     2.0
     (atan2
      (sqrt (+ t_1 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)))
      (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 * ((cos(phi2) * cos(phi1)) * t_0);
	return R * (2.0 * atan2(sqrt((t_1 + pow(sin(((phi1 - phi2) / 2.0)), 2.0))), 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 * ((cos(phi2) * cos(phi1)) * t_0)
    code = r * (2.0d0 * atan2(sqrt((t_1 + (sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0))), 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 * ((Math.cos(phi2) * Math.cos(phi1)) * t_0);
	return R * (2.0 * Math.atan2(Math.sqrt((t_1 + Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0))), 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 * ((math.cos(phi2) * math.cos(phi1)) * t_0)
	return R * (2.0 * math.atan2(math.sqrt((t_1 + math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0))), 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(Float64(cos(phi2) * cos(phi1)) * t_0))
	return Float64(R * Float64(2.0 * atan(sqrt(Float64(t_1 + (sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0))), 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 * ((cos(phi2) * cos(phi1)) * t_0);
	tmp = R * (2.0 * atan2(sqrt((t_1 + (sin(((phi1 - phi2) / 2.0)) ^ 2.0))), 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[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(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[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(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_0\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1 + {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}}}{\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
  1. Initial program 62.3%

    \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  2. Step-by-step derivation
    1. div-sub62.3%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. sin-diff63.4%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  3. Applied egg-rr63.4%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  4. Final simplification63.4%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) + {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}}}{\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} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}\right) \]

Alternative 7: 55.1% 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} + t_0 \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_0\right)\right)\\ t_2 := {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\\ \mathbf{if}\;\lambda_1 \leq -1.48 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + t_2}}{\sqrt{1 - t_1}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{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)\\ \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)
          (* t_0 (* (cos phi2) (* (cos phi1) t_0)))))
        (t_2 (pow (sin (* 0.5 (- phi1 phi2))) 2.0)))
   (if (<= lambda1 -1.48e-5)
     (*
      R
      (*
       2.0
       (atan2
        (sqrt
         (+ (* (cos phi1) (* (cos phi2) (pow (sin (* 0.5 lambda1)) 2.0))) t_2))
        (sqrt (- 1.0 t_1)))))
     (*
      R
      (*
       2.0
       (atan2
        (sqrt t_1)
        (sqrt
         (-
          1.0
          (+
           (* (cos phi1) (* (cos phi2) (pow (sin (* lambda2 -0.5)) 2.0)))
           t_2)))))))))
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) + (t_0 * (cos(phi2) * (cos(phi1) * t_0)));
	double t_2 = pow(sin((0.5 * (phi1 - phi2))), 2.0);
	double tmp;
	if (lambda1 <= -1.48e-5) {
		tmp = R * (2.0 * atan2(sqrt(((cos(phi1) * (cos(phi2) * pow(sin((0.5 * lambda1)), 2.0))) + t_2)), sqrt((1.0 - t_1))));
	} else {
		tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - ((cos(phi1) * (cos(phi2) * pow(sin((lambda2 * -0.5)), 2.0))) + t_2)))));
	}
	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(((lambda1 - lambda2) / 2.0d0))
    t_1 = (sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (t_0 * (cos(phi2) * (cos(phi1) * t_0)))
    t_2 = sin((0.5d0 * (phi1 - phi2))) ** 2.0d0
    if (lambda1 <= (-1.48d-5)) then
        tmp = r * (2.0d0 * atan2(sqrt(((cos(phi1) * (cos(phi2) * (sin((0.5d0 * lambda1)) ** 2.0d0))) + t_2)), sqrt((1.0d0 - t_1))))
    else
        tmp = r * (2.0d0 * atan2(sqrt(t_1), sqrt((1.0d0 - ((cos(phi1) * (cos(phi2) * (sin((lambda2 * (-0.5d0))) ** 2.0d0))) + t_2)))))
    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.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (Math.cos(phi2) * (Math.cos(phi1) * t_0)));
	double t_2 = Math.pow(Math.sin((0.5 * (phi1 - phi2))), 2.0);
	double tmp;
	if (lambda1 <= -1.48e-5) {
		tmp = R * (2.0 * Math.atan2(Math.sqrt(((Math.cos(phi1) * (Math.cos(phi2) * Math.pow(Math.sin((0.5 * lambda1)), 2.0))) + t_2)), Math.sqrt((1.0 - t_1))));
	} else {
		tmp = R * (2.0 * Math.atan2(Math.sqrt(t_1), Math.sqrt((1.0 - ((Math.cos(phi1) * (Math.cos(phi2) * Math.pow(Math.sin((lambda2 * -0.5)), 2.0))) + t_2)))));
	}
	return tmp;
}
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) + (t_0 * (math.cos(phi2) * (math.cos(phi1) * t_0)))
	t_2 = math.pow(math.sin((0.5 * (phi1 - phi2))), 2.0)
	tmp = 0
	if lambda1 <= -1.48e-5:
		tmp = R * (2.0 * math.atan2(math.sqrt(((math.cos(phi1) * (math.cos(phi2) * math.pow(math.sin((0.5 * lambda1)), 2.0))) + t_2)), math.sqrt((1.0 - t_1))))
	else:
		tmp = R * (2.0 * math.atan2(math.sqrt(t_1), math.sqrt((1.0 - ((math.cos(phi1) * (math.cos(phi2) * math.pow(math.sin((lambda2 * -0.5)), 2.0))) + t_2)))))
	return tmp
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(t_0 * Float64(cos(phi2) * Float64(cos(phi1) * t_0))))
	t_2 = sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0
	tmp = 0.0
	if (lambda1 <= -1.48e-5)
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(0.5 * lambda1)) ^ 2.0))) + t_2)), sqrt(Float64(1.0 - t_1)))));
	else
		tmp = Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - Float64(Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(lambda2 * -0.5)) ^ 2.0))) + t_2))))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 2.0));
	t_1 = (sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (t_0 * (cos(phi2) * (cos(phi1) * t_0)));
	t_2 = sin((0.5 * (phi1 - phi2))) ^ 2.0;
	tmp = 0.0;
	if (lambda1 <= -1.48e-5)
		tmp = R * (2.0 * atan2(sqrt(((cos(phi1) * (cos(phi2) * (sin((0.5 * lambda1)) ^ 2.0))) + t_2)), sqrt((1.0 - t_1))));
	else
		tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - ((cos(phi1) * (cos(phi2) * (sin((lambda2 * -0.5)) ^ 2.0))) + t_2)))));
	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[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$0 * N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[lambda1, -1.48e-5], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(0.5 * lambda1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$1], $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] + t$95$2), $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 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_0\right)\right)\\
t_2 := {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\\
\mathbf{if}\;\lambda_1 \leq -1.48 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + t_2}}{\sqrt{1 - t_1}}\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{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)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda1 < -1.4800000000000001e-5

    1. Initial program 48.4%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified48.4%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in lambda2 around 0 47.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]

    if -1.4800000000000001e-5 < lambda1

    1. Initial program 66.6%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified66.6%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in lambda1 around 0 58.2%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification55.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -1.48 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}\right)\\ \end{array} \]

Alternative 8: 55.5% 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(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\\ t_2 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_0\right)\right)\\ \mathbf{if}\;\lambda_2 \leq 3.6 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_2}}{\sqrt{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + t_1\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right) + t_1}}{\sqrt{1 - t_2}}\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 (* 0.5 (- phi1 phi2))) 2.0))
        (t_2
         (+
          (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
          (* t_0 (* (cos phi2) (* (cos phi1) t_0))))))
   (if (<= lambda2 3.6e-9)
     (*
      R
      (*
       2.0
       (atan2
        (sqrt t_2)
        (sqrt
         (-
          1.0
          (+
           (* (cos phi1) (* (cos phi2) (pow (sin (* 0.5 lambda1)) 2.0)))
           t_1))))))
     (*
      R
      (*
       2.0
       (atan2
        (sqrt
         (+
          (* (cos phi1) (* (cos phi2) (pow (sin (* lambda2 -0.5)) 2.0)))
          t_1))
        (sqrt (- 1.0 t_2))))))))
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((0.5 * (phi1 - phi2))), 2.0);
	double t_2 = pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (cos(phi2) * (cos(phi1) * t_0)));
	double tmp;
	if (lambda2 <= 3.6e-9) {
		tmp = R * (2.0 * atan2(sqrt(t_2), sqrt((1.0 - ((cos(phi1) * (cos(phi2) * pow(sin((0.5 * lambda1)), 2.0))) + t_1)))));
	} else {
		tmp = R * (2.0 * atan2(sqrt(((cos(phi1) * (cos(phi2) * pow(sin((lambda2 * -0.5)), 2.0))) + t_1)), sqrt((1.0 - t_2))));
	}
	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(((lambda1 - lambda2) / 2.0d0))
    t_1 = sin((0.5d0 * (phi1 - phi2))) ** 2.0d0
    t_2 = (sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (t_0 * (cos(phi2) * (cos(phi1) * t_0)))
    if (lambda2 <= 3.6d-9) then
        tmp = r * (2.0d0 * atan2(sqrt(t_2), sqrt((1.0d0 - ((cos(phi1) * (cos(phi2) * (sin((0.5d0 * lambda1)) ** 2.0d0))) + t_1)))))
    else
        tmp = r * (2.0d0 * atan2(sqrt(((cos(phi1) * (cos(phi2) * (sin((lambda2 * (-0.5d0))) ** 2.0d0))) + t_1)), sqrt((1.0d0 - t_2))))
    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.pow(Math.sin((0.5 * (phi1 - phi2))), 2.0);
	double t_2 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (Math.cos(phi2) * (Math.cos(phi1) * t_0)));
	double tmp;
	if (lambda2 <= 3.6e-9) {
		tmp = R * (2.0 * Math.atan2(Math.sqrt(t_2), Math.sqrt((1.0 - ((Math.cos(phi1) * (Math.cos(phi2) * Math.pow(Math.sin((0.5 * lambda1)), 2.0))) + t_1)))));
	} else {
		tmp = R * (2.0 * Math.atan2(Math.sqrt(((Math.cos(phi1) * (Math.cos(phi2) * Math.pow(Math.sin((lambda2 * -0.5)), 2.0))) + t_1)), Math.sqrt((1.0 - t_2))));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(((lambda1 - lambda2) / 2.0))
	t_1 = math.pow(math.sin((0.5 * (phi1 - phi2))), 2.0)
	t_2 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (math.cos(phi2) * (math.cos(phi1) * t_0)))
	tmp = 0
	if lambda2 <= 3.6e-9:
		tmp = R * (2.0 * math.atan2(math.sqrt(t_2), math.sqrt((1.0 - ((math.cos(phi1) * (math.cos(phi2) * math.pow(math.sin((0.5 * lambda1)), 2.0))) + t_1)))))
	else:
		tmp = R * (2.0 * math.atan2(math.sqrt(((math.cos(phi1) * (math.cos(phi2) * math.pow(math.sin((lambda2 * -0.5)), 2.0))) + t_1)), math.sqrt((1.0 - t_2))))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0
	t_2 = Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_0 * Float64(cos(phi2) * Float64(cos(phi1) * t_0))))
	tmp = 0.0
	if (lambda2 <= 3.6e-9)
		tmp = Float64(R * Float64(2.0 * atan(sqrt(t_2), sqrt(Float64(1.0 - Float64(Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(0.5 * lambda1)) ^ 2.0))) + t_1))))));
	else
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(lambda2 * -0.5)) ^ 2.0))) + t_1)), sqrt(Float64(1.0 - t_2)))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 2.0));
	t_1 = sin((0.5 * (phi1 - phi2))) ^ 2.0;
	t_2 = (sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (t_0 * (cos(phi2) * (cos(phi1) * t_0)));
	tmp = 0.0;
	if (lambda2 <= 3.6e-9)
		tmp = R * (2.0 * atan2(sqrt(t_2), sqrt((1.0 - ((cos(phi1) * (cos(phi2) * (sin((0.5 * lambda1)) ^ 2.0))) + t_1)))));
	else
		tmp = R * (2.0 * atan2(sqrt(((cos(phi1) * (cos(phi2) * (sin((lambda2 * -0.5)) ^ 2.0))) + t_1)), sqrt((1.0 - t_2))));
	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[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$0 * N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda2, 3.6e-9], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$2], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(0.5 * lambda1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[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$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$2), $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(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\\
t_2 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_0\right)\right)\\
\mathbf{if}\;\lambda_2 \leq 3.6 \cdot 10^{-9}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_2}}{\sqrt{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + t_1\right)}}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda2 < 3.6e-9

    1. Initial program 68.2%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified68.2%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in lambda2 around 0 59.2%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}}\right) \]

    if 3.6e-9 < lambda2

    1. Initial program 48.6%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified48.6%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in lambda1 around 0 48.3%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification56.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 3.6 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)\\ \end{array} \]

Alternative 9: 55.5% 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(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\\ t_2 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\ \mathbf{if}\;\lambda_2 \leq 3.6 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_0 \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_0\right) + t_2}}{\sqrt{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + t_1\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right) + t_1}}{\sqrt{1 - \left(t_2 + t_0 \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_0\right)\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 (pow (sin (* 0.5 (- phi1 phi2))) 2.0))
        (t_2 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)))
   (if (<= lambda2 3.6e-9)
     (*
      R
      (*
       2.0
       (atan2
        (sqrt (+ (* t_0 (* (* (cos phi2) (cos phi1)) t_0)) t_2))
        (sqrt
         (-
          1.0
          (+
           (* (cos phi1) (* (cos phi2) (pow (sin (* 0.5 lambda1)) 2.0)))
           t_1))))))
     (*
      R
      (*
       2.0
       (atan2
        (sqrt
         (+
          (* (cos phi1) (* (cos phi2) (pow (sin (* lambda2 -0.5)) 2.0)))
          t_1))
        (sqrt (- 1.0 (+ t_2 (* t_0 (* (cos phi2) (* (cos phi1) t_0))))))))))))
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((0.5 * (phi1 - phi2))), 2.0);
	double t_2 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
	double tmp;
	if (lambda2 <= 3.6e-9) {
		tmp = R * (2.0 * atan2(sqrt(((t_0 * ((cos(phi2) * cos(phi1)) * t_0)) + t_2)), sqrt((1.0 - ((cos(phi1) * (cos(phi2) * pow(sin((0.5 * lambda1)), 2.0))) + t_1)))));
	} else {
		tmp = R * (2.0 * atan2(sqrt(((cos(phi1) * (cos(phi2) * pow(sin((lambda2 * -0.5)), 2.0))) + t_1)), sqrt((1.0 - (t_2 + (t_0 * (cos(phi2) * (cos(phi1) * t_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(((lambda1 - lambda2) / 2.0d0))
    t_1 = sin((0.5d0 * (phi1 - phi2))) ** 2.0d0
    t_2 = sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0
    if (lambda2 <= 3.6d-9) then
        tmp = r * (2.0d0 * atan2(sqrt(((t_0 * ((cos(phi2) * cos(phi1)) * t_0)) + t_2)), sqrt((1.0d0 - ((cos(phi1) * (cos(phi2) * (sin((0.5d0 * lambda1)) ** 2.0d0))) + t_1)))))
    else
        tmp = r * (2.0d0 * atan2(sqrt(((cos(phi1) * (cos(phi2) * (sin((lambda2 * (-0.5d0))) ** 2.0d0))) + t_1)), sqrt((1.0d0 - (t_2 + (t_0 * (cos(phi2) * (cos(phi1) * t_0))))))))
    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.pow(Math.sin((0.5 * (phi1 - phi2))), 2.0);
	double t_2 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0);
	double tmp;
	if (lambda2 <= 3.6e-9) {
		tmp = R * (2.0 * Math.atan2(Math.sqrt(((t_0 * ((Math.cos(phi2) * Math.cos(phi1)) * t_0)) + t_2)), Math.sqrt((1.0 - ((Math.cos(phi1) * (Math.cos(phi2) * Math.pow(Math.sin((0.5 * lambda1)), 2.0))) + t_1)))));
	} else {
		tmp = R * (2.0 * Math.atan2(Math.sqrt(((Math.cos(phi1) * (Math.cos(phi2) * Math.pow(Math.sin((lambda2 * -0.5)), 2.0))) + t_1)), Math.sqrt((1.0 - (t_2 + (t_0 * (Math.cos(phi2) * (Math.cos(phi1) * t_0))))))));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(((lambda1 - lambda2) / 2.0))
	t_1 = math.pow(math.sin((0.5 * (phi1 - phi2))), 2.0)
	t_2 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0)
	tmp = 0
	if lambda2 <= 3.6e-9:
		tmp = R * (2.0 * math.atan2(math.sqrt(((t_0 * ((math.cos(phi2) * math.cos(phi1)) * t_0)) + t_2)), math.sqrt((1.0 - ((math.cos(phi1) * (math.cos(phi2) * math.pow(math.sin((0.5 * lambda1)), 2.0))) + t_1)))))
	else:
		tmp = R * (2.0 * math.atan2(math.sqrt(((math.cos(phi1) * (math.cos(phi2) * math.pow(math.sin((lambda2 * -0.5)), 2.0))) + t_1)), math.sqrt((1.0 - (t_2 + (t_0 * (math.cos(phi2) * (math.cos(phi1) * t_0))))))))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0
	t_2 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0
	tmp = 0.0
	if (lambda2 <= 3.6e-9)
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(Float64(t_0 * Float64(Float64(cos(phi2) * cos(phi1)) * t_0)) + t_2)), sqrt(Float64(1.0 - Float64(Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(0.5 * lambda1)) ^ 2.0))) + t_1))))));
	else
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(lambda2 * -0.5)) ^ 2.0))) + t_1)), sqrt(Float64(1.0 - Float64(t_2 + Float64(t_0 * Float64(cos(phi2) * Float64(cos(phi1) * t_0)))))))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 2.0));
	t_1 = sin((0.5 * (phi1 - phi2))) ^ 2.0;
	t_2 = sin(((phi1 - phi2) / 2.0)) ^ 2.0;
	tmp = 0.0;
	if (lambda2 <= 3.6e-9)
		tmp = R * (2.0 * atan2(sqrt(((t_0 * ((cos(phi2) * cos(phi1)) * t_0)) + t_2)), sqrt((1.0 - ((cos(phi1) * (cos(phi2) * (sin((0.5 * lambda1)) ^ 2.0))) + t_1)))));
	else
		tmp = R * (2.0 * atan2(sqrt(((cos(phi1) * (cos(phi2) * (sin((lambda2 * -0.5)) ^ 2.0))) + t_1)), sqrt((1.0 - (t_2 + (t_0 * (cos(phi2) * (cos(phi1) * t_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[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[lambda2, 3.6e-9], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[(t$95$0 * N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(0.5 * lambda1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[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$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(t$95$2 + N[(t$95$0 * N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * t$95$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 := {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\\
t_2 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
\mathbf{if}\;\lambda_2 \leq 3.6 \cdot 10^{-9}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_0 \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_0\right) + t_2}}{\sqrt{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + t_1\right)}}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda2 < 3.6e-9

    1. Initial program 68.2%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Taylor expanded in lambda2 around 0 59.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \color{blue}{\sin \left(0.5 \cdot \lambda_1\right)}\right)}}\right) \]
    3. Taylor expanded in lambda2 around 0 59.2%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{\color{blue}{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}}\right) \]

    if 3.6e-9 < lambda2

    1. Initial program 48.6%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified48.6%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in lambda1 around 0 48.3%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification56.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 3.6 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) + {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}}}{\sqrt{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)\\ \end{array} \]

Alternative 10: 62.0% accurate, 1.0× 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(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_0\right)\right)}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_2 \cdot \cos \phi_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))))
   (*
    R
    (*
     2.0
     (atan2
      (sqrt
       (+
        (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
        (* t_0 (* (cos phi2) (* (cos phi1) t_0)))))
      (sqrt
       (-
        1.0
        (fma
         (* (cos phi2) (cos phi1))
         (+ 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));
	return R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (cos(phi2) * (cos(phi1) * t_0))))), sqrt((1.0 - fma((cos(phi2) * cos(phi1)), (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))
	return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_0 * Float64(cos(phi2) * Float64(cos(phi1) * t_0))))), sqrt(Float64(1.0 - fma(Float64(cos(phi2) * cos(phi1)), 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]}, 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[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * 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)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_0\right)\right)}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_2 \cdot \cos \phi_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
  1. Initial program 62.3%

    \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  2. Simplified62.3%

    \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
  3. Applied egg-rr62.4%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 + \left(-\mathsf{fma}\left(\cos \phi_2 \cdot \cos \phi_1, 0.5 - 0.5 \cdot \cos \left(\lambda_1 - \lambda_2\right), {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)\right)}}}\right) \]
  4. Step-by-step derivation
    1. sub-neg62.4%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - \mathsf{fma}\left(\cos \phi_2 \cdot \cos \phi_1, 0.5 - 0.5 \cdot \cos \left(\lambda_1 - \lambda_2\right), {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)}}}\right) \]
    2. cancel-sign-sub-inv62.4%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_2 \cdot \cos \phi_1, \color{blue}{0.5 + \left(-0.5\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)}, {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)}}\right) \]
    3. metadata-eval62.4%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_2 \cdot \cos \phi_1, 0.5 + \color{blue}{-0.5} \cdot \cos \left(\lambda_1 - \lambda_2\right), {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)}}\right) \]
    4. *-commutative62.4%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_2 \cdot \cos \phi_1, 0.5 + -0.5 \cdot \cos \left(\lambda_1 - \lambda_2\right), {\sin \color{blue}{\left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}}^{2}\right)}}\right) \]
  5. Simplified62.4%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - \mathsf{fma}\left(\cos \phi_2 \cdot \cos \phi_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) \]
  6. Final simplification62.4%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_2 \cdot \cos \phi_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) \]

Alternative 11: 62.1% 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} + t_0 \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_0\right)\right)\\ t_2 := \sqrt{t_1}\\ t_3 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_2 + {\sin \left(\phi_2 \cdot -0.5\right)}^{2}\\ \mathbf{if}\;\phi_2 \leq -5.3 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_3}}{\sqrt{1 - t_1}}\right)\\ \mathbf{elif}\;\phi_2 \leq 1.02 \cdot 10^{-16}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_2}{\sqrt{1 - \mathsf{fma}\left({\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_2}{\sqrt{1 - t_3}}\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)
          (* t_0 (* (cos phi2) (* (cos phi1) t_0)))))
        (t_2 (sqrt t_1))
        (t_3
         (+
          (* (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0) (cos phi2))
          (pow (sin (* phi2 -0.5)) 2.0))))
   (if (<= phi2 -5.3e-5)
     (* R (* 2.0 (atan2 (sqrt t_3) (sqrt (- 1.0 t_1)))))
     (if (<= phi2 1.02e-16)
       (*
        R
        (*
         2.0
         (atan2
          t_2
          (sqrt
           (-
            1.0
            (fma
             (pow (sin (* -0.5 (- lambda2 lambda1))) 2.0)
             (cos phi1)
             (pow (sin (* 0.5 phi1)) 2.0)))))))
       (* R (* 2.0 (atan2 t_2 (sqrt (- 1.0 t_3)))))))))
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) + (t_0 * (cos(phi2) * (cos(phi1) * t_0)));
	double t_2 = sqrt(t_1);
	double t_3 = (pow(sin((0.5 * (lambda1 - lambda2))), 2.0) * cos(phi2)) + pow(sin((phi2 * -0.5)), 2.0);
	double tmp;
	if (phi2 <= -5.3e-5) {
		tmp = R * (2.0 * atan2(sqrt(t_3), sqrt((1.0 - t_1))));
	} else if (phi2 <= 1.02e-16) {
		tmp = R * (2.0 * atan2(t_2, sqrt((1.0 - fma(pow(sin((-0.5 * (lambda2 - lambda1))), 2.0), cos(phi1), pow(sin((0.5 * phi1)), 2.0))))));
	} else {
		tmp = R * (2.0 * atan2(t_2, sqrt((1.0 - t_3))));
	}
	return tmp;
}
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(t_0 * Float64(cos(phi2) * Float64(cos(phi1) * t_0))))
	t_2 = sqrt(t_1)
	t_3 = Float64(Float64((sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0) * cos(phi2)) + (sin(Float64(phi2 * -0.5)) ^ 2.0))
	tmp = 0.0
	if (phi2 <= -5.3e-5)
		tmp = Float64(R * Float64(2.0 * atan(sqrt(t_3), sqrt(Float64(1.0 - t_1)))));
	elseif (phi2 <= 1.02e-16)
		tmp = Float64(R * Float64(2.0 * atan(t_2, sqrt(Float64(1.0 - fma((sin(Float64(-0.5 * Float64(lambda2 - lambda1))) ^ 2.0), cos(phi1), (sin(Float64(0.5 * phi1)) ^ 2.0)))))));
	else
		tmp = Float64(R * Float64(2.0 * atan(t_2, sqrt(Float64(1.0 - t_3)))));
	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[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$0 * N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[t$95$1], $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -5.3e-5], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$3], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 1.02e-16], N[(R * N[(2.0 * N[ArcTan[t$95$2 / N[Sqrt[N[(1.0 - N[(N[Power[N[Sin[N[(-0.5 * N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[t$95$2 / N[Sqrt[N[(1.0 - t$95$3), $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} + t_0 \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_0\right)\right)\\
t_2 := \sqrt{t_1}\\
t_3 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_2 + {\sin \left(\phi_2 \cdot -0.5\right)}^{2}\\
\mathbf{if}\;\phi_2 \leq -5.3 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_3}}{\sqrt{1 - t_1}}\right)\\

\mathbf{elif}\;\phi_2 \leq 1.02 \cdot 10^{-16}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_2}{\sqrt{1 - \mathsf{fma}\left({\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < -5.3000000000000001e-5

    1. Initial program 44.5%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified44.5%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in phi1 around 0 45.5%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(-0.5 \cdot \phi_2\right)}^{2}}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]

    if -5.3000000000000001e-5 < phi2 < 1.0200000000000001e-16

    1. Initial program 78.9%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified78.9%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in phi2 around 0 78.5%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - \left(\cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}}\right) \]
    4. Step-by-step derivation
      1. *-commutative78.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left(\color{blue}{{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_1} + {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}\right) \]
      2. fma-def78.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \color{blue}{\mathsf{fma}\left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}}\right) \]
      3. sub-neg78.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \mathsf{fma}\left({\sin \left(0.5 \cdot \color{blue}{\left(\lambda_1 + \left(-\lambda_2\right)\right)}\right)}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}\right) \]
      4. mul-1-neg78.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \mathsf{fma}\left({\sin \left(0.5 \cdot \left(\lambda_1 + \color{blue}{-1 \cdot \lambda_2}\right)\right)}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}\right) \]
      5. distribute-lft-in78.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \mathsf{fma}\left({\sin \color{blue}{\left(0.5 \cdot \lambda_1 + 0.5 \cdot \left(-1 \cdot \lambda_2\right)\right)}}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}\right) \]
      6. associate-*r*78.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \mathsf{fma}\left({\sin \left(0.5 \cdot \lambda_1 + \color{blue}{\left(0.5 \cdot -1\right) \cdot \lambda_2}\right)}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}\right) \]
      7. metadata-eval78.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \mathsf{fma}\left({\sin \left(0.5 \cdot \lambda_1 + \color{blue}{-0.5} \cdot \lambda_2\right)}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}\right) \]
      8. metadata-eval78.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \mathsf{fma}\left({\sin \left(\color{blue}{\left(-0.5 \cdot -1\right)} \cdot \lambda_1 + -0.5 \cdot \lambda_2\right)}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}\right) \]
      9. associate-*r*78.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \mathsf{fma}\left({\sin \left(\color{blue}{-0.5 \cdot \left(-1 \cdot \lambda_1\right)} + -0.5 \cdot \lambda_2\right)}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}\right) \]
      10. distribute-lft-in78.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \mathsf{fma}\left({\sin \color{blue}{\left(-0.5 \cdot \left(-1 \cdot \lambda_1 + \lambda_2\right)\right)}}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}\right) \]
      11. +-commutative78.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \mathsf{fma}\left({\sin \left(-0.5 \cdot \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}\right) \]
      12. mul-1-neg78.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \mathsf{fma}\left({\sin \left(-0.5 \cdot \left(\lambda_2 + \color{blue}{\left(-\lambda_1\right)}\right)\right)}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}\right) \]
      13. unsub-neg78.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \mathsf{fma}\left({\sin \left(-0.5 \cdot \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right)}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}\right) \]
    5. Simplified78.5%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - \mathsf{fma}\left({\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}}\right) \]

    if 1.0200000000000001e-16 < phi2

    1. Initial program 47.6%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified47.6%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in phi1 around 0 49.5%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)}}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification62.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -5.3 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_2 + {\sin \left(\phi_2 \cdot -0.5\right)}^{2}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)\\ \mathbf{elif}\;\phi_2 \leq 1.02 \cdot 10^{-16}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \mathsf{fma}\left({\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\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} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_2 + {\sin \left(\phi_2 \cdot -0.5\right)}^{2}\right)}}\right)\\ \end{array} \]

Alternative 12: 60.8% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi1 < -8.60000000000000004e-23 or 2.14999999999999981e-9 < phi1

    1. Initial program 48.6%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified48.6%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in phi2 around 0 49.2%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(0.5 \cdot \phi_1\right)}^{2}}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]

    if -8.60000000000000004e-23 < phi1 < 2.14999999999999981e-9

    1. Initial program 78.2%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified78.2%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in phi1 around 0 75.2%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(-0.5 \cdot \phi_2\right)}^{2}}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification61.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -8.6 \cdot 10^{-23} \lor \neg \left(\phi_1 \leq 2.15 \cdot 10^{-9}\right):\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(0.5 \cdot \phi_1\right)}^{2} + {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_1}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_2 + {\sin \left(\phi_2 \cdot -0.5\right)}^{2}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)\\ \end{array} \]

Alternative 13: 62.1% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < -1.9000000000000001e-5 or 1.0200000000000001e-16 < phi2

    1. Initial program 46.1%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified46.1%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in phi1 around 0 47.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(-0.5 \cdot \phi_2\right)}^{2}}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]

    if -1.9000000000000001e-5 < phi2 < 1.0200000000000001e-16

    1. Initial program 78.9%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified78.9%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in phi2 around 0 78.5%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - \left(\cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification62.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -1.9 \cdot 10^{-5} \lor \neg \left(\phi_2 \leq 1.02 \cdot 10^{-16}\right):\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_2 + {\sin \left(\phi_2 \cdot -0.5\right)}^{2}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} + {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_1\right)}}\right)\\ \end{array} \]

Alternative 14: 62.1% accurate, 1.1× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < -4.00000000000000033e-5

    1. Initial program 44.5%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified44.5%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in phi1 around 0 45.5%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(-0.5 \cdot \phi_2\right)}^{2}}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]

    if -4.00000000000000033e-5 < phi2 < 1.0200000000000001e-16

    1. Initial program 78.9%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified78.9%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in phi2 around 0 78.5%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - \left(\cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}}\right) \]

    if 1.0200000000000001e-16 < phi2

    1. Initial program 47.6%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified47.6%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in phi1 around 0 49.5%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)}}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification62.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -4 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_2 + {\sin \left(\phi_2 \cdot -0.5\right)}^{2}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)\\ \mathbf{elif}\;\phi_2 \leq 1.02 \cdot 10^{-16}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} + {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_1\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_2 + {\sin \left(\phi_2 \cdot -0.5\right)}^{2}\right)}}\right)\\ \end{array} \]

Alternative 15: 56.6% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < -6.4999999999999997e-4 or 3.10000000000000005e-9 < phi2

    1. Initial program 45.5%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Step-by-step derivation
      1. div-sub45.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
      2. sin-diff47.6%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    3. Applied egg-rr47.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    4. Taylor expanded in lambda1 around 0 37.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    5. Taylor expanded in phi1 around 0 37.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}{\sqrt{\color{blue}{1 - \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(0.5 \cdot \phi_2\right)}^{2}\right)}}}\right) \]

    if -6.4999999999999997e-4 < phi2 < 3.10000000000000005e-9

    1. Initial program 78.4%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified78.4%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in phi2 around 0 73.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(0.5 \cdot \phi_1\right)}^{2}}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]
    4. Taylor expanded in phi2 around 0 73.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(0.5 \cdot \phi_1\right)}^{2}}}{\sqrt{1 - \left({\color{blue}{\sin \left(0.5 \cdot \phi_1\right)}}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification55.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -0.00065 \lor \neg \left(\phi_2 \leq 3.1 \cdot 10^{-9}\right):\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}{\sqrt{1 - \left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_2 + {\sin \left(0.5 \cdot \phi_2\right)}^{2}\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(0.5 \cdot \phi_1\right)}^{2} + {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_1}}{\sqrt{1 - \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right) + {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}\right)\\ \end{array} \]

Alternative 16: 56.2% accurate, 1.1× speedup?

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

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

\mathbf{elif}\;\phi_2 \leq 3.5 \cdot 10^{-9}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_2 + t_0 \cdot \cos \phi_1}}{\sqrt{1 - \left(t_3 \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_3\right)\right) + t_2\right)}}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < -1.2000000000000001e-28

    1. Initial program 45.5%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Taylor expanded in lambda2 around 0 37.2%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \color{blue}{\sin \left(0.5 \cdot \lambda_1\right)}\right)}}\right) \]
    3. Taylor expanded in phi1 around 0 37.3%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(-0.5 \cdot \phi_2\right)}^{2}}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]

    if -1.2000000000000001e-28 < phi2 < 3.4999999999999999e-9

    1. Initial program 79.8%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified79.8%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in phi2 around 0 76.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(0.5 \cdot \phi_1\right)}^{2}}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]
    4. Taylor expanded in phi2 around 0 76.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(0.5 \cdot \phi_1\right)}^{2}}}{\sqrt{1 - \left({\color{blue}{\sin \left(0.5 \cdot \phi_1\right)}}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]

    if 3.4999999999999999e-9 < phi2

    1. Initial program 46.8%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Step-by-step derivation
      1. div-sub46.8%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
      2. sin-diff49.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    3. Applied egg-rr49.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    4. Taylor expanded in lambda1 around 0 38.2%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    5. Taylor expanded in phi1 around 0 37.8%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}{\sqrt{\color{blue}{1 - \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(0.5 \cdot \phi_2\right)}^{2}\right)}}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification56.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -1.2 \cdot 10^{-28}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_2 + {\sin \left(\phi_2 \cdot -0.5\right)}^{2}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right)\\ \mathbf{elif}\;\phi_2 \leq 3.5 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(0.5 \cdot \phi_1\right)}^{2} + {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_1}}{\sqrt{1 - \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right) + {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}{\sqrt{1 - \left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_2 + {\sin \left(0.5 \cdot \phi_2\right)}^{2}\right)}}\right)\\ \end{array} \]

Alternative 17: 48.7% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
t_0 := {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
\mathbf{if}\;\phi_2 \leq -6 \cdot 10^{-5} \lor \neg \left(\phi_2 \leq 3.5 \cdot 10^{-9}\right):\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot t_0\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}{\sqrt{1 - \left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_2 + {\sin \left(0.5 \cdot \phi_2\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 \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_1\right)\right)}}{\sqrt{{\cos \left(\phi_1 \cdot -0.5\right)}^{2} - \cos \phi_1 \cdot t_0}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < -6.00000000000000015e-5 or 3.4999999999999999e-9 < phi2

    1. Initial program 45.2%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Step-by-step derivation
      1. div-sub45.2%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
      2. sin-diff47.3%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    3. Applied egg-rr47.3%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    4. Taylor expanded in lambda1 around 0 37.5%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    5. Taylor expanded in phi1 around 0 36.8%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}{\sqrt{\color{blue}{1 - \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(0.5 \cdot \phi_2\right)}^{2}\right)}}}\right) \]

    if -6.00000000000000015e-5 < phi2 < 3.4999999999999999e-9

    1. Initial program 79.2%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified79.2%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in lambda1 around 0 63.0%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}}\right) \]
    4. Taylor expanded in phi2 around 0 63.0%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - \left(\cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} + {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}}\right) \]
    5. Step-by-step derivation
      1. +-commutative63.0%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \color{blue}{\left({\sin \left(0.5 \cdot \phi_1\right)}^{2} + \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right)}}}\right) \]
      2. associate--r+63.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{\left(1 - {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right) - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}}\right) \]
      3. unpow263.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\left(1 - \color{blue}{\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_1\right)}\right) - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}\right) \]
      4. 1-sub-sin63.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}\right) \]
      5. unpow263.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{{\cos \left(0.5 \cdot \phi_1\right)}^{2}} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}\right) \]
      6. metadata-eval63.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{{\cos \left(\color{blue}{\left(-0.5 \cdot -1\right)} \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}\right) \]
      7. associate-*r*63.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{{\cos \color{blue}{\left(-0.5 \cdot \left(-1 \cdot \phi_1\right)\right)}}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}\right) \]
      8. *-commutative63.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{{\cos \color{blue}{\left(\left(-1 \cdot \phi_1\right) \cdot -0.5\right)}}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}\right) \]
      9. mul-1-neg63.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{{\cos \left(\color{blue}{\left(-\phi_1\right)} \cdot -0.5\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}\right) \]
      10. distribute-lft-neg-out63.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{{\cos \color{blue}{\left(-\phi_1 \cdot -0.5\right)}}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}\right) \]
      11. cos-neg63.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{{\color{blue}{\cos \left(\phi_1 \cdot -0.5\right)}}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}\right) \]
    6. Simplified63.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{{\cos \left(\phi_1 \cdot -0.5\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification50.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -6 \cdot 10^{-5} \lor \neg \left(\phi_2 \leq 3.5 \cdot 10^{-9}\right):\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}{\sqrt{1 - \left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_2 + {\sin \left(0.5 \cdot \phi_2\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} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{{\cos \left(\phi_1 \cdot -0.5\right)}^{2} - \cos \phi_1 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}}}\right)\\ \end{array} \]

Alternative 18: 44.2% accurate, 1.1× 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} + t_0 \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_0\right)\right)\\ \mathbf{if}\;\lambda_1 \leq -2.1 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(0.5 \cdot \phi_1\right)}^{2} + \cos \phi_1 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}}}{\sqrt{1 - t_1}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1}}{\sqrt{{\cos \left(\phi_1 \cdot -0.5\right)}^{2} - \cos \phi_1 \cdot {\sin \left(\lambda_2 \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)))
        (t_1
         (+
          (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
          (* t_0 (* (cos phi2) (* (cos phi1) t_0))))))
   (if (<= lambda1 -2.1e-5)
     (*
      R
      (*
       2.0
       (atan2
        (sqrt
         (+
          (pow (sin (* 0.5 phi1)) 2.0)
          (* (cos phi1) (pow (sin (* 0.5 lambda1)) 2.0))))
        (sqrt (- 1.0 t_1)))))
     (*
      R
      (*
       2.0
       (atan2
        (sqrt t_1)
        (sqrt
         (-
          (pow (cos (* phi1 -0.5)) 2.0)
          (* (cos phi1) (pow (sin (* 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));
	double t_1 = pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (cos(phi2) * (cos(phi1) * t_0)));
	double tmp;
	if (lambda1 <= -2.1e-5) {
		tmp = R * (2.0 * atan2(sqrt((pow(sin((0.5 * phi1)), 2.0) + (cos(phi1) * pow(sin((0.5 * lambda1)), 2.0)))), sqrt((1.0 - t_1))));
	} else {
		tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((pow(cos((phi1 * -0.5)), 2.0) - (cos(phi1) * pow(sin((lambda2 * -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) :: tmp
    t_0 = sin(((lambda1 - lambda2) / 2.0d0))
    t_1 = (sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (t_0 * (cos(phi2) * (cos(phi1) * t_0)))
    if (lambda1 <= (-2.1d-5)) then
        tmp = r * (2.0d0 * atan2(sqrt(((sin((0.5d0 * phi1)) ** 2.0d0) + (cos(phi1) * (sin((0.5d0 * lambda1)) ** 2.0d0)))), sqrt((1.0d0 - t_1))))
    else
        tmp = r * (2.0d0 * atan2(sqrt(t_1), sqrt(((cos((phi1 * (-0.5d0))) ** 2.0d0) - (cos(phi1) * (sin((lambda2 * (-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.sin(((lambda1 - lambda2) / 2.0));
	double t_1 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (Math.cos(phi2) * (Math.cos(phi1) * t_0)));
	double tmp;
	if (lambda1 <= -2.1e-5) {
		tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin((0.5 * phi1)), 2.0) + (Math.cos(phi1) * Math.pow(Math.sin((0.5 * lambda1)), 2.0)))), Math.sqrt((1.0 - t_1))));
	} else {
		tmp = R * (2.0 * Math.atan2(Math.sqrt(t_1), Math.sqrt((Math.pow(Math.cos((phi1 * -0.5)), 2.0) - (Math.cos(phi1) * Math.pow(Math.sin((lambda2 * -0.5)), 2.0))))));
	}
	return tmp;
}
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) + (t_0 * (math.cos(phi2) * (math.cos(phi1) * t_0)))
	tmp = 0
	if lambda1 <= -2.1e-5:
		tmp = R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin((0.5 * phi1)), 2.0) + (math.cos(phi1) * math.pow(math.sin((0.5 * lambda1)), 2.0)))), math.sqrt((1.0 - t_1))))
	else:
		tmp = R * (2.0 * math.atan2(math.sqrt(t_1), math.sqrt((math.pow(math.cos((phi1 * -0.5)), 2.0) - (math.cos(phi1) * math.pow(math.sin((lambda2 * -0.5)), 2.0))))))
	return tmp
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(t_0 * Float64(cos(phi2) * Float64(cos(phi1) * t_0))))
	tmp = 0.0
	if (lambda1 <= -2.1e-5)
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(0.5 * phi1)) ^ 2.0) + Float64(cos(phi1) * (sin(Float64(0.5 * lambda1)) ^ 2.0)))), sqrt(Float64(1.0 - t_1)))));
	else
		tmp = Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64((cos(Float64(phi1 * -0.5)) ^ 2.0) - Float64(cos(phi1) * (sin(Float64(lambda2 * -0.5)) ^ 2.0)))))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 2.0));
	t_1 = (sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (t_0 * (cos(phi2) * (cos(phi1) * t_0)));
	tmp = 0.0;
	if (lambda1 <= -2.1e-5)
		tmp = R * (2.0 * atan2(sqrt(((sin((0.5 * phi1)) ^ 2.0) + (cos(phi1) * (sin((0.5 * lambda1)) ^ 2.0)))), sqrt((1.0 - t_1))));
	else
		tmp = R * (2.0 * atan2(sqrt(t_1), sqrt(((cos((phi1 * -0.5)) ^ 2.0) - (cos(phi1) * (sin((lambda2 * -0.5)) ^ 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[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$0 * N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda1, -2.1e-5], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(0.5 * lambda1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$1], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(phi1 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(lambda2 * -0.5), $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 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_0\right)\right)\\
\mathbf{if}\;\lambda_1 \leq -2.1 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(0.5 \cdot \phi_1\right)}^{2} + \cos \phi_1 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}}}{\sqrt{1 - t_1}}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda1 < -2.09999999999999988e-5

    1. Initial program 48.4%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified48.4%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in phi2 around 0 37.8%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(0.5 \cdot \phi_1\right)}^{2}}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]
    4. Taylor expanded in lambda2 around 0 37.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot {\color{blue}{\sin \left(0.5 \cdot \lambda_1\right)}}^{2} + {\sin \left(0.5 \cdot \phi_1\right)}^{2}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]

    if -2.09999999999999988e-5 < lambda1

    1. Initial program 66.6%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified66.6%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in lambda1 around 0 58.2%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}}\right) \]
    4. Taylor expanded in phi2 around 0 48.8%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - \left(\cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} + {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}}\right) \]
    5. Step-by-step derivation
      1. +-commutative48.8%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \color{blue}{\left({\sin \left(0.5 \cdot \phi_1\right)}^{2} + \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right)}}}\right) \]
      2. associate--r+48.8%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{\left(1 - {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right) - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}}\right) \]
      3. unpow248.8%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\left(1 - \color{blue}{\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_1\right)}\right) - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}\right) \]
      4. 1-sub-sin48.8%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}\right) \]
      5. unpow248.8%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{{\cos \left(0.5 \cdot \phi_1\right)}^{2}} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}\right) \]
      6. metadata-eval48.8%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{{\cos \left(\color{blue}{\left(-0.5 \cdot -1\right)} \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}\right) \]
      7. associate-*r*48.8%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{{\cos \color{blue}{\left(-0.5 \cdot \left(-1 \cdot \phi_1\right)\right)}}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}\right) \]
      8. *-commutative48.8%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{{\cos \color{blue}{\left(\left(-1 \cdot \phi_1\right) \cdot -0.5\right)}}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}\right) \]
      9. mul-1-neg48.8%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{{\cos \left(\color{blue}{\left(-\phi_1\right)} \cdot -0.5\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}\right) \]
      10. distribute-lft-neg-out48.8%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{{\cos \color{blue}{\left(-\phi_1 \cdot -0.5\right)}}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}\right) \]
      11. cos-neg48.8%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{{\color{blue}{\cos \left(\phi_1 \cdot -0.5\right)}}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}\right) \]
    6. Simplified48.8%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{{\cos \left(\phi_1 \cdot -0.5\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification46.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -2.1 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(0.5 \cdot \phi_1\right)}^{2} + \cos \phi_1 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{{\cos \left(\phi_1 \cdot -0.5\right)}^{2} - \cos \phi_1 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}}}\right)\\ \end{array} \]

Alternative 19: 46.4% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < -0.0012999999999999999 or 1.0200000000000001e-16 < phi2

    1. Initial program 45.9%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Step-by-step derivation
      1. div-sub45.9%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
      2. sin-diff48.0%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    3. Applied egg-rr48.0%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    4. Taylor expanded in lambda1 around 0 38.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    5. Taylor expanded in phi1 around 0 37.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}{\sqrt{\color{blue}{1 - \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(0.5 \cdot \phi_2\right)}^{2}\right)}}}\right) \]

    if -0.0012999999999999999 < phi2 < 1.0200000000000001e-16

    1. Initial program 78.3%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Step-by-step derivation
      1. div-sub78.3%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
      2. sin-diff78.3%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    3. Applied egg-rr78.3%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    4. Taylor expanded in lambda1 around 0 59.2%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    5. Taylor expanded in phi2 around 0 59.2%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}{\sqrt{\color{blue}{1 - \left(\cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification48.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -0.0013 \lor \neg \left(\phi_2 \leq 1.02 \cdot 10^{-16}\right):\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}{\sqrt{1 - \left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_2 + {\sin \left(0.5 \cdot \phi_2\right)}^{2}\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}{\sqrt{1 - \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} + {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_1\right)}}\right)\\ \end{array} \]

Alternative 20: 39.7% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda2 < 2.9000000000000003e-14

    1. Initial program 68.1%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified68.1%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in lambda1 around 0 49.7%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}}\right) \]
    4. Taylor expanded in lambda2 around 0 41.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}}\right) \]

    if 2.9000000000000003e-14 < lambda2

    1. Initial program 49.5%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Step-by-step derivation
      1. div-sub49.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
      2. sin-diff50.7%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    3. Applied egg-rr50.7%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\color{blue}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    4. Taylor expanded in lambda1 around 0 49.9%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}}{\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} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    5. Taylor expanded in phi2 around 0 42.0%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}{\sqrt{\color{blue}{1 - \left(\cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification41.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 2.9 \cdot 10^{-14}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\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{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}{\sqrt{1 - \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} + {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_1\right)}}\right)\\ \end{array} \]

Alternative 21: 37.8% accurate, 1.1× 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} + t_0 \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_0\right)\right)\\ t_2 := \sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)\\ \mathbf{if}\;t_0 \leq 0.1:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1}}{\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 + 0.5 \cdot \frac{\phi_1 \cdot \phi_1}{\frac{t_2}{0.25 + {t_2}^{2} \cdot -0.5}}}{\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)
          (* t_0 (* (cos phi2) (* (cos phi1) t_0)))))
        (t_2 (sin (* 0.5 (- lambda1 lambda2)))))
   (if (<= t_0 0.1)
     (*
      R
      (*
       2.0
       (atan2
        (sqrt t_1)
        (sqrt (- 1.0 (pow (sin (* 0.5 (- phi1 phi2))) 2.0))))))
     (*
      R
      (*
       2.0
       (atan2
        (+
         t_2
         (* 0.5 (/ (* phi1 phi1) (/ t_2 (+ 0.25 (* (pow t_2 2.0) -0.5))))))
        (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) + (t_0 * (cos(phi2) * (cos(phi1) * t_0)));
	double t_2 = sin((0.5 * (lambda1 - lambda2)));
	double tmp;
	if (t_0 <= 0.1) {
		tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - pow(sin((0.5 * (phi1 - phi2))), 2.0)))));
	} else {
		tmp = R * (2.0 * atan2((t_2 + (0.5 * ((phi1 * phi1) / (t_2 / (0.25 + (pow(t_2, 2.0) * -0.5)))))), sqrt((1.0 - t_1))));
	}
	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(((lambda1 - lambda2) / 2.0d0))
    t_1 = (sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (t_0 * (cos(phi2) * (cos(phi1) * t_0)))
    t_2 = sin((0.5d0 * (lambda1 - lambda2)))
    if (t_0 <= 0.1d0) then
        tmp = r * (2.0d0 * atan2(sqrt(t_1), sqrt((1.0d0 - (sin((0.5d0 * (phi1 - phi2))) ** 2.0d0)))))
    else
        tmp = r * (2.0d0 * atan2((t_2 + (0.5d0 * ((phi1 * phi1) / (t_2 / (0.25d0 + ((t_2 ** 2.0d0) * (-0.5d0))))))), sqrt((1.0d0 - t_1))))
    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.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (Math.cos(phi2) * (Math.cos(phi1) * t_0)));
	double t_2 = Math.sin((0.5 * (lambda1 - lambda2)));
	double tmp;
	if (t_0 <= 0.1) {
		tmp = R * (2.0 * Math.atan2(Math.sqrt(t_1), Math.sqrt((1.0 - Math.pow(Math.sin((0.5 * (phi1 - phi2))), 2.0)))));
	} else {
		tmp = R * (2.0 * Math.atan2((t_2 + (0.5 * ((phi1 * phi1) / (t_2 / (0.25 + (Math.pow(t_2, 2.0) * -0.5)))))), Math.sqrt((1.0 - t_1))));
	}
	return tmp;
}
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) + (t_0 * (math.cos(phi2) * (math.cos(phi1) * t_0)))
	t_2 = math.sin((0.5 * (lambda1 - lambda2)))
	tmp = 0
	if t_0 <= 0.1:
		tmp = R * (2.0 * math.atan2(math.sqrt(t_1), math.sqrt((1.0 - math.pow(math.sin((0.5 * (phi1 - phi2))), 2.0)))))
	else:
		tmp = R * (2.0 * math.atan2((t_2 + (0.5 * ((phi1 * phi1) / (t_2 / (0.25 + (math.pow(t_2, 2.0) * -0.5)))))), math.sqrt((1.0 - t_1))))
	return tmp
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(t_0 * Float64(cos(phi2) * Float64(cos(phi1) * t_0))))
	t_2 = sin(Float64(0.5 * Float64(lambda1 - lambda2)))
	tmp = 0.0
	if (t_0 <= 0.1)
		tmp = Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0))))));
	else
		tmp = Float64(R * Float64(2.0 * atan(Float64(t_2 + Float64(0.5 * Float64(Float64(phi1 * phi1) / Float64(t_2 / Float64(0.25 + Float64((t_2 ^ 2.0) * -0.5)))))), sqrt(Float64(1.0 - t_1)))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 2.0));
	t_1 = (sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (t_0 * (cos(phi2) * (cos(phi1) * t_0)));
	t_2 = sin((0.5 * (lambda1 - lambda2)));
	tmp = 0.0;
	if (t_0 <= 0.1)
		tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - (sin((0.5 * (phi1 - phi2))) ^ 2.0)))));
	else
		tmp = R * (2.0 * atan2((t_2 + (0.5 * ((phi1 * phi1) / (t_2 / (0.25 + ((t_2 ^ 2.0) * -0.5)))))), sqrt((1.0 - t_1))));
	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[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$0 * N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.1], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$1], $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[(t$95$2 + N[(0.5 * N[(N[(phi1 * phi1), $MachinePrecision] / N[(t$95$2 / N[(0.25 + N[(N[Power[t$95$2, 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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} + t_0 \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_0\right)\right)\\
t_2 := \sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)\\
\mathbf{if}\;t_0 \leq 0.1:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1}}{\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 + 0.5 \cdot \frac{\phi_1 \cdot \phi_1}{\frac{t_2}{0.25 + {t_2}^{2} \cdot -0.5}}}{\sqrt{1 - t_1}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (sin.f64 (/.f64 (-.f64 lambda1 lambda2) 2)) < 0.10000000000000001

    1. Initial program 64.7%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified64.7%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in lambda1 around 0 55.4%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}}\right) \]
    4. Taylor expanded in lambda2 around 0 43.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}}\right) \]

    if 0.10000000000000001 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) 2))

    1. Initial program 57.1%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified57.1%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in phi2 around 0 43.0%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(0.5 \cdot \phi_1\right)}^{2}}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]
    4. Taylor expanded in phi1 around 0 29.7%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right) + 0.5 \cdot \frac{{\phi_1}^{2} \cdot \left(0.25 + -0.5 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right)}{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]
    5. Step-by-step derivation
      1. associate-/l*29.7%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right) + 0.5 \cdot \color{blue}{\frac{{\phi_1}^{2}}{\frac{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}{0.25 + -0.5 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]
      2. unpow229.7%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right) + 0.5 \cdot \frac{\color{blue}{\phi_1 \cdot \phi_1}}{\frac{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}{0.25 + -0.5 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]
      3. *-commutative29.7%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right) + 0.5 \cdot \frac{\phi_1 \cdot \phi_1}{\frac{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}{0.25 + \color{blue}{{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot -0.5}}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]
    6. Simplified29.7%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right) + 0.5 \cdot \frac{\phi_1 \cdot \phi_1}{\frac{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}{0.25 + {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot -0.5}}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification38.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \leq 0.1:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\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{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right) + 0.5 \cdot \frac{\phi_1 \cdot \phi_1}{\frac{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}{0.25 + {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot -0.5}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)\\ \end{array} \]

Alternative 22: 37.1% accurate, 1.2× 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}\\ \mathbf{if}\;\lambda_1 \leq -0.048:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_2, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, 0.25 \cdot \left(\phi_2 \cdot \phi_2\right)\right)}}{\sqrt{1 - \left(t_1 + \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_0\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1 + t_0 \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_0\right)\right)}}{\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 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)))
   (if (<= lambda1 -0.048)
     (*
      R
      (*
       2.0
       (atan2
        (sqrt
         (fma
          (cos phi2)
          (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0)
          (* 0.25 (* phi2 phi2))))
        (sqrt
         (-
          1.0
          (+
           t_1
           (* (* (* (cos phi2) (cos phi1)) t_0) (sin (* 0.5 lambda1)))))))))
     (*
      R
      (*
       2.0
       (atan2
        (sqrt (+ t_1 (* t_0 (* (cos phi2) (* (cos phi1) t_0)))))
        (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 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
	double tmp;
	if (lambda1 <= -0.048) {
		tmp = R * (2.0 * atan2(sqrt(fma(cos(phi2), pow(sin((0.5 * (lambda1 - lambda2))), 2.0), (0.25 * (phi2 * phi2)))), sqrt((1.0 - (t_1 + (((cos(phi2) * cos(phi1)) * t_0) * sin((0.5 * lambda1))))))));
	} else {
		tmp = R * (2.0 * atan2(sqrt((t_1 + (t_0 * (cos(phi2) * (cos(phi1) * t_0))))), sqrt((1.0 - pow(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 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0
	tmp = 0.0
	if (lambda1 <= -0.048)
		tmp = Float64(R * Float64(2.0 * atan(sqrt(fma(cos(phi2), (sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0), Float64(0.25 * Float64(phi2 * phi2)))), sqrt(Float64(1.0 - Float64(t_1 + Float64(Float64(Float64(cos(phi2) * cos(phi1)) * t_0) * sin(Float64(0.5 * lambda1)))))))));
	else
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_1 + Float64(t_0 * Float64(cos(phi2) * Float64(cos(phi1) * t_0))))), sqrt(Float64(1.0 - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 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[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[lambda1, -0.048], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(0.25 * N[(phi2 * phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(t$95$1 + N[(N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Sin[N[(0.5 * lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$1 + N[(t$95$0 * N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
\mathbf{if}\;\lambda_1 \leq -0.048:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_2, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, 0.25 \cdot \left(\phi_2 \cdot \phi_2\right)\right)}}{\sqrt{1 - \left(t_1 + \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_0\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda1 < -0.048000000000000001

    1. Initial program 46.7%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Taylor expanded in lambda2 around 0 46.0%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \color{blue}{\sin \left(0.5 \cdot \lambda_1\right)}\right)}}\right) \]
    3. Taylor expanded in phi2 around 0 34.9%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\left(\sin \left(0.5 \cdot \phi_1\right) + -0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    4. Taylor expanded in phi1 around 0 28.9%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{0.25 \cdot {\phi_2}^{2} + \cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    5. Step-by-step derivation
      1. +-commutative28.9%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\color{blue}{\cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + 0.25 \cdot {\phi_2}^{2}}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
      2. fma-def28.9%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\color{blue}{\mathsf{fma}\left(\cos \phi_2, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, 0.25 \cdot {\phi_2}^{2}\right)}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
      3. unpow228.9%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_2, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, 0.25 \cdot \color{blue}{\left(\phi_2 \cdot \phi_2\right)}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    6. Simplified28.9%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\mathsf{fma}\left(\cos \phi_2, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, 0.25 \cdot \left(\phi_2 \cdot \phi_2\right)\right)}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]

    if -0.048000000000000001 < lambda1

    1. Initial program 66.9%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified66.9%

      \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
    3. Taylor expanded in lambda1 around 0 58.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}}\right) \]
    4. Taylor expanded in lambda2 around 0 41.0%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification38.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -0.048:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_2, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, 0.25 \cdot \left(\phi_2 \cdot \phi_2\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\ \end{array} \]

Alternative 23: 27.3% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := \left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_0\\ \mathbf{if}\;t_0 \leq 0.1:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_0 \cdot t_1 + {\sin \left(0.5 \cdot \phi_1\right)}^{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{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \sqrt{\cos \phi_2}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1 \cdot \sin \left(0.5 \cdot \lambda_1\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 phi2) (cos phi1)) t_0)))
   (if (<= t_0 0.1)
     (*
      R
      (*
       2.0
       (atan2
        (sqrt (+ (* t_0 t_1) (pow (sin (* 0.5 phi1)) 2.0)))
        (sqrt (- 1.0 (pow (sin (* 0.5 (- phi1 phi2))) 2.0))))))
     (*
      R
      (*
       2.0
       (atan2
        (* (sin (* 0.5 (- lambda1 lambda2))) (sqrt (cos phi2)))
        (sqrt
         (-
          1.0
          (+
           (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
           (* t_1 (sin (* 0.5 lambda1))))))))))))
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) * cos(phi1)) * t_0;
	double tmp;
	if (t_0 <= 0.1) {
		tmp = R * (2.0 * atan2(sqrt(((t_0 * t_1) + pow(sin((0.5 * phi1)), 2.0))), sqrt((1.0 - pow(sin((0.5 * (phi1 - phi2))), 2.0)))));
	} else {
		tmp = R * (2.0 * atan2((sin((0.5 * (lambda1 - lambda2))) * sqrt(cos(phi2))), sqrt((1.0 - (pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_1 * sin((0.5 * lambda1))))))));
	}
	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 = (cos(phi2) * cos(phi1)) * t_0
    if (t_0 <= 0.1d0) then
        tmp = r * (2.0d0 * atan2(sqrt(((t_0 * t_1) + (sin((0.5d0 * phi1)) ** 2.0d0))), sqrt((1.0d0 - (sin((0.5d0 * (phi1 - phi2))) ** 2.0d0)))))
    else
        tmp = r * (2.0d0 * atan2((sin((0.5d0 * (lambda1 - lambda2))) * sqrt(cos(phi2))), sqrt((1.0d0 - ((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (t_1 * sin((0.5d0 * lambda1))))))))
    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.cos(phi2) * Math.cos(phi1)) * t_0;
	double tmp;
	if (t_0 <= 0.1) {
		tmp = R * (2.0 * Math.atan2(Math.sqrt(((t_0 * t_1) + Math.pow(Math.sin((0.5 * phi1)), 2.0))), Math.sqrt((1.0 - Math.pow(Math.sin((0.5 * (phi1 - phi2))), 2.0)))));
	} else {
		tmp = R * (2.0 * Math.atan2((Math.sin((0.5 * (lambda1 - lambda2))) * Math.sqrt(Math.cos(phi2))), Math.sqrt((1.0 - (Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_1 * Math.sin((0.5 * lambda1))))))));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(((lambda1 - lambda2) / 2.0))
	t_1 = (math.cos(phi2) * math.cos(phi1)) * t_0
	tmp = 0
	if t_0 <= 0.1:
		tmp = R * (2.0 * math.atan2(math.sqrt(((t_0 * t_1) + math.pow(math.sin((0.5 * phi1)), 2.0))), math.sqrt((1.0 - math.pow(math.sin((0.5 * (phi1 - phi2))), 2.0)))))
	else:
		tmp = R * (2.0 * math.atan2((math.sin((0.5 * (lambda1 - lambda2))) * math.sqrt(math.cos(phi2))), math.sqrt((1.0 - (math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_1 * math.sin((0.5 * lambda1))))))))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = Float64(Float64(cos(phi2) * cos(phi1)) * t_0)
	tmp = 0.0
	if (t_0 <= 0.1)
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(Float64(t_0 * t_1) + (sin(Float64(0.5 * phi1)) ^ 2.0))), sqrt(Float64(1.0 - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0))))));
	else
		tmp = Float64(R * Float64(2.0 * atan(Float64(sin(Float64(0.5 * Float64(lambda1 - lambda2))) * sqrt(cos(phi2))), sqrt(Float64(1.0 - Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_1 * sin(Float64(0.5 * lambda1)))))))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 2.0));
	t_1 = (cos(phi2) * cos(phi1)) * t_0;
	tmp = 0.0;
	if (t_0 <= 0.1)
		tmp = R * (2.0 * atan2(sqrt(((t_0 * t_1) + (sin((0.5 * phi1)) ^ 2.0))), sqrt((1.0 - (sin((0.5 * (phi1 - phi2))) ^ 2.0)))));
	else
		tmp = R * (2.0 * atan2((sin((0.5 * (lambda1 - lambda2))) * sqrt(cos(phi2))), sqrt((1.0 - ((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (t_1 * sin((0.5 * lambda1))))))));
	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[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]}, If[LessEqual[t$95$0, 0.1], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[(t$95$0 * t$95$1), $MachinePrecision] + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $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[(N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Cos[phi2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$1 * N[Sin[N[(0.5 * lambda1), $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 := \left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_0\\
\mathbf{if}\;t_0 \leq 0.1:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_0 \cdot t_1 + {\sin \left(0.5 \cdot \phi_1\right)}^{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{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \sqrt{\cos \phi_2}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1 \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (sin.f64 (/.f64 (-.f64 lambda1 lambda2) 2)) < 0.10000000000000001

    1. Initial program 64.7%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Taylor expanded in lambda2 around 0 51.9%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \color{blue}{\sin \left(0.5 \cdot \lambda_1\right)}\right)}}\right) \]
    3. Taylor expanded in phi2 around 0 37.7%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\sin \left(0.5 \cdot \phi_1\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    4. Taylor expanded in lambda1 around 0 32.0%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(0.5 \cdot \phi_1\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{\color{blue}{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}}\right) \]

    if 0.10000000000000001 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) 2))

    1. Initial program 57.1%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Taylor expanded in lambda2 around 0 41.2%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \color{blue}{\sin \left(0.5 \cdot \lambda_1\right)}\right)}}\right) \]
    3. Taylor expanded in phi2 around 0 29.0%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\sin \left(0.5 \cdot \phi_1\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    4. Taylor expanded in phi1 around 0 23.4%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sqrt{\cos \phi_2} \cdot \sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification29.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \leq 0.1:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) + {\sin \left(0.5 \cdot \phi_1\right)}^{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{\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \sqrt{\cos \phi_2}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right)\\ \end{array} \]

Alternative 24: 35.0% 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(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_0\right)\right)}}{\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))))
   (*
    R
    (*
     2.0
     (atan2
      (sqrt
       (+
        (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
        (* t_0 (* (cos phi2) (* (cos phi1) t_0)))))
      (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));
	return R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (cos(phi2) * (cos(phi1) * t_0))))), sqrt((1.0 - pow(sin((0.5 * (phi1 - phi2))), 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 * (cos(phi2) * (cos(phi1) * t_0))))), sqrt((1.0d0 - (sin((0.5d0 * (phi1 - phi2))) ** 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 * (Math.cos(phi2) * (Math.cos(phi1) * t_0))))), Math.sqrt((1.0 - Math.pow(Math.sin((0.5 * (phi1 - phi2))), 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 * (math.cos(phi2) * (math.cos(phi1) * t_0))))), math.sqrt((1.0 - math.pow(math.sin((0.5 * (phi1 - phi2))), 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(cos(phi2) * Float64(cos(phi1) * t_0))))), sqrt(Float64(1.0 - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 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 * (cos(phi2) * (cos(phi1) * t_0))))), sqrt((1.0 - (sin((0.5 * (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]}, 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[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_0\right)\right)}}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 62.3%

    \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  2. Simplified62.3%

    \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right)}}\right)} \]
  3. Taylor expanded in lambda1 around 0 49.3%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}}\right) \]
  4. Taylor expanded in lambda2 around 0 36.2%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{\color{blue}{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}}\right) \]
  5. Final simplification36.2%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right) \]

Alternative 25: 25.8% 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{t_0 \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_0\right) + {\sin \left(0.5 \cdot \phi_1\right)}^{2}}}{\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))))
   (*
    R
    (*
     2.0
     (atan2
      (sqrt
       (+
        (* t_0 (* (* (cos phi2) (cos phi1)) t_0))
        (pow (sin (* 0.5 phi1)) 2.0)))
      (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));
	return R * (2.0 * atan2(sqrt(((t_0 * ((cos(phi2) * cos(phi1)) * t_0)) + pow(sin((0.5 * phi1)), 2.0))), sqrt((1.0 - pow(sin((0.5 * (phi1 - phi2))), 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(((t_0 * ((cos(phi2) * cos(phi1)) * t_0)) + (sin((0.5d0 * phi1)) ** 2.0d0))), sqrt((1.0d0 - (sin((0.5d0 * (phi1 - phi2))) ** 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(((t_0 * ((Math.cos(phi2) * Math.cos(phi1)) * t_0)) + Math.pow(Math.sin((0.5 * phi1)), 2.0))), Math.sqrt((1.0 - Math.pow(Math.sin((0.5 * (phi1 - phi2))), 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(((t_0 * ((math.cos(phi2) * math.cos(phi1)) * t_0)) + math.pow(math.sin((0.5 * phi1)), 2.0))), math.sqrt((1.0 - math.pow(math.sin((0.5 * (phi1 - phi2))), 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(Float64(t_0 * Float64(Float64(cos(phi2) * cos(phi1)) * t_0)) + (sin(Float64(0.5 * phi1)) ^ 2.0))), sqrt(Float64(1.0 - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0))))))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(((lambda1 - lambda2) / 2.0));
	tmp = R * (2.0 * atan2(sqrt(((t_0 * ((cos(phi2) * cos(phi1)) * t_0)) + (sin((0.5 * phi1)) ^ 2.0))), sqrt((1.0 - (sin((0.5 * (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]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[(t$95$0 * N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $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)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_0 \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_0\right) + {\sin \left(0.5 \cdot \phi_1\right)}^{2}}}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 62.3%

    \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  2. Taylor expanded in lambda2 around 0 48.6%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \color{blue}{\sin \left(0.5 \cdot \lambda_1\right)}\right)}}\right) \]
  3. Taylor expanded in phi2 around 0 35.0%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\sin \left(0.5 \cdot \phi_1\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
  4. Taylor expanded in lambda1 around 0 27.5%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(0.5 \cdot \phi_1\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{\color{blue}{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}}\right) \]
  5. Final simplification27.5%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) + {\sin \left(0.5 \cdot \phi_1\right)}^{2}}}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right) \]

Alternative 26: 15.6% accurate, 1.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < 5.69999999999999971e-18

    1. Initial program 67.3%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Taylor expanded in lambda2 around 0 51.7%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \color{blue}{\sin \left(0.5 \cdot \lambda_1\right)}\right)}}\right) \]
    3. Taylor expanded in phi2 around 0 46.4%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\left(\sin \left(0.5 \cdot \phi_1\right) + -0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    4. Taylor expanded in phi2 around -inf 20.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sin \left(0.5 \cdot \phi_1\right) + -0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]

    if 5.69999999999999971e-18 < phi2

    1. Initial program 47.6%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Taylor expanded in lambda2 around 0 39.4%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \color{blue}{\sin \left(0.5 \cdot \lambda_1\right)}\right)}}\right) \]
    3. Taylor expanded in phi2 around 0 19.2%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\left(\sin \left(0.5 \cdot \phi_1\right) + -0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    4. Taylor expanded in phi2 around inf 16.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    5. Step-by-step derivation
      1. associate-*r*16.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
      2. *-commutative16.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot 0.5\right)} \cdot \cos \left(0.5 \cdot \phi_1\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    6. Simplified16.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification19.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 5.7 \cdot 10^{-18}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sin \left(0.5 \cdot \phi_1\right) + -0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right)\\ \end{array} \]

Alternative 27: 15.7% accurate, 1.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < 4.80000000000000046e-19

    1. Initial program 67.3%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Taylor expanded in lambda2 around 0 51.7%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \color{blue}{\sin \left(0.5 \cdot \lambda_1\right)}\right)}}\right) \]
    3. Taylor expanded in phi2 around 0 46.4%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\left(\sin \left(0.5 \cdot \phi_1\right) + -0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    4. Taylor expanded in phi2 around -inf 20.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\sin \left(0.5 \cdot \phi_1\right) + -0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]

    if 4.80000000000000046e-19 < phi2

    1. Initial program 47.6%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Taylor expanded in lambda2 around 0 39.4%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \color{blue}{\sin \left(0.5 \cdot \lambda_1\right)}\right)}}\right) \]
    3. Taylor expanded in phi2 around 0 19.2%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\left(\sin \left(0.5 \cdot \phi_1\right) + -0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    4. Taylor expanded in phi2 around inf 16.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{-1 \cdot \sin \left(0.5 \cdot \phi_1\right) + 0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    5. Step-by-step derivation
      1. +-commutative16.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right) + -1 \cdot \sin \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
      2. mul-1-neg16.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right) + \color{blue}{\left(-\sin \left(0.5 \cdot \phi_1\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
      3. unsub-neg16.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right) - \sin \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
      4. associate-*r*16.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)} - \sin \left(0.5 \cdot \phi_1\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
      5. *-commutative16.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot 0.5\right)} \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(0.5 \cdot \phi_1\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    6. Simplified16.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification19.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 4.8 \cdot 10^{-19}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sin \left(0.5 \cdot \phi_1\right) + -0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(0.5 \cdot \phi_1\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right)\\ \end{array} \]

Alternative 28: 12.8% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := \cos \phi_1 \cdot \left(\cos \phi_2 \cdot t_0\right)\\ t_2 := \phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\\ \mathbf{if}\;\phi_1 \leq -4.5 \cdot 10^{-116}:\\ \;\;\;\;\tan^{-1}_* \frac{-0.5 \cdot t_2}{\sqrt{1 - \mathsf{fma}\left(t_0, t_1, {\sin \left(\phi_2 \cdot -0.5\right)}^{2}\right)}} \cdot \left(R \cdot 2\right)\\ \mathbf{elif}\;\phi_1 \leq 1.9 \cdot 10^{-104}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\phi_2 \cdot -0.5\right)}{\sqrt{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(R \cdot 2\right) \cdot \tan^{-1}_* \frac{0.5 \cdot t_2}{\sqrt{1 - \mathsf{fma}\left(t_0, t_1, {\sin \left(\frac{\phi_1 - \phi_2}{2}\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 (* (cos phi1) (* (cos phi2) t_0)))
        (t_2 (* phi1 (cos (* phi2 -0.5)))))
   (if (<= phi1 -4.5e-116)
     (*
      (atan2
       (* -0.5 t_2)
       (sqrt (- 1.0 (fma t_0 t_1 (pow (sin (* phi2 -0.5)) 2.0)))))
      (* R 2.0))
     (if (<= phi1 1.9e-104)
       (*
        R
        (*
         2.0
         (atan2
          (* (cos (* 0.5 phi1)) (* phi2 -0.5))
          (sqrt
           (-
            1.0
            (+
             (* (cos phi1) (* (cos phi2) (pow (sin (* 0.5 lambda1)) 2.0)))
             (pow (sin (* 0.5 (- phi1 phi2))) 2.0)))))))
       (*
        (* R 2.0)
        (atan2
         (* 0.5 t_2)
         (sqrt
          (- 1.0 (fma t_0 t_1 (pow (sin (/ (- phi1 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 = cos(phi1) * (cos(phi2) * t_0);
	double t_2 = phi1 * cos((phi2 * -0.5));
	double tmp;
	if (phi1 <= -4.5e-116) {
		tmp = atan2((-0.5 * t_2), sqrt((1.0 - fma(t_0, t_1, pow(sin((phi2 * -0.5)), 2.0))))) * (R * 2.0);
	} else if (phi1 <= 1.9e-104) {
		tmp = R * (2.0 * atan2((cos((0.5 * phi1)) * (phi2 * -0.5)), sqrt((1.0 - ((cos(phi1) * (cos(phi2) * pow(sin((0.5 * lambda1)), 2.0))) + pow(sin((0.5 * (phi1 - phi2))), 2.0))))));
	} else {
		tmp = (R * 2.0) * atan2((0.5 * t_2), sqrt((1.0 - fma(t_0, t_1, pow(sin(((phi1 - phi2) / 2.0)), 2.0)))));
	}
	return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = Float64(cos(phi1) * Float64(cos(phi2) * t_0))
	t_2 = Float64(phi1 * cos(Float64(phi2 * -0.5)))
	tmp = 0.0
	if (phi1 <= -4.5e-116)
		tmp = Float64(atan(Float64(-0.5 * t_2), sqrt(Float64(1.0 - fma(t_0, t_1, (sin(Float64(phi2 * -0.5)) ^ 2.0))))) * Float64(R * 2.0));
	elseif (phi1 <= 1.9e-104)
		tmp = Float64(R * Float64(2.0 * atan(Float64(cos(Float64(0.5 * phi1)) * Float64(phi2 * -0.5)), sqrt(Float64(1.0 - Float64(Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(0.5 * lambda1)) ^ 2.0))) + (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0)))))));
	else
		tmp = Float64(Float64(R * 2.0) * atan(Float64(0.5 * t_2), sqrt(Float64(1.0 - fma(t_0, t_1, (sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 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[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(phi1 * N[Cos[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -4.5e-116], N[(N[ArcTan[N[(-0.5 * t$95$2), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(t$95$0 * t$95$1 + N[Power[N[Sin[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(R * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 1.9e-104], N[(R * N[(2.0 * N[ArcTan[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(phi2 * -0.5), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(0.5 * lambda1), $MachinePrecision]], $MachinePrecision], 2.0], $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], N[(N[(R * 2.0), $MachinePrecision] * N[ArcTan[N[(0.5 * t$95$2), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(t$95$0 * t$95$1 + N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $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 := \cos \phi_1 \cdot \left(\cos \phi_2 \cdot t_0\right)\\
t_2 := \phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\\
\mathbf{if}\;\phi_1 \leq -4.5 \cdot 10^{-116}:\\
\;\;\;\;\tan^{-1}_* \frac{-0.5 \cdot t_2}{\sqrt{1 - \mathsf{fma}\left(t_0, t_1, {\sin \left(\phi_2 \cdot -0.5\right)}^{2}\right)}} \cdot \left(R \cdot 2\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi1 < -4.50000000000000012e-116

    1. Initial program 57.1%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified57.1%

      \[\leadsto \color{blue}{\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right)} \]
    3. Taylor expanded in phi1 around 0 34.1%

      \[\leadsto \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\color{blue}{\left(\sin \left(-0.5 \cdot \phi_2\right) + 0.5 \cdot \left(\phi_1 \cdot \cos \left(-0.5 \cdot \phi_2\right)\right)\right)}}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right) \]
    4. Taylor expanded in phi1 around -inf 14.4%

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{-0.5 \cdot \left(\phi_1 \cdot \cos \left(-0.5 \cdot \phi_2\right)\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right) \]
    5. Step-by-step derivation
      1. *-commutative14.4%

        \[\leadsto \tan^{-1}_* \frac{-0.5 \cdot \left(\phi_1 \cdot \cos \color{blue}{\left(\phi_2 \cdot -0.5\right)}\right)}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right) \]
    6. Simplified14.4%

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{-0.5 \cdot \left(\phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right) \]
    7. Taylor expanded in phi1 around 0 14.4%

      \[\leadsto \tan^{-1}_* \frac{-0.5 \cdot \left(\phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\right)}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), \color{blue}{{\sin \left(-0.5 \cdot \phi_2\right)}^{2}}\right)}} \cdot \left(R \cdot 2\right) \]
    8. Step-by-step derivation
      1. *-commutative14.4%

        \[\leadsto \tan^{-1}_* \frac{-0.5 \cdot \left(\phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\right)}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \color{blue}{\left(\phi_2 \cdot -0.5\right)}}^{2}\right)}} \cdot \left(R \cdot 2\right) \]
    9. Simplified14.4%

      \[\leadsto \tan^{-1}_* \frac{-0.5 \cdot \left(\phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\right)}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), \color{blue}{{\sin \left(\phi_2 \cdot -0.5\right)}^{2}}\right)}} \cdot \left(R \cdot 2\right) \]

    if -4.50000000000000012e-116 < phi1 < 1.9e-104

    1. Initial program 80.2%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Taylor expanded in lambda2 around 0 64.7%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \color{blue}{\sin \left(0.5 \cdot \lambda_1\right)}\right)}}\right) \]
    3. Taylor expanded in phi2 around 0 42.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\left(\sin \left(0.5 \cdot \phi_1\right) + -0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    4. Taylor expanded in phi2 around -inf 18.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{-0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    5. Step-by-step derivation
      1. associate-*r*18.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(-0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
      2. *-commutative18.1%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot -0.5\right)} \cdot \cos \left(0.5 \cdot \phi_1\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    6. Simplified18.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot -0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    7. Taylor expanded in lambda2 around 0 18.1%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\left(\phi_2 \cdot -0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}{\sqrt{\color{blue}{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}}\right) \]

    if 1.9e-104 < phi1

    1. Initial program 53.6%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified53.6%

      \[\leadsto \color{blue}{\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right)} \]
    3. Taylor expanded in phi1 around 0 35.3%

      \[\leadsto \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\color{blue}{\left(\sin \left(-0.5 \cdot \phi_2\right) + 0.5 \cdot \left(\phi_1 \cdot \cos \left(-0.5 \cdot \phi_2\right)\right)\right)}}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right) \]
    4. Taylor expanded in phi1 around inf 13.0%

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{0.5 \cdot \left(\phi_1 \cdot \cos \left(-0.5 \cdot \phi_2\right)\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right) \]
    5. Step-by-step derivation
      1. *-commutative13.0%

        \[\leadsto \tan^{-1}_* \frac{0.5 \cdot \left(\phi_1 \cdot \cos \color{blue}{\left(\phi_2 \cdot -0.5\right)}\right)}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right) \]
    6. Simplified13.0%

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{0.5 \cdot \left(\phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification14.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -4.5 \cdot 10^{-116}:\\ \;\;\;\;\tan^{-1}_* \frac{-0.5 \cdot \left(\phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\right)}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\phi_2 \cdot -0.5\right)}^{2}\right)}} \cdot \left(R \cdot 2\right)\\ \mathbf{elif}\;\phi_1 \leq 1.9 \cdot 10^{-104}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\phi_2 \cdot -0.5\right)}{\sqrt{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(R \cdot 2\right) \cdot \tan^{-1}_* \frac{0.5 \cdot \left(\phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\right)}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}}\\ \end{array} \]

Alternative 29: 12.7% accurate, 1.5× 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 \left(0.5 \cdot \phi_1\right)\\ \mathbf{if}\;\phi_2 \leq -7.3 \cdot 10^{-116}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_2 \cdot \left(\phi_2 \cdot -0.5\right)}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\ \mathbf{elif}\;\phi_2 \leq 6.8 \cdot 10^{-25}:\\ \;\;\;\;\left(R \cdot 2\right) \cdot \tan^{-1}_* \frac{-0.5 \cdot \left(\phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\right)}{\sqrt{1 - \mathsf{fma}\left(t_1, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\lambda_2 \cdot -0.5\right)\right), t_0\right)}}\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\left(0.5 \cdot \phi_2\right) \cdot t_2}{\sqrt{1 - \left(t_0 + \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_1\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\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 (* 0.5 phi1))))
   (if (<= phi2 -7.3e-116)
     (*
      R
      (*
       2.0
       (atan2
        (* t_2 (* phi2 -0.5))
        (sqrt (- 1.0 (pow (sin (* 0.5 (- phi1 phi2))) 2.0))))))
     (if (<= phi2 6.8e-25)
       (*
        (* R 2.0)
        (atan2
         (* -0.5 (* phi1 (cos (* phi2 -0.5))))
         (sqrt
          (-
           1.0
           (fma
            t_1
            (* (cos phi1) (* (cos phi2) (sin (* lambda2 -0.5))))
            t_0)))))
       (*
        R
        (*
         2.0
         (atan2
          (* (* 0.5 phi2) t_2)
          (sqrt
           (-
            1.0
            (+
             t_0
             (*
              (* (* (cos phi2) (cos phi1)) t_1)
              (sin (* 0.5 lambda1)))))))))))))
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((0.5 * phi1));
	double tmp;
	if (phi2 <= -7.3e-116) {
		tmp = R * (2.0 * atan2((t_2 * (phi2 * -0.5)), sqrt((1.0 - pow(sin((0.5 * (phi1 - phi2))), 2.0)))));
	} else if (phi2 <= 6.8e-25) {
		tmp = (R * 2.0) * atan2((-0.5 * (phi1 * cos((phi2 * -0.5)))), sqrt((1.0 - fma(t_1, (cos(phi1) * (cos(phi2) * sin((lambda2 * -0.5)))), t_0))));
	} else {
		tmp = R * (2.0 * atan2(((0.5 * phi2) * t_2), sqrt((1.0 - (t_0 + (((cos(phi2) * cos(phi1)) * t_1) * sin((0.5 * lambda1))))))));
	}
	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 = cos(Float64(0.5 * phi1))
	tmp = 0.0
	if (phi2 <= -7.3e-116)
		tmp = Float64(R * Float64(2.0 * atan(Float64(t_2 * Float64(phi2 * -0.5)), sqrt(Float64(1.0 - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0))))));
	elseif (phi2 <= 6.8e-25)
		tmp = Float64(Float64(R * 2.0) * atan(Float64(-0.5 * Float64(phi1 * cos(Float64(phi2 * -0.5)))), sqrt(Float64(1.0 - fma(t_1, Float64(cos(phi1) * Float64(cos(phi2) * sin(Float64(lambda2 * -0.5)))), t_0)))));
	else
		tmp = Float64(R * Float64(2.0 * atan(Float64(Float64(0.5 * phi2) * t_2), sqrt(Float64(1.0 - Float64(t_0 + Float64(Float64(Float64(cos(phi2) * cos(phi1)) * t_1) * sin(Float64(0.5 * lambda1)))))))));
	end
	return 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[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -7.3e-116], N[(R * N[(2.0 * N[ArcTan[N[(t$95$2 * N[(phi2 * -0.5), $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], If[LessEqual[phi2, 6.8e-25], N[(N[(R * 2.0), $MachinePrecision] * N[ArcTan[N[(-0.5 * N[(phi1 * N[Cos[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(t$95$1 * N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Sin[N[(lambda2 * -0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[(N[(0.5 * phi2), $MachinePrecision] * t$95$2), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(t$95$0 + N[(N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision] * N[Sin[N[(0.5 * lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 \left(0.5 \cdot \phi_1\right)\\
\mathbf{if}\;\phi_2 \leq -7.3 \cdot 10^{-116}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_2 \cdot \left(\phi_2 \cdot -0.5\right)}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\

\mathbf{elif}\;\phi_2 \leq 6.8 \cdot 10^{-25}:\\
\;\;\;\;\left(R \cdot 2\right) \cdot \tan^{-1}_* \frac{-0.5 \cdot \left(\phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\right)}{\sqrt{1 - \mathsf{fma}\left(t_1, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\lambda_2 \cdot -0.5\right)\right), t_0\right)}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < -7.3000000000000006e-116

    1. Initial program 56.1%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Taylor expanded in lambda2 around 0 45.9%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \color{blue}{\sin \left(0.5 \cdot \lambda_1\right)}\right)}}\right) \]
    3. Taylor expanded in phi2 around 0 34.5%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\left(\sin \left(0.5 \cdot \phi_1\right) + -0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    4. Taylor expanded in phi2 around -inf 17.2%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{-0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    5. Step-by-step derivation
      1. associate-*r*17.2%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(-0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
      2. *-commutative17.2%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot -0.5\right)} \cdot \cos \left(0.5 \cdot \phi_1\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    6. Simplified17.2%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot -0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    7. Taylor expanded in lambda1 around 0 17.4%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\left(\phi_2 \cdot -0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}{\sqrt{\color{blue}{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}}\right) \]

    if -7.3000000000000006e-116 < phi2 < 6.80000000000000003e-25

    1. Initial program 77.1%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified77.1%

      \[\leadsto \color{blue}{\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right)} \]
    3. Taylor expanded in phi1 around 0 49.4%

      \[\leadsto \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\color{blue}{\left(\sin \left(-0.5 \cdot \phi_2\right) + 0.5 \cdot \left(\phi_1 \cdot \cos \left(-0.5 \cdot \phi_2\right)\right)\right)}}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right) \]
    4. Taylor expanded in phi1 around -inf 11.9%

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{-0.5 \cdot \left(\phi_1 \cdot \cos \left(-0.5 \cdot \phi_2\right)\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right) \]
    5. Step-by-step derivation
      1. *-commutative11.9%

        \[\leadsto \tan^{-1}_* \frac{-0.5 \cdot \left(\phi_1 \cdot \cos \color{blue}{\left(\phi_2 \cdot -0.5\right)}\right)}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right) \]
    6. Simplified11.9%

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{-0.5 \cdot \left(\phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right) \]
    7. Taylor expanded in lambda1 around 0 11.7%

      \[\leadsto \tan^{-1}_* \frac{-0.5 \cdot \left(\phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\right)}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \color{blue}{\sin \left(-0.5 \cdot \lambda_2\right)}\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right) \]

    if 6.80000000000000003e-25 < phi2

    1. Initial program 49.4%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Taylor expanded in lambda2 around 0 41.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \color{blue}{\sin \left(0.5 \cdot \lambda_1\right)}\right)}}\right) \]
    3. Taylor expanded in phi2 around 0 22.7%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\left(\sin \left(0.5 \cdot \phi_1\right) + -0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    4. Taylor expanded in phi2 around inf 15.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    5. Step-by-step derivation
      1. associate-*r*15.6%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
      2. *-commutative15.6%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot 0.5\right)} \cdot \cos \left(0.5 \cdot \phi_1\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    6. Simplified15.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification14.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -7.3 \cdot 10^{-116}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\phi_2 \cdot -0.5\right)}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\ \mathbf{elif}\;\phi_2 \leq 6.8 \cdot 10^{-25}:\\ \;\;\;\;\left(R \cdot 2\right) \cdot \tan^{-1}_* \frac{-0.5 \cdot \left(\phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\right)}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\lambda_2 \cdot -0.5\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}}\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right)\\ \end{array} \]

Alternative 30: 12.7% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := \cos \left(0.5 \cdot \phi_1\right)\\ \mathbf{if}\;\phi_2 \leq -5.3 \cdot 10^{-115}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1 \cdot \left(\phi_2 \cdot -0.5\right)}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\ \mathbf{elif}\;\phi_2 \leq 1.3 \cdot 10^{-24}:\\ \;\;\;\;\tan^{-1}_* \frac{-0.5 \cdot \left(\phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\right)}{\sqrt{1 - \mathsf{fma}\left(t_0, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot t_0\right), {\sin \left(\phi_2 \cdot -0.5\right)}^{2}\right)}} \cdot \left(R \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\left(0.5 \cdot \phi_2\right) \cdot t_1}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_0\right) \cdot \sin \left(0.5 \cdot \lambda_1\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 (* 0.5 phi1))))
   (if (<= phi2 -5.3e-115)
     (*
      R
      (*
       2.0
       (atan2
        (* t_1 (* phi2 -0.5))
        (sqrt (- 1.0 (pow (sin (* 0.5 (- phi1 phi2))) 2.0))))))
     (if (<= phi2 1.3e-24)
       (*
        (atan2
         (* -0.5 (* phi1 (cos (* phi2 -0.5))))
         (sqrt
          (-
           1.0
           (fma
            t_0
            (* (cos phi1) (* (cos phi2) t_0))
            (pow (sin (* phi2 -0.5)) 2.0)))))
        (* R 2.0))
       (*
        R
        (*
         2.0
         (atan2
          (* (* 0.5 phi2) t_1)
          (sqrt
           (-
            1.0
            (+
             (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
             (*
              (* (* (cos phi2) (cos phi1)) t_0)
              (sin (* 0.5 lambda1)))))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) / 2.0));
	double t_1 = cos((0.5 * phi1));
	double tmp;
	if (phi2 <= -5.3e-115) {
		tmp = R * (2.0 * atan2((t_1 * (phi2 * -0.5)), sqrt((1.0 - pow(sin((0.5 * (phi1 - phi2))), 2.0)))));
	} else if (phi2 <= 1.3e-24) {
		tmp = atan2((-0.5 * (phi1 * cos((phi2 * -0.5)))), sqrt((1.0 - fma(t_0, (cos(phi1) * (cos(phi2) * t_0)), pow(sin((phi2 * -0.5)), 2.0))))) * (R * 2.0);
	} else {
		tmp = R * (2.0 * atan2(((0.5 * phi2) * t_1), sqrt((1.0 - (pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (((cos(phi2) * cos(phi1)) * t_0) * sin((0.5 * lambda1))))))));
	}
	return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = cos(Float64(0.5 * phi1))
	tmp = 0.0
	if (phi2 <= -5.3e-115)
		tmp = Float64(R * Float64(2.0 * atan(Float64(t_1 * Float64(phi2 * -0.5)), sqrt(Float64(1.0 - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0))))));
	elseif (phi2 <= 1.3e-24)
		tmp = Float64(atan(Float64(-0.5 * Float64(phi1 * cos(Float64(phi2 * -0.5)))), sqrt(Float64(1.0 - fma(t_0, Float64(cos(phi1) * Float64(cos(phi2) * t_0)), (sin(Float64(phi2 * -0.5)) ^ 2.0))))) * Float64(R * 2.0));
	else
		tmp = Float64(R * Float64(2.0 * atan(Float64(Float64(0.5 * phi2) * t_1), sqrt(Float64(1.0 - Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(Float64(cos(phi2) * cos(phi1)) * t_0) * sin(Float64(0.5 * lambda1)))))))));
	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[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -5.3e-115], N[(R * N[(2.0 * N[ArcTan[N[(t$95$1 * N[(phi2 * -0.5), $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], If[LessEqual[phi2, 1.3e-24], N[(N[ArcTan[N[(-0.5 * N[(phi1 * N[Cos[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(t$95$0 * N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(R * 2.0), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[(N[(0.5 * phi2), $MachinePrecision] * t$95$1), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Sin[N[(0.5 * lambda1), $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 := \cos \left(0.5 \cdot \phi_1\right)\\
\mathbf{if}\;\phi_2 \leq -5.3 \cdot 10^{-115}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1 \cdot \left(\phi_2 \cdot -0.5\right)}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\

\mathbf{elif}\;\phi_2 \leq 1.3 \cdot 10^{-24}:\\
\;\;\;\;\tan^{-1}_* \frac{-0.5 \cdot \left(\phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\right)}{\sqrt{1 - \mathsf{fma}\left(t_0, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot t_0\right), {\sin \left(\phi_2 \cdot -0.5\right)}^{2}\right)}} \cdot \left(R \cdot 2\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < -5.3e-115

    1. Initial program 56.1%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Taylor expanded in lambda2 around 0 45.9%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \color{blue}{\sin \left(0.5 \cdot \lambda_1\right)}\right)}}\right) \]
    3. Taylor expanded in phi2 around 0 34.5%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\left(\sin \left(0.5 \cdot \phi_1\right) + -0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    4. Taylor expanded in phi2 around -inf 17.2%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{-0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    5. Step-by-step derivation
      1. associate-*r*17.2%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(-0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
      2. *-commutative17.2%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot -0.5\right)} \cdot \cos \left(0.5 \cdot \phi_1\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    6. Simplified17.2%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot -0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    7. Taylor expanded in lambda1 around 0 17.4%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\left(\phi_2 \cdot -0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}{\sqrt{\color{blue}{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}}\right) \]

    if -5.3e-115 < phi2 < 1.3e-24

    1. Initial program 77.1%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Simplified77.1%

      \[\leadsto \color{blue}{\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right)} \]
    3. Taylor expanded in phi1 around 0 49.4%

      \[\leadsto \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\color{blue}{\left(\sin \left(-0.5 \cdot \phi_2\right) + 0.5 \cdot \left(\phi_1 \cdot \cos \left(-0.5 \cdot \phi_2\right)\right)\right)}}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right) \]
    4. Taylor expanded in phi1 around -inf 11.9%

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{-0.5 \cdot \left(\phi_1 \cdot \cos \left(-0.5 \cdot \phi_2\right)\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right) \]
    5. Step-by-step derivation
      1. *-commutative11.9%

        \[\leadsto \tan^{-1}_* \frac{-0.5 \cdot \left(\phi_1 \cdot \cos \color{blue}{\left(\phi_2 \cdot -0.5\right)}\right)}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right) \]
    6. Simplified11.9%

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{-0.5 \cdot \left(\phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}} \cdot \left(R \cdot 2\right) \]
    7. Taylor expanded in phi1 around 0 11.9%

      \[\leadsto \tan^{-1}_* \frac{-0.5 \cdot \left(\phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\right)}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), \color{blue}{{\sin \left(-0.5 \cdot \phi_2\right)}^{2}}\right)}} \cdot \left(R \cdot 2\right) \]
    8. Step-by-step derivation
      1. *-commutative11.9%

        \[\leadsto \tan^{-1}_* \frac{-0.5 \cdot \left(\phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\right)}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \color{blue}{\left(\phi_2 \cdot -0.5\right)}}^{2}\right)}} \cdot \left(R \cdot 2\right) \]
    9. Simplified11.9%

      \[\leadsto \tan^{-1}_* \frac{-0.5 \cdot \left(\phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\right)}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), \color{blue}{{\sin \left(\phi_2 \cdot -0.5\right)}^{2}}\right)}} \cdot \left(R \cdot 2\right) \]

    if 1.3e-24 < phi2

    1. Initial program 49.4%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Taylor expanded in lambda2 around 0 41.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \color{blue}{\sin \left(0.5 \cdot \lambda_1\right)}\right)}}\right) \]
    3. Taylor expanded in phi2 around 0 22.7%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\left(\sin \left(0.5 \cdot \phi_1\right) + -0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    4. Taylor expanded in phi2 around inf 15.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    5. Step-by-step derivation
      1. associate-*r*15.6%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
      2. *-commutative15.6%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot 0.5\right)} \cdot \cos \left(0.5 \cdot \phi_1\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    6. Simplified15.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification14.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -5.3 \cdot 10^{-115}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\phi_2 \cdot -0.5\right)}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\ \mathbf{elif}\;\phi_2 \leq 1.3 \cdot 10^{-24}:\\ \;\;\;\;\tan^{-1}_* \frac{-0.5 \cdot \left(\phi_1 \cdot \cos \left(\phi_2 \cdot -0.5\right)\right)}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\sin \left(\phi_2 \cdot -0.5\right)}^{2}\right)}} \cdot \left(R \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right)\\ \end{array} \]

Alternative 31: 11.7% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(0.5 \cdot \phi_1\right)\\
\mathbf{if}\;\phi_2 \leq 9.2 \cdot 10^{-302}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_0 \cdot \left(\phi_2 \cdot -0.5\right)}{\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{\left(0.5 \cdot \phi_2\right) \cdot t_0}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < 9.20000000000000007e-302

    1. Initial program 62.2%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Taylor expanded in lambda2 around 0 48.8%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \color{blue}{\sin \left(0.5 \cdot \lambda_1\right)}\right)}}\right) \]
    3. Taylor expanded in phi2 around 0 41.0%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\left(\sin \left(0.5 \cdot \phi_1\right) + -0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    4. Taylor expanded in phi2 around -inf 14.8%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{-0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    5. Step-by-step derivation
      1. associate-*r*14.8%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(-0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
      2. *-commutative14.8%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot -0.5\right)} \cdot \cos \left(0.5 \cdot \phi_1\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    6. Simplified14.8%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot -0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    7. Taylor expanded in lambda1 around 0 15.0%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\left(\phi_2 \cdot -0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}{\sqrt{\color{blue}{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}}\right) \]

    if 9.20000000000000007e-302 < phi2

    1. Initial program 62.5%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Taylor expanded in lambda2 around 0 48.3%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \color{blue}{\sin \left(0.5 \cdot \lambda_1\right)}\right)}}\right) \]
    3. Taylor expanded in phi2 around 0 37.9%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\left(\sin \left(0.5 \cdot \phi_1\right) + -0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    4. Taylor expanded in phi2 around inf 10.5%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    5. Step-by-step derivation
      1. associate-*r*10.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
      2. *-commutative10.5%

        \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot 0.5\right)} \cdot \cos \left(0.5 \cdot \phi_1\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    6. Simplified10.5%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification12.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 9.2 \cdot 10^{-302}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\phi_2 \cdot -0.5\right)}{\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{\left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right)\\ \end{array} \]

Alternative 32: 8.6% accurate, 3.0× speedup?

\[\begin{array}{l} \\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\phi_2 \cdot -0.5\right)}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right) \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R
  (*
   2.0
   (atan2
    (* (cos (* 0.5 phi1)) (* phi2 -0.5))
    (sqrt (- 1.0 (pow (sin (* 0.5 (- phi1 phi2))) 2.0)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * (2.0 * atan2((cos((0.5 * phi1)) * (phi2 * -0.5)), sqrt((1.0 - pow(sin((0.5 * (phi1 - phi2))), 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((cos((0.5d0 * phi1)) * (phi2 * (-0.5d0))), sqrt((1.0d0 - (sin((0.5d0 * (phi1 - phi2))) ** 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.cos((0.5 * phi1)) * (phi2 * -0.5)), Math.sqrt((1.0 - Math.pow(Math.sin((0.5 * (phi1 - phi2))), 2.0)))));
}
def code(R, lambda1, lambda2, phi1, phi2):
	return R * (2.0 * math.atan2((math.cos((0.5 * phi1)) * (phi2 * -0.5)), math.sqrt((1.0 - math.pow(math.sin((0.5 * (phi1 - phi2))), 2.0)))))
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(R * Float64(2.0 * atan(Float64(cos(Float64(0.5 * phi1)) * Float64(phi2 * -0.5)), sqrt(Float64(1.0 - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0))))))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = R * (2.0 * atan2((cos((0.5 * phi1)) * (phi2 * -0.5)), sqrt((1.0 - (sin((0.5 * (phi1 - phi2))) ^ 2.0)))));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[(2.0 * N[ArcTan[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(phi2 * -0.5), $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}

\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\phi_2 \cdot -0.5\right)}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)
\end{array}
Derivation
  1. Initial program 62.3%

    \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  2. Taylor expanded in lambda2 around 0 48.6%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \color{blue}{\sin \left(0.5 \cdot \lambda_1\right)}\right)}}\right) \]
  3. Taylor expanded in phi2 around 0 39.5%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\left(\sin \left(0.5 \cdot \phi_1\right) + -0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
  4. Taylor expanded in phi2 around -inf 9.6%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{-0.5 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
  5. Step-by-step derivation
    1. associate-*r*9.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(-0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
    2. *-commutative9.6%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot -0.5\right)} \cdot \cos \left(0.5 \cdot \phi_1\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
  6. Simplified9.6%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\color{blue}{\left(\phi_2 \cdot -0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)\right)}}\right) \]
  7. Taylor expanded in lambda1 around 0 9.9%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\left(\phi_2 \cdot -0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}{\sqrt{\color{blue}{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}}\right) \]
  8. Final simplification9.9%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\phi_2 \cdot -0.5\right)}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right) \]

Reproduce

?
herbie shell --seed 2023293 
(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))))))))))