Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.4% → 99.9%
Time: 30.5s
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: 60.4% 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 59.7%

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

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

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

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

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

      \[\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_1 + \phi_2\right)\right)}\right)\right), \phi_1 - \phi_2\right) \]
    2. +-commutative96.7%

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

      \[\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 \phi_2 + 0.5 \cdot \phi_1\right)}\right)\right), \phi_1 - \phi_2\right) \]
    4. cos-sum99.8%

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

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

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

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

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

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

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

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

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

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

Alternative 2: 90.8% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 125000000:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right), \phi_1 - \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_2 \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 125000000.0)
   (* R (hypot (* (- lambda1 lambda2) (cos (* 0.5 phi1))) (- phi1 phi2)))
   (* R (hypot (* lambda2 (cos (* phi2 0.5))) (- phi1 phi2)))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 125000000.0) {
		tmp = R * hypot(((lambda1 - lambda2) * cos((0.5 * phi1))), (phi1 - phi2));
	} else {
		tmp = R * hypot((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 <= 125000000.0) {
		tmp = R * Math.hypot(((lambda1 - lambda2) * Math.cos((0.5 * phi1))), (phi1 - phi2));
	} else {
		tmp = R * Math.hypot((lambda2 * Math.cos((phi2 * 0.5))), (phi1 - phi2));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 125000000.0:
		tmp = R * math.hypot(((lambda1 - lambda2) * math.cos((0.5 * phi1))), (phi1 - phi2))
	else:
		tmp = R * math.hypot((lambda2 * math.cos((phi2 * 0.5))), (phi1 - phi2))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 125000000.0)
		tmp = Float64(R * hypot(Float64(Float64(lambda1 - lambda2) * cos(Float64(0.5 * phi1))), Float64(phi1 - phi2)));
	else
		tmp = Float64(R * hypot(Float64(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 <= 125000000.0)
		tmp = R * hypot(((lambda1 - lambda2) * cos((0.5 * phi1))), (phi1 - phi2));
	else
		tmp = R * hypot((lambda2 * cos((phi2 * 0.5))), (phi1 - phi2));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 125000000.0], 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[(lambda2 * 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 125000000:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right), \phi_1 - \phi_2\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_2 \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.25e8

    1. Initial program 62.4%

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

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

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Taylor expanded in 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.25e8 < phi2

    1. Initial program 51.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-def93.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. Simplified93.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 0 93.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 93.8% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -7.5 \cdot 10^{-7}:\\ \;\;\;\;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 (<= phi1 -7.5e-7)
   (* 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 (phi1 <= -7.5e-7) {
		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 (phi1 <= -7.5e-7) {
		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 phi1 <= -7.5e-7:
		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 (phi1 <= -7.5e-7)
		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 (phi1 <= -7.5e-7)
		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[phi1, -7.5e-7], 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_1 \leq -7.5 \cdot 10^{-7}:\\
\;\;\;\;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 phi1 < -7.5000000000000002e-7

    1. Initial program 54.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-def93.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. Simplified93.5%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -7.5 \cdot 10^{-7}:\\ \;\;\;\;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 4: 96.3% accurate, 1.5× speedup?

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

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

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

    \[\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 5: 85.3% accurate, 1.6× speedup?

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

\mathbf{else}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_2 \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 lambda2 < 2.6e39

    1. Initial program 58.5%

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

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

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

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

    if 2.6e39 < lambda2

    1. Initial program 63.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-def94.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. Simplified94.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 73.2% accurate, 3.0× speedup?

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

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

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


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

    1. Initial program 61.8%

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

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

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

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

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

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

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

    if 2.19999999999999993e-45 < phi2

    1. Initial program 54.7%

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 33.9% accurate, 3.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq -56000000000000:\\
\;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if lambda2 < -5.6e13

    1. Initial program 54.7%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{R \cdot \lambda_2 - R \cdot \lambda_1} \]
    9. Step-by-step derivation
      1. distribute-lft-out--12.3%

        \[\leadsto \color{blue}{R \cdot \left(\lambda_2 - \lambda_1\right)} \]
    10. Simplified12.3%

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

    if -5.6e13 < lambda2 < 3.3e62

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

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

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

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

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

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

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

    if 3.3e62 < lambda2

    1. Initial program 59.5%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{R \cdot \sqrt{{\lambda_2}^{2} + {\phi_1}^{2}}} \]
    9. Step-by-step derivation
      1. +-commutative53.5%

        \[\leadsto R \cdot \sqrt{\color{blue}{{\phi_1}^{2} + {\lambda_2}^{2}}} \]
      2. unpow253.5%

        \[\leadsto R \cdot \sqrt{\color{blue}{\phi_1 \cdot \phi_1} + {\lambda_2}^{2}} \]
      3. unpow253.5%

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\lambda_2 \cdot \lambda_2}} \]
      4. hypot-def67.9%

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

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

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

Alternative 8: 70.7% accurate, 3.0× speedup?

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

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

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


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

    1. Initial program 62.8%

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

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

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

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

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

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

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

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

    if 2.2e18 < phi2

    1. Initial program 49.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-def93.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. Simplified93.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 73.0%

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

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

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

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

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

Alternative 9: 71.3% accurate, 3.0× speedup?

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

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

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


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

    1. Initial program 62.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-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 phi1 around 0 87.0%

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

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

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

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

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

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

    if 6.49999999999999968e-49 < phi2

    1. Initial program 54.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 85.3% 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 59.7%

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

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

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

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

Alternative 11: 32.3% accurate, 36.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 \leq -1.12 \cdot 10^{+110} \lor \neg \left(\lambda_1 \leq 1.25 \cdot 10^{+57}\right):\\
\;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda1 < -1.1200000000000001e110 or 1.24999999999999993e57 < lambda1

    1. Initial program 52.7%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{R \cdot \lambda_2 - R \cdot \lambda_1} \]
    9. Step-by-step derivation
      1. distribute-lft-out--26.3%

        \[\leadsto \color{blue}{R \cdot \left(\lambda_2 - \lambda_1\right)} \]
    10. Simplified26.3%

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

    if -1.1200000000000001e110 < lambda1 < 1.24999999999999993e57

    1. Initial program 64.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-def99.9%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -1.12 \cdot 10^{+110} \lor \neg \left(\lambda_1 \leq 1.25 \cdot 10^{+57}\right):\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \end{array} \]

Alternative 12: 32.2% accurate, 36.1× speedup?

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

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

\mathbf{elif}\;\phi_2 \leq 2.4 \cdot 10^{+16}:\\
\;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < -4.0000000000000004e-192

    1. Initial program 61.3%

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

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

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

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

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

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

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

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

    if -4.0000000000000004e-192 < phi2 < 2.4e16

    1. Initial program 64.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-def99.9%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{R \cdot \lambda_2 - R \cdot \lambda_1} \]
    9. Step-by-step derivation
      1. distribute-lft-out--32.0%

        \[\leadsto \color{blue}{R \cdot \left(\lambda_2 - \lambda_1\right)} \]
    10. Simplified32.0%

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

    if 2.4e16 < phi2

    1. Initial program 49.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-def93.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. Simplified93.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 inf 67.3%

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

        \[\leadsto \color{blue}{\phi_2 \cdot R} \]
    6. Simplified67.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -4 \cdot 10^{-192}:\\ \;\;\;\;\phi_1 \cdot \left(-R\right)\\ \mathbf{elif}\;\phi_2 \leq 2.4 \cdot 10^{+16}:\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]

