Average Error: 24.2 → 13.8
Time: 54.7s
Precision: 64
\[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\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({\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\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)\]
\[\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right), \left(\cos \phi_1 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right) \cdot \cos \phi_2, {\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right)\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right)\right)}^{2}\right)}} \cdot \left(2 \cdot R\right)\]
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\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({\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\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)
\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right), \left(\cos \phi_1 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)\right) \cdot \cos \phi_2, {\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right)\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right), {\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right)\right)}^{2}\right)}} \cdot \left(2 \cdot R\right)
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r96724 = R;
        double r96725 = 2.0;
        double r96726 = phi1;
        double r96727 = phi2;
        double r96728 = r96726 - r96727;
        double r96729 = r96728 / r96725;
        double r96730 = sin(r96729);
        double r96731 = pow(r96730, r96725);
        double r96732 = cos(r96726);
        double r96733 = cos(r96727);
        double r96734 = r96732 * r96733;
        double r96735 = lambda1;
        double r96736 = lambda2;
        double r96737 = r96735 - r96736;
        double r96738 = r96737 / r96725;
        double r96739 = sin(r96738);
        double r96740 = r96734 * r96739;
        double r96741 = r96740 * r96739;
        double r96742 = r96731 + r96741;
        double r96743 = sqrt(r96742);
        double r96744 = 1.0;
        double r96745 = r96744 - r96742;
        double r96746 = sqrt(r96745);
        double r96747 = atan2(r96743, r96746);
        double r96748 = r96725 * r96747;
        double r96749 = r96724 * r96748;
        return r96749;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r96750 = lambda1;
        double r96751 = lambda2;
        double r96752 = r96750 - r96751;
        double r96753 = 2.0;
        double r96754 = r96752 / r96753;
        double r96755 = sin(r96754);
        double r96756 = log1p(r96755);
        double r96757 = expm1(r96756);
        double r96758 = phi1;
        double r96759 = cos(r96758);
        double r96760 = r96759 * r96757;
        double r96761 = phi2;
        double r96762 = cos(r96761);
        double r96763 = r96760 * r96762;
        double r96764 = r96761 / r96753;
        double r96765 = cos(r96764);
        double r96766 = r96758 / r96753;
        double r96767 = sin(r96766);
        double r96768 = r96765 * r96767;
        double r96769 = sin(r96764);
        double r96770 = cos(r96766);
        double r96771 = r96769 * r96770;
        double r96772 = r96768 - r96771;
        double r96773 = pow(r96772, r96753);
        double r96774 = fma(r96757, r96763, r96773);
        double r96775 = sqrt(r96774);
        double r96776 = 1.0;
        double r96777 = r96759 * r96755;
        double r96778 = r96762 * r96777;
        double r96779 = fma(r96755, r96778, r96773);
        double r96780 = r96776 - r96779;
        double r96781 = sqrt(r96780);
        double r96782 = atan2(r96775, r96781);
        double r96783 = R;
        double r96784 = r96753 * r96783;
        double r96785 = r96782 * r96784;
        return r96785;
}

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.2

    \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\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({\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\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.2

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

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

    \[\leadsto \left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_1\right) \cdot \cos \phi_2, {\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(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_1\right) \cdot \cos \phi_2, {\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}^{2}\right)}}\]
  6. Simplified23.6

    \[\leadsto \left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_1\right) \cdot \cos \phi_2, {\left(\color{blue}{\cos \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{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(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_1\right) \cdot \cos \phi_2, {\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}^{2}\right)}}\]
  7. Simplified23.6

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

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

    \[\leadsto \left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_1\right) \cdot \cos \phi_2, {\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right)\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_1\right) \cdot \cos \phi_2, {\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)}}\]
  11. Simplified13.8

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

    \[\leadsto \left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_1\right) \cdot \cos \phi_2, {\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right)\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_1\right) \cdot \cos \phi_2, {\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right) - \color{blue}{\sin \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right)}\right)}^{2}\right)}}\]
  13. Using strategy rm
  14. Applied expm1-log1p-u13.8

    \[\leadsto \left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)\right)}, \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_1\right) \cdot \cos \phi_2, {\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right)\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_1\right) \cdot \cos \phi_2, {\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right)\right)}^{2}\right)}}\]
  15. Using strategy rm
  16. Applied expm1-log1p-u13.8

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

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

Reproduce

herbie shell --seed 2019196 +o rules:numerics
(FPCore (R lambda1 lambda2 phi1 phi2)
  :name "Distance on a great circle"
  (* 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))))))))))