Equirectangular approximation to distance on a great circle

Percentage Accurate: 58.8% → 90.6%
Time: 14.1s
Alternatives: 11
Speedup: 18.6×

Specification

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

\\
\begin{array}{l}
t_0 := \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\\
R \cdot \sqrt{t\_0 \cdot t\_0 + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}
\end{array}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 11 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: 58.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\\
R \cdot \sqrt{t\_0 \cdot t\_0 + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}
\end{array}
\end{array}

Alternative 1: 90.6% accurate, 1.2× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 0.044:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\phi_1 \cdot 0.5\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi2 0.044)
   (* (hypot phi1 (* (- lambda1 lambda2) (cos (* phi1 0.5)))) R)
   (* R (hypot phi2 (* (- lambda1 lambda2) (cos (* phi2 0.5)))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 0.044) {
		tmp = hypot(phi1, ((lambda1 - lambda2) * cos((phi1 * 0.5)))) * R;
	} else {
		tmp = R * hypot(phi2, ((lambda1 - lambda2) * cos((phi2 * 0.5))));
	}
	return tmp;
}
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 0.044) {
		tmp = Math.hypot(phi1, ((lambda1 - lambda2) * Math.cos((phi1 * 0.5)))) * R;
	} else {
		tmp = R * Math.hypot(phi2, ((lambda1 - lambda2) * Math.cos((phi2 * 0.5))));
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 0.044:
		tmp = math.hypot(phi1, ((lambda1 - lambda2) * math.cos((phi1 * 0.5)))) * R
	else:
		tmp = R * math.hypot(phi2, ((lambda1 - lambda2) * math.cos((phi2 * 0.5))))
	return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 0.044)
		tmp = Float64(hypot(phi1, Float64(Float64(lambda1 - lambda2) * cos(Float64(phi1 * 0.5)))) * R);
	else
		tmp = Float64(R * hypot(phi2, Float64(Float64(lambda1 - lambda2) * cos(Float64(phi2 * 0.5)))));
	end
	return tmp
