Average Error: 39.5 → 0.1
Time: 23.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)}\]
\[R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\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(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right), \phi_1 - \phi_2\right)
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r3891600 = R;
        double r3891601 = lambda1;
        double r3891602 = lambda2;
        double r3891603 = r3891601 - r3891602;
        double r3891604 = phi1;
        double r3891605 = phi2;
        double r3891606 = r3891604 + r3891605;
        double r3891607 = 2.0;
        double r3891608 = r3891606 / r3891607;
        double r3891609 = cos(r3891608);
        double r3891610 = r3891603 * r3891609;
        double r3891611 = r3891610 * r3891610;
        double r3891612 = r3891604 - r3891605;
        double r3891613 = r3891612 * r3891612;
        double r3891614 = r3891611 + r3891613;
        double r3891615 = sqrt(r3891614);
        double r3891616 = r3891600 * r3891615;
        return r3891616;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r3891617 = R;
        double r3891618 = lambda1;
        double r3891619 = lambda2;
        double r3891620 = r3891618 - r3891619;
        double r3891621 = phi1;
        double r3891622 = 0.5;
        double r3891623 = r3891621 * r3891622;
        double r3891624 = cos(r3891623);
        double r3891625 = phi2;
        double r3891626 = r3891622 * r3891625;
        double r3891627 = cos(r3891626);
        double r3891628 = r3891624 * r3891627;
        double r3891629 = sin(r3891626);
        double r3891630 = sin(r3891623);
        double r3891631 = r3891629 * r3891630;
        double r3891632 = r3891628 - r3891631;
        double r3891633 = r3891620 * r3891632;
        double r3891634 = r3891621 - r3891625;
        double r3891635 = hypot(r3891633, r3891634);
        double r3891636 = r3891617 * r3891635;
        return r3891636;
}

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 39.5

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

    \[\leadsto \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 \color{blue}{\left(1 \cdot R\right)}\]
  5. Applied associate-*r*3.8

    \[\leadsto \color{blue}{\left(\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 1\right) \cdot R}\]
  6. Simplified3.8

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

    \[\leadsto \mathsf{hypot}\left(\color{blue}{\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) \cdot R\]
  9. Taylor expanded around inf 3.8

    \[\leadsto \mathsf{hypot}\left(\color{blue}{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right) \cdot R\]
  10. Using strategy rm
  11. Applied distribute-rgt-in3.8

    \[\leadsto \mathsf{hypot}\left(\cos \color{blue}{\left(\phi_1 \cdot 0.5 + \phi_2 \cdot 0.5\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right) \cdot R\]
  12. Applied cos-sum0.1

    \[\leadsto \mathsf{hypot}\left(\color{blue}{\left(\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(\phi_2 \cdot 0.5\right) - \sin \left(\phi_1 \cdot 0.5\right) \cdot \sin \left(\phi_2 \cdot 0.5\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right) \cdot R\]
  13. Final simplification0.1

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

Reproduce

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