Average Error: 38.9 → 3.8
Time: 21.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)}\]
\[R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right)\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 \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \phi_1 - \phi_2\right)
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r56081 = R;
        double r56082 = lambda1;
        double r56083 = lambda2;
        double r56084 = r56082 - r56083;
        double r56085 = phi1;
        double r56086 = phi2;
        double r56087 = r56085 + r56086;
        double r56088 = 2.0;
        double r56089 = r56087 / r56088;
        double r56090 = cos(r56089);
        double r56091 = r56084 * r56090;
        double r56092 = r56091 * r56091;
        double r56093 = r56085 - r56086;
        double r56094 = r56093 * r56093;
        double r56095 = r56092 + r56094;
        double r56096 = sqrt(r56095);
        double r56097 = r56081 * r56096;
        return r56097;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r56098 = R;
        double r56099 = lambda1;
        double r56100 = lambda2;
        double r56101 = r56099 - r56100;
        double r56102 = phi1;
        double r56103 = phi2;
        double r56104 = r56102 + r56103;
        double r56105 = 2.0;
        double r56106 = r56104 / r56105;
        double r56107 = cos(r56106);
        double r56108 = log1p(r56107);
        double r56109 = expm1(r56108);
        double r56110 = r56101 * r56109;
        double r56111 = r56102 - r56103;
        double r56112 = hypot(r56110, r56111);
        double r56113 = r56098 * r56112;
        return r56113;
}

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

    \[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 *-commutative3.7

    \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)}\]
  5. Using strategy rm
  6. Applied add-log-exp3.8

    \[\leadsto R \cdot \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)\]
  7. Using strategy rm
  8. Applied add-sqr-sqrt3.9

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

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(\sqrt{e^{\cos \left(\frac{\phi_1 + \phi_2}{2}\right)}} \cdot \sqrt{e^{\cos \left(\frac{\phi_1 + \phi_2}{2}\right)}}\right)\right)\right)}, \phi_1 - \phi_2\right)\]
  11. Simplified3.8

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)}\right), \phi_1 - \phi_2\right)\]
  12. Final simplification3.8

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \phi_1 - \phi_2\right)\]

Reproduce

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