Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.7% → 99.9%
Time: 28.4s
Alternatives: 17
Speedup: 1.5×

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 17 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.7% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 0.5× speedup?

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

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

    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
  2. Step-by-step derivation
    1. hypot-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. Step-by-step derivation
    1. log1p-expm1-u95.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-inv95.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-eval95.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-rr95.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. *-commutative95.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. +-commutative95.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-in95.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. 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(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}\right)\right), \phi_1 - \phi_2\right) \]
  8. 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.9%

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

      \[\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) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right)}, \phi_1 - \phi_2\right) \]
    3. distribute-lft-in99.9%

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

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

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

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

    \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) + \left(\lambda_1 - \lambda_2\right) \cdot \left(\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) \]
  11. Step-by-step derivation
    1. log1p-expm1-u99.9%

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

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

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

Alternative 2: 87.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot 0.5\right)\\ t_1 := \cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\\ \mathbf{if}\;\lambda_1 \leq -2.25 \cdot 10^{+164}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot \left(t\_1 - t\_0\right), \phi_1 - \phi_2\right)\\ \mathbf{elif}\;\lambda_1 \leq -1.5 \cdot 10^{-71}:\\ \;\;\;\;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)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_2 \cdot \left(t\_0 - t\_1\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)) (sin (* phi2 0.5))))
        (t_1 (* (cos (* 0.5 phi1)) (cos (* phi2 0.5)))))
   (if (<= lambda1 -2.25e+164)
     (* R (hypot (* lambda1 (- t_1 t_0)) (- phi1 phi2)))
     (if (<= lambda1 -1.5e-71)
       (*
        R
        (hypot
         (* (- lambda1 lambda2) (cos (/ (+ phi2 phi1) 2.0)))
         (- phi1 phi2)))
       (* R (hypot (* lambda2 (- t_0 t_1)) (- phi1 phi2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin((0.5 * phi1)) * sin((phi2 * 0.5));
	double t_1 = cos((0.5 * phi1)) * cos((phi2 * 0.5));
	double tmp;
	if (lambda1 <= -2.25e+164) {
		tmp = R * hypot((lambda1 * (t_1 - t_0)), (phi1 - phi2));
	} else if (lambda1 <= -1.5e-71) {
		tmp = R * hypot(((lambda1 - lambda2) * cos(((phi2 + phi1) / 2.0))), (phi1 - phi2));
	} else {
		tmp = R * hypot((lambda2 * (t_0 - t_1)), (phi1 - phi2));
	}
	return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.sin((0.5 * phi1)) * Math.sin((phi2 * 0.5));
	double t_1 = Math.cos((0.5 * phi1)) * Math.cos((phi2 * 0.5));
	double tmp;
	if (lambda1 <= -2.25e+164) {
		tmp = R * Math.hypot((lambda1 * (t_1 - t_0)), (phi1 - phi2));
	} else if (lambda1 <= -1.5e-71) {
		tmp = R * Math.hypot(((lambda1 - lambda2) * Math.cos(((phi2 + phi1) / 2.0))), (phi1 - phi2));
	} else {
		tmp = R * Math.hypot((lambda2 * (t_0 - t_1)), (phi1 - phi2));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin((0.5 * phi1)) * math.sin((phi2 * 0.5))
	t_1 = math.cos((0.5 * phi1)) * math.cos((phi2 * 0.5))
	tmp = 0
	if lambda1 <= -2.25e+164:
		tmp = R * math.hypot((lambda1 * (t_1 - t_0)), (phi1 - phi2))
	elif lambda1 <= -1.5e-71:
		tmp = R * math.hypot(((lambda1 - lambda2) * math.cos(((phi2 + phi1) / 2.0))), (phi1 - phi2))
	else:
		tmp = R * math.hypot((lambda2 * (t_0 - t_1)), (phi1 - phi2))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(sin(Float64(0.5 * phi1)) * sin(Float64(phi2 * 0.5)))
	t_1 = Float64(cos(Float64(0.5 * phi1)) * cos(Float64(phi2 * 0.5)))
	tmp = 0.0
	if (lambda1 <= -2.25e+164)
		tmp = Float64(R * hypot(Float64(lambda1 * Float64(t_1 - t_0)), Float64(phi1 - phi2)));
	elseif (lambda1 <= -1.5e-71)
		tmp = Float64(R * hypot(Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi2 + phi1) / 2.0))), Float64(phi1 - phi2)));
	else
		tmp = Float64(R * hypot(Float64(lambda2 * Float64(t_0 - t_1)), Float64(phi1 - phi2)));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin((0.5 * phi1)) * sin((phi2 * 0.5));
	t_1 = cos((0.5 * phi1)) * cos((phi2 * 0.5));
	tmp = 0.0;
	if (lambda1 <= -2.25e+164)
		tmp = R * hypot((lambda1 * (t_1 - t_0)), (phi1 - phi2));
	elseif (lambda1 <= -1.5e-71)
		tmp = R * hypot(((lambda1 - lambda2) * cos(((phi2 + phi1) / 2.0))), (phi1 - phi2));
	else
		tmp = R * hypot((lambda2 * (t_0 - t_1)), (phi1 - phi2));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda1, -2.25e+164], N[(R * N[Sqrt[N[(lambda1 * N[(t$95$1 - t$95$0), $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda1, -1.5e-71], 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], N[(R * N[Sqrt[N[(lambda2 * N[(t$95$0 - t$95$1), $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) \cdot \sin \left(\phi_2 \cdot 0.5\right)\\
t_1 := \cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\\
\mathbf{if}\;\lambda_1 \leq -2.25 \cdot 10^{+164}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot \left(t\_1 - t\_0\right), \phi_1 - \phi_2\right)\\

\mathbf{elif}\;\lambda_1 \leq -1.5 \cdot 10^{-71}:\\
\;\;\;\;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)\\

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


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

    1. Initial program 36.5%

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

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

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

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

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

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

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

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

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

        \[\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. cos-sum99.6%

        \[\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) \]
    8. Applied egg-rr99.6%

      \[\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 inf 94.2%

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

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

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

    if -2.24999999999999988e164 < lambda1 < -1.5000000000000001e-71

    1. Initial program 58.6%

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

    if -1.5000000000000001e-71 < lambda1

    1. Initial program 61.5%

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

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

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

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

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

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

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

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

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

        \[\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. 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(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}\right)\right), \phi_1 - \phi_2\right) \]
    8. 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.9%

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

        \[\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) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right)}, \phi_1 - \phi_2\right) \]
      3. distribute-lft-in99.9%

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) + \left(\lambda_1 - \lambda_2\right) \cdot \left(\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) \]
    11. Taylor expanded in lambda1 around 0 85.1%

      \[\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)\right)\right) + \lambda_2 \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}, \phi_1 - \phi_2\right) \]
    12. Step-by-step derivation
      1. mul-1-neg85.1%

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

        \[\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)\right)} + \lambda_2 \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right), \phi_1 - \phi_2\right) \]
      3. mul-1-neg85.1%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -2.25 \cdot 10^{+164}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot 0.5\right)\right), \phi_1 - \phi_2\right)\\ \mathbf{elif}\;\lambda_1 \leq -1.5 \cdot 10^{-71}:\\ \;\;\;\;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)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_2 \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot 0.5\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 3: 87.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot 0.5\right)\\ t_1 := \cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\\ \mathbf{if}\;\lambda_1 \leq -3.8 \cdot 10^{+164}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot t\_1 - \lambda_1 \cdot t\_0, \phi_1 - \phi_2\right)\\ \mathbf{elif}\;\lambda_1 \leq -4.8 \cdot 10^{-72}:\\ \;\;\;\;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)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_2 \cdot \left(t\_0 - t\_1\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)) (sin (* phi2 0.5))))
        (t_1 (* (cos (* 0.5 phi1)) (cos (* phi2 0.5)))))
   (if (<= lambda1 -3.8e+164)
     (* R (hypot (- (* lambda1 t_1) (* lambda1 t_0)) (- phi1 phi2)))
     (if (<= lambda1 -4.8e-72)
       (*
        R
        (hypot
         (* (- lambda1 lambda2) (cos (/ (+ phi2 phi1) 2.0)))
         (- phi1 phi2)))
       (* R (hypot (* lambda2 (- t_0 t_1)) (- phi1 phi2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin((0.5 * phi1)) * sin((phi2 * 0.5));
	double t_1 = cos((0.5 * phi1)) * cos((phi2 * 0.5));
	double tmp;
	if (lambda1 <= -3.8e+164) {
		tmp = R * hypot(((lambda1 * t_1) - (lambda1 * t_0)), (phi1 - phi2));
	} else if (lambda1 <= -4.8e-72) {
		tmp = R * hypot(((lambda1 - lambda2) * cos(((phi2 + phi1) / 2.0))), (phi1 - phi2));
	} else {
		tmp = R * hypot((lambda2 * (t_0 - t_1)), (phi1 - phi2));
	}
	return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.sin((0.5 * phi1)) * Math.sin((phi2 * 0.5));
	double t_1 = Math.cos((0.5 * phi1)) * Math.cos((phi2 * 0.5));
	double tmp;
	if (lambda1 <= -3.8e+164) {
		tmp = R * Math.hypot(((lambda1 * t_1) - (lambda1 * t_0)), (phi1 - phi2));
	} else if (lambda1 <= -4.8e-72) {
		tmp = R * Math.hypot(((lambda1 - lambda2) * Math.cos(((phi2 + phi1) / 2.0))), (phi1 - phi2));
	} else {
		tmp = R * Math.hypot((lambda2 * (t_0 - t_1)), (phi1 - phi2));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin((0.5 * phi1)) * math.sin((phi2 * 0.5))
	t_1 = math.cos((0.5 * phi1)) * math.cos((phi2 * 0.5))
	tmp = 0
	if lambda1 <= -3.8e+164:
		tmp = R * math.hypot(((lambda1 * t_1) - (lambda1 * t_0)), (phi1 - phi2))
	elif lambda1 <= -4.8e-72:
		tmp = R * math.hypot(((lambda1 - lambda2) * math.cos(((phi2 + phi1) / 2.0))), (phi1 - phi2))
	else:
		tmp = R * math.hypot((lambda2 * (t_0 - t_1)), (phi1 - phi2))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(sin(Float64(0.5 * phi1)) * sin(Float64(phi2 * 0.5)))
	t_1 = Float64(cos(Float64(0.5 * phi1)) * cos(Float64(phi2 * 0.5)))
	tmp = 0.0
	if (lambda1 <= -3.8e+164)
		tmp = Float64(R * hypot(Float64(Float64(lambda1 * t_1) - Float64(lambda1 * t_0)), Float64(phi1 - phi2)));
	elseif (lambda1 <= -4.8e-72)
		tmp = Float64(R * hypot(Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi2 + phi1) / 2.0))), Float64(phi1 - phi2)));
	else
		tmp = Float64(R * hypot(Float64(lambda2 * Float64(t_0 - t_1)), Float64(phi1 - phi2)));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin((0.5 * phi1)) * sin((phi2 * 0.5));
	t_1 = cos((0.5 * phi1)) * cos((phi2 * 0.5));
	tmp = 0.0;
	if (lambda1 <= -3.8e+164)
		tmp = R * hypot(((lambda1 * t_1) - (lambda1 * t_0)), (phi1 - phi2));
	elseif (lambda1 <= -4.8e-72)
		tmp = R * hypot(((lambda1 - lambda2) * cos(((phi2 + phi1) / 2.0))), (phi1 - phi2));
	else
		tmp = R * hypot((lambda2 * (t_0 - t_1)), (phi1 - phi2));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda1, -3.8e+164], N[(R * N[Sqrt[N[(N[(lambda1 * t$95$1), $MachinePrecision] - N[(lambda1 * t$95$0), $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda1, -4.8e-72], 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], N[(R * N[Sqrt[N[(lambda2 * N[(t$95$0 - t$95$1), $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) \cdot \sin \left(\phi_2 \cdot 0.5\right)\\
t_1 := \cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\\
\mathbf{if}\;\lambda_1 \leq -3.8 \cdot 10^{+164}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot t\_1 - \lambda_1 \cdot t\_0, \phi_1 - \phi_2\right)\\

\mathbf{elif}\;\lambda_1 \leq -4.8 \cdot 10^{-72}:\\
\;\;\;\;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)\\

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


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

    1. Initial program 36.5%

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

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

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

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

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

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

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

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

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

        \[\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. cos-sum99.6%

        \[\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) \]
    8. Applied egg-rr99.6%

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

        \[\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. sub-neg99.6%

        \[\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) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right)}, \phi_1 - \phi_2\right) \]
      3. distribute-lft-in99.7%

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) + \left(\lambda_1 - \lambda_2\right) \cdot \left(\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) \]
    11. Taylor expanded in lambda2 around 0 94.3%

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

    if -3.80000000000000021e164 < lambda1 < -4.8e-72

    1. Initial program 58.6%

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

    if -4.8e-72 < lambda1

    1. Initial program 61.5%

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

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

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

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

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

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

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

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

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

        \[\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. 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(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}\right)\right), \phi_1 - \phi_2\right) \]
    8. 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.9%

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

        \[\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) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right)}, \phi_1 - \phi_2\right) \]
      3. distribute-lft-in99.9%

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) + \left(\lambda_1 - \lambda_2\right) \cdot \left(\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) \]
    11. Taylor expanded in lambda1 around 0 85.1%

      \[\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)\right)\right) + \lambda_2 \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}, \phi_1 - \phi_2\right) \]
    12. Step-by-step derivation
      1. mul-1-neg85.1%

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

        \[\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)\right)} + \lambda_2 \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right), \phi_1 - \phi_2\right) \]
      3. mul-1-neg85.1%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -3.8 \cdot 10^{+164}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\right) - \lambda_1 \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot 0.5\right)\right), \phi_1 - \phi_2\right)\\ \mathbf{elif}\;\lambda_1 \leq -4.8 \cdot 10^{-72}:\\ \;\;\;\;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)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_2 \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot 0.5\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: 97.9% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot 0.5\right)\\ t_1 := \cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\\ \mathbf{if}\;\lambda_1 \leq -4 \cdot 10^{+164}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot t\_1 - \lambda_1 \cdot t\_0, \phi_1 - \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot t\_1 + \lambda_2 \cdot t\_0, \phi_1 - \phi_2\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (sin (* 0.5 phi1)) (sin (* phi2 0.5))))
        (t_1 (* (cos (* 0.5 phi1)) (cos (* phi2 0.5)))))
   (if (<= lambda1 -4e+164)
     (* R (hypot (- (* lambda1 t_1) (* lambda1 t_0)) (- phi1 phi2)))
     (*
      R
      (hypot (+ (* (- lambda1 lambda2) t_1) (* lambda2 t_0)) (- phi1 phi2))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin((0.5 * phi1)) * sin((phi2 * 0.5));
	double t_1 = cos((0.5 * phi1)) * cos((phi2 * 0.5));
	double tmp;
	if (lambda1 <= -4e+164) {
		tmp = R * hypot(((lambda1 * t_1) - (lambda1 * t_0)), (phi1 - phi2));
	} else {
		tmp = R * hypot((((lambda1 - lambda2) * t_1) + (lambda2 * t_0)), (phi1 - phi2));
	}
	return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.sin((0.5 * phi1)) * Math.sin((phi2 * 0.5));
	double t_1 = Math.cos((0.5 * phi1)) * Math.cos((phi2 * 0.5));
	double tmp;
	if (lambda1 <= -4e+164) {
		tmp = R * Math.hypot(((lambda1 * t_1) - (lambda1 * t_0)), (phi1 - phi2));
	} else {
		tmp = R * Math.hypot((((lambda1 - lambda2) * t_1) + (lambda2 * t_0)), (phi1 - phi2));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin((0.5 * phi1)) * math.sin((phi2 * 0.5))
	t_1 = math.cos((0.5 * phi1)) * math.cos((phi2 * 0.5))
	tmp = 0
	if lambda1 <= -4e+164:
		tmp = R * math.hypot(((lambda1 * t_1) - (lambda1 * t_0)), (phi1 - phi2))
	else:
		tmp = R * math.hypot((((lambda1 - lambda2) * t_1) + (lambda2 * t_0)), (phi1 - phi2))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(sin(Float64(0.5 * phi1)) * sin(Float64(phi2 * 0.5)))
	t_1 = Float64(cos(Float64(0.5 * phi1)) * cos(Float64(phi2 * 0.5)))
	tmp = 0.0
	if (lambda1 <= -4e+164)
		tmp = Float64(R * hypot(Float64(Float64(lambda1 * t_1) - Float64(lambda1 * t_0)), Float64(phi1 - phi2)));
	else
		tmp = Float64(R * hypot(Float64(Float64(Float64(lambda1 - lambda2) * t_1) + Float64(lambda2 * t_0)), Float64(phi1 - phi2)));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin((0.5 * phi1)) * sin((phi2 * 0.5));
	t_1 = cos((0.5 * phi1)) * cos((phi2 * 0.5));
	tmp = 0.0;
	if (lambda1 <= -4e+164)
		tmp = R * hypot(((lambda1 * t_1) - (lambda1 * t_0)), (phi1 - phi2));
	else
		tmp = R * hypot((((lambda1 - lambda2) * t_1) + (lambda2 * t_0)), (phi1 - phi2));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda1, -4e+164], N[(R * N[Sqrt[N[(N[(lambda1 * t$95$1), $MachinePrecision] - N[(lambda1 * t$95$0), $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(N[(N[(lambda1 - lambda2), $MachinePrecision] * t$95$1), $MachinePrecision] + N[(lambda2 * t$95$0), $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) \cdot \sin \left(\phi_2 \cdot 0.5\right)\\
t_1 := \cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\\
\mathbf{if}\;\lambda_1 \leq -4 \cdot 10^{+164}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot t\_1 - \lambda_1 \cdot t\_0, \phi_1 - \phi_2\right)\\

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


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

    1. Initial program 36.5%

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

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

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

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

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

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

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

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

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

        \[\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. cos-sum99.6%

        \[\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) \]
    8. Applied egg-rr99.6%

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

        \[\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. sub-neg99.6%

        \[\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) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right)}, \phi_1 - \phi_2\right) \]
      3. distribute-lft-in99.7%

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) + \left(\lambda_1 - \lambda_2\right) \cdot \left(\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) \]
    11. Taylor expanded in lambda2 around 0 94.3%

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

    if -4e164 < lambda1

    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-define97.1%

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

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

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

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

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

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

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

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

        \[\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. 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(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}\right)\right), \phi_1 - \phi_2\right) \]
    8. 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.9%

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

        \[\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) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right)}, \phi_1 - \phi_2\right) \]
      3. distribute-lft-in99.9%

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) + \left(\lambda_1 - \lambda_2\right) \cdot \left(\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) \]
    11. Taylor expanded in lambda1 around 0 98.2%

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

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

