Average Error: 39.2 → 0.2
Time: 32.1s
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(\frac{\left({\left(\cos \left(0.5 \cdot \phi_2\right)\right)}^{2} \cdot {\left(\cos \left(0.5 \cdot \phi_1\right)\right)}^{2} - {\left(\sin \left(0.5 \cdot \phi_1\right)\right)}^{2} \cdot {\left(\sin \left(0.5 \cdot \phi_2\right)\right)}^{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)}{\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)}, \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(\frac{\left({\left(\cos \left(0.5 \cdot \phi_2\right)\right)}^{2} \cdot {\left(\cos \left(0.5 \cdot \phi_1\right)\right)}^{2} - {\left(\sin \left(0.5 \cdot \phi_1\right)\right)}^{2} \cdot {\left(\sin \left(0.5 \cdot \phi_2\right)\right)}^{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)}{\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)}, \phi_1 - \phi_2\right) \cdot R
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r59695 = R;
        double r59696 = lambda1;
        double r59697 = lambda2;
        double r59698 = r59696 - r59697;
        double r59699 = phi1;
        double r59700 = phi2;
        double r59701 = r59699 + r59700;
        double r59702 = 2.0;
        double r59703 = r59701 / r59702;
        double r59704 = cos(r59703);
        double r59705 = r59698 * r59704;
        double r59706 = r59705 * r59705;
        double r59707 = r59699 - r59700;
        double r59708 = r59707 * r59707;
        double r59709 = r59706 + r59708;
        double r59710 = sqrt(r59709);
        double r59711 = r59695 * r59710;
        return r59711;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r59712 = 0.5;
        double r59713 = phi2;
        double r59714 = r59712 * r59713;
        double r59715 = cos(r59714);
        double r59716 = 2.0;
        double r59717 = pow(r59715, r59716);
        double r59718 = phi1;
        double r59719 = r59712 * r59718;
        double r59720 = cos(r59719);
        double r59721 = pow(r59720, r59716);
        double r59722 = r59717 * r59721;
        double r59723 = sin(r59719);
        double r59724 = pow(r59723, r59716);
        double r59725 = sin(r59714);
        double r59726 = pow(r59725, r59716);
        double r59727 = r59724 * r59726;
        double r59728 = r59722 - r59727;
        double r59729 = lambda1;
        double r59730 = lambda2;
        double r59731 = r59729 - r59730;
        double r59732 = r59728 * r59731;
        double r59733 = r59713 * r59712;
        double r59734 = cos(r59733);
        double r59735 = r59718 * r59712;
        double r59736 = cos(r59735);
        double r59737 = r59734 * r59736;
        double r59738 = sin(r59733);
        double r59739 = sin(r59735);
        double r59740 = r59738 * r59739;
        double r59741 = r59737 + r59740;
        double r59742 = r59732 / r59741;
        double r59743 = r59718 - r59713;
        double r59744 = hypot(r59742, r59743);
        double r59745 = R;
        double r59746 = r59744 * r59745;
        return r59746;
}

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

    \[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_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right) \cdot R}\]
  3. Taylor expanded around inf 3.8

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

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

    \[\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 flip--0.1

    \[\leadsto \mathsf{hypot}\left(\color{blue}{\frac{\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right)\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right)\right) - \left(\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right) \cdot \left(\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)}{\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)}} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right) \cdot R\]
  12. Applied associate-*l/0.2

    \[\leadsto \mathsf{hypot}\left(\color{blue}{\frac{\left(\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right)\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right)\right) - \left(\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right) \cdot \left(\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)}{\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)}}, \phi_1 - \phi_2\right) \cdot R\]
  13. Simplified0.2

    \[\leadsto \mathsf{hypot}\left(\frac{\color{blue}{\left({\left(\cos \left(0.5 \cdot \phi_2\right)\right)}^{2} \cdot {\left(\cos \left(0.5 \cdot \phi_1\right)\right)}^{2} - {\left(\sin \left(0.5 \cdot \phi_1\right)\right)}^{2} \cdot {\left(\sin \left(0.5 \cdot \phi_2\right)\right)}^{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)}}{\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)}, \phi_1 - \phi_2\right) \cdot R\]
  14. Final simplification0.2

    \[\leadsto \mathsf{hypot}\left(\frac{\left({\left(\cos \left(0.5 \cdot \phi_2\right)\right)}^{2} \cdot {\left(\cos \left(0.5 \cdot \phi_1\right)\right)}^{2} - {\left(\sin \left(0.5 \cdot \phi_1\right)\right)}^{2} \cdot {\left(\sin \left(0.5 \cdot \phi_2\right)\right)}^{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)}{\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)}, \phi_1 - \phi_2\right) \cdot R\]

Reproduce

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