Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.1% → 99.9%
Time: 32.0s
Alternatives: 14
Speedup: 2.9×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 14 alternatives:

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

Initial Program: 60.1% 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(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(\phi_1 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right), \phi_1 - \phi_2\right) \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R
  (hypot
   (*
    (- lambda1 lambda2)
    (-
     (* (cos (* phi1 0.5)) (cos (* 0.5 phi2)))
     (* (sin (* phi1 0.5)) (sin (* 0.5 phi2)))))
   (- phi1 phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * hypot(((lambda1 - lambda2) * ((cos((phi1 * 0.5)) * cos((0.5 * phi2))) - (sin((phi1 * 0.5)) * sin((0.5 * phi2))))), (phi1 - phi2));
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * Math.hypot(((lambda1 - lambda2) * ((Math.cos((phi1 * 0.5)) * Math.cos((0.5 * phi2))) - (Math.sin((phi1 * 0.5)) * Math.sin((0.5 * phi2))))), (phi1 - phi2));
}
def code(R, lambda1, lambda2, phi1, phi2):
	return R * math.hypot(((lambda1 - lambda2) * ((math.cos((phi1 * 0.5)) * math.cos((0.5 * phi2))) - (math.sin((phi1 * 0.5)) * math.sin((0.5 * phi2))))), (phi1 - phi2))
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(R * hypot(Float64(Float64(lambda1 - lambda2) * Float64(Float64(cos(Float64(phi1 * 0.5)) * cos(Float64(0.5 * phi2))) - Float64(sin(Float64(phi1 * 0.5)) * sin(Float64(0.5 * phi2))))), Float64(phi1 - phi2)))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = R * hypot(((lambda1 - lambda2) * ((cos((phi1 * 0.5)) * cos((0.5 * phi2))) - (sin((phi1 * 0.5)) * sin((0.5 * phi2))))), (phi1 - phi2));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[Sqrt[N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(N[(N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision]), $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 \left(\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(\phi_1 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right), \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 61.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. Step-by-step derivation
    1. add-sqr-sqrt61.2%

      \[\leadsto R \cdot \color{blue}{\left(\sqrt{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \cdot \sqrt{\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)}}\right)} \]
    2. pow261.2%

      \[\leadsto R \cdot \color{blue}{{\left(\sqrt{\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)}}\right)}^{2}} \]
  3. Applied egg-rr96.4%

    \[\leadsto R \cdot \color{blue}{{\left(\sqrt{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right), \phi_1 - \phi_2\right)}\right)}^{2}} \]
  4. Step-by-step derivation
    1. *-commutative96.4%

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

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

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

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

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

      \[\leadsto R \cdot {\left(\sqrt{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\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(\phi_2 \cdot 0.5\right)\right), \phi_1 - \phi_2\right)}\right)}^{2} \]
  5. Applied egg-rr99.4%

    \[\leadsto R \cdot {\left(\sqrt{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\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)}\right)}^{2} \]
  6. Step-by-step derivation
    1. cancel-sign-sub-inv99.4%

      \[\leadsto R \cdot {\left(\sqrt{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(\phi_2 \cdot 0.5\right) + \left(-\sin \left(\phi_1 \cdot 0.5\right)\right) \cdot \sin \left(\phi_2 \cdot 0.5\right)\right)}, \phi_1 - \phi_2\right)}\right)}^{2} \]
    2. add-cube-cbrt99.3%

      \[\leadsto R \cdot {\left(\sqrt{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\color{blue}{\left(\sqrt[3]{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)} \cdot \sqrt[3]{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)}\right) \cdot \sqrt[3]{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)}} + \left(-\sin \left(\phi_1 \cdot 0.5\right)\right) \cdot \sin \left(\phi_2 \cdot 0.5\right)\right), \phi_1 - \phi_2\right)}\right)}^{2} \]
    3. fma-def99.3%

      \[\leadsto R \cdot {\left(\sqrt{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\mathsf{fma}\left(\sqrt[3]{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)} \cdot \sqrt[3]{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)}, \sqrt[3]{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)}, \left(-\sin \left(\phi_1 \cdot 0.5\right)\right) \cdot \sin \left(\phi_2 \cdot 0.5\right)\right)}, \phi_1 - \phi_2\right)}\right)}^{2} \]
    4. pow299.3%

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

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

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

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

    \[\leadsto R \cdot {\left(\sqrt{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\mathsf{fma}\left({\left(\sqrt[3]{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_2\right)}\right)}^{2}, \sqrt[3]{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_2\right)}, \left(-\sin \left(\phi_1 \cdot 0.5\right)\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}, \phi_1 - \phi_2\right)}\right)}^{2} \]
  8. Step-by-step derivation
    1. unpow299.3%

      \[\leadsto R \cdot \color{blue}{\left(\sqrt{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left({\left(\sqrt[3]{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_2\right)}\right)}^{2}, \sqrt[3]{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_2\right)}, \left(-\sin \left(\phi_1 \cdot 0.5\right)\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right), \phi_1 - \phi_2\right)} \cdot \sqrt{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left({\left(\sqrt[3]{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_2\right)}\right)}^{2}, \sqrt[3]{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_2\right)}, \left(-\sin \left(\phi_1 \cdot 0.5\right)\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right), \phi_1 - \phi_2\right)}\right)} \]
    2. add-sqr-sqrt99.7%

      \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left({\left(\sqrt[3]{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_2\right)}\right)}^{2}, \sqrt[3]{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_2\right)}, \left(-\sin \left(\phi_1 \cdot 0.5\right)\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right), \phi_1 - \phi_2\right)} \]
  9. Applied egg-rr99.9%

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

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

