Average Error: 39.3 → 0.1
Time: 43.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(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1, \cos \left(\phi_2 \cdot 0.5\right), \lambda_2 \cdot \left(\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) - \mathsf{fma}\left(\sin \left(0.5 \cdot \phi_1\right) \cdot \lambda_1, \sin \left(\phi_2 \cdot 0.5\right), \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\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(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1, \cos \left(\phi_2 \cdot 0.5\right), \lambda_2 \cdot \left(\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) - \mathsf{fma}\left(\sin \left(0.5 \cdot \phi_1\right) \cdot \lambda_1, \sin \left(\phi_2 \cdot 0.5\right), \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2\right) \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right) \cdot R
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r148865 = R;
        double r148866 = lambda1;
        double r148867 = lambda2;
        double r148868 = r148866 - r148867;
        double r148869 = phi1;
        double r148870 = phi2;
        double r148871 = r148869 + r148870;
        double r148872 = 2.0;
        double r148873 = r148871 / r148872;
        double r148874 = cos(r148873);
        double r148875 = r148868 * r148874;
        double r148876 = r148875 * r148875;
        double r148877 = r148869 - r148870;
        double r148878 = r148877 * r148877;
        double r148879 = r148876 + r148878;
        double r148880 = sqrt(r148879);
        double r148881 = r148865 * r148880;
        return r148881;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r148882 = 0.5;
        double r148883 = phi1;
        double r148884 = r148882 * r148883;
        double r148885 = cos(r148884);
        double r148886 = lambda1;
        double r148887 = r148885 * r148886;
        double r148888 = phi2;
        double r148889 = r148888 * r148882;
        double r148890 = cos(r148889);
        double r148891 = lambda2;
        double r148892 = sin(r148889);
        double r148893 = sin(r148884);
        double r148894 = r148892 * r148893;
        double r148895 = r148891 * r148894;
        double r148896 = r148893 * r148886;
        double r148897 = r148885 * r148891;
        double r148898 = r148897 * r148890;
        double r148899 = fma(r148896, r148892, r148898);
        double r148900 = r148895 - r148899;
        double r148901 = fma(r148887, r148890, r148900);
        double r148902 = r148883 - r148888;
        double r148903 = hypot(r148901, r148902);
        double r148904 = R;
        double r148905 = r148903 * r148904;
        return r148905;
}

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

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

    \[\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-lft-in3.7

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

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

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

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

Reproduce

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