Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.7% → 99.9%
Time: 23.9s
Alternatives: 12
Speedup: 3.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 12 alternatives:

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

Initial Program: 59.7% 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.5× speedup?

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

\\
R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \left(-\sin \left(0.5 \cdot \phi_1\right)\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 59.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. hypot-def96.6%

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

    \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
  4. Step-by-step derivation
    1. expm1-log1p-u96.6%

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \color{blue}{\left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)}\right)\right), \phi_1 - \phi_2\right) \]
    3. distribute-rgt-in96.6%

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \color{blue}{\left(0.5 \cdot \phi_1\right)}, -\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right)\right), \phi_1 - \phi_2\right) \]
    4. *-commutative99.8%

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), -\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \color{blue}{\left(0.5 \cdot \phi_2\right)}\right)\right)\right), \phi_1 - \phi_2\right) \]
    7. distribute-rgt-neg-in99.8%

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

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \sin \left(0.5 \cdot \phi_1\right) \cdot \left(-\sin \left(0.5 \cdot \phi_2\right)\right)\right)}\right)\right), \phi_1 - \phi_2\right) \]
  10. Taylor expanded in phi2 around inf 99.9%

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

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

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

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

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

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

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

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

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

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

Alternative 2: 95.8% accurate, 0.6× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda1 < -3.7999999999999998e124

    1. Initial program 53.8%

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

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

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Step-by-step derivation
      1. expm1-log1p-u92.4%

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right)\right)\right)}, \phi_1 - \phi_2\right) \]
    6. Step-by-step derivation
      1. +-commutative92.4%

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

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

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

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

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \color{blue}{\left(0.5 \cdot \phi_1\right)}, -\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right)\right), \phi_1 - \phi_2\right) \]
      4. *-commutative99.8%

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), -\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \color{blue}{\left(0.5 \cdot \phi_2\right)}\right)\right)\right), \phi_1 - \phi_2\right) \]
      7. distribute-rgt-neg-in99.8%

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

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

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

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

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

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

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

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

    if -3.7999999999999998e124 < lambda1

    1. Initial program 60.4%

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

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

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

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

Alternative 3: 99.9% accurate, 0.6× speedup?

\[\begin{array}{l} \\ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(0.5 \cdot \phi_1\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 (* 0.5 phi2)) (cos (* 0.5 phi1)))
     (* (sin (* 0.5 phi1)) (sin (* 0.5 phi2)))))
   (- phi1 phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * hypot(((lambda1 - lambda2) * ((cos((0.5 * phi2)) * cos((0.5 * phi1))) - (sin((0.5 * phi1)) * 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((0.5 * phi2)) * Math.cos((0.5 * phi1))) - (Math.sin((0.5 * phi1)) * Math.sin((0.5 * phi2))))), (phi1 - phi2));
}
def code(R, lambda1, lambda2, phi1, phi2):
	return R * math.hypot(((lambda1 - lambda2) * ((math.cos((0.5 * phi2)) * math.cos((0.5 * phi1))) - (math.sin((0.5 * phi1)) * 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(0.5 * phi2)) * cos(Float64(0.5 * phi1))) - Float64(sin(Float64(0.5 * phi1)) * sin(Float64(0.5 * phi2))))), Float64(phi1 - phi2)))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = R * hypot(((lambda1 - lambda2) * ((cos((0.5 * phi2)) * cos((0.5 * phi1))) - (sin((0.5 * phi1)) * 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[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(0.5 * phi1), $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(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right), \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 59.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. hypot-def96.6%

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

    \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
  4. Step-by-step derivation
    1. expm1-log1p-u96.6%

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \color{blue}{\left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)}\right)\right), \phi_1 - \phi_2\right) \]
    3. distribute-rgt-in96.6%

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \color{blue}{\left(0.5 \cdot \phi_1\right)}, -\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right)\right), \phi_1 - \phi_2\right) \]
    4. *-commutative99.8%

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), -\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \color{blue}{\left(0.5 \cdot \phi_2\right)}\right)\right)\right), \phi_1 - \phi_2\right) \]
    7. distribute-rgt-neg-in99.8%

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

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \sin \left(0.5 \cdot \phi_1\right) \cdot \left(-\sin \left(0.5 \cdot \phi_2\right)\right)\right)}\right)\right), \phi_1 - \phi_2\right) \]
  10. Taylor expanded in phi2 around inf 99.9%

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

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

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

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

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

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

