Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.1% → 99.9%
Time: 19.1s
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 57.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--.f6495.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. Simplified95.4%

    \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
  4. Add Preprocessing
  5. 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--.f6495.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-rr95.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. div-invN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot \frac{1}{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. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot \frac{1}{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) \]
    3. *-commutativeN/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. 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{1}{2} \cdot \phi_2\right) - \sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \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) \]
    6. 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{1}{2} \cdot \phi_2\right), \mathsf{neg}\left(\sin \left(\frac{1}{2} \cdot \phi_2\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right) + \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), \sin \left(\frac{1}{2} \cdot \phi_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) \]
    7. +-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{1}{2} \cdot \phi_2\right), \mathsf{neg}\left(\sin \left(\frac{1}{2} \cdot \phi_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{1}{2} \cdot \phi_2\right)\right), \sin \left(\frac{1}{2} \cdot \phi_1\right), \sin \left(\frac{1}{2} \cdot \phi_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.9%

    \[\leadsto R \cdot \mathsf{hypot}\left(\frac{\color{blue}{\mathsf{fma}\left(\cos \left(\phi_1 \cdot 0.5\right), \cos \left(\phi_2 \cdot 0.5\right), -\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right) + \mathsf{fma}\left(-\sin \left(\phi_2 \cdot 0.5\right), \sin \left(\phi_1 \cdot 0.5\right), \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)}}{\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 57.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--.f6495.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. Simplified95.4%

    \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
  4. Add Preprocessing
  5. 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--.f6495.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-rr95.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. div-invN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot \frac{1}{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. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{/.f64}\left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot \frac{1}{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) \]
    3. *-commutativeN/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. 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{1}{2} \cdot \phi_2\right) - \sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \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) \]
    6. 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{1}{2} \cdot \phi_2\right), \mathsf{neg}\left(\sin \left(\frac{1}{2} \cdot \phi_2\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right) + \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), \sin \left(\frac{1}{2} \cdot \phi_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) \]
    7. +-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{1}{2} \cdot \phi_2\right), \mathsf{neg}\left(\sin \left(\frac{1}{2} \cdot \phi_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{1}{2} \cdot \phi_2\right)\right), \sin \left(\frac{1}{2} \cdot \phi_1\right), \sin \left(\frac{1}{2} \cdot \phi_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.9%

    \[\leadsto R \cdot \mathsf{hypot}\left(\frac{\color{blue}{\mathsf{fma}\left(\cos \left(\phi_1 \cdot 0.5\right), \cos \left(\phi_2 \cdot 0.5\right), -\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right) + \mathsf{fma}\left(-\sin \left(\phi_2 \cdot 0.5\right), \sin \left(\phi_1 \cdot 0.5\right), \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)}}{\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: 93.3% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 59.9%

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --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{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. 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{1}{2} \cdot \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6491.5%

        \[\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(\frac{1}{2}, \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified91.5%

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

    if 6.49999999999999987e-21 < phi2

    1. Initial program 50.5%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. *-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--.f6493.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. Simplified93.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(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

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

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --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{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. 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{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6492.1%

        \[\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(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified92.1%

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

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

Alternative 4: 96.2% accurate, 1.5× speedup?

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
    3. --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{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    4. 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{1}{2} \cdot \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    5. *-lowering-*.f6490.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(\frac{1}{2}, \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
  7. Simplified90.6%

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

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

Alternative 6: 70.5% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 3700000000:\\ \;\;\;\;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 3700000000.0)
   (* R (hypot phi1 (- lambda1 lambda2)))
   (* R (- phi2 phi1))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 3700000000.0) {
		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 <= 3700000000.0) {
		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 <= 3700000000.0:
		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 <= 3700000000.0)
		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 <= 3700000000.0)
		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, 3700000000.0], 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 3700000000:\\
\;\;\;\;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 < 3.7e9

    1. Initial program 59.9%

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --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{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. 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{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6488.5%

        \[\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(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified88.5%

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

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

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

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

    if 3.7e9 < phi2

    1. Initial program 50.5%

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

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

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

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

      \[\leadsto \color{blue}{0 - \phi_1 \cdot \left(R - \frac{R \cdot \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--.f6477.2%

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

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

Alternative 7: 85.2% accurate, 3.0× speedup?

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

\\
R \cdot \mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 57.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--.f6495.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. Simplified95.4%

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

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

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
    3. --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{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    4. 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{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    5. *-lowering-*.f6489.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(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
  7. Simplified89.7%

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

    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\lambda_1 - \lambda_2\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
  9. Step-by-step derivation
    1. --lowering--.f6485.1%

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

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

Alternative 8: 26.6% accurate, 25.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq -2.65 \cdot 10^{-189}:\\
\;\;\;\;0 - R \cdot \lambda_1\\

\mathbf{elif}\;\phi_2 \leq 3400000000000:\\
\;\;\;\;R \cdot \lambda_2\\

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


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

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

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

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

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

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

      \[\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 phi1 around 0

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

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

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

      \[\leadsto R \cdot \left(\color{blue}{\cos \left(0.5 \cdot \phi_2\right)} \cdot \left(-\lambda_1\right)\right) \]
    11. Taylor expanded in phi2 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-*.f6411.4%

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

      \[\leadsto \color{blue}{0 - R \cdot \lambda_1} \]
    14. Step-by-step derivation
      1. sub0-negN/A

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

        \[\leadsto \mathsf{neg}\left(\lambda_1 \cdot R\right) \]
      3. distribute-lft-neg-inN/A

        \[\leadsto \left(\mathsf{neg}\left(\lambda_1\right)\right) \cdot \color{blue}{R} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right), \color{blue}{R}\right) \]
      5. neg-lowering-neg.f6411.4%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{neg.f64}\left(\lambda_1\right), R\right) \]
    15. Applied egg-rr11.4%

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

    if -2.6499999999999999e-189 < phi2 < 3.4e12

    1. Initial program 54.7%

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --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{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. 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{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6488.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(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified88.0%

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

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

        \[\leadsto \left(R \cdot \lambda_2\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_2\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_2\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_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6421.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right) \]
    10. Simplified21.3%

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

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

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\lambda_2}\right) \]
    13. Simplified21.3%

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

    if 3.4e12 < phi2

    1. Initial program 50.5%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -2.65 \cdot 10^{-189}:\\ \;\;\;\;0 - R \cdot \lambda_1\\ \mathbf{elif}\;\phi_2 \leq 3400000000000:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 33.8% accurate, 32.8× speedup?

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

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

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


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

    1. Initial program 58.1%

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

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

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

      \[\leadsto \color{blue}{0 - \phi_1 \cdot \left(R - \frac{R \cdot \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--.f6435.1%

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

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

    if 3.1000000000000002e218 < lambda2

    1. Initial program 46.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--.f64100.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. Simplified100.0%

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

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

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

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --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{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. 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{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6489.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(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified89.7%

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

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

        \[\leadsto \left(R \cdot \lambda_2\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_2\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_2\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_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6465.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right) \]
    10. Simplified65.3%

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

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

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\lambda_2}\right) \]
    13. Simplified74.1%

      \[\leadsto \color{blue}{R \cdot \lambda_2} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 10: 26.4% accurate, 41.0× speedup?

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

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

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


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

    1. Initial program 59.9%

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --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{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. 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{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6488.5%

        \[\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(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified88.5%

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

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

        \[\leadsto \left(R \cdot \lambda_2\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_2\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_2\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_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6417.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right) \]
    10. Simplified17.1%

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

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

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\lambda_2}\right) \]
    13. Simplified15.7%

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

    if 1.4e12 < phi2

    1. Initial program 50.5%

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

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

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

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

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

Alternative 11: 13.5% accurate, 109.7× speedup?

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

\\
R \cdot \lambda_2
\end{array}
Derivation
  1. Initial program 57.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--.f6495.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. Simplified95.4%

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

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

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
    3. --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{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    4. 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{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    5. *-lowering-*.f6489.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(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
  7. Simplified89.7%

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

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

      \[\leadsto \left(R \cdot \lambda_2\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_2\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_2\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_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right)\right) \]
    5. *-lowering-*.f6414.9%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right) \]
  10. Simplified14.9%

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

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

      \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\lambda_2}\right) \]
  13. Simplified13.6%

    \[\leadsto \color{blue}{R \cdot \lambda_2} \]
  14. Add Preprocessing

Reproduce

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