Average Error: 39.3 → 0.1
Time: 10.0s
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 r97524 = R;
        double r97525 = lambda1;
        double r97526 = lambda2;
        double r97527 = r97525 - r97526;
        double r97528 = phi1;
        double r97529 = phi2;
        double r97530 = r97528 + r97529;
        double r97531 = 2.0;
        double r97532 = r97530 / r97531;
        double r97533 = cos(r97532);
        double r97534 = r97527 * r97533;
        double r97535 = r97534 * r97534;
        double r97536 = r97528 - r97529;
        double r97537 = r97536 * r97536;
        double r97538 = r97535 + r97537;
        double r97539 = sqrt(r97538);
        double r97540 = r97524 * r97539;
        return r97540;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r97541 = 0.5;
        double r97542 = phi1;
        double r97543 = r97541 * r97542;
        double r97544 = cos(r97543);
        double r97545 = phi2;
        double r97546 = r97541 * r97545;
        double r97547 = cos(r97546);
        double r97548 = r97544 * r97547;
        double r97549 = lambda1;
        double r97550 = sin(r97546);
        double r97551 = lambda2;
        double r97552 = sin(r97543);
        double r97553 = r97551 * r97552;
        double r97554 = r97550 * r97553;
        double r97555 = r97544 * r97551;
        double r97556 = r97552 * r97549;
        double r97557 = r97550 * r97556;
        double r97558 = fma(r97547, r97555, r97557);
        double r97559 = r97554 - r97558;
        double r97560 = fma(r97548, r97549, r97559);
        double r97561 = r97542 - r97545;
        double r97562 = hypot(r97560, r97561);
        double r97563 = R;
        double r97564 = r97562 * r97563;
        return r97564;
}

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.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 2020081 +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))))))