?

Average Error: 16.9 → 2.3
Time: 1.0min
Precision: binary64
Cost: 162888

?

\[ \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 := \cos \lambda_1 \cdot \cos \lambda_2\\ t_3 := \sin \phi_1 \cdot \sin \phi_2\\ t_4 := \cos^{-1} \left(t_3 + t_0 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{if}\;t_4 \leq -2 \cdot 10^{-307}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \left(\sqrt[3]{{t_1}^{3}} + t_2\right)\right)\right)\right)\\ \mathbf{elif}\;t_4 \leq 0:\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(t_0, t_2, \mathsf{fma}\left(t_0, t_1, t_3\right)\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 (* (cos lambda1) (cos lambda2)))
        (t_3 (* (sin phi1) (sin phi2)))
        (t_4 (* (acos (+ t_3 (* t_0 (cos (- lambda1 lambda2))))) R)))
   (if (<= t_4 -2e-307)
     (*
      R
      (acos
       (fma
        (sin phi1)
        (sin phi2)
        (* (cos phi2) (* (cos phi1) (+ (cbrt (pow t_1 3.0)) t_2))))))
     (if (<= t_4 0.0)
       (* R (- lambda2 lambda1))
       (* R (acos (fma t_0 t_2 (fma t_0 t_1 t_3))))))))
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 = cos(lambda1) * cos(lambda2);
	double t_3 = sin(phi1) * sin(phi2);
	double t_4 = acos((t_3 + (t_0 * cos((lambda1 - lambda2))))) * R;
	double tmp;
	if (t_4 <= -2e-307) {
		tmp = R * acos(fma(sin(phi1), sin(phi2), (cos(phi2) * (cos(phi1) * (cbrt(pow(t_1, 3.0)) + t_2)))));
	} else if (t_4 <= 0.0) {
		tmp = R * (lambda2 - lambda1);
	} else {
		tmp = R * acos(fma(t_0, t_2, fma(t_0, t_1, t_3)));
	}
	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(cos(lambda1) * cos(lambda2))
	t_3 = Float64(sin(phi1) * sin(phi2))
	t_4 = Float64(acos(Float64(t_3 + Float64(t_0 * cos(Float64(lambda1 - lambda2))))) * R)
	tmp = 0.0
	if (t_4 <= -2e-307)
		tmp = Float64(R * acos(fma(sin(phi1), sin(phi2), Float64(cos(phi2) * Float64(cos(phi1) * Float64(cbrt((t_1 ^ 3.0)) + t_2))))));
	elseif (t_4 <= 0.0)
		tmp = Float64(R * Float64(lambda2 - lambda1));
	else
		tmp = Float64(R * acos(fma(t_0, t_2, fma(t_0, t_1, t_3))));
	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[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[ArcCos[N[(t$95$3 + N[(t$95$0 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]}, If[LessEqual[t$95$4, -2e-307], N[(R * N[ArcCos[N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[(N[Power[N[Power[t$95$1, 3.0], $MachinePrecision], 1/3], $MachinePrecision] + t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$4, 0.0], N[(R * N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(t$95$0 * t$95$2 + N[(t$95$0 * t$95$1 + t$95$3), $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 := \cos \lambda_1 \cdot \cos \lambda_2\\
t_3 := \sin \phi_1 \cdot \sin \phi_2\\
t_4 := \cos^{-1} \left(t_3 + t_0 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
\mathbf{if}\;t_4 \leq -2 \cdot 10^{-307}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \left(\sqrt[3]{{t_1}^{3}} + t_2\right)\right)\right)\right)\\

\mathbf{elif}\;t_4 \leq 0:\\
\;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(t_0, t_2, \mathsf{fma}\left(t_0, t_1, t_3\right)\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.99999999999999982e-307

    1. Initial program 14.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. Simplified14.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

      [Start]14.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 \]

      fma-def [=>]14.3

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

      *-commutative [=>]14.3

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

      associate-*l* [=>]14.3

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

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

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

    if -1.99999999999999982e-307 < (*.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.4

      \[\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.4

      \[\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

      [Start]55.4

      \[ \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 \]

      fma-def [=>]55.4

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

      *-commutative [=>]55.4

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

      associate-*l* [=>]55.4

      \[ \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \color{blue}{\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
    3. Taylor expanded in phi2 around 0 55.7

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)} \cdot R \]
    4. Taylor expanded in phi1 around 0 55.7

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

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

      [Start]55.7

      \[ \cos^{-1} \cos \left(\lambda_1 - \lambda_2\right) \cdot R \]

      sub-neg [=>]55.7

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

      remove-double-neg [<=]55.7

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

      mul-1-neg [<=]55.7

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

      distribute-neg-in [<=]55.7

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

      cos-neg [=>]55.7

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

      +-commutative [=>]55.7

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

      mul-1-neg [=>]55.7

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

      unsub-neg [=>]55.7

      \[ \cos^{-1} \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot R \]
    6. Taylor expanded in lambda2 around 0 27.1

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

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

      [Start]27.1

      \[ \left(-1 \cdot \lambda_1 + \lambda_2\right) \cdot R \]

      mul-1-neg [=>]27.1

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

      +-commutative [=>]27.1

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

      sub-neg [<=]27.1

      \[ \color{blue}{\left(\lambda_2 - \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.9

      \[\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. Simplified14.9

      \[\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

      [Start]14.9

      \[ \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 \]

      fma-def [=>]14.9

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

      *-commutative [=>]14.9

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

      associate-*l* [=>]14.9

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2\right) + \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2\right) + \sin \phi_1 \cdot \sin \phi_2\right)\right)} \cdot R \]
    4. Simplified0.9

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

      [Start]0.9

      \[ \cos^{-1} \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2\right) + \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2\right) + \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]

      fma-def [=>]0.9

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

      *-commutative [=>]0.9

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

      fma-def [=>]0.9

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

    \[\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^{-307}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \left(\sqrt[3]{{\left(\sin \lambda_1 \cdot \sin \lambda_2\right)}^{3}} + \cos \lambda_1 \cdot \cos \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:\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1 \cdot \cos \phi_2, \cos \lambda_1 \cdot \cos \lambda_2, \mathsf{fma}\left(\cos \phi_1 \cdot \cos \phi_2, \sin \lambda_1 \cdot \sin \lambda_2, \sin \phi_1 \cdot \sin \phi_2\right)\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Error2.3
Cost143560
\[\begin{array}{l} t_0 := \sin \lambda_1 \cdot \sin \lambda_2\\ t_1 := \cos \lambda_1 \cdot \cos \lambda_2\\ t_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\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{-307}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \left(\sqrt[3]{{t_0}^{3}} + t_1\right)\right)\right)\right)\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \left(t_0 + t_1\right)\right)\right)\right)\\ \end{array} \]
Alternative 2
Error2.3
Cost137288
\[\begin{array}{l} t_0 := \cos \phi_1 \cdot \cos \phi_2\\ t_1 := \sin \phi_1 \cdot \sin \phi_2\\ t_2 := \cos^{-1} \left(t_1 + t_0 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ t_3 := \sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{-307}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_1 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_3\right)\right)\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_1 + t_0 \cdot t_3\right)\\ \end{array} \]
Alternative 3
Error3.9
Cost97732
\[\begin{array}{l} \mathbf{if}\;\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right) \leq 1:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\ \end{array} \]
Alternative 4
Error3.9
Cost91460
\[\begin{array}{l} t_0 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;t_0 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right) \leq 1:\\ \;\;\;\;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_1 \cdot \cos \lambda_2\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\ \end{array} \]
Alternative 5
Error10.5
Cost58568
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_1 := \cos \phi_1 \cdot \cos \phi_2\\ \mathbf{if}\;\phi_2 \leq -0.75:\\ \;\;\;\;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 0.165:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right) + \sin \phi_1 \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \log \left(e^{\cos^{-1} \left(\mathsf{fma}\left(t_0, t_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)}\right)\\ \end{array} \]
Alternative 6
Error10.5
Cost58568
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\phi_2 \leq -0.72:\\ \;\;\;\;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 0.185:\\ \;\;\;\;R \cdot \cos^{-1} \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right) + \sin \phi_1 \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \log \left(e^{\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)}\right)\\ \end{array} \]
Alternative 7
Error10.5
Cost52552
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_1 := \cos \phi_1 \cdot \cos \phi_2\\ \mathbf{if}\;\phi_2 \leq -0.72:\\ \;\;\;\;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 0.165:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right) + \sin \phi_1 \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t_1 \cdot t_0\right) \cdot R\\ \end{array} \]
Alternative 8
Error10.6
Cost52424
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_1 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\phi_2 \leq -1.15 \cdot 10^{-7}:\\ \;\;\;\;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 0.165:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_1 + \cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(t_1 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_0\right) \cdot R\\ \end{array} \]
Alternative 9
Error10.7
Cost45636
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\phi_2 \leq -9 \cdot 10^{-11}:\\ \;\;\;\;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 6.8 \cdot 10^{-13}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_0\right) \cdot R\\ \end{array} \]
Alternative 10
Error10.7
Cost39620
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_1 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\phi_2 \leq -6.8 \cdot 10^{-11}:\\ \;\;\;\;R \cdot \cos^{-1} \left(1 + \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_0\right) + \left(t_1 + -1\right)\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 7 \cdot 10^{-13}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(t_1 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_0\right) \cdot R\\ \end{array} \]
Alternative 11
Error15.5
Cost39500
\[\begin{array}{l} t_0 := R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\ t_1 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\lambda_1 \leq -3.2 \cdot 10^{+232}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\lambda_1 \leq -0.07:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_1 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq 2.35 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_1 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 12
Error15.5
Cost39500
\[\begin{array}{l} t_0 := \cos \phi_1 \cdot \cos \phi_2\\ t_1 := R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\ t_2 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\lambda_1 \leq -2 \cdot 10^{+232}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\lambda_1 \leq -0.07:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_2 + t_0 \cdot \cos \lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq 7.2 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_2 + t_0 \cdot \cos \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 13
Error10.7
Cost39497
\[\begin{array}{l} \mathbf{if}\;\phi_2 \leq -9.2 \cdot 10^{-11} \lor \neg \left(\phi_2 \leq 7 \cdot 10^{-13}\right):\\ \;\;\;\;\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{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\ \end{array} \]
Alternative 14
Error16.8
Cost39369
\[\begin{array}{l} \mathbf{if}\;\lambda_1 \leq -3.25 \cdot 10^{-6} \lor \neg \left(\lambda_1 \leq 1.7 \cdot 10^{-5}\right):\\ \;\;\;\;R \cdot \cos^{-1} \left(\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(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \lambda_2\right)\right)\\ \end{array} \]
Alternative 15
Error21.8
Cost39368
\[\begin{array}{l} \mathbf{if}\;\phi_2 \leq -0.72:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \cos \phi_2\right)\\ \mathbf{elif}\;\phi_2 \leq 0.165:\\ \;\;\;\;R \cdot \cos^{-1} \left(\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(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\\ \end{array} \]
Alternative 16
Error27.9
Cost33096
\[\begin{array}{l} t_0 := \cos \phi_1 \cdot \cos \phi_2\\ t_1 := \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\phi_2 \leq -12.5:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t_0\right)\\ \mathbf{elif}\;\phi_2 \leq 0.00027:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_0 \cdot t_1 + \sin \phi_1 \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot t_1\right)\\ \end{array} \]
Alternative 17
Error28.0
Cost32708
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\phi_2 \leq -0.00192:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \cos \phi_2\right)\\ \mathbf{elif}\;\phi_2 \leq 2.2 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \phi_2 + \cos \phi_1 \cdot t_0\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot t_0\right)\\ \end{array} \]
Alternative 18
Error37.8
Cost20040
\[\begin{array}{l} \mathbf{if}\;\lambda_1 - \lambda_2 \leq -5 \cdot 10^{-16}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\\ \mathbf{elif}\;\lambda_1 - \lambda_2 \leq -5 \cdot 10^{-140}:\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\ \end{array} \]
Alternative 19
Error32.1
Cost19780
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\phi_1 \leq -1.95 \cdot 10^{+14}:\\ \;\;\;\;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 20
Error43.5
Cost19652
\[\begin{array}{l} \mathbf{if}\;\phi_1 \leq -7.6 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \left(\lambda_2 - \lambda_1\right)\\ \end{array} \]
Alternative 21
Error36.8
Cost19652
\[\begin{array}{l} \mathbf{if}\;\lambda_2 \leq 1.9 \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 22
Error51.5
Cost13124
\[\begin{array}{l} \mathbf{if}\;\lambda_1 \leq -0.000205:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\ \end{array} \]
Alternative 23
Error47.3
Cost13124
\[\begin{array}{l} \mathbf{if}\;\lambda_1 \leq -0.07:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_2\\ \end{array} \]
Alternative 24
Error47.2
Cost13120
\[R \cdot \cos^{-1} \cos \left(\lambda_2 - \lambda_1\right) \]
Alternative 25
Error59.0
Cost388
\[\begin{array}{l} \mathbf{if}\;\lambda_1 \leq -9.5 \cdot 10^{-142}:\\ \;\;\;\;-\lambda_1 \cdot R\\ \mathbf{else}:\\ \;\;\;\;\lambda_2 \cdot R\\ \end{array} \]
Alternative 26
Error59.0
Cost320
\[R \cdot \left(\lambda_2 - \lambda_1\right) \]
Alternative 27
Error60.0
Cost192
\[\lambda_2 \cdot R \]

Error

Reproduce?

herbie shell --seed 2023060 
(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))