Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.0% → 90.7%
Time: 9.5s
Alternatives: 12
Speedup: 2.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 12 alternatives:

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

Initial Program: 60.0% accurate, 1.0× speedup?

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

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

Alternative 1: 90.7% accurate, 1.2× speedup?

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

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


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

    1. Initial program 63.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0420000000000000026 < phi2

    1. Initial program 49.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 86.2% accurate, 1.2× speedup?

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

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


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

    1. Initial program 63.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.94999999999999996 < phi2

    1. Initial program 49.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Alternative 3: 79.5% accurate, 1.3× speedup?

    \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -3 \cdot 10^{+193}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(-0.5 \cdot \phi_1\right), \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -56000000000000:\\ \;\;\;\;\phi_2 \cdot \mathsf{fma}\left(-1, \frac{R \cdot \phi_1}{\phi_2}, R\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 - \lambda_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 (<= phi1 -3e+193)
       (* R (hypot (* lambda1 (cos (* -0.5 phi1))) phi1))
       (if (<= phi1 -56000000000000.0)
         (* phi2 (fma -1.0 (/ (* R phi1) phi2) R))
         (* R (hypot (- lambda1 lambda2) 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 <= -3e+193) {
    		tmp = R * hypot((lambda1 * cos((-0.5 * phi1))), phi1);
    	} else if (phi1 <= -56000000000000.0) {
    		tmp = phi2 * fma(-1.0, ((R * phi1) / phi2), R);
    	} else {
    		tmp = R * hypot((lambda1 - lambda2), 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 <= -3e+193)
    		tmp = Float64(R * hypot(Float64(lambda1 * cos(Float64(-0.5 * phi1))), phi1));
    	elseif (phi1 <= -56000000000000.0)
    		tmp = Float64(phi2 * fma(-1.0, Float64(Float64(R * phi1) / phi2), R));
    	else
    		tmp = Float64(R * hypot(Float64(lambda1 - lambda2), 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, -3e+193], N[(R * N[Sqrt[N[(lambda1 * N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, -56000000000000.0], N[(phi2 * N[(-1.0 * N[(N[(R * phi1), $MachinePrecision] / phi2), $MachinePrecision] + R), $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(lambda1 - lambda2), $MachinePrecision] ^ 2 + phi2 ^ 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 \cdot 10^{+193}:\\
    \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(-0.5 \cdot \phi_1\right), \phi_1\right)\\
    
    \mathbf{elif}\;\phi_1 \leq -56000000000000:\\
    \;\;\;\;\phi_2 \cdot \mathsf{fma}\left(-1, \frac{R \cdot \phi_1}{\phi_2}, R\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_2\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if phi1 < -3e193

      1. Initial program 44.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -3e193 < phi1 < -5.6e13

        1. Initial program 71.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \phi_2 \cdot \mathsf{fma}\left(-1, \color{blue}{\frac{R \cdot \phi_1}{\phi_2}}, R\right) \]
          5. lower-*.f6458.2

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

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

        if -5.6e13 < phi1

        1. Initial program 59.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          Alternative 4: 80.2% accurate, 2.4× speedup?

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

            1. Initial program 62.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \phi_2 \cdot \mathsf{fma}\left(-1, \color{blue}{\frac{R \cdot \phi_1}{\phi_2}}, R\right) \]
              5. lower-*.f6463.3

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

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

              \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{R \cdot \phi_2} \]
            10. Step-by-step derivation
              1. Applied rewrites42.5%

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

                \[\leadsto R \cdot \left(\phi_2 + \color{blue}{-1 \cdot \phi_1}\right) \]
              3. Step-by-step derivation
                1. Applied rewrites56.8%

                  \[\leadsto \left(\phi_2 - \phi_1\right) \cdot R \]

                if -5.6e13 < phi1

                1. Initial program 59.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  Alternative 5: 58.4% accurate, 6.3× speedup?

                  \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 6.2 \cdot 10^{+136}:\\ \;\;\;\;\phi_2 \cdot \frac{\left(\phi_2 - \phi_1\right) \cdot R}{\phi_2}\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(0.0026041666666666665, \lambda_2 \cdot \left(\phi_2 \cdot \phi_2\right), -0.125 \cdot \lambda_2\right), \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 (<= lambda2 6.2e+136)
                     (* phi2 (/ (* (- phi2 phi1) R) phi2))
                     (*
                      R
                      (fma
                       (* phi2 phi2)
                       (fma 0.0026041666666666665 (* lambda2 (* phi2 phi2)) (* -0.125 lambda2))
                       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 (lambda2 <= 6.2e+136) {
                  		tmp = phi2 * (((phi2 - phi1) * R) / phi2);
                  	} else {
                  		tmp = R * fma((phi2 * phi2), fma(0.0026041666666666665, (lambda2 * (phi2 * phi2)), (-0.125 * lambda2)), 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 (lambda2 <= 6.2e+136)
                  		tmp = Float64(phi2 * Float64(Float64(Float64(phi2 - phi1) * R) / phi2));
                  	else
                  		tmp = Float64(R * fma(Float64(phi2 * phi2), fma(0.0026041666666666665, Float64(lambda2 * Float64(phi2 * phi2)), Float64(-0.125 * lambda2)), 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[lambda2, 6.2e+136], N[(phi2 * N[(N[(N[(phi2 - phi1), $MachinePrecision] * R), $MachinePrecision] / phi2), $MachinePrecision]), $MachinePrecision], N[(R * N[(N[(phi2 * phi2), $MachinePrecision] * N[(0.0026041666666666665 * N[(lambda2 * N[(phi2 * phi2), $MachinePrecision]), $MachinePrecision] + N[(-0.125 * lambda2), $MachinePrecision]), $MachinePrecision] + lambda2), $MachinePrecision]), $MachinePrecision]]
                  
                  \begin{array}{l}
                  [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;\lambda_2 \leq 6.2 \cdot 10^{+136}:\\
                  \;\;\;\;\phi_2 \cdot \frac{\left(\phi_2 - \phi_1\right) \cdot R}{\phi_2}\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;R \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(0.0026041666666666665, \lambda_2 \cdot \left(\phi_2 \cdot \phi_2\right), -0.125 \cdot \lambda_2\right), \lambda_2\right)\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 2 regimes
                  2. if lambda2 < 6.19999999999999967e136

                    1. Initial program 61.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \phi_2 \cdot \mathsf{fma}\left(-1, \color{blue}{\frac{R \cdot \phi_1}{\phi_2}}, R\right) \]
                      5. lower-*.f6430.4

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

                      \[\leadsto \color{blue}{\phi_2 \cdot \mathsf{fma}\left(-1, \frac{R \cdot \phi_1}{\phi_2}, R\right)} \]
                    9. Step-by-step derivation
                      1. Applied rewrites31.7%

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

                        \[\leadsto \phi_2 \cdot \frac{-1 \cdot \left(R \cdot \phi_1\right) + R \cdot \phi_2}{\color{blue}{\phi_2}} \]
                      3. Step-by-step derivation
                        1. Applied rewrites30.8%

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

                        if 6.19999999999999967e136 < lambda2

                        1. Initial program 48.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            \[\leadsto R \cdot \left(\lambda_2 + {\phi_2}^{2} \cdot \color{blue}{\left(\frac{-1}{8} \cdot \lambda_2 + \frac{1}{384} \cdot \left(\lambda_2 \cdot {\phi_2}^{2}\right)\right)}\right) \]
                          3. Step-by-step derivation
                            1. Applied rewrites53.4%

                              \[\leadsto R \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(0.0026041666666666665, \color{blue}{\lambda_2 \cdot \left(\phi_2 \cdot \phi_2\right)}, -0.125 \cdot \lambda_2\right), \lambda_2\right) \]
                          4. Recombined 2 regimes into one program.
                          5. Add Preprocessing

                          Alternative 6: 55.8% accurate, 6.5× speedup?

                          \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \left(\phi_2 - \phi_1\right) \cdot R\\ \mathbf{if}\;\phi_2 \leq 1.45 \cdot 10^{-254}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_2 \leq 5.8 \cdot 10^{-86}:\\ \;\;\;\;R \cdot \mathsf{fma}\left(-0.125 \cdot \lambda_2, \phi_2 \cdot \phi_2, \lambda_2\right)\\ \mathbf{elif}\;\phi_2 \leq 5 \cdot 10^{+72}:\\ \;\;\;\;\phi_1 \cdot \mathsf{fma}\left(R, \frac{\phi_2}{\phi_1}, -R\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \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
                           (let* ((t_0 (* (- phi2 phi1) R)))
                             (if (<= phi2 1.45e-254)
                               t_0
                               (if (<= phi2 5.8e-86)
                                 (* R (fma (* -0.125 lambda2) (* phi2 phi2) lambda2))
                                 (if (<= phi2 5e+72) (* phi1 (fma R (/ phi2 phi1) (- R))) t_0)))))
                          assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                          double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                          	double t_0 = (phi2 - phi1) * R;
                          	double tmp;
                          	if (phi2 <= 1.45e-254) {
                          		tmp = t_0;
                          	} else if (phi2 <= 5.8e-86) {
                          		tmp = R * fma((-0.125 * lambda2), (phi2 * phi2), lambda2);
                          	} else if (phi2 <= 5e+72) {
                          		tmp = phi1 * fma(R, (phi2 / phi1), -R);
                          	} else {
                          		tmp = t_0;
                          	}
                          	return tmp;
                          }
                          
                          R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                          function code(R, lambda1, lambda2, phi1, phi2)
                          	t_0 = Float64(Float64(phi2 - phi1) * R)
                          	tmp = 0.0
                          	if (phi2 <= 1.45e-254)
                          		tmp = t_0;
                          	elseif (phi2 <= 5.8e-86)
                          		tmp = Float64(R * fma(Float64(-0.125 * lambda2), Float64(phi2 * phi2), lambda2));
                          	elseif (phi2 <= 5e+72)
                          		tmp = Float64(phi1 * fma(R, Float64(phi2 / phi1), Float64(-R)));
                          	else
                          		tmp = t_0;
                          	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_] := Block[{t$95$0 = N[(N[(phi2 - phi1), $MachinePrecision] * R), $MachinePrecision]}, If[LessEqual[phi2, 1.45e-254], t$95$0, If[LessEqual[phi2, 5.8e-86], N[(R * N[(N[(-0.125 * lambda2), $MachinePrecision] * N[(phi2 * phi2), $MachinePrecision] + lambda2), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 5e+72], N[(phi1 * N[(R * N[(phi2 / phi1), $MachinePrecision] + (-R)), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
                          
                          \begin{array}{l}
                          [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                          \\
                          \begin{array}{l}
                          t_0 := \left(\phi_2 - \phi_1\right) \cdot R\\
                          \mathbf{if}\;\phi_2 \leq 1.45 \cdot 10^{-254}:\\
                          \;\;\;\;t\_0\\
                          
                          \mathbf{elif}\;\phi_2 \leq 5.8 \cdot 10^{-86}:\\
                          \;\;\;\;R \cdot \mathsf{fma}\left(-0.125 \cdot \lambda_2, \phi_2 \cdot \phi_2, \lambda_2\right)\\
                          
                          \mathbf{elif}\;\phi_2 \leq 5 \cdot 10^{+72}:\\
                          \;\;\;\;\phi_1 \cdot \mathsf{fma}\left(R, \frac{\phi_2}{\phi_1}, -R\right)\\
                          
                          \mathbf{else}:\\
                          \;\;\;\;t\_0\\
                          
                          
                          \end{array}
                          \end{array}
                          
                          Derivation
                          1. Split input into 3 regimes
                          2. if phi2 < 1.45e-254 or 4.99999999999999992e72 < phi2

                            1. Initial program 57.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                \[\leadsto \phi_2 \cdot \mathsf{fma}\left(-1, \color{blue}{\frac{R \cdot \phi_1}{\phi_2}}, R\right) \]
                              5. lower-*.f6435.2

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

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

                              \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{R \cdot \phi_2} \]
                            10. Step-by-step derivation
                              1. Applied rewrites29.5%

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

                                \[\leadsto R \cdot \left(\phi_2 + \color{blue}{-1 \cdot \phi_1}\right) \]
                              3. Step-by-step derivation
                                1. Applied rewrites33.1%

                                  \[\leadsto \left(\phi_2 - \phi_1\right) \cdot R \]

                                if 1.45e-254 < phi2 < 5.7999999999999998e-86

                                1. Initial program 77.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                  \[\leadsto R \cdot \left(\lambda_2 \cdot \color{blue}{\cos \left(\frac{-1}{2} \cdot \phi_2\right)}\right) \]
                                7. Step-by-step derivation
                                  1. Applied rewrites39.0%

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

                                    \[\leadsto R \cdot \left(\lambda_2 + \frac{-1}{8} \cdot \color{blue}{\left(\lambda_2 \cdot {\phi_2}^{2}\right)}\right) \]
                                  3. Step-by-step derivation
                                    1. Applied rewrites39.0%

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

                                    if 5.7999999999999998e-86 < phi2 < 4.99999999999999992e72

                                    1. Initial program 59.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                        \[\leadsto \phi_2 \cdot \mathsf{fma}\left(-1, \color{blue}{\frac{R \cdot \phi_1}{\phi_2}}, R\right) \]
                                      5. lower-*.f6423.2

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

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

                                      \[\leadsto \phi_1 \cdot \color{blue}{\left(-1 \cdot R + \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                                    10. Step-by-step derivation
                                      1. Applied rewrites35.5%

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

                                      \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.45 \cdot 10^{-254}:\\ \;\;\;\;\left(\phi_2 - \phi_1\right) \cdot R\\ \mathbf{elif}\;\phi_2 \leq 5.8 \cdot 10^{-86}:\\ \;\;\;\;R \cdot \mathsf{fma}\left(-0.125 \cdot \lambda_2, \phi_2 \cdot \phi_2, \lambda_2\right)\\ \mathbf{elif}\;\phi_2 \leq 5 \cdot 10^{+72}:\\ \;\;\;\;\phi_1 \cdot \mathsf{fma}\left(R, \frac{\phi_2}{\phi_1}, -R\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\phi_2 - \phi_1\right) \cdot R\\ \end{array} \]
                                    13. Add Preprocessing

                                    Alternative 7: 55.3% accurate, 8.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 1.45 \cdot 10^{-254} \lor \neg \left(\phi_2 \leq 5.8 \cdot 10^{-86}\right):\\ \;\;\;\;\left(\phi_2 - \phi_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{fma}\left(-0.125 \cdot \lambda_2, \phi_2 \cdot \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 (or (<= phi2 1.45e-254) (not (<= phi2 5.8e-86)))
                                       (* (- phi2 phi1) R)
                                       (* R (fma (* -0.125 lambda2) (* phi2 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 ((phi2 <= 1.45e-254) || !(phi2 <= 5.8e-86)) {
                                    		tmp = (phi2 - phi1) * R;
                                    	} else {
                                    		tmp = R * fma((-0.125 * lambda2), (phi2 * 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 ((phi2 <= 1.45e-254) || !(phi2 <= 5.8e-86))
                                    		tmp = Float64(Float64(phi2 - phi1) * R);
                                    	else
                                    		tmp = Float64(R * fma(Float64(-0.125 * lambda2), Float64(phi2 * phi2), 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[Or[LessEqual[phi2, 1.45e-254], N[Not[LessEqual[phi2, 5.8e-86]], $MachinePrecision]], N[(N[(phi2 - phi1), $MachinePrecision] * R), $MachinePrecision], N[(R * N[(N[(-0.125 * lambda2), $MachinePrecision] * N[(phi2 * phi2), $MachinePrecision] + lambda2), $MachinePrecision]), $MachinePrecision]]
                                    
                                    \begin{array}{l}
                                    [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                                    \\
                                    \begin{array}{l}
                                    \mathbf{if}\;\phi_2 \leq 1.45 \cdot 10^{-254} \lor \neg \left(\phi_2 \leq 5.8 \cdot 10^{-86}\right):\\
                                    \;\;\;\;\left(\phi_2 - \phi_1\right) \cdot R\\
                                    
                                    \mathbf{else}:\\
                                    \;\;\;\;R \cdot \mathsf{fma}\left(-0.125 \cdot \lambda_2, \phi_2 \cdot \phi_2, \lambda_2\right)\\
                                    
                                    
                                    \end{array}
                                    \end{array}
                                    
                                    Derivation
                                    1. Split input into 2 regimes
                                    2. if phi2 < 1.45e-254 or 5.7999999999999998e-86 < phi2

                                      1. Initial program 57.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                          \[\leadsto \phi_2 \cdot \mathsf{fma}\left(-1, \color{blue}{\frac{R \cdot \phi_1}{\phi_2}}, R\right) \]
                                        5. lower-*.f6433.6

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

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

                                        \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{R \cdot \phi_2} \]
                                      10. Step-by-step derivation
                                        1. Applied rewrites28.7%

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

                                          \[\leadsto R \cdot \left(\phi_2 + \color{blue}{-1 \cdot \phi_1}\right) \]
                                        3. Step-by-step derivation
                                          1. Applied rewrites31.8%

                                            \[\leadsto \left(\phi_2 - \phi_1\right) \cdot R \]

                                          if 1.45e-254 < phi2 < 5.7999999999999998e-86

                                          1. Initial program 77.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                            \[\leadsto R \cdot \left(\lambda_2 \cdot \color{blue}{\cos \left(\frac{-1}{2} \cdot \phi_2\right)}\right) \]
                                          7. Step-by-step derivation
                                            1. Applied rewrites39.0%

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

                                              \[\leadsto R \cdot \left(\lambda_2 + \frac{-1}{8} \cdot \color{blue}{\left(\lambda_2 \cdot {\phi_2}^{2}\right)}\right) \]
                                            3. Step-by-step derivation
                                              1. Applied rewrites39.0%

                                                \[\leadsto R \cdot \mathsf{fma}\left(-0.125 \cdot \lambda_2, \phi_2 \cdot \color{blue}{\phi_2}, \lambda_2\right) \]
                                            4. Recombined 2 regimes into one program.
                                            5. Final simplification32.6%

                                              \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.45 \cdot 10^{-254} \lor \neg \left(\phi_2 \leq 5.8 \cdot 10^{-86}\right):\\ \;\;\;\;\left(\phi_2 - \phi_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{fma}\left(-0.125 \cdot \lambda_2, \phi_2 \cdot \phi_2, \lambda_2\right)\\ \end{array} \]
                                            6. Add Preprocessing

                                            Alternative 8: 58.0% accurate, 9.0× speedup?

                                            \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;R \leq 3.7 \cdot 10^{+88}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-\phi_1, \frac{R}{\phi_2}, R\right) \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 (<= R 3.7e+88)
                                               (fma (- R) phi1 (* R phi2))
                                               (* (fma (- phi1) (/ R phi2) 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 (R <= 3.7e+88) {
                                            		tmp = fma(-R, phi1, (R * phi2));
                                            	} else {
                                            		tmp = fma(-phi1, (R / phi2), 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 (R <= 3.7e+88)
                                            		tmp = fma(Float64(-R), phi1, Float64(R * phi2));
                                            	else
                                            		tmp = Float64(fma(Float64(-phi1), Float64(R / phi2), 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[R, 3.7e+88], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision], N[(N[((-phi1) * N[(R / phi2), $MachinePrecision] + R), $MachinePrecision] * phi2), $MachinePrecision]]
                                            
                                            \begin{array}{l}
                                            [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;R \leq 3.7 \cdot 10^{+88}:\\
                                            \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\mathsf{fma}\left(-\phi_1, \frac{R}{\phi_2}, R\right) \cdot \phi_2\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 2 regimes
                                            2. if R < 3.69999999999999994e88

                                              1. Initial program 51.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                  \[\leadsto \phi_2 \cdot \mathsf{fma}\left(-1, \color{blue}{\frac{R \cdot \phi_1}{\phi_2}}, R\right) \]
                                                5. lower-*.f6429.4

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

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

                                                \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{R \cdot \phi_2} \]
                                              10. Step-by-step derivation
                                                1. Applied rewrites25.5%

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

                                                if 3.69999999999999994e88 < R

                                                1. Initial program 96.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                    \[\leadsto \phi_2 \cdot \mathsf{fma}\left(-1, \color{blue}{\frac{R \cdot \phi_1}{\phi_2}}, R\right) \]
                                                  5. lower-*.f6439.5

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

                                                  \[\leadsto \color{blue}{\phi_2 \cdot \mathsf{fma}\left(-1, \frac{R \cdot \phi_1}{\phi_2}, R\right)} \]
                                                9. Step-by-step derivation
                                                  1. Applied rewrites49.4%

                                                    \[\leadsto \phi_2 \cdot \mathsf{fma}\left(-1, \phi_1 \cdot \color{blue}{\frac{R}{\phi_2}}, R\right) \]
                                                  2. Step-by-step derivation
                                                    1. Applied rewrites49.4%

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

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

                                                  Alternative 9: 57.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}\;R \leq 2.1 \cdot 10^{+111}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot \frac{\left(\phi_2 - \phi_1\right) \cdot R}{\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 (<= R 2.1e+111)
                                                     (fma (- R) phi1 (* R phi2))
                                                     (* phi2 (/ (* (- phi2 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 (R <= 2.1e+111) {
                                                  		tmp = fma(-R, phi1, (R * phi2));
                                                  	} else {
                                                  		tmp = phi2 * (((phi2 - 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 (R <= 2.1e+111)
                                                  		tmp = fma(Float64(-R), phi1, Float64(R * phi2));
                                                  	else
                                                  		tmp = Float64(phi2 * Float64(Float64(Float64(phi2 - phi1) * 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[R, 2.1e+111], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision], N[(phi2 * N[(N[(N[(phi2 - phi1), $MachinePrecision] * R), $MachinePrecision] / phi2), $MachinePrecision]), $MachinePrecision]]
                                                  
                                                  \begin{array}{l}
                                                  [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                                                  \\
                                                  \begin{array}{l}
                                                  \mathbf{if}\;R \leq 2.1 \cdot 10^{+111}:\\
                                                  \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
                                                  
                                                  \mathbf{else}:\\
                                                  \;\;\;\;\phi_2 \cdot \frac{\left(\phi_2 - \phi_1\right) \cdot R}{\phi_2}\\
                                                  
                                                  
                                                  \end{array}
                                                  \end{array}
                                                  
                                                  Derivation
                                                  1. Split input into 2 regimes
                                                  2. if R < 2.09999999999999995e111

                                                    1. Initial program 51.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                      \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{R \cdot \phi_2} \]
                                                    10. Step-by-step derivation
                                                      1. Applied rewrites25.0%

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

                                                      if 2.09999999999999995e111 < R

                                                      1. Initial program 98.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                        \[\leadsto \color{blue}{\phi_2 \cdot \mathsf{fma}\left(-1, \frac{R \cdot \phi_1}{\phi_2}, R\right)} \]
                                                      9. Step-by-step derivation
                                                        1. Applied rewrites53.6%

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

                                                          \[\leadsto \phi_2 \cdot \frac{-1 \cdot \left(R \cdot \phi_1\right) + R \cdot \phi_2}{\color{blue}{\phi_2}} \]
                                                        3. Step-by-step derivation
                                                          1. Applied rewrites47.4%

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

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

                                                        Alternative 10: 51.7% accurate, 19.9× speedup?

                                                        \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 3.6 \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 (<= phi2 3.6e+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 (phi2 <= 3.6e+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 (phi2 <= 3.6d+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 (phi2 <= 3.6e+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 phi2 <= 3.6e+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 (phi2 <= 3.6e+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 (phi2 <= 3.6e+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[phi2, 3.6e+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_2 \leq 3.6 \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 phi2 < 3.6e15

                                                          1. Initial program 64.3%

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

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

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

                                                          if 3.6e15 < phi2

                                                          1. Initial program 47.5%

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

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

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

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

                                                        Alternative 11: 57.3% accurate, 31.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                            \[\leadsto \phi_2 \cdot \mathsf{fma}\left(-1, \color{blue}{\frac{R \cdot \phi_1}{\phi_2}}, R\right) \]
                                                          5. lower-*.f6431.3

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

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

                                                          \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{R \cdot \phi_2} \]
                                                        10. Step-by-step derivation
                                                          1. Applied rewrites26.7%

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

                                                            \[\leadsto R \cdot \left(\phi_2 + \color{blue}{-1 \cdot \phi_1}\right) \]
                                                          3. Step-by-step derivation
                                                            1. Applied rewrites29.4%

                                                              \[\leadsto \left(\phi_2 - \phi_1\right) \cdot R \]
                                                            2. Final simplification29.4%

                                                              \[\leadsto \left(\phi_2 - \phi_1\right) \cdot R \]
                                                            3. Add Preprocessing

                                                            Alternative 12: 31.0% 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 59.7%

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

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

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

                                                              \[\leadsto \color{blue}{R \cdot \phi_2} \]
                                                            6. Add Preprocessing

                                                            Reproduce

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