Alternative 4: 85.1% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 - \lambda_2 \leq -3.1 \cdot 10^{+220}:\\
\;\;\;\;\left|\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \left(R \cdot \left(\lambda_1 - \lambda_2\right)\right)\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 lambda1 lambda2) < -3.1000000000000001e220

    1. Initial program 50.4%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \lambda_1\right)} \cdot R - R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right) \]
      6. associate-*l*29.2%

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

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

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

        \[\leadsto \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \left(\lambda_1 \cdot R\right) - \color{blue}{\left(\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \lambda_2\right)} \cdot R \]
      10. associate-*l*29.2%

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

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

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \left(\lambda_1 \cdot R\right) - \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \left(\lambda_2 \cdot R\right)} \]
    7. Step-by-step derivation
      1. add-sqr-sqrt26.4%

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

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

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

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

        \[\leadsto \sqrt{{\left(\cos \left(0.5 \cdot \color{blue}{\left(\phi_1 + \phi_2\right)}\right) \cdot \left(\lambda_1 \cdot R - \lambda_2 \cdot R\right)\right)}^{2}} \]
      6. distribute-rgt-out--48.7%

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

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

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

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

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

        \[\leadsto \left|\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot R\right)}\right| \]
    10. Applied egg-rr60.9%

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

    if -3.1000000000000001e220 < (-.f64 lambda1 lambda2)

    1. Initial program 61.1%

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

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

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

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

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

Alternative 5: 69.2% accurate, 1.5× speedup?

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

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

\mathbf{elif}\;\phi_1 \leq -6.5 \cdot 10^{-8}:\\
\;\;\;\;\left|\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \left(R \cdot \left(\lambda_1 - \lambda_2\right)\right)\right|\\

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


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

    1. Initial program 51.0%

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

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

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

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

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

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

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

    if -1.9000000000000001e83 < phi1 < -6.49999999999999997e-8

    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. hypot-def87.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \lambda_1\right)} \cdot R - R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right) \]
      6. associate-*l*33.0%

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

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

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

        \[\leadsto \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \left(\lambda_1 \cdot R\right) - \color{blue}{\left(\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \lambda_2\right)} \cdot R \]
      10. associate-*l*33.0%

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

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

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

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

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

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

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

        \[\leadsto \sqrt{{\left(\cos \left(0.5 \cdot \color{blue}{\left(\phi_1 + \phi_2\right)}\right) \cdot \left(\lambda_1 \cdot R - \lambda_2 \cdot R\right)\right)}^{2}} \]
      6. distribute-rgt-out--31.3%

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

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

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

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

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

        \[\leadsto \left|\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot R\right)}\right| \]
    10. Applied egg-rr36.9%

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

    if -6.49999999999999997e-8 < phi1

    1. Initial program 61.7%

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

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

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

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

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

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

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

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

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot \color{blue}{0.5}\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\right)}^{3}\right)}^{0.3333333333333333} \]
    5. Applied egg-rr34.9%

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

      \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\color{blue}{\cos \left(0.5 \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\right)}^{3}\right)}^{0.3333333333333333} \]
    7. Taylor expanded in phi1 around 0 53.3%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.9 \cdot 10^{+83}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -6.5 \cdot 10^{-8}:\\ \;\;\;\;\left|\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \left(R \cdot \left(\lambda_1 - \lambda_2\right)\right)\right|\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \lambda_1 - \lambda_2\right)\\ \end{array} \]

Alternative 6: 93.4% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 61.9%

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

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

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

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

    if 2.69999999999999998e-6 < phi2

    1. Initial program 51.5%

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

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

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

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

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

Alternative 7: 96.3% accurate, 1.5× speedup?

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

