Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.6% → 99.9%
Time: 23.8s
Alternatives: 15
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 15 alternatives:

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

Initial Program: 59.6% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 0.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)}, \phi_1 - \phi_2\right) \]
    2. cancel-sign-sub-inv99.8%

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

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

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

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

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

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

Alternative 2: 87.6% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq 2 \cdot 10^{-134}:\\
\;\;\;\;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(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right), \phi_1 - \phi_2\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda2 < 2.00000000000000008e-134

    1. Initial program 60.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.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. Step-by-step derivation
      1. expm1-log1p-u95.0%

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

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

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

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

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

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

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

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

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

      \[\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) \]
    9. Step-by-step derivation
      1. *-commutative84.1%

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

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

    if 2.00000000000000008e-134 < lambda2

    1. Initial program 49.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-def99.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. Simplified99.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. Step-by-step derivation
      1. expm1-log1p-u99.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 2 \cdot 10^{-134}:\\ \;\;\;\;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(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right), \phi_1 - \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)\right), \phi_1 - \phi_2\right)\\ \end{array} \]

Alternative 3: 79.2% accurate, 1.5× speedup?

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

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

\mathbf{elif}\;\lambda_2 \leq 3.9 \cdot 10^{+68}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_1 - \phi_2\right)\\

\mathbf{elif}\;\lambda_2 \leq 8.5 \cdot 10^{+237}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(-\lambda_2\right), \phi_1 - \phi_2\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if lambda2 < 3.99999999999999974e-148

    1. Initial program 61.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(e^{\color{blue}{\log \left(1 + \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}} - 1\right), \phi_1 - \phi_2\right) \]
      7. add-exp-log95.3%

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

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

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

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

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

    if 3.99999999999999974e-148 < lambda2 < 3.90000000000000019e68

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

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

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

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

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

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

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

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

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

    if 3.90000000000000019e68 < lambda2 < 8.4999999999999994e237

    1. Initial program 37.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.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. Simplified97.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. Step-by-step derivation
      1. expm1-log1p-u97.9%

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\color{blue}{\log \left(1 + \cos \left(0.5 \cdot \phi_1\right)\right)}\right), \phi_1 - \phi_2\right) \]
    7. Taylor expanded in lambda1 around 0 90.2%

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

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

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

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

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

    if 8.4999999999999994e237 < lambda2

    1. Initial program 52.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-def99.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. Simplified99.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. Taylor expanded in lambda1 around inf 40.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 77.7% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 37.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.9999999999999998e181 < (-.f64 lambda1 lambda2)

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

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

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

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

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

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

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

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

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

Alternative 5: 87.7% accurate, 1.5× speedup?

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

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

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


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

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

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

    if 3.19999999999999981e238 < lambda2

    1. Initial program 52.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-def99.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. Simplified99.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. Taylor expanded in lambda1 around inf 40.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 92.8% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 61.1%

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

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

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

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

    if 1.0000000000000001e-18 < phi2

    1. Initial program 44.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-def92.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. Simplified92.2%

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

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

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

Alternative 7: 95.8% 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 56.5%

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

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

