Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.8% → 99.9%
Time: 19.2s
Alternatives: 11
Speedup: 3.0×

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 11 alternatives:

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

Initial Program: 59.8% 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: 99.9% accurate, 0.6× speedup?

\[\begin{array}{l} \\ R \cdot \mathsf{hypot}\left(\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right) \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R
  (hypot
   (*
    (-
     (* (cos (* 0.5 phi2)) (cos (* 0.5 phi1)))
     (* (sin (* 0.5 phi2)) (sin (* 0.5 phi1))))
    (- lambda1 lambda2))
   (- phi1 phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * hypot((((cos((0.5 * phi2)) * cos((0.5 * phi1))) - (sin((0.5 * phi2)) * sin((0.5 * phi1)))) * (lambda1 - lambda2)), (phi1 - phi2));
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * Math.hypot((((Math.cos((0.5 * phi2)) * Math.cos((0.5 * phi1))) - (Math.sin((0.5 * phi2)) * Math.sin((0.5 * phi1)))) * (lambda1 - lambda2)), (phi1 - phi2));
}
def code(R, lambda1, lambda2, phi1, phi2):
	return R * math.hypot((((math.cos((0.5 * phi2)) * math.cos((0.5 * phi1))) - (math.sin((0.5 * phi2)) * math.sin((0.5 * phi1)))) * (lambda1 - lambda2)), (phi1 - phi2))
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(R * hypot(Float64(Float64(Float64(cos(Float64(0.5 * phi2)) * cos(Float64(0.5 * phi1))) - Float64(sin(Float64(0.5 * phi2)) * sin(Float64(0.5 * phi1)))) * Float64(lambda1 - lambda2)), Float64(phi1 - phi2)))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = R * hypot((((cos((0.5 * phi2)) * cos((0.5 * phi1))) - (sin((0.5 * phi2)) * sin((0.5 * phi1)))) * (lambda1 - lambda2)), (phi1 - phi2));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[Sqrt[N[(N[(N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
R \cdot \mathsf{hypot}\left(\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 62.2%

    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
  2. Step-by-step derivation
    1. hypot-def96.0%

      \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
  3. Simplified96.0%

    \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. add-log-exp95.9%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\log \left(e^{\cos \left(\frac{\phi_1 + \phi_2}{2}\right)}\right)}, \phi_1 - \phi_2\right) \]
    2. div-inv95.9%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\cos \color{blue}{\left(\left(\phi_1 + \phi_2\right) \cdot \frac{1}{2}\right)}}\right), \phi_1 - \phi_2\right) \]
    3. metadata-eval95.9%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\cos \left(\left(\phi_1 + \phi_2\right) \cdot \color{blue}{0.5}\right)}\right), \phi_1 - \phi_2\right) \]
  6. Applied egg-rr95.9%

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\log \left(e^{\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right)}\right)}, \phi_1 - \phi_2\right) \]
  7. Step-by-step derivation
    1. *-commutative95.9%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\cos \color{blue}{\left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}}\right), \phi_1 - \phi_2\right) \]
    2. distribute-lft-in95.9%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\cos \color{blue}{\left(0.5 \cdot \phi_1 + 0.5 \cdot \phi_2\right)}}\right), \phi_1 - \phi_2\right) \]
    3. cos-sum99.7%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\color{blue}{\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)}}\right), \phi_1 - \phi_2\right) \]
    4. *-commutative99.7%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\cos \color{blue}{\left(\phi_1 \cdot 0.5\right)} \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)}\right), \phi_1 - \phi_2\right) \]
    5. *-commutative99.7%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \color{blue}{\left(\phi_2 \cdot 0.5\right)} - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)}\right), \phi_1 - \phi_2\right) \]
    6. *-commutative99.7%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(\phi_2 \cdot 0.5\right) - \sin \color{blue}{\left(\phi_1 \cdot 0.5\right)} \cdot \sin \left(0.5 \cdot \phi_2\right)}\right), \phi_1 - \phi_2\right) \]
    7. *-commutative99.7%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(\phi_2 \cdot 0.5\right) - \sin \left(\phi_1 \cdot 0.5\right) \cdot \sin \color{blue}{\left(\phi_2 \cdot 0.5\right)}}\right), \phi_1 - \phi_2\right) \]
  8. Applied egg-rr99.7%

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\color{blue}{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(\phi_2 \cdot 0.5\right) - \sin \left(\phi_1 \cdot 0.5\right) \cdot \sin \left(\phi_2 \cdot 0.5\right)}}\right), \phi_1 - \phi_2\right) \]
  9. Taylor expanded in lambda1 around 0 99.9%

    \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{-1 \cdot \left(\lambda_2 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right) + \lambda_1 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}, \phi_1 - \phi_2\right) \]
  10. Step-by-step derivation
    1. +-commutative99.9%

      \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\lambda_1 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right) + -1 \cdot \left(\lambda_2 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)}, \phi_1 - \phi_2\right) \]
    2. mul-1-neg99.9%

      \[\leadsto R \cdot \mathsf{hypot}\left(\lambda_1 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right) + \color{blue}{\left(-\lambda_2 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)}, \phi_1 - \phi_2\right) \]
    3. distribute-lft-neg-in99.9%

      \[\leadsto R \cdot \mathsf{hypot}\left(\lambda_1 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right) + \color{blue}{\left(-\lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}, \phi_1 - \phi_2\right) \]
    4. distribute-rgt-in99.9%

      \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right) \cdot \left(\lambda_1 + \left(-\lambda_2\right)\right)}, \phi_1 - \phi_2\right) \]
    5. sub-neg99.9%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right) \cdot \color{blue}{\left(\lambda_1 - \lambda_2\right)}, \phi_1 - \phi_2\right) \]
  11. Simplified99.9%

    \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)}, \phi_1 - \phi_2\right) \]
  12. Final simplification99.9%

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right) \]
  13. Add Preprocessing

