R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\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({\sin \left(\frac{\phi_1 - \phi_2}{2}\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)R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \left(\log \left(\sqrt{e^{\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}\right) + \left(\log \left(\sqrt{e^{\sin \left(\frac{\lambda_1}{2}\right) \cdot \cos \left(\frac{\lambda_2}{2}\right)}}\right) - \log \left(\sqrt{e^{\cos \left(\frac{\lambda_1}{2}\right) \cdot \sin \left(\frac{\lambda_2}{2}\right)}}\right)\right)\right)\right)}}\right)(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
R
(*
2.0
(atan2
(sqrt
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(*
(* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0)))
(sin (/ (- lambda1 lambda2) 2.0)))))
(sqrt
(-
1.0
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(*
(* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0)))
(sin (/ (- lambda1 lambda2) 2.0))))))))))(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
R
(*
2.0
(atan2
(sqrt
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(*
(sin (/ (- lambda1 lambda2) 2.0))
(* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0))))))
(sqrt
(-
1.0
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(*
(* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0)))
(+
(log (sqrt (exp (sin (/ (- lambda1 lambda2) 2.0)))))
(-
(log (sqrt (exp (* (sin (/ lambda1 2.0)) (cos (/ lambda2 2.0))))))
(log
(sqrt
(exp (* (cos (/ lambda1 2.0)) (sin (/ lambda2 2.0))))))))))))))))double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * (2.0 * atan2(sqrt(pow(sin((phi1 - phi2) / 2.0), 2.0) + (((cos(phi1) * cos(phi2)) * sin((lambda1 - lambda2) / 2.0)) * sin((lambda1 - lambda2) / 2.0))), sqrt(1.0 - (pow(sin((phi1 - phi2) / 2.0), 2.0) + (((cos(phi1) * cos(phi2)) * sin((lambda1 - lambda2) / 2.0)) * sin((lambda1 - lambda2) / 2.0))))));
}
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * (2.0 * atan2(sqrt(pow(sin((phi1 - phi2) / 2.0), 2.0) + (sin((lambda1 - lambda2) / 2.0) * ((cos(phi1) * cos(phi2)) * sin((lambda1 - lambda2) / 2.0)))), sqrt(1.0 - (pow(sin((phi1 - phi2) / 2.0), 2.0) + (((cos(phi1) * cos(phi2)) * sin((lambda1 - lambda2) / 2.0)) * (log(sqrt(exp(sin((lambda1 - lambda2) / 2.0)))) + (log(sqrt(exp(sin(lambda1 / 2.0) * cos(lambda2 / 2.0)))) - log(sqrt(exp(cos(lambda1 / 2.0) * sin(lambda2 / 2.0)))))))))));
}



Bits error versus R



Bits error versus lambda1



Bits error versus lambda2



Bits error versus phi1



Bits error versus phi2
Results
Initial program 24.3
rmApplied add-log-exp_binary64_489124.3
rmApplied add-sqr-sqrt_binary64_487424.3
Applied log-prod_binary64_493824.3
rmApplied div-sub_binary64_485724.3
Applied sin-diff_binary64_498824.4
Applied exp-diff_binary64_490024.4
Applied sqrt-div_binary64_486924.4
Applied log-div_binary64_493924.3
Final simplification24.3
herbie shell --seed 2020356
(FPCore (R lambda1 lambda2 phi1 phi2)
:name "Distance on a great circle"
:precision binary64
(* R (* 2.0 (atan2 (sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0))) (sin (/ (- lambda1 lambda2) 2.0))))) (sqrt (- 1.0 (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0))) (sin (/ (- lambda1 lambda2) 2.0))))))))))