Average Error: 37.5 → 0.1
Time: 1.4m
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)}\]
\[\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right) - \log \left(e^{\sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)}\right)\right)\right)^2 + \left(\phi_1 - \phi_2\right)^2}^* \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)}
\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right) - \log \left(e^{\sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)}\right)\right)\right)^2 + \left(\phi_1 - \phi_2\right)^2}^* \cdot R
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r8851830 = R;
        double r8851831 = lambda1;
        double r8851832 = lambda2;
        double r8851833 = r8851831 - r8851832;
        double r8851834 = phi1;
        double r8851835 = phi2;
        double r8851836 = r8851834 + r8851835;
        double r8851837 = 2.0;
        double r8851838 = r8851836 / r8851837;
        double r8851839 = cos(r8851838);
        double r8851840 = r8851833 * r8851839;
        double r8851841 = r8851840 * r8851840;
        double r8851842 = r8851834 - r8851835;
        double r8851843 = r8851842 * r8851842;
        double r8851844 = r8851841 + r8851843;
        double r8851845 = sqrt(r8851844);
        double r8851846 = r8851830 * r8851845;
        return r8851846;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r8851847 = lambda1;
        double r8851848 = lambda2;
        double r8851849 = r8851847 - r8851848;
        double r8851850 = 0.5;
        double r8851851 = phi2;
        double r8851852 = r8851850 * r8851851;
        double r8851853 = cos(r8851852);
        double r8851854 = phi1;
        double r8851855 = r8851850 * r8851854;
        double r8851856 = cos(r8851855);
        double r8851857 = r8851853 * r8851856;
        double r8851858 = sin(r8851855);
        double r8851859 = sin(r8851852);
        double r8851860 = r8851858 * r8851859;
        double r8851861 = exp(r8851860);
        double r8851862 = log(r8851861);
        double r8851863 = r8851857 - r8851862;
        double r8851864 = r8851849 * r8851863;
        double r8851865 = r8851854 - r8851851;
        double r8851866 = hypot(r8851864, r8851865);
        double r8851867 = R;
        double r8851868 = r8851866 * r8851867;
        return r8851868;
}

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 37.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.6

    \[\leadsto \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_2 + \phi_1}{2}\right)\right)^2 + \left(\phi_1 - \phi_2\right)^2}^* \cdot R}\]
  3. Taylor expanded around -inf 3.6

    \[\leadsto \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}\right)^2 + \left(\phi_1 - \phi_2\right)^2}^* \cdot R\]
  4. Using strategy rm
  5. Applied distribute-lft-in3.6

    \[\leadsto \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_1 + \frac{1}{2} \cdot \phi_2\right)}\right)^2 + \left(\phi_1 - \phi_2\right)^2}^* \cdot R\]
  6. Applied cos-sum0.1

    \[\leadsto \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right) - \sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)}\right)^2 + \left(\phi_1 - \phi_2\right)^2}^* \cdot R\]
  7. Using strategy rm
  8. Applied add-log-exp0.1

    \[\leadsto \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right) - \color{blue}{\log \left(e^{\sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)}\right)}\right)\right)^2 + \left(\phi_1 - \phi_2\right)^2}^* \cdot R\]
  9. Final simplification0.1

    \[\leadsto \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right) - \log \left(e^{\sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)}\right)\right)\right)^2 + \left(\phi_1 - \phi_2\right)^2}^* \cdot R\]

Reproduce

herbie shell --seed 2019104 +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))) (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2)))) (* (- phi1 phi2) (- phi1 phi2))))))