Average Error: 38.8 → 3.7
Time: 25.2s
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 r55961 = R;
        double r55962 = lambda1;
        double r55963 = lambda2;
        double r55964 = r55962 - r55963;
        double r55965 = phi1;
        double r55966 = phi2;
        double r55967 = r55965 + r55966;
        double r55968 = 2.0;
        double r55969 = r55967 / r55968;
        double r55970 = cos(r55969);
        double r55971 = r55964 * r55970;
        double r55972 = r55971 * r55971;
        double r55973 = r55965 - r55966;
        double r55974 = r55973 * r55973;
        double r55975 = r55972 + r55974;
        double r55976 = sqrt(r55975);
        double r55977 = r55961 * r55976;
        return r55977;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r55978 = lambda1;
        double r55979 = lambda2;
        double r55980 = r55978 - r55979;
        double r55981 = 0.5;
        double r55982 = phi2;
        double r55983 = phi1;
        double r55984 = r55982 + r55983;
        double r55985 = r55981 * r55984;
        double r55986 = cos(r55985);
        double r55987 = r55980 * r55986;
        double r55988 = r55983 - r55982;
        double r55989 = hypot(r55987, r55988);
        double r55990 = R;
        double r55991 = r55989 * r55990;
        return r55991;
}

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