Alternative 5: 99.9% accurate, 0.6× speedup?

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

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

    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
  2. Step-by-step derivation
    1. hypot-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. Step-by-step derivation
    1. log1p-expm1-u95.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-inv95.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-eval95.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-rr95.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. *-commutative95.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. +-commutative95.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-in95.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. 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(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}\right)\right), \phi_1 - \phi_2\right) \]
  8. 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.9%

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

      \[\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) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right)}, \phi_1 - \phi_2\right) \]
    3. distribute-lft-in99.9%

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

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

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

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

    \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) + \left(\lambda_1 - \lambda_2\right) \cdot \left(\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) \]
  11. Final simplification99.9%

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

Alternative 6: 87.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -5 \cdot 10^{-71}:\\ \;\;\;\;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)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_2 \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot 0.5\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 (<= lambda1 -5e-71)
   (*
    R
    (hypot (* (- lambda1 lambda2) (cos (/ (+ phi2 phi1) 2.0))) (- phi1 phi2)))
   (*
    R
    (hypot
     (*
      lambda2
      (-
       (* (sin (* 0.5 phi1)) (sin (* phi2 0.5)))
       (* (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 (lambda1 <= -5e-71) {
		tmp = R * hypot(((lambda1 - lambda2) * cos(((phi2 + phi1) / 2.0))), (phi1 - phi2));
	} else {
		tmp = R * hypot((lambda2 * ((sin((0.5 * phi1)) * sin((phi2 * 0.5))) - (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 (lambda1 <= -5e-71) {
		tmp = R * Math.hypot(((lambda1 - lambda2) * Math.cos(((phi2 + phi1) / 2.0))), (phi1 - phi2));
	} else {
		tmp = R * Math.hypot((lambda2 * ((Math.sin((0.5 * phi1)) * Math.sin((phi2 * 0.5))) - (Math.cos((0.5 * phi1)) * Math.cos((phi2 * 0.5))))), (phi1 - phi2));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if lambda1 <= -5e-71:
		tmp = R * math.hypot(((lambda1 - lambda2) * math.cos(((phi2 + phi1) / 2.0))), (phi1 - phi2))
	else:
		tmp = R * math.hypot((lambda2 * ((math.sin((0.5 * phi1)) * math.sin((phi2 * 0.5))) - (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 (lambda1 <= -5e-71)
		tmp = Float64(R * hypot(Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi2 + phi1) / 2.0))), Float64(phi1 - phi2)));
	else
		tmp = Float64(R * hypot(Float64(lambda2 * Float64(Float64(sin(Float64(0.5 * phi1)) * sin(Float64(phi2 * 0.5))) - Float64(cos(Float64(0.5 * phi1)) * 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 (lambda1 <= -5e-71)
		tmp = R * hypot(((lambda1 - lambda2) * cos(((phi2 + phi1) / 2.0))), (phi1 - phi2));
	else
		tmp = R * hypot((lambda2 * ((sin((0.5 * phi1)) * sin((phi2 * 0.5))) - (cos((0.5 * phi1)) * cos((phi2 * 0.5))))), (phi1 - phi2));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda1, -5e-71], 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], N[(R * N[Sqrt[N[(lambda2 * N[(N[(N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi2 * 0.5), $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_1 \leq -5 \cdot 10^{-71}:\\
\;\;\;\;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)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_2 \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot 0.5\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 lambda1 < -4.99999999999999998e-71

    1. Initial program 50.3%

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

    if -4.99999999999999998e-71 < lambda1

    1. Initial program 61.5%

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

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

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

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

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

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

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

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

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

        \[\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. 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(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}\right)\right), \phi_1 - \phi_2\right) \]
    8. 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.9%

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

        \[\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) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right)}, \phi_1 - \phi_2\right) \]
      3. distribute-lft-in99.9%

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) + \left(\lambda_1 - \lambda_2\right) \cdot \left(\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) \]
    11. Taylor expanded in lambda1 around 0 85.1%

      \[\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)\right)\right) + \lambda_2 \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}, \phi_1 - \phi_2\right) \]
    12. Step-by-step derivation
      1. mul-1-neg85.1%

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

        \[\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)\right)} + \lambda_2 \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right), \phi_1 - \phi_2\right) \]
      3. mul-1-neg85.1%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -5 \cdot 10^{-71}:\\ \;\;\;\;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)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_2 \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot 0.5\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 7: 32.0% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := R \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\\ \mathbf{if}\;\lambda_2 \leq -3.6 \cdot 10^{-69}:\\ \;\;\;\;t\_0 \cdot \left(\lambda_2 - \lambda_1\right)\\ \mathbf{elif}\;\lambda_2 \leq 1.32 \cdot 10^{+101}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\left|\lambda_2 \cdot t\_0\right|\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* R (cos (* 0.5 (+ phi2 phi1))))))
   (if (<= lambda2 -3.6e-69)
     (* t_0 (- lambda2 lambda1))
     (if (<= lambda2 1.32e+101) (* R (- phi2 phi1)) (fabs (* lambda2 t_0))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * cos((0.5 * (phi2 + phi1)));
	double tmp;
	if (lambda2 <= -3.6e-69) {
		tmp = t_0 * (lambda2 - lambda1);
	} else if (lambda2 <= 1.32e+101) {
		tmp = R * (phi2 - phi1);
	} else {
		tmp = fabs((lambda2 * t_0));
	}
	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 * cos((0.5d0 * (phi2 + phi1)))
    if (lambda2 <= (-3.6d-69)) then
        tmp = t_0 * (lambda2 - lambda1)
    else if (lambda2 <= 1.32d+101) then
        tmp = r * (phi2 - phi1)
    else
        tmp = abs((lambda2 * t_0))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * Math.cos((0.5 * (phi2 + phi1)));
	double tmp;
	if (lambda2 <= -3.6e-69) {
		tmp = t_0 * (lambda2 - lambda1);
	} else if (lambda2 <= 1.32e+101) {
		tmp = R * (phi2 - phi1);
	} else {
		tmp = Math.abs((lambda2 * t_0));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = R * math.cos((0.5 * (phi2 + phi1)))
	tmp = 0
	if lambda2 <= -3.6e-69:
		tmp = t_0 * (lambda2 - lambda1)
	elif lambda2 <= 1.32e+101:
		tmp = R * (phi2 - phi1)
	else:
		tmp = math.fabs((lambda2 * t_0))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(R * cos(Float64(0.5 * Float64(phi2 + phi1))))
	tmp = 0.0
	if (lambda2 <= -3.6e-69)
		tmp = Float64(t_0 * Float64(lambda2 - lambda1));
	elseif (lambda2 <= 1.32e+101)
		tmp = Float64(R * Float64(phi2 - phi1));
	else
		tmp = abs(Float64(lambda2 * t_0));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = R * cos((0.5 * (phi2 + phi1)));
	tmp = 0.0;
	if (lambda2 <= -3.6e-69)
		tmp = t_0 * (lambda2 - lambda1);
	elseif (lambda2 <= 1.32e+101)
		tmp = R * (phi2 - phi1);
	else
		tmp = abs((lambda2 * t_0));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(R * N[Cos[N[(0.5 * N[(phi2 + phi1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda2, -3.6e-69], N[(t$95$0 * N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda2, 1.32e+101], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], N[Abs[N[(lambda2 * t$95$0), $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := R \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\\
\mathbf{if}\;\lambda_2 \leq -3.6 \cdot 10^{-69}:\\
\;\;\;\;t\_0 \cdot \left(\lambda_2 - \lambda_1\right)\\

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

\mathbf{else}:\\
\;\;\;\;\left|\lambda_2 \cdot t\_0\right|\\


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

    1. Initial program 56.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-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 lambda1 around -inf 28.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.60000000000000018e-69 < lambda2 < 1.32e101

    1. Initial program 60.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.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. Simplified95.4%

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

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

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

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

        \[\leadsto \color{blue}{R \cdot \phi_2 - R \cdot \phi_1} \]
      4. *-commutative38.1%

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

        \[\leadsto \phi_2 \cdot R - \color{blue}{\phi_1 \cdot R} \]
    7. Simplified38.1%

      \[\leadsto \color{blue}{\phi_2 \cdot R - \phi_1 \cdot R} \]
    8. Taylor expanded in phi2 around 0 38.1%

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

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

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

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

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

        \[\leadsto \color{blue}{\phi_2 \cdot R - \phi_1 \cdot R} \]
      6. distribute-rgt-out--38.9%

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

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

    if 1.32e101 < lambda2

    1. Initial program 51.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.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 lambda2 around inf 43.2%

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

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{{\left(\left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right) \cdot R\right)}^{2}}} \]
      4. associate-*l*32.5%

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

        \[\leadsto \sqrt{{\left(\lambda_2 \cdot \color{blue}{\left(R \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}\right)}^{2}} \]
      6. associate-*r*32.4%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left|\lambda_2 \cdot \left(R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right|} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification35.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq -3.6 \cdot 10^{-69}:\\ \;\;\;\;\left(R \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right) \cdot \left(\lambda_2 - \lambda_1\right)\\ \mathbf{elif}\;\lambda_2 \leq 1.32 \cdot 10^{+101}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\left|\lambda_2 \cdot \left(R \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 82.3% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 4.7 \cdot 10^{-94}:\\ \;\;\;\;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(\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 4.7e-94)
   (* R (hypot phi1 (* (- lambda1 lambda2) (cos (* 0.5 phi1)))))
   (* 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 <= 4.7e-94) {
		tmp = R * hypot(phi1, ((lambda1 - lambda2) * cos((0.5 * phi1))));
	} 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 <= 4.7e-94) {
		tmp = R * Math.hypot(phi1, ((lambda1 - lambda2) * Math.cos((0.5 * phi1))));
	} 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 <= 4.7e-94:
		tmp = R * math.hypot(phi1, ((lambda1 - lambda2) * math.cos((0.5 * phi1))))
	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 <= 4.7e-94)
		tmp = Float64(R * hypot(phi1, Float64(Float64(lambda1 - lambda2) * cos(Float64(0.5 * phi1)))));
	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 <= 4.7e-94)
		tmp = R * hypot(phi1, ((lambda1 - lambda2) * cos((0.5 * phi1))));
	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, 4.7e-94], 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[(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 4.7 \cdot 10^{-94}:\\
\;\;\;\;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(\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 < 4.70000000000000003e-94

    1. Initial program 59.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-define96.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. Simplified96.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 45.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}}} \]
    6. Step-by-step derivation
      1. +-commutative45.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. unpow245.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. unpow245.6%

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

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

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

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

      \[\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 4.70000000000000003e-94 < phi2

    1. Initial program 55.1%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 4.7 \cdot 10^{-94}:\\ \;\;\;\;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(\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 9: 75.5% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 4.2 \cdot 10^{+25}:\\ \;\;\;\;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 - \phi_1\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi2 4.2e+25)
   (* R (hypot phi1 (* (- lambda1 lambda2) (cos (* 0.5 phi1)))))
   (* R (- phi2 phi1))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 4.2e+25) {
		tmp = R * hypot(phi1, ((lambda1 - lambda2) * cos((0.5 * phi1))));
	} else {
		tmp = R * (phi2 - phi1);
	}
	return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 4.2e+25) {
		tmp = R * Math.hypot(phi1, ((lambda1 - lambda2) * Math.cos((0.5 * phi1))));
	} else {
		tmp = R * (phi2 - phi1);
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 4.2e+25:
		tmp = R * math.hypot(phi1, ((lambda1 - lambda2) * math.cos((0.5 * phi1))))
	else:
		tmp = R * (phi2 - phi1)
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 4.2e+25)
		tmp = Float64(R * hypot(phi1, Float64(Float64(lambda1 - lambda2) * cos(Float64(0.5 * phi1)))));
	else
		tmp = Float64(R * Float64(phi2 - phi1));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi2 <= 4.2e+25)
		tmp = R * hypot(phi1, ((lambda1 - lambda2) * cos((0.5 * phi1))));
	else
		tmp = R * (phi2 - phi1);
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 4.2e+25], 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 - phi1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 4.2 \cdot 10^{+25}:\\
\;\;\;\;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 - \phi_1\right)\\


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

    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-define96.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. Simplified96.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 45.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}}} \]
    6. Step-by-step derivation
      1. +-commutative45.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. unpow245.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. unpow245.3%

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

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

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

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \]
    7. Simplified71.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 4.1999999999999998e25 < phi2

    1. Initial program 52.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-define95.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. Simplified95.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.7%

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

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

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

        \[\leadsto \color{blue}{R \cdot \phi_2 - R \cdot \phi_1} \]
      4. *-commutative73.7%

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

        \[\leadsto \phi_2 \cdot R - \color{blue}{\phi_1 \cdot R} \]
    7. Simplified73.7%

      \[\leadsto \color{blue}{\phi_2 \cdot R - \phi_1 \cdot R} \]
    8. Taylor expanded in phi2 around 0 73.7%

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

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

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

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

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

        \[\leadsto \color{blue}{\phi_2 \cdot R - \phi_1 \cdot R} \]
      6. distribute-rgt-out--75.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 4.2 \cdot 10^{+25}:\\ \;\;\;\;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 - \phi_1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 78.6% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 6.9 \cdot 10^{-46}:\\
