Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.1% → 99.8%
Time: 29.6s
Alternatives: 18
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 18 alternatives:

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

Initial Program: 60.1% accurate, 1.0× speedup?

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

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

Alternative 1: 99.8% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(0.5 \cdot \phi_1\right)\\ t_1 := \sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot t\_0}\\ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\mathsf{fma}\left(\cos \left(\phi_2 \cdot 0.5\right), \cos \left(0.5 \cdot \phi_1\right), {t\_1}^{2} \cdot \left(-t\_1\right)\right) + \phi_2 \cdot \left(t\_0 \cdot 0\right)\right), \phi_1 - \phi_2\right) \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (* 0.5 phi1))) (t_1 (cbrt (* (sin (* phi2 0.5)) t_0))))
   (*
    R
    (hypot
     (*
      (- lambda1 lambda2)
      (+
       (fma (cos (* phi2 0.5)) (cos (* 0.5 phi1)) (* (pow t_1 2.0) (- t_1)))
       (* phi2 (* t_0 0.0))))
     (- phi1 phi2)))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin((0.5 * phi1));
	double t_1 = cbrt((sin((phi2 * 0.5)) * t_0));
	return R * hypot(((lambda1 - lambda2) * (fma(cos((phi2 * 0.5)), cos((0.5 * phi1)), (pow(t_1, 2.0) * -t_1)) + (phi2 * (t_0 * 0.0)))), (phi1 - phi2));
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(0.5 * phi1))
	t_1 = cbrt(Float64(sin(Float64(phi2 * 0.5)) * t_0))
	return Float64(R * hypot(Float64(Float64(lambda1 - lambda2) * Float64(fma(cos(Float64(phi2 * 0.5)), cos(Float64(0.5 * phi1)), Float64((t_1 ^ 2.0) * Float64(-t_1))) + Float64(phi2 * Float64(t_0 * 0.0)))), Float64(phi1 - phi2)))
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision], 1/3], $MachinePrecision]}, N[(R * N[Sqrt[N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] + N[(N[Power[t$95$1, 2.0], $MachinePrecision] * (-t$95$1)), $MachinePrecision]), $MachinePrecision] + N[(phi2 * N[(t$95$0 * 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \phi_1\right)\\
t_1 := \sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot t\_0}\\
R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\mathsf{fma}\left(\cos \left(\phi_2 \cdot 0.5\right), \cos \left(0.5 \cdot \phi_1\right), {t\_1}^{2} \cdot \left(-t\_1\right)\right) + \phi_2 \cdot \left(t\_0 \cdot 0\right)\right), \phi_1 - \phi_2\right)
\end{array}
\end{array}
Derivation
  1. Initial program 57.6%

    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
  2. Step-by-step derivation
    1. hypot-define95.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. Simplified95.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. Add Preprocessing
  5. Step-by-step derivation
    1. log1p-expm1-u95.8%

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\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-eval95.8%

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\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{log1p}\left(\mathsf{expm1}\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \color{blue}{\left(\phi_1 \cdot 0.5\right)} - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right), \phi_1 - \phi_2\right) \]
    7. *-commutative99.8%

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

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\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) \]
  9. Step-by-step derivation
    1. log1p-expm1-u99.8%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\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)}, \phi_1 - \phi_2\right) \]
    2. *-commutative99.8%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \color{blue}{\left(0.5 \cdot \phi_2\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), \phi_1 - \phi_2\right) \]
    3. add-cube-cbrt99.8%

      \[\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(\phi_1 \cdot 0.5\right) - \color{blue}{\left(\sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)} \cdot \sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}\right) \cdot \sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}}\right), \phi_1 - \phi_2\right) \]
    4. prod-diff99.9%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(\phi_1 \cdot 0.5\right), -\sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)} \cdot \left(\sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)} \cdot \sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}, \sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)} \cdot \sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}, \sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)} \cdot \left(\sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)} \cdot \sqrt[3]{\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) \]
  10. Applied egg-rr99.9%

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\mathsf{fma}\left(\cos \left(\phi_2 \cdot 0.5\right), \cos \left(0.5 \cdot \phi_1\right), -\sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)} \cdot {\left(\sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)}, {\left(\sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)}\right)}^{2}, \sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)} \cdot {\left(\sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)}\right)}^{2}\right)\right)}, \phi_1 - \phi_2\right) \]
  11. Taylor expanded in phi2 around 0 99.9%

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

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

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

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

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\mathsf{fma}\left(\cos \left(\phi_2 \cdot 0.5\right), \cos \left(0.5 \cdot \phi_1\right), {\left(\sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)}\right)}^{2} \cdot \left(-\sqrt[3]{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)}\right)\right) + \phi_2 \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot 0\right)\right), \phi_1 - \phi_2\right) \]
  15. Add Preprocessing

