Average Error: 24.1 → 24.0
Time: 50.2s
Precision: 64
\[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right)\]
\[\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right), \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \sin \left(\frac{\phi_1 - \phi_2}{2}\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)\right)\right)}}{\sqrt{\log \left(e^{\cos \left(\frac{\phi_1 - \phi_2}{2}\right)}\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(e^{\cos \left(\frac{\phi_1 - \phi_2}{2}\right)}\right)\right)\right) - \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}} \cdot \left(R + R\right)\]
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right)
\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right), \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \sin \left(\frac{\phi_1 - \phi_2}{2}\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)\right)\right)}}{\sqrt{\log \left(e^{\cos \left(\frac{\phi_1 - \phi_2}{2}\right)}\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(e^{\cos \left(\frac{\phi_1 - \phi_2}{2}\right)}\right)\right)\right) - \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}} \cdot \left(R + R\right)
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r3921210 = R;
        double r3921211 = 2.0;
        double r3921212 = phi1;
        double r3921213 = phi2;
        double r3921214 = r3921212 - r3921213;
        double r3921215 = r3921214 / r3921211;
        double r3921216 = sin(r3921215);
        double r3921217 = pow(r3921216, r3921211);
        double r3921218 = cos(r3921212);
        double r3921219 = cos(r3921213);
        double r3921220 = r3921218 * r3921219;
        double r3921221 = lambda1;
        double r3921222 = lambda2;
        double r3921223 = r3921221 - r3921222;
        double r3921224 = r3921223 / r3921211;
        double r3921225 = sin(r3921224);
        double r3921226 = r3921220 * r3921225;
        double r3921227 = r3921226 * r3921225;
        double r3921228 = r3921217 + r3921227;
        double r3921229 = sqrt(r3921228);
        double r3921230 = 1.0;
        double r3921231 = r3921230 - r3921228;
        double r3921232 = sqrt(r3921231);
        double r3921233 = atan2(r3921229, r3921232);
        double r3921234 = r3921211 * r3921233;
        double r3921235 = r3921210 * r3921234;
        return r3921235;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r3921236 = lambda1;
        double r3921237 = lambda2;
        double r3921238 = r3921236 - r3921237;
        double r3921239 = 2.0;
        double r3921240 = r3921238 / r3921239;
        double r3921241 = sin(r3921240);
        double r3921242 = phi1;
        double r3921243 = cos(r3921242);
        double r3921244 = phi2;
        double r3921245 = cos(r3921244);
        double r3921246 = r3921243 * r3921245;
        double r3921247 = r3921241 * r3921246;
        double r3921248 = r3921242 - r3921244;
        double r3921249 = r3921248 / r3921239;
        double r3921250 = sin(r3921249);
        double r3921251 = expm1(r3921250);
        double r3921252 = log1p(r3921251);
        double r3921253 = r3921250 * r3921252;
        double r3921254 = fma(r3921247, r3921241, r3921253);
        double r3921255 = sqrt(r3921254);
        double r3921256 = cos(r3921249);
        double r3921257 = exp(r3921256);
        double r3921258 = log(r3921257);
        double r3921259 = expm1(r3921258);
        double r3921260 = log1p(r3921259);
        double r3921261 = r3921258 * r3921260;
        double r3921262 = r3921247 * r3921241;
        double r3921263 = r3921261 - r3921262;
        double r3921264 = sqrt(r3921263);
        double r3921265 = atan2(r3921255, r3921264);
        double r3921266 = R;
        double r3921267 = r3921266 + r3921266;
        double r3921268 = r3921265 * r3921267;
        return r3921268;
}

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 24.1

    \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right)\]
  2. Simplified24.0

    \[\leadsto \color{blue}{\left(R + R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \sin \left(\frac{\phi_1 - \phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}}{\sqrt{\cos \left(\frac{\phi_1 - \phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1 - \phi_2}{2}\right) - \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}}\]
  3. Using strategy rm
  4. Applied log1p-expm1-u24.0

    \[\leadsto \left(R + R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \sin \left(\frac{\phi_1 - \phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}}{\sqrt{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\frac{\phi_1 - \phi_2}{2}\right)\right)\right)} \cdot \cos \left(\frac{\phi_1 - \phi_2}{2}\right) - \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}\]
  5. Using strategy rm
  6. Applied add-log-exp24.0

    \[\leadsto \left(R + R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \sin \left(\frac{\phi_1 - \phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}}{\sqrt{\mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\log \left(e^{\cos \left(\frac{\phi_1 - \phi_2}{2}\right)}\right)}\right)\right) \cdot \cos \left(\frac{\phi_1 - \phi_2}{2}\right) - \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}\]
  7. Using strategy rm
  8. Applied add-log-exp24.0

    \[\leadsto \left(R + R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \sin \left(\frac{\phi_1 - \phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}}{\sqrt{\mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(e^{\cos \left(\frac{\phi_1 - \phi_2}{2}\right)}\right)\right)\right) \cdot \color{blue}{\log \left(e^{\cos \left(\frac{\phi_1 - \phi_2}{2}\right)}\right)} - \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}\]
  9. Using strategy rm
  10. Applied log1p-expm1-u24.0

    \[\leadsto \left(R + R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \sin \left(\frac{\phi_1 - \phi_2}{2}\right) \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)\right)}\right)}}{\sqrt{\mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(e^{\cos \left(\frac{\phi_1 - \phi_2}{2}\right)}\right)\right)\right) \cdot \log \left(e^{\cos \left(\frac{\phi_1 - \phi_2}{2}\right)}\right) - \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}\]
  11. Final simplification24.0

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

Reproduce

herbie shell --seed 2019164 +o rules:numerics
(FPCore (R lambda1 lambda2 phi1 phi2)
  :name "Distance on a great circle"
  (* R (* 2 (atan2 (sqrt (+ (pow (sin (/ (- phi1 phi2) 2)) 2) (* (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2))) (sin (/ (- lambda1 lambda2) 2))))) (sqrt (- 1 (+ (pow (sin (/ (- phi1 phi2) 2)) 2) (* (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2))) (sin (/ (- lambda1 lambda2) 2))))))))))