Distance on a great circle

Percentage Accurate: 62.2% → 62.8%
Time: 21.0s
Alternatives: 17
Speedup: 1.3×

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))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
    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}

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 17 alternatives:

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

Initial Program: 62.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_1 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_0\right) \cdot t\_0\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right) \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_1
         (+
          (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
          (* (* (* (cos phi1) (cos phi2)) t_0) t_0))))
   (* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(((lambda1 - lambda2) / 2.0));
	double t_1 = pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0);
	return R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
    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.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)\\
t_1 := {t\_0}^{2}\\
t_2 := \sin \left(0.5 \cdot \phi_1\right)\\
t_3 := \mathsf{fma}\left(\cos \phi_2, t\_1, {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)\\
t_4 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_3}}{\sqrt{1 - t\_3}}\right)\\
\mathbf{if}\;\phi_2 \leq -8.5 \cdot 10^{-12}:\\
\;\;\;\;t\_4\\

\mathbf{elif}\;\phi_2 \leq 0.0027:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_1 \cdot t\_0, \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right), {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)}}{\sqrt{\left(1 + \phi_2 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot t\_2\right)\right) - \mathsf{fma}\left(\cos \phi_1, t\_1, {t\_2}^{2}\right)}} \cdot 2\right) \cdot R\\

\mathbf{else}:\\
\;\;\;\;t\_4\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < -8.4999999999999997e-12 or 0.0027000000000000001 < phi2

    1. Initial program 62.2%

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

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

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

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

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

    if -8.4999999999999997e-12 < phi2 < 0.0027000000000000001

    1. Initial program 62.2%

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

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

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

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

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

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

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

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

Alternative 2: 62.8% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
t_0 := \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\\
t_1 := \mathsf{fma}\left(\cos \phi_1, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)\\
t_2 := \sqrt{1 - t\_1}\\
t_3 := {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\\
t_4 := \mathsf{fma}\left(\cos \phi_2 \cdot t\_0, t\_0, t\_3\right)\\
\mathbf{if}\;\phi_1 \leq -2.1 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{t\_2}\right)\\

\mathbf{elif}\;\phi_1 \leq 110:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{t\_4}}{\sqrt{1 - t\_4}} \cdot 2\right) \cdot R\\

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


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

    1. Initial program 62.2%

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

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

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

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

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

    if -2.09999999999999988e-5 < phi1 < 110

    1. Initial program 62.2%

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

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

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

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

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

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

    if 110 < phi1

    1. Initial program 62.2%

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

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

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

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

Alternative 3: 62.8% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)\\
t_1 := {t\_0}^{2}\\
t_2 := \mathsf{fma}\left(\cos \phi_2, t\_1, {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)\\
t_3 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_2}}{\sqrt{1 - t\_2}}\right)\\
\mathbf{if}\;\phi_2 \leq -8.5 \cdot 10^{-12}:\\
\;\;\;\;t\_3\\

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

\mathbf{else}:\\
\;\;\;\;t\_3\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < -8.4999999999999997e-12 or 0.0027000000000000001 < phi2

    1. Initial program 62.2%

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

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

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

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

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

    if -8.4999999999999997e-12 < phi2 < 0.0027000000000000001

    1. Initial program 62.2%

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

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

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

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

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

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

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

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

Alternative 4: 62.7% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \cos \phi_1 \cdot t\_0\\
t_2 := \mathsf{fma}\left(\cos \phi_2, t\_0, {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)\\
t_3 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_2}}{\sqrt{1 - t\_2}}\right)\\
\mathbf{if}\;\phi_2 \leq -8.5 \cdot 10^{-12}:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;\phi_2 \leq 0.0027:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)\\

\mathbf{else}:\\
\;\;\;\;t\_3\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < -8.4999999999999997e-12 or 0.0027000000000000001 < phi2

    1. Initial program 62.2%

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

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

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

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

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

    if -8.4999999999999997e-12 < phi2 < 0.0027000000000000001

    1. Initial program 62.2%

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

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

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

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

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

Alternative 5: 62.2% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\\
t_1 := \mathsf{fma}\left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_0, t\_0, {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)\\
\left(\tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}} \cdot 2\right) \cdot R
\end{array}
\end{array}
Derivation
  1. Initial program 62.2%

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

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

