Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.7% → 99.9%
Time: 22.8s
Alternatives: 17
Speedup: 3.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 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.6× speedup?

\[\begin{array}{l} \\ R \cdot \mathsf{hypot}\left(\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) - \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \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
   (-
    (* (* (sin (* 0.5 phi1)) (sin (* phi2 0.5))) (- lambda2 lambda1))
    (* (* (cos (* 0.5 phi1)) (cos (* phi2 0.5))) (- lambda2 lambda1)))
   (- phi1 phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * hypot((((sin((0.5 * phi1)) * sin((phi2 * 0.5))) * (lambda2 - lambda1)) - ((cos((0.5 * phi1)) * cos((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((((Math.sin((0.5 * phi1)) * Math.sin((phi2 * 0.5))) * (lambda2 - lambda1)) - ((Math.cos((0.5 * phi1)) * Math.cos((phi2 * 0.5))) * (lambda2 - lambda1))), (phi1 - phi2));
}
def code(R, lambda1, lambda2, phi1, phi2):
	return R * math.hypot((((math.sin((0.5 * phi1)) * math.sin((phi2 * 0.5))) * (lambda2 - lambda1)) - ((math.cos((0.5 * phi1)) * math.cos((phi2 * 0.5))) * (lambda2 - lambda1))), (phi1 - phi2))
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(R * hypot(Float64(Float64(Float64(sin(Float64(0.5 * phi1)) * sin(Float64(phi2 * 0.5))) * Float64(lambda2 - lambda1)) - Float64(Float64(cos(Float64(0.5 * phi1)) * cos(Float64(phi2 * 0.5))) * Float64(lambda2 - lambda1))), Float64(phi1 - phi2)))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = R * hypot((((sin((0.5 * phi1)) * sin((phi2 * 0.5))) * (lambda2 - lambda1)) - ((cos((0.5 * phi1)) * cos((phi2 * 0.5))) * (lambda2 - lambda1))), (phi1 - phi2));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[Sqrt[N[(N[(N[(N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision] - N[(N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Cos[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(\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) - \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \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-def95.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-lft-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(0.5 \cdot \phi_2 + 0.5 \cdot \phi_1\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(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)}\right)\right), \phi_1 - \phi_2\right) \]
    5. *-commutative99.8%

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

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

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

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

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

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

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

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

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

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

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

    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-def97.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-lft-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(0.5 \cdot \phi_2 + 0.5 \cdot \phi_1\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(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)}\right)\right), \phi_1 - \phi_2\right) \]
      5. *-commutative99.8%

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

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

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(-\lambda_2 \cdot \color{blue}{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\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) \]
      3. *-commutative85.1%

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(-\lambda_2 \cdot \left(\cos \color{blue}{\left(\phi_2 \cdot 0.5\right)} \cdot \cos \left(0.5 \cdot \phi_1\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-rgt-neg-in85.1%

        \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\lambda_2 \cdot \left(-\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\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) \]
      5. *-commutative85.1%

        \[\leadsto R \cdot \mathsf{hypot}\left(\lambda_2 \cdot \left(-\cos \color{blue}{\left(0.5 \cdot \phi_2\right)} \cdot \cos \left(0.5 \cdot \phi_1\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) \]
      6. *-commutative85.1%

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

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

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

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

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

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

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

    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-def97.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-lft-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(0.5 \cdot \phi_2 + 0.5 \cdot \phi_1\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(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)}\right)\right), \phi_1 - \phi_2\right) \]
      5. *-commutative99.8%

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

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

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(-\lambda_2 \cdot \color{blue}{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\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) \]
      3. *-commutative85.1%

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(-\lambda_2 \cdot \left(\cos \color{blue}{\left(\phi_2 \cdot 0.5\right)} \cdot \cos \left(0.5 \cdot \phi_1\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-rgt-neg-in85.1%

        \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\lambda_2 \cdot \left(-\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\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) \]
      5. *-commutative85.1%

        \[\leadsto R \cdot \mathsf{hypot}\left(\lambda_2 \cdot \left(-\cos \color{blue}{\left(0.5 \cdot \phi_2\right)} \cdot \cos \left(0.5 \cdot \phi_1\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) \]
      6. *-commutative85.1%

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

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}\right)\right), \phi_1 - \phi_2\right) \]
    9. Step-by-step derivation
      1. log1p-expm1-u99.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: 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-def93.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-def97.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-lft-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(0.5 \cdot \phi_2 + 0.5 \cdot \phi_1\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(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)}\right)\right), \phi_1 - \phi_2\right) \]
      5. *-commutative99.8%

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

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

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(-\lambda_2 \cdot \color{blue}{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\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) \]
      3. *-commutative85.1%

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(-\lambda_2 \cdot \left(\cos \color{blue}{\left(\phi_2 \cdot 0.5\right)} \cdot \cos \left(0.5 \cdot \phi_1\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-rgt-neg-in85.1%

        \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\lambda_2 \cdot \left(-\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\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) \]
      5. *-commutative85.1%

        \[\leadsto R \cdot \mathsf{hypot}\left(\lambda_2 \cdot \left(-\cos \color{blue}{\left(0.5 \cdot \phi_2\right)} \cdot \cos \left(0.5 \cdot \phi_1\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) \]
      6. *-commutative85.1%

        \[\leadsto R \cdot \mathsf{hypot}\left(\lambda_2 \cdot \left(-\color{blue}{\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) \]
      7. 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) \]
      8. 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) \]
      9. +-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) \]
    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 6: 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-def96.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-def71.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-def95.3%

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

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in 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 7: 79.7% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 3.9 \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(\lambda_1 - \lambda_2, \phi_1 - \phi_2\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < 3.9000000000000002e-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-def96.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-def71.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 3.9000000000000002e-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-def95.3%

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

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in 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) \]
    6. Taylor expanded in phi2 around 0 85.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 3.9 \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(\lambda_1 - \lambda_2, \phi_1 - \phi_2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 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-def96.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-def72.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-def95.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-def85.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 9: 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-def95.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 10: 85.7% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 58.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-def96.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. Simplified96.1%

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

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

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

    if 5.1000000000000003e206 < lambda2

    1. Initial program 44.5%

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

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi2 around 0 44.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. +-commutative44.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. unpow244.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. unpow244.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. unpow244.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-sqr44.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-def86.8%

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

      \[\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)} \]
    8. Taylor expanded in lambda1 around 0 86.8%

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\cos \left(0.5 \cdot \phi_1\right) \cdot \left(-\lambda_2\right)}\right) \]
    11. Step-by-step derivation
      1. expm1-log1p-u41.2%

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(-\lambda_2\right)\right)\right)} - 1} \]
      3. *-commutative33.3%

        \[\leadsto e^{\mathsf{log1p}\left(R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\left(-\lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}\right)\right)} - 1 \]
      4. add-sqr-sqrt0.0%

        \[\leadsto e^{\mathsf{log1p}\left(R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\sqrt{-\lambda_2} \cdot \sqrt{-\lambda_2}\right)} \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)} - 1 \]
      5. sqrt-unprod18.2%

        \[\leadsto e^{\mathsf{log1p}\left(R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\sqrt{\left(-\lambda_2\right) \cdot \left(-\lambda_2\right)}} \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)} - 1 \]
      6. sqr-neg18.2%

        \[\leadsto e^{\mathsf{log1p}\left(R \cdot \mathsf{hypot}\left(\phi_1, \sqrt{\color{blue}{\lambda_2 \cdot \lambda_2}} \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)} - 1 \]
      7. sqrt-unprod33.3%

        \[\leadsto e^{\mathsf{log1p}\left(R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\sqrt{\lambda_2} \cdot \sqrt{\lambda_2}\right)} \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)} - 1 \]
      8. add-sqr-sqrt33.3%

        \[\leadsto e^{\mathsf{log1p}\left(R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_2} \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)} - 1 \]
    12. Applied egg-rr33.3%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(R \cdot \mathsf{hypot}\left(\phi_1, \lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)} - 1} \]
    13. Step-by-step derivation
      1. expm1-def41.2%

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

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

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

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

