Average Error: 39.5 → 0.1
Time: 34.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(\left(\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \log \left(e^{\sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}\right)\right) \cdot \left(\lambda_1 - \lambda_2\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(\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \log \left(e^{\sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}\right)\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right) \cdot R
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r3851568 = R;
        double r3851569 = lambda1;
        double r3851570 = lambda2;
        double r3851571 = r3851569 - r3851570;
        double r3851572 = phi1;
        double r3851573 = phi2;
        double r3851574 = r3851572 + r3851573;
        double r3851575 = 2.0;
        double r3851576 = r3851574 / r3851575;
        double r3851577 = cos(r3851576);
        double r3851578 = r3851571 * r3851577;
        double r3851579 = r3851578 * r3851578;
        double r3851580 = r3851572 - r3851573;
        double r3851581 = r3851580 * r3851580;
        double r3851582 = r3851579 + r3851581;
        double r3851583 = sqrt(r3851582);
        double r3851584 = r3851568 * r3851583;
        return r3851584;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r3851585 = phi1;
        double r3851586 = 0.5;
        double r3851587 = r3851585 * r3851586;
        double r3851588 = cos(r3851587);
        double r3851589 = phi2;
        double r3851590 = r3851586 * r3851589;
        double r3851591 = cos(r3851590);
        double r3851592 = r3851588 * r3851591;
        double r3851593 = sin(r3851590);
        double r3851594 = sin(r3851587);
        double r3851595 = r3851593 * r3851594;
        double r3851596 = exp(r3851595);
        double r3851597 = log(r3851596);
        double r3851598 = r3851592 - r3851597;
        double r3851599 = lambda1;
        double r3851600 = lambda2;
        double r3851601 = r3851599 - r3851600;
        double r3851602 = r3851598 * r3851601;
        double r3851603 = r3851585 - r3851589;
        double r3851604 = hypot(r3851602, r3851603);
        double r3851605 = R;
        double r3851606 = r3851604 * r3851605;
        return r3851606;
}

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. Taylor expanded around inf 3.8

    \[\leadsto \mathsf{hypot}\left(\color{blue}{\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) - \lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}, \phi_1 - \phi_2\right) \cdot R\]
  4. Simplified3.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\]
  5. Using strategy rm
  6. 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\]
  7. 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\]
  8. Using strategy rm
  9. Applied add-log-exp0.1

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

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

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