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{{\left(\cos \left(-0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot 0.5\right)\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{\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) + {\left(\sqrt[3]{{\left(\sqrt[3]{{\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{3}}\right)}^{3}}\right)}^{2}\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
(-
(* (cos (* -0.5 phi2)) (sin (* 0.5 phi1)))
(* (cos (* 0.5 phi1)) (sin (* phi2 0.5))))
2.0)
(*
(sin (/ (- lambda1 lambda2) 2.0))
(* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0))))))
(sqrt
(-
1.0
(+
(*
(sin (/ (- lambda1 lambda2) 2.0))
(* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0))))
(pow
(cbrt
(pow
(cbrt
(pow
(-
(* (sin (/ phi1 2.0)) (cos (/ phi2 2.0)))
(* (cos (/ phi1 2.0)) (sin (/ phi2 2.0))))
3.0))
3.0))
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(((cos(-0.5 * phi2) * sin(0.5 * phi1)) - (cos(0.5 * phi1) * sin(phi2 * 0.5))), 2.0) + (sin((lambda1 - lambda2) / 2.0) * ((cos(phi1) * cos(phi2)) * sin((lambda1 - lambda2) / 2.0)))), sqrt(1.0 - ((sin((lambda1 - lambda2) / 2.0) * ((cos(phi1) * cos(phi2)) * sin((lambda1 - lambda2) / 2.0))) + pow(cbrt(pow(cbrt(pow(((sin(phi1 / 2.0) * cos(phi2 / 2.0)) - (cos(phi1 / 2.0) * sin(phi2 / 2.0))), 3.0)), 3.0)), 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.2
rmApplied add-cbrt-cube_binary6424.3
Simplified24.3
rmApplied add-cbrt-cube_binary6424.3
Simplified24.3
rmApplied div-sub_binary6424.3
Applied sin-diff_binary6423.7
Simplified23.7
Simplified23.7
rmApplied div-sub_binary6423.7
Applied sin-diff_binary6413.7
Final simplification13.7
herbie shell --seed 2021175
(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))))))))))