\[ \begin{array}{c}[phi1, phi2] = \mathsf{sort}([phi1, phi2])\\ \end{array} \]
\[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R
\]
↓
\[\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \left(\left(\cos \phi_2 \cdot \cos \lambda_1\right) \cdot \cos \lambda_2\right) \cdot \cos \phi_1 + \cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \left(\cos \phi_2 \cdot \sin \lambda_2\right)\right)\right)\right) \cdot R
\]
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
(acos
(+
(* (sin phi1) (sin phi2))
(* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2)))))
R))↓
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
(acos
(fma
(sin phi1)
(sin phi2)
(+
(* (* (* (cos phi2) (cos lambda1)) (cos lambda2)) (cos phi1))
(* (cos phi1) (* (sin lambda1) (* (cos phi2) (sin lambda2)))))))
R))double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * R;
}
↓
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return acos(fma(sin(phi1), sin(phi2), ((((cos(phi2) * cos(lambda1)) * cos(lambda2)) * cos(phi1)) + (cos(phi1) * (sin(lambda1) * (cos(phi2) * sin(lambda2))))))) * R;
}
function code(R, lambda1, lambda2, phi1, phi2)
return Float64(acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2))))) * R)
end
↓
function code(R, lambda1, lambda2, phi1, phi2)
return Float64(acos(fma(sin(phi1), sin(phi2), Float64(Float64(Float64(Float64(cos(phi2) * cos(lambda1)) * cos(lambda2)) * cos(phi1)) + Float64(cos(phi1) * Float64(sin(lambda1) * Float64(cos(phi2) * sin(lambda2))))))) * R)
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
↓
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision] + N[(N[(N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Sin[lambda1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R
↓
\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \left(\left(\cos \phi_2 \cdot \cos \lambda_1\right) \cdot \cos \lambda_2\right) \cdot \cos \phi_1 + \cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \left(\cos \phi_2 \cdot \sin \lambda_2\right)\right)\right)\right) \cdot R
Alternatives
| Alternative 1 |
|---|
| Error | 4.0 |
|---|
| Cost | 64960 |
|---|
\[R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)
\]
| Alternative 2 |
|---|
| Error | 10.5 |
|---|
| Cost | 58824 |
|---|
\[\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
t_1 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_1 \leq -0.00028:\\
\;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t_0 \cdot \log \left(1 + \mathsf{expm1}\left(t_1\right)\right)\right)\\
\mathbf{elif}\;\phi_1 \leq 0.0019:\\
\;\;\;\;R \cdot \cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + t_0 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \mathsf{log1p}\left(\mathsf{expm1}\left(t_0 \cdot t_1\right)\right)\right)\right)\\
\end{array}
\]
| Alternative 3 |
|---|
| Error | 4.0 |
|---|
| Cost | 58688 |
|---|
\[R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right)\right)
\]
| Alternative 4 |
|---|
| Error | 10.5 |
|---|
| Cost | 58568 |
|---|
\[\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
t_1 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_1 \leq -0.00028:\\
\;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t_0 \cdot \log \left(1 + \mathsf{expm1}\left(t_1\right)\right)\right)\\
\mathbf{elif}\;\phi_1 \leq 0.041:\\
\;\;\;\;R \cdot \cos^{-1} \left(\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot t_0 + \phi_1 \cdot \sin \phi_2\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \mathsf{log1p}\left(\mathsf{expm1}\left(t_0 \cdot t_1\right)\right)\right)\right)\\
\end{array}
\]
| Alternative 5 |
|---|
| Error | 10.5 |
|---|
| Cost | 52552 |
|---|
\[\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
t_1 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_1 \leq -0.00024:\\
\;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t_0 \cdot \log \left(1 + \mathsf{expm1}\left(t_1\right)\right)\right)\\
\mathbf{elif}\;\phi_1 \leq 1.36 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot t_0 + \phi_1 \cdot \sin \phi_2\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot t_1\right)\right)\right)\\
\end{array}
\]
| Alternative 6 |
|---|
| Error | 15.9 |
|---|
| Cost | 46024 |
|---|
\[\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_2 \leq -8.2 \cdot 10^{-261}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_0\right)\right)\right)\\
\mathbf{elif}\;\phi_2 \leq 5.4 \cdot 10^{-86}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot t_0\right)\right)\right)\\
\end{array}
\]
| Alternative 7 |
|---|
| Error | 16.6 |
|---|
| Cost | 45504 |
|---|
\[R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)
\]
| Alternative 8 |
|---|
| Error | 16.6 |
|---|
| Cost | 45504 |
|---|
\[R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)
\]
| Alternative 9 |
|---|
| Error | 23.6 |
|---|
| Cost | 39633 |
|---|
\[\begin{array}{l}
t_0 := R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \left(\cos \lambda_2 \cdot \cos \phi_1\right)\right)\\
\mathbf{if}\;\phi_2 \leq -0.0095:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\phi_2 \leq 0.047:\\
\;\;\;\;R \cdot \cos^{-1} \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right) + \sin \phi_1 \cdot \phi_2\right)\\
\mathbf{elif}\;\phi_2 \leq 2.8 \cdot 10^{+89} \lor \neg \left(\phi_2 \leq 2.7 \cdot 10^{+203}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\\
\end{array}
\]
| Alternative 10 |
|---|
| Error | 23.0 |
|---|
| Cost | 39236 |
|---|
\[\begin{array}{l}
t_0 := \sin \phi_1 \cdot \sin \phi_2\\
\mathbf{if}\;\lambda_1 \leq -2.9 \cdot 10^{-6}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_0 + \cos \lambda_1 \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_0 + \cos \phi_2 \cdot \left(\cos \lambda_2 \cdot \cos \phi_1\right)\right)\\
\end{array}
\]
| Alternative 11 |
|---|
| Error | 23.0 |
|---|
| Cost | 39236 |
|---|
\[\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
t_1 := \sin \phi_1 \cdot \sin \phi_2\\
\mathbf{if}\;\lambda_1 \leq -4.9 \cdot 10^{-6}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_1 + \cos \lambda_1 \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_1 + \cos \lambda_2 \cdot t_0\right)\\
\end{array}
\]
| Alternative 12 |
|---|
| Error | 16.6 |
|---|
| Cost | 39232 |
|---|
\[R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)
\]
| Alternative 13 |
|---|
| Error | 25.6 |
|---|
| Cost | 39108 |
|---|
\[\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -2.9 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_1 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\\
\mathbf{elif}\;\phi_1 \leq 4.1 \cdot 10^{-11}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \cos \phi_1\right)\\
\end{array}
\]
| Alternative 14 |
|---|
| Error | 26.6 |
|---|
| Cost | 39108 |
|---|
\[\begin{array}{l}
t_0 := \cos \left(\lambda_2 - \lambda_1\right)\\
\mathbf{if}\;\phi_1 \leq -9.5 \cdot 10^{-16}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_1 \cdot t_0\right)\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_2 \cdot t_0\right)\right)\\
\end{array}
\]
| Alternative 15 |
|---|
| Error | 29.0 |
|---|
| Cost | 33097 |
|---|
\[\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
\mathbf{if}\;\phi_1 \leq -5.5 \cdot 10^{+93} \lor \neg \left(\phi_1 \leq 4.1 \cdot 10^{-11}\right):\\
\;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t_0\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + t_0 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\\
\end{array}
\]
| Alternative 16 |
|---|
| Error | 29.1 |
|---|
| Cost | 32972 |
|---|
\[\begin{array}{l}
t_0 := R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \cos \phi_1\right)\\
t_1 := \phi_1 \cdot \sin \phi_2\\
t_2 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_1 \leq -5.4 \cdot 10^{+93}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\phi_1 \leq -4.5 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_1 + \cos \phi_1 \cdot t_2\right)\\
\mathbf{elif}\;\phi_1 \leq 4.1 \cdot 10^{-11}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_1 + \cos \phi_2 \cdot t_2\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\]
| Alternative 17 |
|---|
| Error | 29.1 |
|---|
| Cost | 32972 |
|---|
\[\begin{array}{l}
t_0 := R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \cos \phi_1\right)\\
t_1 := \cos \left(\lambda_1 - \lambda_2\right)\\
t_2 := \phi_1 \cdot \sin \phi_2\\
\mathbf{if}\;\phi_1 \leq -3.3 \cdot 10^{+93}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\phi_1 \leq -4.2 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(t_1, \cos \phi_1, t_2\right)\right)\\
\mathbf{elif}\;\phi_1 \leq 4.1 \cdot 10^{-11}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_2 + \cos \phi_2 \cdot t_1\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\]
| Alternative 18 |
|---|
| Error | 27.6 |
|---|
| Cost | 32964 |
|---|
\[\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
t_1 := \cos \phi_2 \cdot \cos \phi_1\\
\mathbf{if}\;\phi_1 \leq -2.8 \cdot 10^{-6}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_1 \cdot t_0 + \sin \phi_1 \cdot \phi_2\right)\\
\mathbf{elif}\;\phi_1 \leq 4.1 \cdot 10^{-11}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t_1\right)\\
\end{array}
\]
| Alternative 19 |
|---|
| Error | 36.1 |
|---|
| Cost | 26436 |
|---|
\[\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
t_1 := \phi_1 \cdot \sin \phi_2\\
\mathbf{if}\;\phi_2 \leq 7 \cdot 10^{-39}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_1 + \cos \phi_1 \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_1 + \cos \phi_2 \cdot t_0\right)\\
\end{array}
\]
| Alternative 20 |
|---|
| Error | 47.8 |
|---|
| Cost | 26308 |
|---|
\[\begin{array}{l}
t_0 := \phi_1 \cdot \sin \phi_2\\
\mathbf{if}\;\phi_1 \leq -0.018:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_0 + \cos \lambda_1 \cdot \cos \phi_1\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_0 + \cos \left(\lambda_1 - \lambda_2\right) \cdot \left(1 + -0.5 \cdot \left(\phi_1 \cdot \phi_1\right)\right)\right)\\
\end{array}
\]
| Alternative 21 |
|---|
| Error | 49.2 |
|---|
| Cost | 26308 |
|---|
\[\begin{array}{l}
t_0 := \phi_1 \cdot \sin \phi_2\\
\mathbf{if}\;\lambda_1 \leq -9.3 \cdot 10^{-7}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_0 + \cos \lambda_1 \cdot \cos \phi_1\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_0 + \cos \lambda_2 \cdot \cos \phi_1\right)\\
\end{array}
\]
| Alternative 22 |
|---|
| Error | 46.3 |
|---|
| Cost | 26304 |
|---|
\[R \cdot \cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)
\]
| Alternative 23 |
|---|
| Error | 51.2 |
|---|
| Cost | 19776 |
|---|
\[R \cdot \cos^{-1} \left(\cos \left(\lambda_1 - \lambda_2\right) + \phi_1 \cdot \sin \phi_2\right)
\]
| Alternative 24 |
|---|
| Error | 52.5 |
|---|
| Cost | 13376 |
|---|
\[R \cdot \cos^{-1} \left(\cos \left(\lambda_1 - \lambda_2\right) + \phi_1 \cdot \phi_2\right)
\]