Alternative 8: 80.3% accurate, 1.5× speedup?

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

    1. Initial program 62.0%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. 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. Taylor expanded in lambda1 around inf 27.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left|\cos \left(\phi_2 \cdot 0.5\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot R\right)\right|} \]
      3. associate-*r*32.7%

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

        \[\leadsto \left|\left(\cos \color{blue}{\left(0.5 \cdot \phi_2\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\right| \]
      5. *-commutative32.7%

        \[\leadsto \left|\color{blue}{R \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}\right| \]
      6. associate-*r*32.7%

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

        \[\leadsto \left|\left(R \cdot \cos \color{blue}{\left(\phi_2 \cdot 0.5\right)}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right| \]
    13. Simplified32.7%

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

    if -4.99999999999999995e238 < (-.f64 lambda1 lambda2)

    1. Initial program 56.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-def97.2%

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

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

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

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

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

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

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

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

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

Alternative 9: 33.7% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{if}\;\lambda_2 \leq 2.4 \cdot 10^{+96}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\lambda_2 \leq 2.6 \cdot 10^{+108}:\\ \;\;\;\;\cos \left(\phi_2 \cdot 0.5\right) \cdot \left(R \cdot \lambda_2\right)\\ \mathbf{elif}\;\lambda_2 \leq 1.65 \cdot 10^{+138}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\cos \left(0.5 \cdot \phi_1\right) \cdot \left(R \cdot \lambda_2\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* R (- phi2 phi1))))
   (if (<= lambda2 2.4e+96)
     t_0
     (if (<= lambda2 2.6e+108)
       (* (cos (* phi2 0.5)) (* R lambda2))
       (if (<= lambda2 1.65e+138) t_0 (* (cos (* 0.5 phi1)) (* R lambda2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * (phi2 - phi1);
	double tmp;
	if (lambda2 <= 2.4e+96) {
		tmp = t_0;
	} else if (lambda2 <= 2.6e+108) {
		tmp = cos((phi2 * 0.5)) * (R * lambda2);
	} else if (lambda2 <= 1.65e+138) {
		tmp = t_0;
	} else {
		tmp = cos((0.5 * phi1)) * (R * lambda2);
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: tmp
    t_0 = r * (phi2 - phi1)
    if (lambda2 <= 2.4d+96) then
        tmp = t_0
    else if (lambda2 <= 2.6d+108) then
        tmp = cos((phi2 * 0.5d0)) * (r * lambda2)
    else if (lambda2 <= 1.65d+138) then
        tmp = t_0
    else
        tmp = cos((0.5d0 * phi1)) * (r * lambda2)
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * (phi2 - phi1);
	double tmp;
	if (lambda2 <= 2.4e+96) {
		tmp = t_0;
	} else if (lambda2 <= 2.6e+108) {
		tmp = Math.cos((phi2 * 0.5)) * (R * lambda2);
	} else if (lambda2 <= 1.65e+138) {
		tmp = t_0;
	} else {
		tmp = Math.cos((0.5 * phi1)) * (R * lambda2);
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = R * (phi2 - phi1)
	tmp = 0
	if lambda2 <= 2.4e+96:
		tmp = t_0
	elif lambda2 <= 2.6e+108:
		tmp = math.cos((phi2 * 0.5)) * (R * lambda2)
	elif lambda2 <= 1.65e+138:
		tmp = t_0
	else:
		tmp = math.cos((0.5 * phi1)) * (R * lambda2)
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(R * Float64(phi2 - phi1))
	tmp = 0.0
	if (lambda2 <= 2.4e+96)
		tmp = t_0;
	elseif (lambda2 <= 2.6e+108)
		tmp = Float64(cos(Float64(phi2 * 0.5)) * Float64(R * lambda2));
	elseif (lambda2 <= 1.65e+138)
		tmp = t_0;
	else
		tmp = Float64(cos(Float64(0.5 * phi1)) * Float64(R * lambda2));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = R * (phi2 - phi1);
	tmp = 0.0;
	if (lambda2 <= 2.4e+96)
		tmp = t_0;
	elseif (lambda2 <= 2.6e+108)
		tmp = cos((phi2 * 0.5)) * (R * lambda2);
	elseif (lambda2 <= 1.65e+138)
		tmp = t_0;
	else
		tmp = cos((0.5 * phi1)) * (R * lambda2);
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda2, 2.4e+96], t$95$0, If[LessEqual[lambda2, 2.6e+108], N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[(R * lambda2), $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda2, 1.65e+138], t$95$0, N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(R * lambda2), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\lambda_2 \leq 2.6 \cdot 10^{+108}:\\
\;\;\;\;\cos \left(\phi_2 \cdot 0.5\right) \cdot \left(R \cdot \lambda_2\right)\\

\mathbf{elif}\;\lambda_2 \leq 1.65 \cdot 10^{+138}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if lambda2 < 2.39999999999999993e96 or 2.6000000000000002e108 < lambda2 < 1.64999999999999989e138

    1. Initial program 60.4%

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

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

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

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

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

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

    if 2.39999999999999993e96 < lambda2 < 2.6000000000000002e108

    1. Initial program 100.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-def100.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\lambda_2 \cdot R\right)} \cdot \cos \left(0.5 \cdot \phi_2\right) \]
    9. Simplified76.8%

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

    if 1.64999999999999989e138 < lambda2

    1. Initial program 30.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-def97.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. Simplified97.6%

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

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

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

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

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

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

      \[\leadsto \color{blue}{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
    8. Step-by-step derivation
      1. associate-*r*49.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 2.4 \cdot 10^{+96}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\lambda_2 \leq 2.6 \cdot 10^{+108}:\\ \;\;\;\;\cos \left(\phi_2 \cdot 0.5\right) \cdot \left(R \cdot \lambda_2\right)\\ \mathbf{elif}\;\lambda_2 \leq 1.65 \cdot 10^{+138}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\cos \left(0.5 \cdot \phi_1\right) \cdot \left(R \cdot \lambda_2\right)\\ \end{array} \]

Alternative 10: 33.8% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{if}\;\lambda_2 \leq 1.1 \cdot 10^{+97}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\lambda_2 \leq 5.4 \cdot 10^{+108}:\\ \;\;\;\;R \cdot \left(\lambda_2 \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\\ \mathbf{elif}\;\lambda_2 \leq 1.05 \cdot 10^{+138}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\cos \left(0.5 \cdot \phi_1\right) \cdot \left(R \cdot \lambda_2\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* R (- phi2 phi1))))
   (if (<= lambda2 1.1e+97)
     t_0
     (if (<= lambda2 5.4e+108)
       (* R (* lambda2 (cos (* phi2 0.5))))
       (if (<= lambda2 1.05e+138) t_0 (* (cos (* 0.5 phi1)) (* R lambda2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * (phi2 - phi1);
	double tmp;
	if (lambda2 <= 1.1e+97) {
		tmp = t_0;
	} else if (lambda2 <= 5.4e+108) {
		tmp = R * (lambda2 * cos((phi2 * 0.5)));
	} else if (lambda2 <= 1.05e+138) {
		tmp = t_0;
	} else {
		tmp = cos((0.5 * phi1)) * (R * lambda2);
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: tmp
    t_0 = r * (phi2 - phi1)
    if (lambda2 <= 1.1d+97) then
        tmp = t_0
    else if (lambda2 <= 5.4d+108) then
        tmp = r * (lambda2 * cos((phi2 * 0.5d0)))
    else if (lambda2 <= 1.05d+138) then
        tmp = t_0
    else
        tmp = cos((0.5d0 * phi1)) * (r * lambda2)
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * (phi2 - phi1);
	double tmp;
	if (lambda2 <= 1.1e+97) {
		tmp = t_0;
	} else if (lambda2 <= 5.4e+108) {
		tmp = R * (lambda2 * Math.cos((phi2 * 0.5)));
	} else if (lambda2 <= 1.05e+138) {
		tmp = t_0;
	} else {
		tmp = Math.cos((0.5 * phi1)) * (R * lambda2);
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = R * (phi2 - phi1)
	tmp = 0
	if lambda2 <= 1.1e+97:
		tmp = t_0
	elif lambda2 <= 5.4e+108:
		tmp = R * (lambda2 * math.cos((phi2 * 0.5)))
	elif lambda2 <= 1.05e+138:
		tmp = t_0
	else:
		tmp = math.cos((0.5 * phi1)) * (R * lambda2)
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(R * Float64(phi2 - phi1))
	tmp = 0.0
	if (lambda2 <= 1.1e+97)
		tmp = t_0;
	elseif (lambda2 <= 5.4e+108)
		tmp = Float64(R * Float64(lambda2 * cos(Float64(phi2 * 0.5))));
	elseif (lambda2 <= 1.05e+138)
		tmp = t_0;
	else
		tmp = Float64(cos(Float64(0.5 * phi1)) * Float64(R * lambda2));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = R * (phi2 - phi1);
	tmp = 0.0;
	if (lambda2 <= 1.1e+97)
		tmp = t_0;
	elseif (lambda2 <= 5.4e+108)
		tmp = R * (lambda2 * cos((phi2 * 0.5)));
	elseif (lambda2 <= 1.05e+138)
		tmp = t_0;
	else
		tmp = cos((0.5 * phi1)) * (R * lambda2);
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda2, 1.1e+97], t$95$0, If[LessEqual[lambda2, 5.4e+108], N[(R * N[(lambda2 * N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda2, 1.05e+138], t$95$0, N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(R * lambda2), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\lambda_2 \leq 5.4 \cdot 10^{+108}:\\
\;\;\;\;R \cdot \left(\lambda_2 \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\\

\mathbf{elif}\;\lambda_2 \leq 1.05 \cdot 10^{+138}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if lambda2 < 1.1e97 or 5.4e108 < lambda2 < 1.05000000000000003e138

    1. Initial program 60.4%

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

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

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

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

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

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

    if 1.1e97 < lambda2 < 5.4e108

    1. Initial program 100.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-def100.0%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)} \cdot R \]
    8. Step-by-step derivation
      1. *-commutative76.8%

        \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_2\right)} \cdot R \]
    9. Simplified76.8%

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

    if 1.05000000000000003e138 < lambda2

    1. Initial program 30.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-def97.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. Simplified97.6%

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

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

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

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

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

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

      \[\leadsto \color{blue}{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
    8. Step-by-step derivation
      1. associate-*r*49.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 1.1 \cdot 10^{+97}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\lambda_2 \leq 5.4 \cdot 10^{+108}:\\ \;\;\;\;R \cdot \left(\lambda_2 \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\\ \mathbf{elif}\;\lambda_2 \leq 1.05 \cdot 10^{+138}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\cos \left(0.5 \cdot \phi_1\right) \cdot \left(R \cdot \lambda_2\right)\\ \end{array} \]

Alternative 11: 33.7% accurate, 3.0× speedup?

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

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

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


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

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

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

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

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

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

    if 3.40000000000000011e138 < lambda2

    1. Initial program 30.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-def97.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. Simplified97.6%

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

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

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

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

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

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

      \[\leadsto \color{blue}{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
    8. Step-by-step derivation
      1. associate-*r*49.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 3.4 \cdot 10^{+138}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\cos \left(0.5 \cdot \phi_1\right) \cdot \left(R \cdot \lambda_2\right)\\ \end{array} \]

Alternative 12: 84.6% 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 56.5%

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

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

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

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

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

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

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

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

Alternative 13: 28.3% accurate, 54.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -175000000:\\ \;\;\;\;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 (<= phi1 -175000000.0) (* R (- phi1)) (* R phi2)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -175000000.0) {
		tmp = R * -phi1;
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: tmp
    if (phi1 <= (-175000000.0d0)) then
        tmp = r * -phi1
    else
        tmp = r * phi2
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -175000000.0) {
		tmp = R * -phi1;
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -175000000.0:
		tmp = R * -phi1
	else:
		tmp = R * phi2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -175000000.0)
		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 (phi1 <= -175000000.0)
		tmp = R * -phi1;
	else
		tmp = R * phi2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -175000000.0], N[(R * (-phi1)), $MachinePrecision], N[(R * phi2), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -175000000:\\
\;\;\;\;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 phi1 < -1.75e8

    1. Initial program 48.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-def91.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. Simplified91.5%

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

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

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

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

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

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

    if -1.75e8 < phi1

    1. Initial program 58.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.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. Simplified97.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. Taylor expanded in phi2 around inf 16.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -175000000:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]

Alternative 14: 29.4% accurate, 65.8× speedup?

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

\\
R \cdot \left(\phi_2 - \phi_1\right)
\end{array}
Derivation
  1. Initial program 56.5%

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

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

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

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

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

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

Alternative 15: 17.4% accurate, 109.7× speedup?

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

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

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

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

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

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

    \[\leadsto R \cdot \phi_2 \]

Reproduce

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