end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi2 <= 0.044)
		tmp = hypot(phi1, ((lambda1 - lambda2) * cos((phi1 * 0.5)))) * R;
	else
		tmp = R * hypot(phi2, ((lambda1 - lambda2) * cos((phi2 * 0.5))));
	end
	tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 0.044], N[(N[Sqrt[phi1 ^ 2 + N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(R * N[Sqrt[phi2 ^ 2 + N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 0.044:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\phi_1 \cdot 0.5\right)\right) \cdot R\\

\mathbf{else}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < 0.043999999999999997

    1. Initial program 60.8%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi2 around 0

      \[\leadsto \color{blue}{R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
      3. +-commutativeN/A

        \[\leadsto \sqrt{\color{blue}{{\phi_1}^{2} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}}} \cdot R \]
      4. unpow2N/A

        \[\leadsto \sqrt{\color{blue}{\phi_1 \cdot \phi_1} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      5. unpow2N/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      6. unpow2N/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      7. unswap-sqrN/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      8. accelerator-lowering-hypot.f64N/A

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      11. --lowering--.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot R \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      13. *-lowering-*.f6480.6

        \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(0.5 \cdot \phi_1\right)}\right) \cdot R \]
    5. Simplified80.6%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot R} \]

    if 0.043999999999999997 < phi2

    1. Initial program 49.4%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \color{blue}{R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}}} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}} \cdot R} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}} \cdot R} \]
      3. +-commutativeN/A

        \[\leadsto \sqrt{\color{blue}{{\phi_2}^{2} + {\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}}} \cdot R \]
      4. unpow2N/A

        \[\leadsto \sqrt{\color{blue}{\phi_2 \cdot \phi_2} + {\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      5. unpow2N/A

        \[\leadsto \sqrt{\phi_2 \cdot \phi_2 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      6. unpow2N/A

        \[\leadsto \sqrt{\phi_2 \cdot \phi_2 + \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      7. unswap-sqrN/A

        \[\leadsto \sqrt{\phi_2 \cdot \phi_2 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      8. accelerator-lowering-hypot.f64N/A

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_2, \cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_2, \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_2, \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_2\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_2, \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_2\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      12. --lowering--.f6482.5

        \[\leadsto \mathsf{hypot}\left(\phi_2, \cos \left(0.5 \cdot \phi_2\right) \cdot \color{blue}{\left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
    5. Simplified82.5%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_2, \cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification81.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 0.044:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\phi_1 \cdot 0.5\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 86.1% accurate, 1.2× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 0.045:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\phi_1 \cdot 0.5\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \lambda_2 \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi2 0.045)
   (* (hypot phi1 (* (- lambda1 lambda2) (cos (* phi1 0.5)))) R)
   (* R (hypot phi2 (* lambda2 (cos (* phi2 0.5)))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 0.045) {
		tmp = hypot(phi1, ((lambda1 - lambda2) * cos((phi1 * 0.5)))) * R;
	} else {
		tmp = R * hypot(phi2, (lambda2 * cos((phi2 * 0.5))));
	}
	return tmp;
}
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 0.045) {
		tmp = Math.hypot(phi1, ((lambda1 - lambda2) * Math.cos((phi1 * 0.5)))) * R;
	} else {
		tmp = R * Math.hypot(phi2, (lambda2 * Math.cos((phi2 * 0.5))));
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 0.045:
		tmp = math.hypot(phi1, ((lambda1 - lambda2) * math.cos((phi1 * 0.5)))) * R
	else:
		tmp = R * math.hypot(phi2, (lambda2 * math.cos((phi2 * 0.5))))
	return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 0.045)
		tmp = Float64(hypot(phi1, Float64(Float64(lambda1 - lambda2) * cos(Float64(phi1 * 0.5)))) * R);
	else
		tmp = Float64(R * hypot(phi2, Float64(lambda2 * cos(Float64(phi2 * 0.5)))));
	end
	return tmp
end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi2 <= 0.045)
		tmp = hypot(phi1, ((lambda1 - lambda2) * cos((phi1 * 0.5)))) * R;
	else
		tmp = R * hypot(phi2, (lambda2 * cos((phi2 * 0.5))));
	end
	tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 0.045], N[(N[Sqrt[phi1 ^ 2 + N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(R * N[Sqrt[phi2 ^ 2 + N[(lambda2 * N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 0.045:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\phi_1 \cdot 0.5\right)\right) \cdot R\\

\mathbf{else}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \lambda_2 \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < 0.044999999999999998

    1. Initial program 60.8%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi2 around 0

      \[\leadsto \color{blue}{R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
      3. +-commutativeN/A

        \[\leadsto \sqrt{\color{blue}{{\phi_1}^{2} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}}} \cdot R \]
      4. unpow2N/A

        \[\leadsto \sqrt{\color{blue}{\phi_1 \cdot \phi_1} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      5. unpow2N/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      6. unpow2N/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      7. unswap-sqrN/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      8. accelerator-lowering-hypot.f64N/A

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      11. --lowering--.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot R \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      13. *-lowering-*.f6480.6

        \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(0.5 \cdot \phi_1\right)}\right) \cdot R \]
    5. Simplified80.6%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot R} \]

    if 0.044999999999999998 < phi2

    1. Initial program 49.4%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \color{blue}{R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}}} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}} \cdot R} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}} \cdot R} \]
      3. +-commutativeN/A

        \[\leadsto \sqrt{\color{blue}{{\phi_2}^{2} + {\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}}} \cdot R \]
      4. unpow2N/A

        \[\leadsto \sqrt{\color{blue}{\phi_2 \cdot \phi_2} + {\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      5. unpow2N/A

        \[\leadsto \sqrt{\phi_2 \cdot \phi_2 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      6. unpow2N/A

        \[\leadsto \sqrt{\phi_2 \cdot \phi_2 + \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      7. unswap-sqrN/A

        \[\leadsto \sqrt{\phi_2 \cdot \phi_2 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      8. accelerator-lowering-hypot.f64N/A

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_2, \cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_2, \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_2, \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_2\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_2, \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_2\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      12. --lowering--.f6482.5

        \[\leadsto \mathsf{hypot}\left(\phi_2, \cos \left(0.5 \cdot \phi_2\right) \cdot \color{blue}{\left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
    5. Simplified82.5%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_2, \cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
    6. Taylor expanded in lambda1 around 0

      \[\leadsto \color{blue}{\sqrt{{\lambda_2}^{2} \cdot {\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} + {\phi_2}^{2}}} \cdot R \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \sqrt{\color{blue}{{\phi_2}^{2} + {\lambda_2}^{2} \cdot {\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2}}} \cdot R \]
      2. unpow2N/A

        \[\leadsto \sqrt{\color{blue}{\phi_2 \cdot \phi_2} + {\lambda_2}^{2} \cdot {\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2}} \cdot R \]
      3. unpow2N/A

        \[\leadsto \sqrt{\phi_2 \cdot \phi_2 + \color{blue}{\left(\lambda_2 \cdot \lambda_2\right)} \cdot {\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2}} \cdot R \]
      4. unpow2N/A

        \[\leadsto \sqrt{\phi_2 \cdot \phi_2 + \left(\lambda_2 \cdot \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)}} \cdot R \]
      5. unswap-sqrN/A

        \[\leadsto \sqrt{\phi_2 \cdot \phi_2 + \color{blue}{\left(\lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right) \cdot \left(\lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)}} \cdot R \]
      6. accelerator-lowering-hypot.f64N/A

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_2, \lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)} \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_2, \color{blue}{\lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_2, \lambda_2 \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_2\right)}\right) \cdot R \]
      9. *-lowering-*.f6470.5

        \[\leadsto \mathsf{hypot}\left(\phi_2, \lambda_2 \cdot \cos \color{blue}{\left(0.5 \cdot \phi_2\right)}\right) \cdot R \]
    8. Simplified70.5%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_2, \lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)} \cdot R \]
  3. Recombined 2 regimes into one program.
  4. Final simplification78.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 0.045:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\phi_1 \cdot 0.5\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \lambda_2 \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 80.4% accurate, 1.3× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 0.042:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \lambda_2 \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi2 0.042)
   (* R (hypot phi1 (- lambda1 lambda2)))
   (* R (hypot phi2 (* lambda2 (cos (* phi2 0.5)))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 0.042) {
		tmp = R * hypot(phi1, (lambda1 - lambda2));
	} else {
		tmp = R * hypot(phi2, (lambda2 * cos((phi2 * 0.5))));
	}
	return tmp;
}
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 0.042) {
		tmp = R * Math.hypot(phi1, (lambda1 - lambda2));
	} else {
		tmp = R * Math.hypot(phi2, (lambda2 * Math.cos((phi2 * 0.5))));
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 0.042:
		tmp = R * math.hypot(phi1, (lambda1 - lambda2))
	else:
		tmp = R * math.hypot(phi2, (lambda2 * math.cos((phi2 * 0.5))))
	return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 0.042)
		tmp = Float64(R * hypot(phi1, Float64(lambda1 - lambda2)));
	else
		tmp = Float64(R * hypot(phi2, Float64(lambda2 * cos(Float64(phi2 * 0.5)))));
	end
	return tmp
end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi2 <= 0.042)
		tmp = R * hypot(phi1, (lambda1 - lambda2));
	else
		tmp = R * hypot(phi2, (lambda2 * cos((phi2 * 0.5))));
	end
	tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 0.042], N[(R * N[Sqrt[phi1 ^ 2 + N[(lambda1 - lambda2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[phi2 ^ 2 + N[(lambda2 * N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 0.042:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \lambda_2 \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < 0.0420000000000000026

    1. Initial program 60.8%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi2 around 0

      \[\leadsto \color{blue}{R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
      3. +-commutativeN/A

        \[\leadsto \sqrt{\color{blue}{{\phi_1}^{2} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}}} \cdot R \]
      4. unpow2N/A

        \[\leadsto \sqrt{\color{blue}{\phi_1 \cdot \phi_1} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      5. unpow2N/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      6. unpow2N/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      7. unswap-sqrN/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      8. accelerator-lowering-hypot.f64N/A

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      11. --lowering--.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot R \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      13. *-lowering-*.f6480.6

        \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(0.5 \cdot \phi_1\right)}\right) \cdot R \]
    5. Simplified80.6%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot R} \]
    6. Taylor expanded in phi1 around 0

      \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_1 - \lambda_2}\right) \cdot R \]
    7. Step-by-step derivation
      1. --lowering--.f6474.4

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_1 - \lambda_2}\right) \cdot R \]
    8. Simplified74.4%

      \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_1 - \lambda_2}\right) \cdot R \]

    if 0.0420000000000000026 < phi2

    1. Initial program 49.4%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \color{blue}{R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}}} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}} \cdot R} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}} \cdot R} \]
      3. +-commutativeN/A

        \[\leadsto \sqrt{\color{blue}{{\phi_2}^{2} + {\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}}} \cdot R \]
      4. unpow2N/A

        \[\leadsto \sqrt{\color{blue}{\phi_2 \cdot \phi_2} + {\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      5. unpow2N/A

        \[\leadsto \sqrt{\phi_2 \cdot \phi_2 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      6. unpow2N/A

        \[\leadsto \sqrt{\phi_2 \cdot \phi_2 + \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      7. unswap-sqrN/A

        \[\leadsto \sqrt{\phi_2 \cdot \phi_2 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      8. accelerator-lowering-hypot.f64N/A

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_2, \cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_2, \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_2, \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_2\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_2, \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_2\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      12. --lowering--.f6482.5

        \[\leadsto \mathsf{hypot}\left(\phi_2, \cos \left(0.5 \cdot \phi_2\right) \cdot \color{blue}{\left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
    5. Simplified82.5%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_2, \cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
    6. Taylor expanded in lambda1 around 0

      \[\leadsto \color{blue}{\sqrt{{\lambda_2}^{2} \cdot {\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} + {\phi_2}^{2}}} \cdot R \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \sqrt{\color{blue}{{\phi_2}^{2} + {\lambda_2}^{2} \cdot {\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2}}} \cdot R \]
      2. unpow2N/A

        \[\leadsto \sqrt{\color{blue}{\phi_2 \cdot \phi_2} + {\lambda_2}^{2} \cdot {\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2}} \cdot R \]
      3. unpow2N/A

        \[\leadsto \sqrt{\phi_2 \cdot \phi_2 + \color{blue}{\left(\lambda_2 \cdot \lambda_2\right)} \cdot {\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2}} \cdot R \]
      4. unpow2N/A

        \[\leadsto \sqrt{\phi_2 \cdot \phi_2 + \left(\lambda_2 \cdot \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)}} \cdot R \]
      5. unswap-sqrN/A

        \[\leadsto \sqrt{\phi_2 \cdot \phi_2 + \color{blue}{\left(\lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right) \cdot \left(\lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)}} \cdot R \]
      6. accelerator-lowering-hypot.f64N/A

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_2, \lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)} \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_2, \color{blue}{\lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_2, \lambda_2 \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_2\right)}\right) \cdot R \]
      9. *-lowering-*.f6470.5

        \[\leadsto \mathsf{hypot}\left(\phi_2, \lambda_2 \cdot \cos \color{blue}{\left(0.5 \cdot \phi_2\right)}\right) \cdot R \]
    8. Simplified70.5%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_2, \lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)} \cdot R \]
  3. Recombined 2 regimes into one program.
  4. Final simplification73.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 0.042:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \lambda_2 \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 81.5% accurate, 1.7× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -5.2 \cdot 10^{+117}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\ \mathbf{elif}\;\phi_1 \leq -1.75 \cdot 10^{-37}:\\ \;\;\;\;R \cdot \sqrt{\mathsf{fma}\left(\lambda_1 - \lambda_2, \left(\lambda_1 - \lambda_2\right) \cdot \left(0.5 + 0.5 \cdot \cos \left(\phi_2 + \phi_1\right)\right), \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \lambda_1 - \lambda_2\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi1 -5.2e+117)
   (* R (hypot phi1 (- lambda1 lambda2)))
   (if (<= phi1 -1.75e-37)
     (*
      R
      (sqrt
       (fma
        (- lambda1 lambda2)
        (* (- lambda1 lambda2) (+ 0.5 (* 0.5 (cos (+ phi2 phi1)))))
        (* (- phi1 phi2) (- phi1 phi2)))))
     (* R (hypot phi2 (- lambda1 lambda2))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -5.2e+117) {
		tmp = R * hypot(phi1, (lambda1 - lambda2));
	} else if (phi1 <= -1.75e-37) {
		tmp = R * sqrt(fma((lambda1 - lambda2), ((lambda1 - lambda2) * (0.5 + (0.5 * cos((phi2 + phi1))))), ((phi1 - phi2) * (phi1 - phi2))));
	} else {
		tmp = R * hypot(phi2, (lambda1 - lambda2));
	}
	return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -5.2e+117)
		tmp = Float64(R * hypot(phi1, Float64(lambda1 - lambda2)));
	elseif (phi1 <= -1.75e-37)
		tmp = Float64(R * sqrt(fma(Float64(lambda1 - lambda2), Float64(Float64(lambda1 - lambda2) * Float64(0.5 + Float64(0.5 * cos(Float64(phi2 + phi1))))), Float64(Float64(phi1 - phi2) * Float64(phi1 - phi2)))));
	else
		tmp = Float64(R * hypot(phi2, Float64(lambda1 - lambda2)));
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -5.2e+117], N[(R * N[Sqrt[phi1 ^ 2 + N[(lambda1 - lambda2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, -1.75e-37], N[(R * N[Sqrt[N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(0.5 + N[(0.5 * N[Cos[N[(phi2 + phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(phi1 - phi2), $MachinePrecision] * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[phi2 ^ 2 + N[(lambda1 - lambda2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -5.2 \cdot 10^{+117}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\

\mathbf{elif}\;\phi_1 \leq -1.75 \cdot 10^{-37}:\\
\;\;\;\;R \cdot \sqrt{\mathsf{fma}\left(\lambda_1 - \lambda_2, \left(\lambda_1 - \lambda_2\right) \cdot \left(0.5 + 0.5 \cdot \cos \left(\phi_2 + \phi_1\right)\right), \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \lambda_1 - \lambda_2\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi1 < -5.1999999999999999e117

    1. Initial program 35.3%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi2 around 0

      \[\leadsto \color{blue}{R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
      3. +-commutativeN/A

        \[\leadsto \sqrt{\color{blue}{{\phi_1}^{2} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}}} \cdot R \]
      4. unpow2N/A

        \[\leadsto \sqrt{\color{blue}{\phi_1 \cdot \phi_1} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      5. unpow2N/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      6. unpow2N/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      7. unswap-sqrN/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      8. accelerator-lowering-hypot.f64N/A

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      11. --lowering--.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot R \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      13. *-lowering-*.f6490.4

        \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(0.5 \cdot \phi_1\right)}\right) \cdot R \]
    5. Simplified90.4%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot R} \]
    6. Taylor expanded in phi1 around 0

      \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_1 - \lambda_2}\right) \cdot R \]
    7. Step-by-step derivation
      1. --lowering--.f6488.2

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_1 - \lambda_2}\right) \cdot R \]
    8. Simplified88.2%

      \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_1 - \lambda_2}\right) \cdot R \]

    if -5.1999999999999999e117 < phi1 < -1.7500000000000001e-37

    1. Initial program 65.9%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \cdot R} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \cdot R} \]
    4. Applied egg-rr65.9%

      \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(\lambda_1 - \lambda_2, \left(\lambda_1 - \lambda_2\right) \cdot \left(0.5 + 0.5 \cdot \cos \left(\phi_1 + \phi_2\right)\right), \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\right)} \cdot R} \]

    if -1.7500000000000001e-37 < phi1

    1. Initial program 62.0%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \color{blue}{R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}}} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}} \cdot R} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}} \cdot R} \]
      3. +-commutativeN/A

        \[\leadsto \sqrt{\color{blue}{{\phi_2}^{2} + {\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}}} \cdot R \]
      4. unpow2N/A

        \[\leadsto \sqrt{\color{blue}{\phi_2 \cdot \phi_2} + {\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      5. unpow2N/A

        \[\leadsto \sqrt{\phi_2 \cdot \phi_2 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      6. unpow2N/A

        \[\leadsto \sqrt{\phi_2 \cdot \phi_2 + \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      7. unswap-sqrN/A

        \[\leadsto \sqrt{\phi_2 \cdot \phi_2 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      8. accelerator-lowering-hypot.f64N/A

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_2, \cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_2, \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_2, \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_2\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_2, \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_2\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      12. --lowering--.f6482.3

        \[\leadsto \mathsf{hypot}\left(\phi_2, \cos \left(0.5 \cdot \phi_2\right) \cdot \color{blue}{\left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
    5. Simplified82.3%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_2, \cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
    6. Taylor expanded in phi2 around 0

      \[\leadsto \mathsf{hypot}\left(\phi_2, \color{blue}{\lambda_1 - \lambda_2}\right) \cdot R \]
    7. Step-by-step derivation
      1. --lowering--.f6474.4

        \[\leadsto \mathsf{hypot}\left(\phi_2, \color{blue}{\lambda_1 - \lambda_2}\right) \cdot R \]
    8. Simplified74.4%

      \[\leadsto \mathsf{hypot}\left(\phi_2, \color{blue}{\lambda_1 - \lambda_2}\right) \cdot R \]
  3. Recombined 3 regimes into one program.
  4. Final simplification75.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -5.2 \cdot 10^{+117}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\ \mathbf{elif}\;\phi_1 \leq -1.75 \cdot 10^{-37}:\\ \;\;\;\;R \cdot \sqrt{\mathsf{fma}\left(\lambda_1 - \lambda_2, \left(\lambda_1 - \lambda_2\right) \cdot \left(0.5 + 0.5 \cdot \cos \left(\phi_2 + \phi_1\right)\right), \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \lambda_1 - \lambda_2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 80.6% accurate, 1.8× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 0.045:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\ \mathbf{elif}\;\phi_2 \leq 10^{+103}:\\ \;\;\;\;R \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(0.5, \cos \phi_2, 0.5\right), \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_2 \cdot \phi_2\right)}\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi2 0.045)
   (* R (hypot phi1 (- lambda1 lambda2)))
   (if (<= phi2 1e+103)
     (*
      R
      (sqrt
       (fma
        (fma 0.5 (cos phi2) 0.5)
        (* (- lambda1 lambda2) (- lambda1 lambda2))
        (* phi2 phi2))))
     (* R (- phi2 phi1)))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 0.045) {
		tmp = R * hypot(phi1, (lambda1 - lambda2));
	} else if (phi2 <= 1e+103) {
		tmp = R * sqrt(fma(fma(0.5, cos(phi2), 0.5), ((lambda1 - lambda2) * (lambda1 - lambda2)), (phi2 * phi2)));
	} else {
		tmp = R * (phi2 - phi1);
	}
	return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 0.045)
		tmp = Float64(R * hypot(phi1, Float64(lambda1 - lambda2)));
	elseif (phi2 <= 1e+103)
		tmp = Float64(R * sqrt(fma(fma(0.5, cos(phi2), 0.5), Float64(Float64(lambda1 - lambda2) * Float64(lambda1 - lambda2)), Float64(phi2 * phi2))));
	else
		tmp = Float64(R * Float64(phi2 - phi1));
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 0.045], N[(R * N[Sqrt[phi1 ^ 2 + N[(lambda1 - lambda2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 1e+103], N[(R * N[Sqrt[N[(N[(0.5 * N[Cos[phi2], $MachinePrecision] + 0.5), $MachinePrecision] * N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] + N[(phi2 * phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 0.045:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\

\mathbf{elif}\;\phi_2 \leq 10^{+103}:\\
\;\;\;\;R \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(0.5, \cos \phi_2, 0.5\right), \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_2 \cdot \phi_2\right)}\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < 0.044999999999999998

    1. Initial program 60.8%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi2 around 0

      \[\leadsto \color{blue}{R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
      3. +-commutativeN/A

        \[\leadsto \sqrt{\color{blue}{{\phi_1}^{2} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}}} \cdot R \]
      4. unpow2N/A

        \[\leadsto \sqrt{\color{blue}{\phi_1 \cdot \phi_1} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      5. unpow2N/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      6. unpow2N/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      7. unswap-sqrN/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      8. accelerator-lowering-hypot.f64N/A

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      11. --lowering--.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot R \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      13. *-lowering-*.f6480.6

        \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(0.5 \cdot \phi_1\right)}\right) \cdot R \]
    5. Simplified80.6%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot R} \]
    6. Taylor expanded in phi1 around 0

      \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_1 - \lambda_2}\right) \cdot R \]
    7. Step-by-step derivation
      1. --lowering--.f6474.4

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_1 - \lambda_2}\right) \cdot R \]
    8. Simplified74.4%

      \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_1 - \lambda_2}\right) \cdot R \]

    if 0.044999999999999998 < phi2 < 1e103

    1. Initial program 68.6%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. flip-+N/A

        \[\leadsto R \cdot \sqrt{\color{blue}{\frac{\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right) \cdot \left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right) - \left(\left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\right) \cdot \left(\left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\right)}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) - \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}}} \]
      2. clear-numN/A

        \[\leadsto R \cdot \sqrt{\color{blue}{\frac{1}{\frac{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) - \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}{\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right) \cdot \left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right) - \left(\left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\right) \cdot \left(\left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\right)}}}} \]
      3. sqrt-divN/A

        \[\leadsto R \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{\frac{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) - \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}{\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right) \cdot \left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right) - \left(\left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\right) \cdot \left(\left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\right)}}}} \]
    4. Applied egg-rr68.6%

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

      \[\leadsto \color{blue}{R \cdot \sqrt{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \phi_2\right) \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}}} \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{R \cdot \sqrt{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \phi_2\right) \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}}} \]
      2. sqrt-lowering-sqrt.f64N/A

        \[\leadsto R \cdot \color{blue}{\sqrt{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \phi_2\right) \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}}} \]
      3. accelerator-lowering-fma.f64N/A

        \[\leadsto R \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \phi_2, {\left(\lambda_1 - \lambda_2\right)}^{2}, {\phi_2}^{2}\right)}} \]
      4. +-commutativeN/A

        \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\color{blue}{\frac{1}{2} \cdot \cos \phi_2 + \frac{1}{2}}, {\left(\lambda_1 - \lambda_2\right)}^{2}, {\phi_2}^{2}\right)} \]
      5. accelerator-lowering-fma.f64N/A

        \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\frac{1}{2}, \cos \phi_2, \frac{1}{2}\right)}, {\left(\lambda_1 - \lambda_2\right)}^{2}, {\phi_2}^{2}\right)} \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2}, \color{blue}{\cos \phi_2}, \frac{1}{2}\right), {\left(\lambda_1 - \lambda_2\right)}^{2}, {\phi_2}^{2}\right)} \]
      7. unpow2N/A

        \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2}, \cos \phi_2, \frac{1}{2}\right), \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)}, {\phi_2}^{2}\right)} \]
      8. *-lowering-*.f64N/A

        \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2}, \cos \phi_2, \frac{1}{2}\right), \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)}, {\phi_2}^{2}\right)} \]
      9. --lowering--.f64N/A

        \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2}, \cos \phi_2, \frac{1}{2}\right), \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot \left(\lambda_1 - \lambda_2\right), {\phi_2}^{2}\right)} \]
      10. --lowering--.f64N/A

        \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2}, \cos \phi_2, \frac{1}{2}\right), \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\lambda_1 - \lambda_2\right)}, {\phi_2}^{2}\right)} \]
      11. unpow2N/A

        \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2}, \cos \phi_2, \frac{1}{2}\right), \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \color{blue}{\phi_2 \cdot \phi_2}\right)} \]
      12. *-lowering-*.f6459.6

        \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(0.5, \cos \phi_2, 0.5\right), \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \color{blue}{\phi_2 \cdot \phi_2}\right)} \]
    7. Simplified59.6%

      \[\leadsto \color{blue}{R \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(0.5, \cos \phi_2, 0.5\right), \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_2 \cdot \phi_2\right)}} \]

    if 1e103 < phi2

    1. Initial program 42.3%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi1 around -inf

      \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
      2. neg-lowering-neg.f64N/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
      4. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \left(R + \color{blue}{\left(\mathsf{neg}\left(\frac{R \cdot \phi_2}{\phi_1}\right)\right)}\right)\right) \]
      5. unsub-negN/A

        \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \color{blue}{\left(R - \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
      6. --lowering--.f64N/A

        \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \color{blue}{\left(R - \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \left(R - \color{blue}{\frac{R \cdot \phi_2}{\phi_1}}\right)\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \left(R - \frac{\color{blue}{\phi_2 \cdot R}}{\phi_1}\right)\right) \]
      9. *-lowering-*.f6474.1

        \[\leadsto -\phi_1 \cdot \left(R - \frac{\color{blue}{\phi_2 \cdot R}}{\phi_1}\right) \]
    5. Simplified74.1%

      \[\leadsto \color{blue}{-\phi_1 \cdot \left(R - \frac{\phi_2 \cdot R}{\phi_1}\right)} \]
    6. Taylor expanded in phi1 around 0

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right) - -1 \cdot \left(R \cdot \phi_2\right)} \]
    7. Step-by-step derivation
      1. cancel-sign-sub-invN/A

        \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right) + \left(\mathsf{neg}\left(-1\right)\right) \cdot \left(R \cdot \phi_2\right)} \]
      2. metadata-evalN/A

        \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{1} \cdot \left(R \cdot \phi_2\right) \]
      3. *-lft-identityN/A

        \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{R \cdot \phi_2} \]
      4. +-commutativeN/A

        \[\leadsto \color{blue}{R \cdot \phi_2 + -1 \cdot \left(R \cdot \phi_1\right)} \]
      5. mul-1-negN/A

        \[\leadsto R \cdot \phi_2 + \color{blue}{\left(\mathsf{neg}\left(R \cdot \phi_1\right)\right)} \]
      6. sub-negN/A

        \[\leadsto \color{blue}{R \cdot \phi_2 - R \cdot \phi_1} \]
      7. distribute-lft-out--N/A

        \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
      8. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
      9. --lowering--.f6484.1

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 - \phi_1\right)} \]
    8. Simplified84.1%

      \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification75.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 0.045:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\ \mathbf{elif}\;\phi_2 \leq 10^{+103}:\\ \;\;\;\;R \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(0.5, \cos \phi_2, 0.5\right), \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_2 \cdot \phi_2\right)}\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 79.6% accurate, 2.4× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.2 \cdot 10^{+44}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi2 1.2e+44)
   (* R (hypot phi1 (- lambda1 lambda2)))
   (* R (- phi2 phi1))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 1.2e+44) {
		tmp = R * hypot(phi1, (lambda1 - lambda2));
	} else {
		tmp = R * (phi2 - phi1);
	}
	return tmp;
}
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 1.2e+44) {
		tmp = R * Math.hypot(phi1, (lambda1 - lambda2));
	} else {
		tmp = R * (phi2 - phi1);
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 1.2e+44:
		tmp = R * math.hypot(phi1, (lambda1 - lambda2))
	else:
		tmp = R * (phi2 - phi1)
	return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 1.2e+44)
		tmp = Float64(R * hypot(phi1, Float64(lambda1 - lambda2)));
	else
		tmp = Float64(R * Float64(phi2 - phi1));
	end
	return tmp