Alternative 2: 82.2% accurate, 0.8× speedup?

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

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

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


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

    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. Taylor expanded in phi2 around 0 55.2%

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      4. unswap-sqr55.2%

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

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

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

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

    if 1.8999999999999999e-11 < phi2

    1. Initial program 53.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. add-sqr-sqrt52.9%

        \[\leadsto R \cdot \color{blue}{\left(\sqrt{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \cdot \sqrt{\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)}}\right)} \]
      2. pow252.9%

        \[\leadsto R \cdot \color{blue}{{\left(\sqrt{\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)}}\right)}^{2}} \]
    3. Applied egg-rr93.7%

      \[\leadsto R \cdot \color{blue}{{\left(\sqrt{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right), \phi_1 - \phi_2\right)}\right)}^{2}} \]
    4. Taylor expanded in phi1 around 0 93.7%

      \[\leadsto R \cdot {\left(\sqrt{\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)}\right)}^{2} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification83.1%

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

Alternative 3: 94.7% accurate, 0.8× speedup?

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

\\
R \cdot {\left(\sqrt[3]{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right), \phi_1 - \phi_2\right)}\right)}^{3}
\end{array}
Derivation
  1. Initial program 61.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. Step-by-step derivation
    1. add-cube-cbrt60.9%

      \[\leadsto R \cdot \color{blue}{\left(\left(\sqrt[3]{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \cdot \sqrt[3]{\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)}}\right) \cdot \sqrt[3]{\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)}}\right)} \]
    2. pow361.0%

      \[\leadsto R \cdot \color{blue}{{\left(\sqrt[3]{\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)}}\right)}^{3}} \]
  3. Applied egg-rr95.7%

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

    \[\leadsto R \cdot {\left(\sqrt[3]{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right), \phi_1 - \phi_2\right)}\right)}^{3} \]

Alternative 4: 95.5% accurate, 0.8× speedup?

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

\\
R \cdot {\left(\sqrt{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right), \phi_1 - \phi_2\right)}\right)}^{2}
\end{array}
Derivation
  1. Initial program 61.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. Step-by-step derivation
    1. add-sqr-sqrt61.2%

      \[\leadsto R \cdot \color{blue}{\left(\sqrt{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \cdot \sqrt{\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)}}\right)} \]
    2. pow261.2%

      \[\leadsto R \cdot \color{blue}{{\left(\sqrt{\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)}}\right)}^{2}} \]
  3. Applied egg-rr96.4%

    \[\leadsto R \cdot \color{blue}{{\left(\sqrt{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right), \phi_1 - \phi_2\right)}\right)}^{2}} \]
  4. Final simplification96.4%

    \[\leadsto R \cdot {\left(\sqrt{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right), \phi_1 - \phi_2\right)}\right)}^{2} \]

Alternative 5: 75.9% accurate, 1.6× speedup?

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

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