Alternative 13: 28.8% accurate, 54.3× speedup?

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

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

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


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

    1. Initial program 61.7%

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

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

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

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

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

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

    if 1.3e-43 < phi2

    1. Initial program 54.7%

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

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

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

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

        \[\leadsto \color{blue}{\phi_2 \cdot R} \]
    6. Simplified61.4%

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

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

Alternative 14: 25.0% accurate, 65.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 \leq 5 \cdot 10^{+57}:\\
\;\;\;\;R \cdot \phi_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda1 < 4.99999999999999972e57

    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-def97.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. Simplified97.4%

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

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

        \[\leadsto \color{blue}{\phi_2 \cdot R} \]
    6. Simplified21.0%

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

    if 4.99999999999999972e57 < lambda1

    1. Initial program 54.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-def94.3%

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

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

      \[\leadsto \color{blue}{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.7%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq 5 \cdot 10^{+57}:\\ \;\;\;\;R \cdot \phi_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \lambda_1\\ \end{array} \]

Alternative 15: 14.2% accurate, 109.7× speedup?

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

\\
R \cdot \lambda_1
\end{array}
Derivation
  1. Initial program 59.7%

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

    \[\leadsto \color{blue}{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. *-commutative16.6%

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

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

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

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

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

    \[\leadsto \color{blue}{\lambda_1} \cdot R \]
  11. Final simplification14.4%

    \[\leadsto R \cdot \lambda_1 \]

Reproduce

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