\\
R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_2 + \phi_1}{2}\right), \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 59.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. hypot-def96.6%

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

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

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

Alternative 8: 69.3% accurate, 2.9× speedup?

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

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

\mathbf{elif}\;\phi_1 \leq -4200000000:\\
\;\;\;\;R \cdot \left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \left(\lambda_2 - \lambda_1\right)\right)\\

\mathbf{elif}\;\phi_1 \leq -0.00178:\\
\;\;\;\;R \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)\\

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


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

    1. Initial program 51.0%

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

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

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

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

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

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

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

    if -8.60000000000000008e80 < phi1 < -4.2e9

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

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

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

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

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

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

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

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

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

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

    if -4.2e9 < phi1 < -0.0017799999999999999

    1. Initial program 98.4%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \lambda_1\right)} \cdot R - R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right) \]
      6. associate-*l*0.9%

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

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

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

        \[\leadsto \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \left(\lambda_1 \cdot R\right) - \color{blue}{\left(\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \lambda_2\right)} \cdot R \]
      10. associate-*l*0.9%

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

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

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

      \[\leadsto \color{blue}{R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right) - R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
    8. Step-by-step derivation
      1. distribute-lft-out--0.9%

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

        \[\leadsto R \cdot \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \]
    9. Simplified0.9%

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

    if -0.0017799999999999999 < phi1

    1. Initial program 61.8%

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

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

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

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

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

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

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

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

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot \color{blue}{0.5}\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\right)}^{3}\right)}^{0.3333333333333333} \]
    5. Applied egg-rr34.4%

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

      \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\color{blue}{\cos \left(0.5 \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\right)}^{3}\right)}^{0.3333333333333333} \]
    7. Taylor expanded in phi1 around 0 53.5%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -8.6 \cdot 10^{+80}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -4200000000:\\ \;\;\;\;R \cdot \left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \left(\lambda_2 - \lambda_1\right)\right)\\ \mathbf{elif}\;\phi_1 \leq -0.00178:\\ \;\;\;\;R \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \lambda_1 - \lambda_2\right)\\ \end{array} \]

Alternative 9: 71.4% accurate, 3.0× speedup?

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

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

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


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

    1. Initial program 51.0%

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

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

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

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

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

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

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

    if -5.8000000000000003e82 < phi1

    1. Initial program 61.7%

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

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

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Step-by-step derivation
      1. add-cbrt-cube62.6%

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

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

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

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

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

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot \color{blue}{0.5}\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\right)}^{3}\right)}^{0.3333333333333333} \]
    5. Applied egg-rr34.0%

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

      \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\color{blue}{\cos \left(0.5 \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\right)}^{3}\right)}^{0.3333333333333333} \]
    7. Taylor expanded in phi1 around 0 52.7%

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

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

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

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

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

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

Alternative 10: 27.3% accurate, 54.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -1.3 \cdot 10^{+86}:\\
\;\;\;\;-R \cdot \phi_1\\

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


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

    1. Initial program 51.0%

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

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

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

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

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

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

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

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

    if -1.2999999999999999e86 < phi1

    1. Initial program 61.7%

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

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

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

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

        \[\leadsto \color{blue}{\phi_2 \cdot R} \]
    6. Simplified16.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.3 \cdot 10^{+86}:\\ \;\;\;\;-R \cdot \phi_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]

Alternative 11: 29.2% accurate, 65.8× speedup?

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

\\
R \cdot \left(\phi_2 - \phi_1\right)
\end{array}
Derivation
  1. Initial program 59.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. hypot-def96.6%

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

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

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

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

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

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

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

Alternative 12: 17.1% 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 59.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. hypot-def96.6%

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

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

    \[\leadsto \color{blue}{R \cdot \phi_2} \]
  5. Step-by-step derivation
    1. *-commutative15.2%

      \[\leadsto \color{blue}{\phi_2 \cdot R} \]
  6. Simplified15.2%

    \[\leadsto \color{blue}{\phi_2 \cdot R} \]
  7. Final simplification15.2%

    \[\leadsto R \cdot \phi_2 \]

Reproduce

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