Alternative 2: 91.0% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 8.5 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \left(-\lambda_2\right), \phi_1 - \phi_2\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi2 8.5e-5)
   (* R (hypot (* (cos (* 0.5 phi1)) (- lambda1 lambda2)) (- phi1 phi2)))
   (* R (hypot (* (cos (* 0.5 phi2)) (- lambda2)) (- phi1 phi2)))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 8.5e-5) {
		tmp = R * hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), (phi1 - phi2));
	} else {
		tmp = R * hypot((cos((0.5 * phi2)) * -lambda2), (phi1 - phi2));
	}
	return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 8.5e-5) {
		tmp = R * Math.hypot((Math.cos((0.5 * phi1)) * (lambda1 - lambda2)), (phi1 - phi2));
	} else {
		tmp = R * Math.hypot((Math.cos((0.5 * phi2)) * -lambda2), (phi1 - phi2));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 8.5e-5:
		tmp = R * math.hypot((math.cos((0.5 * phi1)) * (lambda1 - lambda2)), (phi1 - phi2))
	else:
		tmp = R * math.hypot((math.cos((0.5 * phi2)) * -lambda2), (phi1 - phi2))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 8.5e-5)
		tmp = Float64(R * hypot(Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2)), Float64(phi1 - phi2)));
	else
		tmp = Float64(R * hypot(Float64(cos(Float64(0.5 * phi2)) * Float64(-lambda2)), Float64(phi1 - phi2)));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi2 <= 8.5e-5)
		tmp = R * hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), (phi1 - phi2));
	else
		tmp = R * hypot((cos((0.5 * phi2)) * -lambda2), (phi1 - phi2));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 8.5e-5], N[(R * N[Sqrt[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * (-lambda2)), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 8.5 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\\

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


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

    1. Initial program 64.6%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-def97.9%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified97.9%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi2 around 0 95.2%

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

    if 8.500000000000001e-5 < phi2

    1. Initial program 55.1%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-def90.1%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified90.1%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi1 around 0 90.0%

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{-1 \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)}, \phi_1 - \phi_2\right) \]
    7. Step-by-step derivation
      1. mul-1-neg80.9%

        \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{-\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)}, \phi_1 - \phi_2\right) \]
      2. *-commutative80.9%

        \[\leadsto R \cdot \mathsf{hypot}\left(-\color{blue}{\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_2}, \phi_1 - \phi_2\right) \]
      3. distribute-rgt-neg-in80.9%

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

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

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

