Average Error: 39.3 → 0.1
Time: 44.6s
Precision: 64
\[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)}\]
\[\mathsf{hypot}\left(\mathsf{fma}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1, \cos \left(\phi_2 \cdot 0.5\right), \lambda_2 \cdot \left(\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) - \mathsf{fma}\left(\sin \left(0.5 \cdot \phi_1\right) \cdot \lambda_1, \sin \left(\phi_2 \cdot 0.5\right), \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right) \cdot R\]
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)}
\mathsf{hypot}\left(\mathsf{fma}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1, \cos \left(\phi_2 \cdot 0.5\right), \lambda_2 \cdot \left(\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) - \mathsf{fma}\left(\sin \left(0.5 \cdot \phi_1\right) \cdot \lambda_1, \sin \left(\phi_2 \cdot 0.5\right), \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right) \cdot R
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r140851 = R;
        double r140852 = lambda1;
        double r140853 = lambda2;
        double r140854 = r140852 - r140853;
        double r140855 = phi1;
        double r140856 = phi2;
        double r140857 = r140855 + r140856;
        double r140858 = 2.0;
        double r140859 = r140857 / r140858;
        double r140860 = cos(r140859);
        double r140861 = r140854 * r140860;
        double r140862 = r140861 * r140861;
        double r140863 = r140855 - r140856;
        double r140864 = r140863 * r140863;
        double r140865 = r140862 + r140864;
        double r140866 = sqrt(r140865);
        double r140867 = r140851 * r140866;
        return r140867;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r140868 = 0.5;
        double r140869 = phi1;
        double r140870 = r140868 * r140869;
        double r140871 = cos(r140870);
        double r140872 = lambda1;
        double r140873 = r140871 * r140872;
        double r140874 = phi2;
        double r140875 = r140874 * r140868;
        double r140876 = cos(r140875);
        double r140877 = lambda2;
        double r140878 = sin(r140875);
        double r140879 = sin(r140870);
        double r140880 = r140878 * r140879;
        double r140881 = r140877 * r140880;
        double r140882 = r140879 * r140872;
        double r140883 = r140871 * r140877;
        double r140884 = r140883 * r140876;
        double r140885 = fma(r140882, r140878, r140884);
        double r140886 = r140881 - r140885;
        double r140887 = fma(r140873, r140876, r140886);
        double r140888 = r140869 - r140874;
        double r140889 = hypot(r140887, r140888);
        double r140890 = R;
        double r140891 = r140889 * r140890;
        return r140891;
}

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 39.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. Simplified3.7

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

    \[\leadsto \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}, \phi_1 - \phi_2\right) \cdot R\]
  4. Using strategy rm
  5. Applied distribute-lft-in3.7

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

    \[\leadsto \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \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)}, \phi_1 - \phi_2\right) \cdot R\]
  7. Simplified0.1

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

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

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

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

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

Reproduce

herbie shell --seed 2019194 +o rules:numerics
(FPCore (R lambda1 lambda2 phi1 phi2)
  :name "Equirectangular approximation to distance on a great circle"
  (* R (sqrt (+ (* (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0))) (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0)))) (* (- phi1 phi2) (- phi1 phi2))))))