Alternative 6: 60.9% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := \mathsf{fma}\left(\cos \phi_2, t\_0, {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)\\
t_2 := \mathsf{fma}\left(\cos \phi_1, t\_0, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)\\
t_3 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_2}}{\sqrt{1 - t\_2}}\right)\\
\mathbf{if}\;\phi_1 \leq -2.2 \cdot 10^{-50}:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;\phi_1 \leq 1.28 \cdot 10^{-11}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)\\

\mathbf{else}:\\
\;\;\;\;t\_3\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi1 < -2.1999999999999999e-50 or 1.28e-11 < phi1

    1. Initial program 62.2%

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

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

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

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

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

    if -2.1999999999999999e-50 < phi1 < 1.28e-11

    1. Initial program 62.2%

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

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

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

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

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

Alternative 7: 52.3% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\cos \phi_1, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\\
t_3 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_0}}{\sqrt{1 - t\_0}}\right)\\
\mathbf{if}\;t\_1 \leq -0.05:\\
\;\;\;\;t\_3\\

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

\mathbf{else}:\\
\;\;\;\;t\_3\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) < -0.050000000000000003 or 4.0000000000000002e-26 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))

    1. Initial program 62.2%

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

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

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

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

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

    if -0.050000000000000003 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) < 4.0000000000000002e-26

    1. Initial program 62.2%

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

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

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

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

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

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

Alternative 8: 44.8% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \phi_1\right)}^{2}\\
t_1 := \mathsf{fma}\left(\cos \phi_1, {\sin \left(0.5 \cdot \lambda_1\right)}^{2}, t\_0\right)\\
t_2 := \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\\
t_3 := \mathsf{fma}\left(\cos \phi_1, {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, t\_0\right)\\
t_4 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_3}}{\sqrt{1 - t\_3}}\right)\\
\mathbf{if}\;\lambda_2 \leq -2.3 \cdot 10^{-12}:\\
\;\;\;\;t\_4\\

\mathbf{elif}\;\lambda_2 \leq 2.8 \cdot 10^{-145}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)\\

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

\mathbf{else}:\\
\;\;\;\;t\_4\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if lambda2 < -2.29999999999999989e-12 or 0.149999999999999994 < lambda2

    1. Initial program 62.2%

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

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

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

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

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

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

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

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

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

    if -2.29999999999999989e-12 < lambda2 < 2.8000000000000001e-145

    1. Initial program 62.2%

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

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

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

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

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

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

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

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

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

    if 2.8000000000000001e-145 < lambda2 < 0.149999999999999994

    1. Initial program 62.2%

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

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

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

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

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

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

Alternative 9: 42.5% accurate, 1.2× speedup?

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

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

\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-30}:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_3 \cdot t\_1, t\_1, {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)}}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}} \cdot 2\right) \cdot R\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) < -0.298999999999999988

    1. Initial program 62.2%

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

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

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

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

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

    if -0.298999999999999988 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) < 4.99999999999999972e-30

    1. Initial program 62.2%

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

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

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

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

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

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

    if 4.99999999999999972e-30 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))

    1. Initial program 62.2%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Taylor expanded in phi2 around 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 + \phi_2 \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right) - \left(\cos \phi_1 \cdot {\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}}\right) \]
    3. Applied rewrites42.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 + \phi_2 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right) - \mathsf{fma}\left(\cos \phi_1, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}}\right) \]
    4. Taylor expanded in phi1 around 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}{{\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}}\right) \]
    5. Applied rewrites34.8%

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