Alternative 3: 93.5% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.4 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi1 -1.4e-5)
   (* R (hypot (* (cos (* 0.5 phi1)) (- lambda1 lambda2)) (- phi1 phi2)))
   (* R (hypot (* (cos (* 0.5 phi2)) (- lambda1 lambda2)) (- phi1 phi2)))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -1.4e-5) {
		tmp = R * hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), (phi1 - phi2));
	} else {
		tmp = R * hypot((cos((0.5 * phi2)) * (lambda1 - lambda2)), (phi1 - phi2));
	}
	return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -1.4e-5) {
		tmp = R * Math.hypot((Math.cos((0.5 * phi1)) * (lambda1 - lambda2)), (phi1 - phi2));
	} else {
		tmp = R * Math.hypot((Math.cos((0.5 * phi2)) * (lambda1 - lambda2)), (phi1 - phi2));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -1.4e-5:
		tmp = R * math.hypot((math.cos((0.5 * phi1)) * (lambda1 - lambda2)), (phi1 - phi2))
	else:
		tmp = R * math.hypot((math.cos((0.5 * phi2)) * (lambda1 - lambda2)), (phi1 - phi2))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -1.4e-5)
		tmp = Float64(R * hypot(Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2)), Float64(phi1 - phi2)));
	else
		tmp = Float64(R * hypot(Float64(cos(Float64(0.5 * phi2)) * Float64(lambda1 - lambda2)), Float64(phi1 - phi2)));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi1 <= -1.4e-5)
		tmp = R * hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), (phi1 - phi2));
	else
		tmp = R * hypot((cos((0.5 * phi2)) * (lambda1 - lambda2)), (phi1 - phi2));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -1.4e-5], N[(R * N[Sqrt[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -1.4 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi1 < -1.39999999999999998e-5

    1. Initial program 46.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. Step-by-step derivation
      1. hypot-def92.7%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified92.7%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi2 around 0 92.8%

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

    if -1.39999999999999998e-5 < phi1

    1. Initial program 67.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. Step-by-step derivation
      1. hypot-def97.0%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified97.0%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi1 around 0 93.6%

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

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

Alternative 4: 96.1% accurate, 1.5× speedup?

\[\begin{array}{l} \\ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_2 + \phi_1}{2}\right), \phi_1 - \phi_2\right) \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R
  (hypot (* (- lambda1 lambda2) (cos (/ (+ phi2 phi1) 2.0))) (- phi1 phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * hypot(((lambda1 - lambda2) * cos(((phi2 + phi1) / 2.0))), (phi1 - phi2));
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * Math.hypot(((lambda1 - lambda2) * Math.cos(((phi2 + phi1) / 2.0))), (phi1 - phi2));
}
def code(R, lambda1, lambda2, phi1, phi2):
	return R * math.hypot(((lambda1 - lambda2) * math.cos(((phi2 + phi1) / 2.0))), (phi1 - phi2))
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(R * hypot(Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi2 + phi1) / 2.0))), Float64(phi1 - phi2)))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = R * hypot(((lambda1 - lambda2) * cos(((phi2 + phi1) / 2.0))), (phi1 - phi2));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[Sqrt[N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(N[(phi2 + phi1), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_2 + \phi_1}{2}\right), \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 62.2%

    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
  2. Step-by-step derivation
    1. hypot-def96.0%

      \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
  3. Simplified96.0%

    \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
  4. Add Preprocessing
  5. Final simplification96.0%

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_2 + \phi_1}{2}\right), \phi_1 - \phi_2\right) \]
  6. Add Preprocessing

Alternative 5: 74.8% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 5.5 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \left(-\lambda_2\right), \phi_1 - \phi_2\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi2 5.5e-5)
   (* R (hypot phi1 (- lambda1 lambda2)))
   (* R (hypot (* (cos (* 0.5 phi2)) (- lambda2)) (- phi1 phi2)))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 5.5e-5) {
		tmp = R * hypot(phi1, (lambda1 - lambda2));
	} else {
		tmp = R * hypot((cos((0.5 * phi2)) * -lambda2), (phi1 - phi2));
	}
	return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 5.5e-5) {
		tmp = R * Math.hypot(phi1, (lambda1 - lambda2));
	} else {
		tmp = R * Math.hypot((Math.cos((0.5 * phi2)) * -lambda2), (phi1 - phi2));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 5.5e-5:
		tmp = R * math.hypot(phi1, (lambda1 - lambda2))
	else:
		tmp = R * math.hypot((math.cos((0.5 * phi2)) * -lambda2), (phi1 - phi2))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 5.5e-5)
		tmp = Float64(R * hypot(phi1, Float64(lambda1 - lambda2)));
	else
		tmp = Float64(R * hypot(Float64(cos(Float64(0.5 * phi2)) * Float64(-lambda2)), Float64(phi1 - phi2)));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi2 <= 5.5e-5)
		tmp = R * hypot(phi1, (lambda1 - lambda2));
	else
		tmp = R * hypot((cos((0.5 * phi2)) * -lambda2), (phi1 - phi2));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 5.5e-5], N[(R * N[Sqrt[phi1 ^ 2 + N[(lambda1 - lambda2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * (-lambda2)), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 5.5 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\

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


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

    1. Initial program 64.6%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-def97.9%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified97.9%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi1 around 0 90.4%

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

      \[\leadsto \color{blue}{R \cdot \sqrt{{\phi_1}^{2} + {\left(\lambda_1 - \lambda_2\right)}^{2}}} \]
    7. Step-by-step derivation
      1. unpow257.2%

        \[\leadsto R \cdot \sqrt{\color{blue}{\phi_1 \cdot \phi_1} + {\left(\lambda_1 - \lambda_2\right)}^{2}} \]
      2. unpow257.2%

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)}} \]
      3. hypot-def77.3%

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

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

    if 5.5000000000000002e-5 < phi2

    1. Initial program 55.1%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-def90.1%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified90.1%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi1 around 0 90.0%

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{-1 \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)}, \phi_1 - \phi_2\right) \]
    7. Step-by-step derivation
      1. mul-1-neg80.9%

        \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{-\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)}, \phi_1 - \phi_2\right) \]
      2. *-commutative80.9%

        \[\leadsto R \cdot \mathsf{hypot}\left(-\color{blue}{\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_2}, \phi_1 - \phi_2\right) \]
      3. distribute-rgt-neg-in80.9%

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

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

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

