Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.5% → 90.8%
Time: 13.8s
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.5% accurate, 1.0× speedup?

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

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

Alternative 1: 90.8% accurate, 1.2× speedup?

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

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


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

    1. Initial program 61.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.9000000000000001e-39 < phi2

    1. Initial program 66.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

    1. Initial program 61.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.5999999999999999e-39 < phi2

    1. Initial program 66.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 80.4% accurate, 2.4× speedup?

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

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


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

    1. Initial program 61.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.1e-39 < phi2

    1. Initial program 66.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 78.6% accurate, 2.4× speedup?

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

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


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

    1. Initial program 63.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.9499999999999999e111 < phi2

    1. Initial program 60.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 54.6% accurate, 4.4× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \mathsf{fma}\left(\phi_1 \cdot \phi_1, -0.125, 1\right)\\ \mathbf{if}\;\phi_1 \leq -0.035:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq 6.5 \cdot 10^{-249}:\\ \;\;\;\;R \cdot \left(\lambda_2 \cdot \mathsf{fma}\left(-\lambda_1, \frac{t\_0}{\lambda_2}, t\_0\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot \left(\phi_1 \cdot \left(\frac{R}{\phi_1} - \frac{R}{\phi_2}\right)\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (fma (* phi1 phi1) -0.125 1.0)))
   (if (<= phi1 -0.035)
     (* R (- phi2 phi1))
     (if (<= phi1 6.5e-249)
       (* R (* lambda2 (fma (- lambda1) (/ t_0 lambda2) t_0)))
       (* phi2 (* phi1 (- (/ 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 t_0 = fma((phi1 * phi1), -0.125, 1.0);
	double tmp;
	if (phi1 <= -0.035) {
		tmp = R * (phi2 - phi1);
	} else if (phi1 <= 6.5e-249) {
		tmp = R * (lambda2 * fma(-lambda1, (t_0 / lambda2), t_0));
	} else {
		tmp = phi2 * (phi1 * ((R / phi1) - (R / phi2)));
	}
	return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = fma(Float64(phi1 * phi1), -0.125, 1.0)
	tmp = 0.0
	if (phi1 <= -0.035)
		tmp = Float64(R * Float64(phi2 - phi1));
	elseif (phi1 <= 6.5e-249)
		tmp = Float64(R * Float64(lambda2 * fma(Float64(-lambda1), Float64(t_0 / lambda2), t_0)));
	else
		tmp = Float64(phi2 * Float64(phi1 * Float64(Float64(R / phi1) - Float64(R / phi2))));
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(phi1 * phi1), $MachinePrecision] * -0.125 + 1.0), $MachinePrecision]}, If[LessEqual[phi1, -0.035], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 6.5e-249], N[(R * N[(lambda2 * N[((-lambda1) * N[(t$95$0 / lambda2), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(phi2 * N[(phi1 * N[(N[(R / phi1), $MachinePrecision] - N[(R / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\phi_1 \cdot \phi_1, -0.125, 1\right)\\
\mathbf{if}\;\phi_1 \leq -0.035:\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\

\mathbf{elif}\;\phi_1 \leq 6.5 \cdot 10^{-249}:\\
\;\;\;\;R \cdot \left(\lambda_2 \cdot \mathsf{fma}\left(-\lambda_1, \frac{t\_0}{\lambda_2}, t\_0\right)\right)\\

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


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

    1. Initial program 64.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.035000000000000003 < phi1 < 6.50000000000000016e-249

    1. Initial program 71.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(\color{blue}{\phi_1 \cdot \phi_1}, \frac{-1}{8}, 1\right)\right) \cdot R \]
      5. lower-*.f6468.1

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

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

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

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

        \[\leadsto \left(\lambda_2 \cdot \color{blue}{\left(\left(-1 \cdot \frac{\lambda_1 \cdot \left(1 + \frac{-1}{8} \cdot {\phi_1}^{2}\right)}{\lambda_2} + \frac{-1}{8} \cdot {\phi_1}^{2}\right) + 1\right)}\right) \cdot R \]
      3. associate-+l+N/A

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

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

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

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

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

        \[\leadsto \left(\lambda_2 \cdot \left(\left(-1 \cdot \lambda_1\right) \cdot \frac{1 + \frac{-1}{8} \cdot {\phi_1}^{2}}{\lambda_2} + \color{blue}{\left(1 + \frac{-1}{8} \cdot {\phi_1}^{2}\right)}\right)\right) \cdot R \]
      9. lower-fma.f64N/A

        \[\leadsto \left(\lambda_2 \cdot \color{blue}{\mathsf{fma}\left(-1 \cdot \lambda_1, \frac{1 + \frac{-1}{8} \cdot {\phi_1}^{2}}{\lambda_2}, 1 + \frac{-1}{8} \cdot {\phi_1}^{2}\right)}\right) \cdot R \]
      10. mul-1-negN/A

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

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

        \[\leadsto \left(\lambda_2 \cdot \mathsf{fma}\left(\mathsf{neg}\left(\lambda_1\right), \color{blue}{\frac{1 + \frac{-1}{8} \cdot {\phi_1}^{2}}{\lambda_2}}, 1 + \frac{-1}{8} \cdot {\phi_1}^{2}\right)\right) \cdot R \]
      13. +-commutativeN/A

        \[\leadsto \left(\lambda_2 \cdot \mathsf{fma}\left(\mathsf{neg}\left(\lambda_1\right), \frac{\color{blue}{\frac{-1}{8} \cdot {\phi_1}^{2} + 1}}{\lambda_2}, 1 + \frac{-1}{8} \cdot {\phi_1}^{2}\right)\right) \cdot R \]
      14. *-commutativeN/A

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

        \[\leadsto \left(\lambda_2 \cdot \mathsf{fma}\left(\mathsf{neg}\left(\lambda_1\right), \frac{\color{blue}{\mathsf{fma}\left({\phi_1}^{2}, \frac{-1}{8}, 1\right)}}{\lambda_2}, 1 + \frac{-1}{8} \cdot {\phi_1}^{2}\right)\right) \cdot R \]
      16. unpow2N/A

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

        \[\leadsto \left(\lambda_2 \cdot \mathsf{fma}\left(\mathsf{neg}\left(\lambda_1\right), \frac{\mathsf{fma}\left(\color{blue}{\phi_1 \cdot \phi_1}, \frac{-1}{8}, 1\right)}{\lambda_2}, 1 + \frac{-1}{8} \cdot {\phi_1}^{2}\right)\right) \cdot R \]
      18. +-commutativeN/A

        \[\leadsto \left(\lambda_2 \cdot \mathsf{fma}\left(\mathsf{neg}\left(\lambda_1\right), \frac{\mathsf{fma}\left(\phi_1 \cdot \phi_1, \frac{-1}{8}, 1\right)}{\lambda_2}, \color{blue}{\frac{-1}{8} \cdot {\phi_1}^{2} + 1}\right)\right) \cdot R \]
    11. Simplified31.9%

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

    if 6.50000000000000016e-249 < phi1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 54.6% accurate, 5.8× speedup?

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

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

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


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

    1. Initial program 64.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -8.00000000000000038e-4 < phi1 < 2.3e-248

    1. Initial program 71.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.3e-248 < phi1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 55.3% accurate, 7.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\phi_2 \cdot R\\


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

    1. Initial program 64.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.0999999999999999e-4 < phi1 < 2.3e-248

    1. Initial program 71.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.3e-248 < phi1

    1. Initial program 54.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. *-commutativeN/A

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

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

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

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

Alternative 8: 50.0% accurate, 10.7× speedup?

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

\mathbf{elif}\;\phi_2 \leq 1.45 \cdot 10^{-52}:\\
\;\;\;\;\lambda_2 \cdot R\\

\mathbf{elif}\;\phi_2 \leq 1.3 \cdot 10^{+33}:\\
\;\;\;\;\lambda_1 \cdot \left(-R\right)\\

\mathbf{else}:\\
\;\;\;\;\phi_2 \cdot R\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if phi2 < 7.6e-175

    1. Initial program 62.6%

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

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

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

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

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

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

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

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

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

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

    if 7.6e-175 < phi2 < 1.4500000000000001e-52

    1. Initial program 50.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    11. Simplified12.5%

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

    if 1.4500000000000001e-52 < phi2 < 1.2999999999999999e33

    1. Initial program 87.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 \color{blue}{R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}}} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \color{blue}{\left(-\lambda_1\right)}\right) \cdot R \]
    8. Simplified15.5%

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

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

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

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

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

    if 1.2999999999999999e33 < phi2

    1. Initial program 62.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. *-commutativeN/A

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 7.6 \cdot 10^{-175}:\\ \;\;\;\;\phi_1 \cdot \left(-R\right)\\ \mathbf{elif}\;\phi_2 \leq 1.45 \cdot 10^{-52}:\\ \;\;\;\;\lambda_2 \cdot R\\ \mathbf{elif}\;\phi_2 \leq 1.3 \cdot 10^{+33}:\\ \;\;\;\;\lambda_1 \cdot \left(-R\right)\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot R\\ \end{array} \]
  5. Add Preprocessing

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

\mathbf{elif}\;\lambda_2 \leq 1.1 \cdot 10^{+157}:\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\

\mathbf{else}:\\
\;\;\;\;\lambda_2 \cdot R\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if lambda2 < -1.10000000000000005e-231

    1. Initial program 62.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right) \cdot R \]
      9. lower-neg.f6417.0

        \[\leadsto \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \color{blue}{\left(-\lambda_1\right)}\right) \cdot R \]
    8. Simplified17.0%

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

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

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

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

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

    if -1.10000000000000005e-231 < lambda2 < 1.1000000000000001e157

    1. Initial program 70.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.1000000000000001e157 < lambda2

    1. Initial program 43.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
      2. lower-*.f6466.8

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    11. Simplified66.8%

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

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

Alternative 10: 50.7% accurate, 15.5× speedup?

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

\mathbf{elif}\;\phi_2 \leq 7 \cdot 10^{-36}:\\
\;\;\;\;\lambda_2 \cdot R\\

\mathbf{else}:\\
\;\;\;\;\phi_2 \cdot R\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < 3.49999999999999999e-175

    1. Initial program 62.6%

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

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

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

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

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

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

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

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

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

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

    if 3.49999999999999999e-175 < phi2 < 6.9999999999999999e-36

    1. Initial program 57.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    11. Simplified14.5%

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

    if 6.9999999999999999e-36 < phi2

    1. Initial program 65.9%

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

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

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

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

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

Alternative 11: 38.2% accurate, 23.2× speedup?

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

\mathbf{else}:\\
\;\;\;\;\phi_2 \cdot R\\


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

    1. Initial program 61.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
      2. lower-*.f6416.7

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    11. Simplified16.7%

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

    if 6.9999999999999999e-36 < phi2

    1. Initial program 65.9%

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

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

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

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

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

Alternative 12: 14.2% accurate, 46.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    2. lower-*.f6415.2

      \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
  11. Simplified15.2%

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

Reproduce

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