Average Error: 39.8 → 0.1
Time: 8.5s
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 \cos \left(0.5 \cdot \phi_2\right), \lambda_1, \sin \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right) - \mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2, \sin \left(0.5 \cdot \phi_2\right) \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \lambda_1\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 \cos \left(0.5 \cdot \phi_2\right), \lambda_1, \sin \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right) - \mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2, \sin \left(0.5 \cdot \phi_2\right) \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \lambda_1\right)\right)\right), \phi_1 - \phi_2\right) \cdot R
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r90998 = R;
        double r90999 = lambda1;
        double r91000 = lambda2;
        double r91001 = r90999 - r91000;
        double r91002 = phi1;
        double r91003 = phi2;
        double r91004 = r91002 + r91003;
        double r91005 = 2.0;
        double r91006 = r91004 / r91005;
        double r91007 = cos(r91006);
        double r91008 = r91001 * r91007;
        double r91009 = r91008 * r91008;
        double r91010 = r91002 - r91003;
        double r91011 = r91010 * r91010;
        double r91012 = r91009 + r91011;
        double r91013 = sqrt(r91012);
        double r91014 = r90998 * r91013;
        return r91014;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r91015 = 0.5;
        double r91016 = phi1;
        double r91017 = r91015 * r91016;
        double r91018 = cos(r91017);
        double r91019 = phi2;
        double r91020 = r91015 * r91019;
        double r91021 = cos(r91020);
        double r91022 = r91018 * r91021;
        double r91023 = lambda1;
        double r91024 = sin(r91020);
        double r91025 = lambda2;
        double r91026 = sin(r91017);
        double r91027 = r91025 * r91026;
        double r91028 = r91024 * r91027;
        double r91029 = r91018 * r91025;
        double r91030 = r91026 * r91023;
        double r91031 = r91024 * r91030;
        double r91032 = fma(r91021, r91029, r91031);
        double r91033 = r91028 - r91032;
        double r91034 = fma(r91022, r91023, r91033);
        double r91035 = r91016 - r91019;
        double r91036 = hypot(r91034, r91035);
        double r91037 = R;
        double r91038 = r91036 * r91037;
        return r91038;
}

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

    \[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.8

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

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

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

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

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

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

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

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

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

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

Reproduce

herbie shell --seed 2020002 +o rules:numerics
(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))) (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2)))) (* (- phi1 phi2) (- phi1 phi2))))))