(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
(let* ((t_0 (cos (* phi2 0.5)))
(t_1 (cos (* 0.5 phi1)))
(t_2 (sin (* phi2 0.5)))
(t_3 (sin (/ (- lambda1 lambda2) 2.0)))
(t_4 (sin (* 0.5 phi1))))
(*
R
(*
2.0
(atan2
(sqrt
(+
(+
(*
(cos phi2)
(* (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0) (cos phi1)))
(+ (* (pow t_4 2.0) (pow t_0 2.0)) (* (pow t_1 2.0) (pow t_2 2.0))))
(* (* t_1 (* t_4 (* t_0 t_2))) -2.0)))
(sqrt
(-
1.0
(+
(pow
(-
(* (sin (/ phi1 2.0)) (cos (/ phi2 2.0)))
(* (cos (/ phi1 2.0)) (sin (/ phi2 2.0))))
2.0)
(* t_3 (* (* (cos phi2) (cos phi1)) t_3))))))))))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) {
double t_0 = cos((phi2 * 0.5));
double t_1 = cos((0.5 * phi1));
double t_2 = sin((phi2 * 0.5));
double t_3 = sin(((lambda1 - lambda2) / 2.0));
double t_4 = sin((0.5 * phi1));
return R * (2.0 * atan2(sqrt((((cos(phi2) * (pow(sin((0.5 * (lambda1 - lambda2))), 2.0) * cos(phi1))) + ((pow(t_4, 2.0) * pow(t_0, 2.0)) + (pow(t_1, 2.0) * pow(t_2, 2.0)))) + ((t_1 * (t_4 * (t_0 * t_2))) * -2.0))), sqrt((1.0 - (pow(((sin((phi1 / 2.0)) * cos((phi2 / 2.0))) - (cos((phi1 / 2.0)) * sin((phi2 / 2.0)))), 2.0) + (t_3 * ((cos(phi2) * cos(phi1)) * t_3)))))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
code = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (((cos(phi1) * cos(phi2)) * sin(((lambda1 - lambda2) / 2.0d0))) * sin(((lambda1 - lambda2) / 2.0d0))))), sqrt((1.0d0 - ((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (((cos(phi1) * cos(phi2)) * sin(((lambda1 - lambda2) / 2.0d0))) * sin(((lambda1 - lambda2) / 2.0d0))))))))
end function
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: t_4
t_0 = cos((phi2 * 0.5d0))
t_1 = cos((0.5d0 * phi1))
t_2 = sin((phi2 * 0.5d0))
t_3 = sin(((lambda1 - lambda2) / 2.0d0))
t_4 = sin((0.5d0 * phi1))
code = r * (2.0d0 * atan2(sqrt((((cos(phi2) * ((sin((0.5d0 * (lambda1 - lambda2))) ** 2.0d0) * cos(phi1))) + (((t_4 ** 2.0d0) * (t_0 ** 2.0d0)) + ((t_1 ** 2.0d0) * (t_2 ** 2.0d0)))) + ((t_1 * (t_4 * (t_0 * t_2))) * (-2.0d0)))), sqrt((1.0d0 - ((((sin((phi1 / 2.0d0)) * cos((phi2 / 2.0d0))) - (cos((phi1 / 2.0d0)) * sin((phi2 / 2.0d0)))) ** 2.0d0) + (t_3 * ((cos(phi2) * cos(phi1)) * t_3)))))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (((Math.cos(phi1) * Math.cos(phi2)) * Math.sin(((lambda1 - lambda2) / 2.0))) * Math.sin(((lambda1 - lambda2) / 2.0))))), Math.sqrt((1.0 - (Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (((Math.cos(phi1) * Math.cos(phi2)) * Math.sin(((lambda1 - lambda2) / 2.0))) * Math.sin(((lambda1 - lambda2) / 2.0))))))));
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.cos((phi2 * 0.5));
double t_1 = Math.cos((0.5 * phi1));
double t_2 = Math.sin((phi2 * 0.5));
double t_3 = Math.sin(((lambda1 - lambda2) / 2.0));
double t_4 = Math.sin((0.5 * phi1));
return R * (2.0 * Math.atan2(Math.sqrt((((Math.cos(phi2) * (Math.pow(Math.sin((0.5 * (lambda1 - lambda2))), 2.0) * Math.cos(phi1))) + ((Math.pow(t_4, 2.0) * Math.pow(t_0, 2.0)) + (Math.pow(t_1, 2.0) * Math.pow(t_2, 2.0)))) + ((t_1 * (t_4 * (t_0 * t_2))) * -2.0))), Math.sqrt((1.0 - (Math.pow(((Math.sin((phi1 / 2.0)) * Math.cos((phi2 / 2.0))) - (Math.cos((phi1 / 2.0)) * Math.sin((phi2 / 2.0)))), 2.0) + (t_3 * ((Math.cos(phi2) * Math.cos(phi1)) * t_3)))))));
}
def code(R, lambda1, lambda2, phi1, phi2): return R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (((math.cos(phi1) * math.cos(phi2)) * math.sin(((lambda1 - lambda2) / 2.0))) * math.sin(((lambda1 - lambda2) / 2.0))))), math.sqrt((1.0 - (math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (((math.cos(phi1) * math.cos(phi2)) * math.sin(((lambda1 - lambda2) / 2.0))) * math.sin(((lambda1 - lambda2) / 2.0))))))))
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.cos((phi2 * 0.5)) t_1 = math.cos((0.5 * phi1)) t_2 = math.sin((phi2 * 0.5)) t_3 = math.sin(((lambda1 - lambda2) / 2.0)) t_4 = math.sin((0.5 * phi1)) return R * (2.0 * math.atan2(math.sqrt((((math.cos(phi2) * (math.pow(math.sin((0.5 * (lambda1 - lambda2))), 2.0) * math.cos(phi1))) + ((math.pow(t_4, 2.0) * math.pow(t_0, 2.0)) + (math.pow(t_1, 2.0) * math.pow(t_2, 2.0)))) + ((t_1 * (t_4 * (t_0 * t_2))) * -2.0))), math.sqrt((1.0 - (math.pow(((math.sin((phi1 / 2.0)) * math.cos((phi2 / 2.0))) - (math.cos((phi1 / 2.0)) * math.sin((phi2 / 2.0)))), 2.0) + (t_3 * ((math.cos(phi2) * math.cos(phi1)) * t_3)))))))
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * sin(Float64(Float64(lambda1 - lambda2) / 2.0))) * sin(Float64(Float64(lambda1 - lambda2) / 2.0))))), sqrt(Float64(1.0 - Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * sin(Float64(Float64(lambda1 - lambda2) / 2.0))) * sin(Float64(Float64(lambda1 - lambda2) / 2.0))))))))) end
function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(phi2 * 0.5)) t_1 = cos(Float64(0.5 * phi1)) t_2 = sin(Float64(phi2 * 0.5)) t_3 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_4 = sin(Float64(0.5 * phi1)) return Float64(R * Float64(2.0 * atan(sqrt(Float64(Float64(Float64(cos(phi2) * Float64((sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0) * cos(phi1))) + Float64(Float64((t_4 ^ 2.0) * (t_0 ^ 2.0)) + Float64((t_1 ^ 2.0) * (t_2 ^ 2.0)))) + Float64(Float64(t_1 * Float64(t_4 * Float64(t_0 * t_2))) * -2.0))), sqrt(Float64(1.0 - Float64((Float64(Float64(sin(Float64(phi1 / 2.0)) * cos(Float64(phi2 / 2.0))) - Float64(cos(Float64(phi1 / 2.0)) * sin(Float64(phi2 / 2.0)))) ^ 2.0) + Float64(t_3 * Float64(Float64(cos(phi2) * cos(phi1)) * t_3)))))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (((cos(phi1) * cos(phi2)) * sin(((lambda1 - lambda2) / 2.0))) * sin(((lambda1 - lambda2) / 2.0))))), sqrt((1.0 - ((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (((cos(phi1) * cos(phi2)) * sin(((lambda1 - lambda2) / 2.0))) * sin(((lambda1 - lambda2) / 2.0)))))))); end
function tmp = code(R, lambda1, lambda2, phi1, phi2) t_0 = cos((phi2 * 0.5)); t_1 = cos((0.5 * phi1)); t_2 = sin((phi2 * 0.5)); t_3 = sin(((lambda1 - lambda2) / 2.0)); t_4 = sin((0.5 * phi1)); tmp = R * (2.0 * atan2(sqrt((((cos(phi2) * ((sin((0.5 * (lambda1 - lambda2))) ^ 2.0) * cos(phi1))) + (((t_4 ^ 2.0) * (t_0 ^ 2.0)) + ((t_1 ^ 2.0) * (t_2 ^ 2.0)))) + ((t_1 * (t_4 * (t_0 * t_2))) * -2.0))), sqrt((1.0 - ((((sin((phi1 / 2.0)) * cos((phi2 / 2.0))) - (cos((phi1 / 2.0)) * sin((phi2 / 2.0)))) ^ 2.0) + (t_3 * ((cos(phi2) * cos(phi1)) * t_3))))))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[(N[(N[Cos[phi2], $MachinePrecision] * N[(N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[t$95$4, 2.0], $MachinePrecision] * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[Power[t$95$1, 2.0], $MachinePrecision] * N[Power[t$95$2, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(t$95$1 * N[(t$95$4 * N[(t$95$0 * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Power[N[(N[(N[Sin[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$3 * N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
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)
\begin{array}{l}
t_0 := \cos \left(\phi_2 \cdot 0.5\right)\\
t_1 := \cos \left(0.5 \cdot \phi_1\right)\\
t_2 := \sin \left(\phi_2 \cdot 0.5\right)\\
t_3 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_4 := \sin \left(0.5 \cdot \phi_1\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\left(\cos \phi_2 \cdot \left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_1\right) + \left({t_4}^{2} \cdot {t_0}^{2} + {t_1}^{2} \cdot {t_2}^{2}\right)\right) + \left(t_1 \cdot \left(t_4 \cdot \left(t_0 \cdot t_2\right)\right)\right) \cdot -2}}{\sqrt{1 - \left({\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)}^{2} + t_3 \cdot \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t_3\right)\right)}}\right)
\end{array}



Bits error versus R



Bits error versus lambda1



Bits error versus lambda2



Bits error versus phi1



Bits error versus phi2
Results
Initial program 24.7
Applied egg-rr24.1
Applied egg-rr14.3
Taylor expanded in phi2 around inf 14.3
Final simplification14.3
herbie shell --seed 2022159
(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))))))))))