\;\;\;\;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(\phi_2, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\\


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

    1. Initial program 60.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-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 0 46.5%

      \[\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}}} \]
    6. Step-by-step derivation
      1. +-commutative46.5%

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

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

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

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

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

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \]
    7. Simplified72.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 6.8999999999999998e-46 < phi2

    1. Initial program 53.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.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. Simplified95.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 52.0%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 6.9 \cdot 10^{-46}:\\ \;\;\;\;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(\phi_2, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 96.1% accurate, 1.5× speedup?

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

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

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

    \[\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 12: 33.0% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.8 \cdot 10^{-7} \lor \neg \left(\phi_1 \leq 9.4 \cdot 10^{-250}\right):\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(R \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right) \cdot \left(\lambda_2 - \lambda_1\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (or (<= phi1 -1.8e-7) (not (<= phi1 9.4e-250)))
   (* R (- phi2 phi1))
   (* (* R (cos (* 0.5 (+ phi2 phi1)))) (- lambda2 lambda1))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if ((phi1 <= -1.8e-7) || !(phi1 <= 9.4e-250)) {
		tmp = R * (phi2 - phi1);
	} else {
		tmp = (R * cos((0.5 * (phi2 + phi1)))) * (lambda2 - lambda1);
	}
	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.8d-7)) .or. (.not. (phi1 <= 9.4d-250))) then
        tmp = r * (phi2 - phi1)
    else
        tmp = (r * cos((0.5d0 * (phi2 + phi1)))) * (lambda2 - lambda1)
    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.8e-7) || !(phi1 <= 9.4e-250)) {
		tmp = R * (phi2 - phi1);
	} else {
		tmp = (R * Math.cos((0.5 * (phi2 + phi1)))) * (lambda2 - lambda1);
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if (phi1 <= -1.8e-7) or not (phi1 <= 9.4e-250):
		tmp = R * (phi2 - phi1)
	else:
		tmp = (R * math.cos((0.5 * (phi2 + phi1)))) * (lambda2 - lambda1)
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if ((phi1 <= -1.8e-7) || !(phi1 <= 9.4e-250))
		tmp = Float64(R * Float64(phi2 - phi1));
	else
		tmp = Float64(Float64(R * cos(Float64(0.5 * Float64(phi2 + phi1)))) * Float64(lambda2 - lambda1));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if ((phi1 <= -1.8e-7) || ~((phi1 <= 9.4e-250)))
		tmp = R * (phi2 - phi1);
	else
		tmp = (R * cos((0.5 * (phi2 + phi1)))) * (lambda2 - lambda1);
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[Or[LessEqual[phi1, -1.8e-7], N[Not[LessEqual[phi1, 9.4e-250]], $MachinePrecision]], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], N[(N[(R * N[Cos[N[(0.5 * N[(phi2 + phi1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -1.8 \cdot 10^{-7} \lor \neg \left(\phi_1 \leq 9.4 \cdot 10^{-250}\right):\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi1 < -1.79999999999999997e-7 or 9.39999999999999964e-250 < phi1

    1. Initial program 54.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-define93.6%

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

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

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

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

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

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

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

        \[\leadsto \phi_2 \cdot R - \color{blue}{\phi_1 \cdot R} \]
    7. Simplified36.5%

      \[\leadsto \color{blue}{\phi_2 \cdot R - \phi_1 \cdot R} \]
    8. Taylor expanded in phi2 around 0 36.5%

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

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

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

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

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

        \[\leadsto \color{blue}{\phi_2 \cdot R - \phi_1 \cdot R} \]
      6. distribute-rgt-out--37.8%

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

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

    if -1.79999999999999997e-7 < phi1 < 9.39999999999999964e-250

    1. Initial program 62.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 lambda1 around -inf 37.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.8 \cdot 10^{-7} \lor \neg \left(\phi_1 \leq 9.4 \cdot 10^{-250}\right):\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(R \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right) \cdot \left(\lambda_2 - \lambda_1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 29.8% accurate, 2.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq -3.6 \cdot 10^{-69}:\\
\;\;\;\;\left(\lambda_1 \cdot \cos \left(\phi_2 \cdot 0.5\right)\right) \cdot \left(-R\right)\\

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

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


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

    1. Initial program 56.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-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 lambda1 around -inf 22.0%

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

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

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

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

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

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

    if -3.60000000000000018e-69 < lambda2 < 4.9999999999999999e202

    1. Initial program 60.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.6%

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

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

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

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

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

        \[\leadsto \color{blue}{R \cdot \phi_2 - R \cdot \phi_1} \]
      4. *-commutative34.2%

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

        \[\leadsto \phi_2 \cdot R - \color{blue}{\phi_1 \cdot R} \]
    7. Simplified34.2%

      \[\leadsto \color{blue}{\phi_2 \cdot R - \phi_1 \cdot R} \]
    8. Taylor expanded in phi2 around 0 34.2%

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

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

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

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

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

        \[\leadsto \color{blue}{\phi_2 \cdot R - \phi_1 \cdot R} \]
      6. distribute-rgt-out--34.8%

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

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

    if 4.9999999999999999e202 < lambda2

    1. Initial program 36.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-define94.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. Simplified94.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 lambda1 around -inf 48.7%

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right) + R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} - 1} \]
    7. Applied egg-rr25.3%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(R \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right) \cdot \left(\lambda_2 + \lambda_1\right)\right)\right)} \]
    10. Taylor expanded in phi1 around 0 25.8%

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

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot R\right)} \cdot \left(\lambda_2 + \lambda_1\right)\right)\right) \]
    12. Simplified25.8%

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot R\right)} \cdot \left(\lambda_2 + \lambda_1\right)\right)\right) \]
    13. Taylor expanded in phi2 around 0 61.5%

      \[\leadsto \color{blue}{R \cdot \left(\lambda_1 + \lambda_2\right)} \]
    14. Step-by-step derivation
      1. +-commutative61.5%

        \[\leadsto R \cdot \color{blue}{\left(\lambda_2 + \lambda_1\right)} \]
    15. Simplified61.5%

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

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

