Equirectangular approximation to distance on a great circle

Percentage Accurate: 58.8% → 90.7%
Time: 15.0s
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.7% 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_1 \leq -7.4 \cdot 10^{+15}:\\ \;\;\;\;\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(0.5 \cdot \phi_2\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 (<= phi1 -7.4e+15)
   (* (hypot phi1 (* (- lambda1 lambda2) (cos (* phi1 0.5)))) R)
   (* R (hypot phi2 (* (- lambda1 lambda2) (cos (* 0.5 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 <= -7.4e+15) {
		tmp = hypot(phi1, ((lambda1 - lambda2) * cos((phi1 * 0.5)))) * R;
	} else {
		tmp = R * hypot(phi2, ((lambda1 - lambda2) * cos((0.5 * phi2))));
	}
	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 (phi1 <= -7.4e+15) {
		tmp = Math.hypot(phi1, ((lambda1 - lambda2) * Math.cos((phi1 * 0.5)))) * R;
	} else {
		tmp = R * Math.hypot(phi2, ((lambda1 - lambda2) * Math.cos((0.5 * phi2))));
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -7.4e+15:
		tmp = math.hypot(phi1, ((lambda1 - lambda2) * math.cos((phi1 * 0.5)))) * R
	else:
		tmp = R * math.hypot(phi2, ((lambda1 - lambda2) * math.cos((0.5 * 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 <= -7.4e+15)
		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(0.5 * phi2)))));
	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 <= -7.4e+15)
		tmp = hypot(phi1, ((lambda1 - lambda2) * cos((phi1 * 0.5)))) * R;
	else
		tmp = R * hypot(phi2, ((lambda1 - lambda2) * cos((0.5 * phi2))));
	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, -7.4e+15], 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[(0.5 * phi2), $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_1 \leq -7.4 \cdot 10^{+15}:\\
\;\;\;\;\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(0.5 \cdot \phi_2\right)\right)\\


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

    1. Initial program 46.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-*.f6488.8

        \[\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. Simplified88.8%

      \[\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 -7.4e15 < phi1

    1. Initial program 58.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 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--.f6481.4

        \[\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. Simplified81.4%

      \[\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 simplification82.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -7.4 \cdot 10^{+15}:\\ \;\;\;\;\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(0.5 \cdot \phi_2\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 85.3% 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_1 \leq -6.8 \cdot 10^{+15}:\\ \;\;\;\;\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_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 -6.8e+15)
   (* (hypot phi1 (* (- lambda1 lambda2) (cos (* phi1 0.5)))) R)
   (* 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 <= -6.8e+15) {
		tmp = hypot(phi1, ((lambda1 - lambda2) * cos((phi1 * 0.5)))) * R;
	} else {
		tmp = R * hypot(phi2, (lambda1 - lambda2));
	}
	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 (phi1 <= -6.8e+15) {
		tmp = Math.hypot(phi1, ((lambda1 - lambda2) * Math.cos((phi1 * 0.5)))) * R;
	} else {
		tmp = R * Math.hypot(phi2, (lambda1 - lambda2));
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -6.8e+15:
		tmp = math.hypot(phi1, ((lambda1 - lambda2) * math.cos((phi1 * 0.5)))) * R
	else:
		tmp = R * math.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 <= -6.8e+15)
		tmp = Float64(hypot(phi1, Float64(Float64(lambda1 - lambda2) * cos(Float64(phi1 * 0.5)))) * R);
	else
		tmp = Float64(R * hypot(phi2, Float64(lambda1 - lambda2)));
	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 <= -6.8e+15)
		tmp = hypot(phi1, ((lambda1 - lambda2) * cos((phi1 * 0.5)))) * R;
	else
		tmp = R * hypot(phi2, (lambda1 - lambda2));
	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, -6.8e+15], 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[(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 -6.8 \cdot 10^{+15}:\\
\;\;\;\;\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_1 - \lambda_2\right)\\


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

    1. Initial program 46.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-*.f6488.8

        \[\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. Simplified88.8%

      \[\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 -6.8e15 < phi1

    1. Initial program 58.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 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--.f6481.4

        \[\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. Simplified81.4%

      \[\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.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -6.8 \cdot 10^{+15}:\\ \;\;\;\;\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_1 - \lambda_2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 81.5% 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_1 \leq -2 \cdot 10^{+36}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 \cdot \cos \left(\phi_1 \cdot 0.5\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 -2e+36)
   (* R (hypot phi1 (* lambda1 (cos (* phi1 0.5)))))
   (* 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 <= -2e+36) {
		tmp = R * hypot(phi1, (lambda1 * cos((phi1 * 0.5))));
	} else {
		tmp = R * hypot(phi2, (lambda1 - lambda2));
	}
	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 (phi1 <= -2e+36) {
		tmp = R * Math.hypot(phi1, (lambda1 * Math.cos((phi1 * 0.5))));
	} else {
		tmp = R * Math.hypot(phi2, (lambda1 - lambda2));
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -2e+36:
		tmp = R * math.hypot(phi1, (lambda1 * math.cos((phi1 * 0.5))))
	else:
		tmp = R * math.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 <= -2e+36)
		tmp = Float64(R * hypot(phi1, Float64(lambda1 * cos(Float64(phi1 * 0.5)))));
	else
		tmp = Float64(R * hypot(phi2, Float64(lambda1 - lambda2)));
	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 <= -2e+36)
		tmp = R * hypot(phi1, (lambda1 * cos((phi1 * 0.5))));
	else
		tmp = R * hypot(phi2, (lambda1 - lambda2));
	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, -2e+36], N[(R * N[Sqrt[phi1 ^ 2 + N[(lambda1 * N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2], $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 -2 \cdot 10^{+36}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 \cdot \cos \left(\phi_1 \cdot 0.5\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 2 regimes
  2. if phi1 < -2.00000000000000008e36

    1. Initial program 43.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-*.f6488.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. Simplified88.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 0

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

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

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

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

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

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

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

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

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

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

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

    if -2.00000000000000008e36 < phi1

    1. Initial program 58.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 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--.f6481.6

        \[\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. Simplified81.6%

      \[\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.8

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

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

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

Alternative 4: 63.8% accurate, 2.3× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -0.6:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -1.62 \cdot 10^{-192}:\\ \;\;\;\;R \cdot \left(\lambda_1 \cdot \left(-1 + \frac{\lambda_2}{\lambda_1}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \lambda_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 (<= phi1 -0.6)
   (* R (- phi2 phi1))
   (if (<= phi1 -1.62e-192)
     (* R (* lambda1 (+ -1.0 (/ lambda2 lambda1))))
     (* R (hypot phi2 lambda1)))))
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 <= -0.6) {
		tmp = R * (phi2 - phi1);
	} else if (phi1 <= -1.62e-192) {
		tmp = R * (lambda1 * (-1.0 + (lambda2 / lambda1)));
	} else {
		tmp = R * hypot(phi2, lambda1);
	}
	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 (phi1 <= -0.6) {
		tmp = R * (phi2 - phi1);
	} else if (phi1 <= -1.62e-192) {
		tmp = R * (lambda1 * (-1.0 + (lambda2 / lambda1)));
	} else {
		tmp = R * Math.hypot(phi2, lambda1);
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -0.6:
		tmp = R * (phi2 - phi1)
	elif phi1 <= -1.62e-192:
		tmp = R * (lambda1 * (-1.0 + (lambda2 / lambda1)))
	else:
		tmp = R * math.hypot(phi2, lambda1)
	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 <= -0.6)
		tmp = Float64(R * Float64(phi2 - phi1));
	elseif (phi1 <= -1.62e-192)
		tmp = Float64(R * Float64(lambda1 * Float64(-1.0 + Float64(lambda2 / lambda1))));
	else
		tmp = Float64(R * hypot(phi2, lambda1));
	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 <= -0.6)
		tmp = R * (phi2 - phi1);
	elseif (phi1 <= -1.62e-192)
		tmp = R * (lambda1 * (-1.0 + (lambda2 / lambda1)));
	else
		tmp = R * hypot(phi2, lambda1);
	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, -0.6], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, -1.62e-192], N[(R * N[(lambda1 * N[(-1.0 + N[(lambda2 / lambda1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[phi2 ^ 2 + lambda1 ^ 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 -0.6:\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\

\mathbf{elif}\;\phi_1 \leq -1.62 \cdot 10^{-192}:\\
\;\;\;\;R \cdot \left(\lambda_1 \cdot \left(-1 + \frac{\lambda_2}{\lambda_1}\right)\right)\\

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


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

    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 phi2 around inf

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

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

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

        \[\leadsto \phi_2 \cdot \left(\color{blue}{\left(\mathsf{neg}\left(\frac{R \cdot \phi_1}{\phi_2}\right)\right)} + R\right) \]
      4. associate-/l*N/A

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

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

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

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

        \[\leadsto \phi_2 \cdot \mathsf{fma}\left(R, \color{blue}{\mathsf{neg}\left(\frac{\phi_1}{\phi_2}\right)}, R\right) \]
      9. neg-sub0N/A

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

        \[\leadsto \phi_2 \cdot \mathsf{fma}\left(R, \color{blue}{0 - \frac{\phi_1}{\phi_2}}, R\right) \]
      11. /-lowering-/.f6451.2

        \[\leadsto \phi_2 \cdot \mathsf{fma}\left(R, 0 - \color{blue}{\frac{\phi_1}{\phi_2}}, R\right) \]
    5. Simplified51.2%

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(R, \phi_2, -1 \cdot \left(R \cdot \phi_1\right)\right)} \]
      3. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(R, \phi_2, \color{blue}{\mathsf{neg}\left(R \cdot \phi_1\right)}\right) \]
      4. neg-sub0N/A

        \[\leadsto \mathsf{fma}\left(R, \phi_2, \color{blue}{0 - R \cdot \phi_1}\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{fma}\left(R, \phi_2, \color{blue}{0 - R \cdot \phi_1}\right) \]
      6. *-lowering-*.f6463.2

        \[\leadsto \mathsf{fma}\left(R, \phi_2, 0 - \color{blue}{R \cdot \phi_1}\right) \]
    8. Simplified63.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(R, \phi_2, 0 - R \cdot \phi_1\right)} \]
    9. Taylor expanded in R around 0

      \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
    10. Step-by-step derivation
      1. *-lowering-*.f64N/A

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

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 - \phi_1\right)} \]
    11. Simplified61.3%

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

    if -0.599999999999999978 < phi1 < -1.6199999999999999e-192

    1. Initial program 60.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--.f6497.9

        \[\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. Simplified97.9%

      \[\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--.f6485.2

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

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

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

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

        \[\leadsto \left(\left(-1 \cdot \lambda_1\right) \cdot \color{blue}{\left(-1 \cdot \frac{\lambda_2}{\lambda_1} + 1\right)}\right) \cdot R \]
      3. distribute-lft-inN/A

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

        \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)} \cdot \left(-1 \cdot \frac{\lambda_2}{\lambda_1}\right) + \left(-1 \cdot \lambda_1\right) \cdot 1\right) \cdot R \]
      5. distribute-lft-neg-inN/A

        \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(\lambda_1 \cdot \left(-1 \cdot \frac{\lambda_2}{\lambda_1}\right)\right)\right)} + \left(-1 \cdot \lambda_1\right) \cdot 1\right) \cdot R \]
      6. *-commutativeN/A

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

        \[\leadsto \left(\left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\frac{\lambda_2}{\lambda_1}\right)\right)} \cdot \lambda_1\right)\right) + \left(-1 \cdot \lambda_1\right) \cdot 1\right) \cdot R \]
      8. distribute-lft-neg-outN/A

        \[\leadsto \left(\left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\frac{\lambda_2}{\lambda_1} \cdot \lambda_1\right)\right)}\right)\right) + \left(-1 \cdot \lambda_1\right) \cdot 1\right) \cdot R \]
      9. remove-double-negN/A

        \[\leadsto \left(\color{blue}{\frac{\lambda_2}{\lambda_1} \cdot \lambda_1} + \left(-1 \cdot \lambda_1\right) \cdot 1\right) \cdot R \]
      10. *-rgt-identityN/A

        \[\leadsto \left(\frac{\lambda_2}{\lambda_1} \cdot \lambda_1 + \color{blue}{-1 \cdot \lambda_1}\right) \cdot R \]
      11. distribute-rgt-inN/A

        \[\leadsto \color{blue}{\left(\lambda_1 \cdot \left(\frac{\lambda_2}{\lambda_1} + -1\right)\right)} \cdot R \]
      12. metadata-evalN/A

        \[\leadsto \left(\lambda_1 \cdot \left(\frac{\lambda_2}{\lambda_1} + \color{blue}{\left(\mathsf{neg}\left(1\right)\right)}\right)\right) \cdot R \]
      13. sub-negN/A

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

        \[\leadsto \color{blue}{\left(\lambda_1 \cdot \left(\frac{\lambda_2}{\lambda_1} - 1\right)\right)} \cdot R \]
      15. sub-negN/A

        \[\leadsto \left(\lambda_1 \cdot \color{blue}{\left(\frac{\lambda_2}{\lambda_1} + \left(\mathsf{neg}\left(1\right)\right)\right)}\right) \cdot R \]
      16. metadata-evalN/A

        \[\leadsto \left(\lambda_1 \cdot \left(\frac{\lambda_2}{\lambda_1} + \color{blue}{-1}\right)\right) \cdot R \]
      17. +-commutativeN/A

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

        \[\leadsto \left(\lambda_1 \cdot \color{blue}{\left(-1 + \frac{\lambda_2}{\lambda_1}\right)}\right) \cdot R \]
      19. /-lowering-/.f6421.1

        \[\leadsto \left(\lambda_1 \cdot \left(-1 + \color{blue}{\frac{\lambda_2}{\lambda_1}}\right)\right) \cdot R \]
    11. Simplified21.1%

      \[\leadsto \color{blue}{\left(\lambda_1 \cdot \left(-1 + \frac{\lambda_2}{\lambda_1}\right)\right)} \cdot R \]

    if -1.6199999999999999e-192 < phi1

    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 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--.f6476.0

        \[\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. Simplified76.0%

      \[\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--.f6470.6

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

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

      \[\leadsto \mathsf{hypot}\left(\phi_2, \color{blue}{\lambda_1}\right) \cdot R \]
    10. Step-by-step derivation
      1. Simplified55.7%

        \[\leadsto \mathsf{hypot}\left(\phi_2, \color{blue}{\lambda_1}\right) \cdot R \]
    11. Recombined 3 regimes into one program.
    12. Final simplification50.6%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -0.6:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -1.62 \cdot 10^{-192}:\\ \;\;\;\;R \cdot \left(\lambda_1 \cdot \left(-1 + \frac{\lambda_2}{\lambda_1}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \lambda_1\right)\\ \end{array} \]
    13. Add Preprocessing

    Alternative 5: 80.5% 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_1 \leq -1.02 \cdot 10^{+16}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\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 -1.02e+16)
       (* R (hypot phi1 (- lambda1 lambda2)))
       (* 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 <= -1.02e+16) {
    		tmp = R * hypot(phi1, (lambda1 - lambda2));
    	} else {
    		tmp = R * hypot(phi2, (lambda1 - lambda2));
    	}
    	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 (phi1 <= -1.02e+16) {
    		tmp = R * Math.hypot(phi1, (lambda1 - lambda2));
    	} else {
    		tmp = R * Math.hypot(phi2, (lambda1 - lambda2));
    	}
    	return tmp;
    }
    
    [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
    def code(R, lambda1, lambda2, phi1, phi2):
    	tmp = 0
    	if phi1 <= -1.02e+16:
    		tmp = R * math.hypot(phi1, (lambda1 - lambda2))
    	else:
    		tmp = R * math.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 <= -1.02e+16)
    		tmp = Float64(R * hypot(phi1, Float64(lambda1 - lambda2)));
    	else
    		tmp = Float64(R * hypot(phi2, Float64(lambda1 - lambda2)));
    	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 <= -1.02e+16)
    		tmp = R * hypot(phi1, (lambda1 - lambda2));
    	else
    		tmp = R * hypot(phi2, (lambda1 - lambda2));
    	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, -1.02e+16], N[(R * N[Sqrt[phi1 ^ 2 + N[(lambda1 - lambda2), $MachinePrecision] ^ 2], $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 -1.02 \cdot 10^{+16}:\\
    \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \lambda_1 - \lambda_2\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if phi1 < -1.02e16

      1. Initial program 46.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-*.f6488.8

          \[\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. Simplified88.8%

        \[\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--.f6468.2

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

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

      if -1.02e16 < phi1

      1. Initial program 58.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 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--.f6481.4

          \[\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. Simplified81.4%

        \[\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.5

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

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

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

    Alternative 6: 79.9% 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 2.4 \cdot 10^{+25}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(R, 0 - \phi_1, R \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 (<= phi2 2.4e+25)
       (* R (hypot phi1 (- lambda1 lambda2)))
       (fma R (- 0.0 phi1) (* R 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 (phi2 <= 2.4e+25) {
    		tmp = R * hypot(phi1, (lambda1 - lambda2));
    	} else {
    		tmp = fma(R, (0.0 - phi1), (R * 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 (phi2 <= 2.4e+25)
    		tmp = Float64(R * hypot(phi1, Float64(lambda1 - lambda2)));
    	else
    		tmp = fma(R, Float64(0.0 - phi1), Float64(R * 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[phi2, 2.4e+25], N[(R * N[Sqrt[phi1 ^ 2 + N[(lambda1 - lambda2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[(0.0 - phi1), $MachinePrecision] + N[(R * phi2), $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 2.4 \cdot 10^{+25}:\\
    \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\mathsf{fma}\left(R, 0 - \phi_1, R \cdot \phi_2\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if phi2 < 2.39999999999999996e25

      1. Initial program 56.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. 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-*.f6475.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. Simplified75.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 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--.f6466.9

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

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

      if 2.39999999999999996e25 < phi2

      1. Initial program 54.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. Taylor expanded in phi2 around inf

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

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

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

          \[\leadsto \phi_2 \cdot \left(\color{blue}{\left(\mathsf{neg}\left(\frac{R \cdot \phi_1}{\phi_2}\right)\right)} + R\right) \]
        4. associate-/l*N/A

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

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

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

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

          \[\leadsto \phi_2 \cdot \mathsf{fma}\left(R, \color{blue}{\mathsf{neg}\left(\frac{\phi_1}{\phi_2}\right)}, R\right) \]
        9. neg-sub0N/A

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

          \[\leadsto \phi_2 \cdot \mathsf{fma}\left(R, \color{blue}{0 - \frac{\phi_1}{\phi_2}}, R\right) \]
        11. /-lowering-/.f6469.4

          \[\leadsto \phi_2 \cdot \mathsf{fma}\left(R, 0 - \color{blue}{\frac{\phi_1}{\phi_2}}, R\right) \]
      5. Simplified69.4%

        \[\leadsto \color{blue}{\phi_2 \cdot \mathsf{fma}\left(R, 0 - \frac{\phi_1}{\phi_2}, R\right)} \]
      6. Step-by-step derivation
        1. sub0-negN/A

          \[\leadsto \phi_2 \cdot \mathsf{fma}\left(R, \color{blue}{\mathsf{neg}\left(\frac{\phi_1}{\phi_2}\right)}, R\right) \]
        2. clear-numN/A

          \[\leadsto \phi_2 \cdot \mathsf{fma}\left(R, \mathsf{neg}\left(\color{blue}{\frac{1}{\frac{\phi_2}{\phi_1}}}\right), R\right) \]
        3. distribute-neg-fracN/A

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

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

          \[\leadsto \phi_2 \cdot \mathsf{fma}\left(R, \color{blue}{\frac{-1}{\frac{\phi_2}{\phi_1}}}, R\right) \]
        6. /-lowering-/.f6469.4

          \[\leadsto \phi_2 \cdot \mathsf{fma}\left(R, \frac{-1}{\color{blue}{\frac{\phi_2}{\phi_1}}}, R\right) \]
      7. Applied egg-rr69.4%

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(R, \color{blue}{\mathsf{neg}\left(\phi_1\right)}, R \cdot \phi_2\right) \]
        6. neg-sub0N/A

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

          \[\leadsto \mathsf{fma}\left(R, \color{blue}{0 - \phi_1}, R \cdot \phi_2\right) \]
        8. *-lowering-*.f6471.1

          \[\leadsto \mathsf{fma}\left(R, 0 - \phi_1, \color{blue}{R \cdot \phi_2}\right) \]
      10. Simplified71.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(R, 0 - \phi_1, R \cdot \phi_2\right)} \]
    3. Recombined 2 regimes into one program.
    4. Final simplification67.9%

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

    Alternative 7: 55.2% accurate, 7.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 -0.125:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq 4.7 \cdot 10^{-222}:\\ \;\;\;\;R \cdot \left(\lambda_1 \cdot \left(-1 + \frac{\lambda_2}{\lambda_1}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \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 -0.125)
       (* R (- phi2 phi1))
       (if (<= phi1 4.7e-222)
         (* R (* lambda1 (+ -1.0 (/ lambda2 lambda1))))
         (* R 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 <= -0.125) {
    		tmp = R * (phi2 - phi1);
    	} else if (phi1 <= 4.7e-222) {
    		tmp = R * (lambda1 * (-1.0 + (lambda2 / lambda1)));
    	} else {
    		tmp = R * phi2;
    	}
    	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 <= (-0.125d0)) then
            tmp = r * (phi2 - phi1)
        else if (phi1 <= 4.7d-222) then
            tmp = r * (lambda1 * ((-1.0d0) + (lambda2 / lambda1)))
        else
            tmp = r * phi2
        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 <= -0.125) {
    		tmp = R * (phi2 - phi1);
    	} else if (phi1 <= 4.7e-222) {
    		tmp = R * (lambda1 * (-1.0 + (lambda2 / lambda1)));
    	} else {
    		tmp = R * phi2;
    	}
    	return tmp;
    }
    
    [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
    def code(R, lambda1, lambda2, phi1, phi2):
    	tmp = 0
    	if phi1 <= -0.125:
    		tmp = R * (phi2 - phi1)
    	elif phi1 <= 4.7e-222:
    		tmp = R * (lambda1 * (-1.0 + (lambda2 / lambda1)))
    	else:
    		tmp = R * 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 <= -0.125)
    		tmp = Float64(R * Float64(phi2 - phi1));
    	elseif (phi1 <= 4.7e-222)
    		tmp = Float64(R * Float64(lambda1 * Float64(-1.0 + Float64(lambda2 / lambda1))));
    	else
    		tmp = Float64(R * phi2);
    	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 <= -0.125)
    		tmp = R * (phi2 - phi1);
    	elseif (phi1 <= 4.7e-222)
    		tmp = R * (lambda1 * (-1.0 + (lambda2 / lambda1)));
    	else
    		tmp = R * phi2;
    	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, -0.125], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 4.7e-222], N[(R * N[(lambda1 * N[(-1.0 + N[(lambda2 / lambda1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * phi2), $MachinePrecision]]]
    
    \begin{array}{l}
    [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
    \\
    \begin{array}{l}
    \mathbf{if}\;\phi_1 \leq -0.125:\\
    \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
    
    \mathbf{elif}\;\phi_1 \leq 4.7 \cdot 10^{-222}:\\
    \;\;\;\;R \cdot \left(\lambda_1 \cdot \left(-1 + \frac{\lambda_2}{\lambda_1}\right)\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;R \cdot \phi_2\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if phi1 < -0.125

      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 phi2 around inf

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

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

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

          \[\leadsto \phi_2 \cdot \left(\color{blue}{\left(\mathsf{neg}\left(\frac{R \cdot \phi_1}{\phi_2}\right)\right)} + R\right) \]
        4. associate-/l*N/A

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

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

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

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

          \[\leadsto \phi_2 \cdot \mathsf{fma}\left(R, \color{blue}{\mathsf{neg}\left(\frac{\phi_1}{\phi_2}\right)}, R\right) \]
        9. neg-sub0N/A

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

          \[\leadsto \phi_2 \cdot \mathsf{fma}\left(R, \color{blue}{0 - \frac{\phi_1}{\phi_2}}, R\right) \]
        11. /-lowering-/.f6451.2

          \[\leadsto \phi_2 \cdot \mathsf{fma}\left(R, 0 - \color{blue}{\frac{\phi_1}{\phi_2}}, R\right) \]
      5. Simplified51.2%

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

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

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

          \[\leadsto \color{blue}{\mathsf{fma}\left(R, \phi_2, -1 \cdot \left(R \cdot \phi_1\right)\right)} \]
        3. mul-1-negN/A

          \[\leadsto \mathsf{fma}\left(R, \phi_2, \color{blue}{\mathsf{neg}\left(R \cdot \phi_1\right)}\right) \]
        4. neg-sub0N/A

          \[\leadsto \mathsf{fma}\left(R, \phi_2, \color{blue}{0 - R \cdot \phi_1}\right) \]
        5. --lowering--.f64N/A

          \[\leadsto \mathsf{fma}\left(R, \phi_2, \color{blue}{0 - R \cdot \phi_1}\right) \]
        6. *-lowering-*.f6463.2

          \[\leadsto \mathsf{fma}\left(R, \phi_2, 0 - \color{blue}{R \cdot \phi_1}\right) \]
      8. Simplified63.2%

        \[\leadsto \color{blue}{\mathsf{fma}\left(R, \phi_2, 0 - R \cdot \phi_1\right)} \]
      9. Taylor expanded in R around 0

        \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
      10. Step-by-step derivation
        1. *-lowering-*.f64N/A

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

          \[\leadsto R \cdot \color{blue}{\left(\phi_2 - \phi_1\right)} \]
      11. Simplified61.3%

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

      if -0.125 < phi1 < 4.6999999999999997e-222

      1. Initial program 56.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 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--.f6498.8

          \[\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. Simplified98.8%

        \[\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--.f6486.3

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

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

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

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

          \[\leadsto \left(\left(-1 \cdot \lambda_1\right) \cdot \color{blue}{\left(-1 \cdot \frac{\lambda_2}{\lambda_1} + 1\right)}\right) \cdot R \]
        3. distribute-lft-inN/A

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

          \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)} \cdot \left(-1 \cdot \frac{\lambda_2}{\lambda_1}\right) + \left(-1 \cdot \lambda_1\right) \cdot 1\right) \cdot R \]
        5. distribute-lft-neg-inN/A

          \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(\lambda_1 \cdot \left(-1 \cdot \frac{\lambda_2}{\lambda_1}\right)\right)\right)} + \left(-1 \cdot \lambda_1\right) \cdot 1\right) \cdot R \]
        6. *-commutativeN/A

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

          \[\leadsto \left(\left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\frac{\lambda_2}{\lambda_1}\right)\right)} \cdot \lambda_1\right)\right) + \left(-1 \cdot \lambda_1\right) \cdot 1\right) \cdot R \]
        8. distribute-lft-neg-outN/A

          \[\leadsto \left(\left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\frac{\lambda_2}{\lambda_1} \cdot \lambda_1\right)\right)}\right)\right) + \left(-1 \cdot \lambda_1\right) \cdot 1\right) \cdot R \]
        9. remove-double-negN/A

          \[\leadsto \left(\color{blue}{\frac{\lambda_2}{\lambda_1} \cdot \lambda_1} + \left(-1 \cdot \lambda_1\right) \cdot 1\right) \cdot R \]
        10. *-rgt-identityN/A

          \[\leadsto \left(\frac{\lambda_2}{\lambda_1} \cdot \lambda_1 + \color{blue}{-1 \cdot \lambda_1}\right) \cdot R \]
        11. distribute-rgt-inN/A

          \[\leadsto \color{blue}{\left(\lambda_1 \cdot \left(\frac{\lambda_2}{\lambda_1} + -1\right)\right)} \cdot R \]
        12. metadata-evalN/A

          \[\leadsto \left(\lambda_1 \cdot \left(\frac{\lambda_2}{\lambda_1} + \color{blue}{\left(\mathsf{neg}\left(1\right)\right)}\right)\right) \cdot R \]
        13. sub-negN/A

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

          \[\leadsto \color{blue}{\left(\lambda_1 \cdot \left(\frac{\lambda_2}{\lambda_1} - 1\right)\right)} \cdot R \]
        15. sub-negN/A

          \[\leadsto \left(\lambda_1 \cdot \color{blue}{\left(\frac{\lambda_2}{\lambda_1} + \left(\mathsf{neg}\left(1\right)\right)\right)}\right) \cdot R \]
        16. metadata-evalN/A

          \[\leadsto \left(\lambda_1 \cdot \left(\frac{\lambda_2}{\lambda_1} + \color{blue}{-1}\right)\right) \cdot R \]
        17. +-commutativeN/A

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

          \[\leadsto \left(\lambda_1 \cdot \color{blue}{\left(-1 + \frac{\lambda_2}{\lambda_1}\right)}\right) \cdot R \]
        19. /-lowering-/.f6422.9

          \[\leadsto \left(\lambda_1 \cdot \left(-1 + \color{blue}{\frac{\lambda_2}{\lambda_1}}\right)\right) \cdot R \]
      11. Simplified22.9%

        \[\leadsto \color{blue}{\left(\lambda_1 \cdot \left(-1 + \frac{\lambda_2}{\lambda_1}\right)\right)} \cdot R \]

      if 4.6999999999999997e-222 < phi1

      1. Initial program 59.1%

        \[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-*.f6425.3

          \[\leadsto \color{blue}{\phi_2 \cdot R} \]
      5. Simplified25.3%

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -0.125:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq 4.7 \cdot 10^{-222}:\\ \;\;\;\;R \cdot \left(\lambda_1 \cdot \left(-1 + \frac{\lambda_2}{\lambda_1}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]
    5. Add Preprocessing

    Alternative 8: 53.9% accurate, 7.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 -0.175:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq 3.6 \cdot 10^{-163}:\\ \;\;\;\;\lambda_2 \cdot \left(R \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \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 -0.175)
       (* R (- phi2 phi1))
       (if (<= phi1 3.6e-163)
         (* lambda2 (* R (- 1.0 (/ lambda1 lambda2))))
         (* R 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 <= -0.175) {
    		tmp = R * (phi2 - phi1);
    	} else if (phi1 <= 3.6e-163) {
    		tmp = lambda2 * (R * (1.0 - (lambda1 / lambda2)));
    	} else {
    		tmp = R * phi2;
    	}
    	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 <= (-0.175d0)) then
            tmp = r * (phi2 - phi1)
        else if (phi1 <= 3.6d-163) then
            tmp = lambda2 * (r * (1.0d0 - (lambda1 / lambda2)))
        else
            tmp = r * phi2
        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 <= -0.175) {
    		tmp = R * (phi2 - phi1);
    	} else if (phi1 <= 3.6e-163) {
    		tmp = lambda2 * (R * (1.0 - (lambda1 / lambda2)));
    	} else {
    		tmp = R * phi2;
    	}
    	return tmp;
    }
    
    [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
    def code(R, lambda1, lambda2, phi1, phi2):
    	tmp = 0
    	if phi1 <= -0.175:
    		tmp = R * (phi2 - phi1)
    	elif phi1 <= 3.6e-163:
    		tmp = lambda2 * (R * (1.0 - (lambda1 / lambda2)))
    	else:
    		tmp = R * 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 <= -0.175)
    		tmp = Float64(R * Float64(phi2 - phi1));
    	elseif (phi1 <= 3.6e-163)
    		tmp = Float64(lambda2 * Float64(R * Float64(1.0 - Float64(lambda1 / lambda2))));
    	else
    		tmp = Float64(R * phi2);
    	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 <= -0.175)
    		tmp = R * (phi2 - phi1);
    	elseif (phi1 <= 3.6e-163)
    		tmp = lambda2 * (R * (1.0 - (lambda1 / lambda2)));
    	else
    		tmp = R * phi2;
    	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, -0.175], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 3.6e-163], N[(lambda2 * N[(R * N[(1.0 - N[(lambda1 / lambda2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * phi2), $MachinePrecision]]]
    
    \begin{array}{l}
    [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
    \\
    \begin{array}{l}
    \mathbf{if}\;\phi_1 \leq -0.175:\\
    \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
    
    \mathbf{elif}\;\phi_1 \leq 3.6 \cdot 10^{-163}:\\
    \;\;\;\;\lambda_2 \cdot \left(R \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;R \cdot \phi_2\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if phi1 < -0.17499999999999999

      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 phi2 around inf

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

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

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

          \[\leadsto \phi_2 \cdot \left(\color{blue}{\left(\mathsf{neg}\left(\frac{R \cdot \phi_1}{\phi_2}\right)\right)} + R\right) \]
        4. associate-/l*N/A

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

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

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

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

          \[\leadsto \phi_2 \cdot \mathsf{fma}\left(R, \color{blue}{\mathsf{neg}\left(\frac{\phi_1}{\phi_2}\right)}, R\right) \]
        9. neg-sub0N/A

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

          \[\leadsto \phi_2 \cdot \mathsf{fma}\left(R, \color{blue}{0 - \frac{\phi_1}{\phi_2}}, R\right) \]
        11. /-lowering-/.f6451.2

          \[\leadsto \phi_2 \cdot \mathsf{fma}\left(R, 0 - \color{blue}{\frac{\phi_1}{\phi_2}}, R\right) \]
      5. Simplified51.2%

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

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

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

          \[\leadsto \color{blue}{\mathsf{fma}\left(R, \phi_2, -1 \cdot \left(R \cdot \phi_1\right)\right)} \]
        3. mul-1-negN/A

          \[\leadsto \mathsf{fma}\left(R, \phi_2, \color{blue}{\mathsf{neg}\left(R \cdot \phi_1\right)}\right) \]
        4. neg-sub0N/A

          \[\leadsto \mathsf{fma}\left(R, \phi_2, \color{blue}{0 - R \cdot \phi_1}\right) \]
        5. --lowering--.f64N/A

          \[\leadsto \mathsf{fma}\left(R, \phi_2, \color{blue}{0 - R \cdot \phi_1}\right) \]
        6. *-lowering-*.f6463.2

          \[\leadsto \mathsf{fma}\left(R, \phi_2, 0 - \color{blue}{R \cdot \phi_1}\right) \]
      8. Simplified63.2%

        \[\leadsto \color{blue}{\mathsf{fma}\left(R, \phi_2, 0 - R \cdot \phi_1\right)} \]
      9. Taylor expanded in R around 0

        \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
      10. Step-by-step derivation
        1. *-lowering-*.f64N/A

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

          \[\leadsto R \cdot \color{blue}{\left(\phi_2 - \phi_1\right)} \]
      11. Simplified61.3%

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

      if -0.17499999999999999 < phi1 < 3.5999999999999998e-163

      1. Initial program 56.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 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--.f6498.9

          \[\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. Simplified98.9%

        \[\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--.f6486.3

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

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

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

          \[\leadsto \color{blue}{\lambda_2 \cdot \left(R + -1 \cdot \frac{R \cdot \lambda_1}{\lambda_2}\right)} \]
        2. *-rgt-identityN/A

          \[\leadsto \lambda_2 \cdot \left(\color{blue}{R \cdot 1} + -1 \cdot \frac{R \cdot \lambda_1}{\lambda_2}\right) \]
        3. mul-1-negN/A

          \[\leadsto \lambda_2 \cdot \left(R \cdot 1 + \color{blue}{\left(\mathsf{neg}\left(\frac{R \cdot \lambda_1}{\lambda_2}\right)\right)}\right) \]
        4. associate-/l*N/A

          \[\leadsto \lambda_2 \cdot \left(R \cdot 1 + \left(\mathsf{neg}\left(\color{blue}{R \cdot \frac{\lambda_1}{\lambda_2}}\right)\right)\right) \]
        5. distribute-rgt-neg-inN/A

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

          \[\leadsto \lambda_2 \cdot \left(R \cdot 1 + R \cdot \color{blue}{\left(-1 \cdot \frac{\lambda_1}{\lambda_2}\right)}\right) \]
        7. distribute-lft-outN/A

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

          \[\leadsto \lambda_2 \cdot \color{blue}{\left(R \cdot \left(1 + -1 \cdot \frac{\lambda_1}{\lambda_2}\right)\right)} \]
        9. mul-1-negN/A

          \[\leadsto \lambda_2 \cdot \left(R \cdot \left(1 + \color{blue}{\left(\mathsf{neg}\left(\frac{\lambda_1}{\lambda_2}\right)\right)}\right)\right) \]
        10. unsub-negN/A

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

          \[\leadsto \lambda_2 \cdot \left(R \cdot \color{blue}{\left(1 - \frac{\lambda_1}{\lambda_2}\right)}\right) \]
        12. /-lowering-/.f6424.0

          \[\leadsto \lambda_2 \cdot \left(R \cdot \left(1 - \color{blue}{\frac{\lambda_1}{\lambda_2}}\right)\right) \]
      11. Simplified24.0%

        \[\leadsto \color{blue}{\lambda_2 \cdot \left(R \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)} \]

      if 3.5999999999999998e-163 < phi1

      1. Initial program 59.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. 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-*.f6426.1

          \[\leadsto \color{blue}{\phi_2 \cdot R} \]
      5. Simplified26.1%

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -0.175:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq 3.6 \cdot 10^{-163}:\\ \;\;\;\;\lambda_2 \cdot \left(R \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]
    5. Add Preprocessing

    Alternative 9: 61.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 3.8 \cdot 10^{+143}:\\ \;\;\;\;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 3.8e+143) (* 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 <= 3.8e+143) {
    		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 <= 3.8d+143) 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 <= 3.8e+143) {
    		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 <= 3.8e+143:
    		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 <= 3.8e+143)
    		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 <= 3.8e+143)
    		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, 3.8e+143], 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 3.8 \cdot 10^{+143}:\\
    \;\;\;\;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 < 3.8e143

      1. Initial program 57.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 inf

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

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

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

          \[\leadsto \phi_2 \cdot \left(\color{blue}{\left(\mathsf{neg}\left(\frac{R \cdot \phi_1}{\phi_2}\right)\right)} + R\right) \]
        4. associate-/l*N/A

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

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

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

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

          \[\leadsto \phi_2 \cdot \mathsf{fma}\left(R, \color{blue}{\mathsf{neg}\left(\frac{\phi_1}{\phi_2}\right)}, R\right) \]
        9. neg-sub0N/A

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

          \[\leadsto \phi_2 \cdot \mathsf{fma}\left(R, \color{blue}{0 - \frac{\phi_1}{\phi_2}}, R\right) \]
        11. /-lowering-/.f6428.2

          \[\leadsto \phi_2 \cdot \mathsf{fma}\left(R, 0 - \color{blue}{\frac{\phi_1}{\phi_2}}, R\right) \]
      5. Simplified28.2%

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

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

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

          \[\leadsto \color{blue}{\mathsf{fma}\left(R, \phi_2, -1 \cdot \left(R \cdot \phi_1\right)\right)} \]
        3. mul-1-negN/A

          \[\leadsto \mathsf{fma}\left(R, \phi_2, \color{blue}{\mathsf{neg}\left(R \cdot \phi_1\right)}\right) \]
        4. neg-sub0N/A

          \[\leadsto \mathsf{fma}\left(R, \phi_2, \color{blue}{0 - R \cdot \phi_1}\right) \]
        5. --lowering--.f64N/A

          \[\leadsto \mathsf{fma}\left(R, \phi_2, \color{blue}{0 - R \cdot \phi_1}\right) \]
        6. *-lowering-*.f6429.2

          \[\leadsto \mathsf{fma}\left(R, \phi_2, 0 - \color{blue}{R \cdot \phi_1}\right) \]
      8. Simplified29.2%

        \[\leadsto \color{blue}{\mathsf{fma}\left(R, \phi_2, 0 - R \cdot \phi_1\right)} \]
      9. Taylor expanded in R around 0

        \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
      10. Step-by-step derivation
        1. *-lowering-*.f64N/A

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

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

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

      if 3.8e143 < lambda2

      1. Initial program 45.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 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--.f6481.1

          \[\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. Simplified81.1%

        \[\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 \]
      9. Taylor expanded in lambda2 around inf

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

          \[\leadsto \color{blue}{\lambda_2} \cdot R \]
      11. Recombined 2 regimes into one program.
      12. Add Preprocessing

      Alternative 10: 37.2% 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.8 \cdot 10^{+24}:\\ \;\;\;\;\lambda_2 \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \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.8e+24) (* lambda2 R) (* R 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 (phi2 <= 7.8e+24) {
      		tmp = lambda2 * R;
      	} else {
      		tmp = R * phi2;
      	}
      	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.8d+24) then
              tmp = lambda2 * r
          else
              tmp = r * phi2
          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.8e+24) {
      		tmp = lambda2 * R;
      	} else {
      		tmp = R * phi2;
      	}
      	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.8e+24:
      		tmp = lambda2 * R
      	else:
      		tmp = R * 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 (phi2 <= 7.8e+24)
      		tmp = Float64(lambda2 * R);
      	else
      		tmp = Float64(R * phi2);
      	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.8e+24)
      		tmp = lambda2 * R;
      	else
      		tmp = R * phi2;
      	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.8e+24], N[(lambda2 * R), $MachinePrecision], N[(R * phi2), $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.8 \cdot 10^{+24}:\\
      \;\;\;\;\lambda_2 \cdot R\\
      
      \mathbf{else}:\\
      \;\;\;\;R \cdot \phi_2\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if phi2 < 7.7999999999999995e24

        1. Initial program 56.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. 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--.f6471.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. Simplified71.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--.f6466.6

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

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

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

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

          if 7.7999999999999995e24 < phi2

          1. Initial program 54.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. 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-*.f6468.9

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

            \[\leadsto \color{blue}{\phi_2 \cdot R} \]
        11. Recombined 2 regimes into one program.
        12. Final simplification28.6%

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

        Alternative 11: 13.9% 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 56.1%

          \[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--.f6474.2

            \[\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. Simplified74.2%

          \[\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--.f6468.5

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

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

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

            \[\leadsto \color{blue}{\lambda_2} \cdot R \]
          2. Add Preprocessing

          Reproduce

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