Average Error: 39.2 → 0.2
Time: 56.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(\frac{\left(\lambda_1 - \lambda_2\right) \cdot \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)}{\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(\lambda_1 - \lambda_2\right) \cdot \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)}{\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 r150773 = R;
        double r150774 = lambda1;
        double r150775 = lambda2;
        double r150776 = r150774 - r150775;
        double r150777 = phi1;
        double r150778 = phi2;
        double r150779 = r150777 + r150778;
        double r150780 = 2.0;
        double r150781 = r150779 / r150780;
        double r150782 = cos(r150781);
        double r150783 = r150776 * r150782;
        double r150784 = r150783 * r150783;
        double r150785 = r150777 - r150778;
        double r150786 = r150785 * r150785;
        double r150787 = r150784 + r150786;
        double r150788 = sqrt(r150787);
        double r150789 = r150773 * r150788;
        return r150789;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r150790 = lambda1;
        double r150791 = lambda2;
        double r150792 = r150790 - r150791;
        double r150793 = 0.5;
        double r150794 = phi2;
        double r150795 = r150793 * r150794;
        double r150796 = cos(r150795);
        double r150797 = 2.0;
        double r150798 = pow(r150796, r150797);
        double r150799 = phi1;
        double r150800 = r150793 * r150799;
        double r150801 = cos(r150800);
        double r150802 = pow(r150801, r150797);
        double r150803 = r150798 * r150802;
        double r150804 = sin(r150800);
        double r150805 = pow(r150804, r150797);
        double r150806 = sin(r150795);
        double r150807 = pow(r150806, r150797);
        double r150808 = r150805 * r150807;
        double r150809 = r150803 - r150808;
        double r150810 = r150792 * r150809;
        double r150811 = r150794 * r150793;
        double r150812 = cos(r150811);
        double r150813 = r150799 * r150793;
        double r150814 = cos(r150813);
        double r150815 = r150812 * r150814;
        double r150816 = sin(r150811);
        double r150817 = sin(r150813);
        double r150818 = r150816 * r150817;
        double r150819 = r150815 + r150818;
        double r150820 = r150810 / r150819;
        double r150821 = r150799 - r150794;
        double r150822 = hypot(r150820, r150821);
        double r150823 = R;
        double r150824 = r150822 * r150823;
        return r150824;
}

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(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)}, \phi_1 - \phi_2\right) \cdot R\]
  4. Using strategy rm
  5. Applied distribute-lft-in3.8

    \[\leadsto \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(0.5 \cdot \phi_2 + 0.5 \cdot \phi_1\right)}, \phi_1 - \phi_2\right) \cdot R\]
  6. Applied cos-sum0.1

    \[\leadsto \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \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)}, \phi_1 - \phi_2\right) \cdot R\]
  7. Simplified0.1

    \[\leadsto \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \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), \phi_1 - \phi_2\right) \cdot R\]
  8. Simplified0.1

    \[\leadsto \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \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), \phi_1 - \phi_2\right) \cdot R\]
  9. Using strategy rm
  10. Applied flip--0.1

    \[\leadsto \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \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)}}, \phi_1 - \phi_2\right) \cdot R\]
  11. Applied associate-*r/0.2

    \[\leadsto \mathsf{hypot}\left(\color{blue}{\frac{\left(\lambda_1 - \lambda_2\right) \cdot \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)}{\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\]
  12. Simplified0.2

    \[\leadsto \mathsf{hypot}\left(\frac{\color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \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)}}{\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. Final simplification0.2

    \[\leadsto \mathsf{hypot}\left(\frac{\left(\lambda_1 - \lambda_2\right) \cdot \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)}{\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))))))