Alternative 14: 29.8% accurate, 2.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq -3.6 \cdot 10^{-69}:\\
\;\;\;\;\cos \left(\phi_2 \cdot 0.5\right) \cdot \left(R \cdot \left(-\lambda_1\right)\right)\\

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

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


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

    1. Initial program 56.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-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 lambda1 around -inf 22.0%

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

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

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

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

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

      \[\leadsto -\color{blue}{R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)} \]
    9. Step-by-step derivation
      1. associate-*r*22.5%

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

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

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

    if -3.60000000000000018e-69 < lambda2 < 9.6000000000000008e202

    1. Initial program 60.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.6%

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

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

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

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

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

        \[\leadsto \color{blue}{R \cdot \phi_2 - R \cdot \phi_1} \]
      4. *-commutative34.2%

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

        \[\leadsto \phi_2 \cdot R - \color{blue}{\phi_1 \cdot R} \]
    7. Simplified34.2%

      \[\leadsto \color{blue}{\phi_2 \cdot R - \phi_1 \cdot R} \]
    8. Taylor expanded in phi2 around 0 34.2%

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

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

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

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

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

        \[\leadsto \color{blue}{\phi_2 \cdot R - \phi_1 \cdot R} \]
      6. distribute-rgt-out--34.8%

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

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

    if 9.6000000000000008e202 < lambda2

    1. Initial program 36.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-define94.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. Simplified94.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 lambda1 around -inf 48.7%

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right) + R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} - 1} \]
    7. Applied egg-rr25.3%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(R \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right) \cdot \left(\lambda_2 + \lambda_1\right)\right)\right)} \]
    10. Taylor expanded in phi1 around 0 25.8%

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

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot R\right)} \cdot \left(\lambda_2 + \lambda_1\right)\right)\right) \]
    12. Simplified25.8%

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot R\right)} \cdot \left(\lambda_2 + \lambda_1\right)\right)\right) \]
    13. Taylor expanded in phi2 around 0 61.5%

      \[\leadsto \color{blue}{R \cdot \left(\lambda_1 + \lambda_2\right)} \]
    14. Step-by-step derivation
      1. +-commutative61.5%

        \[\leadsto R \cdot \color{blue}{\left(\lambda_2 + \lambda_1\right)} \]
    15. Simplified61.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq -3.6 \cdot 10^{-69}:\\ \;\;\;\;\cos \left(\phi_2 \cdot 0.5\right) \cdot \left(R \cdot \left(-\lambda_1\right)\right)\\ \mathbf{elif}\;\lambda_2 \leq 9.6 \cdot 10^{+202}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\lambda_1 + \lambda_2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 33.0% accurate, 32.8× speedup?

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

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

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


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

    1. Initial program 59.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-define96.0%

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

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

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

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

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

        \[\leadsto \color{blue}{R \cdot \phi_2 - R \cdot \phi_1} \]
      4. *-commutative33.7%

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

        \[\leadsto \phi_2 \cdot R - \color{blue}{\phi_1 \cdot R} \]
    7. Simplified33.7%

      \[\leadsto \color{blue}{\phi_2 \cdot R - \phi_1 \cdot R} \]
    8. Taylor expanded in phi2 around 0 33.7%

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

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

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

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

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

        \[\leadsto \color{blue}{\phi_2 \cdot R - \phi_1 \cdot R} \]
      6. distribute-rgt-out--34.2%

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

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

    if 5.7999999999999999e202 < lambda2

    1. Initial program 36.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-define94.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. Simplified94.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 lambda1 around -inf 48.7%

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right) + R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} - 1} \]
    7. Applied egg-rr25.3%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(R \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right) \cdot \left(\lambda_2 + \lambda_1\right)\right)\right)} \]
    10. Taylor expanded in phi1 around 0 25.8%

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

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot R\right)} \cdot \left(\lambda_2 + \lambda_1\right)\right)\right) \]
    12. Simplified25.8%

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot R\right)} \cdot \left(\lambda_2 + \lambda_1\right)\right)\right) \]
    13. Taylor expanded in phi2 around 0 61.5%

      \[\leadsto \color{blue}{R \cdot \left(\lambda_1 + \lambda_2\right)} \]
    14. Step-by-step derivation
      1. +-commutative61.5%

        \[\leadsto R \cdot \color{blue}{\left(\lambda_2 + \lambda_1\right)} \]
    15. Simplified61.5%

      \[\leadsto \color{blue}{R \cdot \left(\lambda_2 + \lambda_1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification35.8%

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

Alternative 16: 28.1% accurate, 36.5× speedup?

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

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

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


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

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

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

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

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

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

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

    if 5.0000000000000002e-62 < phi2

    1. Initial program 53.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.1%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 5 \cdot 10^{-62}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 17: 17.8% accurate, 109.7× speedup?

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

\\
R \cdot \phi_2
\end{array}
Derivation
  1. Initial program 57.7%

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

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

      \[\leadsto \color{blue}{\phi_2 \cdot R} \]
  7. Simplified26.1%

    \[\leadsto \color{blue}{\phi_2 \cdot R} \]
  8. Final simplification26.1%

    \[\leadsto R \cdot \phi_2 \]
  9. Add Preprocessing

Reproduce

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