Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.0% → 88.8%
Time: 10.4s
Alternatives: 14
Speedup: 2.4×

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 14 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: 88.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_1 \leq -5 \cdot 10^{+60}:\\ \;\;\;\;\mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_2\right) \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 -5e+60)
   (* (hypot (* (cos (* 0.5 phi1)) (- lambda1 lambda2)) phi1) R)
   (* (hypot (* (cos (* phi2 0.5)) (- 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 <= -5e+60) {
		tmp = hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R;
	} else {
		tmp = hypot((cos((phi2 * 0.5)) * (lambda1 - lambda2)), phi2) * R;
	}
	return tmp;
}
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -5e+60) {
		tmp = Math.hypot((Math.cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R;
	} else {
		tmp = Math.hypot((Math.cos((phi2 * 0.5)) * (lambda1 - lambda2)), 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 <= -5e+60:
		tmp = math.hypot((math.cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R
	else:
		tmp = math.hypot((math.cos((phi2 * 0.5)) * (lambda1 - lambda2)), 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 <= -5e+60)
		tmp = Float64(hypot(Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2)), phi1) * R);
	else
		tmp = Float64(hypot(Float64(cos(Float64(phi2 * 0.5)) * Float64(lambda1 - lambda2)), 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 <= -5e+60)
		tmp = hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R;
	else
		tmp = hypot((cos((phi2 * 0.5)) * (lambda1 - lambda2)), 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, -5e+60], N[(N[Sqrt[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(N[Sqrt[N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision] * 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 -5 \cdot 10^{+60}:\\
\;\;\;\;\mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \cdot R\\

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


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

    1. Initial program 53.7%

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

      \[\leadsto R \cdot \color{blue}{\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. unpow2N/A

        \[\leadsto R \cdot \sqrt{\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} + {\phi_1}^{2}} \]
      2. unpow2N/A

        \[\leadsto R \cdot \sqrt{\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)} + {\phi_1}^{2}} \]
      3. unswap-sqrN/A

        \[\leadsto R \cdot \sqrt{\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)} + {\phi_1}^{2}} \]
      4. unpow2N/A

        \[\leadsto R \cdot \sqrt{\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) + \color{blue}{\phi_1 \cdot \phi_1}} \]
      5. lower-hypot.f64N/A

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

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

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

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

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

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

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

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

    if -4.99999999999999975e60 < phi1

    1. Initial program 62.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 R \cdot \color{blue}{\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. unpow2N/A

        \[\leadsto R \cdot \sqrt{\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} + {\phi_2}^{2}} \]
      2. unpow2N/A

        \[\leadsto R \cdot \sqrt{\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)} + {\phi_2}^{2}} \]
      3. unswap-sqrN/A

        \[\leadsto R \cdot \sqrt{\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)} + {\phi_2}^{2}} \]
      4. unpow2N/A

        \[\leadsto R \cdot \sqrt{\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) + \color{blue}{\phi_2 \cdot \phi_2}} \]
      5. lower-hypot.f64N/A

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

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

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

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

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

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

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

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

Alternative 2: 85.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_1 \leq -9.8 \cdot 10^{+61}:\\ \;\;\;\;\mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1, \phi_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_2\right) \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 -9.8e+61)
   (* (hypot (* (cos (* 0.5 phi1)) lambda1) phi1) R)
   (* (hypot (* (cos (* phi2 0.5)) (- 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 <= -9.8e+61) {
		tmp = hypot((cos((0.5 * phi1)) * lambda1), phi1) * R;
	} else {
		tmp = hypot((cos((phi2 * 0.5)) * (lambda1 - lambda2)), phi2) * R;
	}
	return tmp;
}
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -9.8e+61) {
		tmp = Math.hypot((Math.cos((0.5 * phi1)) * lambda1), phi1) * R;
	} else {
		tmp = Math.hypot((Math.cos((phi2 * 0.5)) * (lambda1 - lambda2)), 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 <= -9.8e+61:
		tmp = math.hypot((math.cos((0.5 * phi1)) * lambda1), phi1) * R
	else:
		tmp = math.hypot((math.cos((phi2 * 0.5)) * (lambda1 - lambda2)), 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 <= -9.8e+61)
		tmp = Float64(hypot(Float64(cos(Float64(0.5 * phi1)) * lambda1), phi1) * R);
	else
		tmp = Float64(hypot(Float64(cos(Float64(phi2 * 0.5)) * Float64(lambda1 - lambda2)), 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 <= -9.8e+61)
		tmp = hypot((cos((0.5 * phi1)) * lambda1), phi1) * R;
	else
		tmp = hypot((cos((phi2 * 0.5)) * (lambda1 - lambda2)), 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, -9.8e+61], N[(N[Sqrt[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * lambda1), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(N[Sqrt[N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision] * 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 -9.8 \cdot 10^{+61}:\\
\;\;\;\;\mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1, \phi_1\right) \cdot R\\

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


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

    1. Initial program 53.7%

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

      \[\leadsto R \cdot \color{blue}{\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. unpow2N/A

        \[\leadsto R \cdot \sqrt{\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} + {\phi_1}^{2}} \]
      2. unpow2N/A

        \[\leadsto R \cdot \sqrt{\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)} + {\phi_1}^{2}} \]
      3. unswap-sqrN/A

        \[\leadsto R \cdot \sqrt{\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)} + {\phi_1}^{2}} \]
      4. unpow2N/A

        \[\leadsto R \cdot \sqrt{\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) + \color{blue}{\phi_1 \cdot \phi_1}} \]
      5. lower-hypot.f64N/A

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right), \phi_1\right) \]
    7. Step-by-step derivation
      1. Applied rewrites79.1%

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

      if -9.8000000000000005e61 < phi1

      1. Initial program 62.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 R \cdot \color{blue}{\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. unpow2N/A

          \[\leadsto R \cdot \sqrt{\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} + {\phi_2}^{2}} \]
        2. unpow2N/A

          \[\leadsto R \cdot \sqrt{\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)} + {\phi_2}^{2}} \]
        3. unswap-sqrN/A

          \[\leadsto R \cdot \sqrt{\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)} + {\phi_2}^{2}} \]
        4. unpow2N/A

          \[\leadsto R \cdot \sqrt{\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) + \color{blue}{\phi_2 \cdot \phi_2}} \]
        5. lower-hypot.f64N/A

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

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

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

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

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

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

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

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

    Alternative 3: 80.7% accurate, 1.3× speedup?

    \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -9.8 \cdot 10^{+61}:\\ \;\;\;\;\mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1, \phi_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_2\right) \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 -9.8e+61)
       (* (hypot (* (cos (* 0.5 phi1)) lambda1) phi1) R)
       (* (hypot (- 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 <= -9.8e+61) {
    		tmp = hypot((cos((0.5 * phi1)) * lambda1), phi1) * R;
    	} else {
    		tmp = hypot((lambda1 - lambda2), phi2) * R;
    	}
    	return tmp;
    }
    
    assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi1 <= -9.8e+61) {
    		tmp = Math.hypot((Math.cos((0.5 * phi1)) * lambda1), phi1) * R;
    	} else {
    		tmp = Math.hypot((lambda1 - lambda2), 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 <= -9.8e+61:
    		tmp = math.hypot((math.cos((0.5 * phi1)) * lambda1), phi1) * R
    	else:
    		tmp = math.hypot((lambda1 - lambda2), 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 <= -9.8e+61)
    		tmp = Float64(hypot(Float64(cos(Float64(0.5 * phi1)) * lambda1), phi1) * R);
    	else
    		tmp = Float64(hypot(Float64(lambda1 - lambda2), 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 <= -9.8e+61)
    		tmp = hypot((cos((0.5 * phi1)) * lambda1), phi1) * R;
    	else
    		tmp = hypot((lambda1 - lambda2), 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, -9.8e+61], N[(N[Sqrt[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * lambda1), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(N[Sqrt[N[(lambda1 - lambda2), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision] * 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 -9.8 \cdot 10^{+61}:\\
    \;\;\;\;\mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1, \phi_1\right) \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;\mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_2\right) \cdot R\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if phi1 < -9.8000000000000005e61

      1. Initial program 53.7%

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

        \[\leadsto R \cdot \color{blue}{\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. unpow2N/A

          \[\leadsto R \cdot \sqrt{\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} + {\phi_1}^{2}} \]
        2. unpow2N/A

          \[\leadsto R \cdot \sqrt{\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)} + {\phi_1}^{2}} \]
        3. unswap-sqrN/A

          \[\leadsto R \cdot \sqrt{\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)} + {\phi_1}^{2}} \]
        4. unpow2N/A

          \[\leadsto R \cdot \sqrt{\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) + \color{blue}{\phi_1 \cdot \phi_1}} \]
        5. lower-hypot.f64N/A

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

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

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

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

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

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right), \phi_1\right) \]
      7. Step-by-step derivation
        1. Applied rewrites79.1%

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

        if -9.8000000000000005e61 < phi1

        1. Initial program 62.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 R \cdot \color{blue}{\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. unpow2N/A

            \[\leadsto R \cdot \sqrt{\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} + {\phi_2}^{2}} \]
          2. unpow2N/A

            \[\leadsto R \cdot \sqrt{\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)} + {\phi_2}^{2}} \]
          3. unswap-sqrN/A

            \[\leadsto R \cdot \sqrt{\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)} + {\phi_2}^{2}} \]
          4. unpow2N/A

            \[\leadsto R \cdot \sqrt{\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) + \color{blue}{\phi_2 \cdot \phi_2}} \]
          5. lower-hypot.f64N/A

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

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

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

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

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

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

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

          \[\leadsto R \cdot \mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_2\right) \]
        7. Step-by-step derivation
          1. Applied rewrites72.9%

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

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

        Alternative 4: 80.7% accurate, 1.3× speedup?

        \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -6.4 \cdot 10^{+60}:\\ \;\;\;\;\mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2, \phi_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_2\right) \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 -6.4e+60)
           (* (hypot (* (cos (* 0.5 phi1)) lambda2) phi1) R)
           (* (hypot (- 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 <= -6.4e+60) {
        		tmp = hypot((cos((0.5 * phi1)) * lambda2), phi1) * R;
        	} else {
        		tmp = hypot((lambda1 - lambda2), phi2) * R;
        	}
        	return tmp;
        }
        
        assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
        public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
        	double tmp;
        	if (phi1 <= -6.4e+60) {
        		tmp = Math.hypot((Math.cos((0.5 * phi1)) * lambda2), phi1) * R;
        	} else {
        		tmp = Math.hypot((lambda1 - lambda2), 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 <= -6.4e+60:
        		tmp = math.hypot((math.cos((0.5 * phi1)) * lambda2), phi1) * R
        	else:
        		tmp = math.hypot((lambda1 - lambda2), 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 <= -6.4e+60)
        		tmp = Float64(hypot(Float64(cos(Float64(0.5 * phi1)) * lambda2), phi1) * R);
        	else
        		tmp = Float64(hypot(Float64(lambda1 - lambda2), 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 <= -6.4e+60)
        		tmp = hypot((cos((0.5 * phi1)) * lambda2), phi1) * R;
        	else
        		tmp = hypot((lambda1 - lambda2), 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, -6.4e+60], N[(N[Sqrt[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * lambda2), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(N[Sqrt[N[(lambda1 - lambda2), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision] * 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 -6.4 \cdot 10^{+60}:\\
        \;\;\;\;\mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2, \phi_1\right) \cdot R\\
        
        \mathbf{else}:\\
        \;\;\;\;\mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_2\right) \cdot R\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if phi1 < -6.39999999999999982e60

          1. Initial program 53.7%

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

            \[\leadsto R \cdot \color{blue}{\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. unpow2N/A

              \[\leadsto R \cdot \sqrt{\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} + {\phi_1}^{2}} \]
            2. unpow2N/A

              \[\leadsto R \cdot \sqrt{\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)} + {\phi_1}^{2}} \]
            3. unswap-sqrN/A

              \[\leadsto R \cdot \sqrt{\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)} + {\phi_1}^{2}} \]
            4. unpow2N/A

              \[\leadsto R \cdot \sqrt{\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) + \color{blue}{\phi_1 \cdot \phi_1}} \]
            5. lower-hypot.f64N/A

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

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

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

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

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

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

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

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

            \[\leadsto R \cdot \sqrt{{\lambda_2}^{2} \cdot {\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} + {\phi_1}^{2}} \]
          7. Step-by-step derivation
            1. Applied rewrites83.3%

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

            if -6.39999999999999982e60 < phi1

            1. Initial program 62.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 R \cdot \color{blue}{\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. unpow2N/A

                \[\leadsto R \cdot \sqrt{\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} + {\phi_2}^{2}} \]
              2. unpow2N/A

                \[\leadsto R \cdot \sqrt{\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)} + {\phi_2}^{2}} \]
              3. unswap-sqrN/A

                \[\leadsto R \cdot \sqrt{\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)} + {\phi_2}^{2}} \]
              4. unpow2N/A

                \[\leadsto R \cdot \sqrt{\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) + \color{blue}{\phi_2 \cdot \phi_2}} \]
              5. lower-hypot.f64N/A

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

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

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

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

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

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

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

              \[\leadsto R \cdot \mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_2\right) \]
            7. Step-by-step derivation
              1. Applied rewrites72.9%

                \[\leadsto R \cdot \mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_2\right) \]
            8. Recombined 2 regimes into one program.
            9. Final simplification75.0%

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

            Alternative 5: 80.3% accurate, 2.4× speedup?

            \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -9 \cdot 10^{+60}:\\ \;\;\;\;\mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_2\right) \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 -9e+60)
               (* (hypot (- lambda1 lambda2) phi1) R)
               (* (hypot (- 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 <= -9e+60) {
            		tmp = hypot((lambda1 - lambda2), phi1) * R;
            	} else {
            		tmp = hypot((lambda1 - lambda2), phi2) * R;
            	}
            	return tmp;
            }
            
            assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
            public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
            	double tmp;
            	if (phi1 <= -9e+60) {
            		tmp = Math.hypot((lambda1 - lambda2), phi1) * R;
            	} else {
            		tmp = Math.hypot((lambda1 - lambda2), 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 <= -9e+60:
            		tmp = math.hypot((lambda1 - lambda2), phi1) * R
            	else:
            		tmp = math.hypot((lambda1 - lambda2), 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 <= -9e+60)
            		tmp = Float64(hypot(Float64(lambda1 - lambda2), phi1) * R);
            	else
            		tmp = Float64(hypot(Float64(lambda1 - lambda2), 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 <= -9e+60)
            		tmp = hypot((lambda1 - lambda2), phi1) * R;
            	else
            		tmp = hypot((lambda1 - lambda2), 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, -9e+60], N[(N[Sqrt[N[(lambda1 - lambda2), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(N[Sqrt[N[(lambda1 - lambda2), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision] * 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 -9 \cdot 10^{+60}:\\
            \;\;\;\;\mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_1\right) \cdot R\\
            
            \mathbf{else}:\\
            \;\;\;\;\mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_2\right) \cdot R\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if phi1 < -9.00000000000000026e60

              1. Initial program 53.7%

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

                \[\leadsto R \cdot \color{blue}{\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. unpow2N/A

                  \[\leadsto R \cdot \sqrt{\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} + {\phi_1}^{2}} \]
                2. unpow2N/A

                  \[\leadsto R \cdot \sqrt{\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)} + {\phi_1}^{2}} \]
                3. unswap-sqrN/A

                  \[\leadsto R \cdot \sqrt{\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)} + {\phi_1}^{2}} \]
                4. unpow2N/A

                  \[\leadsto R \cdot \sqrt{\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) + \color{blue}{\phi_1 \cdot \phi_1}} \]
                5. lower-hypot.f64N/A

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

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

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

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

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

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

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

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

                \[\leadsto R \cdot \mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_1\right) \]
              7. Step-by-step derivation
                1. Applied rewrites81.6%

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

                if -9.00000000000000026e60 < phi1

                1. Initial program 62.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 R \cdot \color{blue}{\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. unpow2N/A

                    \[\leadsto R \cdot \sqrt{\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} + {\phi_2}^{2}} \]
                  2. unpow2N/A

                    \[\leadsto R \cdot \sqrt{\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)} + {\phi_2}^{2}} \]
                  3. unswap-sqrN/A

                    \[\leadsto R \cdot \sqrt{\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)} + {\phi_2}^{2}} \]
                  4. unpow2N/A

                    \[\leadsto R \cdot \sqrt{\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) + \color{blue}{\phi_2 \cdot \phi_2}} \]
                  5. lower-hypot.f64N/A

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

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

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

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

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

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

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

                  \[\leadsto R \cdot \mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_2\right) \]
                7. Step-by-step derivation
                  1. Applied rewrites72.9%

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

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

                Alternative 6: 79.9% accurate, 2.4× speedup?

                \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -7.2 \cdot 10^{+61}:\\ \;\;\;\;\left(\left(\frac{\phi_2}{\phi_1} - 1\right) \cdot \phi_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_2\right) \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 -7.2e+61)
                   (* (* (- (/ phi2 phi1) 1.0) phi1) R)
                   (* (hypot (- 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 <= -7.2e+61) {
                		tmp = (((phi2 / phi1) - 1.0) * phi1) * R;
                	} else {
                		tmp = hypot((lambda1 - lambda2), phi2) * R;
                	}
                	return tmp;
                }
                
                assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
                public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                	double tmp;
                	if (phi1 <= -7.2e+61) {
                		tmp = (((phi2 / phi1) - 1.0) * phi1) * R;
                	} else {
                		tmp = Math.hypot((lambda1 - lambda2), 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 <= -7.2e+61:
                		tmp = (((phi2 / phi1) - 1.0) * phi1) * R
                	else:
                		tmp = math.hypot((lambda1 - lambda2), 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 <= -7.2e+61)
                		tmp = Float64(Float64(Float64(Float64(phi2 / phi1) - 1.0) * phi1) * R);
                	else
                		tmp = Float64(hypot(Float64(lambda1 - lambda2), 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 <= -7.2e+61)
                		tmp = (((phi2 / phi1) - 1.0) * phi1) * R;
                	else
                		tmp = hypot((lambda1 - lambda2), 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, -7.2e+61], N[(N[(N[(N[(phi2 / phi1), $MachinePrecision] - 1.0), $MachinePrecision] * phi1), $MachinePrecision] * R), $MachinePrecision], N[(N[Sqrt[N[(lambda1 - lambda2), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision] * 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 -7.2 \cdot 10^{+61}:\\
                \;\;\;\;\left(\left(\frac{\phi_2}{\phi_1} - 1\right) \cdot \phi_1\right) \cdot R\\
                
                \mathbf{else}:\\
                \;\;\;\;\mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_2\right) \cdot R\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if phi1 < -7.20000000000000021e61

                  1. Initial program 53.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 R \cdot \color{blue}{\left(-1 \cdot \left(\phi_1 \cdot \left(1 + -1 \cdot \frac{\phi_2}{\phi_1}\right)\right)\right)} \]
                  4. Step-by-step derivation
                    1. associate-*r*N/A

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

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

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

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

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

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

                      \[\leadsto R \cdot \left(\left(-\phi_1\right) \cdot \color{blue}{\left(1 - \frac{\phi_2}{\phi_1}\right)}\right) \]
                    8. lower-/.f6477.5

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

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

                  if -7.20000000000000021e61 < phi1

                  1. Initial program 62.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 R \cdot \color{blue}{\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. unpow2N/A

                      \[\leadsto R \cdot \sqrt{\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} + {\phi_2}^{2}} \]
                    2. unpow2N/A

                      \[\leadsto R \cdot \sqrt{\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)} + {\phi_2}^{2}} \]
                    3. unswap-sqrN/A

                      \[\leadsto R \cdot \sqrt{\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)} + {\phi_2}^{2}} \]
                    4. unpow2N/A

                      \[\leadsto R \cdot \sqrt{\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) + \color{blue}{\phi_2 \cdot \phi_2}} \]
                    5. lower-hypot.f64N/A

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

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

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

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

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

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

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

                    \[\leadsto R \cdot \mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_2\right) \]
                  7. Step-by-step derivation
                    1. Applied rewrites72.9%

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

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

                  Alternative 7: 67.3% accurate, 2.4× speedup?

                  \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -5.5 \cdot 10^{+60}:\\ \;\;\;\;\left(\left(\frac{\phi_2}{\phi_1} - 1\right) \cdot \phi_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(-\lambda_2, \phi_2\right) \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 -5.5e+60)
                     (* (* (- (/ phi2 phi1) 1.0) phi1) R)
                     (* (hypot (- 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 <= -5.5e+60) {
                  		tmp = (((phi2 / phi1) - 1.0) * phi1) * R;
                  	} else {
                  		tmp = hypot(-lambda2, phi2) * R;
                  	}
                  	return tmp;
                  }
                  
                  assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
                  public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                  	double tmp;
                  	if (phi1 <= -5.5e+60) {
                  		tmp = (((phi2 / phi1) - 1.0) * phi1) * R;
                  	} else {
                  		tmp = Math.hypot(-lambda2, 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 <= -5.5e+60:
                  		tmp = (((phi2 / phi1) - 1.0) * phi1) * R
                  	else:
                  		tmp = math.hypot(-lambda2, 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 <= -5.5e+60)
                  		tmp = Float64(Float64(Float64(Float64(phi2 / phi1) - 1.0) * phi1) * R);
                  	else
                  		tmp = Float64(hypot(Float64(-lambda2), 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 <= -5.5e+60)
                  		tmp = (((phi2 / phi1) - 1.0) * phi1) * R;
                  	else
                  		tmp = hypot(-lambda2, 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, -5.5e+60], N[(N[(N[(N[(phi2 / phi1), $MachinePrecision] - 1.0), $MachinePrecision] * phi1), $MachinePrecision] * R), $MachinePrecision], N[(N[Sqrt[(-lambda2) ^ 2 + phi2 ^ 2], $MachinePrecision] * 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 -5.5 \cdot 10^{+60}:\\
                  \;\;\;\;\left(\left(\frac{\phi_2}{\phi_1} - 1\right) \cdot \phi_1\right) \cdot R\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\mathsf{hypot}\left(-\lambda_2, \phi_2\right) \cdot R\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 2 regimes
                  2. if phi1 < -5.5000000000000001e60

                    1. Initial program 53.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 R \cdot \color{blue}{\left(-1 \cdot \left(\phi_1 \cdot \left(1 + -1 \cdot \frac{\phi_2}{\phi_1}\right)\right)\right)} \]
                    4. Step-by-step derivation
                      1. associate-*r*N/A

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

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

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

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

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

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

                        \[\leadsto R \cdot \left(\left(-\phi_1\right) \cdot \color{blue}{\left(1 - \frac{\phi_2}{\phi_1}\right)}\right) \]
                      8. lower-/.f6477.5

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

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

                    if -5.5000000000000001e60 < phi1

                    1. Initial program 62.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 R \cdot \color{blue}{\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. unpow2N/A

                        \[\leadsto R \cdot \sqrt{\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} + {\phi_2}^{2}} \]
                      2. unpow2N/A

                        \[\leadsto R \cdot \sqrt{\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)} + {\phi_2}^{2}} \]
                      3. unswap-sqrN/A

                        \[\leadsto R \cdot \sqrt{\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)} + {\phi_2}^{2}} \]
                      4. unpow2N/A

                        \[\leadsto R \cdot \sqrt{\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) + \color{blue}{\phi_2 \cdot \phi_2}} \]
                      5. lower-hypot.f64N/A

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

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

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

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

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

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

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

                      \[\leadsto R \cdot \mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_2\right) \]
                    7. Step-by-step derivation
                      1. Applied rewrites72.9%

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

                        \[\leadsto R \cdot \mathsf{hypot}\left(-1 \cdot \lambda_2, \phi_2\right) \]
                      3. Step-by-step derivation
                        1. Applied rewrites56.2%

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

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

                      Alternative 8: 50.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 -4.2 \cdot 10^{+124}:\\ \;\;\;\;\left(-\phi_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq -1.36 \cdot 10^{+16}:\\ \;\;\;\;\left(R - \frac{R \cdot \phi_1}{\phi_2}\right) \cdot \phi_2\\ \mathbf{elif}\;\phi_1 \leq 9 \cdot 10^{-290}:\\ \;\;\;\;\left(-\lambda_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot R\\ \end{array} \end{array} \]
                      NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                      (FPCore (R lambda1 lambda2 phi1 phi2)
                       :precision binary64
                       (if (<= phi1 -4.2e+124)
                         (* (- phi1) R)
                         (if (<= phi1 -1.36e+16)
                           (* (- R (/ (* R phi1) phi2)) phi2)
                           (if (<= phi1 9e-290) (* (- 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 <= -4.2e+124) {
                      		tmp = -phi1 * R;
                      	} else if (phi1 <= -1.36e+16) {
                      		tmp = (R - ((R * phi1) / phi2)) * phi2;
                      	} else if (phi1 <= 9e-290) {
                      		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 (phi1 <= (-4.2d+124)) then
                              tmp = -phi1 * r
                          else if (phi1 <= (-1.36d+16)) then
                              tmp = (r - ((r * phi1) / phi2)) * phi2
                          else if (phi1 <= 9d-290) 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 (phi1 <= -4.2e+124) {
                      		tmp = -phi1 * R;
                      	} else if (phi1 <= -1.36e+16) {
                      		tmp = (R - ((R * phi1) / phi2)) * phi2;
                      	} else if (phi1 <= 9e-290) {
                      		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 phi1 <= -4.2e+124:
                      		tmp = -phi1 * R
                      	elif phi1 <= -1.36e+16:
                      		tmp = (R - ((R * phi1) / phi2)) * phi2
                      	elif phi1 <= 9e-290:
                      		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 (phi1 <= -4.2e+124)
                      		tmp = Float64(Float64(-phi1) * R);
                      	elseif (phi1 <= -1.36e+16)
                      		tmp = Float64(Float64(R - Float64(Float64(R * phi1) / phi2)) * phi2);
                      	elseif (phi1 <= 9e-290)
                      		tmp = Float64(Float64(-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 <= -4.2e+124)
                      		tmp = -phi1 * R;
                      	elseif (phi1 <= -1.36e+16)
                      		tmp = (R - ((R * phi1) / phi2)) * phi2;
                      	elseif (phi1 <= 9e-290)
                      		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[phi1, -4.2e+124], N[((-phi1) * R), $MachinePrecision], If[LessEqual[phi1, -1.36e+16], N[(N[(R - N[(N[(R * phi1), $MachinePrecision] / phi2), $MachinePrecision]), $MachinePrecision] * phi2), $MachinePrecision], If[LessEqual[phi1, 9e-290], 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_1 \leq -4.2 \cdot 10^{+124}:\\
                      \;\;\;\;\left(-\phi_1\right) \cdot R\\
                      
                      \mathbf{elif}\;\phi_1 \leq -1.36 \cdot 10^{+16}:\\
                      \;\;\;\;\left(R - \frac{R \cdot \phi_1}{\phi_2}\right) \cdot \phi_2\\
                      
                      \mathbf{elif}\;\phi_1 \leq 9 \cdot 10^{-290}:\\
                      \;\;\;\;\left(-\lambda_1\right) \cdot R\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;\phi_2 \cdot R\\
                      
                      
                      \end{array}
                      \end{array}
                      
                      Derivation
                      1. Split input into 4 regimes
                      2. if phi1 < -4.20000000000000023e124

                        1. Initial program 48.0%

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

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

                            \[\leadsto R \cdot \color{blue}{\left(\mathsf{neg}\left(\phi_1\right)\right)} \]
                          2. lower-neg.f6482.6

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

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

                        if -4.20000000000000023e124 < phi1 < -1.36e16

                        1. Initial program 64.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 R \cdot \color{blue}{\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. unpow2N/A

                            \[\leadsto R \cdot \sqrt{\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} + {\phi_1}^{2}} \]
                          2. unpow2N/A

                            \[\leadsto R \cdot \sqrt{\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)} + {\phi_1}^{2}} \]
                          3. unswap-sqrN/A

                            \[\leadsto R \cdot \sqrt{\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)} + {\phi_1}^{2}} \]
                          4. unpow2N/A

                            \[\leadsto R \cdot \sqrt{\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) + \color{blue}{\phi_1 \cdot \phi_1}} \]
                          5. lower-hypot.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

                            \[\leadsto \color{blue}{\left(R - \frac{R \cdot \phi_1}{\phi_2}\right)} \cdot \phi_2 \]
                          5. lower--.f64N/A

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

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

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

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

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

                        if -1.36e16 < phi1 < 9e-290

                        1. Initial program 66.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 lambda1 around -inf

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

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

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

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

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

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

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

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

                            \[\leadsto R \cdot \left(\left(-\lambda_1\right) \cdot \cos \left(\color{blue}{\left(\phi_2 + \phi_1\right)} \cdot \frac{1}{2}\right)\right) \]
                          9. lower-+.f6422.2

                            \[\leadsto R \cdot \left(\left(-\lambda_1\right) \cdot \cos \left(\color{blue}{\left(\phi_2 + \phi_1\right)} \cdot 0.5\right)\right) \]
                        5. Applied rewrites22.2%

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

                          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) + \color{blue}{\frac{1}{2} \cdot \left(\lambda_1 \cdot \left(\phi_2 \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)}\right) \]
                        7. Step-by-step derivation
                          1. Applied rewrites21.2%

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

                            \[\leadsto R \cdot \left(-1 \cdot \lambda_1\right) \]
                          3. Step-by-step derivation
                            1. Applied rewrites19.3%

                              \[\leadsto R \cdot \left(-\lambda_1\right) \]

                            if 9e-290 < phi1

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

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

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

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

                            \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -4.2 \cdot 10^{+124}:\\ \;\;\;\;\left(-\phi_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq -1.36 \cdot 10^{+16}:\\ \;\;\;\;\left(R - \frac{R \cdot \phi_1}{\phi_2}\right) \cdot \phi_2\\ \mathbf{elif}\;\phi_1 \leq 9 \cdot 10^{-290}:\\ \;\;\;\;\left(-\lambda_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot R\\ \end{array} \]
                          6. Add Preprocessing

                          Alternative 9: 49.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 -4.5 \cdot 10^{+89}:\\ \;\;\;\;\left(-\phi_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq -1.36 \cdot 10^{+16}:\\ \;\;\;\;\left(R - \frac{\phi_1}{\phi_2} \cdot R\right) \cdot \phi_2\\ \mathbf{elif}\;\phi_1 \leq 9 \cdot 10^{-290}:\\ \;\;\;\;\left(-\lambda_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot R\\ \end{array} \end{array} \]
                          NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                          (FPCore (R lambda1 lambda2 phi1 phi2)
                           :precision binary64
                           (if (<= phi1 -4.5e+89)
                             (* (- phi1) R)
                             (if (<= phi1 -1.36e+16)
                               (* (- R (* (/ phi1 phi2) R)) phi2)
                               (if (<= phi1 9e-290) (* (- 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 <= -4.5e+89) {
                          		tmp = -phi1 * R;
                          	} else if (phi1 <= -1.36e+16) {
                          		tmp = (R - ((phi1 / phi2) * R)) * phi2;
                          	} else if (phi1 <= 9e-290) {
                          		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 (phi1 <= (-4.5d+89)) then
                                  tmp = -phi1 * r
                              else if (phi1 <= (-1.36d+16)) then
                                  tmp = (r - ((phi1 / phi2) * r)) * phi2
                              else if (phi1 <= 9d-290) 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 (phi1 <= -4.5e+89) {
                          		tmp = -phi1 * R;
                          	} else if (phi1 <= -1.36e+16) {
                          		tmp = (R - ((phi1 / phi2) * R)) * phi2;
                          	} else if (phi1 <= 9e-290) {
                          		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 phi1 <= -4.5e+89:
                          		tmp = -phi1 * R
                          	elif phi1 <= -1.36e+16:
                          		tmp = (R - ((phi1 / phi2) * R)) * phi2
                          	elif phi1 <= 9e-290:
                          		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 (phi1 <= -4.5e+89)
                          		tmp = Float64(Float64(-phi1) * R);
                          	elseif (phi1 <= -1.36e+16)
                          		tmp = Float64(Float64(R - Float64(Float64(phi1 / phi2) * R)) * phi2);
                          	elseif (phi1 <= 9e-290)
                          		tmp = Float64(Float64(-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 <= -4.5e+89)
                          		tmp = -phi1 * R;
                          	elseif (phi1 <= -1.36e+16)
                          		tmp = (R - ((phi1 / phi2) * R)) * phi2;
                          	elseif (phi1 <= 9e-290)
                          		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[phi1, -4.5e+89], N[((-phi1) * R), $MachinePrecision], If[LessEqual[phi1, -1.36e+16], N[(N[(R - N[(N[(phi1 / phi2), $MachinePrecision] * R), $MachinePrecision]), $MachinePrecision] * phi2), $MachinePrecision], If[LessEqual[phi1, 9e-290], 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_1 \leq -4.5 \cdot 10^{+89}:\\
                          \;\;\;\;\left(-\phi_1\right) \cdot R\\
                          
                          \mathbf{elif}\;\phi_1 \leq -1.36 \cdot 10^{+16}:\\
                          \;\;\;\;\left(R - \frac{\phi_1}{\phi_2} \cdot R\right) \cdot \phi_2\\
                          
                          \mathbf{elif}\;\phi_1 \leq 9 \cdot 10^{-290}:\\
                          \;\;\;\;\left(-\lambda_1\right) \cdot R\\
                          
                          \mathbf{else}:\\
                          \;\;\;\;\phi_2 \cdot R\\
                          
                          
                          \end{array}
                          \end{array}
                          
                          Derivation
                          1. Split input into 4 regimes
                          2. if phi1 < -4.5e89

                            1. Initial program 49.6%

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

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

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

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

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

                            if -4.5e89 < phi1 < -1.36e16

                            1. Initial program 65.0%

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

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

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

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

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

                                \[\leadsto \color{blue}{\left(R - \frac{R \cdot \phi_1}{\phi_2}\right)} \cdot \phi_2 \]
                              5. lower--.f64N/A

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

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

                                \[\leadsto \left(R - \color{blue}{R \cdot \frac{\phi_1}{\phi_2}}\right) \cdot \phi_2 \]
                              8. lower-/.f6469.3

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

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

                            if -1.36e16 < phi1 < 9e-290

                            1. Initial program 66.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 lambda1 around -inf

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

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

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

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

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

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

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

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

                                \[\leadsto R \cdot \left(\left(-\lambda_1\right) \cdot \cos \left(\color{blue}{\left(\phi_2 + \phi_1\right)} \cdot \frac{1}{2}\right)\right) \]
                              9. lower-+.f6422.2

                                \[\leadsto R \cdot \left(\left(-\lambda_1\right) \cdot \cos \left(\color{blue}{\left(\phi_2 + \phi_1\right)} \cdot 0.5\right)\right) \]
                            5. Applied rewrites22.2%

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

                              \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) + \color{blue}{\frac{1}{2} \cdot \left(\lambda_1 \cdot \left(\phi_2 \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)}\right) \]
                            7. Step-by-step derivation
                              1. Applied rewrites21.2%

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

                                \[\leadsto R \cdot \left(-1 \cdot \lambda_1\right) \]
                              3. Step-by-step derivation
                                1. Applied rewrites19.3%

                                  \[\leadsto R \cdot \left(-\lambda_1\right) \]

                                if 9e-290 < phi1

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

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

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

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

                                \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -4.5 \cdot 10^{+89}:\\ \;\;\;\;\left(-\phi_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq -1.36 \cdot 10^{+16}:\\ \;\;\;\;\left(R - \frac{\phi_1}{\phi_2} \cdot R\right) \cdot \phi_2\\ \mathbf{elif}\;\phi_1 \leq 9 \cdot 10^{-290}:\\ \;\;\;\;\left(-\lambda_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot R\\ \end{array} \]
                              6. Add Preprocessing

                              Alternative 10: 51.3% accurate, 8.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 -1.36 \cdot 10^{+16}:\\ \;\;\;\;\mathsf{fma}\left(R, \frac{-\phi_2}{\phi_1}, R\right) \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq 9 \cdot 10^{-290}:\\ \;\;\;\;\left(-\lambda_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot R\\ \end{array} \end{array} \]
                              NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                              (FPCore (R lambda1 lambda2 phi1 phi2)
                               :precision binary64
                               (if (<= phi1 -1.36e+16)
                                 (* (fma R (/ (- phi2) phi1) R) (- phi1))
                                 (if (<= phi1 9e-290) (* (- 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 <= -1.36e+16) {
                              		tmp = fma(R, (-phi2 / phi1), R) * -phi1;
                              	} else if (phi1 <= 9e-290) {
                              		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 (phi1 <= -1.36e+16)
                              		tmp = Float64(fma(R, Float64(Float64(-phi2) / phi1), R) * Float64(-phi1));
                              	elseif (phi1 <= 9e-290)
                              		tmp = Float64(Float64(-lambda1) * R);
                              	else
                              		tmp = Float64(phi2 * 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, -1.36e+16], N[(N[(R * N[((-phi2) / phi1), $MachinePrecision] + R), $MachinePrecision] * (-phi1)), $MachinePrecision], If[LessEqual[phi1, 9e-290], 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_1 \leq -1.36 \cdot 10^{+16}:\\
                              \;\;\;\;\mathsf{fma}\left(R, \frac{-\phi_2}{\phi_1}, R\right) \cdot \left(-\phi_1\right)\\
                              
                              \mathbf{elif}\;\phi_1 \leq 9 \cdot 10^{-290}:\\
                              \;\;\;\;\left(-\lambda_1\right) \cdot R\\
                              
                              \mathbf{else}:\\
                              \;\;\;\;\phi_2 \cdot R\\
                              
                              
                              \end{array}
                              \end{array}
                              
                              Derivation
                              1. Split input into 3 regimes
                              2. if phi1 < -1.36e16

                                1. Initial program 54.3%

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

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

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

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

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

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

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

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

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

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

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

                                    \[\leadsto \left(-\phi_1\right) \cdot \color{blue}{\mathsf{fma}\left(R, -1 \cdot \frac{\phi_2}{\phi_1}, R\right)} \]
                                  11. associate-*r/N/A

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

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

                                    \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(R, \frac{\color{blue}{\mathsf{neg}\left(\phi_2\right)}}{\phi_1}, R\right) \]
                                  14. lower-neg.f6473.6

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

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

                                if -1.36e16 < phi1 < 9e-290

                                1. Initial program 66.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 lambda1 around -inf

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

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

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

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

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

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

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

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

                                    \[\leadsto R \cdot \left(\left(-\lambda_1\right) \cdot \cos \left(\color{blue}{\left(\phi_2 + \phi_1\right)} \cdot \frac{1}{2}\right)\right) \]
                                  9. lower-+.f6422.2

                                    \[\leadsto R \cdot \left(\left(-\lambda_1\right) \cdot \cos \left(\color{blue}{\left(\phi_2 + \phi_1\right)} \cdot 0.5\right)\right) \]
                                5. Applied rewrites22.2%

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

                                  \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) + \color{blue}{\frac{1}{2} \cdot \left(\lambda_1 \cdot \left(\phi_2 \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)}\right) \]
                                7. Step-by-step derivation
                                  1. Applied rewrites21.2%

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

                                    \[\leadsto R \cdot \left(-1 \cdot \lambda_1\right) \]
                                  3. Step-by-step derivation
                                    1. Applied rewrites19.3%

                                      \[\leadsto R \cdot \left(-\lambda_1\right) \]

                                    if 9e-290 < phi1

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

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

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

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

                                    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.36 \cdot 10^{+16}:\\ \;\;\;\;\mathsf{fma}\left(R, \frac{-\phi_2}{\phi_1}, R\right) \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq 9 \cdot 10^{-290}:\\ \;\;\;\;\left(-\lambda_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot R\\ \end{array} \]
                                  6. Add Preprocessing

                                  Alternative 11: 51.3% accurate, 9.0× speedup?

                                  \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.36 \cdot 10^{+16}:\\ \;\;\;\;\left(\left(\frac{\phi_2}{\phi_1} - 1\right) \cdot \phi_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq 9 \cdot 10^{-290}:\\ \;\;\;\;\left(-\lambda_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot R\\ \end{array} \end{array} \]
                                  NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                  (FPCore (R lambda1 lambda2 phi1 phi2)
                                   :precision binary64
                                   (if (<= phi1 -1.36e+16)
                                     (* (* (- (/ phi2 phi1) 1.0) phi1) R)
                                     (if (<= phi1 9e-290) (* (- 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 <= -1.36e+16) {
                                  		tmp = (((phi2 / phi1) - 1.0) * phi1) * R;
                                  	} else if (phi1 <= 9e-290) {
                                  		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 (phi1 <= (-1.36d+16)) then
                                          tmp = (((phi2 / phi1) - 1.0d0) * phi1) * r
                                      else if (phi1 <= 9d-290) 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 (phi1 <= -1.36e+16) {
                                  		tmp = (((phi2 / phi1) - 1.0) * phi1) * R;
                                  	} else if (phi1 <= 9e-290) {
                                  		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 phi1 <= -1.36e+16:
                                  		tmp = (((phi2 / phi1) - 1.0) * phi1) * R
                                  	elif phi1 <= 9e-290:
                                  		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 (phi1 <= -1.36e+16)
                                  		tmp = Float64(Float64(Float64(Float64(phi2 / phi1) - 1.0) * phi1) * R);
                                  	elseif (phi1 <= 9e-290)
                                  		tmp = Float64(Float64(-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 <= -1.36e+16)
                                  		tmp = (((phi2 / phi1) - 1.0) * phi1) * R;
                                  	elseif (phi1 <= 9e-290)
                                  		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[phi1, -1.36e+16], N[(N[(N[(N[(phi2 / phi1), $MachinePrecision] - 1.0), $MachinePrecision] * phi1), $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi1, 9e-290], 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_1 \leq -1.36 \cdot 10^{+16}:\\
                                  \;\;\;\;\left(\left(\frac{\phi_2}{\phi_1} - 1\right) \cdot \phi_1\right) \cdot R\\
                                  
                                  \mathbf{elif}\;\phi_1 \leq 9 \cdot 10^{-290}:\\
                                  \;\;\;\;\left(-\lambda_1\right) \cdot R\\
                                  
                                  \mathbf{else}:\\
                                  \;\;\;\;\phi_2 \cdot R\\
                                  
                                  
                                  \end{array}
                                  \end{array}
                                  
                                  Derivation
                                  1. Split input into 3 regimes
                                  2. if phi1 < -1.36e16

                                    1. Initial program 54.3%

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

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

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

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

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

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

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

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

                                        \[\leadsto R \cdot \left(\left(-\phi_1\right) \cdot \color{blue}{\left(1 - \frac{\phi_2}{\phi_1}\right)}\right) \]
                                      8. lower-/.f6473.7

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

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

                                    if -1.36e16 < phi1 < 9e-290

                                    1. Initial program 66.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 lambda1 around -inf

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

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

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

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

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

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

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

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

                                        \[\leadsto R \cdot \left(\left(-\lambda_1\right) \cdot \cos \left(\color{blue}{\left(\phi_2 + \phi_1\right)} \cdot \frac{1}{2}\right)\right) \]
                                      9. lower-+.f6422.2

                                        \[\leadsto R \cdot \left(\left(-\lambda_1\right) \cdot \cos \left(\color{blue}{\left(\phi_2 + \phi_1\right)} \cdot 0.5\right)\right) \]
                                    5. Applied rewrites22.2%

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

                                      \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) + \color{blue}{\frac{1}{2} \cdot \left(\lambda_1 \cdot \left(\phi_2 \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)}\right) \]
                                    7. Step-by-step derivation
                                      1. Applied rewrites21.2%

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

                                        \[\leadsto R \cdot \left(-1 \cdot \lambda_1\right) \]
                                      3. Step-by-step derivation
                                        1. Applied rewrites19.3%

                                          \[\leadsto R \cdot \left(-\lambda_1\right) \]

                                        if 9e-290 < phi1

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

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

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

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

                                        \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.36 \cdot 10^{+16}:\\ \;\;\;\;\left(\left(\frac{\phi_2}{\phi_1} - 1\right) \cdot \phi_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq 9 \cdot 10^{-290}:\\ \;\;\;\;\left(-\lambda_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot R\\ \end{array} \]
                                      6. Add Preprocessing

                                      Alternative 12: 47.3% accurate, 10.7× speedup?

                                      \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -9 \cdot 10^{+60}:\\ \;\;\;\;\left(-\phi_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq -1.45 \cdot 10^{+16} \lor \neg \left(\phi_1 \leq 9 \cdot 10^{-290}\right):\\ \;\;\;\;\phi_2 \cdot R\\ \mathbf{else}:\\ \;\;\;\;\left(-\lambda_1\right) \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 -9e+60)
                                         (* (- phi1) R)
                                         (if (or (<= phi1 -1.45e+16) (not (<= phi1 9e-290)))
                                           (* phi2 R)
                                           (* (- lambda1) 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 <= -9e+60) {
                                      		tmp = -phi1 * R;
                                      	} else if ((phi1 <= -1.45e+16) || !(phi1 <= 9e-290)) {
                                      		tmp = phi2 * R;
                                      	} else {
                                      		tmp = -lambda1 * 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 <= (-9d+60)) then
                                              tmp = -phi1 * r
                                          else if ((phi1 <= (-1.45d+16)) .or. (.not. (phi1 <= 9d-290))) then
                                              tmp = phi2 * r
                                          else
                                              tmp = -lambda1 * 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 <= -9e+60) {
                                      		tmp = -phi1 * R;
                                      	} else if ((phi1 <= -1.45e+16) || !(phi1 <= 9e-290)) {
                                      		tmp = phi2 * R;
                                      	} else {
                                      		tmp = -lambda1 * 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 <= -9e+60:
                                      		tmp = -phi1 * R
                                      	elif (phi1 <= -1.45e+16) or not (phi1 <= 9e-290):
                                      		tmp = phi2 * R
                                      	else:
                                      		tmp = -lambda1 * 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 <= -9e+60)
                                      		tmp = Float64(Float64(-phi1) * R);
                                      	elseif ((phi1 <= -1.45e+16) || !(phi1 <= 9e-290))
                                      		tmp = Float64(phi2 * R);
                                      	else
                                      		tmp = Float64(Float64(-lambda1) * 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 <= -9e+60)
                                      		tmp = -phi1 * R;
                                      	elseif ((phi1 <= -1.45e+16) || ~((phi1 <= 9e-290)))
                                      		tmp = phi2 * R;
                                      	else
                                      		tmp = -lambda1 * 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, -9e+60], N[((-phi1) * R), $MachinePrecision], If[Or[LessEqual[phi1, -1.45e+16], N[Not[LessEqual[phi1, 9e-290]], $MachinePrecision]], N[(phi2 * R), $MachinePrecision], N[((-lambda1) * 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 -9 \cdot 10^{+60}:\\
                                      \;\;\;\;\left(-\phi_1\right) \cdot R\\
                                      
                                      \mathbf{elif}\;\phi_1 \leq -1.45 \cdot 10^{+16} \lor \neg \left(\phi_1 \leq 9 \cdot 10^{-290}\right):\\
                                      \;\;\;\;\phi_2 \cdot R\\
                                      
                                      \mathbf{else}:\\
                                      \;\;\;\;\left(-\lambda_1\right) \cdot R\\
                                      
                                      
                                      \end{array}
                                      \end{array}
                                      
                                      Derivation
                                      1. Split input into 3 regimes
                                      2. if phi1 < -9.00000000000000026e60

                                        1. Initial program 53.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 R \cdot \color{blue}{\left(-1 \cdot \phi_1\right)} \]
                                        4. Step-by-step derivation
                                          1. mul-1-negN/A

                                            \[\leadsto R \cdot \color{blue}{\left(\mathsf{neg}\left(\phi_1\right)\right)} \]
                                          2. lower-neg.f6474.4

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

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

                                        if -9.00000000000000026e60 < phi1 < -1.45e16 or 9e-290 < phi1

                                        1. Initial program 59.9%

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

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

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

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

                                        if -1.45e16 < phi1 < 9e-290

                                        1. Initial program 66.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 lambda1 around -inf

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

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

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

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

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

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

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

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

                                            \[\leadsto R \cdot \left(\left(-\lambda_1\right) \cdot \cos \left(\color{blue}{\left(\phi_2 + \phi_1\right)} \cdot \frac{1}{2}\right)\right) \]
                                          9. lower-+.f6422.2

                                            \[\leadsto R \cdot \left(\left(-\lambda_1\right) \cdot \cos \left(\color{blue}{\left(\phi_2 + \phi_1\right)} \cdot 0.5\right)\right) \]
                                        5. Applied rewrites22.2%

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

                                          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) + \color{blue}{\frac{1}{2} \cdot \left(\lambda_1 \cdot \left(\phi_2 \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)}\right) \]
                                        7. Step-by-step derivation
                                          1. Applied rewrites21.2%

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

                                            \[\leadsto R \cdot \left(-1 \cdot \lambda_1\right) \]
                                          3. Step-by-step derivation
                                            1. Applied rewrites19.3%

                                              \[\leadsto R \cdot \left(-\lambda_1\right) \]
                                          4. Recombined 3 regimes into one program.
                                          5. Final simplification32.2%

                                            \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -9 \cdot 10^{+60}:\\ \;\;\;\;\left(-\phi_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq -1.45 \cdot 10^{+16} \lor \neg \left(\phi_1 \leq 9 \cdot 10^{-290}\right):\\ \;\;\;\;\phi_2 \cdot R\\ \mathbf{else}:\\ \;\;\;\;\left(-\lambda_1\right) \cdot R\\ \end{array} \]
                                          6. Add Preprocessing

                                          Alternative 13: 37.6% 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 1.26 \cdot 10^{-20}:\\ \;\;\;\;\left(-\lambda_1\right) \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 1.26e-20) (* (- 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.26e-20) {
                                          		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.26d-20) 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.26e-20) {
                                          		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.26e-20:
                                          		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.26e-20)
                                          		tmp = Float64(Float64(-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 (phi2 <= 1.26e-20)
                                          		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.26e-20], 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.26 \cdot 10^{-20}:\\
                                          \;\;\;\;\left(-\lambda_1\right) \cdot R\\
                                          
                                          \mathbf{else}:\\
                                          \;\;\;\;\phi_2 \cdot R\\
                                          
                                          
                                          \end{array}
                                          \end{array}
                                          
                                          Derivation
                                          1. Split input into 2 regimes
                                          2. if phi2 < 1.26e-20

                                            1. Initial program 61.2%

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

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

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

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

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

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

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

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

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

                                                \[\leadsto R \cdot \left(\left(-\lambda_1\right) \cdot \cos \left(\color{blue}{\left(\phi_2 + \phi_1\right)} \cdot \frac{1}{2}\right)\right) \]
                                              9. lower-+.f6415.7

                                                \[\leadsto R \cdot \left(\left(-\lambda_1\right) \cdot \cos \left(\color{blue}{\left(\phi_2 + \phi_1\right)} \cdot 0.5\right)\right) \]
                                            5. Applied rewrites15.7%

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

                                              \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) + \color{blue}{\frac{1}{2} \cdot \left(\lambda_1 \cdot \left(\phi_2 \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)}\right) \]
                                            7. Step-by-step derivation
                                              1. Applied rewrites16.7%

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

                                                \[\leadsto R \cdot \left(-1 \cdot \lambda_1\right) \]
                                              3. Step-by-step derivation
                                                1. Applied rewrites14.9%

                                                  \[\leadsto R \cdot \left(-\lambda_1\right) \]

                                                if 1.26e-20 < phi2

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

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

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

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

                                                \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.26 \cdot 10^{-20}:\\ \;\;\;\;\left(-\lambda_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot R\\ \end{array} \]
                                              6. Add Preprocessing

                                              Alternative 14: 31.0% accurate, 46.5× speedup?

                                              \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \phi_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 (* phi2 R))
                                              assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                                              double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                              	return phi2 * 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 = phi2 * 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 phi2 * R;
                                              }
                                              
                                              [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
                                              def code(R, lambda1, lambda2, phi1, phi2):
                                              	return phi2 * R
                                              
                                              R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                                              function code(R, lambda1, lambda2, phi1, phi2)
                                              	return Float64(phi2 * R)
                                              end
                                              
                                              R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
                                              function tmp = code(R, lambda1, lambda2, phi1, phi2)
                                              	tmp = phi2 * 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[(phi2 * R), $MachinePrecision]
                                              
                                              \begin{array}{l}
                                              [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                                              \\
                                              \phi_2 \cdot R
                                              \end{array}
                                              
                                              Derivation
                                              1. Initial program 60.7%

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

                                                \[\leadsto \color{blue}{R \cdot \phi_2} \]
                                              4. Step-by-step derivation
                                                1. lower-*.f6418.2

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

                                                \[\leadsto \color{blue}{R \cdot \phi_2} \]
                                              6. Final simplification18.2%

                                                \[\leadsto \phi_2 \cdot R \]
                                              7. Add Preprocessing

                                              Reproduce

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