Distance on a great circle

Percentage Accurate: 62.3% → 62.5%
Time: 1.7min
Alternatives: 15
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 15 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.3% 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: 62.5% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := t_0 \cdot \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_0\right)\\ t_2 := {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}\\ \mathbf{if}\;\phi_1 \leq -0.000118 \lor \neg \left(\phi_1 \leq 130000\right):\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\phi_1 \cdot 0.5\right)}^{2} + t_1}}{\sqrt{{\cos \left(\phi_1 \cdot 0.5\right)}^{2} - \cos \phi_1 \cdot t_2}}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1}}{\sqrt{{\cos \left(\phi_2 \cdot 0.5\right)}^{2} - \cos \phi_2 \cdot 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 phi1) (cos phi2)) t_0)))
        (t_2 (pow (sin (* -0.5 (- lambda2 lambda1))) 2.0)))
   (if (or (<= phi1 -0.000118) (not (<= phi1 130000.0)))
     (*
      R
      (*
       2.0
       (atan2
        (sqrt (+ (pow (sin (* phi1 0.5)) 2.0) t_1))
        (sqrt (- (pow (cos (* phi1 0.5)) 2.0) (* (cos phi1) t_2))))))
     (*
      R
      (*
       2.0
       (atan2
        (sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) t_1))
        (sqrt (- (pow (cos (* phi2 0.5)) 2.0) (* (cos phi2) 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(phi1) * cos(phi2)) * t_0);
	double t_2 = pow(sin((-0.5 * (lambda2 - lambda1))), 2.0);
	double tmp;
	if ((phi1 <= -0.000118) || !(phi1 <= 130000.0)) {
		tmp = R * (2.0 * atan2(sqrt((pow(sin((phi1 * 0.5)), 2.0) + t_1)), sqrt((pow(cos((phi1 * 0.5)), 2.0) - (cos(phi1) * t_2)))));
	} else {
		tmp = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)), sqrt((pow(cos((phi2 * 0.5)), 2.0) - (cos(phi2) * 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(phi1) * cos(phi2)) * t_0)
    t_2 = sin(((-0.5d0) * (lambda2 - lambda1))) ** 2.0d0
    if ((phi1 <= (-0.000118d0)) .or. (.not. (phi1 <= 130000.0d0))) then
        tmp = r * (2.0d0 * atan2(sqrt(((sin((phi1 * 0.5d0)) ** 2.0d0) + t_1)), sqrt(((cos((phi1 * 0.5d0)) ** 2.0d0) - (cos(phi1) * t_2)))))
    else
        tmp = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + t_1)), sqrt(((cos((phi2 * 0.5d0)) ** 2.0d0) - (cos(phi2) * 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(phi1) * Math.cos(phi2)) * t_0);
	double t_2 = Math.pow(Math.sin((-0.5 * (lambda2 - lambda1))), 2.0);
	double tmp;
	if ((phi1 <= -0.000118) || !(phi1 <= 130000.0)) {
		tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin((phi1 * 0.5)), 2.0) + t_1)), Math.sqrt((Math.pow(Math.cos((phi1 * 0.5)), 2.0) - (Math.cos(phi1) * t_2)))));
	} else {
		tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)), Math.sqrt((Math.pow(Math.cos((phi2 * 0.5)), 2.0) - (Math.cos(phi2) * 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(phi1) * math.cos(phi2)) * t_0)
	t_2 = math.pow(math.sin((-0.5 * (lambda2 - lambda1))), 2.0)
	tmp = 0
	if (phi1 <= -0.000118) or not (phi1 <= 130000.0):
		tmp = R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin((phi1 * 0.5)), 2.0) + t_1)), math.sqrt((math.pow(math.cos((phi1 * 0.5)), 2.0) - (math.cos(phi1) * t_2)))))
	else:
		tmp = R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)), math.sqrt((math.pow(math.cos((phi2 * 0.5)), 2.0) - (math.cos(phi2) * 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(phi1) * cos(phi2)) * t_0))
	t_2 = sin(Float64(-0.5 * Float64(lambda2 - lambda1))) ^ 2.0
	tmp = 0.0
	if ((phi1 <= -0.000118) || !(phi1 <= 130000.0))
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(phi1 * 0.5)) ^ 2.0) + t_1)), sqrt(Float64((cos(Float64(phi1 * 0.5)) ^ 2.0) - Float64(cos(phi1) * t_2))))));
	else
		tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + t_1)), sqrt(Float64((cos(Float64(phi2 * 0.5)) ^ 2.0) - Float64(cos(phi2) * 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(phi1) * cos(phi2)) * t_0);
	t_2 = sin((-0.5 * (lambda2 - lambda1))) ^ 2.0;
	tmp = 0.0;
	if ((phi1 <= -0.000118) || ~((phi1 <= 130000.0)))
		tmp = R * (2.0 * atan2(sqrt(((sin((phi1 * 0.5)) ^ 2.0) + t_1)), sqrt(((cos((phi1 * 0.5)) ^ 2.0) - (cos(phi1) * t_2)))));
	else
		tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + t_1)), sqrt(((cos((phi2 * 0.5)) ^ 2.0) - (cos(phi2) * 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[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[N[(-0.5 * N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, If[Or[LessEqual[phi1, -0.000118], N[Not[LessEqual[phi1, 130000.0]], $MachinePrecision]], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + t$95$1), $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$2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(N[Cos[phi2], $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 := t_0 \cdot \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_0\right)\\
t_2 := {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}\\
\mathbf{if}\;\phi_1 \leq -0.000118 \lor \neg \left(\phi_1 \leq 130000\right):\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\phi_1 \cdot 0.5\right)}^{2} + t_1}}{\sqrt{{\cos \left(\phi_1 \cdot 0.5\right)}^{2} - \cos \phi_1 \cdot t_2}}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi1 < -1.18e-4 or 1.3e5 < phi1

    1. Initial program 45.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 phi2 around 0 46.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{\color{blue}{1 - \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} + \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right)}}}\right) \]
    3. Step-by-step derivation
      1. associate--r+46.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{\color{blue}{\left(1 - {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right) - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}}\right) \]
      2. unpow246.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{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      3. 1-sub-sin46.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{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      4. unpow246.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{\color{blue}{{\cos \left(0.5 \cdot \phi_1\right)}^{2}} - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      5. *-commutative46.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}^{2}}}\right) \]
      6. unpow246.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot \color{blue}{\left(\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right)}}}\right) \]
      7. associate-*r*46.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \color{blue}{\left(\cos \phi_1 \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}}\right) \]
    4. Simplified46.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{\color{blue}{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}}\right) \]
    5. Taylor expanded in phi2 around 0 47.4%

      \[\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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}\right) \]

    if -1.18e-4 < phi1 < 1.3e5

    1. Initial program 74.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 phi1 around 0 74.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{\color{blue}{1 - \left({\sin \left(-0.5 \cdot \phi_2\right)}^{2} + \cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right)}}}\right) \]
    3. Step-by-step derivation
      1. associate--r+74.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{\color{blue}{\left(1 - {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right) - \cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}}\right) \]
      2. unpow274.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{\left(1 - \color{blue}{\sin \left(-0.5 \cdot \phi_2\right) \cdot \sin \left(-0.5 \cdot \phi_2\right)}\right) - \cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      3. 1-sub-sin74.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{\color{blue}{\cos \left(-0.5 \cdot \phi_2\right) \cdot \cos \left(-0.5 \cdot \phi_2\right)} - \cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      4. unpow274.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{\color{blue}{{\cos \left(-0.5 \cdot \phi_2\right)}^{2}} - \cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      5. metadata-eval74.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{{\cos \left(\color{blue}{\left(0.5 \cdot -1\right)} \cdot \phi_2\right)}^{2} - \cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      6. associate-*r*74.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{{\cos \color{blue}{\left(0.5 \cdot \left(-1 \cdot \phi_2\right)\right)}}^{2} - \cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      7. *-commutative74.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{{\cos \color{blue}{\left(\left(-1 \cdot \phi_2\right) \cdot 0.5\right)}}^{2} - \cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      8. mul-1-neg74.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{{\cos \left(\color{blue}{\left(-\phi_2\right)} \cdot 0.5\right)}^{2} - \cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      9. distribute-lft-neg-out74.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{{\cos \color{blue}{\left(-\phi_2 \cdot 0.5\right)}}^{2} - \cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      10. cos-neg74.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{{\color{blue}{\cos \left(\phi_2 \cdot 0.5\right)}}^{2} - \cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      11. sub-neg74.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{{\cos \left(\phi_2 \cdot 0.5\right)}^{2} - \cos \phi_2 \cdot {\sin \left(0.5 \cdot \color{blue}{\left(\lambda_1 + \left(-\lambda_2\right)\right)}\right)}^{2}}}\right) \]
      12. mul-1-neg74.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{{\cos \left(\phi_2 \cdot 0.5\right)}^{2} - \cos \phi_2 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 + \color{blue}{-1 \cdot \lambda_2}\right)\right)}^{2}}}\right) \]
      13. +-commutative74.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{{\cos \left(\phi_2 \cdot 0.5\right)}^{2} - \cos \phi_2 \cdot {\sin \left(0.5 \cdot \color{blue}{\left(-1 \cdot \lambda_2 + \lambda_1\right)}\right)}^{2}}}\right) \]
    4. Simplified74.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{\color{blue}{{\cos \left(\phi_2 \cdot 0.5\right)}^{2} - \cos \phi_2 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification61.6%

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

Alternative 2: 62.4% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \phi_1 \cdot \cos \phi_2\\
t_1 := \cos \left(2 \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right)\\
t_2 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_3 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
t_4 := 0.5 \cdot t_1\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_3 + t_0 \cdot \left(t_2 \cdot t_2\right)}}{\sqrt{\left(1 - t_3\right) - t_0 \cdot \frac{0.125 - 0.125 \cdot {t_1}^{3}}{0.25 + t_4 \cdot \left(0.5 + t_4\right)}}}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 60.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. Step-by-step derivation
    1. associate-*l*60.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 62.4% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := \cos \phi_1 \cdot \cos \phi_2\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1 \cdot \left(t_0 \cdot t_0\right) + \mathsf{log1p}\left(\mathsf{expm1}\left({\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)\right)}}{\sqrt{\left(1 - {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right) - t_1 \cdot \left(0.5 - 0.5 \cdot \cos \left(2 \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\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 (* (cos phi1) (cos phi2))))
   (*
    R
    (*
     2.0
     (atan2
      (sqrt
       (+
        (* t_1 (* t_0 t_0))
        (log1p (expm1 (pow (sin (* (- phi1 phi2) 0.5)) 2.0)))))
      (sqrt
       (-
        (- 1.0 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0))
        (*
         t_1
         (- 0.5 (* 0.5 (cos (* 2.0 (* (- lambda1 lambda2) 0.5)))))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) / 2.0));
	double t_1 = cos(phi1) * cos(phi2);
	return R * (2.0 * atan2(sqrt(((t_1 * (t_0 * t_0)) + log1p(expm1(pow(sin(((phi1 - phi2) * 0.5)), 2.0))))), sqrt(((1.0 - pow(sin(((phi1 - phi2) / 2.0)), 2.0)) - (t_1 * (0.5 - (0.5 * cos((2.0 * ((lambda1 - lambda2) * 0.5))))))))));
}
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(phi1) * Math.cos(phi2);
	return R * (2.0 * Math.atan2(Math.sqrt(((t_1 * (t_0 * t_0)) + Math.log1p(Math.expm1(Math.pow(Math.sin(((phi1 - phi2) * 0.5)), 2.0))))), Math.sqrt(((1.0 - Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0)) - (t_1 * (0.5 - (0.5 * Math.cos((2.0 * ((lambda1 - lambda2) * 0.5))))))))));
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(((lambda1 - lambda2) / 2.0))
	t_1 = math.cos(phi1) * math.cos(phi2)
	return R * (2.0 * math.atan2(math.sqrt(((t_1 * (t_0 * t_0)) + math.log1p(math.expm1(math.pow(math.sin(((phi1 - phi2) * 0.5)), 2.0))))), math.sqrt(((1.0 - math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0)) - (t_1 * (0.5 - (0.5 * math.cos((2.0 * ((lambda1 - lambda2) * 0.5))))))))))
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = Float64(cos(phi1) * cos(phi2))
	return Float64(R * Float64(2.0 * atan(sqrt(Float64(Float64(t_1 * Float64(t_0 * t_0)) + log1p(expm1((sin(Float64(Float64(phi1 - phi2) * 0.5)) ^ 2.0))))), sqrt(Float64(Float64(1.0 - (sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0)) - Float64(t_1 * Float64(0.5 - Float64(0.5 * cos(Float64(2.0 * Float64(Float64(lambda1 - lambda2) * 0.5)))))))))))
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[(t$95$1 * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision] + N[Log[1 + N[(Exp[N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(1.0 - N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] - N[(t$95$1 * N[(0.5 - N[(0.5 * N[Cos[N[(2.0 * N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]], $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 \phi_1 \cdot \cos \phi_2\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1 \cdot \left(t_0 \cdot t_0\right) + \mathsf{log1p}\left(\mathsf{expm1}\left({\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)\right)}}{\sqrt{\left(1 - {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right) - t_1 \cdot \left(0.5 - 0.5 \cdot \cos \left(2 \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right)\right)}}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 60.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. Step-by-step derivation
    1. associate-*l*60.7%

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 62.4% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \phi_1 \cdot \cos \phi_2\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_2 + t_0 \cdot \left(t_1 \cdot t_1\right)}}{\sqrt{\left(1 - t_2\right) - t_0 \cdot \left(0.5 - 0.5 \cdot \cos \left(2 \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right)\right)}}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 60.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. Step-by-step derivation
    1. associate-*l*60.7%

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

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

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

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

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

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

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

Alternative 5: 55.2% accurate, 1.1× speedup?

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

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


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

    1. Initial program 65.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. associate-*l*65.9%

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

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

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

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

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

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

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

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

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

    if 2.9e-5 < lambda2

    1. Initial program 47.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. associate-*l*47.2%

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

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

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

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

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

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

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

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

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

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

Alternative 6: 57.9% accurate, 1.1× speedup?

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

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

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

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


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

    1. Initial program 38.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 lambda1 around 0 31.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{\color{blue}{1 - \left({\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2} + {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right)\right)}}}\right) \]
    3. Step-by-step derivation
      1. +-commutative31.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 - \color{blue}{\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}}\right) \]
      2. *-commutative31.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(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + {\sin \color{blue}{\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}}^{2}\right)}}\right) \]
      3. fma-def31.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 - \color{blue}{\mathsf{fma}\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, \cos \phi_2 \cdot \cos \phi_1, {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)}}}\right) \]
    4. Simplified31.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{\color{blue}{1 - \mathsf{fma}\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, \cos \phi_2 \cdot \cos \phi_1, {\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}^{2}\right)}}}\right) \]
    5. Taylor expanded in phi1 around 0 32.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{\color{blue}{1 - \left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2 + {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)}}}\right) \]

    if -2.05000000000000016e-8 < phi2 < 2.4499999999999999e-4

    1. Initial program 78.0%

      \[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 phi2 around 0 78.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{\color{blue}{1 - \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} + \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right)}}}\right) \]
    3. Step-by-step derivation
      1. associate--r+78.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{\color{blue}{\left(1 - {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right) - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}}\right) \]
      2. unpow278.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{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      3. 1-sub-sin78.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{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      4. unpow278.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{\color{blue}{{\cos \left(0.5 \cdot \phi_1\right)}^{2}} - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      5. *-commutative78.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}^{2}}}\right) \]
      6. unpow278.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot \color{blue}{\left(\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right)}}}\right) \]
      7. associate-*r*78.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \color{blue}{\left(\cos \phi_1 \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}}\right) \]
    4. Simplified78.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{\color{blue}{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}}\right) \]

    if 2.4499999999999999e-4 < phi2

    1. Initial program 49.0%

      \[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 lambda1 around 0 36.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{\color{blue}{1 - \left({\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2} + {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right)\right)}}}\right) \]
    3. Step-by-step derivation
      1. +-commutative36.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 - \color{blue}{\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}}\right) \]
      2. *-commutative36.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(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + {\sin \color{blue}{\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}}^{2}\right)}}\right) \]
      3. fma-def36.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 - \color{blue}{\mathsf{fma}\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, \cos \phi_2 \cdot \cos \phi_1, {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)}}}\right) \]
    4. Simplified36.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{\color{blue}{1 - \mathsf{fma}\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, \cos \phi_2 \cdot \cos \phi_1, {\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}^{2}\right)}}}\right) \]
    5. Taylor expanded in phi1 around 0 36.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{\color{blue}{1 - \left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2 + {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)}}}\right) \]
    6. Step-by-step derivation
      1. +-commutative36.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 - \color{blue}{\left({\sin \left(-0.5 \cdot \phi_2\right)}^{2} + {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2\right)}}}\right) \]
      2. associate--r+36.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{\color{blue}{\left(1 - {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right) - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}}\right) \]
      3. unpow236.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{\left(1 - \color{blue}{\sin \left(-0.5 \cdot \phi_2\right) \cdot \sin \left(-0.5 \cdot \phi_2\right)}\right) - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      4. 1-sub-sin36.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{\color{blue}{\cos \left(-0.5 \cdot \phi_2\right) \cdot \cos \left(-0.5 \cdot \phi_2\right)} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      5. unpow236.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{\color{blue}{{\cos \left(-0.5 \cdot \phi_2\right)}^{2}} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      6. metadata-eval36.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{{\cos \left(\color{blue}{\left(0.5 \cdot -1\right)} \cdot \phi_2\right)}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      7. associate-*r*36.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{{\cos \color{blue}{\left(0.5 \cdot \left(-1 \cdot \phi_2\right)\right)}}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      8. *-commutative36.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{{\cos \color{blue}{\left(\left(-1 \cdot \phi_2\right) \cdot 0.5\right)}}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      9. mul-1-neg36.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{{\cos \left(\color{blue}{\left(-\phi_2\right)} \cdot 0.5\right)}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      10. distribute-lft-neg-out36.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{{\cos \color{blue}{\left(-\phi_2 \cdot 0.5\right)}}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      11. cos-neg36.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{{\color{blue}{\cos \left(\phi_2 \cdot 0.5\right)}}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
    7. Simplified36.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{\color{blue}{{\cos \left(\phi_2 \cdot 0.5\right)}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification56.0%

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

Alternative 7: 56.5% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < -5.39999999999999963e-26 or 0.00142000000000000004 < 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. Taylor expanded in lambda1 around 0 35.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{\color{blue}{1 - \left({\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2} + {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right)\right)}}}\right) \]
    3. Step-by-step derivation
      1. +-commutative35.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 - \color{blue}{\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}}\right) \]
      2. *-commutative35.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(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + {\sin \color{blue}{\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}}^{2}\right)}}\right) \]
      3. fma-def35.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 - \color{blue}{\mathsf{fma}\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, \cos \phi_2 \cdot \cos \phi_1, {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)}}}\right) \]
    4. Simplified35.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{\color{blue}{1 - \mathsf{fma}\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, \cos \phi_2 \cdot \cos \phi_1, {\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}^{2}\right)}}}\right) \]
    5. Taylor expanded in phi1 around 0 35.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{\color{blue}{1 - \left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2 + {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)}}}\right) \]
    6. Step-by-step derivation
      1. +-commutative35.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 - \color{blue}{\left({\sin \left(-0.5 \cdot \phi_2\right)}^{2} + {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2\right)}}}\right) \]
      2. associate--r+35.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{\color{blue}{\left(1 - {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right) - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}}\right) \]
      3. unpow235.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{\left(1 - \color{blue}{\sin \left(-0.5 \cdot \phi_2\right) \cdot \sin \left(-0.5 \cdot \phi_2\right)}\right) - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      4. 1-sub-sin36.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{\color{blue}{\cos \left(-0.5 \cdot \phi_2\right) \cdot \cos \left(-0.5 \cdot \phi_2\right)} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      5. unpow236.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{\color{blue}{{\cos \left(-0.5 \cdot \phi_2\right)}^{2}} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      6. metadata-eval36.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{{\cos \left(\color{blue}{\left(0.5 \cdot -1\right)} \cdot \phi_2\right)}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      7. associate-*r*36.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{{\cos \color{blue}{\left(0.5 \cdot \left(-1 \cdot \phi_2\right)\right)}}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      8. *-commutative36.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{{\cos \color{blue}{\left(\left(-1 \cdot \phi_2\right) \cdot 0.5\right)}}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      9. mul-1-neg36.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{{\cos \left(\color{blue}{\left(-\phi_2\right)} \cdot 0.5\right)}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      10. distribute-lft-neg-out36.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{{\cos \color{blue}{\left(-\phi_2 \cdot 0.5\right)}}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      11. cos-neg36.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{{\color{blue}{\cos \left(\phi_2 \cdot 0.5\right)}}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
    7. Simplified36.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{\color{blue}{{\cos \left(\phi_2 \cdot 0.5\right)}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}}\right) \]

    if -5.39999999999999963e-26 < phi2 < 0.00142000000000000004

    1. Initial program 77.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 phi2 around 0 77.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{\color{blue}{1 - \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} + \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right)}}}\right) \]
    3. Step-by-step derivation
      1. associate--r+77.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{\color{blue}{\left(1 - {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right) - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}}\right) \]
      2. unpow277.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{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      3. 1-sub-sin77.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{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      4. unpow277.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{\color{blue}{{\cos \left(0.5 \cdot \phi_1\right)}^{2}} - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      5. *-commutative77.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}^{2}}}\right) \]
      6. unpow277.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot \color{blue}{\left(\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right)}}}\right) \]
      7. associate-*r*77.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \color{blue}{\left(\cos \phi_1 \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}}\right) \]
    4. Simplified77.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{\color{blue}{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}}\right) \]
    5. Taylor expanded in phi2 around 0 76.4%

      \[\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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification55.4%

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

Alternative 8: 56.5% accurate, 1.1× speedup?

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

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

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

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


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

    1. Initial program 41.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 lambda1 around 0 34.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{\color{blue}{1 - \left({\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2} + {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right)\right)}}}\right) \]
    3. Step-by-step derivation
      1. +-commutative34.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 - \color{blue}{\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}}\right) \]
      2. *-commutative34.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(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + {\sin \color{blue}{\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}}^{2}\right)}}\right) \]
      3. fma-def34.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 - \color{blue}{\mathsf{fma}\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, \cos \phi_2 \cdot \cos \phi_1, {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)}}}\right) \]
    4. Simplified34.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{\color{blue}{1 - \mathsf{fma}\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, \cos \phi_2 \cdot \cos \phi_1, {\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}^{2}\right)}}}\right) \]
    5. Taylor expanded in phi1 around 0 35.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{\color{blue}{1 - \left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2 + {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)}}}\right) \]

    if -5.39999999999999963e-26 < phi2 < 1.85e-4

    1. Initial program 77.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 phi2 around 0 77.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{\color{blue}{1 - \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} + \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right)}}}\right) \]
    3. Step-by-step derivation
      1. associate--r+77.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{\color{blue}{\left(1 - {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right) - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}}\right) \]
      2. unpow277.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{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      3. 1-sub-sin77.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{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      4. unpow277.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{\color{blue}{{\cos \left(0.5 \cdot \phi_1\right)}^{2}} - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      5. *-commutative77.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}^{2}}}\right) \]
      6. unpow277.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot \color{blue}{\left(\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right)}}}\right) \]
      7. associate-*r*77.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \color{blue}{\left(\cos \phi_1 \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}}\right) \]
    4. Simplified77.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{\color{blue}{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}}\right) \]
    5. Taylor expanded in phi2 around 0 76.4%

      \[\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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}\right) \]

    if 1.85e-4 < phi2

    1. Initial program 49.0%

      \[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 lambda1 around 0 36.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{\color{blue}{1 - \left({\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2} + {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right)\right)}}}\right) \]
    3. Step-by-step derivation
      1. +-commutative36.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 - \color{blue}{\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}}\right) \]
      2. *-commutative36.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(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + {\sin \color{blue}{\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}}^{2}\right)}}\right) \]
      3. fma-def36.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 - \color{blue}{\mathsf{fma}\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, \cos \phi_2 \cdot \cos \phi_1, {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)}}}\right) \]
    4. Simplified36.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{\color{blue}{1 - \mathsf{fma}\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, \cos \phi_2 \cdot \cos \phi_1, {\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}^{2}\right)}}}\right) \]
    5. Taylor expanded in phi1 around 0 36.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{\color{blue}{1 - \left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2 + {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)}}}\right) \]
    6. Step-by-step derivation
      1. +-commutative36.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 - \color{blue}{\left({\sin \left(-0.5 \cdot \phi_2\right)}^{2} + {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2\right)}}}\right) \]
      2. associate--r+36.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{\color{blue}{\left(1 - {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right) - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}}\right) \]
      3. unpow236.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{\left(1 - \color{blue}{\sin \left(-0.5 \cdot \phi_2\right) \cdot \sin \left(-0.5 \cdot \phi_2\right)}\right) - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      4. 1-sub-sin36.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{\color{blue}{\cos \left(-0.5 \cdot \phi_2\right) \cdot \cos \left(-0.5 \cdot \phi_2\right)} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      5. unpow236.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{\color{blue}{{\cos \left(-0.5 \cdot \phi_2\right)}^{2}} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      6. metadata-eval36.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{{\cos \left(\color{blue}{\left(0.5 \cdot -1\right)} \cdot \phi_2\right)}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      7. associate-*r*36.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{{\cos \color{blue}{\left(0.5 \cdot \left(-1 \cdot \phi_2\right)\right)}}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      8. *-commutative36.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{{\cos \color{blue}{\left(\left(-1 \cdot \phi_2\right) \cdot 0.5\right)}}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      9. mul-1-neg36.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{{\cos \left(\color{blue}{\left(-\phi_2\right)} \cdot 0.5\right)}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      10. distribute-lft-neg-out36.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{{\cos \color{blue}{\left(-\phi_2 \cdot 0.5\right)}}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
      11. cos-neg36.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{{\color{blue}{\cos \left(\phi_2 \cdot 0.5\right)}}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}\right) \]
    7. Simplified36.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{\color{blue}{{\cos \left(\phi_2 \cdot 0.5\right)}^{2} - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \cos \phi_2}}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification55.4%

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

Alternative 9: 41.7% accurate, 1.1× speedup?

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

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

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


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

    1. Initial program 55.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 phi2 around 0 43.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{\color{blue}{1 - \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} + \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right)}}}\right) \]
    3. Step-by-step derivation
      1. associate--r+43.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{\color{blue}{\left(1 - {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right) - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}}\right) \]
      2. unpow243.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{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      3. 1-sub-sin43.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{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      4. unpow243.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{\color{blue}{{\cos \left(0.5 \cdot \phi_1\right)}^{2}} - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      5. *-commutative43.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}^{2}}}\right) \]
      6. unpow243.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot \color{blue}{\left(\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right)}}}\right) \]
      7. associate-*r*43.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \color{blue}{\left(\cos \phi_1 \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}}\right) \]
    4. Simplified43.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{\color{blue}{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}}\right) \]
    5. Taylor expanded in phi2 around 0 41.4%

      \[\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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}\right) \]

    if -1e-51 < (-.f64 lambda1 lambda2)

    1. Initial program 64.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. Taylor expanded in lambda1 around 0 54.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{\color{blue}{1 - \left({\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2} + {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right)\right)}}}\right) \]
    3. Step-by-step derivation
      1. +-commutative54.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 - \color{blue}{\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}}\right) \]
      2. *-commutative54.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(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + {\sin \color{blue}{\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}}^{2}\right)}}\right) \]
      3. fma-def54.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 - \color{blue}{\mathsf{fma}\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, \cos \phi_2 \cdot \cos \phi_1, {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)}}}\right) \]
    4. Simplified54.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{\color{blue}{1 - \mathsf{fma}\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, \cos \phi_2 \cdot \cos \phi_1, {\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}^{2}\right)}}}\right) \]
    5. Taylor expanded in lambda2 around 0 42.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{\color{blue}{1 - {\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}^{2}}}}\right) \]
    6. Step-by-step derivation
      1. unpow242.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 - \color{blue}{\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}}\right) \]
      2. cancel-sign-sub-inv42.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{\color{blue}{1 + \left(-\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}}\right) \]
      3. sub-neg42.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(-0.5 \cdot \color{blue}{\left(\phi_2 + \left(-\phi_1\right)\right)}\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      4. mul-1-neg42.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(-0.5 \cdot \left(\phi_2 + \color{blue}{-1 \cdot \phi_1}\right)\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      5. distribute-lft-in42.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(-0.5 \cdot \phi_2 + -0.5 \cdot \left(-1 \cdot \phi_1\right)\right)}\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      6. metadata-eval42.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(\color{blue}{\left(0.5 \cdot -1\right)} \cdot \phi_2 + -0.5 \cdot \left(-1 \cdot \phi_1\right)\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      7. associate-*r*42.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(\color{blue}{0.5 \cdot \left(-1 \cdot \phi_2\right)} + -0.5 \cdot \left(-1 \cdot \phi_1\right)\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      8. associate-*r*42.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(0.5 \cdot \left(-1 \cdot \phi_2\right) + \color{blue}{\left(-0.5 \cdot -1\right) \cdot \phi_1}\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      9. metadata-eval42.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(0.5 \cdot \left(-1 \cdot \phi_2\right) + \color{blue}{0.5} \cdot \phi_1\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      10. distribute-lft-in42.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(0.5 \cdot \left(-1 \cdot \phi_2 + \phi_1\right)\right)}\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      11. +-commutative42.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(0.5 \cdot \color{blue}{\left(\phi_1 + -1 \cdot \phi_2\right)}\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      12. mul-1-neg42.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(0.5 \cdot \left(\phi_1 + \color{blue}{\left(-\phi_2\right)}\right)\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      13. sub-neg42.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(0.5 \cdot \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      14. sub-neg42.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(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\right) \cdot \sin \left(-0.5 \cdot \color{blue}{\left(\phi_2 + \left(-\phi_1\right)\right)}\right)}}\right) \]
      15. mul-1-neg42.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(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 + \color{blue}{-1 \cdot \phi_1}\right)\right)}}\right) \]
      16. distribute-lft-in42.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(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\right) \cdot \sin \color{blue}{\left(-0.5 \cdot \phi_2 + -0.5 \cdot \left(-1 \cdot \phi_1\right)\right)}}}\right) \]
    7. Simplified42.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{\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 simplification42.3%

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

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

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

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


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

    1. Initial program 55.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 phi2 around 0 43.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{\color{blue}{1 - \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} + \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right)}}}\right) \]
    3. Step-by-step derivation
      1. associate--r+43.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{\color{blue}{\left(1 - {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right) - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}}\right) \]
      2. unpow243.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{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      3. 1-sub-sin43.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{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      4. unpow243.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{\color{blue}{{\cos \left(0.5 \cdot \phi_1\right)}^{2}} - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      5. *-commutative43.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}^{2}}}\right) \]
      6. unpow243.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot \color{blue}{\left(\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right)}}}\right) \]
      7. associate-*r*43.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \color{blue}{\left(\cos \phi_1 \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}}\right) \]
    4. Simplified43.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{\color{blue}{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}}\right) \]
    5. Taylor expanded in phi1 around 0 35.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{\color{blue}{1 - {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}}\right) \]
    6. Taylor expanded in phi1 around 0 35.5%

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

    if -9.9999999999999998e23 < (-.f64 lambda1 lambda2)

    1. Initial program 64.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 lambda1 around 0 54.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{\color{blue}{1 - \left({\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2} + {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right)\right)}}}\right) \]
    3. Step-by-step derivation
      1. +-commutative54.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 - \color{blue}{\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}}\right) \]
      2. *-commutative54.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(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + {\sin \color{blue}{\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}}^{2}\right)}}\right) \]
      3. fma-def54.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 - \color{blue}{\mathsf{fma}\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, \cos \phi_2 \cdot \cos \phi_1, {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)}}}\right) \]
    4. Simplified54.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{\color{blue}{1 - \mathsf{fma}\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, \cos \phi_2 \cdot \cos \phi_1, {\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}^{2}\right)}}}\right) \]
    5. Taylor expanded in lambda2 around 0 42.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{\color{blue}{1 - {\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}^{2}}}}\right) \]
    6. Step-by-step derivation
      1. unpow242.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 - \color{blue}{\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}}\right) \]
      2. cancel-sign-sub-inv42.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{\color{blue}{1 + \left(-\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}}\right) \]
      3. sub-neg42.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(-0.5 \cdot \color{blue}{\left(\phi_2 + \left(-\phi_1\right)\right)}\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      4. mul-1-neg42.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(-0.5 \cdot \left(\phi_2 + \color{blue}{-1 \cdot \phi_1}\right)\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      5. distribute-lft-in42.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(-0.5 \cdot \phi_2 + -0.5 \cdot \left(-1 \cdot \phi_1\right)\right)}\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      6. metadata-eval42.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(\color{blue}{\left(0.5 \cdot -1\right)} \cdot \phi_2 + -0.5 \cdot \left(-1 \cdot \phi_1\right)\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      7. associate-*r*42.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(\color{blue}{0.5 \cdot \left(-1 \cdot \phi_2\right)} + -0.5 \cdot \left(-1 \cdot \phi_1\right)\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      8. associate-*r*42.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(0.5 \cdot \left(-1 \cdot \phi_2\right) + \color{blue}{\left(-0.5 \cdot -1\right) \cdot \phi_1}\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      9. metadata-eval42.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(0.5 \cdot \left(-1 \cdot \phi_2\right) + \color{blue}{0.5} \cdot \phi_1\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      10. distribute-lft-in42.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(0.5 \cdot \left(-1 \cdot \phi_2 + \phi_1\right)\right)}\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      11. +-commutative42.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(0.5 \cdot \color{blue}{\left(\phi_1 + -1 \cdot \phi_2\right)}\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      12. mul-1-neg42.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(0.5 \cdot \left(\phi_1 + \color{blue}{\left(-\phi_2\right)}\right)\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      13. sub-neg42.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(0.5 \cdot \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      14. sub-neg42.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(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\right) \cdot \sin \left(-0.5 \cdot \color{blue}{\left(\phi_2 + \left(-\phi_1\right)\right)}\right)}}\right) \]
      15. mul-1-neg42.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(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 + \color{blue}{-1 \cdot \phi_1}\right)\right)}}\right) \]
      16. distribute-lft-in42.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(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\right) \cdot \sin \color{blue}{\left(-0.5 \cdot \phi_2 + -0.5 \cdot \left(-1 \cdot \phi_1\right)\right)}}}\right) \]
    7. Simplified42.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{\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 simplification39.7%

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

Alternative 11: 38.6% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 55.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 phi2 around 0 43.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{\color{blue}{1 - \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} + \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right)}}}\right) \]
    3. Step-by-step derivation
      1. associate--r+43.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{\color{blue}{\left(1 - {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right) - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}}\right) \]
      2. unpow243.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{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      3. 1-sub-sin43.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{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      4. unpow243.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{\color{blue}{{\cos \left(0.5 \cdot \phi_1\right)}^{2}} - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      5. *-commutative43.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}^{2}}}\right) \]
      6. unpow243.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot \color{blue}{\left(\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right)}}}\right) \]
      7. associate-*r*43.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \color{blue}{\left(\cos \phi_1 \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}}\right) \]
    4. Simplified43.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{\color{blue}{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}}\right) \]
    5. Taylor expanded in phi1 around 0 35.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{\color{blue}{1 - {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}}\right) \]

    if -9.9999999999999998e23 < (-.f64 lambda1 lambda2)

    1. Initial program 64.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 lambda1 around 0 54.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{\color{blue}{1 - \left({\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2} + {\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right)\right)}}}\right) \]
    3. Step-by-step derivation
      1. +-commutative54.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 - \color{blue}{\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)}}}\right) \]
      2. *-commutative54.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(-0.5 \cdot \lambda_2\right)}^{2} \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + {\sin \color{blue}{\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}}^{2}\right)}}\right) \]
      3. fma-def54.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 - \color{blue}{\mathsf{fma}\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, \cos \phi_2 \cdot \cos \phi_1, {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)}}}\right) \]
    4. Simplified54.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{\color{blue}{1 - \mathsf{fma}\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, \cos \phi_2 \cdot \cos \phi_1, {\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}^{2}\right)}}}\right) \]
    5. Taylor expanded in lambda2 around 0 42.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{\color{blue}{1 - {\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}^{2}}}}\right) \]
    6. Step-by-step derivation
      1. unpow242.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 - \color{blue}{\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}}\right) \]
      2. cancel-sign-sub-inv42.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{\color{blue}{1 + \left(-\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}}\right) \]
      3. sub-neg42.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(-0.5 \cdot \color{blue}{\left(\phi_2 + \left(-\phi_1\right)\right)}\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      4. mul-1-neg42.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(-0.5 \cdot \left(\phi_2 + \color{blue}{-1 \cdot \phi_1}\right)\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      5. distribute-lft-in42.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(-0.5 \cdot \phi_2 + -0.5 \cdot \left(-1 \cdot \phi_1\right)\right)}\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      6. metadata-eval42.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(\color{blue}{\left(0.5 \cdot -1\right)} \cdot \phi_2 + -0.5 \cdot \left(-1 \cdot \phi_1\right)\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      7. associate-*r*42.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(\color{blue}{0.5 \cdot \left(-1 \cdot \phi_2\right)} + -0.5 \cdot \left(-1 \cdot \phi_1\right)\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      8. associate-*r*42.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(0.5 \cdot \left(-1 \cdot \phi_2\right) + \color{blue}{\left(-0.5 \cdot -1\right) \cdot \phi_1}\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      9. metadata-eval42.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(0.5 \cdot \left(-1 \cdot \phi_2\right) + \color{blue}{0.5} \cdot \phi_1\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      10. distribute-lft-in42.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(0.5 \cdot \left(-1 \cdot \phi_2 + \phi_1\right)\right)}\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      11. +-commutative42.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(0.5 \cdot \color{blue}{\left(\phi_1 + -1 \cdot \phi_2\right)}\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      12. mul-1-neg42.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(0.5 \cdot \left(\phi_1 + \color{blue}{\left(-\phi_2\right)}\right)\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      13. sub-neg42.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(0.5 \cdot \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}}\right) \]
      14. sub-neg42.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(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\right) \cdot \sin \left(-0.5 \cdot \color{blue}{\left(\phi_2 + \left(-\phi_1\right)\right)}\right)}}\right) \]
      15. mul-1-neg42.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(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\right) \cdot \sin \left(-0.5 \cdot \left(\phi_2 + \color{blue}{-1 \cdot \phi_1}\right)\right)}}\right) \]
      16. distribute-lft-in42.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(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\right) \cdot \sin \color{blue}{\left(-0.5 \cdot \phi_2 + -0.5 \cdot \left(-1 \cdot \phi_1\right)\right)}}}\right) \]
    7. Simplified42.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{\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 simplification39.7%

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

Alternative 12: 34.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_0\right)}}{\sqrt{1 - {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\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 phi1) (cos phi2)) t_0))))
      (sqrt (- 1.0 (pow (sin (* -0.5 (- lambda2 lambda1))) 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(phi1) * cos(phi2)) * t_0)))), sqrt((1.0 - pow(sin((-0.5 * (lambda2 - lambda1))), 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(phi1) * cos(phi2)) * t_0)))), sqrt((1.0d0 - (sin(((-0.5d0) * (lambda2 - lambda1))) ** 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(phi1) * Math.cos(phi2)) * t_0)))), Math.sqrt((1.0 - Math.pow(Math.sin((-0.5 * (lambda2 - lambda1))), 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(phi1) * math.cos(phi2)) * t_0)))), math.sqrt((1.0 - math.pow(math.sin((-0.5 * (lambda2 - lambda1))), 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(Float64(cos(phi1) * cos(phi2)) * t_0)))), sqrt(Float64(1.0 - (sin(Float64(-0.5 * Float64(lambda2 - lambda1))) ^ 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(phi1) * cos(phi2)) * t_0)))), sqrt((1.0 - (sin((-0.5 * (lambda2 - lambda1))) ^ 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[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(-0.5 * N[(lambda2 - lambda1), $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(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_0\right)}}{\sqrt{1 - {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 60.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 phi2 around 0 48.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{\color{blue}{1 - \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} + \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right)}}}\right) \]
  3. Step-by-step derivation
    1. associate--r+48.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{\color{blue}{\left(1 - {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right) - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}}\right) \]
    2. unpow248.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{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
    3. 1-sub-sin48.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}{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
    4. unpow248.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}{{\cos \left(0.5 \cdot \phi_1\right)}^{2}} - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
    5. *-commutative48.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}^{2}}}\right) \]
    6. unpow248.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot \color{blue}{\left(\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right)}}}\right) \]
    7. associate-*r*48.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \color{blue}{\left(\cos \phi_1 \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}}\right) \]
  4. Simplified48.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}{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}}\right) \]
  5. Taylor expanded in phi1 around 0 35.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{\color{blue}{1 - {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}}\right) \]
  6. Final simplification35.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(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}{\sqrt{1 - {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}\right) \]