Alternative 2: 99.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(\cos \left(\phi_2 \cdot 0.5\right), \cos \left(0.5 \cdot \phi_1\right), \sin \left(\phi_2 \cdot 0.5\right) \cdot \left(-\sin \left(0.5 \cdot \phi_1\right)\right)\right), \phi_1 - \phi_2\right) \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R
  (hypot
   (*
    (- lambda1 lambda2)
    (fma
     (cos (* phi2 0.5))
     (cos (* 0.5 phi1))
     (* (sin (* phi2 0.5)) (- (sin (* 0.5 phi1))))))
   (- phi1 phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * hypot(((lambda1 - lambda2) * fma(cos((phi2 * 0.5)), cos((0.5 * phi1)), (sin((phi2 * 0.5)) * -sin((0.5 * phi1))))), (phi1 - phi2));
}
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(R * hypot(Float64(Float64(lambda1 - lambda2) * fma(cos(Float64(phi2 * 0.5)), cos(Float64(0.5 * phi1)), Float64(sin(Float64(phi2 * 0.5)) * Float64(-sin(Float64(0.5 * phi1)))))), Float64(phi1 - phi2)))
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[Sqrt[N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] + N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * (-N[Sin[N[(0.5 * phi1), $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 \mathsf{fma}\left(\cos \left(\phi_2 \cdot 0.5\right), \cos \left(0.5 \cdot \phi_1\right), \sin \left(\phi_2 \cdot 0.5\right) \cdot \left(-\sin \left(0.5 \cdot \phi_1\right)\right)\right), \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 57.6%

    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
  2. Step-by-step derivation
    1. hypot-define95.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. Simplified95.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. Add Preprocessing
  5. Step-by-step derivation
    1. log1p-expm1-u95.8%

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\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-eval95.8%

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\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{log1p}\left(\mathsf{expm1}\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \color{blue}{\left(\phi_1 \cdot 0.5\right)} - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right), \phi_1 - \phi_2\right) \]
    7. *-commutative99.8%

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

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\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) \]
  9. Step-by-step derivation
    1. log1p-expm1-u99.8%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\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)}, \phi_1 - \phi_2\right) \]
    2. cancel-sign-sub-inv99.8%

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

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

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

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

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

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

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

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

Alternative 3: 96.0% accurate, 0.6× speedup?

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

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

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


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

    1. Initial program 58.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-define96.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. Add Preprocessing
    5. Step-by-step derivation
      1. log1p-expm1-u96.4%

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\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.4%

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

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

    if 4.1999999999999997e141 < lambda2

    1. Initial program 52.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-define91.9%

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\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-eval91.9%

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

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

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

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

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

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\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 \color{blue}{\left(\phi_1 \cdot 0.5\right)}\right)\right), \phi_1 - \phi_2\right) \]
    8. Applied egg-rr99.9%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\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) \]
    9. Taylor expanded in lambda1 around 0 96.9%

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{-\lambda_2 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}, \phi_1 - \phi_2\right) \]
      2. *-commutative96.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 \lambda_2}, \phi_1 - \phi_2\right) \]
      3. distribute-rgt-neg-in96.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_2\right)}, \phi_1 - \phi_2\right) \]
    11. Simplified96.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_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_2 \leq 4.2 \cdot 10^{+141}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)\right), \phi_1 - \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_2 \cdot \left(\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\right), \phi_1 - \phi_2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 91.0% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 61.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-define97.0%

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

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

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

    if 8.2000000000000007e29 < phi2

    1. Initial program 45.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-define92.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. Simplified92.3%

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

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

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

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

Alternative 5: 93.3% accurate, 1.5× speedup?

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

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

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


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

    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-define97.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. Add Preprocessing
    5. Taylor expanded in phi2 around 0 93.4%

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

    if 1.8e-12 < phi2

    1. Initial program 48.6%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define91.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. Simplified91.6%

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

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

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

Alternative 6: 75.9% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 61.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-define97.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.8e38 < phi2

    1. Initial program 45.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-define92.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. Simplified92.3%

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

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

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

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

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

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

