Average Error: 24.1 → 13.6
Time: 1.2min
Precision: binary64
\[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
\[\begin{array}{l} t_0 := {\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2}\\ t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\ t_2 := \cos \phi_1 \cdot \cos \phi_2\\ t_3 := \mathsf{fma}\left(t_1, t_1 \cdot t_2, t_0\right)\\ R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_3}}{\sqrt{\frac{1 - t_3 \cdot t_3}{1 + \mathsf{fma}\left(t_1, t_2 \cdot \sqrt[3]{t_1 \cdot \left(t_1 \cdot t_1\right)}, t_0\right)}}}\right) \end{array} \]
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right)
\begin{array}{l}
t_0 := {\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2}\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := \cos \phi_1 \cdot \cos \phi_2\\
t_3 := \mathsf{fma}\left(t_1, t_1 \cdot t_2, t_0\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_3}}{\sqrt{\frac{1 - t_3 \cdot t_3}{1 + \mathsf{fma}\left(t_1, t_2 \cdot \sqrt[3]{t_1 \cdot \left(t_1 \cdot t_1\right)}, t_0\right)}}}\right)
\end{array}
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R
  (*
   2.0
   (atan2
    (sqrt
     (+
      (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
      (*
       (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0)))
       (sin (/ (- lambda1 lambda2) 2.0)))))
    (sqrt
     (-
      1.0
      (+
       (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
       (*
        (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0)))
        (sin (/ (- lambda1 lambda2) 2.0))))))))))
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0
         (pow
          (-
           (* (sin (/ phi1 2.0)) (cos (/ phi2 2.0)))
           (* (cos (/ phi1 2.0)) (sin (/ phi2 2.0))))
          2.0))
        (t_1 (sin (/ (- lambda1 lambda2) 2.0)))
        (t_2 (* (cos phi1) (cos phi2)))
        (t_3 (fma t_1 (* t_1 t_2) t_0)))
   (*
    R
    (*
     2.0
     (atan2
      (sqrt t_3)
      (sqrt
       (/
        (- 1.0 (* t_3 t_3))
        (+ 1.0 (fma t_1 (* t_2 (cbrt (* t_1 (* t_1 t_1)))) t_0)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * (2.0 * atan2(sqrt(pow(sin((phi1 - phi2) / 2.0), 2.0) + (((cos(phi1) * cos(phi2)) * sin((lambda1 - lambda2) / 2.0)) * sin((lambda1 - lambda2) / 2.0))), sqrt(1.0 - (pow(sin((phi1 - phi2) / 2.0), 2.0) + (((cos(phi1) * cos(phi2)) * sin((lambda1 - lambda2) / 2.0)) * sin((lambda1 - lambda2) / 2.0))))));
}
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = pow(((sin(phi1 / 2.0) * cos(phi2 / 2.0)) - (cos(phi1 / 2.0) * sin(phi2 / 2.0))), 2.0);
	double t_1 = sin((lambda1 - lambda2) / 2.0);
	double t_2 = cos(phi1) * cos(phi2);
	double t_3 = fma(t_1, (t_1 * t_2), t_0);
	return R * (2.0 * atan2(sqrt(t_3), sqrt((1.0 - (t_3 * t_3)) / (1.0 + fma(t_1, (t_2 * cbrt(t_1 * (t_1 * t_1))), t_0)))));
}

Error

Bits error versus R

Bits error versus lambda1

Bits error versus lambda2

Bits error versus phi1

Bits error versus phi2

Derivation

  1. Initial program 24.1

    \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right) \]
  2. Simplified24.1

    \[\leadsto \color{blue}{R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}}\right)} \]
  3. Applied div-sub_binary6424.1

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), {\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2}\right)}}\right) \]
  4. Applied sin-diff_binary6423.5

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), {\color{blue}{\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}}^{2}\right)}}\right) \]
  5. Applied div-sub_binary6423.5

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), {\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\right)}}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), {\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2}\right)}}\right) \]
  6. Applied sin-diff_binary6413.6

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), {\color{blue}{\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), {\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2}\right)}}\right) \]
  7. Applied flip--_binary6413.6

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), {\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2}\right)}}{\sqrt{\color{blue}{\frac{1 \cdot 1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), {\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2}\right) \cdot \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), {\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2}\right)}{1 + \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), {\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2}\right)}}}}\right) \]
  8. Applied add-cbrt-cube_binary6413.6

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), {\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2}\right)}}{\sqrt{\frac{1 \cdot 1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), {\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2}\right) \cdot \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), {\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2}\right)}{1 + \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\sqrt[3]{\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}, {\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2}\right)}}}\right) \]
  9. Final simplification13.6

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right), {\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2}\right)}}{\sqrt{\frac{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right), {\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2}\right) \cdot \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right), {\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2}\right)}{1 + \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sqrt[3]{\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}, {\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2}\right)}}}\right) \]

Reproduce

herbie shell --seed 2022088 
(FPCore (R lambda1 lambda2 phi1 phi2)
  :name "Distance on a great circle"
  :precision binary64
  (* R (* 2.0 (atan2 (sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0))) (sin (/ (- lambda1 lambda2) 2.0))))) (sqrt (- 1.0 (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0))) (sin (/ (- lambda1 lambda2) 2.0))))))))))