Alternative 11: 70.6% accurate, 3.0× speedup?

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

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

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


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

    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-def96.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 phi1 around 0 87.6%

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

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

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

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

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

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

    if 8.00000000000000072e25 < 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-def95.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 0 95.2%

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

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

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

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

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

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

Alternative 12: 57.4% accurate, 3.0× speedup?

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

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

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


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

    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-def96.6%

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

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

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

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

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

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

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

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

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

      \[\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)} \]
    8. Taylor expanded in lambda1 around 0 50.9%

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{-\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)}\right) \]
      2. distribute-lft-neg-out50.9%

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

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

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

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

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

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

    if 5500 < phi2

    1. Initial program 52.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-def94.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 phi1 around 0 94.5%

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

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

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

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

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

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

Alternative 13: 85.7% accurate, 3.0× speedup?

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

\\
R \cdot \mathsf{hypot}\left(\lambda_1 - \lambda_2, \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-def95.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 phi1 around 0 89.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) \]
  6. Taylor expanded in phi2 around 0 83.7%

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

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

Alternative 14: 33.1% accurate, 32.8× speedup?

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

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

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


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

    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-def96.0%

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

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

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

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

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

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

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

    if 4.2e202 < 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-def94.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 lambda2 around inf 55.8%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \cdot R \]
    9. Step-by-step derivation
      1. *-commutative53.3%

        \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2\right)} \cdot R \]
    10. Simplified53.3%

      \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2\right)} \cdot R \]
    11. Taylor expanded in phi1 around 0 61.2%

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

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    13. Simplified61.2%

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

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

Alternative 15: 28.1% accurate, 36.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 3.85 \cdot 10^{-59}:\\
\;\;\;\;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 < 3.85e-59

    1. Initial program 59.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-def96.4%

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

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

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

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

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

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

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

    if 3.85e-59 < phi2

    1. Initial program 54.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-def95.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 65.4%

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

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

      \[\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 3.85 \cdot 10^{-59}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 16: 26.8% accurate, 41.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 3700:\\
\;\;\;\;R \cdot \lambda_2\\

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


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

    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-def96.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \cdot R \]
    9. Step-by-step derivation
      1. *-commutative14.4%

        \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2\right)} \cdot R \]
    10. Simplified14.4%

      \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2\right)} \cdot R \]
    11. Taylor expanded in phi1 around 0 13.2%

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

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    13. Simplified13.2%

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

    if 3700 < phi2

    1. Initial program 52.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-def94.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 phi2 around inf 70.5%

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

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

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

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

Alternative 17: 14.3% accurate, 109.7× speedup?

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \cdot R \]
  9. Step-by-step derivation
    1. *-commutative13.4%

      \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2\right)} \cdot R \]
  10. Simplified13.4%

    \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2\right)} \cdot R \]
  11. Taylor expanded in phi1 around 0 11.5%

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

      \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
  13. Simplified11.5%

    \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
  14. Final simplification11.5%

    \[\leadsto R \cdot \lambda_2 \]
  15. 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))))))