Average Error: 38.9 → 0.1
Time: 1.3m
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 \mathsf{fma}\left(\cos \left(\phi_1 \cdot 0.5\right), \cos \left(\phi_2 \cdot 0.5\right), \sin \left(\phi_2 \cdot 0.5\right) \cdot \left(-\sin \left(\phi_1 \cdot 0.5\right)\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 \mathsf{fma}\left(\cos \left(\phi_1 \cdot 0.5\right), \cos \left(\phi_2 \cdot 0.5\right), \sin \left(\phi_2 \cdot 0.5\right) \cdot \left(-\sin \left(\phi_1 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right)
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r4728801 = R;
        double r4728802 = lambda1;
        double r4728803 = lambda2;
        double r4728804 = r4728802 - r4728803;
        double r4728805 = phi1;
        double r4728806 = phi2;
        double r4728807 = r4728805 + r4728806;
        double r4728808 = 2.0;
        double r4728809 = r4728807 / r4728808;
        double r4728810 = cos(r4728809);
        double r4728811 = r4728804 * r4728810;
        double r4728812 = r4728811 * r4728811;
        double r4728813 = r4728805 - r4728806;
        double r4728814 = r4728813 * r4728813;
        double r4728815 = r4728812 + r4728814;
        double r4728816 = sqrt(r4728815);
        double r4728817 = r4728801 * r4728816;
        return r4728817;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r4728818 = R;
        double r4728819 = lambda1;
        double r4728820 = lambda2;
        double r4728821 = r4728819 - r4728820;
        double r4728822 = phi1;
        double r4728823 = 0.5;
        double r4728824 = r4728822 * r4728823;
        double r4728825 = cos(r4728824);
        double r4728826 = phi2;
        double r4728827 = r4728826 * r4728823;
        double r4728828 = cos(r4728827);
        double r4728829 = sin(r4728827);
        double r4728830 = sin(r4728824);
        double r4728831 = -r4728830;
        double r4728832 = r4728829 * r4728831;
        double r4728833 = fma(r4728825, r4728828, r4728832);
        double r4728834 = r4728821 * r4728833;
        double r4728835 = r4728822 - r4728826;
        double r4728836 = hypot(r4728834, r4728835);
        double r4728837 = r4728818 * r4728836;
        return r4728837;
}

Error

Bits error versus R

Bits error versus lambda1

Bits error versus lambda2

Bits error versus phi1

Bits error versus phi2

Derivation

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

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

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

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

Reproduce

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