Alternative 13: 32.2% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 65.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. Taylor expanded in phi2 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{\color{blue}{1 - \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} + \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right)}}}\right) \]
    3. Step-by-step derivation
      1. associate--r+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{\color{blue}{\left(1 - {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right) - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}}\right) \]
      2. unpow251.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{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      3. 1-sub-sin52.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{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      4. unpow252.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{\color{blue}{{\cos \left(0.5 \cdot \phi_1\right)}^{2}} - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      5. *-commutative52.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}^{2}}}\right) \]
      6. unpow252.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot \color{blue}{\left(\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right)}}}\right) \]
      7. associate-*r*52.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \color{blue}{\left(\cos \phi_1 \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}}\right) \]
    4. Simplified52.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{\color{blue}{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}}\right) \]
    5. Taylor expanded in phi1 around 0 36.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{\color{blue}{1 - {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}}\right) \]
    6. Taylor expanded in lambda2 around 0 32.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{\color{blue}{1 - {\sin \left(0.5 \cdot \lambda_1\right)}^{2}}}}\right) \]
    7. Step-by-step derivation
      1. unpow232.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 - \color{blue}{\sin \left(0.5 \cdot \lambda_1\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)}}}\right) \]
      2. 1-sub-sin32.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{\color{blue}{\cos \left(0.5 \cdot \lambda_1\right) \cdot \cos \left(0.5 \cdot \lambda_1\right)}}}\right) \]
      3. unpow232.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{\color{blue}{{\cos \left(0.5 \cdot \lambda_1\right)}^{2}}}}\right) \]
      4. *-commutative32.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{{\cos \color{blue}{\left(\lambda_1 \cdot 0.5\right)}}^{2}}}\right) \]
    8. Simplified32.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{\color{blue}{{\cos \left(\lambda_1 \cdot 0.5\right)}^{2}}}}\right) \]

    if 2.59999999999999977e-4 < lambda2

    1. Initial program 47.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 phi2 around 0 38.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({\sin \left(0.5 \cdot \phi_1\right)}^{2} + \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right)}}}\right) \]
    3. Step-by-step derivation
      1. associate--r+38.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}{\left(1 - {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right) - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}}\right) \]
      2. unpow238.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{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      3. 1-sub-sin38.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}{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      4. unpow238.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}{{\cos \left(0.5 \cdot \phi_1\right)}^{2}} - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
      5. *-commutative38.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}^{2}}}\right) \]
      6. unpow238.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot \color{blue}{\left(\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right)}}}\right) \]
      7. associate-*r*38.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \color{blue}{\left(\cos \phi_1 \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}}\right) \]
    4. Simplified38.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}{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}}\right) \]
    5. Taylor expanded in phi1 around 0 31.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{\color{blue}{1 - {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}}\right) \]
    6. Taylor expanded in lambda1 around 0 31.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{\color{blue}{1 - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}}\right) \]
    7. Step-by-step derivation
      1. unpow231.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 - \color{blue}{\sin \left(-0.5 \cdot \lambda_2\right) \cdot \sin \left(-0.5 \cdot \lambda_2\right)}}}\right) \]
      2. 1-sub-sin31.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{\color{blue}{\cos \left(-0.5 \cdot \lambda_2\right) \cdot \cos \left(-0.5 \cdot \lambda_2\right)}}}\right) \]
      3. unpow231.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{\color{blue}{{\cos \left(-0.5 \cdot \lambda_2\right)}^{2}}}}\right) \]
      4. metadata-eval31.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{{\cos \left(\color{blue}{\left(0.5 \cdot -1\right)} \cdot \lambda_2\right)}^{2}}}\right) \]
      5. associate-*r*31.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{{\cos \color{blue}{\left(0.5 \cdot \left(-1 \cdot \lambda_2\right)\right)}}^{2}}}\right) \]
      6. neg-mul-131.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{{\cos \left(0.5 \cdot \color{blue}{\left(-\lambda_2\right)}\right)}^{2}}}\right) \]
      7. distribute-rgt-neg-out31.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{{\cos \color{blue}{\left(-0.5 \cdot \lambda_2\right)}}^{2}}}\right) \]
      8. cos-neg31.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{{\color{blue}{\cos \left(0.5 \cdot \lambda_2\right)}}^{2}}}\right) \]
      9. *-commutative31.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{{\cos \color{blue}{\left(\lambda_2 \cdot 0.5\right)}}^{2}}}\right) \]
    8. Simplified31.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{\color{blue}{{\cos \left(\lambda_2 \cdot 0.5\right)}^{2}}}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification32.2%

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

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

