Average Error: 38.8 → 3.7
Time: 24.8s
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(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\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(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right), \phi_1 - \phi_2\right) \cdot R
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r62523 = R;
        double r62524 = lambda1;
        double r62525 = lambda2;
        double r62526 = r62524 - r62525;
        double r62527 = phi1;
        double r62528 = phi2;
        double r62529 = r62527 + r62528;
        double r62530 = 2.0;
        double r62531 = r62529 / r62530;
        double r62532 = cos(r62531);
        double r62533 = r62526 * r62532;
        double r62534 = r62533 * r62533;
        double r62535 = r62527 - r62528;
        double r62536 = r62535 * r62535;
        double r62537 = r62534 + r62536;
        double r62538 = sqrt(r62537);
        double r62539 = r62523 * r62538;
        return r62539;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r62540 = lambda1;
        double r62541 = lambda2;
        double r62542 = r62540 - r62541;
        double r62543 = 0.5;
        double r62544 = phi2;
        double r62545 = phi1;
        double r62546 = r62544 + r62545;
        double r62547 = r62543 * r62546;
        double r62548 = cos(r62547);
        double r62549 = r62542 * r62548;
        double r62550 = r62545 - r62544;
        double r62551 = hypot(r62549, r62550);
        double r62552 = R;
        double r62553 = r62551 * r62552;
        return r62553;
}

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

    \[\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. Using strategy rm
  4. Applied add-log-exp3.8

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

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

    \[\leadsto \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right)}}\right)\right)\right), \phi_1 - \phi_2\right) \cdot R\]
  9. 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_2 + \phi_1\right)\right)}, \phi_1 - \phi_2\right) \cdot R\]
  10. Final simplification3.7

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

Reproduce

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