Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.2% → 99.9%
Time: 19.3s
Alternatives: 20
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 20 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.2% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 0.6× speedup?

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

\\
R \cdot \mathsf{hypot}\left(\left(\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot 0.5\right)\right) \cdot \left(\lambda_2 - \lambda_1\right) - \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\right) \cdot \left(\lambda_2 - \lambda_1\right), \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 55.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-define95.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\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), \phi_1 - \phi_2\right) \]
  9. Step-by-step derivation
    1. rem-log-exp99.9%

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

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

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

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

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

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

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

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

Alternative 2: 98.2% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot 0.5\right)\\
t_1 := \cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\\
\mathbf{if}\;\lambda_1 \leq -6.8 \cdot 10^{+241}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot t\_1 - \lambda_1 \cdot t\_0, \phi_1 - \phi_2\right)\\

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


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

    1. Initial program 45.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-define83.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. Simplified83.5%

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\log \left(e^{\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right)}\right)}, \phi_1 - \phi_2\right) \]
    7. Step-by-step derivation
      1. *-commutative83.5%

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\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), \phi_1 - \phi_2\right) \]
    9. Step-by-step derivation
      1. rem-log-exp99.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. sub-neg99.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) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right)}, \phi_1 - \phi_2\right) \]
      3. distribute-lft-in99.8%

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

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

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

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

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

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

    if -6.79999999999999987e241 < lambda1

    1. Initial program 56.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\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), \phi_1 - \phi_2\right) \]
    9. Step-by-step derivation
      1. rem-log-exp99.9%

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

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

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

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

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

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

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

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

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

Alternative 3: 85.4% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot 0.5\right)\\
t_1 := \cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\\
\mathbf{if}\;\lambda_2 \leq 620:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot t\_1 - \lambda_1 \cdot t\_0, \phi_1 - \phi_2\right)\\

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


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

    1. Initial program 59.7%

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\log \left(e^{\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right)}\right)}, \phi_1 - \phi_2\right) \]
    7. Step-by-step derivation
      1. *-commutative96.4%

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\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), \phi_1 - \phi_2\right) \]
    9. Step-by-step derivation
      1. rem-log-exp99.9%

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

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

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

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

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

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

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

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

    if 620 < lambda2

    1. Initial program 44.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\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), \phi_1 - \phi_2\right) \]
    9. Taylor expanded in lambda1 around 0 90.7%

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

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

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

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

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

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

Alternative 4: 85.4% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot 0.5\right)\\
t_1 := \cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\\
\mathbf{if}\;\lambda_2 \leq 8800:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot \left(t\_1 - t\_0\right), \phi_1 - \phi_2\right)\\

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


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

    1. Initial program 59.7%

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\log \left(e^{\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right)}\right)}, \phi_1 - \phi_2\right) \]
    7. Step-by-step derivation
      1. *-commutative96.4%

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\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), \phi_1 - \phi_2\right) \]
    9. Taylor expanded in lambda1 around inf 86.9%

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

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

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

    if 8800 < lambda2

    1. Initial program 44.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\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), \phi_1 - \phi_2\right) \]
    9. Taylor expanded in lambda1 around 0 90.7%

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

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

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

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

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

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

Alternative 5: 96.4% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\\
\mathbf{if}\;\lambda_1 \leq -5 \cdot 10^{+241}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot \left(t\_0 - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot 0.5\right)\right), \phi_1 - \phi_2\right)\\

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


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

    1. Initial program 45.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-define83.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. Simplified83.5%

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\log \left(e^{\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right)}\right)}, \phi_1 - \phi_2\right) \]
    7. Step-by-step derivation
      1. *-commutative83.5%

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\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), \phi_1 - \phi_2\right) \]
    9. Taylor expanded in lambda1 around inf 99.8%

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

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

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

    if -5.00000000000000025e241 < lambda1

    1. Initial program 56.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\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), \phi_1 - \phi_2\right) \]
    9. Step-by-step derivation
      1. rem-log-exp99.9%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) + \left(\lambda_1 - \lambda_2\right) \cdot \left(\sin \left(\phi_2 \cdot 0.5\right) \cdot \color{blue}{\left(\sqrt{\sin \left(0.5 \cdot \phi_1\right)} \cdot \sqrt{\sin \left(0.5 \cdot \phi_1\right)}\right)}\right), \phi_1 - \phi_2\right) \]
      5. add-sqr-sqrt97.0%

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) + \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\frac{\cos \left(\mathsf{fma}\left(\phi_2, 0.5, 0.5 \cdot \phi_1\right)\right) - \cos \left(\mathsf{fma}\left(\phi_2, 0.5, 0.5 \cdot \phi_1\right)\right)}{2}}, \phi_1 - \phi_2\right) \]
    13. Step-by-step derivation
      1. +-inverses96.9%

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

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

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

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