Alternative 10: 42.4% accurate, 1.2× 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\\ t_2 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(t\_1 \cdot t\_0\right) \cdot t\_0}}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right)\\ t_3 := \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\\ \mathbf{if}\;t\_0 \leq -0.299:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-30}:\\ \;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_1 \cdot t\_3, t\_3, {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)}}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}} \cdot 2\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_1 (* (cos phi1) (cos phi2)))
        (t_2
         (*
          R
          (*
           2.0
           (atan2
            (sqrt
             (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* (* t_1 t_0) t_0)))
            (sqrt (- 1.0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0)))))))
        (t_3 (sin (* (- lambda1 lambda2) 0.5))))
   (if (<= t_0 -0.299)
     t_2
     (if (<= t_0 5e-30)
       (*
        (*
         (atan2
          (sqrt (fma (* t_1 t_3) t_3 (pow (sin (* (- phi1 phi2) 0.5)) 2.0)))
          (sqrt (- 1.0 (pow (sin (* 0.5 (- phi1 phi2))) 2.0))))
         2.0)
        R)
       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 = cos(phi1) * cos(phi2);
	double t_2 = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + ((t_1 * t_0) * t_0))), sqrt((1.0 - pow(sin((0.5 * (lambda1 - lambda2))), 2.0)))));
	double t_3 = sin(((lambda1 - lambda2) * 0.5));
	double tmp;
	if (t_0 <= -0.299) {
		tmp = t_2;
	} else if (t_0 <= 5e-30) {
		tmp = (atan2(sqrt(fma((t_1 * t_3), t_3, pow(sin(((phi1 - phi2) * 0.5)), 2.0))), sqrt((1.0 - pow(sin((0.5 * (phi1 - phi2))), 2.0)))) * 2.0) * R;
	} else {
		tmp = t_2;
	}
	return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0))
	t_1 = Float64(cos(phi1) * cos(phi2))
	t_2 = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(t_1 * t_0) * t_0))), sqrt(Float64(1.0 - (sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0))))))
	t_3 = sin(Float64(Float64(lambda1 - lambda2) * 0.5))
	tmp = 0.0
	if (t_0 <= -0.299)
		tmp = t_2;
	elseif (t_0 <= 5e-30)
		tmp = Float64(Float64(atan(sqrt(fma(Float64(t_1 * t_3), t_3, (sin(Float64(Float64(phi1 - phi2) * 0.5)) ^ 2.0))), sqrt(Float64(1.0 - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0)))) * 2.0) * R);
	else
		tmp = t_2;
	end
	return tmp
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(t$95$1 * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, -0.299], t$95$2, If[LessEqual[t$95$0, 5e-30], N[(N[(N[ArcTan[N[Sqrt[N[(N[(t$95$1 * t$95$3), $MachinePrecision] * t$95$3 + N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision], t$95$2]]]]]]
\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\\
t_2 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(t\_1 \cdot t\_0\right) \cdot t\_0}}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}\right)\\
t_3 := \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\\
\mathbf{if}\;t\_0 \leq -0.299:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-30}:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_1 \cdot t\_3, t\_3, {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)}}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}} \cdot 2\right) \cdot R\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) < -0.298999999999999988 or 4.99999999999999972e-30 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))

    1. Initial program 62.2%

      \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
    2. Taylor expanded in phi2 around 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 + \phi_2 \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right) - \left(\cos \phi_1 \cdot {\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + {\sin \left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}}\right) \]
    3. Applied rewrites42.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 + \phi_2 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right) - \mathsf{fma}\left(\cos \phi_1, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}}\right) \]
    4. Taylor expanded in phi1 around 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}{{\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}}}}\right) \]
    5. Applied rewrites34.8%

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

    if -0.298999999999999988 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) < 4.99999999999999972e-30

    1. Initial program 62.2%

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

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

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

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

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

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

Alternative 11: 40.7% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
t_0 := \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\\
t_1 := \left(\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_0, t\_0, {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)}}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}} \cdot 2\right) \cdot R\\
t_2 := \mathsf{fma}\left(1, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)\\
\mathbf{if}\;\phi_2 \leq -2.46 \cdot 10^{-23}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\phi_2 \leq 5 \cdot 10^{-22}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_2}}{\sqrt{1 - t\_2}}\right)\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < -2.4599999999999999e-23 or 4.99999999999999954e-22 < phi2

    1. Initial program 62.2%

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

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

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

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

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

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

    if -2.4599999999999999e-23 < phi2 < 4.99999999999999954e-22

    1. Initial program 62.2%

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

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

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

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

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

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

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

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

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

Alternative 12: 40.6% accurate, 1.5× speedup?

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

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

\mathbf{elif}\;\phi_2 \leq 16:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_2}}{\sqrt{1 - t\_2}}\right)\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


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

    1. Initial program 62.2%

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

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

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

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

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

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

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

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

    if -0.160000000000000003 < phi2 < 16

    1. Initial program 62.2%

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

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

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

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

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

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

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

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

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

