Average Error: 38.6 → 0.1
Time: 22.6s
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(\phi_1 \cdot 0.5\right), \cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1, \sin \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_2 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right) - \mathsf{fma}\left(\cos \left(0.5 \cdot \phi_1\right), \lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\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\]
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(\phi_1 \cdot 0.5\right), \cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1, \sin \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_2 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right) - \mathsf{fma}\left(\cos \left(0.5 \cdot \phi_1\right), \lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\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
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r61479 = R;
        double r61480 = lambda1;
        double r61481 = lambda2;
        double r61482 = r61480 - r61481;
        double r61483 = phi1;
        double r61484 = phi2;
        double r61485 = r61483 + r61484;
        double r61486 = 2.0;
        double r61487 = r61485 / r61486;
        double r61488 = cos(r61487);
        double r61489 = r61482 * r61488;
        double r61490 = r61489 * r61489;
        double r61491 = r61483 - r61484;
        double r61492 = r61491 * r61491;
        double r61493 = r61490 + r61492;
        double r61494 = sqrt(r61493);
        double r61495 = r61479 * r61494;
        return r61495;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r61496 = phi1;
        double r61497 = 0.5;
        double r61498 = r61496 * r61497;
        double r61499 = cos(r61498);
        double r61500 = phi2;
        double r61501 = r61497 * r61500;
        double r61502 = cos(r61501);
        double r61503 = lambda1;
        double r61504 = r61502 * r61503;
        double r61505 = r61497 * r61496;
        double r61506 = sin(r61505);
        double r61507 = lambda2;
        double r61508 = sin(r61501);
        double r61509 = r61507 * r61508;
        double r61510 = r61506 * r61509;
        double r61511 = fma(r61499, r61504, r61510);
        double r61512 = cos(r61505);
        double r61513 = r61507 * r61502;
        double r61514 = r61508 * r61503;
        double r61515 = r61506 * r61514;
        double r61516 = fma(r61512, r61513, r61515);
        double r61517 = r61511 - r61516;
        double r61518 = r61496 - r61500;
        double r61519 = hypot(r61517, r61518);
        double r61520 = R;
        double r61521 = r61519 * r61520;
        return r61521;
}

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 38.6

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

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

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

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

    \[\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(\phi_1 \cdot 0.5\right), \cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1, \sin \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_2 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right) - \mathsf{fma}\left(\cos \left(0.5 \cdot \phi_1\right), \lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\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\]
  12. Final simplification0.1

    \[\leadsto \mathsf{hypot}\left(\mathsf{fma}\left(\cos \left(\phi_1 \cdot 0.5\right), \cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1, \sin \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_2 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right) - \mathsf{fma}\left(\cos \left(0.5 \cdot \phi_1\right), \lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\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\]

Reproduce

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