Average Error: 39.2 → 0.1
Time: 8.3s
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 r99620 = R;
        double r99621 = lambda1;
        double r99622 = lambda2;
        double r99623 = r99621 - r99622;
        double r99624 = phi1;
        double r99625 = phi2;
        double r99626 = r99624 + r99625;
        double r99627 = 2.0;
        double r99628 = r99626 / r99627;
        double r99629 = cos(r99628);
        double r99630 = r99623 * r99629;
        double r99631 = r99630 * r99630;
        double r99632 = r99624 - r99625;
        double r99633 = r99632 * r99632;
        double r99634 = r99631 + r99633;
        double r99635 = sqrt(r99634);
        double r99636 = r99620 * r99635;
        return r99636;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r99637 = 0.5;
        double r99638 = phi1;
        double r99639 = r99637 * r99638;
        double r99640 = cos(r99639);
        double r99641 = phi2;
        double r99642 = r99637 * r99641;
        double r99643 = cos(r99642);
        double r99644 = r99640 * r99643;
        double r99645 = lambda1;
        double r99646 = sin(r99642);
        double r99647 = lambda2;
        double r99648 = sin(r99639);
        double r99649 = r99647 * r99648;
        double r99650 = r99646 * r99649;
        double r99651 = r99640 * r99647;
        double r99652 = r99648 * r99645;
        double r99653 = r99646 * r99652;
        double r99654 = fma(r99643, r99651, r99653);
        double r99655 = r99650 - r99654;
        double r99656 = fma(r99644, r99645, r99655);
        double r99657 = r99638 - r99641;
        double r99658 = hypot(r99656, r99657);
        double r99659 = R;
        double r99660 = r99658 * r99659;
        return r99660;
}

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

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