\\
\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(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_0\right)}}{\sqrt{{\cos \left(\lambda_1 \cdot 0.5\right)}^{2}}}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 60.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 phi2 around 0 48.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{\color{blue}{1 - \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} + \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right)}}}\right) \]
  3. Step-by-step derivation
    1. associate--r+48.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{\color{blue}{\left(1 - {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right) - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}}\right) \]
    2. unpow248.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{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
    3. 1-sub-sin48.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}{\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 \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
    4. unpow248.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}{{\cos \left(0.5 \cdot \phi_1\right)}^{2}} - \cos \phi_1 \cdot {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right) \]
    5. *-commutative48.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}^{2}}}\right) \]
    6. unpow248.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot \color{blue}{\left(\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right)}}}\right) \]
    7. associate-*r*48.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{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \color{blue}{\left(\cos \phi_1 \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\right) \cdot \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}}}\right) \]
  4. Simplified48.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}{{\cos \left(0.5 \cdot \phi_1\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}}\right) \]
  5. Taylor expanded in phi1 around 0 35.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{\color{blue}{1 - {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}}\right) \]
  6. Taylor expanded in lambda2 around 0 29.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{\color{blue}{1 - {\sin \left(0.5 \cdot \lambda_1\right)}^{2}}}}\right) \]
  7. Step-by-step derivation
    1. unpow229.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 - \color{blue}{\sin \left(0.5 \cdot \lambda_1\right) \cdot \sin \left(0.5 \cdot \lambda_1\right)}}}\right) \]
    2. 1-sub-sin29.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{\color{blue}{\cos \left(0.5 \cdot \lambda_1\right) \cdot \cos \left(0.5 \cdot \lambda_1\right)}}}\right) \]
    3. unpow229.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{\color{blue}{{\cos \left(0.5 \cdot \lambda_1\right)}^{2}}}}\right) \]
    4. *-commutative29.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{{\cos \color{blue}{\left(\lambda_1 \cdot 0.5\right)}}^{2}}}\right) \]
  8. Simplified29.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{\color{blue}{{\cos \left(\lambda_1 \cdot 0.5\right)}^{2}}}}\right) \]
  9. Final simplification29.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(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}{\sqrt{{\cos \left(\lambda_1 \cdot 0.5\right)}^{2}}}\right) \]

Alternative 15: 11.1% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
t_0 := \sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_0}{\sqrt{{t_0}^{2} - \mathsf{fma}\left(\cos \phi_1 \cdot \cos \phi_2, 0.5 - \frac{\cos \left(\lambda_2 - \lambda_1\right)}{2}, -1\right)}}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 60.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. Simplified34.5%

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

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

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

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

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

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

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

Reproduce

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