\mathbf{elif}\;\phi_2 \leq 1.75 \cdot 10^{+159} \lor \neg \left(\phi_2 \leq 1.5 \cdot 10^{+173}\right):\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\

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


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

    1. Initial program 63.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. Taylor expanded in phi2 around 0 52.4%

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      4. unswap-sqr52.4%

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

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

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

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

    if 1.75e119 < phi2 < 1.75e159 or 1.4999999999999999e173 < phi2

    1. Initial program 45.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. Taylor expanded in phi1 around -inf 79.1%

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

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

        \[\leadsto R \cdot \left(\phi_2 + \color{blue}{\left(-\phi_1\right)}\right) \]
      3. unsub-neg79.1%

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

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

    if 1.75e159 < phi2 < 1.4999999999999999e173

    1. Initial program 72.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. Taylor expanded in lambda1 around inf 43.1%

      \[\leadsto R \cdot \color{blue}{\left(\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \lambda_1 + -1 \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} \]
    3. Step-by-step derivation
      1. mul-1-neg43.1%

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

        \[\leadsto R \cdot \left(\cos \color{blue}{\left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right)} \cdot \lambda_1 + \left(-\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right) \]
      3. *-commutative43.1%

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

        \[\leadsto R \cdot \left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right) \cdot \lambda_1 + \left(-\cos \color{blue}{\left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right)} \cdot \lambda_2\right)\right) \]
      5. distribute-rgt-neg-out43.1%

        \[\leadsto R \cdot \left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right) \cdot \lambda_1 + \color{blue}{\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right) \cdot \left(-\lambda_2\right)}\right) \]
      6. distribute-lft-out43.1%

        \[\leadsto R \cdot \color{blue}{\left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right) \cdot \left(\lambda_1 + \left(-\lambda_2\right)\right)\right)} \]
      7. sub-neg43.1%

        \[\leadsto R \cdot \left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right) \cdot \color{blue}{\left(\lambda_1 - \lambda_2\right)}\right) \]
      8. *-commutative43.1%

        \[\leadsto R \cdot \left(\cos \color{blue}{\left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \]
      9. *-commutative43.1%

        \[\leadsto R \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \]
    4. Simplified43.1%

      \[\leadsto R \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \]
    5. Taylor expanded in phi1 around 0 43.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.75 \cdot 10^{+119}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\phi_1 \cdot 0.5\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 1.75 \cdot 10^{+159} \lor \neg \left(\phi_2 \leq 1.5 \cdot 10^{+173}\right):\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_2\right)\right)\\ \end{array} \]

Alternative 6: 79.4% accurate, 1.6× speedup?

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

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

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


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

    1. Initial program 57.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. Taylor expanded in phi2 around 0 54.4%

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      4. unswap-sqr54.4%

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      5. hypot-def81.6%

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

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

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

    if -2.59999999999999977e-4 < phi1

    1. Initial program 62.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. Taylor expanded in phi1 around 0 57.1%

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_2 \cdot \phi_2 + \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      4. unswap-sqr57.1%

        \[\leadsto R \cdot \sqrt{\phi_2 \cdot \phi_2 + \color{blue}{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      5. hypot-def85.1%

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

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

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

Alternative 7: 71.0% accurate, 2.9× speedup?

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

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

\mathbf{elif}\;\phi_2 \leq 1.75 \cdot 10^{+159} \lor \neg \left(\phi_2 \leq 1.5 \cdot 10^{+173}\right):\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\

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


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

    1. Initial program 63.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. Taylor expanded in phi2 around 0 52.4%

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      4. unswap-sqr52.4%

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

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

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

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

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

    if 5.5000000000000003e118 < phi2 < 1.75e159 or 1.4999999999999999e173 < phi2

    1. Initial program 45.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. Taylor expanded in phi1 around -inf 79.1%

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

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

        \[\leadsto R \cdot \left(\phi_2 + \color{blue}{\left(-\phi_1\right)}\right) \]
      3. unsub-neg79.1%

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

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

    if 1.75e159 < phi2 < 1.4999999999999999e173

    1. Initial program 72.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. Taylor expanded in lambda1 around inf 43.1%

      \[\leadsto R \cdot \color{blue}{\left(\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \lambda_1 + -1 \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} \]
    3. Step-by-step derivation
      1. mul-1-neg43.1%

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

        \[\leadsto R \cdot \left(\cos \color{blue}{\left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right)} \cdot \lambda_1 + \left(-\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right) \]
      3. *-commutative43.1%

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

        \[\leadsto R \cdot \left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right) \cdot \lambda_1 + \left(-\cos \color{blue}{\left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right)} \cdot \lambda_2\right)\right) \]
      5. distribute-rgt-neg-out43.1%

        \[\leadsto R \cdot \left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right) \cdot \lambda_1 + \color{blue}{\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right) \cdot \left(-\lambda_2\right)}\right) \]
      6. distribute-lft-out43.1%

        \[\leadsto R \cdot \color{blue}{\left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right) \cdot \left(\lambda_1 + \left(-\lambda_2\right)\right)\right)} \]
      7. sub-neg43.1%

        \[\leadsto R \cdot \left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right) \cdot \color{blue}{\left(\lambda_1 - \lambda_2\right)}\right) \]
      8. *-commutative43.1%

        \[\leadsto R \cdot \left(\cos \color{blue}{\left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \]
      9. *-commutative43.1%

        \[\leadsto R \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \]
    4. Simplified43.1%

      \[\leadsto R \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \]
    5. Taylor expanded in phi1 around 0 43.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 5.5 \cdot 10^{+118}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\ \mathbf{elif}\;\phi_2 \leq 1.75 \cdot 10^{+159} \lor \neg \left(\phi_2 \leq 1.5 \cdot 10^{+173}\right):\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_2\right)\right)\\ \end{array} \]

