Average Error: 39.9 → 0.1
Time: 28.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 \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(\phi_1 \cdot 0.5\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(0.5 \cdot \phi_2\right) \cdot \cos \left(\phi_1 \cdot 0.5\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 r2151532 = R;
        double r2151533 = lambda1;
        double r2151534 = lambda2;
        double r2151535 = r2151533 - r2151534;
        double r2151536 = phi1;
        double r2151537 = phi2;
        double r2151538 = r2151536 + r2151537;
        double r2151539 = 2.0;
        double r2151540 = r2151538 / r2151539;
        double r2151541 = cos(r2151540);
        double r2151542 = r2151535 * r2151541;
        double r2151543 = r2151542 * r2151542;
        double r2151544 = r2151536 - r2151537;
        double r2151545 = r2151544 * r2151544;
        double r2151546 = r2151543 + r2151545;
        double r2151547 = sqrt(r2151546);
        double r2151548 = r2151532 * r2151547;
        return r2151548;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r2151549 = R;
        double r2151550 = lambda1;
        double r2151551 = lambda2;
        double r2151552 = r2151550 - r2151551;
        double r2151553 = 0.5;
        double r2151554 = phi2;
        double r2151555 = r2151553 * r2151554;
        double r2151556 = cos(r2151555);
        double r2151557 = phi1;
        double r2151558 = r2151557 * r2151553;
        double r2151559 = cos(r2151558);
        double r2151560 = r2151556 * r2151559;
        double r2151561 = sin(r2151555);
        double r2151562 = sin(r2151558);
        double r2151563 = r2151561 * r2151562;
        double r2151564 = r2151560 - r2151563;
        double r2151565 = r2151552 * r2151564;
        double r2151566 = r2151557 - r2151554;
        double r2151567 = hypot(r2151565, r2151566);
        double r2151568 = r2151549 * r2151567;
        return r2151568;
}

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

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

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

    \[\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-lft-in3.9

    \[\leadsto \mathsf{hypot}\left(\cos \color{blue}{\left(0.5 \cdot \phi_1 + 0.5 \cdot \phi_2\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_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right) \cdot R\]
  8. Using strategy rm
  9. Applied *-commutative0.1

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

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