Average Error: 40.0 → 0.1
Time: 6.9s
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 r81259 = R;
        double r81260 = lambda1;
        double r81261 = lambda2;
        double r81262 = r81260 - r81261;
        double r81263 = phi1;
        double r81264 = phi2;
        double r81265 = r81263 + r81264;
        double r81266 = 2.0;
        double r81267 = r81265 / r81266;
        double r81268 = cos(r81267);
        double r81269 = r81262 * r81268;
        double r81270 = r81269 * r81269;
        double r81271 = r81263 - r81264;
        double r81272 = r81271 * r81271;
        double r81273 = r81270 + r81272;
        double r81274 = sqrt(r81273);
        double r81275 = r81259 * r81274;
        return r81275;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r81276 = 0.5;
        double r81277 = phi1;
        double r81278 = r81276 * r81277;
        double r81279 = cos(r81278);
        double r81280 = phi2;
        double r81281 = r81276 * r81280;
        double r81282 = cos(r81281);
        double r81283 = r81279 * r81282;
        double r81284 = lambda1;
        double r81285 = sin(r81281);
        double r81286 = lambda2;
        double r81287 = sin(r81278);
        double r81288 = r81286 * r81287;
        double r81289 = r81285 * r81288;
        double r81290 = r81279 * r81286;
        double r81291 = r81287 * r81284;
        double r81292 = r81285 * r81291;
        double r81293 = fma(r81282, r81290, r81292);
        double r81294 = r81289 - r81293;
        double r81295 = fma(r81283, r81284, r81294);
        double r81296 = r81277 - r81280;
        double r81297 = hypot(r81295, r81296);
        double r81298 = R;
        double r81299 = r81297 * r81298;
        return r81299;
}

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 40.0

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

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

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

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

    \[\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 2020025 +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))))))