Average Error: 37.3 → 0.1
Time: 57.2s
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(\mathsf{fma}\left(\sin \left(\frac{1}{2} \cdot \phi_2\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right), \lambda_2, \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right)\right) \cdot \left(\lambda_1 - \lambda_2\right) - \left(\lambda_1 \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right) + \mathsf{fma}\left(-\sin \left(\frac{1}{2} \cdot \phi_2\right), \sin \left(\phi_1 \cdot \frac{1}{2}\right), \sin \left(\frac{1}{2} \cdot \phi_2\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right) \cdot \left(\lambda_1 - \lambda_2\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(\mathsf{fma}\left(\sin \left(\frac{1}{2} \cdot \phi_2\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right), \lambda_2, \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right)\right) \cdot \left(\lambda_1 - \lambda_2\right) - \left(\lambda_1 \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right) + \mathsf{fma}\left(-\sin \left(\frac{1}{2} \cdot \phi_2\right), \sin \left(\phi_1 \cdot \frac{1}{2}\right), \sin \left(\frac{1}{2} \cdot \phi_2\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right) \cdot R
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r3847777 = R;
        double r3847778 = lambda1;
        double r3847779 = lambda2;
        double r3847780 = r3847778 - r3847779;
        double r3847781 = phi1;
        double r3847782 = phi2;
        double r3847783 = r3847781 + r3847782;
        double r3847784 = 2.0;
        double r3847785 = r3847783 / r3847784;
        double r3847786 = cos(r3847785);
        double r3847787 = r3847780 * r3847786;
        double r3847788 = r3847787 * r3847787;
        double r3847789 = r3847781 - r3847782;
        double r3847790 = r3847789 * r3847789;
        double r3847791 = r3847788 + r3847790;
        double r3847792 = sqrt(r3847791);
        double r3847793 = r3847777 * r3847792;
        return r3847793;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r3847794 = 0.5;
        double r3847795 = phi2;
        double r3847796 = r3847794 * r3847795;
        double r3847797 = sin(r3847796);
        double r3847798 = phi1;
        double r3847799 = r3847798 * r3847794;
        double r3847800 = sin(r3847799);
        double r3847801 = r3847797 * r3847800;
        double r3847802 = lambda2;
        double r3847803 = cos(r3847796);
        double r3847804 = cos(r3847799);
        double r3847805 = r3847803 * r3847804;
        double r3847806 = lambda1;
        double r3847807 = r3847806 - r3847802;
        double r3847808 = r3847805 * r3847807;
        double r3847809 = r3847806 * r3847800;
        double r3847810 = r3847809 * r3847797;
        double r3847811 = r3847808 - r3847810;
        double r3847812 = fma(r3847801, r3847802, r3847811);
        double r3847813 = -r3847797;
        double r3847814 = fma(r3847813, r3847800, r3847801);
        double r3847815 = r3847814 * r3847807;
        double r3847816 = r3847812 + r3847815;
        double r3847817 = r3847798 - r3847795;
        double r3847818 = hypot(r3847816, r3847817);
        double r3847819 = R;
        double r3847820 = r3847818 * r3847819;
        return r3847820;
}

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 37.3

    \[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}{\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.6

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

    \[\leadsto \mathsf{hypot}\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)}, \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(\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)}, \phi_1 - \phi_2\right) \cdot R\]
  7. Using strategy rm
  8. Applied prod-diff0.1

    \[\leadsto \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot \phi_1\right), \cos \left(\frac{1}{2} \cdot \phi_2\right), -\sin \left(\frac{1}{2} \cdot \phi_2\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right) + \mathsf{fma}\left(-\sin \left(\frac{1}{2} \cdot \phi_2\right), \sin \left(\frac{1}{2} \cdot \phi_1\right), \sin \left(\frac{1}{2} \cdot \phi_2\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)}, \phi_1 - \phi_2\right) \cdot R\]
  9. Applied distribute-lft-in0.1

    \[\leadsto \mathsf{hypot}\left(\color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot \phi_1\right), \cos \left(\frac{1}{2} \cdot \phi_2\right), -\sin \left(\frac{1}{2} \cdot \phi_2\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right) + \left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(-\sin \left(\frac{1}{2} \cdot \phi_2\right), \sin \left(\frac{1}{2} \cdot \phi_1\right), \sin \left(\frac{1}{2} \cdot \phi_2\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)}, \phi_1 - \phi_2\right) \cdot R\]
  10. Simplified0.1

    \[\leadsto \mathsf{hypot}\left(\color{blue}{\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) - \sin \left(\frac{1}{2} \cdot \phi_2\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)} + \left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(-\sin \left(\frac{1}{2} \cdot \phi_2\right), \sin \left(\frac{1}{2} \cdot \phi_1\right), \sin \left(\frac{1}{2} \cdot \phi_2\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right), \phi_1 - \phi_2\right) \cdot R\]
  11. Taylor expanded around -inf 0.1

    \[\leadsto \mathsf{hypot}\left(\color{blue}{\left(\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \lambda_1\right) + \sin \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_2 \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right) - \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) + \sin \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \lambda_1\right)\right)\right)} + \left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(-\sin \left(\frac{1}{2} \cdot \phi_2\right), \sin \left(\frac{1}{2} \cdot \phi_1\right), \sin \left(\frac{1}{2} \cdot \phi_2\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right), \phi_1 - \phi_2\right) \cdot R\]
  12. Simplified0.1

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

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

Reproduce

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