Average Error: 38.9 → 3.9
Time: 23.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)}\]
\[R \cdot \mathsf{hypot}\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\]
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)}
R \cdot \mathsf{hypot}\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r3165267 = R;
        double r3165268 = lambda1;
        double r3165269 = lambda2;
        double r3165270 = r3165268 - r3165269;
        double r3165271 = phi1;
        double r3165272 = phi2;
        double r3165273 = r3165271 + r3165272;
        double r3165274 = 2.0;
        double r3165275 = r3165273 / r3165274;
        double r3165276 = cos(r3165275);
        double r3165277 = r3165270 * r3165276;
        double r3165278 = r3165277 * r3165277;
        double r3165279 = r3165271 - r3165272;
        double r3165280 = r3165279 * r3165279;
        double r3165281 = r3165278 + r3165280;
        double r3165282 = sqrt(r3165281);
        double r3165283 = r3165267 * r3165282;
        return r3165283;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r3165284 = R;
        double r3165285 = phi1;
        double r3165286 = phi2;
        double r3165287 = r3165285 + r3165286;
        double r3165288 = 2.0;
        double r3165289 = r3165287 / r3165288;
        double r3165290 = cos(r3165289);
        double r3165291 = log1p(r3165290);
        double r3165292 = expm1(r3165291);
        double r3165293 = lambda1;
        double r3165294 = lambda2;
        double r3165295 = r3165293 - r3165294;
        double r3165296 = r3165292 * r3165295;
        double r3165297 = r3165285 - r3165286;
        double r3165298 = hypot(r3165296, r3165297);
        double r3165299 = r3165284 * r3165298;
        return r3165299;
}

Error

Bits error versus R

Bits error versus lambda1

Bits error versus lambda2

Bits error versus phi1

Bits error versus phi2

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 38.9

    \[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_2 + \phi_1}{2}\right), \phi_1 - \phi_2\right) \cdot R}\]
  3. Using strategy rm
  4. Applied *-commutative3.9

    \[\leadsto \mathsf{hypot}\left(\color{blue}{\cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)}, \phi_1 - \phi_2\right) \cdot R\]
  5. Using strategy rm
  6. Applied add-log-exp4.0

    \[\leadsto \mathsf{hypot}\left(\color{blue}{\log \left(e^{\cos \left(\frac{\phi_2 + \phi_1}{2}\right)}\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right) \cdot R\]
  7. Using strategy rm
  8. Applied expm1-log1p-u4.0

    \[\leadsto \mathsf{hypot}\left(\log \color{blue}{\left(\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\cos \left(\frac{\phi_2 + \phi_1}{2}\right)}\right)\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right) \cdot R\]
  9. Using strategy rm
  10. Applied expm1-log1p-u4.0

    \[\leadsto \mathsf{hypot}\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\cos \left(\frac{\phi_2 + \phi_1}{2}\right)}\right)\right)\right)\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right) \cdot R\]
  11. Simplified3.9

    \[\leadsto \mathsf{hypot}\left(\mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(\cos \left(\frac{\phi_2 + \phi_1}{2}\right)\right)}\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right) \cdot R\]
  12. Final simplification3.9

    \[\leadsto R \cdot \mathsf{hypot}\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\]

Reproduce

herbie shell --seed 2019172 +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))))))