Alternative 6: 96.1% accurate, 1.0× speedup?

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

\\
R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\right) + 0 \cdot \left(\lambda_2 - \lambda_1\right), \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 55.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-define95.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\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), \phi_1 - \phi_2\right) \]
  9. Step-by-step derivation
    1. rem-log-exp99.9%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) + \left(\lambda_1 - \lambda_2\right) \cdot \left(\sin \left(\phi_2 \cdot 0.5\right) \cdot \color{blue}{\left(\sqrt{\sin \left(0.5 \cdot \phi_1\right)} \cdot \sqrt{\sin \left(0.5 \cdot \phi_1\right)}\right)}\right), \phi_1 - \phi_2\right) \]
    5. add-sqr-sqrt95.9%

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

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

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) + \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\frac{\cos \left(\mathsf{fma}\left(\phi_2, 0.5, 0.5 \cdot \phi_1\right)\right) - \cos \left(\mathsf{fma}\left(\phi_2, 0.5, 0.5 \cdot \phi_1\right)\right)}{2}}, \phi_1 - \phi_2\right) \]
  13. Step-by-step derivation
    1. +-inverses95.9%

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

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

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) + \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{0}, \phi_1 - \phi_2\right) \]
  15. Final simplification95.9%

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

Alternative 7: 92.7% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 57.6%

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

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

      \[\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.4000000000000001e-45 < phi2

    1. Initial program 48.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-define88.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. Simplified88.6%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi1 around 0 88.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) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification93.7%

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