Alternative 7: 79.8% accurate, 1.5× speedup?

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

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

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


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

    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-define97.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. Add Preprocessing
    5. Taylor expanded in phi2 around 0 90.4%

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

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

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

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

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

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

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

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

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

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

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

    if 1.89999999999999998e-12 < phi2

    1. Initial program 48.6%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define91.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. Simplified91.6%

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

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

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

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

Alternative 8: 96.0% 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 57.6%

    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
  2. Step-by-step derivation
    1. hypot-define95.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. Simplified95.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. Add Preprocessing
  5. Final simplification95.8%

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

Alternative 9: 58.1% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -1.5 \cdot 10^{+32}:\\
\;\;\;\;R \cdot \left(\phi_1 \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\

\mathbf{elif}\;\phi_1 \leq -2 \cdot 10^{-133} \lor \neg \left(\phi_1 \leq -2.55 \cdot 10^{-164}\right):\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \lambda_2\right)\\

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


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

    1. Initial program 43.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-define89.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. Simplified89.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. Add Preprocessing
    5. Taylor expanded in phi1 around -inf 75.1%

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

        \[\leadsto R \cdot \color{blue}{\left(-\phi_1 \cdot \left(1 + -1 \cdot \frac{\phi_2}{\phi_1}\right)\right)} \]
      2. distribute-rgt-neg-in75.1%

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

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

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

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

    if -1.5e32 < phi1 < -2.0000000000000001e-133 or -2.55000000000000018e-164 < phi1

    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-define97.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. Add Preprocessing
    5. Taylor expanded in phi2 around 0 84.9%

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

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

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

        \[\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-define72.0%

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

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

      \[\leadsto \color{blue}{R \cdot \sqrt{{\lambda_2}^{2} + {\phi_2}^{2}}} \]
    10. Step-by-step derivation
      1. +-commutative40.3%

        \[\leadsto R \cdot \sqrt{\color{blue}{{\phi_2}^{2} + {\lambda_2}^{2}}} \]
      2. unpow240.3%

        \[\leadsto R \cdot \sqrt{\color{blue}{\phi_2 \cdot \phi_2} + {\lambda_2}^{2}} \]
      3. unpow240.3%

        \[\leadsto R \cdot \sqrt{\phi_2 \cdot \phi_2 + \color{blue}{\lambda_2 \cdot \lambda_2}} \]
      4. hypot-define55.7%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_2, \lambda_2\right)} \]
    11. Simplified55.7%

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

    if -2.0000000000000001e-133 < phi1 < -2.55000000000000018e-164

    1. Initial program 68.6%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define100.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. Simplified100.0%

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

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

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

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

        \[\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-define95.0%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\lambda_1 \cdot \left(R + -1 \cdot \frac{R \cdot \lambda_2}{\lambda_1}\right)\right)} \]
    10. Step-by-step derivation
      1. mul-1-neg51.1%

        \[\leadsto \color{blue}{-\lambda_1 \cdot \left(R + -1 \cdot \frac{R \cdot \lambda_2}{\lambda_1}\right)} \]
      2. associate-*r/51.1%

        \[\leadsto -\lambda_1 \cdot \left(R + \color{blue}{\frac{-1 \cdot \left(R \cdot \lambda_2\right)}{\lambda_1}}\right) \]
      3. associate-*r*51.1%

        \[\leadsto -\lambda_1 \cdot \left(R + \frac{\color{blue}{\left(-1 \cdot R\right) \cdot \lambda_2}}{\lambda_1}\right) \]
      4. mul-1-neg51.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.5 \cdot 10^{+32}:\\ \;\;\;\;R \cdot \left(\phi_1 \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\ \mathbf{elif}\;\phi_1 \leq -2 \cdot 10^{-133} \lor \neg \left(\phi_1 \leq -2.55 \cdot 10^{-164}\right):\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 \cdot \left(\frac{R \cdot \lambda_2}{\lambda_1} - R\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 70.7% accurate, 3.0× speedup?

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

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

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


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

    1. Initial program 61.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-define97.0%

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

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

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

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

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

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

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

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

    if 4.5e34 < phi2

    1. Initial program 45.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-define92.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. Simplified92.3%

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

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

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

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

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

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

Alternative 11: 71.7% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -7.6 \cdot 10^{+31}:\\ \;\;\;\;R \cdot \left(\phi_1 \cdot \left(\frac{\phi_2}{\phi_1} + -1\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 -7.6e+31)
   (* R (* phi1 (+ (/ phi2 phi1) -1.0)))
   (* R (hypot phi2 (- lambda1 lambda2)))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -7.6e+31) {
		tmp = R * (phi1 * ((phi2 / phi1) + -1.0));
	} 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 <= -7.6e+31) {
		tmp = R * (phi1 * ((phi2 / phi1) + -1.0));
	} else {
		tmp = R * Math.hypot(phi2, (lambda1 - lambda2));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -7.6e+31:
		tmp = R * (phi1 * ((phi2 / phi1) + -1.0))
	else:
		tmp = R * math.hypot(phi2, (lambda1 - lambda2))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -7.6e+31)
		tmp = Float64(R * Float64(phi1 * Float64(Float64(phi2 / phi1) + -1.0)));
	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 <= -7.6e+31)
		tmp = R * (phi1 * ((phi2 / phi1) + -1.0));
	else
		tmp = R * hypot(phi2, (lambda1 - lambda2));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -7.6e+31], N[(R * N[(phi1 * N[(N[(phi2 / phi1), $MachinePrecision] + -1.0), $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 -7.6 \cdot 10^{+31}:\\
\;\;\;\;R \cdot \left(\phi_1 \cdot \left(\frac{\phi_2}{\phi_1} + -1\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 2 regimes
  2. if phi1 < -7.6000000000000003e31

    1. Initial program 43.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-define89.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. Simplified89.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. Add Preprocessing
    5. Taylor expanded in phi1 around -inf 75.1%

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

        \[\leadsto R \cdot \color{blue}{\left(-\phi_1 \cdot \left(1 + -1 \cdot \frac{\phi_2}{\phi_1}\right)\right)} \]
      2. distribute-rgt-neg-in75.1%

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

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

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

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

    if -7.6000000000000003e31 < phi1

    1. Initial program 60.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-define97.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. Simplified97.3%

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

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

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

        \[\leadsto R \cdot \sqrt{\color{blue}{\phi_2 \cdot \phi_2} + {\left(\lambda_1 - \lambda_2\right)}^{2}} \]
      2. unpow254.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-define72.6%

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

      \[\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.0%

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

Alternative 12: 34.7% accurate, 14.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := R \cdot \phi_2 - R \cdot \phi_1\\ \mathbf{if}\;\lambda_2 \leq 2.9 \cdot 10^{-206}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\lambda_2 \leq 2.25 \cdot 10^{+88}:\\ \;\;\;\;\phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right)\\ \mathbf{elif}\;\lambda_2 \leq 1.36 \cdot 10^{+150}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;R \cdot \lambda_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (- (* R phi2) (* R phi1))))
   (if (<= lambda2 2.9e-206)
     t_0
     (if (<= lambda2 2.25e+88)
       (* phi2 (- R (* phi1 (/ R phi2))))
       (if (<= lambda2 1.36e+150) t_0 (* R lambda2))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (R * phi2) - (R * phi1);
	double tmp;
	if (lambda2 <= 2.9e-206) {
		tmp = t_0;
	} else if (lambda2 <= 2.25e+88) {
		tmp = phi2 * (R - (phi1 * (R / phi2)));
	} else if (lambda2 <= 1.36e+150) {
		tmp = t_0;
	} else {
		tmp = R * lambda2;
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (r * phi2) - (r * phi1)
    if (lambda2 <= 2.9d-206) then
        tmp = t_0
    else if (lambda2 <= 2.25d+88) then
        tmp = phi2 * (r - (phi1 * (r / phi2)))
    else if (lambda2 <= 1.36d+150) then
        tmp = t_0
    else
        tmp = r * lambda2
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (R * phi2) - (R * phi1);
	double tmp;
	if (lambda2 <= 2.9e-206) {
		tmp = t_0;
	} else if (lambda2 <= 2.25e+88) {
		tmp = phi2 * (R - (phi1 * (R / phi2)));
	} else if (lambda2 <= 1.36e+150) {
		tmp = t_0;
	} else {
		tmp = R * lambda2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = (R * phi2) - (R * phi1)
	tmp = 0
	if lambda2 <= 2.9e-206:
		tmp = t_0
	elif lambda2 <= 2.25e+88:
		tmp = phi2 * (R - (phi1 * (R / phi2)))
	elif lambda2 <= 1.36e+150:
		tmp = t_0
	else:
		tmp = R * lambda2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(Float64(R * phi2) - Float64(R * phi1))
	tmp = 0.0
	if (lambda2 <= 2.9e-206)
		tmp = t_0;
	elseif (lambda2 <= 2.25e+88)
		tmp = Float64(phi2 * Float64(R - Float64(phi1 * Float64(R / phi2))));
	elseif (lambda2 <= 1.36e+150)
		tmp = t_0;
	else
		tmp = Float64(R * lambda2);
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = (R * phi2) - (R * phi1);
	tmp = 0.0;
	if (lambda2 <= 2.9e-206)
		tmp = t_0;
	elseif (lambda2 <= 2.25e+88)
		tmp = phi2 * (R - (phi1 * (R / phi2)));
	elseif (lambda2 <= 1.36e+150)
		tmp = t_0;
	else
		tmp = R * lambda2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(R * phi2), $MachinePrecision] - N[(R * phi1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda2, 2.9e-206], t$95$0, If[LessEqual[lambda2, 2.25e+88], N[(phi2 * N[(R - N[(phi1 * N[(R / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda2, 1.36e+150], t$95$0, N[(R * lambda2), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := R \cdot \phi_2 - R \cdot \phi_1\\
\mathbf{if}\;\lambda_2 \leq 2.9 \cdot 10^{-206}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;\lambda_2 \leq 1.36 \cdot 10^{+150}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if lambda2 < 2.9000000000000002e-206 or 2.25e88 < lambda2 < 1.3599999999999999e150

    1. Initial program 55.3%

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

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

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

      \[\leadsto \color{blue}{\phi_2 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_1}{\phi_2}\right)} \]
    6. Step-by-step derivation
      1. associate-*r/28.2%

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

        \[\leadsto \phi_2 \cdot \left(R + \frac{\color{blue}{-R \cdot \phi_1}}{\phi_2}\right) \]
      3. *-commutative28.2%

        \[\leadsto \phi_2 \cdot \left(R + \frac{-\color{blue}{\phi_1 \cdot R}}{\phi_2}\right) \]
    7. Simplified28.2%

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

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

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

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

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

        \[\leadsto \color{blue}{R \cdot \phi_2 - \phi_1 \cdot R} \]
      5. *-commutative29.3%

        \[\leadsto \color{blue}{\phi_2 \cdot R} - \phi_1 \cdot R \]
    10. Simplified29.3%

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

    if 2.9000000000000002e-206 < lambda2 < 2.25e88

    1. Initial program 66.3%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define98.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. Add Preprocessing
    5. Taylor expanded in phi2 around inf 33.2%

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

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

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

        \[\leadsto \phi_2 \cdot \left(R - \frac{\color{blue}{\phi_1 \cdot R}}{\phi_2}\right) \]
      4. associate-/l*35.0%

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

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

    if 1.3599999999999999e150 < lambda2

    1. Initial program 55.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-define91.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. Simplified91.4%

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

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

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

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

        \[\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-define65.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 2.9 \cdot 10^{-206}:\\ \;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\ \mathbf{elif}\;\lambda_2 \leq 2.25 \cdot 10^{+88}:\\ \;\;\;\;\phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right)\\ \mathbf{elif}\;\lambda_2 \leq 1.36 \cdot 10^{+150}:\\ \;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \lambda_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 45.3% accurate, 17.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -50000:\\
\;\;\;\;R \cdot \left(\phi_1 \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\

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

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


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

    1. Initial program 44.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-define90.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. Simplified90.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. Add Preprocessing
    5. Taylor expanded in phi1 around -inf 74.2%

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

        \[\leadsto R \cdot \color{blue}{\left(-\phi_1 \cdot \left(1 + -1 \cdot \frac{\phi_2}{\phi_1}\right)\right)} \]
      2. distribute-rgt-neg-in74.2%

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

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

        \[\leadsto R \cdot \left(\phi_1 \cdot \left(-\color{blue}{\left(1 - \frac{\phi_2}{\phi_1}\right)}\right)\right) \]
    7. Simplified74.2%

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

    if -5e4 < phi1 < 1.34999999999999995e-281

    1. Initial program 63.3%

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

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

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

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

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

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

        \[\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-define86.1%

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

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

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

        \[\leadsto \lambda_2 \cdot \left(R + \color{blue}{\frac{-1 \cdot \left(R \cdot \lambda_1\right)}{\lambda_2}}\right) \]
      2. associate-*r*26.0%

        \[\leadsto \lambda_2 \cdot \left(R + \frac{\color{blue}{\left(-1 \cdot R\right) \cdot \lambda_1}}{\lambda_2}\right) \]
      3. mul-1-neg26.0%

        \[\leadsto \lambda_2 \cdot \left(R + \frac{\color{blue}{\left(-R\right)} \cdot \lambda_1}{\lambda_2}\right) \]
    11. Simplified26.0%

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

    if 1.34999999999999995e-281 < phi1

    1. Initial program 59.7%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define95.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. Simplified95.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. Add Preprocessing
    5. Taylor expanded in phi2 around inf 13.3%

      \[\leadsto \color{blue}{\phi_2 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_1}{\phi_2}\right)} \]
    6. Step-by-step derivation
      1. associate-*r/13.3%

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

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

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

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

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\left(-\phi_1 \cdot R\right) \cdot \frac{1}{\phi_2}}\right) \]
      2. add-sqr-sqrt9.6%

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\left(\sqrt{-\phi_1 \cdot R} \cdot \sqrt{-\phi_1 \cdot R}\right)} \cdot \frac{1}{\phi_2}\right) \]
      3. sqrt-unprod32.6%

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\sqrt{\left(-\phi_1 \cdot R\right) \cdot \left(-\phi_1 \cdot R\right)}} \cdot \frac{1}{\phi_2}\right) \]
      4. sqr-neg32.6%

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

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\left(\sqrt{\phi_1 \cdot R} \cdot \sqrt{\phi_1 \cdot R}\right)} \cdot \frac{1}{\phi_2}\right) \]
      6. add-sqr-sqrt51.0%

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\left(\phi_1 \cdot R\right)} \cdot \frac{1}{\phi_2}\right) \]
    9. Applied egg-rr51.0%

      \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\left(\phi_1 \cdot R\right) \cdot \frac{1}{\phi_2}}\right) \]
    10. Step-by-step derivation
      1. associate-*r/51.1%

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\frac{\left(\phi_1 \cdot R\right) \cdot 1}{\phi_2}}\right) \]
      2. *-rgt-identity51.1%

        \[\leadsto \phi_2 \cdot \left(R + \frac{\color{blue}{\phi_1 \cdot R}}{\phi_2}\right) \]
      3. associate-*r/52.4%

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\phi_1 \cdot \frac{R}{\phi_2}}\right) \]
    11. Simplified52.4%

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

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