Alternative 8: 71.2% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 5.5 \cdot 10^{+118} \lor \neg \left(\phi_2 \leq 2.25 \cdot 10^{+154}\right) \land \phi_2 \leq 7 \cdot 10^{+176}:\\ \;\;\;\;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 (or (<= phi2 5.5e+118) (and (not (<= phi2 2.25e+154)) (<= phi2 7e+176)))
   (* R (hypot phi1 (- lambda1 lambda2)))
   (* R (- phi2 phi1))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if ((phi2 <= 5.5e+118) || (!(phi2 <= 2.25e+154) && (phi2 <= 7e+176))) {
		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 <= 5.5e+118) || (!(phi2 <= 2.25e+154) && (phi2 <= 7e+176))) {
		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 <= 5.5e+118) or (not (phi2 <= 2.25e+154) and (phi2 <= 7e+176)):
		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 <= 5.5e+118) || (!(phi2 <= 2.25e+154) && (phi2 <= 7e+176)))
		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 <= 5.5e+118) || (~((phi2 <= 2.25e+154)) && (phi2 <= 7e+176)))
		tmp = R * hypot(phi1, (lambda1 - lambda2));
	else
		tmp = R * (phi2 - phi1);
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[Or[LessEqual[phi2, 5.5e+118], And[N[Not[LessEqual[phi2, 2.25e+154]], $MachinePrecision], LessEqual[phi2, 7e+176]]], 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 5.5 \cdot 10^{+118} \lor \neg \left(\phi_2 \leq 2.25 \cdot 10^{+154}\right) \land \phi_2 \leq 7 \cdot 10^{+176}:\\
\;\;\;\;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 < 5.5000000000000003e118 or 2.25000000000000005e154 < phi2 < 7.00000000000000005e176

    1. Initial program 64.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. Taylor expanded in phi2 around 0 53.3%

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      4. unswap-sqr53.3%

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      5. hypot-def75.6%

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

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

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

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

    if 5.5000000000000003e118 < phi2 < 2.25000000000000005e154 or 7.00000000000000005e176 < phi2

    1. Initial program 43.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. Taylor expanded in phi1 around -inf 80.1%

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

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

        \[\leadsto R \cdot \left(\phi_2 + \color{blue}{\left(-\phi_1\right)}\right) \]
      3. unsub-neg80.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 5.5 \cdot 10^{+118} \lor \neg \left(\phi_2 \leq 2.25 \cdot 10^{+154}\right) \land \phi_2 \leq 7 \cdot 10^{+176}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \end{array} \]

Alternative 9: 44.2% accurate, 3.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 \leq -1.5 \cdot 10^{+128}:\\
\;\;\;\;R \cdot \left(-\lambda_1\right)\\

\mathbf{elif}\;\lambda_1 \leq 2.25 \cdot 10^{-252}:\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\

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


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

    1. Initial program 53.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. Taylor expanded in phi2 around 0 51.1%

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      4. unswap-sqr51.1%

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      5. hypot-def79.9%

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

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

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

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

        \[\leadsto R \cdot \color{blue}{\left(-\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1\right)} \]
      2. distribute-rgt-neg-in64.2%

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

      \[\leadsto R \cdot \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(-\lambda_1\right)\right)} \]
    8. Taylor expanded in phi1 around 0 64.8%

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

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

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

        \[\leadsto \color{blue}{\lambda_1 \cdot \left(-R\right)} \]
    10. Simplified64.8%

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

    if -1.4999999999999999e128 < lambda1 < 2.2500000000000001e-252

    1. Initial program 61.0%

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

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

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 + -1 \cdot \phi_1\right)} \]
      2. mul-1-neg37.3%

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

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

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

    if 2.2500000000000001e-252 < lambda1

    1. Initial program 65.0%

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

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      4. unswap-sqr51.9%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{-\lambda_2}\right) \]
    10. Simplified53.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -1.5 \cdot 10^{+128}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq 2.25 \cdot 10^{-252}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, -\lambda_2\right)\\ \end{array} \]