Alternative 6: 70.0% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 4200000000000:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi2 4200000000000.0)
   (* R (hypot phi1 (- lambda1 lambda2)))
   (* R (- phi2 phi1))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 4200000000000.0) {
		tmp = R * hypot(phi1, (lambda1 - lambda2));
	} else {
		tmp = R * (phi2 - phi1);
	}
	return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 4200000000000.0) {
		tmp = R * Math.hypot(phi1, (lambda1 - lambda2));
	} else {
		tmp = R * (phi2 - phi1);
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 4200000000000.0:
		tmp = R * math.hypot(phi1, (lambda1 - lambda2))
	else:
		tmp = R * (phi2 - phi1)
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 4200000000000.0)
		tmp = Float64(R * hypot(phi1, Float64(lambda1 - lambda2)));
	else
		tmp = Float64(R * Float64(phi2 - phi1));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi2 <= 4200000000000.0)
		tmp = R * hypot(phi1, (lambda1 - lambda2));
	else
		tmp = R * (phi2 - phi1);
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 4200000000000.0], N[(R * N[Sqrt[phi1 ^ 2 + N[(lambda1 - lambda2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 4200000000000:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\

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


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

    1. Initial program 64.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. Step-by-step derivation
      1. hypot-def98.0%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified98.0%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi1 around 0 90.6%

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

      \[\leadsto \color{blue}{R \cdot \sqrt{{\phi_1}^{2} + {\left(\lambda_1 - \lambda_2\right)}^{2}}} \]
    7. Step-by-step derivation
      1. unpow256.6%

        \[\leadsto R \cdot \sqrt{\color{blue}{\phi_1 \cdot \phi_1} + {\left(\lambda_1 - \lambda_2\right)}^{2}} \]
      2. unpow256.6%

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)}} \]
      3. hypot-def76.7%

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

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

    if 4.2e12 < phi2

    1. Initial program 53.8%

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

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

        \[\leadsto R \cdot \left(\phi_2 + \color{blue}{\left(-\phi_1\right)}\right) \]
      2. unsub-neg65.4%

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

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

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

Alternative 7: 28.8% accurate, 24.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -R \cdot \lambda_1\\ t_1 := R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{if}\;\lambda_1 \leq -3.2 \cdot 10^{+214}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\lambda_1 \leq -1.46 \cdot 10^{+197}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\lambda_1 \leq -3.2 \cdot 10^{+62}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\lambda_1 \leq 3.3 \cdot 10^{-164}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \lambda_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (- (* R lambda1))) (t_1 (* R (- phi2 phi1))))
   (if (<= lambda1 -3.2e+214)
     t_0
     (if (<= lambda1 -1.46e+197)
       t_1
       (if (<= lambda1 -3.2e+62)
         t_0
         (if (<= lambda1 3.3e-164) t_1 (* R lambda2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = -(R * lambda1);
	double t_1 = R * (phi2 - phi1);
	double tmp;
	if (lambda1 <= -3.2e+214) {
		tmp = t_0;
	} else if (lambda1 <= -1.46e+197) {
		tmp = t_1;
	} else if (lambda1 <= -3.2e+62) {
		tmp = t_0;
	} else if (lambda1 <= 3.3e-164) {
		tmp = t_1;
	} else {
		tmp = R * lambda2;
	}
	return tmp;
}
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
    real(8) :: t_1
    real(8) :: tmp
    t_0 = -(r * lambda1)
    t_1 = r * (phi2 - phi1)
    if (lambda1 <= (-3.2d+214)) then
        tmp = t_0
    else if (lambda1 <= (-1.46d+197)) then
        tmp = t_1
    else if (lambda1 <= (-3.2d+62)) then
        tmp = t_0
    else if (lambda1 <= 3.3d-164) then
        tmp = t_1
    else
        tmp = r * lambda2
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = -(R * lambda1);
	double t_1 = R * (phi2 - phi1);
	double tmp;
	if (lambda1 <= -3.2e+214) {
		tmp = t_0;
	} else if (lambda1 <= -1.46e+197) {
		tmp = t_1;
	} else if (lambda1 <= -3.2e+62) {
		tmp = t_0;
	} else if (lambda1 <= 3.3e-164) {
		tmp = t_1;
	} else {
		tmp = R * lambda2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = -(R * lambda1)
	t_1 = R * (phi2 - phi1)
	tmp = 0
	if lambda1 <= -3.2e+214:
		tmp = t_0
	elif lambda1 <= -1.46e+197:
		tmp = t_1
	elif lambda1 <= -3.2e+62:
		tmp = t_0
	elif lambda1 <= 3.3e-164:
		tmp = t_1
	else:
		tmp = R * lambda2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(-Float64(R * lambda1))
	t_1 = Float64(R * Float64(phi2 - phi1))
	tmp = 0.0
	if (lambda1 <= -3.2e+214)
		tmp = t_0;
	elseif (lambda1 <= -1.46e+197)
		tmp = t_1;
	elseif (lambda1 <= -3.2e+62)
		tmp = t_0;
	elseif (lambda1 <= 3.3e-164)
		tmp = t_1;
	else
		tmp = Float64(R * lambda2);
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = -(R * lambda1);
	t_1 = R * (phi2 - phi1);
	tmp = 0.0;
	if (lambda1 <= -3.2e+214)
		tmp = t_0;
	elseif (lambda1 <= -1.46e+197)
		tmp = t_1;
	elseif (lambda1 <= -3.2e+62)
		tmp = t_0;
	elseif (lambda1 <= 3.3e-164)
		tmp = t_1;
	else
		tmp = R * lambda2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = (-N[(R * lambda1), $MachinePrecision])}, Block[{t$95$1 = N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda1, -3.2e+214], t$95$0, If[LessEqual[lambda1, -1.46e+197], t$95$1, If[LessEqual[lambda1, -3.2e+62], t$95$0, If[LessEqual[lambda1, 3.3e-164], t$95$1, N[(R * lambda2), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -R \cdot \lambda_1\\
t_1 := R \cdot \left(\phi_2 - \phi_1\right)\\
\mathbf{if}\;\lambda_1 \leq -3.2 \cdot 10^{+214}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\lambda_1 \leq -1.46 \cdot 10^{+197}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\lambda_1 \leq -3.2 \cdot 10^{+62}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\lambda_1 \leq 3.3 \cdot 10^{-164}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if lambda1 < -3.19999999999999995e214 or -1.46e197 < lambda1 < -3.19999999999999984e62

    1. Initial program 62.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. Step-by-step derivation
      1. hypot-def94.4%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified94.4%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi1 around 0 86.0%

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)\right)} \]
    7. Step-by-step derivation
      1. mul-1-neg48.9%

        \[\leadsto \color{blue}{-R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)} \]
      2. *-commutative48.9%

        \[\leadsto -\color{blue}{\left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot R} \]
      3. distribute-rgt-neg-in48.9%

        \[\leadsto \color{blue}{\left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \left(-R\right)} \]
      4. *-commutative48.9%

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

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

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

    if -3.19999999999999995e214 < lambda1 < -1.46e197 or -3.19999999999999984e62 < lambda1 < 3.3e-164

    1. Initial program 58.2%

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

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

        \[\leadsto R \cdot \left(\phi_2 + \color{blue}{\left(-\phi_1\right)}\right) \]
      2. unsub-neg34.0%

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

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

    if 3.3e-164 < lambda1

    1. Initial program 66.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. Step-by-step derivation
      1. hypot-def97.9%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified97.9%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi1 around 0 83.8%

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

      \[\leadsto \color{blue}{R \cdot \left(\lambda_2 \cdot \left(\cos \left(0.5 \cdot \phi_2\right) + -0.5 \cdot \left(\phi_1 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right)} \]
    7. Taylor expanded in phi2 around 0 19.5%

      \[\leadsto \color{blue}{R \cdot \lambda_2} \]
    8. Step-by-step derivation
      1. *-commutative19.5%

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    9. Simplified19.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -3.2 \cdot 10^{+214}:\\ \;\;\;\;-R \cdot \lambda_1\\ \mathbf{elif}\;\lambda_1 \leq -1.46 \cdot 10^{+197}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\lambda_1 \leq -3.2 \cdot 10^{+62}:\\ \;\;\;\;-R \cdot \lambda_1\\ \mathbf{elif}\;\lambda_1 \leq 3.3 \cdot 10^{-164}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \lambda_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 27.5% accurate, 26.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -R \cdot \lambda_1\\ \mathbf{if}\;\phi_1 \leq -2.3 \cdot 10^{+40}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -6.2 \cdot 10^{-35}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\phi_1 \leq -7 \cdot 10^{-251}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{elif}\;\phi_1 \leq 2.5 \cdot 10^{-214}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (- (* R lambda1))))
   (if (<= phi1 -2.3e+40)
     (* R (- phi1))
     (if (<= phi1 -6.2e-35)
       t_0
       (if (<= phi1 -7e-251)
         (* R lambda2)
         (if (<= phi1 2.5e-214) t_0 (* R phi2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = -(R * lambda1);
	double tmp;
	if (phi1 <= -2.3e+40) {
		tmp = R * -phi1;
	} else if (phi1 <= -6.2e-35) {
		tmp = t_0;
	} else if (phi1 <= -7e-251) {
		tmp = R * lambda2;
	} else if (phi1 <= 2.5e-214) {
		tmp = t_0;
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
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
    real(8) :: tmp
    t_0 = -(r * lambda1)
    if (phi1 <= (-2.3d+40)) then
        tmp = r * -phi1
    else if (phi1 <= (-6.2d-35)) then
        tmp = t_0
    else if (phi1 <= (-7d-251)) then
        tmp = r * lambda2
    else if (phi1 <= 2.5d-214) then
        tmp = t_0
    else
        tmp = r * phi2
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = -(R * lambda1);
	double tmp;
	if (phi1 <= -2.3e+40) {
		tmp = R * -phi1;
	} else if (phi1 <= -6.2e-35) {
		tmp = t_0;
	} else if (phi1 <= -7e-251) {
		tmp = R * lambda2;
	} else if (phi1 <= 2.5e-214) {
		tmp = t_0;
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = -(R * lambda1)
	tmp = 0
	if phi1 <= -2.3e+40:
		tmp = R * -phi1
	elif phi1 <= -6.2e-35:
		tmp = t_0
	elif phi1 <= -7e-251:
		tmp = R * lambda2
	elif phi1 <= 2.5e-214:
		tmp = t_0
	else:
		tmp = R * phi2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(-Float64(R * lambda1))
	tmp = 0.0
	if (phi1 <= -2.3e+40)
		tmp = Float64(R * Float64(-phi1));
	elseif (phi1 <= -6.2e-35)
		tmp = t_0;
	elseif (phi1 <= -7e-251)
		tmp = Float64(R * lambda2);
	elseif (phi1 <= 2.5e-214)
		tmp = t_0;
	else
		tmp = Float64(R * phi2);
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = -(R * lambda1);
	tmp = 0.0;
	if (phi1 <= -2.3e+40)
		tmp = R * -phi1;
	elseif (phi1 <= -6.2e-35)
		tmp = t_0;
	elseif (phi1 <= -7e-251)
		tmp = R * lambda2;
	elseif (phi1 <= 2.5e-214)
		tmp = t_0;
	else
		tmp = R * phi2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = (-N[(R * lambda1), $MachinePrecision])}, If[LessEqual[phi1, -2.3e+40], N[(R * (-phi1)), $MachinePrecision], If[LessEqual[phi1, -6.2e-35], t$95$0, If[LessEqual[phi1, -7e-251], N[(R * lambda2), $MachinePrecision], If[LessEqual[phi1, 2.5e-214], t$95$0, N[(R * phi2), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -R \cdot \lambda_1\\
\mathbf{if}\;\phi_1 \leq -2.3 \cdot 10^{+40}:\\
\;\;\;\;R \cdot \left(-\phi_1\right)\\

\mathbf{elif}\;\phi_1 \leq -6.2 \cdot 10^{-35}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\phi_1 \leq -7 \cdot 10^{-251}:\\
\;\;\;\;R \cdot \lambda_2\\

\mathbf{elif}\;\phi_1 \leq 2.5 \cdot 10^{-214}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if phi1 < -2.29999999999999994e40

    1. Initial program 45.1%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-def94.6%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified94.6%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi1 around -inf 64.3%

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg64.3%

        \[\leadsto \color{blue}{-R \cdot \phi_1} \]
      2. *-commutative64.3%

        \[\leadsto -\color{blue}{\phi_1 \cdot R} \]
      3. distribute-rgt-neg-in64.3%

        \[\leadsto \color{blue}{\phi_1 \cdot \left(-R\right)} \]
    7. Simplified64.3%

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

    if -2.29999999999999994e40 < phi1 < -6.20000000000000024e-35 or -7.00000000000000069e-251 < phi1 < 2.4999999999999999e-214

    1. Initial program 58.6%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-def95.6%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified95.6%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi1 around 0 93.2%

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)\right)} \]
    7. Step-by-step derivation
      1. mul-1-neg25.1%

        \[\leadsto \color{blue}{-R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)} \]
      2. *-commutative25.1%

        \[\leadsto -\color{blue}{\left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot R} \]
      3. distribute-rgt-neg-in25.1%

        \[\leadsto \color{blue}{\left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \left(-R\right)} \]
      4. *-commutative25.1%

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

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

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

    if -6.20000000000000024e-35 < phi1 < -7.00000000000000069e-251

    1. Initial program 79.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. Step-by-step derivation
      1. hypot-def99.9%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi1 around 0 99.9%

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

      \[\leadsto \color{blue}{R \cdot \left(\lambda_2 \cdot \left(\cos \left(0.5 \cdot \phi_2\right) + -0.5 \cdot \left(\phi_1 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right)} \]
    7. Taylor expanded in phi2 around 0 26.9%

      \[\leadsto \color{blue}{R \cdot \lambda_2} \]
    8. Step-by-step derivation
      1. *-commutative26.9%

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    9. Simplified26.9%

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

    if 2.4999999999999999e-214 < phi1

    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. Step-by-step derivation
      1. hypot-def94.6%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified94.6%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi2 around inf 22.0%

      \[\leadsto \color{blue}{R \cdot \phi_2} \]
    6. Step-by-step derivation
      1. *-commutative22.0%

        \[\leadsto \color{blue}{\phi_2 \cdot R} \]
    7. Simplified22.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -2.3 \cdot 10^{+40}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -6.2 \cdot 10^{-35}:\\ \;\;\;\;-R \cdot \lambda_1\\ \mathbf{elif}\;\phi_1 \leq -7 \cdot 10^{-251}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{elif}\;\phi_1 \leq 2.5 \cdot 10^{-214}:\\ \;\;\;\;-R \cdot \lambda_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 23.2% accurate, 46.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -2.4 \cdot 10^{+20}:\\ \;\;\;\;-R \cdot \lambda_1\\ \mathbf{elif}\;\lambda_1 \leq 1.36 \cdot 10^{-166}:\\ \;\;\;\;R \cdot \phi_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \lambda_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= lambda1 -2.4e+20)
   (- (* R lambda1))
   (if (<= lambda1 1.36e-166) (* R phi2) (* R lambda2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda1 <= -2.4e+20) {
		tmp = -(R * lambda1);
	} else if (lambda1 <= 1.36e-166) {
		tmp = R * phi2;
	} else {
		tmp = R * lambda2;
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: tmp
    if (lambda1 <= (-2.4d+20)) then
        tmp = -(r * lambda1)
    else if (lambda1 <= 1.36d-166) then
        tmp = r * phi2
    else
        tmp = r * lambda2
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda1 <= -2.4e+20) {
		tmp = -(R * lambda1);
	} else if (lambda1 <= 1.36e-166) {
		tmp = R * phi2;
	} else {
		tmp = R * lambda2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if lambda1 <= -2.4e+20:
		tmp = -(R * lambda1)
	elif lambda1 <= 1.36e-166:
		tmp = R * phi2
	else:
		tmp = R * lambda2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (lambda1 <= -2.4e+20)
		tmp = Float64(-Float64(R * lambda1));
	elseif (lambda1 <= 1.36e-166)
		tmp = Float64(R * phi2);
	else
		tmp = Float64(R * lambda2);
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (lambda1 <= -2.4e+20)
		tmp = -(R * lambda1);
	elseif (lambda1 <= 1.36e-166)
		tmp = R * phi2;
	else
		tmp = R * lambda2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda1, -2.4e+20], (-N[(R * lambda1), $MachinePrecision]), If[LessEqual[lambda1, 1.36e-166], N[(R * phi2), $MachinePrecision], N[(R * lambda2), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 \leq -2.4 \cdot 10^{+20}:\\
\;\;\;\;-R \cdot \lambda_1\\

\mathbf{elif}\;\lambda_1 \leq 1.36 \cdot 10^{-166}:\\
\;\;\;\;R \cdot \phi_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if lambda1 < -2.4e20

    1. Initial program 61.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. Step-by-step derivation
      1. hypot-def93.9%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified93.9%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi1 around 0 86.7%

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)\right)} \]
    7. Step-by-step derivation
      1. mul-1-neg44.6%

        \[\leadsto \color{blue}{-R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)} \]
      2. *-commutative44.6%

        \[\leadsto -\color{blue}{\left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot R} \]
      3. distribute-rgt-neg-in44.6%

        \[\leadsto \color{blue}{\left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \left(-R\right)} \]
      4. *-commutative44.6%

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

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

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

    if -2.4e20 < lambda1 < 1.3599999999999999e-166

    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. Step-by-step derivation
      1. hypot-def95.3%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified95.3%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi2 around inf 21.8%

      \[\leadsto \color{blue}{R \cdot \phi_2} \]
    6. Step-by-step derivation
      1. *-commutative21.8%

        \[\leadsto \color{blue}{\phi_2 \cdot R} \]
    7. Simplified21.8%

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

    if 1.3599999999999999e-166 < lambda1

    1. Initial program 67.2%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-def97.9%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified97.9%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi1 around 0 84.0%

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

      \[\leadsto \color{blue}{R \cdot \left(\lambda_2 \cdot \left(\cos \left(0.5 \cdot \phi_2\right) + -0.5 \cdot \left(\phi_1 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right)} \]
    7. Taylor expanded in phi2 around 0 19.3%

      \[\leadsto \color{blue}{R \cdot \lambda_2} \]
    8. Step-by-step derivation
      1. *-commutative19.3%

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    9. Simplified19.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -2.4 \cdot 10^{+20}:\\ \;\;\;\;-R \cdot \lambda_1\\ \mathbf{elif}\;\lambda_1 \leq 1.36 \cdot 10^{-166}:\\ \;\;\;\;R \cdot \phi_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \lambda_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 26.2% accurate, 65.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.3 \cdot 10^{+19}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi2 1.3e+19) (* R lambda2) (* R phi2)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 1.3e+19) {
		tmp = R * lambda2;
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: tmp
    if (phi2 <= 1.3d+19) then
        tmp = r * lambda2
    else
        tmp = r * phi2
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 1.3e+19) {
		tmp = R * lambda2;
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 1.3e+19:
		tmp = R * lambda2
	else:
		tmp = R * phi2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 1.3e+19)
		tmp = Float64(R * lambda2);
	else
		tmp = Float64(R * phi2);
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi2 <= 1.3e+19)
		tmp = R * lambda2;
	else
		tmp = R * phi2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 1.3e+19], N[(R * lambda2), $MachinePrecision], N[(R * phi2), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 1.3 \cdot 10^{+19}:\\
\;\;\;\;R \cdot \lambda_2\\

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


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

    1. Initial program 64.3%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-def98.0%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified98.0%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi1 around 0 85.5%

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

      \[\leadsto \color{blue}{R \cdot \left(\lambda_2 \cdot \left(\cos \left(0.5 \cdot \phi_2\right) + -0.5 \cdot \left(\phi_1 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right)} \]
    7. Taylor expanded in phi2 around 0 18.0%

      \[\leadsto \color{blue}{R \cdot \lambda_2} \]
    8. Step-by-step derivation
      1. *-commutative18.0%

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    9. Simplified18.0%

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

    if 1.3e19 < phi2

    1. Initial program 54.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. Step-by-step derivation
      1. hypot-def88.9%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified88.9%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi2 around inf 61.3%

      \[\leadsto \color{blue}{R \cdot \phi_2} \]
    6. Step-by-step derivation
      1. *-commutative61.3%

        \[\leadsto \color{blue}{\phi_2 \cdot R} \]
    7. Simplified61.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.3 \cdot 10^{+19}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 14.1% accurate, 109.7× speedup?

\[\begin{array}{l} \\ R \cdot \lambda_2 \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R lambda2))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * lambda2;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = r * lambda2
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * lambda2;
}
def code(R, lambda1, lambda2, phi1, phi2):
	return R * lambda2
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(R * lambda2)
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = R * lambda2;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * lambda2), $MachinePrecision]
\begin{array}{l}

\\
R \cdot \lambda_2
\end{array}
Derivation
  1. Initial program 62.2%

    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
  2. Step-by-step derivation
    1. hypot-def96.0%

      \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
  3. Simplified96.0%

    \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in phi1 around 0 83.9%

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

    \[\leadsto \color{blue}{R \cdot \left(\lambda_2 \cdot \left(\cos \left(0.5 \cdot \phi_2\right) + -0.5 \cdot \left(\phi_1 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right)} \]
  7. Taylor expanded in phi2 around 0 16.1%

    \[\leadsto \color{blue}{R \cdot \lambda_2} \]
  8. Step-by-step derivation
    1. *-commutative16.1%

      \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
  9. Simplified16.1%

    \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
  10. Final simplification16.1%

    \[\leadsto R \cdot \lambda_2 \]
  11. Add Preprocessing

Reproduce

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