Alternative 8: 90.5% accurate, 1.5× speedup?

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

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


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

    1. Initial program 58.8%

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

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

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

      \[\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.30000000000000001e26 < phi2

    1. Initial program 42.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-define88.0%

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

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

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

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

        \[\leadsto R \cdot \sqrt{\color{blue}{{\left(\phi_1 - \phi_2\right)}^{2} + {\left(-1 \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right) + 0.5 \cdot \left(\lambda_2 \cdot \left(\phi_1 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right)}^{2}}} \]
      2. unpow242.7%

        \[\leadsto R \cdot \sqrt{\color{blue}{\left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} + {\left(-1 \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right) + 0.5 \cdot \left(\lambda_2 \cdot \left(\phi_1 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right)}^{2}} \]
      3. unpow242.7%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 79.2% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 59.7%

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

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

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

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

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

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

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

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

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

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

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

    if 10.5999999999999996 < lambda2

    1. Initial program 44.2%

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

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

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

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

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

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

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

        \[\leadsto R \cdot \sqrt{\left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right) + \color{blue}{\left(-1 \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right) + 0.5 \cdot \left(\lambda_2 \cdot \left(\phi_1 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right) \cdot \left(-1 \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right) + 0.5 \cdot \left(\lambda_2 \cdot \left(\phi_1 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right)}} \]
      4. hypot-define70.0%

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 79.2% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(0.5 \cdot \phi_1\right)\\
\mathbf{if}\;\lambda_2 \leq 680:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot t\_0, \phi_1 - \phi_2\right)\\

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


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

    1. Initial program 59.7%

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

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

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

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

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

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

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

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

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

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

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

    if 680 < lambda2

    1. Initial program 44.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 74.0% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -100000000:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right), \phi_1 - \phi_2\right)\\ \mathbf{elif}\;\phi_1 \leq -5.2 \cdot 10^{-42}:\\ \;\;\;\;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 (<= phi1 -100000000.0)
   (* R (hypot (* lambda1 (cos (* 0.5 phi1))) (- phi1 phi2)))
   (if (<= phi1 -5.2e-42)
     (* 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 (phi1 <= -100000000.0) {
		tmp = R * hypot((lambda1 * cos((0.5 * phi1))), (phi1 - phi2));
	} else if (phi1 <= -5.2e-42) {
		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 (phi1 <= -100000000.0) {
		tmp = R * Math.hypot((lambda1 * Math.cos((0.5 * phi1))), (phi1 - phi2));
	} else if (phi1 <= -5.2e-42) {
		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 phi1 <= -100000000.0:
		tmp = R * math.hypot((lambda1 * math.cos((0.5 * phi1))), (phi1 - phi2))
	elif phi1 <= -5.2e-42:
		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 (phi1 <= -100000000.0)
		tmp = Float64(R * hypot(Float64(lambda1 * cos(Float64(0.5 * phi1))), Float64(phi1 - phi2)));
	elseif (phi1 <= -5.2e-42)
		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 (phi1 <= -100000000.0)
		tmp = R * hypot((lambda1 * cos((0.5 * phi1))), (phi1 - phi2));
	elseif (phi1 <= -5.2e-42)
		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[phi1, -100000000.0], N[(R * N[Sqrt[N[(lambda1 * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, -5.2e-42], 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_1 \leq -100000000:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right), \phi_1 - \phi_2\right)\\

\mathbf{elif}\;\phi_1 \leq -5.2 \cdot 10^{-42}:\\
\;\;\;\;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 3 regimes
  2. if phi1 < -1e8

    1. Initial program 52.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-define94.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. Simplified94.4%

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

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

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

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

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

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

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

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

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

    if -1e8 < phi1 < -5.2e-42

    1. Initial program 51.9%

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

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

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

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

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

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

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

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

    if -5.2e-42 < phi1

    1. Initial program 56.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -100000000:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right), \phi_1 - \phi_2\right)\\ \mathbf{elif}\;\phi_1 \leq -5.2 \cdot 10^{-42}:\\ \;\;\;\;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} \]
  5. Add Preprocessing

Alternative 12: 96.1% accurate, 1.5× speedup?

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

\\
R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_2 + \phi_1}{2}\right), \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 55.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-define95.9%

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

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

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

Alternative 13: 70.3% accurate, 3.0× speedup?

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

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

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


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

    1. Initial program 58.4%

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

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

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

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

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

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

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

    if 2.5e20 < phi2

    1. Initial program 44.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-define88.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. Simplified88.4%

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

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

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

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

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

Alternative 14: 57.4% accurate, 3.0× speedup?

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

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

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


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

    1. Initial program 58.4%

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

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

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

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

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

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

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

        \[\leadsto R \cdot \sqrt{\left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right) + \color{blue}{\left(-1 \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right) + 0.5 \cdot \left(\lambda_2 \cdot \left(\phi_1 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right) \cdot \left(-1 \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right) + 0.5 \cdot \left(\lambda_2 \cdot \left(\phi_1 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right)}} \]
      4. hypot-define70.0%

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

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

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

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

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

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

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

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

        \[\leadsto R \cdot \sqrt{\lambda_2 \cdot \lambda_2 + \color{blue}{\phi_1 \cdot \phi_1}} \]
      3. hypot-define57.7%

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

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

    if 8.6e15 < phi2

    1. Initial program 44.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-define88.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. Simplified88.4%

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

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

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

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

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

Alternative 15: 30.5% accurate, 23.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi1 < -1.32000000000000004e-20

    1. Initial program 51.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-define95.0%

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

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

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

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

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

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

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

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

    if -1.32000000000000004e-20 < phi1

    1. Initial program 56.8%

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

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

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

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

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

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

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

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

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

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

Alternative 16: 30.4% accurate, 23.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi1 < -1.45000000000000004e108

    1. Initial program 50.3%

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

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

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

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

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

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

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

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

    if -1.45000000000000004e108 < phi1

    1. Initial program 56.6%

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

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

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

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

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

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

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

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

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

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

Alternative 17: 29.8% accurate, 23.5× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

    if 1.2e-123 < phi2

    1. Initial program 52.0%

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

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

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

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

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

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

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

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

Alternative 18: 27.4% accurate, 36.5× speedup?

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

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

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


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

    1. Initial program 57.6%

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

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

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

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

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

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

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

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

    if 5.70000000000000021e88 < phi2

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

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

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

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

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

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

Alternative 19: 16.7% accurate, 109.7× speedup?

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

\\
R \cdot \phi_2
\end{array}
Derivation
  1. Initial program 55.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-define95.9%

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

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

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

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

    \[\leadsto \color{blue}{\phi_2 \cdot R} \]
  8. Final simplification16.0%

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

Alternative 20: 13.7% 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 55.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-define95.9%

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\lambda_1} \cdot R \]
  12. Final simplification12.8%

    \[\leadsto R \cdot \lambda_1 \]
  13. Add Preprocessing

Reproduce

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