Alternative 10: 28.6% accurate, 36.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 \leq -2.8 \cdot 10^{+131}:\\
\;\;\;\;R \cdot \left(-\lambda_1\right)\\

\mathbf{elif}\;\lambda_1 \leq 2.3 \cdot 10^{-231}:\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\

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


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

    1. Initial program 53.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. Taylor expanded in phi2 around 0 51.1%

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      4. unswap-sqr51.1%

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      5. hypot-def79.9%

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

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

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

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

        \[\leadsto R \cdot \color{blue}{\left(-\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1\right)} \]
      2. distribute-rgt-neg-in64.2%

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

      \[\leadsto R \cdot \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(-\lambda_1\right)\right)} \]
    8. Taylor expanded in phi1 around 0 64.8%

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

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

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

        \[\leadsto \color{blue}{\lambda_1 \cdot \left(-R\right)} \]
    10. Simplified64.8%

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

    if -2.8000000000000001e131 < lambda1 < 2.3e-231

    1. Initial program 62.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. Taylor expanded in phi1 around -inf 38.1%

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

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

        \[\leadsto R \cdot \left(\phi_2 + \color{blue}{\left(-\phi_1\right)}\right) \]
      3. unsub-neg38.1%

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

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

    if 2.3e-231 < lambda1

    1. Initial program 64.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. Taylor expanded in phi2 around 0 51.5%

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      4. unswap-sqr51.5%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -2.8 \cdot 10^{+131}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq 2.3 \cdot 10^{-231}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \lambda_2\\ \end{array} \]

Alternative 11: 28.1% accurate, 40.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -7.8 \cdot 10^{-14}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -1.55 \cdot 10^{-307}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi1 -7.8e-14)
   (* R (- phi1))
   (if (<= phi1 -1.55e-307) (* R (- lambda1)) (* R phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -7.8e-14) {
		tmp = R * -phi1;
	} else if (phi1 <= -1.55e-307) {
		tmp = R * -lambda1;
	} 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 (phi1 <= (-7.8d-14)) then
        tmp = r * -phi1
    else if (phi1 <= (-1.55d-307)) then
        tmp = r * -lambda1
    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 (phi1 <= -7.8e-14) {
		tmp = R * -phi1;
	} else if (phi1 <= -1.55e-307) {
		tmp = R * -lambda1;
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -7.8e-14:
		tmp = R * -phi1
	elif phi1 <= -1.55e-307:
		tmp = R * -lambda1
	else:
		tmp = R * phi2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -7.8e-14)
		tmp = Float64(R * Float64(-phi1));
	elseif (phi1 <= -1.55e-307)
		tmp = Float64(R * Float64(-lambda1));
	else
		tmp = Float64(R * phi2);
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi1 <= -7.8e-14)
		tmp = R * -phi1;
	elseif (phi1 <= -1.55e-307)
		tmp = R * -lambda1;
	else
		tmp = R * phi2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -7.8e-14], N[(R * (-phi1)), $MachinePrecision], If[LessEqual[phi1, -1.55e-307], N[(R * (-lambda1)), $MachinePrecision], N[(R * phi2), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -7.8 \cdot 10^{-14}:\\
\;\;\;\;R \cdot \left(-\phi_1\right)\\

\mathbf{elif}\;\phi_1 \leq -1.55 \cdot 10^{-307}:\\
\;\;\;\;R \cdot \left(-\lambda_1\right)\\

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


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

    1. Initial program 57.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. Taylor expanded in phi1 around -inf 58.6%

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

        \[\leadsto R \cdot \color{blue}{\left(-\phi_1\right)} \]
    4. Simplified58.6%

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

    if -7.7999999999999996e-14 < phi1 < -1.5499999999999999e-307

    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. Taylor expanded in phi2 around 0 42.8%

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      4. unswap-sqr42.8%

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

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

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

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

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

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

        \[\leadsto R \cdot \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(-\lambda_1\right)\right)} \]
    7. Simplified21.6%

      \[\leadsto R \cdot \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(-\lambda_1\right)\right)} \]
    8. Taylor expanded in phi1 around 0 21.6%

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

        \[\leadsto \color{blue}{-R \cdot \lambda_1} \]
      2. *-commutative21.6%

        \[\leadsto -\color{blue}{\lambda_1 \cdot R} \]
      3. distribute-rgt-neg-in21.6%

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

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

    if -1.5499999999999999e-307 < phi1

    1. Initial program 63.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. Taylor expanded in phi2 around inf 17.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -7.8 \cdot 10^{-14}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -1.55 \cdot 10^{-307}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]

