Average Error: 16.9 → 2.2
Time: 57.7s
Precision: binary64
Cost: 137288
\[ \begin{array}{c}[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\ \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 \]
\[\begin{array}{l} t_0 := \cos \phi_1 \cdot \cos \phi_2\\ t_1 := \sin \lambda_1 \cdot \sin \lambda_2\\ t_2 := \sin \phi_1 \cdot \sin \phi_2\\ t_3 := \cos^{-1} \left(t_2 + t_0 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{if}\;t_3 \leq -2 \cdot 10^{-308}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_2 + t_0 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \mathsf{expm1}\left(\mathsf{log1p}\left(t_1\right)\right)\right)\right)\\ \mathbf{elif}\;t_3 \leq 0:\\ \;\;\;\;\lambda_2 \cdot R - \lambda_1 \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_2 + t_0 \cdot \left(t_1 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\\ \end{array} \]
(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
 (let* ((t_0 (* (cos phi1) (cos phi2)))
        (t_1 (* (sin lambda1) (sin lambda2)))
        (t_2 (* (sin phi1) (sin phi2)))
        (t_3 (* (acos (+ t_2 (* t_0 (cos (- lambda1 lambda2))))) R)))
   (if (<= t_3 -2e-308)
     (*
      R
      (acos
       (+ t_2 (* t_0 (fma (cos lambda2) (cos lambda1) (expm1 (log1p t_1)))))))
     (if (<= t_3 0.0)
       (- (* lambda2 R) (* lambda1 R))
       (* R (acos (+ t_2 (* t_0 (+ t_1 (* (cos lambda2) (cos lambda1)))))))))))
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) {
	double t_0 = cos(phi1) * cos(phi2);
	double t_1 = sin(lambda1) * sin(lambda2);
	double t_2 = sin(phi1) * sin(phi2);
	double t_3 = acos((t_2 + (t_0 * cos((lambda1 - lambda2))))) * R;
	double tmp;
	if (t_3 <= -2e-308) {
		tmp = R * acos((t_2 + (t_0 * fma(cos(lambda2), cos(lambda1), expm1(log1p(t_1))))));
	} else if (t_3 <= 0.0) {
		tmp = (lambda2 * R) - (lambda1 * R);
	} else {
		tmp = R * acos((t_2 + (t_0 * (t_1 + (cos(lambda2) * cos(lambda1))))));
	}
	return tmp;
}
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)
	t_0 = Float64(cos(phi1) * cos(phi2))
	t_1 = Float64(sin(lambda1) * sin(lambda2))
	t_2 = Float64(sin(phi1) * sin(phi2))
	t_3 = Float64(acos(Float64(t_2 + Float64(t_0 * cos(Float64(lambda1 - lambda2))))) * R)
	tmp = 0.0
	if (t_3 <= -2e-308)
		tmp = Float64(R * acos(Float64(t_2 + Float64(t_0 * fma(cos(lambda2), cos(lambda1), expm1(log1p(t_1)))))));
	elseif (t_3 <= 0.0)
		tmp = Float64(Float64(lambda2 * R) - Float64(lambda1 * R));
	else
		tmp = Float64(R * acos(Float64(t_2 + Float64(t_0 * Float64(t_1 + Float64(cos(lambda2) * cos(lambda1)))))));
	end
	return tmp
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_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[ArcCos[N[(t$95$2 + N[(t$95$0 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]}, If[LessEqual[t$95$3, -2e-308], N[(R * N[ArcCos[N[(t$95$2 + N[(t$95$0 * N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(Exp[N[Log[1 + t$95$1], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.0], N[(N[(lambda2 * R), $MachinePrecision] - N[(lambda1 * R), $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(t$95$2 + N[(t$95$0 * N[(t$95$1 + N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $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
\begin{array}{l}
t_0 := \cos \phi_1 \cdot \cos \phi_2\\
t_1 := \sin \lambda_1 \cdot \sin \lambda_2\\
t_2 := \sin \phi_1 \cdot \sin \phi_2\\
t_3 := \cos^{-1} \left(t_2 + t_0 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
\mathbf{if}\;t_3 \leq -2 \cdot 10^{-308}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_2 + t_0 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \mathsf{expm1}\left(\mathsf{log1p}\left(t_1\right)\right)\right)\right)\\

\mathbf{elif}\;t_3 \leq 0:\\
\;\;\;\;\lambda_2 \cdot R - \lambda_1 \cdot R\\

\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_2 + t_0 \cdot \left(t_1 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\\


\end{array}

Error

Derivation

  1. Split input into 3 regimes
  2. if (*.f64 (acos.f64 (+.f64 (*.f64 (sin.f64 phi1) (sin.f64 phi2)) (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (cos.f64 (-.f64 lambda1 lambda2))))) R) < -1.9999999999999998e-308

    1. Initial program 15.2

      \[\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 \]
    2. Applied egg-rr0.8

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
    3. Applied egg-rr0.8

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)}\right)\right) \cdot R \]

    if -1.9999999999999998e-308 < (*.f64 (acos.f64 (+.f64 (*.f64 (sin.f64 phi1) (sin.f64 phi2)) (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (cos.f64 (-.f64 lambda1 lambda2))))) R) < 0.0

    1. Initial program 55.3

      \[\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 \]
    2. Simplified55.3

      \[\leadsto \color{blue}{\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) \cdot R} \]
      Proof
      (*.f64 (acos.f64 (fma.f64 (sin.f64 phi1) (sin.f64 phi2) (*.f64 (cos.f64 phi2) (*.f64 (cos.f64 phi1) (cos.f64 (-.f64 lambda1 lambda2)))))) R): 0 points increase in error, 0 points decrease in error
      (*.f64 (acos.f64 (fma.f64 (sin.f64 phi1) (sin.f64 phi2) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (cos.f64 phi2) (cos.f64 phi1)) (cos.f64 (-.f64 lambda1 lambda2)))))) R): 2 points increase in error, 6 points decrease in error
      (*.f64 (acos.f64 (fma.f64 (sin.f64 phi1) (sin.f64 phi2) (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 (cos.f64 phi1) (cos.f64 phi2))) (cos.f64 (-.f64 lambda1 lambda2))))) R): 0 points increase in error, 0 points decrease in error
      (*.f64 (acos.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (sin.f64 phi1) (sin.f64 phi2)) (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (cos.f64 (-.f64 lambda1 lambda2)))))) R): 1 points increase in error, 4 points decrease in error
    3. Taylor expanded in phi2 around 0 55.4

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)} \cdot R \]
    4. Simplified55.4

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1\right)} \cdot R \]
      Proof
      (*.f64 (cos.f64 (-.f64 lambda2 lambda1)) (cos.f64 phi1)): 0 points increase in error, 0 points decrease in error
      (*.f64 (cos.f64 (Rewrite<= unsub-neg_binary64 (+.f64 lambda2 (neg.f64 lambda1)))) (cos.f64 phi1)): 0 points increase in error, 0 points decrease in error
      (*.f64 (cos.f64 (+.f64 lambda2 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 lambda1)))) (cos.f64 phi1)): 0 points increase in error, 0 points decrease in error
      (*.f64 (cos.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 lambda1) lambda2))) (cos.f64 phi1)): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= cos-neg_binary64 (cos.f64 (neg.f64 (+.f64 (*.f64 -1 lambda1) lambda2)))) (cos.f64 phi1)): 0 points increase in error, 0 points decrease in error
      (*.f64 (cos.f64 (neg.f64 (Rewrite=> +-commutative_binary64 (+.f64 lambda2 (*.f64 -1 lambda1))))) (cos.f64 phi1)): 0 points increase in error, 0 points decrease in error
      (*.f64 (cos.f64 (Rewrite=> distribute-neg-in_binary64 (+.f64 (neg.f64 lambda2) (neg.f64 (*.f64 -1 lambda1))))) (cos.f64 phi1)): 0 points increase in error, 0 points decrease in error
      (*.f64 (cos.f64 (+.f64 (Rewrite=> neg-mul-1_binary64 (*.f64 -1 lambda2)) (neg.f64 (*.f64 -1 lambda1)))) (cos.f64 phi1)): 0 points increase in error, 0 points decrease in error
      (*.f64 (cos.f64 (+.f64 (*.f64 -1 lambda2) (neg.f64 (Rewrite=> mul-1-neg_binary64 (neg.f64 lambda1))))) (cos.f64 phi1)): 0 points increase in error, 0 points decrease in error
      (*.f64 (cos.f64 (+.f64 (*.f64 -1 lambda2) (Rewrite=> remove-double-neg_binary64 lambda1))) (cos.f64 phi1)): 0 points increase in error, 0 points decrease in error
      (*.f64 (cos.f64 (+.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 lambda2)) lambda1)) (cos.f64 phi1)): 0 points increase in error, 0 points decrease in error
      (*.f64 (cos.f64 (Rewrite=> +-commutative_binary64 (+.f64 lambda1 (neg.f64 lambda2)))) (cos.f64 phi1)): 0 points increase in error, 0 points decrease in error
      (*.f64 (cos.f64 (Rewrite<= sub-neg_binary64 (-.f64 lambda1 lambda2))) (cos.f64 phi1)): 0 points increase in error, 0 points decrease in error
    5. Taylor expanded in phi1 around 0 55.4

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_2 - \lambda_1\right)} \cdot R \]
    6. Applied egg-rr27.1

      \[\leadsto \color{blue}{\lambda_2 \cdot R + \left(-\lambda_1\right) \cdot R} \]

    if 0.0 < (*.f64 (acos.f64 (+.f64 (*.f64 (sin.f64 phi1) (sin.f64 phi2)) (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (cos.f64 (-.f64 lambda1 lambda2))))) R)

    1. Initial program 14.2

      \[\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 \]
    2. Applied egg-rr0.8

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;\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 \leq -2 \cdot 10^{-308}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \mathsf{expm1}\left(\mathsf{log1p}\left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right)\\ \mathbf{elif}\;\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 \leq 0:\\ \;\;\;\;\lambda_2 \cdot R - \lambda_1 \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Error2.2
Cost104132
\[\begin{array}{l} t_0 := \sin \phi_1 \cdot \sin \phi_2\\ t_1 := \cos \phi_1 \cdot \cos \phi_2\\ \mathbf{if}\;\cos^{-1} \left(t_0 + t_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \leq 0:\\ \;\;\;\;\lambda_2 \cdot R - \lambda_1 \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_0 + t_1 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\ \end{array} \]
Alternative 2
Error2.2
Cost97860
\[\begin{array}{l} t_0 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\cos^{-1} \left(t_0 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \leq 0:\\ \;\;\;\;\lambda_2 \cdot R - \lambda_1 \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_0 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\right)\\ \end{array} \]
Alternative 3
Error2.2
Cost97860
\[\begin{array}{l} t_0 := \sin \phi_1 \cdot \sin \phi_2\\ t_1 := \cos \phi_1 \cdot \cos \phi_2\\ \mathbf{if}\;\cos^{-1} \left(t_0 + t_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \leq 0:\\ \;\;\;\;\lambda_2 \cdot R - \lambda_1 \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_0 + t_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\\ \end{array} \]
Alternative 4
Error10.5
Cost52296
\[\begin{array}{l} t_0 := \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\\ t_1 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\phi_2 \leq -1.0013632525226777 \cdot 10^{-10}:\\ \;\;\;\;\cos^{-1} \left(t_1 + t_0\right) \cdot R\\ \mathbf{elif}\;\phi_2 \leq 7.213895704966735 \cdot 10^{-14}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \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(t_0 + \mathsf{log1p}\left(\mathsf{expm1}\left(t_1\right)\right)\right)\\ \end{array} \]
Alternative 5
Error10.5
Cost45768
\[\begin{array}{l} t_0 := \cos \phi_1 \cdot \cos \phi_2\\ t_1 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\phi_2 \leq -1.0013632525226777 \cdot 10^{-10}:\\ \;\;\;\;\cos^{-1} \left(t_1 + t_0 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{elif}\;\phi_2 \leq 7.213895704966735 \cdot 10^{-14}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \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(\cos \left(\lambda_2 - \lambda_1\right), t_0, t_1\right)\right)\\ \end{array} \]
Alternative 6
Error10.5
Cost45640
\[\begin{array}{l} t_0 := \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\\ \mathbf{if}\;\phi_2 \leq -1.0013632525226777 \cdot 10^{-10}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\phi_2 \leq 7.213895704966735 \cdot 10^{-14}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error10.5
Cost39496
\[\begin{array}{l} t_0 := R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\\ \mathbf{if}\;\phi_2 \leq -1.0013632525226777 \cdot 10^{-10}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\phi_2 \leq 7.213895704966735 \cdot 10^{-14}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error10.7
Cost39496
\[\begin{array}{l} t_0 := \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\\ \mathbf{if}\;\phi_2 \leq -5.149181388041772 \cdot 10^{-30}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\phi_2 \leq 7.213895704966735 \cdot 10^{-14}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error17.0
Cost39368
\[\begin{array}{l} t_0 := R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_1\right)\\ \mathbf{if}\;\phi_2 \leq -210.1913110966665:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\phi_2 \leq 3.779320740945154 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error15.5
Cost39368
\[\begin{array}{l} t_0 := \cos \phi_1 \cdot \cos \phi_2\\ t_1 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\lambda_1 \leq -3.4256186025529285 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_1 + t_0 \cdot \cos \lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq 5.526404210216698 \cdot 10^{-28}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_1 + t_0 \cdot \cos \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\\ \end{array} \]
Alternative 11
Error25.4
Cost39236
\[\begin{array}{l} \mathbf{if}\;\phi_2 \leq 7.213895704966735 \cdot 10^{-14}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\\ \end{array} \]
Alternative 12
Error32.0
Cost19780
\[\begin{array}{l} t_0 := \cos \left(\lambda_2 - \lambda_1\right)\\ \mathbf{if}\;\phi_1 \leq -0.6269829744584192:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t_0\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot t_0\right)\\ \end{array} \]
Alternative 13
Error39.9
Cost19652
\[\begin{array}{l} \mathbf{if}\;\lambda_1 \leq -0.007134889041098479:\\ \;\;\;\;R \cdot \cos^{-1} \cos \left(\lambda_2 - \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_2\right)\\ \end{array} \]
Alternative 14
Error36.6
Cost19652
\[\begin{array}{l} \mathbf{if}\;\lambda_2 \leq 2.90737317719705 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_2\right)\\ \end{array} \]
Alternative 15
Error36.6
Cost19648
\[R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right) \]
Alternative 16
Error47.2
Cost13384
\[\begin{array}{l} t_0 := R \cdot \cos^{-1} \cos \left(\lambda_2 - \lambda_1\right)\\ \mathbf{if}\;\lambda_1 \leq -5.898658629055607 \cdot 10^{-8}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\lambda_1 \leq -5.2215708184416566 \cdot 10^{-73}:\\ \;\;\;\;\lambda_2 \cdot R - \lambda_1 \cdot R\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 17
Error47.2
Cost13256
\[\begin{array}{l} \mathbf{if}\;\lambda_1 \leq -5.898658629055607 \cdot 10^{-8}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\ \mathbf{elif}\;\lambda_1 \leq -5.2215708184416566 \cdot 10^{-73}:\\ \;\;\;\;\lambda_2 \cdot R - \lambda_1 \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_2\\ \end{array} \]
Alternative 18
Error51.6
Cost13124
\[\begin{array}{l} \mathbf{if}\;\lambda_2 \leq 1.5731866354638557 \cdot 10^{-11}:\\ \;\;\;\;\lambda_2 \cdot R - \lambda_1 \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_2\\ \end{array} \]
Alternative 19
Error59.1
Cost448
\[\lambda_2 \cdot R - \lambda_1 \cdot R \]
Alternative 20
Error59.1
Cost388
\[\begin{array}{l} \mathbf{if}\;\lambda_2 \leq 8.102830912656707 \cdot 10^{-134}:\\ \;\;\;\;\lambda_1 \cdot \left(-R\right)\\ \mathbf{else}:\\ \;\;\;\;\lambda_2 \cdot R\\ \end{array} \]
Alternative 21
Error59.1
Cost320
\[R \cdot \left(\lambda_2 - \lambda_1\right) \]
Alternative 22
Error59.9
Cost192
\[\lambda_2 \cdot R \]

Error

Reproduce

herbie shell --seed 2022312 
(FPCore (R lambda1 lambda2 phi1 phi2)
  :name "Spherical law of cosines"
  :precision binary64
  (* (acos (+ (* (sin phi1) (sin phi2)) (* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2))))) R))