Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.1% → 99.9%
Time: 18.5s
Alternatives: 11
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 11 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.1% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 0.5× speedup?

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

\\
R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(0 - \sin \left(0.5 \cdot \phi_2\right), \sin \left(0.5 \cdot \phi_1\right), \cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 58.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. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
    2. hypot-defineN/A

      \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
    3. hypot-lowering-hypot.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
    5. --lowering--.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    6. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    7. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    8. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    9. --lowering--.f6497.4%

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
  3. Simplified97.4%

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
    2. flip--N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \frac{\lambda_1 \cdot \lambda_1 - \lambda_2 \cdot \lambda_2}{\lambda_1 + \lambda_2}\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    3. clear-numN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \frac{1}{\frac{\lambda_1 + \lambda_2}{\lambda_1 \cdot \lambda_1 - \lambda_2 \cdot \lambda_2}}\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    4. un-div-invN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\frac{\cos \left(\frac{\phi_1 + \phi_2}{2}\right)}{\frac{\lambda_1 + \lambda_2}{\lambda_1 \cdot \lambda_1 - \lambda_2 \cdot \lambda_2}}\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
    5. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right), \left(\frac{\lambda_1 + \lambda_2}{\lambda_1 \cdot \lambda_1 - \lambda_2 \cdot \lambda_2}\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
    6. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\frac{\lambda_1 + \lambda_2}{\lambda_1 \cdot \lambda_1 - \lambda_2 \cdot \lambda_2}\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right), \left(\frac{\lambda_1 + \lambda_2}{\lambda_1 \cdot \lambda_1 - \lambda_2 \cdot \lambda_2}\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    8. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right), \left(\frac{\lambda_1 + \lambda_2}{\lambda_1 \cdot \lambda_1 - \lambda_2 \cdot \lambda_2}\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    9. clear-numN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right), \left(\frac{1}{\frac{\lambda_1 \cdot \lambda_1 - \lambda_2 \cdot \lambda_2}{\lambda_1 + \lambda_2}}\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    10. flip--N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right), \left(\frac{1}{\lambda_1 - \lambda_2}\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    11. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right), \mathsf{/.f64}\left(1, \left(\lambda_1 - \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    12. --lowering--.f6497.3%

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
  6. Applied egg-rr97.3%

    \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\frac{\cos \left(\frac{\phi_1 + \phi_2}{2}\right)}{\frac{1}{\lambda_1 - \lambda_2}}}, \phi_1 - \phi_2\right) \]
  7. Step-by-step derivation
    1. clear-numN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\frac{1}{\frac{2}{\phi_1 + \phi_2}}\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    2. associate-/r/N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    3. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    4. distribute-lft-inN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\frac{1}{2} \cdot \phi_1 + \frac{1}{2} \cdot \phi_2\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    5. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\frac{1}{2} \cdot \phi_1 + \frac{1}{2} \cdot \phi_2\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. associate-/r/N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\frac{1}{2} \cdot \phi_1 + \frac{1}{\frac{2}{\phi_2}}\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. clear-numN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\frac{1}{2} \cdot \phi_1 + \frac{\phi_2}{2}\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    8. cos-sumN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    9. prod-diffN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\left(\mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot \phi_1\right), \cos \left(\frac{\phi_2}{2}\right), \mathsf{neg}\left(\sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right) + \mathsf{fma}\left(\mathsf{neg}\left(\sin \left(\frac{\phi_2}{2}\right)\right), \sin \left(\frac{1}{2} \cdot \phi_1\right), \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    10. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\left(\mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot \phi_1\right), \cos \left(\frac{\phi_2}{2}\right), \mathsf{neg}\left(\sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)\right), \left(\mathsf{fma}\left(\mathsf{neg}\left(\sin \left(\frac{\phi_2}{2}\right)\right), \sin \left(\frac{1}{2} \cdot \phi_1\right), \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
  8. Applied egg-rr99.8%

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

    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\left(-1 \cdot \left(\sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right) + \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
  10. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(-1 \cdot \left(\sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right) + \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \left(\lambda_1 - \lambda_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
  11. Simplified99.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 \left(\lambda_1 - \lambda_2\right)}, \phi_1 - \phi_2\right) \]
  12. Step-by-step derivation
    1. sub-negN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right) + \left(\mathsf{neg}\left(\sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)\right), \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    2. +-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\left(\mathsf{neg}\left(\sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right) + \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    3. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\left(\mathsf{neg}\left(\sin \left(\frac{1}{2} \cdot \phi_2\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right) + \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    4. distribute-lft-neg-inN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\left(\mathsf{neg}\left(\sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right) + \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    5. fma-defineN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\mathsf{fma}\left(\mathsf{neg}\left(\sin \left(\frac{1}{2} \cdot \phi_2\right)\right), \sin \left(\frac{1}{2} \cdot \phi_1\right), \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. fma-lowering-fma.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{fma.f64}\left(\left(\mathsf{neg}\left(\sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \sin \left(\frac{1}{2} \cdot \phi_1\right), \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. neg-sub0N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{fma.f64}\left(\left(0 - \sin \left(\frac{1}{2} \cdot \phi_2\right)\right), \sin \left(\frac{1}{2} \cdot \phi_1\right), \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    8. --lowering--.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{fma.f64}\left(\mathsf{\_.f64}\left(0, \sin \left(\frac{1}{2} \cdot \phi_2\right)\right), \sin \left(\frac{1}{2} \cdot \phi_1\right), \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    9. sin-lowering-sin.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{fma.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{sin.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \sin \left(\frac{1}{2} \cdot \phi_1\right), \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    10. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{fma.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{sin.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right), \sin \left(\frac{1}{2} \cdot \phi_1\right), \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    11. sin-lowering-sin.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{fma.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{sin.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{sin.f64}\left(\left(\frac{1}{2} \cdot \phi_1\right)\right), \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    12. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{fma.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{sin.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{sin.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right), \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    13. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{fma.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{sin.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{sin.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right), \mathsf{*.f64}\left(\cos \left(\frac{1}{2} \cdot \phi_1\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    14. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{fma.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{sin.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{sin.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_1\right)\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    15. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{fma.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{sin.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{sin.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    16. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{fma.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{sin.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{sin.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right)\right)\right), \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    17. *-lowering-*.f6499.9%

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{fma.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{sin.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{sin.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right)\right), \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
  13. Applied egg-rr99.9%

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

Alternative 2: 99.9% accurate, 0.6× speedup?

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

\\
R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right), \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 58.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. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
    2. hypot-defineN/A

      \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
    3. hypot-lowering-hypot.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
    5. --lowering--.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    6. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    7. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    8. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    9. --lowering--.f6497.4%

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
  3. Simplified97.4%

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
    2. flip--N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \frac{\lambda_1 \cdot \lambda_1 - \lambda_2 \cdot \lambda_2}{\lambda_1 + \lambda_2}\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    3. clear-numN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \frac{1}{\frac{\lambda_1 + \lambda_2}{\lambda_1 \cdot \lambda_1 - \lambda_2 \cdot \lambda_2}}\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    4. un-div-invN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\frac{\cos \left(\frac{\phi_1 + \phi_2}{2}\right)}{\frac{\lambda_1 + \lambda_2}{\lambda_1 \cdot \lambda_1 - \lambda_2 \cdot \lambda_2}}\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
    5. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right), \left(\frac{\lambda_1 + \lambda_2}{\lambda_1 \cdot \lambda_1 - \lambda_2 \cdot \lambda_2}\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
    6. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\frac{\lambda_1 + \lambda_2}{\lambda_1 \cdot \lambda_1 - \lambda_2 \cdot \lambda_2}\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right), \left(\frac{\lambda_1 + \lambda_2}{\lambda_1 \cdot \lambda_1 - \lambda_2 \cdot \lambda_2}\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    8. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right), \left(\frac{\lambda_1 + \lambda_2}{\lambda_1 \cdot \lambda_1 - \lambda_2 \cdot \lambda_2}\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    9. clear-numN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right), \left(\frac{1}{\frac{\lambda_1 \cdot \lambda_1 - \lambda_2 \cdot \lambda_2}{\lambda_1 + \lambda_2}}\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    10. flip--N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right), \left(\frac{1}{\lambda_1 - \lambda_2}\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    11. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right), \mathsf{/.f64}\left(1, \left(\lambda_1 - \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    12. --lowering--.f6497.3%

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
  6. Applied egg-rr97.3%

    \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\frac{\cos \left(\frac{\phi_1 + \phi_2}{2}\right)}{\frac{1}{\lambda_1 - \lambda_2}}}, \phi_1 - \phi_2\right) \]
  7. Step-by-step derivation
    1. clear-numN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\frac{1}{\frac{2}{\phi_1 + \phi_2}}\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    2. associate-/r/N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    3. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    4. distribute-lft-inN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\frac{1}{2} \cdot \phi_1 + \frac{1}{2} \cdot \phi_2\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    5. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\frac{1}{2} \cdot \phi_1 + \frac{1}{2} \cdot \phi_2\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. associate-/r/N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\frac{1}{2} \cdot \phi_1 + \frac{1}{\frac{2}{\phi_2}}\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. clear-numN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\frac{1}{2} \cdot \phi_1 + \frac{\phi_2}{2}\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    8. cos-sumN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    9. prod-diffN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\left(\mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot \phi_1\right), \cos \left(\frac{\phi_2}{2}\right), \mathsf{neg}\left(\sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right) + \mathsf{fma}\left(\mathsf{neg}\left(\sin \left(\frac{\phi_2}{2}\right)\right), \sin \left(\frac{1}{2} \cdot \phi_1\right), \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    10. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\left(\mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot \phi_1\right), \cos \left(\frac{\phi_2}{2}\right), \mathsf{neg}\left(\sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)\right), \left(\mathsf{fma}\left(\mathsf{neg}\left(\sin \left(\frac{\phi_2}{2}\right)\right), \sin \left(\frac{1}{2} \cdot \phi_1\right), \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)\right), \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
  8. Applied egg-rr99.8%

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

    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\left(-1 \cdot \left(\sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right) + \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
  10. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(-1 \cdot \left(\sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right) + \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \left(\lambda_1 - \lambda_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
  11. Simplified99.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 \left(\lambda_1 - \lambda_2\right)}, \phi_1 - \phi_2\right) \]
  12. Final simplification99.9%

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

Alternative 3: 92.7% accurate, 1.5× speedup?

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

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

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


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

    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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
      2. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
      3. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      9. --lowering--.f6498.2%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
    3. Simplified98.2%

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\color{blue}{\phi_1}, 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. Step-by-step derivation
      1. Simplified94.2%

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

      if 9.99999999999999961e-81 < phi2

      1. Initial program 53.3%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Step-by-step derivation
        1. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
        2. hypot-defineN/A

          \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
        3. hypot-lowering-hypot.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
        4. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
        5. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
        6. cos-lowering-cos.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
        7. /-lowering-/.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
        8. +-lowering-+.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
        9. --lowering--.f6495.0%

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

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

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\color{blue}{\phi_2}, 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      6. Step-by-step derivation
        1. Simplified95.3%

          \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\color{blue}{\phi_2}}{2}\right), \phi_1 - \phi_2\right) \]
      7. Recombined 2 regimes into one program.
      8. Add Preprocessing

      Alternative 4: 95.9% 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 58.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. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
        2. hypot-defineN/A

          \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
        3. hypot-lowering-hypot.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
        4. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
        5. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
        6. cos-lowering-cos.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
        7. /-lowering-/.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
        8. +-lowering-+.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
        9. --lowering--.f6497.4%

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
      3. Simplified97.4%

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

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

      \[\begin{array}{l} \\ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1}{2}\right), \phi_1 - \phi_2\right) \end{array} \]
      (FPCore (R lambda1 lambda2 phi1 phi2)
       :precision binary64
       (* R (hypot (* (- lambda1 lambda2) (cos (/ phi1 2.0))) (- phi1 phi2))))
      double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	return R * hypot(((lambda1 - lambda2) * cos((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((phi1 / 2.0))), (phi1 - phi2));
      }
      
      def code(R, lambda1, lambda2, phi1, phi2):
      	return R * math.hypot(((lambda1 - lambda2) * math.cos((phi1 / 2.0))), (phi1 - phi2))
      
      function code(R, lambda1, lambda2, phi1, phi2)
      	return Float64(R * hypot(Float64(Float64(lambda1 - lambda2) * cos(Float64(phi1 / 2.0))), Float64(phi1 - phi2)))
      end
      
      function tmp = code(R, lambda1, lambda2, phi1, phi2)
      	tmp = R * hypot(((lambda1 - lambda2) * cos((phi1 / 2.0))), (phi1 - phi2));
      end
      
      code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[Sqrt[N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(phi1 / 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_1}{2}\right), \phi_1 - \phi_2\right)
      \end{array}
      
      Derivation
      1. Initial program 58.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. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
        2. hypot-defineN/A

          \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
        3. hypot-lowering-hypot.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
        4. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
        5. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
        6. cos-lowering-cos.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
        7. /-lowering-/.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
        8. +-lowering-+.f64N/A

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
        9. --lowering--.f6497.4%

          \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
      3. Simplified97.4%

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

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\color{blue}{\phi_1}, 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      6. Step-by-step derivation
        1. Simplified92.7%

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

        Alternative 6: 69.9% accurate, 2.8× speedup?

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

          1. Initial program 58.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. *-lowering-*.f64N/A

              \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
            2. hypot-defineN/A

              \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
            3. hypot-lowering-hypot.f64N/A

              \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
            4. *-lowering-*.f64N/A

              \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
            5. --lowering--.f64N/A

              \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
            6. cos-lowering-cos.f64N/A

              \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
            7. /-lowering-/.f64N/A

              \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
            8. +-lowering-+.f64N/A

              \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
            9. --lowering--.f6498.3%

              \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\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 phi1 around 0

            \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\color{blue}{\phi_2}, 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
          6. Step-by-step derivation
            1. Simplified91.5%

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

              \[\leadsto \color{blue}{R \cdot \sqrt{{\phi_1}^{2} + {\left(\lambda_1 - \lambda_2\right)}^{2}}} \]
            3. Step-by-step derivation
              1. *-lowering-*.f64N/A

                \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\sqrt{{\phi_1}^{2} + {\left(\lambda_1 - \lambda_2\right)}^{2}}\right)}\right) \]
              2. unpow2N/A

                \[\leadsto \mathsf{*.f64}\left(R, \left(\sqrt{\phi_1 \cdot \phi_1 + {\left(\lambda_1 - \lambda_2\right)}^{2}}\right)\right) \]
              3. unpow2N/A

                \[\leadsto \mathsf{*.f64}\left(R, \left(\sqrt{\phi_1 \cdot \phi_1 + \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)}\right)\right) \]
              4. hypot-defineN/A

                \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_1 - \lambda_2}\right)\right)\right) \]
              5. hypot-lowering-hypot.f64N/A

                \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right)}\right)\right) \]
              6. --lowering--.f6475.8%

                \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\phi_1, \mathsf{\_.f64}\left(\lambda_1, \color{blue}{\lambda_2}\right)\right)\right) \]
            4. Simplified75.8%

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

            if 1.50000000000000003e-17 < phi2 < 2.39999999999999987e109

            1. Initial program 57.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. *-lowering-*.f64N/A

                \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
              2. hypot-defineN/A

                \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
              3. hypot-lowering-hypot.f64N/A

                \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
              4. *-lowering-*.f64N/A

                \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
              5. --lowering--.f64N/A

                \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
              6. cos-lowering-cos.f64N/A

                \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
              7. /-lowering-/.f64N/A

                \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
              8. +-lowering-+.f64N/A

                \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
              9. --lowering--.f6488.8%

                \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
            3. Simplified88.8%

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

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

                \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right) \]
              2. neg-sub0N/A

                \[\leadsto 0 - \color{blue}{\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
              3. --lowering--.f64N/A

                \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)}\right) \]
              4. *-lowering-*.f64N/A

                \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)}\right)\right) \]
              5. mul-1-negN/A

                \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \left(R + \left(\mathsf{neg}\left(\frac{R \cdot \phi_2}{\phi_1}\right)\right)\right)\right)\right) \]
              6. unsub-negN/A

                \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \left(R - \color{blue}{\frac{R \cdot \phi_2}{\phi_1}}\right)\right)\right) \]
              7. --lowering--.f64N/A

                \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \mathsf{\_.f64}\left(R, \color{blue}{\left(\frac{R \cdot \phi_2}{\phi_1}\right)}\right)\right)\right) \]
              8. associate-/l*N/A

                \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \mathsf{\_.f64}\left(R, \left(R \cdot \color{blue}{\frac{\phi_2}{\phi_1}}\right)\right)\right)\right) \]
              9. *-lowering-*.f64N/A

                \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \mathsf{\_.f64}\left(R, \mathsf{*.f64}\left(R, \color{blue}{\left(\frac{\phi_2}{\phi_1}\right)}\right)\right)\right)\right) \]
              10. /-lowering-/.f6447.6%

                \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \mathsf{\_.f64}\left(R, \mathsf{*.f64}\left(R, \mathsf{/.f64}\left(\phi_2, \color{blue}{\phi_1}\right)\right)\right)\right)\right) \]
            7. Simplified47.6%

              \[\leadsto \color{blue}{0 - \phi_1 \cdot \left(R - R \cdot \frac{\phi_2}{\phi_1}\right)} \]
            8. Step-by-step derivation
              1. cancel-sign-sub-invN/A

                \[\leadsto 0 + \color{blue}{\left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \left(R - R \cdot \frac{\phi_2}{\phi_1}\right)} \]
              2. +-lft-identityN/A

                \[\leadsto \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \color{blue}{\left(R - R \cdot \frac{\phi_2}{\phi_1}\right)} \]
              3. flip--N/A

                \[\leadsto \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \frac{R \cdot R - \left(R \cdot \frac{\phi_2}{\phi_1}\right) \cdot \left(R \cdot \frac{\phi_2}{\phi_1}\right)}{\color{blue}{R + R \cdot \frac{\phi_2}{\phi_1}}} \]
              4. associate-*r/N/A

                \[\leadsto \frac{\left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \left(R \cdot R - \left(R \cdot \frac{\phi_2}{\phi_1}\right) \cdot \left(R \cdot \frac{\phi_2}{\phi_1}\right)\right)}{\color{blue}{R + R \cdot \frac{\phi_2}{\phi_1}}} \]
              5. /-lowering-/.f64N/A

                \[\leadsto \mathsf{/.f64}\left(\left(\left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \left(R \cdot R - \left(R \cdot \frac{\phi_2}{\phi_1}\right) \cdot \left(R \cdot \frac{\phi_2}{\phi_1}\right)\right)\right), \color{blue}{\left(R + R \cdot \frac{\phi_2}{\phi_1}\right)}\right) \]
            9. Applied egg-rr34.3%

              \[\leadsto \color{blue}{\frac{\left(0 - \phi_1\right) \cdot \left(\left(\left(\frac{\phi_2}{\phi_1} + 1\right) \cdot R\right) \cdot \left(R - \frac{R \cdot \phi_2}{\phi_1}\right)\right)}{\left(\frac{\phi_2}{\phi_1} + 1\right) \cdot R}} \]
            10. Taylor expanded in phi1 around inf

              \[\leadsto \mathsf{/.f64}\left(\color{blue}{\left(-1 \cdot \left({R}^{2} \cdot \phi_1\right)\right)}, \mathsf{*.f64}\left(\mathsf{+.f64}\left(\mathsf{/.f64}\left(\phi_2, \phi_1\right), 1\right), R\right)\right) \]
            11. Step-by-step derivation
              1. mul-1-negN/A

                \[\leadsto \mathsf{/.f64}\left(\left(\mathsf{neg}\left({R}^{2} \cdot \phi_1\right)\right), \mathsf{*.f64}\left(\color{blue}{\mathsf{+.f64}\left(\mathsf{/.f64}\left(\phi_2, \phi_1\right), 1\right)}, R\right)\right) \]
              2. neg-sub0N/A

                \[\leadsto \mathsf{/.f64}\left(\left(0 - {R}^{2} \cdot \phi_1\right), \mathsf{*.f64}\left(\color{blue}{\mathsf{+.f64}\left(\mathsf{/.f64}\left(\phi_2, \phi_1\right), 1\right)}, R\right)\right) \]
              3. --lowering--.f64N/A

                \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(0, \left({R}^{2} \cdot \phi_1\right)\right), \mathsf{*.f64}\left(\color{blue}{\mathsf{+.f64}\left(\mathsf{/.f64}\left(\phi_2, \phi_1\right), 1\right)}, R\right)\right) \]
              4. *-commutativeN/A

                \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(0, \left(\phi_1 \cdot {R}^{2}\right)\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(\mathsf{/.f64}\left(\phi_2, \phi_1\right), \color{blue}{1}\right), R\right)\right) \]
              5. *-lowering-*.f64N/A

                \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \left({R}^{2}\right)\right)\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(\mathsf{/.f64}\left(\phi_2, \phi_1\right), \color{blue}{1}\right), R\right)\right) \]
              6. unpow2N/A

                \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \left(R \cdot R\right)\right)\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(\mathsf{/.f64}\left(\phi_2, \phi_1\right), 1\right), R\right)\right) \]
              7. *-lowering-*.f6416.0%

                \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \mathsf{*.f64}\left(R, R\right)\right)\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(\mathsf{/.f64}\left(\phi_2, \phi_1\right), 1\right), R\right)\right) \]
            12. Simplified16.0%

              \[\leadsto \frac{\color{blue}{0 - \phi_1 \cdot \left(R \cdot R\right)}}{\left(\frac{\phi_2}{\phi_1} + 1\right) \cdot R} \]
            13. Taylor expanded in phi1 around inf

              \[\leadsto \color{blue}{\phi_1 \cdot \left(-1 \cdot R + \frac{R \cdot \phi_2}{\phi_1}\right)} \]
            14. Step-by-step derivation
              1. *-lowering-*.f64N/A

                \[\leadsto \mathsf{*.f64}\left(\phi_1, \color{blue}{\left(-1 \cdot R + \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
              2. +-commutativeN/A

                \[\leadsto \mathsf{*.f64}\left(\phi_1, \left(\frac{R \cdot \phi_2}{\phi_1} + \color{blue}{-1 \cdot R}\right)\right) \]
              3. associate-/l*N/A

                \[\leadsto \mathsf{*.f64}\left(\phi_1, \left(R \cdot \frac{\phi_2}{\phi_1} + \color{blue}{-1} \cdot R\right)\right) \]
              4. *-commutativeN/A

                \[\leadsto \mathsf{*.f64}\left(\phi_1, \left(R \cdot \frac{\phi_2}{\phi_1} + R \cdot \color{blue}{-1}\right)\right) \]
              5. distribute-lft-outN/A

                \[\leadsto \mathsf{*.f64}\left(\phi_1, \left(R \cdot \color{blue}{\left(\frac{\phi_2}{\phi_1} + -1\right)}\right)\right) \]
              6. *-lowering-*.f64N/A

                \[\leadsto \mathsf{*.f64}\left(\phi_1, \mathsf{*.f64}\left(R, \color{blue}{\left(\frac{\phi_2}{\phi_1} + -1\right)}\right)\right) \]
              7. +-lowering-+.f64N/A

                \[\leadsto \mathsf{*.f64}\left(\phi_1, \mathsf{*.f64}\left(R, \mathsf{+.f64}\left(\left(\frac{\phi_2}{\phi_1}\right), \color{blue}{-1}\right)\right)\right) \]
              8. /-lowering-/.f6447.6%

                \[\leadsto \mathsf{*.f64}\left(\phi_1, \mathsf{*.f64}\left(R, \mathsf{+.f64}\left(\mathsf{/.f64}\left(\phi_2, \phi_1\right), -1\right)\right)\right) \]
            15. Simplified47.6%

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

            if 2.39999999999999987e109 < phi2

            1. Initial program 55.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. *-lowering-*.f64N/A

                \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
              2. hypot-defineN/A

                \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
              3. hypot-lowering-hypot.f64N/A

                \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
              4. *-lowering-*.f64N/A

                \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
              5. --lowering--.f64N/A

                \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
              6. cos-lowering-cos.f64N/A

                \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
              7. /-lowering-/.f64N/A

                \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
              8. +-lowering-+.f64N/A

                \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
              9. --lowering--.f6497.7%

                \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
            3. Simplified97.7%

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

              \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\color{blue}{\phi_1}, 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
            6. Step-by-step derivation
              1. Simplified93.3%

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

                \[\leadsto \color{blue}{R \cdot \sqrt{{\phi_2}^{2} + {\left(\lambda_1 - \lambda_2\right)}^{2}}} \]
              3. Step-by-step derivation
                1. *-lowering-*.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\sqrt{{\phi_2}^{2} + {\left(\lambda_1 - \lambda_2\right)}^{2}}\right)}\right) \]
                2. unpow2N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \left(\sqrt{\phi_2 \cdot \phi_2 + {\left(\lambda_1 - \lambda_2\right)}^{2}}\right)\right) \]
                3. unpow2N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \left(\sqrt{\phi_2 \cdot \phi_2 + \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)}\right)\right) \]
                4. hypot-defineN/A

                  \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\phi_2, \color{blue}{\lambda_1 - \lambda_2}\right)\right)\right) \]
                5. hypot-lowering-hypot.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\phi_2, \color{blue}{\left(\lambda_1 - \lambda_2\right)}\right)\right) \]
                6. --lowering--.f6493.2%

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\phi_2, \mathsf{\_.f64}\left(\lambda_1, \color{blue}{\lambda_2}\right)\right)\right) \]
              4. Simplified93.2%

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

            Alternative 7: 70.9% accurate, 3.0× speedup?

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

              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. *-lowering-*.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
                2. hypot-defineN/A

                  \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
                3. hypot-lowering-hypot.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
                4. *-lowering-*.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
                5. --lowering--.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                6. cos-lowering-cos.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                7. /-lowering-/.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                8. +-lowering-+.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                9. --lowering--.f6498.0%

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\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

                \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\color{blue}{\phi_2}, 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
              6. Step-by-step derivation
                1. Simplified91.6%

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

                  \[\leadsto \color{blue}{R \cdot \sqrt{{\phi_1}^{2} + {\left(\lambda_1 - \lambda_2\right)}^{2}}} \]
                3. Step-by-step derivation
                  1. *-lowering-*.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\sqrt{{\phi_1}^{2} + {\left(\lambda_1 - \lambda_2\right)}^{2}}\right)}\right) \]
                  2. unpow2N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \left(\sqrt{\phi_1 \cdot \phi_1 + {\left(\lambda_1 - \lambda_2\right)}^{2}}\right)\right) \]
                  3. unpow2N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \left(\sqrt{\phi_1 \cdot \phi_1 + \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)}\right)\right) \]
                  4. hypot-defineN/A

                    \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_1 - \lambda_2}\right)\right)\right) \]
                  5. hypot-lowering-hypot.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right)}\right)\right) \]
                  6. --lowering--.f6475.1%

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\phi_1, \mathsf{\_.f64}\left(\lambda_1, \color{blue}{\lambda_2}\right)\right)\right) \]
                4. Simplified75.1%

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

                if 4.8000000000000002e48 < phi2

                1. Initial program 60.0%

                  \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
                2. Step-by-step derivation
                  1. *-lowering-*.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
                  2. hypot-defineN/A

                    \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
                  3. hypot-lowering-hypot.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
                  4. *-lowering-*.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
                  5. --lowering--.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                  6. cos-lowering-cos.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                  7. /-lowering-/.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                  8. +-lowering-+.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                  9. --lowering--.f6494.6%

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
                3. Simplified94.6%

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

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

                    \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right) \]
                  2. neg-sub0N/A

                    \[\leadsto 0 - \color{blue}{\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                  3. --lowering--.f64N/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)}\right) \]
                  4. *-lowering-*.f64N/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)}\right)\right) \]
                  5. mul-1-negN/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \left(R + \left(\mathsf{neg}\left(\frac{R \cdot \phi_2}{\phi_1}\right)\right)\right)\right)\right) \]
                  6. unsub-negN/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \left(R - \color{blue}{\frac{R \cdot \phi_2}{\phi_1}}\right)\right)\right) \]
                  7. --lowering--.f64N/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \mathsf{\_.f64}\left(R, \color{blue}{\left(\frac{R \cdot \phi_2}{\phi_1}\right)}\right)\right)\right) \]
                  8. associate-/l*N/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \mathsf{\_.f64}\left(R, \left(R \cdot \color{blue}{\frac{\phi_2}{\phi_1}}\right)\right)\right)\right) \]
                  9. *-lowering-*.f64N/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \mathsf{\_.f64}\left(R, \mathsf{*.f64}\left(R, \color{blue}{\left(\frac{\phi_2}{\phi_1}\right)}\right)\right)\right)\right) \]
                  10. /-lowering-/.f6468.5%

                    \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \mathsf{\_.f64}\left(R, \mathsf{*.f64}\left(R, \mathsf{/.f64}\left(\phi_2, \color{blue}{\phi_1}\right)\right)\right)\right)\right) \]
                7. Simplified68.5%

                  \[\leadsto \color{blue}{0 - \phi_1 \cdot \left(R - R \cdot \frac{\phi_2}{\phi_1}\right)} \]
                8. Taylor expanded in phi2 around 0

                  \[\leadsto \color{blue}{R \cdot \phi_2 - R \cdot \phi_1} \]
                9. Step-by-step derivation
                  1. distribute-lft-out--N/A

                    \[\leadsto R \cdot \color{blue}{\left(\phi_2 - \phi_1\right)} \]
                  2. *-lowering-*.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\phi_2 - \phi_1\right)}\right) \]
                  3. --lowering--.f6475.0%

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{\_.f64}\left(\phi_2, \color{blue}{\phi_1}\right)\right) \]
                10. Simplified75.0%

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

              Alternative 8: 34.4% accurate, 32.8× speedup?

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

                1. Initial program 50.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. *-lowering-*.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
                  2. hypot-defineN/A

                    \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
                  3. hypot-lowering-hypot.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
                  4. *-lowering-*.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
                  5. --lowering--.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                  6. cos-lowering-cos.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                  7. /-lowering-/.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                  8. +-lowering-+.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                  9. --lowering--.f6491.0%

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
                3. Simplified91.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 lambda1 around -inf

                  \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(-1 \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}\right) \]
                6. Step-by-step derivation
                  1. mul-1-negN/A

                    \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{neg}\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)\right) \]
                  2. *-commutativeN/A

                    \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{neg}\left(\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \lambda_1\right)\right)\right) \]
                  3. distribute-rgt-neg-inN/A

                    \[\leadsto \mathsf{*.f64}\left(R, \left(\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \]
                  4. mul-1-negN/A

                    \[\leadsto \mathsf{*.f64}\left(R, \left(\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \left(-1 \cdot \color{blue}{\lambda_1}\right)\right)\right) \]
                  5. *-lowering-*.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right), \color{blue}{\left(-1 \cdot \lambda_1\right)}\right)\right) \]
                  6. cos-lowering-cos.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right), \left(\color{blue}{-1} \cdot \lambda_1\right)\right)\right) \]
                  7. *-lowering-*.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(\phi_1 + \phi_2\right)\right)\right), \left(-1 \cdot \lambda_1\right)\right)\right) \]
                  8. +-lowering-+.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{+.f64}\left(\phi_1, \phi_2\right)\right)\right), \left(-1 \cdot \lambda_1\right)\right)\right) \]
                  9. mul-1-negN/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{+.f64}\left(\phi_1, \phi_2\right)\right)\right), \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) \]
                  10. neg-lowering-neg.f6444.2%

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{+.f64}\left(\phi_1, \phi_2\right)\right)\right), \mathsf{neg.f64}\left(\lambda_1\right)\right)\right) \]
                7. Simplified44.2%

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

                  \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)} \]
                9. Step-by-step derivation
                  1. mul-1-negN/A

                    \[\leadsto \mathsf{neg}\left(R \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)\right) \]
                  2. neg-sub0N/A

                    \[\leadsto 0 - \color{blue}{R \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)} \]
                  3. --lowering--.f64N/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left(R \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)}\right) \]
                  4. associate-*r*N/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \left(\left(R \cdot \lambda_1\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)}\right)\right) \]
                  5. *-lowering-*.f64N/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\left(R \cdot \lambda_1\right), \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)}\right)\right) \]
                  6. *-lowering-*.f64N/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_1\right), \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_1\right)}\right)\right) \]
                  7. cos-lowering-cos.f64N/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_1\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_1\right)\right)\right)\right) \]
                  8. *-lowering-*.f6456.7%

                    \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_1\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right)\right)\right) \]
                10. Simplified56.7%

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

                  \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \lambda_1\right)} \]
                12. Step-by-step derivation
                  1. mul-1-negN/A

                    \[\leadsto \mathsf{neg}\left(R \cdot \lambda_1\right) \]
                  2. neg-sub0N/A

                    \[\leadsto 0 - \color{blue}{R \cdot \lambda_1} \]
                  3. --lowering--.f64N/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left(R \cdot \lambda_1\right)}\right) \]
                  4. *-lowering-*.f6463.8%

                    \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(R, \color{blue}{\lambda_1}\right)\right) \]
                13. Simplified63.8%

                  \[\leadsto \color{blue}{0 - R \cdot \lambda_1} \]

                if -3.1e140 < lambda1

                1. Initial program 59.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. *-lowering-*.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
                  2. hypot-defineN/A

                    \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
                  3. hypot-lowering-hypot.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
                  4. *-lowering-*.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
                  5. --lowering--.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                  6. cos-lowering-cos.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                  7. /-lowering-/.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                  8. +-lowering-+.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                  9. --lowering--.f6498.4%

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
                3. Simplified98.4%

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

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

                    \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right) \]
                  2. neg-sub0N/A

                    \[\leadsto 0 - \color{blue}{\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                  3. --lowering--.f64N/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)}\right) \]
                  4. *-lowering-*.f64N/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)}\right)\right) \]
                  5. mul-1-negN/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \left(R + \left(\mathsf{neg}\left(\frac{R \cdot \phi_2}{\phi_1}\right)\right)\right)\right)\right) \]
                  6. unsub-negN/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \left(R - \color{blue}{\frac{R \cdot \phi_2}{\phi_1}}\right)\right)\right) \]
                  7. --lowering--.f64N/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \mathsf{\_.f64}\left(R, \color{blue}{\left(\frac{R \cdot \phi_2}{\phi_1}\right)}\right)\right)\right) \]
                  8. associate-/l*N/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \mathsf{\_.f64}\left(R, \left(R \cdot \color{blue}{\frac{\phi_2}{\phi_1}}\right)\right)\right)\right) \]
                  9. *-lowering-*.f64N/A

                    \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \mathsf{\_.f64}\left(R, \mathsf{*.f64}\left(R, \color{blue}{\left(\frac{\phi_2}{\phi_1}\right)}\right)\right)\right)\right) \]
                  10. /-lowering-/.f6428.6%

                    \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \mathsf{\_.f64}\left(R, \mathsf{*.f64}\left(R, \mathsf{/.f64}\left(\phi_2, \color{blue}{\phi_1}\right)\right)\right)\right)\right) \]
                7. Simplified28.6%

                  \[\leadsto \color{blue}{0 - \phi_1 \cdot \left(R - R \cdot \frac{\phi_2}{\phi_1}\right)} \]
                8. Taylor expanded in phi2 around 0

                  \[\leadsto \color{blue}{R \cdot \phi_2 - R \cdot \phi_1} \]
                9. Step-by-step derivation
                  1. distribute-lft-out--N/A

                    \[\leadsto R \cdot \color{blue}{\left(\phi_2 - \phi_1\right)} \]
                  2. *-lowering-*.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\phi_2 - \phi_1\right)}\right) \]
                  3. --lowering--.f6429.6%

                    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{\_.f64}\left(\phi_2, \color{blue}{\phi_1}\right)\right) \]
                10. Simplified29.6%

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

              Alternative 9: 29.3% accurate, 65.8× speedup?

              \[\begin{array}{l} \\ R \cdot \left(\phi_2 - \phi_1\right) \end{array} \]
              (FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R (- phi2 phi1)))
              double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
              	return R * (phi2 - phi1);
              }
              
              real(8) function code(r, lambda1, lambda2, phi1, phi2)
                  real(8), intent (in) :: r
                  real(8), intent (in) :: lambda1
                  real(8), intent (in) :: lambda2
                  real(8), intent (in) :: phi1
                  real(8), intent (in) :: phi2
                  code = r * (phi2 - phi1)
              end function
              
              public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
              	return R * (phi2 - phi1);
              }
              
              def code(R, lambda1, lambda2, phi1, phi2):
              	return R * (phi2 - phi1)
              
              function code(R, lambda1, lambda2, phi1, phi2)
              	return Float64(R * Float64(phi2 - phi1))
              end
              
              function tmp = code(R, lambda1, lambda2, phi1, phi2)
              	tmp = R * (phi2 - phi1);
              end
              
              code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]
              
              \begin{array}{l}
              
              \\
              R \cdot \left(\phi_2 - \phi_1\right)
              \end{array}
              
              Derivation
              1. Initial program 58.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. *-lowering-*.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
                2. hypot-defineN/A

                  \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
                3. hypot-lowering-hypot.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
                4. *-lowering-*.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
                5. --lowering--.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                6. cos-lowering-cos.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                7. /-lowering-/.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                8. +-lowering-+.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                9. --lowering--.f6497.4%

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
              3. Simplified97.4%

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

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

                  \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right) \]
                2. neg-sub0N/A

                  \[\leadsto 0 - \color{blue}{\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                3. --lowering--.f64N/A

                  \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)}\right) \]
                4. *-lowering-*.f64N/A

                  \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)}\right)\right) \]
                5. mul-1-negN/A

                  \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \left(R + \left(\mathsf{neg}\left(\frac{R \cdot \phi_2}{\phi_1}\right)\right)\right)\right)\right) \]
                6. unsub-negN/A

                  \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \left(R - \color{blue}{\frac{R \cdot \phi_2}{\phi_1}}\right)\right)\right) \]
                7. --lowering--.f64N/A

                  \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \mathsf{\_.f64}\left(R, \color{blue}{\left(\frac{R \cdot \phi_2}{\phi_1}\right)}\right)\right)\right) \]
                8. associate-/l*N/A

                  \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \mathsf{\_.f64}\left(R, \left(R \cdot \color{blue}{\frac{\phi_2}{\phi_1}}\right)\right)\right)\right) \]
                9. *-lowering-*.f64N/A

                  \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \mathsf{\_.f64}\left(R, \mathsf{*.f64}\left(R, \color{blue}{\left(\frac{\phi_2}{\phi_1}\right)}\right)\right)\right)\right) \]
                10. /-lowering-/.f6428.3%

                  \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\phi_1, \mathsf{\_.f64}\left(R, \mathsf{*.f64}\left(R, \mathsf{/.f64}\left(\phi_2, \color{blue}{\phi_1}\right)\right)\right)\right)\right) \]
              7. Simplified28.3%

                \[\leadsto \color{blue}{0 - \phi_1 \cdot \left(R - R \cdot \frac{\phi_2}{\phi_1}\right)} \]
              8. Taylor expanded in phi2 around 0

                \[\leadsto \color{blue}{R \cdot \phi_2 - R \cdot \phi_1} \]
              9. Step-by-step derivation
                1. distribute-lft-out--N/A

                  \[\leadsto R \cdot \color{blue}{\left(\phi_2 - \phi_1\right)} \]
                2. *-lowering-*.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\phi_2 - \phi_1\right)}\right) \]
                3. --lowering--.f6429.1%

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{\_.f64}\left(\phi_2, \color{blue}{\phi_1}\right)\right) \]
              10. Simplified29.1%

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

              Alternative 10: 17.6% 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 58.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. *-lowering-*.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
                2. hypot-defineN/A

                  \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
                3. hypot-lowering-hypot.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
                4. *-lowering-*.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
                5. --lowering--.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                6. cos-lowering-cos.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                7. /-lowering-/.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                8. +-lowering-+.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                9. --lowering--.f6497.4%

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
              3. Simplified97.4%

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

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

                  \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\phi_2}\right) \]
              7. Simplified17.4%

                \[\leadsto \color{blue}{R \cdot \phi_2} \]
              8. Add Preprocessing

              Alternative 11: 14.0% 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 58.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. *-lowering-*.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
                2. hypot-defineN/A

                  \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
                3. hypot-lowering-hypot.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
                4. *-lowering-*.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
                5. --lowering--.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                6. cos-lowering-cos.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                7. /-lowering-/.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                8. +-lowering-+.f64N/A

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
                9. --lowering--.f6497.4%

                  \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
              3. Simplified97.4%

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

                \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\color{blue}{\phi_2}, 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
              6. Step-by-step derivation
                1. Simplified92.2%

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

                  \[\leadsto \color{blue}{R \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)} \]
                3. Step-by-step derivation
                  1. associate-*r*N/A

                    \[\leadsto \left(R \cdot \lambda_1\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_2\right)} \]
                  2. *-lowering-*.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(\left(R \cdot \lambda_1\right), \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_2\right)}\right) \]
                  3. *-lowering-*.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_1\right), \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_2\right)}\right) \]
                  4. cos-lowering-cos.f64N/A

                    \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_1\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right)\right) \]
                  5. *-lowering-*.f6415.8%

                    \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_1\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right) \]
                4. Simplified15.8%

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

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

                    \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\lambda_1}\right) \]
                7. Simplified14.1%

                  \[\leadsto \color{blue}{R \cdot \lambda_1} \]
                8. Add Preprocessing

                Reproduce

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