Alternative 12: 28.3% accurate, 46.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 4.5 \cdot 10^{-209}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_2 \leq 410:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi2 4.5e-209)
   (* R (- phi1))
   (if (<= phi2 410.0) (* R lambda2) (* R phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 4.5e-209) {
		tmp = R * -phi1;
	} else if (phi2 <= 410.0) {
		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 <= 4.5d-209) then
        tmp = r * -phi1
    else if (phi2 <= 410.0d0) 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 <= 4.5e-209) {
		tmp = R * -phi1;
	} else if (phi2 <= 410.0) {
		tmp = R * lambda2;
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 4.5e-209:
		tmp = R * -phi1
	elif phi2 <= 410.0:
		tmp = R * lambda2
	else:
		tmp = R * phi2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 4.5e-209)
		tmp = Float64(R * Float64(-phi1));
	elseif (phi2 <= 410.0)
		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 <= 4.5e-209)
		tmp = R * -phi1;
	elseif (phi2 <= 410.0)
		tmp = R * lambda2;
	else
		tmp = R * phi2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 4.5e-209], N[(R * (-phi1)), $MachinePrecision], If[LessEqual[phi2, 410.0], N[(R * lambda2), $MachinePrecision], N[(R * phi2), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 4.5 \cdot 10^{-209}:\\
\;\;\;\;R \cdot \left(-\phi_1\right)\\

\mathbf{elif}\;\phi_2 \leq 410:\\
\;\;\;\;R \cdot \lambda_2\\

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


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

    1. Initial program 66.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. Taylor expanded in phi1 around -inf 17.7%

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

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

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

    if 4.4999999999999998e-209 < phi2 < 410

    1. Initial program 59.7%

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

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      4. unswap-sqr59.7%

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

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

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

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

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

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

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

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

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

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

    if 410 < phi2

    1. Initial program 53.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. Taylor expanded in phi2 around inf 52.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 4.5 \cdot 10^{-209}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_2 \leq 410:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]

Alternative 13: 25.6% accurate, 65.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 9.5 \cdot 10^{+32}:\\ \;\;\;\;R \cdot \phi_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \lambda_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= lambda2 9.5e+32) (* R phi2) (* R lambda2)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda2 <= 9.5e+32) {
		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 (lambda2 <= 9.5d+32) 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 (lambda2 <= 9.5e+32) {
		tmp = R * phi2;
	} else {
		tmp = R * lambda2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if lambda2 <= 9.5e+32:
		tmp = R * phi2
	else:
		tmp = R * lambda2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (lambda2 <= 9.5e+32)
		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 (lambda2 <= 9.5e+32)
		tmp = R * phi2;
	else
		tmp = R * lambda2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda2, 9.5e+32], N[(R * phi2), $MachinePrecision], N[(R * lambda2), $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda2 < 9.50000000000000006e32

    1. Initial program 60.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. Taylor expanded in phi2 around inf 18.5%

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

    if 9.50000000000000006e32 < lambda2

    1. Initial program 63.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. Taylor expanded in phi2 around 0 61.1%

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      4. unswap-sqr61.1%

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      5. hypot-def78.9%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 9.5 \cdot 10^{+32}:\\ \;\;\;\;R \cdot \phi_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \lambda_2\\ \end{array} \]

Alternative 14: 17.7% accurate, 109.7× speedup?

\[\begin{array}{l} \\ R \cdot \phi_2 \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R phi2))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * 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
    code = r * phi2
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * phi2;
}
def code(R, lambda1, lambda2, phi1, phi2):
	return R * phi2
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(R * phi2)
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = R * phi2;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * phi2), $MachinePrecision]
\begin{array}{l}

\\
R \cdot \phi_2
\end{array}
Derivation
  1. Initial program 61.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. Taylor expanded in phi2 around inf 16.7%

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

    \[\leadsto R \cdot \phi_2 \]

Reproduce

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