Alternative 14: 44.9% accurate, 17.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -7.5 \cdot 10^{+29}:\\
\;\;\;\;R \cdot \left(\phi_1 \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\

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

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


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

    1. Initial program 43.4%

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

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

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

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

        \[\leadsto R \cdot \color{blue}{\left(-\phi_1 \cdot \left(1 + -1 \cdot \frac{\phi_2}{\phi_1}\right)\right)} \]
      2. distribute-rgt-neg-in76.1%

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

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

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

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

    if -7.49999999999999945e29 < phi1 < 5.0000000000000001e-282

    1. Initial program 62.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-define99.9%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\lambda_1 \cdot \left(R + -1 \cdot \frac{R \cdot \lambda_2}{\lambda_1}\right)\right)} \]
    10. Step-by-step derivation
      1. mul-1-neg29.0%

        \[\leadsto \color{blue}{-\lambda_1 \cdot \left(R + -1 \cdot \frac{R \cdot \lambda_2}{\lambda_1}\right)} \]
      2. associate-*r/29.0%

        \[\leadsto -\lambda_1 \cdot \left(R + \color{blue}{\frac{-1 \cdot \left(R \cdot \lambda_2\right)}{\lambda_1}}\right) \]
      3. associate-*r*29.0%

        \[\leadsto -\lambda_1 \cdot \left(R + \frac{\color{blue}{\left(-1 \cdot R\right) \cdot \lambda_2}}{\lambda_1}\right) \]
      4. mul-1-neg29.0%

        \[\leadsto -\lambda_1 \cdot \left(R + \frac{\color{blue}{\left(-R\right)} \cdot \lambda_2}{\lambda_1}\right) \]
    11. Simplified29.0%

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

    if 5.0000000000000001e-282 < phi1

    1. Initial program 59.7%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define95.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. Simplified95.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. Add Preprocessing
    5. Taylor expanded in phi2 around inf 13.3%

      \[\leadsto \color{blue}{\phi_2 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_1}{\phi_2}\right)} \]
    6. Step-by-step derivation
      1. associate-*r/13.3%

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

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

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

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

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\left(-\phi_1 \cdot R\right) \cdot \frac{1}{\phi_2}}\right) \]
      2. add-sqr-sqrt9.6%

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\left(\sqrt{-\phi_1 \cdot R} \cdot \sqrt{-\phi_1 \cdot R}\right)} \cdot \frac{1}{\phi_2}\right) \]
      3. sqrt-unprod32.6%

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\sqrt{\left(-\phi_1 \cdot R\right) \cdot \left(-\phi_1 \cdot R\right)}} \cdot \frac{1}{\phi_2}\right) \]
      4. sqr-neg32.6%

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

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\left(\sqrt{\phi_1 \cdot R} \cdot \sqrt{\phi_1 \cdot R}\right)} \cdot \frac{1}{\phi_2}\right) \]
      6. add-sqr-sqrt51.0%

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\left(\phi_1 \cdot R\right)} \cdot \frac{1}{\phi_2}\right) \]
    9. Applied egg-rr51.0%

      \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\left(\phi_1 \cdot R\right) \cdot \frac{1}{\phi_2}}\right) \]
    10. Step-by-step derivation
      1. associate-*r/51.1%

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\frac{\left(\phi_1 \cdot R\right) \cdot 1}{\phi_2}}\right) \]
      2. *-rgt-identity51.1%

        \[\leadsto \phi_2 \cdot \left(R + \frac{\color{blue}{\phi_1 \cdot R}}{\phi_2}\right) \]
      3. associate-*r/52.4%

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\phi_1 \cdot \frac{R}{\phi_2}}\right) \]
    11. Simplified52.4%

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

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