end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi2 <= 1.2e+44)
		tmp = R * hypot(phi1, (lambda1 - lambda2));
	else
		tmp = R * (phi2 - phi1);
	end
	tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 1.2e+44], N[(R * N[Sqrt[phi1 ^ 2 + N[(lambda1 - lambda2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 1.2 \cdot 10^{+44}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < 1.20000000000000007e44

    1. Initial program 61.2%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi2 around 0

      \[\leadsto \color{blue}{R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
      3. +-commutativeN/A

        \[\leadsto \sqrt{\color{blue}{{\phi_1}^{2} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}}} \cdot R \]
      4. unpow2N/A

        \[\leadsto \sqrt{\color{blue}{\phi_1 \cdot \phi_1} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      5. unpow2N/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      6. unpow2N/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      7. unswap-sqrN/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      8. accelerator-lowering-hypot.f64N/A

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      11. --lowering--.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot R \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      13. *-lowering-*.f6481.1

        \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(0.5 \cdot \phi_1\right)}\right) \cdot R \]
    5. Simplified81.1%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot R} \]
    6. Taylor expanded in phi1 around 0

      \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_1 - \lambda_2}\right) \cdot R \]
    7. Step-by-step derivation
      1. --lowering--.f6475.0

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_1 - \lambda_2}\right) \cdot R \]
    8. Simplified75.0%

      \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_1 - \lambda_2}\right) \cdot R \]

    if 1.20000000000000007e44 < phi2

    1. Initial program 46.0%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi1 around -inf

      \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
      2. neg-lowering-neg.f64N/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
      4. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \left(R + \color{blue}{\left(\mathsf{neg}\left(\frac{R \cdot \phi_2}{\phi_1}\right)\right)}\right)\right) \]
      5. unsub-negN/A

        \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \color{blue}{\left(R - \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
      6. --lowering--.f64N/A

        \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \color{blue}{\left(R - \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \left(R - \color{blue}{\frac{R \cdot \phi_2}{\phi_1}}\right)\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \left(R - \frac{\color{blue}{\phi_2 \cdot R}}{\phi_1}\right)\right) \]
      9. *-lowering-*.f6470.9

        \[\leadsto -\phi_1 \cdot \left(R - \frac{\color{blue}{\phi_2 \cdot R}}{\phi_1}\right) \]
    5. Simplified70.9%

      \[\leadsto \color{blue}{-\phi_1 \cdot \left(R - \frac{\phi_2 \cdot R}{\phi_1}\right)} \]
    6. Taylor expanded in phi1 around 0

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right) - -1 \cdot \left(R \cdot \phi_2\right)} \]
    7. Step-by-step derivation
      1. cancel-sign-sub-invN/A

        \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right) + \left(\mathsf{neg}\left(-1\right)\right) \cdot \left(R \cdot \phi_2\right)} \]
      2. metadata-evalN/A

        \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{1} \cdot \left(R \cdot \phi_2\right) \]
      3. *-lft-identityN/A

        \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{R \cdot \phi_2} \]
      4. +-commutativeN/A

        \[\leadsto \color{blue}{R \cdot \phi_2 + -1 \cdot \left(R \cdot \phi_1\right)} \]
      5. mul-1-negN/A

        \[\leadsto R \cdot \phi_2 + \color{blue}{\left(\mathsf{neg}\left(R \cdot \phi_1\right)\right)} \]
      6. sub-negN/A

        \[\leadsto \color{blue}{R \cdot \phi_2 - R \cdot \phi_1} \]
      7. distribute-lft-out--N/A

        \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
      8. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
      9. --lowering--.f6479.1

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 - \phi_1\right)} \]
    8. Simplified79.1%

      \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification75.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.2 \cdot 10^{+44}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 63.4% accurate, 4.2× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -8.5 \cdot 10^{+22}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \frac{1}{\sqrt{\frac{1}{\mathsf{fma}\left(1, \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_2 \cdot \phi_2\right)}}}\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi1 -8.5e+22)
   (* R (- phi2 phi1))
   (*
    R
    (/
     1.0
     (sqrt
      (/
       1.0
       (fma
        1.0
        (* (- lambda1 lambda2) (- lambda1 lambda2))
        (* phi2 phi2))))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -8.5e+22) {
		tmp = R * (phi2 - phi1);
	} else {
		tmp = R * (1.0 / sqrt((1.0 / fma(1.0, ((lambda1 - lambda2) * (lambda1 - lambda2)), (phi2 * phi2)))));
	}
	return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -8.5e+22)
		tmp = Float64(R * Float64(phi2 - phi1));
	else
		tmp = Float64(R * Float64(1.0 / sqrt(Float64(1.0 / fma(1.0, Float64(Float64(lambda1 - lambda2) * Float64(lambda1 - lambda2)), Float64(phi2 * phi2))))));
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -8.5e+22], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], N[(R * N[(1.0 / N[Sqrt[N[(1.0 / N[(1.0 * N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] + N[(phi2 * phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -8.5 \cdot 10^{+22}:\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \frac{1}{\sqrt{\frac{1}{\mathsf{fma}\left(1, \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_2 \cdot \phi_2\right)}}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi1 < -8.49999999999999979e22

    1. Initial program 46.4%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi1 around -inf

      \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
      2. neg-lowering-neg.f64N/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
      4. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \left(R + \color{blue}{\left(\mathsf{neg}\left(\frac{R \cdot \phi_2}{\phi_1}\right)\right)}\right)\right) \]
      5. unsub-negN/A

        \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \color{blue}{\left(R - \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
      6. --lowering--.f64N/A

        \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \color{blue}{\left(R - \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \left(R - \color{blue}{\frac{R \cdot \phi_2}{\phi_1}}\right)\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \left(R - \frac{\color{blue}{\phi_2 \cdot R}}{\phi_1}\right)\right) \]
      9. *-lowering-*.f6480.2

        \[\leadsto -\phi_1 \cdot \left(R - \frac{\color{blue}{\phi_2 \cdot R}}{\phi_1}\right) \]
    5. Simplified80.2%

      \[\leadsto \color{blue}{-\phi_1 \cdot \left(R - \frac{\phi_2 \cdot R}{\phi_1}\right)} \]
    6. Taylor expanded in phi1 around 0

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right) - -1 \cdot \left(R \cdot \phi_2\right)} \]
    7. Step-by-step derivation
      1. cancel-sign-sub-invN/A

        \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right) + \left(\mathsf{neg}\left(-1\right)\right) \cdot \left(R \cdot \phi_2\right)} \]
      2. metadata-evalN/A

        \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{1} \cdot \left(R \cdot \phi_2\right) \]
      3. *-lft-identityN/A

        \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{R \cdot \phi_2} \]
      4. +-commutativeN/A

        \[\leadsto \color{blue}{R \cdot \phi_2 + -1 \cdot \left(R \cdot \phi_1\right)} \]
      5. mul-1-negN/A

        \[\leadsto R \cdot \phi_2 + \color{blue}{\left(\mathsf{neg}\left(R \cdot \phi_1\right)\right)} \]
      6. sub-negN/A

        \[\leadsto \color{blue}{R \cdot \phi_2 - R \cdot \phi_1} \]
      7. distribute-lft-out--N/A

        \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
      8. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
      9. --lowering--.f6480.2

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 - \phi_1\right)} \]
    8. Simplified80.2%

      \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]

    if -8.49999999999999979e22 < phi1

    1. Initial program 61.6%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. flip-+N/A

        \[\leadsto R \cdot \sqrt{\color{blue}{\frac{\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right) \cdot \left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right) - \left(\left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\right) \cdot \left(\left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\right)}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) - \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}}} \]
      2. clear-numN/A

        \[\leadsto R \cdot \sqrt{\color{blue}{\frac{1}{\frac{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) - \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}{\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right) \cdot \left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right) - \left(\left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\right) \cdot \left(\left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\right)}}}} \]
      3. sqrt-divN/A

        \[\leadsto R \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{\frac{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) - \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}{\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right) \cdot \left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right) - \left(\left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\right) \cdot \left(\left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\right)}}}} \]
    4. Applied egg-rr61.5%

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

      \[\leadsto R \cdot \frac{1}{\color{blue}{\sqrt{\frac{1}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \phi_2\right) \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}}}}} \]
    6. Step-by-step derivation
      1. sqrt-lowering-sqrt.f64N/A

        \[\leadsto R \cdot \frac{1}{\color{blue}{\sqrt{\frac{1}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \phi_2\right) \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}}}}} \]
      2. /-lowering-/.f64N/A

        \[\leadsto R \cdot \frac{1}{\sqrt{\color{blue}{\frac{1}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \phi_2\right) \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}}}}} \]
      3. accelerator-lowering-fma.f64N/A

        \[\leadsto R \cdot \frac{1}{\sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \phi_2, {\left(\lambda_1 - \lambda_2\right)}^{2}, {\phi_2}^{2}\right)}}}} \]
      4. +-commutativeN/A

        \[\leadsto R \cdot \frac{1}{\sqrt{\frac{1}{\mathsf{fma}\left(\color{blue}{\frac{1}{2} \cdot \cos \phi_2 + \frac{1}{2}}, {\left(\lambda_1 - \lambda_2\right)}^{2}, {\phi_2}^{2}\right)}}} \]
      5. accelerator-lowering-fma.f64N/A

        \[\leadsto R \cdot \frac{1}{\sqrt{\frac{1}{\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\frac{1}{2}, \cos \phi_2, \frac{1}{2}\right)}, {\left(\lambda_1 - \lambda_2\right)}^{2}, {\phi_2}^{2}\right)}}} \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto R \cdot \frac{1}{\sqrt{\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2}, \color{blue}{\cos \phi_2}, \frac{1}{2}\right), {\left(\lambda_1 - \lambda_2\right)}^{2}, {\phi_2}^{2}\right)}}} \]
      7. unpow2N/A

        \[\leadsto R \cdot \frac{1}{\sqrt{\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2}, \cos \phi_2, \frac{1}{2}\right), \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)}, {\phi_2}^{2}\right)}}} \]
      8. *-lowering-*.f64N/A

        \[\leadsto R \cdot \frac{1}{\sqrt{\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2}, \cos \phi_2, \frac{1}{2}\right), \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)}, {\phi_2}^{2}\right)}}} \]
      9. --lowering--.f64N/A

        \[\leadsto R \cdot \frac{1}{\sqrt{\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2}, \cos \phi_2, \frac{1}{2}\right), \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot \left(\lambda_1 - \lambda_2\right), {\phi_2}^{2}\right)}}} \]
      10. --lowering--.f64N/A

        \[\leadsto R \cdot \frac{1}{\sqrt{\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2}, \cos \phi_2, \frac{1}{2}\right), \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\lambda_1 - \lambda_2\right)}, {\phi_2}^{2}\right)}}} \]
      11. unpow2N/A

        \[\leadsto R \cdot \frac{1}{\sqrt{\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2}, \cos \phi_2, \frac{1}{2}\right), \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \color{blue}{\phi_2 \cdot \phi_2}\right)}}} \]
      12. *-lowering-*.f6454.6

        \[\leadsto R \cdot \frac{1}{\sqrt{\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(0.5, \cos \phi_2, 0.5\right), \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \color{blue}{\phi_2 \cdot \phi_2}\right)}}} \]
    7. Simplified54.6%

      \[\leadsto R \cdot \frac{1}{\color{blue}{\sqrt{\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(0.5, \cos \phi_2, 0.5\right), \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_2 \cdot \phi_2\right)}}}} \]
    8. Taylor expanded in phi2 around 0

      \[\leadsto R \cdot \frac{1}{\sqrt{\frac{1}{\mathsf{fma}\left(\color{blue}{1}, \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_2 \cdot \phi_2\right)}}} \]
    9. Step-by-step derivation
      1. Simplified52.9%

        \[\leadsto R \cdot \frac{1}{\sqrt{\frac{1}{\mathsf{fma}\left(\color{blue}{1}, \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_2 \cdot \phi_2\right)}}} \]
    10. Recombined 2 regimes into one program.
    11. Add Preprocessing

    Alternative 8: 48.3% accurate, 15.5× speedup?

    \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -35000:\\ \;\;\;\;-\phi_1 \cdot R\\ \mathbf{elif}\;\phi_1 \leq 4.5 \cdot 10^{-281}:\\ \;\;\;\;\lambda_2 \cdot R\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot R\\ \end{array} \end{array} \]
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (<= phi1 -35000.0)
       (- (* phi1 R))
       (if (<= phi1 4.5e-281) (* lambda2 R) (* phi2 R))))
    assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi1 <= -35000.0) {
    		tmp = -(phi1 * R);
    	} else if (phi1 <= 4.5e-281) {
    		tmp = lambda2 * R;
    	} else {
    		tmp = phi2 * R;
    	}
    	return tmp;
    }
    
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    real(8) function code(r, lambda1, lambda2, phi1, phi2)
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: tmp
        if (phi1 <= (-35000.0d0)) then
            tmp = -(phi1 * r)
        else if (phi1 <= 4.5d-281) then
            tmp = lambda2 * r
        else
            tmp = phi2 * r
        end if
        code = tmp
    end function
    
    assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi1 <= -35000.0) {
    		tmp = -(phi1 * R);
    	} else if (phi1 <= 4.5e-281) {
    		tmp = lambda2 * R;
    	} else {
    		tmp = phi2 * R;
    	}
    	return tmp;
    }
    
    [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
    def code(R, lambda1, lambda2, phi1, phi2):
    	tmp = 0
    	if phi1 <= -35000.0:
    		tmp = -(phi1 * R)
    	elif phi1 <= 4.5e-281:
    		tmp = lambda2 * R
    	else:
    		tmp = phi2 * R
    	return tmp
    
    R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (phi1 <= -35000.0)
    		tmp = Float64(-Float64(phi1 * R));
    	elseif (phi1 <= 4.5e-281)
    		tmp = Float64(lambda2 * R);
    	else
    		tmp = Float64(phi2 * R);
    	end
    	return tmp
    end
    
    R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0;
    	if (phi1 <= -35000.0)
    		tmp = -(phi1 * R);
    	elseif (phi1 <= 4.5e-281)
    		tmp = lambda2 * R;
    	else
    		tmp = phi2 * R;
    	end
    	tmp_2 = tmp;
    end
    
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -35000.0], (-N[(phi1 * R), $MachinePrecision]), If[LessEqual[phi1, 4.5e-281], N[(lambda2 * R), $MachinePrecision], N[(phi2 * R), $MachinePrecision]]]
    
    \begin{array}{l}
    [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
    \\
    \begin{array}{l}
    \mathbf{if}\;\phi_1 \leq -35000:\\
    \;\;\;\;-\phi_1 \cdot R\\
    
    \mathbf{elif}\;\phi_1 \leq 4.5 \cdot 10^{-281}:\\
    \;\;\;\;\lambda_2 \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;\phi_2 \cdot R\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if phi1 < -35000

      1. Initial program 47.7%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Add Preprocessing
      3. Taylor expanded in phi1 around -inf

        \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right)} \]
      4. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \color{blue}{\mathsf{neg}\left(R \cdot \phi_1\right)} \]
        2. *-commutativeN/A

          \[\leadsto \mathsf{neg}\left(\color{blue}{\phi_1 \cdot R}\right) \]
        3. distribute-rgt-neg-inN/A

          \[\leadsto \color{blue}{\phi_1 \cdot \left(\mathsf{neg}\left(R\right)\right)} \]
        4. mul-1-negN/A

          \[\leadsto \phi_1 \cdot \color{blue}{\left(-1 \cdot R\right)} \]
        5. *-lowering-*.f64N/A

          \[\leadsto \color{blue}{\phi_1 \cdot \left(-1 \cdot R\right)} \]
        6. mul-1-negN/A

          \[\leadsto \phi_1 \cdot \color{blue}{\left(\mathsf{neg}\left(R\right)\right)} \]
        7. neg-lowering-neg.f6467.2

          \[\leadsto \phi_1 \cdot \color{blue}{\left(-R\right)} \]
      5. Simplified67.2%

        \[\leadsto \color{blue}{\phi_1 \cdot \left(-R\right)} \]

      if -35000 < phi1 < 4.49999999999999993e-281

      1. Initial program 59.2%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Add Preprocessing
      3. Taylor expanded in phi2 around 0

        \[\leadsto \color{blue}{R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
        2. *-lowering-*.f64N/A

          \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
        3. +-commutativeN/A

          \[\leadsto \sqrt{\color{blue}{{\phi_1}^{2} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}}} \cdot R \]
        4. unpow2N/A

          \[\leadsto \sqrt{\color{blue}{\phi_1 \cdot \phi_1} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
        5. unpow2N/A

          \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
        6. unpow2N/A

          \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
        7. unswap-sqrN/A

          \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
        8. accelerator-lowering-hypot.f64N/A

          \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
        9. *-commutativeN/A

          \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
        10. *-lowering-*.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
        11. --lowering--.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot R \]
        12. cos-lowering-cos.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
        13. *-lowering-*.f6466.6

          \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(0.5 \cdot \phi_1\right)}\right) \cdot R \]
      5. Simplified66.6%

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot R} \]
      6. Taylor expanded in lambda2 around inf

        \[\leadsto \color{blue}{R \cdot \left(\lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)} \]
      7. Step-by-step derivation
        1. associate-*r*N/A

          \[\leadsto \color{blue}{\left(R \cdot \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)} \]
        2. *-lowering-*.f64N/A

          \[\leadsto \color{blue}{\left(R \cdot \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)} \]
        3. *-lowering-*.f64N/A

          \[\leadsto \color{blue}{\left(R \cdot \lambda_2\right)} \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right) \]
        4. cos-lowering-cos.f64N/A

          \[\leadsto \left(R \cdot \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)} \]
        5. *-lowering-*.f6417.5

          \[\leadsto \left(R \cdot \lambda_2\right) \cdot \cos \color{blue}{\left(0.5 \cdot \phi_1\right)} \]
      8. Simplified17.5%

        \[\leadsto \color{blue}{\left(R \cdot \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)} \]
      9. Taylor expanded in phi1 around 0

        \[\leadsto \color{blue}{R \cdot \lambda_2} \]
      10. Step-by-step derivation
        1. *-lowering-*.f6417.5

          \[\leadsto \color{blue}{R \cdot \lambda_2} \]
      11. Simplified17.5%

        \[\leadsto \color{blue}{R \cdot \lambda_2} \]

      if 4.49999999999999993e-281 < phi1

      1. Initial program 63.0%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Add Preprocessing
      3. Taylor expanded in phi2 around inf

        \[\leadsto \color{blue}{R \cdot \phi_2} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{\phi_2 \cdot R} \]
        2. *-lowering-*.f6416.9

          \[\leadsto \color{blue}{\phi_2 \cdot R} \]
      5. Simplified16.9%

        \[\leadsto \color{blue}{\phi_2 \cdot R} \]
    3. Recombined 3 regimes into one program.
    4. Final simplification28.5%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -35000:\\ \;\;\;\;-\phi_1 \cdot R\\ \mathbf{elif}\;\phi_1 \leq 4.5 \cdot 10^{-281}:\\ \;\;\;\;\lambda_2 \cdot R\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot R\\ \end{array} \]
    5. Add Preprocessing

    Alternative 9: 60.3% accurate, 18.6× speedup?

    \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 4.4 \cdot 10^{+106}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\lambda_2 \cdot R\\ \end{array} \end{array} \]
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (<= lambda2 4.4e+106) (* R (- phi2 phi1)) (* lambda2 R)))
    assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (lambda2 <= 4.4e+106) {
    		tmp = R * (phi2 - phi1);
    	} else {
    		tmp = lambda2 * R;
    	}
    	return tmp;
    }
    
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    real(8) function code(r, lambda1, lambda2, phi1, phi2)
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: tmp
        if (lambda2 <= 4.4d+106) then
            tmp = r * (phi2 - phi1)
        else
            tmp = lambda2 * r
        end if
        code = tmp
    end function
    
    assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (lambda2 <= 4.4e+106) {
    		tmp = R * (phi2 - phi1);
    	} else {
    		tmp = lambda2 * R;
    	}
    	return tmp;
    }
    
    [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
    def code(R, lambda1, lambda2, phi1, phi2):
    	tmp = 0
    	if lambda2 <= 4.4e+106:
    		tmp = R * (phi2 - phi1)
    	else:
    		tmp = lambda2 * R
    	return tmp
    
    R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (lambda2 <= 4.4e+106)
    		tmp = Float64(R * Float64(phi2 - phi1));
    	else
    		tmp = Float64(lambda2 * R);
    	end
    	return tmp
    end
    
    R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0;
    	if (lambda2 <= 4.4e+106)
    		tmp = R * (phi2 - phi1);
    	else
    		tmp = lambda2 * R;
    	end
    	tmp_2 = tmp;
    end
    
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda2, 4.4e+106], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], N[(lambda2 * R), $MachinePrecision]]
    
    \begin{array}{l}
    [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
    \\
    \begin{array}{l}
    \mathbf{if}\;\lambda_2 \leq 4.4 \cdot 10^{+106}:\\
    \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\lambda_2 \cdot R\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if lambda2 < 4.39999999999999983e106

      1. Initial program 57.5%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Add Preprocessing
      3. Taylor expanded in phi1 around -inf

        \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
      4. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \color{blue}{\mathsf{neg}\left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
        2. neg-lowering-neg.f64N/A

          \[\leadsto \color{blue}{\mathsf{neg}\left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
        3. *-lowering-*.f64N/A

          \[\leadsto \mathsf{neg}\left(\color{blue}{\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
        4. mul-1-negN/A

          \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \left(R + \color{blue}{\left(\mathsf{neg}\left(\frac{R \cdot \phi_2}{\phi_1}\right)\right)}\right)\right) \]
        5. unsub-negN/A

          \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \color{blue}{\left(R - \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
        6. --lowering--.f64N/A

          \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \color{blue}{\left(R - \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
        7. /-lowering-/.f64N/A

          \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \left(R - \color{blue}{\frac{R \cdot \phi_2}{\phi_1}}\right)\right) \]
        8. *-commutativeN/A

          \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \left(R - \frac{\color{blue}{\phi_2 \cdot R}}{\phi_1}\right)\right) \]
        9. *-lowering-*.f6430.5

          \[\leadsto -\phi_1 \cdot \left(R - \frac{\color{blue}{\phi_2 \cdot R}}{\phi_1}\right) \]
      5. Simplified30.5%

        \[\leadsto \color{blue}{-\phi_1 \cdot \left(R - \frac{\phi_2 \cdot R}{\phi_1}\right)} \]
      6. Taylor expanded in phi1 around 0

        \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right) - -1 \cdot \left(R \cdot \phi_2\right)} \]
      7. Step-by-step derivation
        1. cancel-sign-sub-invN/A

          \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right) + \left(\mathsf{neg}\left(-1\right)\right) \cdot \left(R \cdot \phi_2\right)} \]
        2. metadata-evalN/A

          \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{1} \cdot \left(R \cdot \phi_2\right) \]
        3. *-lft-identityN/A

          \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{R \cdot \phi_2} \]
        4. +-commutativeN/A

          \[\leadsto \color{blue}{R \cdot \phi_2 + -1 \cdot \left(R \cdot \phi_1\right)} \]
        5. mul-1-negN/A

          \[\leadsto R \cdot \phi_2 + \color{blue}{\left(\mathsf{neg}\left(R \cdot \phi_1\right)\right)} \]
        6. sub-negN/A

          \[\leadsto \color{blue}{R \cdot \phi_2 - R \cdot \phi_1} \]
        7. distribute-lft-out--N/A

          \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
        8. *-lowering-*.f64N/A

          \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
        9. --lowering--.f6431.4

          \[\leadsto R \cdot \color{blue}{\left(\phi_2 - \phi_1\right)} \]
      8. Simplified31.4%

        \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]

      if 4.39999999999999983e106 < lambda2

      1. Initial program 65.7%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Add Preprocessing
      3. Taylor expanded in phi2 around 0

        \[\leadsto \color{blue}{R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
        2. *-lowering-*.f64N/A

          \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
        3. +-commutativeN/A

          \[\leadsto \sqrt{\color{blue}{{\phi_1}^{2} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}}} \cdot R \]
        4. unpow2N/A

          \[\leadsto \sqrt{\color{blue}{\phi_1 \cdot \phi_1} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
        5. unpow2N/A

          \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
        6. unpow2N/A

          \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
        7. unswap-sqrN/A

          \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
        8. accelerator-lowering-hypot.f64N/A

          \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
        9. *-commutativeN/A

          \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
        10. *-lowering-*.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
        11. --lowering--.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot R \]
        12. cos-lowering-cos.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
        13. *-lowering-*.f6483.4

          \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(0.5 \cdot \phi_1\right)}\right) \cdot R \]
      5. Simplified83.4%

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot R} \]
      6. Taylor expanded in lambda2 around inf

        \[\leadsto \color{blue}{R \cdot \left(\lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)} \]
      7. Step-by-step derivation
        1. associate-*r*N/A

          \[\leadsto \color{blue}{\left(R \cdot \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)} \]
        2. *-lowering-*.f64N/A

          \[\leadsto \color{blue}{\left(R \cdot \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)} \]
        3. *-lowering-*.f64N/A

          \[\leadsto \color{blue}{\left(R \cdot \lambda_2\right)} \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right) \]
        4. cos-lowering-cos.f64N/A

          \[\leadsto \left(R \cdot \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)} \]
        5. *-lowering-*.f6449.9

          \[\leadsto \left(R \cdot \lambda_2\right) \cdot \cos \color{blue}{\left(0.5 \cdot \phi_1\right)} \]
      8. Simplified49.9%

        \[\leadsto \color{blue}{\left(R \cdot \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)} \]
      9. Taylor expanded in phi1 around 0

        \[\leadsto \color{blue}{R \cdot \lambda_2} \]
      10. Step-by-step derivation
        1. *-lowering-*.f6469.3

          \[\leadsto \color{blue}{R \cdot \lambda_2} \]
      11. Simplified69.3%

        \[\leadsto \color{blue}{R \cdot \lambda_2} \]
    3. Recombined 2 regimes into one program.
    4. Final simplification35.7%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 4.4 \cdot 10^{+106}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\lambda_2 \cdot R\\ \end{array} \]
    5. Add Preprocessing

    Alternative 10: 35.9% accurate, 23.2× speedup?

    \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 7.6 \cdot 10^{+43}:\\ \;\;\;\;\lambda_2 \cdot R\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot R\\ \end{array} \end{array} \]
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (<= phi2 7.6e+43) (* lambda2 R) (* phi2 R)))
    assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi2 <= 7.6e+43) {
    		tmp = lambda2 * R;
    	} else {
    		tmp = phi2 * R;
    	}
    	return tmp;
    }
    
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    real(8) function code(r, lambda1, lambda2, phi1, phi2)
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: tmp
        if (phi2 <= 7.6d+43) then
            tmp = lambda2 * r
        else
            tmp = phi2 * r
        end if
        code = tmp
    end function
    
    assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi2 <= 7.6e+43) {
    		tmp = lambda2 * R;
    	} else {
    		tmp = phi2 * R;
    	}
    	return tmp;
    }
    
    [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
    def code(R, lambda1, lambda2, phi1, phi2):
    	tmp = 0
    	if phi2 <= 7.6e+43:
    		tmp = lambda2 * R
    	else:
    		tmp = phi2 * R
    	return tmp
    
    R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (phi2 <= 7.6e+43)
    		tmp = Float64(lambda2 * R);
    	else
    		tmp = Float64(phi2 * R);
    	end
    	return tmp
    end
    
    R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0;
    	if (phi2 <= 7.6e+43)
    		tmp = lambda2 * R;
    	else
    		tmp = phi2 * R;
    	end
    	tmp_2 = tmp;
    end
    
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 7.6e+43], N[(lambda2 * R), $MachinePrecision], N[(phi2 * R), $MachinePrecision]]
    
    \begin{array}{l}
    [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
    \\
    \begin{array}{l}
    \mathbf{if}\;\phi_2 \leq 7.6 \cdot 10^{+43}:\\
    \;\;\;\;\lambda_2 \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;\phi_2 \cdot R\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if phi2 < 7.60000000000000016e43

      1. Initial program 61.2%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Add Preprocessing
      3. Taylor expanded in phi2 around 0

        \[\leadsto \color{blue}{R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
        2. *-lowering-*.f64N/A

          \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
        3. +-commutativeN/A

          \[\leadsto \sqrt{\color{blue}{{\phi_1}^{2} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}}} \cdot R \]
        4. unpow2N/A

          \[\leadsto \sqrt{\color{blue}{\phi_1 \cdot \phi_1} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
        5. unpow2N/A

          \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
        6. unpow2N/A

          \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
        7. unswap-sqrN/A

          \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
        8. accelerator-lowering-hypot.f64N/A

          \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
        9. *-commutativeN/A

          \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
        10. *-lowering-*.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
        11. --lowering--.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot R \]
        12. cos-lowering-cos.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
        13. *-lowering-*.f6481.1

          \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(0.5 \cdot \phi_1\right)}\right) \cdot R \]
      5. Simplified81.1%

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot R} \]
      6. Taylor expanded in lambda2 around inf

        \[\leadsto \color{blue}{R \cdot \left(\lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)} \]
      7. Step-by-step derivation
        1. associate-*r*N/A

          \[\leadsto \color{blue}{\left(R \cdot \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)} \]
        2. *-lowering-*.f64N/A

          \[\leadsto \color{blue}{\left(R \cdot \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)} \]
        3. *-lowering-*.f64N/A

          \[\leadsto \color{blue}{\left(R \cdot \lambda_2\right)} \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right) \]
        4. cos-lowering-cos.f64N/A

          \[\leadsto \left(R \cdot \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)} \]
        5. *-lowering-*.f6415.4

          \[\leadsto \left(R \cdot \lambda_2\right) \cdot \cos \color{blue}{\left(0.5 \cdot \phi_1\right)} \]
      8. Simplified15.4%

        \[\leadsto \color{blue}{\left(R \cdot \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)} \]
      9. Taylor expanded in phi1 around 0

        \[\leadsto \color{blue}{R \cdot \lambda_2} \]
      10. Step-by-step derivation
        1. *-lowering-*.f6415.2

          \[\leadsto \color{blue}{R \cdot \lambda_2} \]
      11. Simplified15.2%

        \[\leadsto \color{blue}{R \cdot \lambda_2} \]

      if 7.60000000000000016e43 < phi2

      1. Initial program 46.0%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Add Preprocessing
      3. Taylor expanded in phi2 around inf

        \[\leadsto \color{blue}{R \cdot \phi_2} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{\phi_2 \cdot R} \]
        2. *-lowering-*.f6467.0

          \[\leadsto \color{blue}{\phi_2 \cdot R} \]
      5. Simplified67.0%

        \[\leadsto \color{blue}{\phi_2 \cdot R} \]
    3. Recombined 2 regimes into one program.
    4. Final simplification24.7%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 7.6 \cdot 10^{+43}:\\ \;\;\;\;\lambda_2 \cdot R\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot R\\ \end{array} \]
    5. Add Preprocessing

    Alternative 11: 13.1% accurate, 46.5× speedup?

    \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \lambda_2 \cdot R \end{array} \]
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    (FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* lambda2 R))
    assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	return lambda2 * R;
    }
    
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    real(8) function code(r, lambda1, lambda2, phi1, phi2)
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        code = lambda2 * r
    end function
    
    assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	return lambda2 * R;
    }
    
    [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
    def code(R, lambda1, lambda2, phi1, phi2):
    	return lambda2 * R
    
    R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
    function code(R, lambda1, lambda2, phi1, phi2)
    	return Float64(lambda2 * R)
    end
    
    R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
    function tmp = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = lambda2 * R;
    end
    
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(lambda2 * R), $MachinePrecision]
    
    \begin{array}{l}
    [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
    \\
    \lambda_2 \cdot R
    \end{array}
    
    Derivation
    1. Initial program 58.4%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi2 around 0

      \[\leadsto \color{blue}{R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}} \cdot R} \]
      3. +-commutativeN/A

        \[\leadsto \sqrt{\color{blue}{{\phi_1}^{2} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}}} \cdot R \]
      4. unpow2N/A

        \[\leadsto \sqrt{\color{blue}{\phi_1 \cdot \phi_1} + {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      5. unpow2N/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2}} \cdot R \]
      6. unpow2N/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      7. unswap-sqrN/A

        \[\leadsto \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \cdot R \]
      8. accelerator-lowering-hypot.f64N/A

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      11. --lowering--.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot R \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
      13. *-lowering-*.f6472.3

        \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(0.5 \cdot \phi_1\right)}\right) \cdot R \]
    5. Simplified72.3%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot R} \]
    6. Taylor expanded in lambda2 around inf

      \[\leadsto \color{blue}{R \cdot \left(\lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)} \]
    7. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \color{blue}{\left(R \cdot \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\left(R \cdot \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)} \]
      3. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\left(R \cdot \lambda_2\right)} \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right) \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \left(R \cdot \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)} \]
      5. *-lowering-*.f6413.1

        \[\leadsto \left(R \cdot \lambda_2\right) \cdot \cos \color{blue}{\left(0.5 \cdot \phi_1\right)} \]
    8. Simplified13.1%

      \[\leadsto \color{blue}{\left(R \cdot \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)} \]
    9. Taylor expanded in phi1 around 0

      \[\leadsto \color{blue}{R \cdot \lambda_2} \]
    10. Step-by-step derivation
      1. *-lowering-*.f6413.7

        \[\leadsto \color{blue}{R \cdot \lambda_2} \]
    11. Simplified13.7%

      \[\leadsto \color{blue}{R \cdot \lambda_2} \]
    12. Final simplification13.7%

      \[\leadsto \lambda_2 \cdot R \]
    13. Add Preprocessing

    Reproduce

    ?
    herbie shell --seed 2024204 
    (FPCore (R lambda1 lambda2 phi1 phi2)
      :name "Equirectangular approximation to distance on a great circle"
      :precision binary64
      (* R (sqrt (+ (* (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0))) (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0)))) (* (- phi1 phi2) (- phi1 phi2))))))