Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.5% → 90.6%
Time: 12.0s
Alternatives: 15
Speedup: 8.5×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 15 alternatives:

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

Initial Program: 59.5% accurate, 1.0× speedup?

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

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

Alternative 1: 90.6% accurate, 1.2× speedup?

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

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


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

    1. Initial program 52.4%

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

      \[\leadsto 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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.2e15 < phi1

    1. Initial program 58.3%

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

      \[\leadsto 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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 85.1% accurate, 1.2× speedup?

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

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


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

    1. Initial program 52.4%

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

      \[\leadsto 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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.2e15 < phi1

    1. Initial program 58.3%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
    6. 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}}} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      1. Initial program 52.4%

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

        \[\leadsto 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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\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 rewrites74.8%

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

        if -3.8e15 < phi1

        1. Initial program 58.3%

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
        6. 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}}} \]
        7. Step-by-step derivation
          1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        Alternative 4: 82.2% accurate, 1.7× speedup?

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

          1. Initial program 45.8%

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
          6. 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)} \]
          7. Step-by-step derivation
            1. mul-1-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          if -1.1000000000000001e120 < phi1 < -2.5e15

          1. Initial program 63.1%

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

              \[\leadsto \color{blue}{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. *-commutativeN/A

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

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

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

          if -2.5e15 < phi1

          1. Initial program 58.3%

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
          6. 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}}} \]
          7. Step-by-step derivation
            1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          Alternative 5: 82.2% accurate, 1.7× speedup?

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

            1. Initial program 45.8%

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
            6. 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)} \]
            7. Step-by-step derivation
              1. mul-1-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if -1.1000000000000001e120 < phi1 < -2.5e15

            1. Initial program 63.1%

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

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

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

                \[\leadsto R \cdot \sqrt{\color{blue}{\left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} + \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)} \]
              4. lower-fma.f6463.1

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

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

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

                \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\phi_1 - \phi_2, \phi_1 - \phi_2, \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)}\right)} \]
              8. swap-sqrN/A

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

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

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

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

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

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

            if -2.5e15 < phi1

            1. Initial program 58.3%

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
            6. 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}}} \]
            7. Step-by-step derivation
              1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            Alternative 6: 80.9% accurate, 2.3× speedup?

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

              1. Initial program 44.8%

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

                \[\leadsto 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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
              6. 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)} \]
              7. Step-by-step derivation
                1. mul-1-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              if -1.45000000000000008e118 < phi1 < -4e15

              1. Initial program 65.6%

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

                \[\leadsto 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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                if -4e15 < phi1

                1. Initial program 58.3%

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

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
                6. 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}}} \]
                7. Step-by-step derivation
                  1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                Alternative 7: 69.0% accurate, 2.3× speedup?

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

                  1. Initial program 44.8%

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

                    \[\leadsto 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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
                  6. 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)} \]
                  7. Step-by-step derivation
                    1. mul-1-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  if -1.45000000000000008e118 < phi1 < -1.02000000000000001e-85

                  1. Initial program 61.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 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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \color{blue}{\lambda_2}\right) \]
                    2. Step-by-step derivation
                      1. lift-*.f64N/A

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

                        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right) \cdot R} \]
                      3. lower-*.f6454.0

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

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

                    if -1.02000000000000001e-85 < phi1

                    1. Initial program 58.6%

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

                      \[\leadsto 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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
                    6. 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}}} \]
                    7. Step-by-step derivation
                      1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.45 \cdot 10^{+118}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(R, \frac{\phi_2}{-\phi_1}, R\right)\\ \mathbf{elif}\;\phi_1 \leq -1.02 \cdot 10^{-85}:\\ \;\;\;\;R \cdot \sqrt{\mathsf{fma}\left(\lambda_1 - \lambda_2, \lambda_1 - \lambda_2, \phi_1 \cdot \phi_1\right)}\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, -\lambda_2\right)\\ \end{array} \]
                      6. Add Preprocessing

                      Alternative 8: 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_2 \leq 6.8 \cdot 10^{+47}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot \mathsf{fma}\left(R, \frac{\phi_1}{-\phi_2}, R\right)\\ \end{array} \end{array} \]
                      NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                      (FPCore (R lambda1 lambda2 phi1 phi2)
                       :precision binary64
                       (if (<= phi2 6.8e+47)
                         (* R (hypot phi1 (- lambda1 lambda2)))
                         (* phi2 (fma R (/ phi1 (- phi2)) R))))
                      assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                      double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                      	double tmp;
                      	if (phi2 <= 6.8e+47) {
                      		tmp = R * hypot(phi1, (lambda1 - lambda2));
                      	} else {
                      		tmp = phi2 * fma(R, (phi1 / -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 <= 6.8e+47)
                      		tmp = Float64(R * hypot(phi1, Float64(lambda1 - lambda2)));
                      	else
                      		tmp = Float64(phi2 * fma(R, Float64(phi1 / 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[phi2, 6.8e+47], N[(R * N[Sqrt[phi1 ^ 2 + N[(lambda1 - lambda2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[(phi2 * N[(R * N[(phi1 / (-phi2)), $MachinePrecision] + R), $MachinePrecision]), $MachinePrecision]]
                      
                      \begin{array}{l}
                      [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                      \\
                      \begin{array}{l}
                      \mathbf{if}\;\phi_2 \leq 6.8 \cdot 10^{+47}:\\
                      \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;\phi_2 \cdot \mathsf{fma}\left(R, \frac{\phi_1}{-\phi_2}, R\right)\\
                      
                      
                      \end{array}
                      \end{array}
                      
                      Derivation
                      1. Split input into 2 regimes
                      2. if phi2 < 6.7999999999999996e47

                        1. Initial program 59.6%

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

                          \[\leadsto 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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                          if 6.7999999999999996e47 < phi2

                          1. Initial program 45.8%

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

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

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

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

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

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

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

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

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

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

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

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

                            \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\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. lower-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

                        Alternative 9: 67.0% accurate, 6.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 -4.5 \cdot 10^{+15}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(R, \frac{\phi_2}{-\phi_1}, R\right)\\ \mathbf{elif}\;\phi_1 \leq 1.6 \cdot 10^{-202}:\\ \;\;\;\;R \cdot \sqrt{\mathsf{fma}\left(\lambda_1 - \lambda_2, \lambda_1 - \lambda_2, \phi_2 \cdot \phi_2\right)}\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot \mathsf{fma}\left(R, \frac{\phi_1}{-\phi_2}, R\right)\\ \end{array} \end{array} \]
                        NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                        (FPCore (R lambda1 lambda2 phi1 phi2)
                         :precision binary64
                         (if (<= phi1 -4.5e+15)
                           (* (- phi1) (fma R (/ phi2 (- phi1)) R))
                           (if (<= phi1 1.6e-202)
                             (* R (sqrt (fma (- lambda1 lambda2) (- lambda1 lambda2) (* phi2 phi2))))
                             (* phi2 (fma R (/ phi1 (- phi2)) R)))))
                        assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                        double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                        	double tmp;
                        	if (phi1 <= -4.5e+15) {
                        		tmp = -phi1 * fma(R, (phi2 / -phi1), R);
                        	} else if (phi1 <= 1.6e-202) {
                        		tmp = R * sqrt(fma((lambda1 - lambda2), (lambda1 - lambda2), (phi2 * phi2)));
                        	} else {
                        		tmp = phi2 * fma(R, (phi1 / -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+15)
                        		tmp = Float64(Float64(-phi1) * fma(R, Float64(phi2 / Float64(-phi1)), R));
                        	elseif (phi1 <= 1.6e-202)
                        		tmp = Float64(R * sqrt(fma(Float64(lambda1 - lambda2), Float64(lambda1 - lambda2), Float64(phi2 * phi2))));
                        	else
                        		tmp = Float64(phi2 * fma(R, Float64(phi1 / 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, -4.5e+15], N[((-phi1) * N[(R * N[(phi2 / (-phi1)), $MachinePrecision] + R), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 1.6e-202], N[(R * N[Sqrt[N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision] + N[(phi2 * phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(phi2 * N[(R * N[(phi1 / (-phi2)), $MachinePrecision] + R), $MachinePrecision]), $MachinePrecision]]]
                        
                        \begin{array}{l}
                        [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                        \\
                        \begin{array}{l}
                        \mathbf{if}\;\phi_1 \leq -4.5 \cdot 10^{+15}:\\
                        \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(R, \frac{\phi_2}{-\phi_1}, R\right)\\
                        
                        \mathbf{elif}\;\phi_1 \leq 1.6 \cdot 10^{-202}:\\
                        \;\;\;\;R \cdot \sqrt{\mathsf{fma}\left(\lambda_1 - \lambda_2, \lambda_1 - \lambda_2, \phi_2 \cdot \phi_2\right)}\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;\phi_2 \cdot \mathsf{fma}\left(R, \frac{\phi_1}{-\phi_2}, R\right)\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 3 regimes
                        2. if phi1 < -4.5e15

                          1. Initial program 51.6%

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

                            \[\leadsto 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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

                            \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
                          6. 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)} \]
                          7. Step-by-step derivation
                            1. mul-1-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                          if -4.5e15 < phi1 < 1.6000000000000001e-202

                          1. Initial program 62.6%

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

                            \[\leadsto 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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

                            \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
                          6. 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}}} \]
                          7. Step-by-step derivation
                            1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

                              \[\leadsto R \cdot \mathsf{hypot}\left(\phi_2, \lambda_1 - \color{blue}{\lambda_2}\right) \]
                            2. Step-by-step derivation
                              1. lift-*.f64N/A

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

                                \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_2, \lambda_1 - \lambda_2\right) \cdot R} \]
                              3. lower-*.f6489.9

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

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

                            if 1.6000000000000001e-202 < phi1

                            1. Initial program 55.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 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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

                              \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\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. lower-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

                            \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -4.5 \cdot 10^{+15}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(R, \frac{\phi_2}{-\phi_1}, R\right)\\ \mathbf{elif}\;\phi_1 \leq 1.6 \cdot 10^{-202}:\\ \;\;\;\;R \cdot \sqrt{\mathsf{fma}\left(\lambda_1 - \lambda_2, \lambda_1 - \lambda_2, \phi_2 \cdot \phi_2\right)}\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot \mathsf{fma}\left(R, \frac{\phi_1}{-\phi_2}, R\right)\\ \end{array} \]
                          13. Add Preprocessing

                          Alternative 10: 66.4% accurate, 6.2× speedup?

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

                            1. Initial program 55.6%

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

                              \[\leadsto 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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

                              \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
                            6. 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)} \]
                            7. Step-by-step derivation
                              1. mul-1-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            if -2.2500000000000001e-167 < phi2 < 4.00000000000000009e-46

                            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 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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

                                \[\leadsto R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \color{blue}{\lambda_2}\right) \]
                              2. Step-by-step derivation
                                1. lift-*.f64N/A

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

                                  \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right) \cdot R} \]
                                3. lower-*.f6487.2

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

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

                              if 4.00000000000000009e-46 < phi2

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

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

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

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

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

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

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

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

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

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

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

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

                              \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -2.25 \cdot 10^{-167}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(R, \frac{\phi_2}{-\phi_1}, R\right)\\ \mathbf{elif}\;\phi_2 \leq 4 \cdot 10^{-46}:\\ \;\;\;\;R \cdot \sqrt{\mathsf{fma}\left(\lambda_1 - \lambda_2, \lambda_1 - \lambda_2, \phi_1 \cdot \phi_1\right)}\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{fma}\left(\phi_2, \frac{\phi_1}{-\phi_2}, \phi_2\right)\\ \end{array} \]
                            10. Add Preprocessing

                            Alternative 11: 60.5% 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 -4 \cdot 10^{+15}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(R, \frac{\phi_2}{-\phi_1}, R\right)\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right)\\ \end{array} \end{array} \]
                            NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                            (FPCore (R lambda1 lambda2 phi1 phi2)
                             :precision binary64
                             (if (<= phi1 -4e+15)
                               (* (- phi1) (fma R (/ phi2 (- phi1)) R))
                               (* phi2 (- R (* phi1 (/ R phi2))))))
                            assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                            double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                            	double tmp;
                            	if (phi1 <= -4e+15) {
                            		tmp = -phi1 * fma(R, (phi2 / -phi1), R);
                            	} else {
                            		tmp = phi2 * (R - (phi1 * (R / phi2)));
                            	}
                            	return tmp;
                            }
                            
                            R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                            function code(R, lambda1, lambda2, phi1, phi2)
                            	tmp = 0.0
                            	if (phi1 <= -4e+15)
                            		tmp = Float64(Float64(-phi1) * fma(R, Float64(phi2 / Float64(-phi1)), R));
                            	else
                            		tmp = Float64(phi2 * Float64(R - Float64(phi1 * Float64(R / phi2))));
                            	end
                            	return tmp
                            end
                            
                            NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                            code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -4e+15], N[((-phi1) * N[(R * N[(phi2 / (-phi1)), $MachinePrecision] + R), $MachinePrecision]), $MachinePrecision], N[(phi2 * N[(R - N[(phi1 * N[(R / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
                            
                            \begin{array}{l}
                            [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                            \\
                            \begin{array}{l}
                            \mathbf{if}\;\phi_1 \leq -4 \cdot 10^{+15}:\\
                            \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(R, \frac{\phi_2}{-\phi_1}, R\right)\\
                            
                            \mathbf{else}:\\
                            \;\;\;\;\phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right)\\
                            
                            
                            \end{array}
                            \end{array}
                            
                            Derivation
                            1. Split input into 2 regimes
                            2. if phi1 < -4e15

                              1. Initial program 52.4%

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

                                \[\leadsto 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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

                                \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
                              6. 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)} \]
                              7. Step-by-step derivation
                                1. mul-1-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                              if -4e15 < phi1

                              1. Initial program 58.3%

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

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

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

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

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

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

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

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

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

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

                              \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -4 \cdot 10^{+15}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(R, \frac{\phi_2}{-\phi_1}, R\right)\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right)\\ \end{array} \]
                            5. Add Preprocessing

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

                              1. Initial program 50.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 phi1 around -inf

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

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

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

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

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

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

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

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

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

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

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

                              if -9.20000000000000001e-5 < phi1

                              1. Initial program 58.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}{\phi_2 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_1}{\phi_2}\right)} \]
                              4. Step-by-step derivation
                                1. lower-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

                              1. Initial program 45.8%

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

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

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

                              if -3.70000000000000013e121 < phi1

                              1. Initial program 58.8%

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

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

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

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

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

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

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

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

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

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

                            Alternative 14: 52.3% accurate, 19.9× speedup?

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

                              1. Initial program 52.4%

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

                                \[\leadsto 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.f6461.4

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

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

                              if -3.8e15 < phi1

                              1. Initial program 58.3%

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

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

                                  \[\leadsto \color{blue}{\phi_2 \cdot R} \]
                                2. lower-*.f6417.5

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

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

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

                            Alternative 15: 31.3% accurate, 46.5× speedup?

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

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

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

                                \[\leadsto \color{blue}{\phi_2 \cdot R} \]
                              2. lower-*.f6417.5

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

                              \[\leadsto \color{blue}{\phi_2 \cdot R} \]
                            6. Final simplification17.5%

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

                            Reproduce

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