Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.0% → 90.8%
Time: 13.7s
Alternatives: 15
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 15 alternatives:

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

Initial Program: 60.0% 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.8% accurate, 1.1× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 0.38:\\ \;\;\;\;\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, \frac{\cos \left(\phi_2 \cdot 0.5\right)}{\frac{-1}{\lambda_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 (<= phi2 0.38)
   (* (hypot phi1 (* (- lambda1 lambda2) (cos (* phi1 0.5)))) R)
   (* R (hypot phi2 (/ (cos (* phi2 0.5)) (/ -1.0 (- lambda2 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 (phi2 <= 0.38) {
		tmp = hypot(phi1, ((lambda1 - lambda2) * cos((phi1 * 0.5)))) * R;
	} else {
		tmp = R * hypot(phi2, (cos((phi2 * 0.5)) / (-1.0 / (lambda2 - 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 (phi2 <= 0.38) {
		tmp = Math.hypot(phi1, ((lambda1 - lambda2) * Math.cos((phi1 * 0.5)))) * R;
	} else {
		tmp = R * Math.hypot(phi2, (Math.cos((phi2 * 0.5)) / (-1.0 / (lambda2 - lambda1))));
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 0.38:
		tmp = math.hypot(phi1, ((lambda1 - lambda2) * math.cos((phi1 * 0.5)))) * R
	else:
		tmp = R * math.hypot(phi2, (math.cos((phi2 * 0.5)) / (-1.0 / (lambda2 - 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 (phi2 <= 0.38)
		tmp = Float64(hypot(phi1, Float64(Float64(lambda1 - lambda2) * cos(Float64(phi1 * 0.5)))) * R);
	else
		tmp = Float64(R * hypot(phi2, Float64(cos(Float64(phi2 * 0.5)) / Float64(-1.0 / Float64(lambda2 - 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 (phi2 <= 0.38)
		tmp = hypot(phi1, ((lambda1 - lambda2) * cos((phi1 * 0.5)))) * R;
	else
		tmp = R * hypot(phi2, (cos((phi2 * 0.5)) / (-1.0 / (lambda2 - 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[phi2, 0.38], 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[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] / N[(-1.0 / N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 0.38:\\
\;\;\;\;\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, \frac{\cos \left(\phi_2 \cdot 0.5\right)}{\frac{-1}{\lambda_2 - \lambda_1}}\right)\\


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

    1. Initial program 64.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.38 < phi2

    1. Initial program 68.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--.f6485.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. Simplified85.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. Step-by-step derivation
      1. flip--N/A

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

        \[\leadsto \mathsf{hypot}\left(\phi_2, \cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \color{blue}{\frac{1}{\frac{\lambda_1 + \lambda_2}{\lambda_1 \cdot \lambda_1 - \lambda_2 \cdot \lambda_2}}}\right) \cdot R \]
      3. un-div-invN/A

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

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

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

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

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

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

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

        \[\leadsto \mathsf{hypot}\left(\phi_2, \frac{\cos \left(0.5 \cdot \phi_2\right)}{\frac{1}{\color{blue}{\lambda_1 - \lambda_2}}}\right) \cdot R \]
    7. Applied egg-rr85.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 0.38:\\ \;\;\;\;\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, \frac{\cos \left(\phi_2 \cdot 0.5\right)}{\frac{-1}{\lambda_2 - \lambda_1}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 90.8% accurate, 1.2× speedup?

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

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


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

    1. Initial program 64.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.37 < phi2

    1. Initial program 68.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--.f6485.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. Simplified85.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} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification81.9%

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

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

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

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


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

    1. Initial program 64.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.00320000000000000015 < phi2 < 5.29999999999999996e73

    1. Initial program 87.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. Step-by-step derivation
      1. swap-sqrN/A

        \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{\phi_1 + \phi_2}{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. *-commutativeN/A

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

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

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

    if 5.29999999999999996e73 < phi2

    1. Initial program 62.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 81.5% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 64.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.021999999999999999 < phi2 < 1.2e75

    1. Initial program 87.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. Step-by-step derivation
      1. swap-sqrN/A

        \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{\phi_1 + \phi_2}{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. *-commutativeN/A

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

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

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

    if 1.2e75 < phi2

    1. Initial program 62.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

    1. Initial program 65.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.75000000000000008e37 < phi2

    1. Initial program 65.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
      13. --lowering--.f6476.7

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

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

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

Alternative 6: 69.2% accurate, 2.5× speedup?

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

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


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

    1. Initial program 64.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 4.49999999999999993e-8 < phi2

      1. Initial program 68.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Alternative 7: 52.5% 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 -3.8 \cdot 10^{-12}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq 1.02 \cdot 10^{-60}:\\ \;\;\;\;\lambda_1 \cdot \left(\frac{\lambda_2 \cdot R}{\lambda_1} - R\right)\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot R\\ \end{array} \end{array} \]
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (<= phi1 -3.8e-12)
       (* R (- phi2 phi1))
       (if (<= phi1 1.02e-60)
         (* lambda1 (- (/ (* lambda2 R) lambda1) R))
         (* phi2 R))))
    assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi1 <= -3.8e-12) {
    		tmp = R * (phi2 - phi1);
    	} else if (phi1 <= 1.02e-60) {
    		tmp = lambda1 * (((lambda2 * R) / lambda1) - R);
    	} else {
    		tmp = phi2 * R;
    	}
    	return tmp;
    }
    
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    real(8) function code(r, lambda1, lambda2, phi1, phi2)
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: tmp
        if (phi1 <= (-3.8d-12)) then
            tmp = r * (phi2 - phi1)
        else if (phi1 <= 1.02d-60) then
            tmp = lambda1 * (((lambda2 * r) / lambda1) - r)
        else
            tmp = phi2 * r
        end if
        code = tmp
    end function
    
    assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi1 <= -3.8e-12) {
    		tmp = R * (phi2 - phi1);
    	} else if (phi1 <= 1.02e-60) {
    		tmp = lambda1 * (((lambda2 * R) / lambda1) - R);
    	} else {
    		tmp = phi2 * R;
    	}
    	return tmp;
    }
    
    [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
    def code(R, lambda1, lambda2, phi1, phi2):
    	tmp = 0
    	if phi1 <= -3.8e-12:
    		tmp = R * (phi2 - phi1)
    	elif phi1 <= 1.02e-60:
    		tmp = lambda1 * (((lambda2 * R) / lambda1) - R)
    	else:
    		tmp = phi2 * R
    	return tmp
    
    R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (phi1 <= -3.8e-12)
    		tmp = Float64(R * Float64(phi2 - phi1));
    	elseif (phi1 <= 1.02e-60)
    		tmp = Float64(lambda1 * Float64(Float64(Float64(lambda2 * R) / lambda1) - R));
    	else
    		tmp = Float64(phi2 * R);
    	end
    	return tmp
    end
    
    R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0;
    	if (phi1 <= -3.8e-12)
    		tmp = R * (phi2 - phi1);
    	elseif (phi1 <= 1.02e-60)
    		tmp = lambda1 * (((lambda2 * R) / lambda1) - R);
    	else
    		tmp = phi2 * R;
    	end
    	tmp_2 = tmp;
    end
    
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -3.8e-12], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 1.02e-60], N[(lambda1 * N[(N[(N[(lambda2 * R), $MachinePrecision] / lambda1), $MachinePrecision] - R), $MachinePrecision]), $MachinePrecision], N[(phi2 * R), $MachinePrecision]]]
    
    \begin{array}{l}
    [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
    \\
    \begin{array}{l}
    \mathbf{if}\;\phi_1 \leq -3.8 \cdot 10^{-12}:\\
    \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
    
    \mathbf{elif}\;\phi_1 \leq 1.02 \cdot 10^{-60}:\\
    \;\;\;\;\lambda_1 \cdot \left(\frac{\lambda_2 \cdot R}{\lambda_1} - R\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\phi_2 \cdot R\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if phi1 < -3.79999999999999996e-12

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
        13. --lowering--.f6468.8

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

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

      if -3.79999999999999996e-12 < phi1 < 1.01999999999999994e-60

      1. Initial program 73.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
        13. *-lowering-*.f6467.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. Simplified67.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--.f6467.8

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \left(\mathsf{neg}\left(\lambda_1\right)\right) \cdot \left(R - \frac{\color{blue}{\lambda_2 \cdot R}}{\lambda_1}\right) \]
        10. *-lowering-*.f6434.6

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

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

      if 1.01999999999999994e-60 < phi1

      1. Initial program 55.8%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Add Preprocessing
      3. Taylor expanded in phi2 around 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-*.f6420.8

          \[\leadsto \color{blue}{\phi_2 \cdot R} \]
      5. Simplified20.8%

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

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

    Alternative 8: 54.3% 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 -3.45 \cdot 10^{-12}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq 1.02 \cdot 10^{-172}:\\ \;\;\;\;R \cdot \left(\lambda_2 \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\phi_1 \cdot \left(\frac{\phi_2 \cdot R}{\phi_1} - R\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 -3.45e-12)
       (* R (- phi2 phi1))
       (if (<= phi1 1.02e-172)
         (* R (* lambda2 (- 1.0 (/ lambda1 lambda2))))
         (* phi1 (- (/ (* phi2 R) phi1) R)))))
    assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi1 <= -3.45e-12) {
    		tmp = R * (phi2 - phi1);
    	} else if (phi1 <= 1.02e-172) {
    		tmp = R * (lambda2 * (1.0 - (lambda1 / lambda2)));
    	} else {
    		tmp = phi1 * (((phi2 * R) / phi1) - R);
    	}
    	return tmp;
    }
    
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    real(8) function code(r, lambda1, lambda2, phi1, phi2)
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: tmp
        if (phi1 <= (-3.45d-12)) then
            tmp = r * (phi2 - phi1)
        else if (phi1 <= 1.02d-172) then
            tmp = r * (lambda2 * (1.0d0 - (lambda1 / lambda2)))
        else
            tmp = phi1 * (((phi2 * r) / phi1) - r)
        end if
        code = tmp
    end function
    
    assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi1 <= -3.45e-12) {
    		tmp = R * (phi2 - phi1);
    	} else if (phi1 <= 1.02e-172) {
    		tmp = R * (lambda2 * (1.0 - (lambda1 / lambda2)));
    	} else {
    		tmp = phi1 * (((phi2 * R) / phi1) - R);
    	}
    	return tmp;
    }
    
    [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
    def code(R, lambda1, lambda2, phi1, phi2):
    	tmp = 0
    	if phi1 <= -3.45e-12:
    		tmp = R * (phi2 - phi1)
    	elif phi1 <= 1.02e-172:
    		tmp = R * (lambda2 * (1.0 - (lambda1 / lambda2)))
    	else:
    		tmp = phi1 * (((phi2 * R) / phi1) - R)
    	return tmp
    
    R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (phi1 <= -3.45e-12)
    		tmp = Float64(R * Float64(phi2 - phi1));
    	elseif (phi1 <= 1.02e-172)
    		tmp = Float64(R * Float64(lambda2 * Float64(1.0 - Float64(lambda1 / lambda2))));
    	else
    		tmp = Float64(phi1 * Float64(Float64(Float64(phi2 * R) / phi1) - R));
    	end
    	return tmp
    end
    
    R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0;
    	if (phi1 <= -3.45e-12)
    		tmp = R * (phi2 - phi1);
    	elseif (phi1 <= 1.02e-172)
    		tmp = R * (lambda2 * (1.0 - (lambda1 / lambda2)));
    	else
    		tmp = phi1 * (((phi2 * R) / phi1) - R);
    	end
    	tmp_2 = tmp;
    end
    
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -3.45e-12], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 1.02e-172], N[(R * N[(lambda2 * N[(1.0 - N[(lambda1 / lambda2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(phi1 * N[(N[(N[(phi2 * R), $MachinePrecision] / phi1), $MachinePrecision] - R), $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 -3.45 \cdot 10^{-12}:\\
    \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
    
    \mathbf{elif}\;\phi_1 \leq 1.02 \cdot 10^{-172}:\\
    \;\;\;\;R \cdot \left(\lambda_2 \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\phi_1 \cdot \left(\frac{\phi_2 \cdot R}{\phi_1} - R\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if phi1 < -3.45e-12

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
        13. --lowering--.f6468.8

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

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

      if -3.45e-12 < phi1 < 1.02e-172

      1. Initial program 76.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-*.f6467.9

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

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

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

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

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

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

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

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

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

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

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

      if 1.02e-172 < phi1

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

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

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

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

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

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

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

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

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

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

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

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

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

    Alternative 9: 53.5% 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 -2.9 \cdot 10^{-12}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq 1.02 \cdot 10^{-172}:\\ \;\;\;\;R \cdot \left(\lambda_2 \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\phi_1 \cdot \mathsf{fma}\left(R, \frac{\phi_2}{\phi_1}, -R\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 -2.9e-12)
       (* R (- phi2 phi1))
       (if (<= phi1 1.02e-172)
         (* R (* lambda2 (- 1.0 (/ lambda1 lambda2))))
         (* phi1 (fma R (/ phi2 phi1) (- R))))))
    assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi1 <= -2.9e-12) {
    		tmp = R * (phi2 - phi1);
    	} else if (phi1 <= 1.02e-172) {
    		tmp = R * (lambda2 * (1.0 - (lambda1 / lambda2)));
    	} else {
    		tmp = phi1 * fma(R, (phi2 / phi1), -R);
    	}
    	return tmp;
    }
    
    R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (phi1 <= -2.9e-12)
    		tmp = Float64(R * Float64(phi2 - phi1));
    	elseif (phi1 <= 1.02e-172)
    		tmp = Float64(R * Float64(lambda2 * Float64(1.0 - Float64(lambda1 / lambda2))));
    	else
    		tmp = Float64(phi1 * fma(R, Float64(phi2 / phi1), Float64(-R)));
    	end
    	return tmp
    end
    
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -2.9e-12], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 1.02e-172], N[(R * N[(lambda2 * N[(1.0 - N[(lambda1 / lambda2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(phi1 * N[(R * N[(phi2 / phi1), $MachinePrecision] + (-R)), $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.9 \cdot 10^{-12}:\\
    \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
    
    \mathbf{elif}\;\phi_1 \leq 1.02 \cdot 10^{-172}:\\
    \;\;\;\;R \cdot \left(\lambda_2 \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\phi_1 \cdot \mathsf{fma}\left(R, \frac{\phi_2}{\phi_1}, -R\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if phi1 < -2.9000000000000002e-12

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
        13. --lowering--.f6468.8

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

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

      if -2.9000000000000002e-12 < phi1 < 1.02e-172

      1. Initial program 76.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-*.f6467.9

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

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

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

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

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

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

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

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

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

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

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

      if 1.02e-172 < phi1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -2.9 \cdot 10^{-12}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq 1.02 \cdot 10^{-172}:\\ \;\;\;\;R \cdot \left(\lambda_2 \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\phi_1 \cdot \mathsf{fma}\left(R, \frac{\phi_2}{\phi_1}, -R\right)\\ \end{array} \]
    5. Add Preprocessing

    Alternative 10: 52.1% 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 -2.7 \cdot 10^{-13}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq 1.4 \cdot 10^{-60}:\\ \;\;\;\;R \cdot \left(\lambda_2 \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot R\\ \end{array} \end{array} \]
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (<= phi1 -2.7e-13)
       (* R (- phi2 phi1))
       (if (<= phi1 1.4e-60)
         (* R (* lambda2 (- 1.0 (/ lambda1 lambda2))))
         (* phi2 R))))
    assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi1 <= -2.7e-13) {
    		tmp = R * (phi2 - phi1);
    	} else if (phi1 <= 1.4e-60) {
    		tmp = R * (lambda2 * (1.0 - (lambda1 / lambda2)));
    	} else {
    		tmp = phi2 * R;
    	}
    	return tmp;
    }
    
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    real(8) function code(r, lambda1, lambda2, phi1, phi2)
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: tmp
        if (phi1 <= (-2.7d-13)) then
            tmp = r * (phi2 - phi1)
        else if (phi1 <= 1.4d-60) then
            tmp = r * (lambda2 * (1.0d0 - (lambda1 / lambda2)))
        else
            tmp = phi2 * r
        end if
        code = tmp
    end function
    
    assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi1 <= -2.7e-13) {
    		tmp = R * (phi2 - phi1);
    	} else if (phi1 <= 1.4e-60) {
    		tmp = R * (lambda2 * (1.0 - (lambda1 / lambda2)));
    	} else {
    		tmp = phi2 * R;
    	}
    	return tmp;
    }
    
    [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
    def code(R, lambda1, lambda2, phi1, phi2):
    	tmp = 0
    	if phi1 <= -2.7e-13:
    		tmp = R * (phi2 - phi1)
    	elif phi1 <= 1.4e-60:
    		tmp = R * (lambda2 * (1.0 - (lambda1 / lambda2)))
    	else:
    		tmp = phi2 * R
    	return tmp
    
    R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (phi1 <= -2.7e-13)
    		tmp = Float64(R * Float64(phi2 - phi1));
    	elseif (phi1 <= 1.4e-60)
    		tmp = Float64(R * Float64(lambda2 * Float64(1.0 - Float64(lambda1 / lambda2))));
    	else
    		tmp = Float64(phi2 * R);
    	end
    	return tmp
    end
    
    R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0;
    	if (phi1 <= -2.7e-13)
    		tmp = R * (phi2 - phi1);
    	elseif (phi1 <= 1.4e-60)
    		tmp = R * (lambda2 * (1.0 - (lambda1 / lambda2)));
    	else
    		tmp = phi2 * R;
    	end
    	tmp_2 = tmp;
    end
    
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -2.7e-13], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 1.4e-60], N[(R * N[(lambda2 * N[(1.0 - N[(lambda1 / lambda2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(phi2 * R), $MachinePrecision]]]
    
    \begin{array}{l}
    [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
    \\
    \begin{array}{l}
    \mathbf{if}\;\phi_1 \leq -2.7 \cdot 10^{-13}:\\
    \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
    
    \mathbf{elif}\;\phi_1 \leq 1.4 \cdot 10^{-60}:\\
    \;\;\;\;R \cdot \left(\lambda_2 \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\phi_2 \cdot R\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if phi1 < -2.70000000000000011e-13

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
        13. --lowering--.f6468.8

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

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

      if -2.70000000000000011e-13 < phi1 < 1.4000000000000001e-60

      1. Initial program 73.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \cdot R \]
        13. *-lowering-*.f6467.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. Simplified67.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--.f6467.8

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

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

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

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

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

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

          \[\leadsto \left(\lambda_2 \cdot \color{blue}{\left(1 - \frac{\lambda_1}{\lambda_2}\right)}\right) \cdot R \]
        5. /-lowering-/.f6434.2

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

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

      if 1.4000000000000001e-60 < phi1

      1. Initial program 55.8%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Add Preprocessing
      3. Taylor expanded in phi2 around 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-*.f6420.8

          \[\leadsto \color{blue}{\phi_2 \cdot R} \]
      5. Simplified20.8%

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

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

    Alternative 11: 50.0% accurate, 13.9× speedup?

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

      1. Initial program 63.7%

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

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

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

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

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

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

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

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

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

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

      if 1.0999999999999999e-230 < phi2 < 0.46000000000000002

      1. Initial program 67.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)} \cdot R \]
        2. neg-lowering-neg.f6418.4

          \[\leadsto \color{blue}{\left(-\lambda_1\right)} \cdot R \]
      11. Simplified18.4%

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

      if 0.46000000000000002 < phi2

      1. Initial program 68.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}{R \cdot \phi_2} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

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

          \[\leadsto \color{blue}{\phi_2 \cdot R} \]
      5. Simplified73.2%

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.1 \cdot 10^{-230}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_2 \leq 0.46:\\ \;\;\;\;\lambda_1 \cdot \left(-R\right)\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot R\\ \end{array} \]
    5. Add Preprocessing

    Alternative 12: 61.2% 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_1 \leq -2.8 \cdot 10^{+105}:\\ \;\;\;\;\lambda_1 \cdot \left(-R\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \end{array} \end{array} \]
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (<= lambda1 -2.8e+105) (* lambda1 (- R)) (* R (- phi2 phi1))))
    assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (lambda1 <= -2.8e+105) {
    		tmp = lambda1 * -R;
    	} else {
    		tmp = R * (phi2 - phi1);
    	}
    	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 (lambda1 <= (-2.8d+105)) then
            tmp = lambda1 * -r
        else
            tmp = r * (phi2 - phi1)
        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 (lambda1 <= -2.8e+105) {
    		tmp = lambda1 * -R;
    	} else {
    		tmp = R * (phi2 - phi1);
    	}
    	return tmp;
    }
    
    [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
    def code(R, lambda1, lambda2, phi1, phi2):
    	tmp = 0
    	if lambda1 <= -2.8e+105:
    		tmp = lambda1 * -R
    	else:
    		tmp = R * (phi2 - phi1)
    	return tmp
    
    R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (lambda1 <= -2.8e+105)
    		tmp = Float64(lambda1 * Float64(-R));
    	else
    		tmp = Float64(R * Float64(phi2 - phi1));
    	end
    	return tmp
    end
    
    R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0;
    	if (lambda1 <= -2.8e+105)
    		tmp = lambda1 * -R;
    	else
    		tmp = R * (phi2 - phi1);
    	end
    	tmp_2 = tmp;
    end
    
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda1, -2.8e+105], N[(lambda1 * (-R)), $MachinePrecision], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
    \\
    \begin{array}{l}
    \mathbf{if}\;\lambda_1 \leq -2.8 \cdot 10^{+105}:\\
    \;\;\;\;\lambda_1 \cdot \left(-R\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if lambda1 < -2.8000000000000001e105

      1. Initial program 62.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 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-*.f6479.4

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

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

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

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

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

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

          \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)} \cdot R \]
        2. neg-lowering-neg.f6472.8

          \[\leadsto \color{blue}{\left(-\lambda_1\right)} \cdot R \]
      11. Simplified72.8%

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

      if -2.8000000000000001e105 < lambda1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{R \cdot \left(\phi_2 - \phi_1\right)} \]
        13. --lowering--.f6437.6

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

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

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

    Alternative 13: 52.3% accurate, 19.9× speedup?

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

      1. Initial program 64.4%

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

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

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

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

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

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

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

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

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

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

      if 3.4e6 < phi2

      1. Initial program 68.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}{R \cdot \phi_2} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

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

          \[\leadsto \color{blue}{\phi_2 \cdot R} \]
      5. Simplified73.2%

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

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

    Alternative 14: 37.6% 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 14200000000000:\\ \;\;\;\;\lambda_2 \cdot R\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot R\\ \end{array} \end{array} \]
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (<= phi2 14200000000000.0) (* lambda2 R) (* phi2 R)))
    assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi2 <= 14200000000000.0) {
    		tmp = lambda2 * R;
    	} else {
    		tmp = phi2 * R;
    	}
    	return tmp;
    }
    
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    real(8) function code(r, lambda1, lambda2, phi1, phi2)
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: tmp
        if (phi2 <= 14200000000000.0d0) then
            tmp = lambda2 * r
        else
            tmp = phi2 * r
        end if
        code = tmp
    end function
    
    assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi2 <= 14200000000000.0) {
    		tmp = lambda2 * R;
    	} else {
    		tmp = phi2 * R;
    	}
    	return tmp;
    }
    
    [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
    def code(R, lambda1, lambda2, phi1, phi2):
    	tmp = 0
    	if phi2 <= 14200000000000.0:
    		tmp = lambda2 * R
    	else:
    		tmp = phi2 * R
    	return tmp
    
    R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (phi2 <= 14200000000000.0)
    		tmp = Float64(lambda2 * R);
    	else
    		tmp = Float64(phi2 * R);
    	end
    	return tmp
    end
    
    R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0;
    	if (phi2 <= 14200000000000.0)
    		tmp = lambda2 * R;
    	else
    		tmp = phi2 * R;
    	end
    	tmp_2 = tmp;
    end
    
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 14200000000000.0], N[(lambda2 * R), $MachinePrecision], N[(phi2 * R), $MachinePrecision]]
    
    \begin{array}{l}
    [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
    \\
    \begin{array}{l}
    \mathbf{if}\;\phi_2 \leq 14200000000000:\\
    \;\;\;\;\lambda_2 \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;\phi_2 \cdot R\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if phi2 < 1.42e13

      1. Initial program 64.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-*.f6480.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. Simplified80.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--.f6477.5

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

        \[\leadsto \mathsf{hypot}\left(\phi_1, \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. Simplified16.4%

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

        if 1.42e13 < phi2

        1. Initial program 67.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-*.f6474.3

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

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

      Alternative 15: 13.6% 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 65.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{hypot}\left(\phi_1, \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.1%

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

        Reproduce

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