Alternative 13: 34.2% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(1, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(0.5 \cdot \phi_1\right)}^{2}\right)\\
t_1 := \mathsf{fma}\left(1, {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)\\
t_2 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)\\
\mathbf{if}\;\phi_1 \leq -2.05 \cdot 10^{-5}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;\phi_1 \leq 7.8 \cdot 10^{-32}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_0}}{\sqrt{1 - t\_0}}\right)\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi1 < -2.05000000000000002e-5 or 7.8000000000000003e-32 < phi1

    1. Initial program 62.2%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(1, {\sin \left(\frac{-1}{2} \cdot \lambda_2\right)}^{2}, {\sin \left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(1, {\sin \left(\frac{-1}{2} \cdot \lambda_2\right)}^{\color{blue}{2}}, {\sin \left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}\right) \]
    13. Applied rewrites26.4%

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

    if -2.05000000000000002e-5 < phi1 < 7.8000000000000003e-32

    1. Initial program 62.2%

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

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(1, {\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(1, {\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\sin \left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}\right) \]
    11. Applied rewrites28.2%

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

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(1, {\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(1, {\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}\right) \]
    13. Applied rewrites22.3%

      \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(1, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(0.5 \cdot \phi_1\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(1, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(0.5 \cdot \phi_1\right)}^{2}\right)}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 14: 33.5% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(1, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_0}}{\sqrt{1 - t\_0}}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 62.2%

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

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

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

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

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

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

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

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

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

Alternative 15: 22.3% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(1, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(\phi_1 \cdot \left(0.5 + -0.020833333333333332 \cdot {\phi_1}^{2}\right)\right)}^{2}\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_0}}{\sqrt{1 - t\_0}}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 62.2%

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

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

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

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

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

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

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

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

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

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(1, {\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(\phi_1 \cdot \left(\frac{1}{2} + \frac{-1}{48} \cdot {\phi_1}^{2}\right)\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(1, {\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\sin \left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}\right) \]
  11. Applied rewrites28.2%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(1, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(\phi_1 \cdot \left(0.5 + -0.020833333333333332 \cdot {\phi_1}^{2}\right)\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(1, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}\right) \]
  12. Taylor expanded in phi1 around 0

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(1, {\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(\phi_1 \cdot \left(\frac{1}{2} + \frac{-1}{48} \cdot {\phi_1}^{2}\right)\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(1, {\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(\phi_1 \cdot \left(\frac{1}{2} + \frac{-1}{48} \cdot {\phi_1}^{2}\right)\right)}^{2}\right)}}\right) \]
  13. Applied rewrites22.3%

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(1, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(\phi_1 \cdot \left(0.5 + -0.020833333333333332 \cdot {\phi_1}^{2}\right)\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(1, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(\phi_1 \cdot \left(0.5 + -0.020833333333333332 \cdot {\phi_1}^{2}\right)\right)}^{2}\right)}}\right) \]
  14. Add Preprocessing

Alternative 16: 22.3% accurate, 2.4× speedup?

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

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(1, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(0.5 \cdot \phi_1\right)}^{2}\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_0}}{\sqrt{1 - t\_0}}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 62.2%

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

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

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

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

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

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

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

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

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

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(1, {\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(1, {\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\sin \left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}\right) \]
  11. Applied rewrites28.2%

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

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(1, {\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(1, {\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}\right) \]
  13. Applied rewrites22.3%

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

Alternative 17: 14.2% accurate, 2.5× speedup?

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

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(1, {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, {\left(0.5 \cdot \phi_1\right)}^{2}\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_0}}{\sqrt{1 - t\_0}}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 62.2%

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

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

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

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

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

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

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

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

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

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(1, {\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(1, {\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\sin \left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}\right) \]
  11. Applied rewrites28.2%

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

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(1, {\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(1, {\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}\right) \]
  13. Applied rewrites22.3%

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

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(1, {\sin \left(\frac{-1}{2} \cdot \lambda_2\right)}^{2}, {\left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(1, {\sin \left(\frac{1}{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}\right) \]
  15. Applied rewrites14.2%

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

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(1, {\sin \left(\frac{-1}{2} \cdot \lambda_2\right)}^{2}, {\left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(1, {\sin \left(\frac{-1}{2} \cdot \lambda_2\right)}^{2}, {\left(\frac{1}{2} \cdot \phi_1\right)}^{2}\right)}}\right) \]
  17. Applied rewrites14.2%

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

Reproduce

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