Alternative 15: 29.0% accurate, 25.2× speedup?

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

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

\mathbf{elif}\;\phi_1 \leq -6.8 \cdot 10^{-99}:\\
\;\;\;\;R \cdot \lambda_2\\

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


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

    1. Initial program 43.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-define89.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. Simplified89.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. Add Preprocessing
    5. Taylor expanded in phi1 around -inf 73.0%

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

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

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

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

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

    if -1.5200000000000001e32 < phi1 < -6.80000000000000014e-99

    1. Initial program 59.7%

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

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

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

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

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

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

        \[\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-define81.0%

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

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

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

    if -6.80000000000000014e-99 < phi1

    1. Initial program 60.8%

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

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

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

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

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

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

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

Alternative 16: 34.9% accurate, 27.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq 4.7 \cdot 10^{+150}:\\
\;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\

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


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

    1. Initial program 57.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-define96.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. Simplified96.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. Add Preprocessing
    5. Taylor expanded in phi2 around inf 29.4%

      \[\leadsto \color{blue}{\phi_2 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_1}{\phi_2}\right)} \]
    6. Step-by-step derivation
      1. associate-*r/29.4%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{R \cdot \phi_2 - \phi_1 \cdot R} \]
      5. *-commutative29.8%

        \[\leadsto \color{blue}{\phi_2 \cdot R} - \phi_1 \cdot R \]
    10. Simplified29.8%

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

    if 4.70000000000000004e150 < lambda2

    1. Initial program 55.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-define91.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. Simplified91.4%

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

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

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

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

        \[\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-define65.9%

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

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

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

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

Alternative 17: 26.7% accurate, 41.0× speedup?

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

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

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


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

    1. Initial program 61.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-define97.0%

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

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

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

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

        \[\leadsto R \cdot \sqrt{\color{blue}{\phi_2 \cdot \phi_2} + {\left(\lambda_1 - \lambda_2\right)}^{2}} \]
      2. unpow251.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-define65.0%

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

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

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

    if 6.8000000000000005e30 < phi2

    1. Initial program 45.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-define92.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. Simplified92.3%

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

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

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

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

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

Alternative 18: 14.8% accurate, 109.7× speedup?

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

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

    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
  2. Step-by-step derivation
    1. hypot-define95.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. Simplified95.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. Add Preprocessing
  5. Taylor expanded in phi2 around 0 83.1%

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

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

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

      \[\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-define65.2%

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

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

    \[\leadsto \color{blue}{R \cdot \lambda_2} \]
  10. Final simplification15.9%

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

Reproduce

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