Average Error: 39.1 → 0.1
Time: 9.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(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \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)\]
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(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \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)
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r85219 = R;
        double r85220 = lambda1;
        double r85221 = lambda2;
        double r85222 = r85220 - r85221;
        double r85223 = phi1;
        double r85224 = phi2;
        double r85225 = r85223 + r85224;
        double r85226 = 2.0;
        double r85227 = r85225 / r85226;
        double r85228 = cos(r85227);
        double r85229 = r85222 * r85228;
        double r85230 = r85229 * r85229;
        double r85231 = r85223 - r85224;
        double r85232 = r85231 * r85231;
        double r85233 = r85230 + r85232;
        double r85234 = sqrt(r85233);
        double r85235 = r85219 * r85234;
        return r85235;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r85236 = R;
        double r85237 = phi2;
        double r85238 = 0.5;
        double r85239 = r85237 * r85238;
        double r85240 = cos(r85239);
        double r85241 = phi1;
        double r85242 = r85241 * r85238;
        double r85243 = cos(r85242);
        double r85244 = r85240 * r85243;
        double r85245 = sin(r85239);
        double r85246 = sin(r85242);
        double r85247 = r85245 * r85246;
        double r85248 = r85244 - r85247;
        double r85249 = lambda1;
        double r85250 = lambda2;
        double r85251 = r85249 - r85250;
        double r85252 = r85248 * r85251;
        double r85253 = r85241 - r85237;
        double r85254 = hypot(r85252, r85253);
        double r85255 = r85236 * r85254;
        return r85255;
}

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

    \[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. Using strategy rm
  11. Applied *-commutative0.1

    \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \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)}\]
  12. Final simplification0.1

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

Reproduce

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