Average Error: 16.5 → 2.1
Time: 1.2min
Precision: binary64
Cost: 97860
\[ \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 := \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 2 \cdot 10^{-6}:\\ \;\;\;\;\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_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\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 (* (sin phi1) (sin phi2))))
   (if (<=
        (acos (+ t_0 (* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2)))))
        2e-6)
     (- (* lambda2 R) (* lambda1 R))
     (*
      R
      (acos
       (+
        t_0
        (*
         (cos phi2)
         (*
          (cos phi1)
          (+
           (* (sin lambda2) (sin lambda1))
           (* (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 = sin(phi1) * sin(phi2);
	double tmp;
	if (acos((t_0 + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) <= 2e-6) {
		tmp = (lambda2 * R) - (lambda1 * R);
	} else {
		tmp = R * acos((t_0 + (cos(phi2) * (cos(phi1) * ((sin(lambda2) * sin(lambda1)) + (cos(lambda2) * cos(lambda1)))))));
	}
	return tmp;
}
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 = acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * r
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) :: tmp
    t_0 = sin(phi1) * sin(phi2)
    if (acos((t_0 + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) <= 2d-6) then
        tmp = (lambda2 * r) - (lambda1 * r)
    else
        tmp = r * acos((t_0 + (cos(phi2) * (cos(phi1) * ((sin(lambda2) * sin(lambda1)) + (cos(lambda2) * cos(lambda1)))))))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return Math.acos(((Math.sin(phi1) * Math.sin(phi2)) + ((Math.cos(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2))))) * R;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.sin(phi1) * Math.sin(phi2);
	double tmp;
	if (Math.acos((t_0 + ((Math.cos(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2))))) <= 2e-6) {
		tmp = (lambda2 * R) - (lambda1 * R);
	} else {
		tmp = R * Math.acos((t_0 + (Math.cos(phi2) * (Math.cos(phi1) * ((Math.sin(lambda2) * Math.sin(lambda1)) + (Math.cos(lambda2) * Math.cos(lambda1)))))));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	return math.acos(((math.sin(phi1) * math.sin(phi2)) + ((math.cos(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2))))) * R
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(phi1) * math.sin(phi2)
	tmp = 0
	if math.acos((t_0 + ((math.cos(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2))))) <= 2e-6:
		tmp = (lambda2 * R) - (lambda1 * R)
	else:
		tmp = R * math.acos((t_0 + (math.cos(phi2) * (math.cos(phi1) * ((math.sin(lambda2) * math.sin(lambda1)) + (math.cos(lambda2) * math.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(sin(phi1) * sin(phi2))
	tmp = 0.0
	if (acos(Float64(t_0 + Float64(Float64(cos(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2))))) <= 2e-6)
		tmp = Float64(Float64(lambda2 * R) - Float64(lambda1 * R));
	else
		tmp = Float64(R * acos(Float64(t_0 + Float64(cos(phi2) * Float64(cos(phi1) * Float64(Float64(sin(lambda2) * sin(lambda1)) + Float64(cos(lambda2) * cos(lambda1))))))));
	end
	return tmp
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * R;
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(phi1) * sin(phi2);
	tmp = 0.0;
	if (acos((t_0 + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) <= 2e-6)
		tmp = (lambda2 * R) - (lambda1 * R);
	else
		tmp = R * acos((t_0 + (cos(phi2) * (cos(phi1) * ((sin(lambda2) * sin(lambda1)) + (cos(lambda2) * cos(lambda1)))))));
	end
	tmp_2 = 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[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[ArcCos[N[(t$95$0 + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2e-6], N[(N[(lambda2 * R), $MachinePrecision] - N[(lambda1 * R), $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(t$95$0 + N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[(N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $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 := \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 2 \cdot 10^{-6}:\\
\;\;\;\;\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_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\right)\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if (acos.f64 (+.f64 (*.f64 (sin.f64 phi1) (sin.f64 phi2)) (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (cos.f64 (-.f64 lambda1 lambda2))))) < 1.99999999999999991e-6

    1. Initial program 55.5

      \[\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. Taylor expanded in phi1 around 0 55.5

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

      \[\leadsto \color{blue}{\cos^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), \cos \phi_2 \cdot \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)} \cdot R \]
      Proof
      (acos.f64 (fma.f64 (cos.f64 (-.f64 lambda2 lambda1)) (*.f64 (cos.f64 phi2) (cos.f64 phi1)) (*.f64 (sin.f64 phi1) (sin.f64 phi2)))): 0 points increase in error, 0 points decrease in error
      (acos.f64 (fma.f64 (cos.f64 (Rewrite<= unsub-neg (+.f64 lambda2 (neg.f64 lambda1)))) (*.f64 (cos.f64 phi2) (cos.f64 phi1)) (*.f64 (sin.f64 phi1) (sin.f64 phi2)))): 0 points increase in error, 0 points decrease in error
      (acos.f64 (fma.f64 (cos.f64 (+.f64 lambda2 (Rewrite<= mul-1-neg (*.f64 -1 lambda1)))) (*.f64 (cos.f64 phi2) (cos.f64 phi1)) (*.f64 (sin.f64 phi1) (sin.f64 phi2)))): 0 points increase in error, 0 points decrease in error
      (acos.f64 (fma.f64 (cos.f64 (Rewrite<= +-commutative (+.f64 (*.f64 -1 lambda1) lambda2))) (*.f64 (cos.f64 phi2) (cos.f64 phi1)) (*.f64 (sin.f64 phi1) (sin.f64 phi2)))): 0 points increase in error, 0 points decrease in error
      (acos.f64 (fma.f64 (Rewrite<= cos-neg (cos.f64 (neg.f64 (+.f64 (*.f64 -1 lambda1) lambda2)))) (*.f64 (cos.f64 phi2) (cos.f64 phi1)) (*.f64 (sin.f64 phi1) (sin.f64 phi2)))): 0 points increase in error, 0 points decrease in error
      (acos.f64 (Rewrite<= fma-def (+.f64 (*.f64 (cos.f64 (neg.f64 (+.f64 (*.f64 -1 lambda1) lambda2))) (*.f64 (cos.f64 phi2) (cos.f64 phi1))) (*.f64 (sin.f64 phi1) (sin.f64 phi2))))): 4 points increase in error, 1 points decrease in error
      (acos.f64 (Rewrite=> fma-def (fma.f64 (cos.f64 (neg.f64 (+.f64 (*.f64 -1 lambda1) lambda2))) (*.f64 (cos.f64 phi2) (cos.f64 phi1)) (*.f64 (sin.f64 phi1) (sin.f64 phi2))))): 1 points increase in error, 4 points decrease in error
      (acos.f64 (fma.f64 (cos.f64 (Rewrite=> distribute-neg-in (+.f64 (neg.f64 (*.f64 -1 lambda1)) (neg.f64 lambda2)))) (*.f64 (cos.f64 phi2) (cos.f64 phi1)) (*.f64 (sin.f64 phi1) (sin.f64 phi2)))): 0 points increase in error, 0 points decrease in error
      (acos.f64 (fma.f64 (cos.f64 (+.f64 (neg.f64 (Rewrite=> mul-1-neg (neg.f64 lambda1))) (neg.f64 lambda2))) (*.f64 (cos.f64 phi2) (cos.f64 phi1)) (*.f64 (sin.f64 phi1) (sin.f64 phi2)))): 0 points increase in error, 0 points decrease in error
      (acos.f64 (fma.f64 (cos.f64 (+.f64 (Rewrite=> remove-double-neg lambda1) (neg.f64 lambda2))) (*.f64 (cos.f64 phi2) (cos.f64 phi1)) (*.f64 (sin.f64 phi1) (sin.f64 phi2)))): 0 points increase in error, 0 points decrease in error
      (acos.f64 (fma.f64 (cos.f64 (+.f64 lambda1 (Rewrite<= mul-1-neg (*.f64 -1 lambda2)))) (*.f64 (cos.f64 phi2) (cos.f64 phi1)) (*.f64 (sin.f64 phi1) (sin.f64 phi2)))): 0 points increase in error, 0 points decrease in error
      (acos.f64 (fma.f64 (cos.f64 (Rewrite<= +-commutative (+.f64 (*.f64 -1 lambda2) lambda1))) (*.f64 (cos.f64 phi2) (cos.f64 phi1)) (*.f64 (sin.f64 phi1) (sin.f64 phi2)))): 0 points increase in error, 0 points decrease in error
      (acos.f64 (Rewrite<= fma-def (+.f64 (*.f64 (cos.f64 (+.f64 (*.f64 -1 lambda2) lambda1)) (*.f64 (cos.f64 phi2) (cos.f64 phi1))) (*.f64 (sin.f64 phi1) (sin.f64 phi2))))): 4 points increase in error, 1 points decrease in error
      (acos.f64 (Rewrite=> fma-def (fma.f64 (cos.f64 (+.f64 (*.f64 -1 lambda2) lambda1)) (*.f64 (cos.f64 phi2) (cos.f64 phi1)) (*.f64 (sin.f64 phi1) (sin.f64 phi2))))): 1 points increase in error, 4 points decrease in error
      (acos.f64 (fma.f64 (cos.f64 (Rewrite=> +-commutative (+.f64 lambda1 (*.f64 -1 lambda2)))) (*.f64 (cos.f64 phi2) (cos.f64 phi1)) (*.f64 (sin.f64 phi1) (sin.f64 phi2)))): 0 points increase in error, 0 points decrease in error
      (acos.f64 (fma.f64 (cos.f64 (+.f64 lambda1 (Rewrite=> mul-1-neg (neg.f64 lambda2)))) (*.f64 (cos.f64 phi2) (cos.f64 phi1)) (*.f64 (sin.f64 phi1) (sin.f64 phi2)))): 0 points increase in error, 0 points decrease in error
      (acos.f64 (fma.f64 (cos.f64 (Rewrite<= sub-neg (-.f64 lambda1 lambda2))) (*.f64 (cos.f64 phi2) (cos.f64 phi1)) (*.f64 (sin.f64 phi1) (sin.f64 phi2)))): 0 points increase in error, 0 points decrease in error
      (acos.f64 (Rewrite<= fma-def (+.f64 (*.f64 (cos.f64 (-.f64 lambda1 lambda2)) (*.f64 (cos.f64 phi2) (cos.f64 phi1))) (*.f64 (sin.f64 phi1) (sin.f64 phi2))))): 4 points increase in error, 1 points decrease in error
    4. Taylor expanded in phi2 around 0 55.5

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

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

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

    if 1.99999999999999991e-6 < (acos.f64 (+.f64 (*.f64 (sin.f64 phi1) (sin.f64 phi2)) (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (cos.f64 (-.f64 lambda1 lambda2)))))

    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.7

      \[\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. Taylor expanded in phi1 around inf 0.7

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

    \[\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) \leq 2 \cdot 10^{-6}:\\ \;\;\;\;\lambda_2 \cdot R - \lambda_1 \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Error10.2
Cost58824
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_1 := \cos \phi_1 \cdot \cos \phi_2\\ t_2 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\phi_1 \leq -56801.11291929814:\\ \;\;\;\;\mathsf{fma}\left(\pi \cdot 0.5, R, R \cdot \left(-\sin^{-1} \left(\mathsf{fma}\left(t_0, t_1, t_2\right)\right)\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 1.9271134508852888 \cdot 10^{-17}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + t_1 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_1 \cdot t_0 + \frac{1}{\frac{1}{t_2}}\right)\\ \end{array} \]
Alternative 2
Error10.1
Cost58692
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_1 := \cos \phi_1 \cdot \cos \phi_2\\ t_2 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\phi_1 \leq -0.009754333911024758:\\ \;\;\;\;\mathsf{fma}\left(\pi \cdot 0.5, R, R \cdot \left(-\sin^{-1} \left(\mathsf{fma}\left(t_0, t_1, t_2\right)\right)\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 1.9271134508852888 \cdot 10^{-17}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_2 + \cos \phi_2 \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_1 \cdot t_0 + \frac{1}{\frac{1}{t_2}}\right)\\ \end{array} \]
Alternative 3
Error10.1
Cost52424
\[\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_1 \leq -1.518655669388917 \cdot 10^{-11}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, t_0\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 1.9271134508852888 \cdot 10^{-17}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_1 + \cos \phi_2 \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_0 + \frac{1}{\frac{1}{t_1}}\right)\\ \end{array} \]
Alternative 4
Error11.2
Cost45892
\[\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 -2.6346245622427554 \cdot 10^{-48}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \frac{1}{\frac{\frac{1}{t_0}}{t_1}}\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 5.398425980427339 \cdot 10^{-27}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_0 \cdot t_1 + \frac{1}{\frac{1}{\sin \phi_1 \cdot \sin \phi_2}}\right)\\ \end{array} \]
Alternative 5
Error11.6
Cost45764
\[\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 -4.1472499936089594 \cdot 10^{-92}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \frac{t_0}{\frac{1}{t_1}}\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 5.398425980427339 \cdot 10^{-27}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_1 \cdot t_0 + \frac{1}{\frac{1}{\sin \phi_1 \cdot \sin \phi_2}}\right)\\ \end{array} \]
Alternative 6
Error11.6
Cost39752
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_1 := \cos \phi_1 \cdot \cos \phi_2\\ t_2 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\phi_2 \leq -4.1472499936089594 \cdot 10^{-92}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_2 + \frac{t_0}{\frac{1}{t_1}}\right)\\ \mathbf{elif}\;\phi_2 \leq 5.398425980427339 \cdot 10^{-27}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_1 \cdot t_0 + \frac{1}{\frac{1}{t_2}}\right)\\ \end{array} \]
Alternative 7
Error11.4
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 -71005389823324184:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\phi_2 \leq 5.398425980427339 \cdot 10^{-27}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error11.6
Cost39496
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_1 := \cos \phi_1 \cdot \cos \phi_2\\ t_2 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\phi_2 \leq -4.1472499936089594 \cdot 10^{-92}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_2 + \frac{t_0}{\frac{1}{t_1}}\right)\\ \mathbf{elif}\;\phi_2 \leq 5.398425980427339 \cdot 10^{-27}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(t_2 + t_1 \cdot t_0\right) \cdot R\\ \end{array} \]
Alternative 9
Error28.2
Cost39372
\[\begin{array}{l} t_0 := \cos \phi_1 \cdot \cos \phi_2\\ \mathbf{if}\;\phi_2 \leq -71005389823324184:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, t_0\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 1405763819360421.8:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_0 \cdot \cos \left(\lambda_1 - \lambda_2\right) + \sin \phi_1 \cdot \phi_2\right)\\ \mathbf{elif}\;\phi_2 \leq 5.473368291690849 \cdot 10^{+108}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t_0\right)\\ \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
Error23.3
Cost39368
\[\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 \lambda_1\right)\right)\\ \mathbf{if}\;\phi_2 \leq -71005389823324184:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\phi_2 \leq 9.196251035014615 \cdot 10^{-18}:\\ \;\;\;\;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{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Error17.5
Cost39368
\[\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 \lambda_1\right)\right)\\ \mathbf{if}\;\phi_2 \leq -71005389823324184:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\phi_2 \leq 9.196251035014615 \cdot 10^{-18}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 12
Error15.2
Cost39368
\[\begin{array}{l} t_0 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\lambda_1 \leq -1.401269559717865 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_0 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \lambda_1\right)\right)\\ \mathbf{elif}\;\lambda_1 \leq 4.826221919811612 \cdot 10^{-17}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_0 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\\ \end{array} \]
Alternative 13
Error28.1
Cost38980
\[\begin{array}{l} t_0 := \cos \phi_1 \cdot \cos \phi_2\\ \mathbf{if}\;\phi_2 \leq -71005389823324184:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, t_0\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 1405763819360421.8:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_0 \cdot \cos \left(\lambda_1 - \lambda_2\right) + \sin \phi_1 \cdot \phi_2\right)\\ \mathbf{elif}\;\phi_2 \leq 5.473368291690849 \cdot 10^{+108}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t_0\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\\ \end{array} \]
Alternative 14
Error28.1
Cost33096
\[\begin{array}{l} t_0 := \cos \phi_1 \cdot \cos \phi_2\\ t_1 := R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t_0\right)\\ \mathbf{if}\;\phi_2 \leq -71005389823324184:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\phi_2 \leq 1405763819360421.8:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_0 \cdot \cos \left(\lambda_1 - \lambda_2\right) + \sin \phi_1 \cdot \phi_2\right)\\ \mathbf{elif}\;\phi_2 \leq 5.473368291690849 \cdot 10^{+108}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\\ \end{array} \]
Alternative 15
Error36.9
Cost19784
\[\begin{array}{l} \mathbf{if}\;\lambda_1 \leq -2.850880258250221 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq -5.802316097185745 \cdot 10^{-203}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_2\right)\\ \end{array} \]
Alternative 16
Error33.0
Cost19780
\[\begin{array}{l} \mathbf{if}\;\phi_1 \leq -0.009754333911024758:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\\ \end{array} \]
Alternative 17
Error31.6
Cost19780
\[\begin{array}{l} t_0 := \cos \left(\lambda_2 - \lambda_1\right)\\ \mathbf{if}\;\phi_2 \leq 2.115584907086277 \cdot 10^{-7}:\\ \;\;\;\;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 18
Error46.3
Cost19652
\[\begin{array}{l} t_0 := R \cdot \cos^{-1} \cos \left(\lambda_2 - \lambda_1\right)\\ t_1 := R \cdot \cos^{-1} \cos \phi_2\\ \mathbf{if}\;\phi_1 \leq -0.009754333911024758:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_2\right)\\ \mathbf{elif}\;\phi_1 \leq -1.157071485028341 \cdot 10^{-265}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\phi_1 \leq 1.0015030098475422 \cdot 10^{-181}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\phi_1 \leq 1.3673710090706307 \cdot 10^{-102}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 19
Error47.8
Cost13648
\[\begin{array}{l} t_0 := R \cdot \cos^{-1} \cos \left(\lambda_2 - \lambda_1\right)\\ t_1 := R \cdot \cos^{-1} \cos \phi_2\\ \mathbf{if}\;\phi_1 \leq -1.7469452007195502 \cdot 10^{-17}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -1.157071485028341 \cdot 10^{-265}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\phi_1 \leq 1.0015030098475422 \cdot 10^{-181}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\phi_1 \leq 1.3673710090706307 \cdot 10^{-102}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 20
Error49.9
Cost13388
\[\begin{array}{l} \mathbf{if}\;\phi_2 \leq -7.774648332706178 \cdot 10^{-225}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \phi_1\\ \mathbf{elif}\;\phi_2 \leq 4.214097319121884 \cdot 10^{-229}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_2\\ \mathbf{elif}\;\phi_2 \leq 1.6903410713415965 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \phi_2\\ \end{array} \]
Alternative 21
Error46.1
Cost13256
\[\begin{array}{l} \mathbf{if}\;\lambda_1 \leq -2.850880258250221 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\ \mathbf{elif}\;\lambda_1 \leq -5.802316097185745 \cdot 10^{-203}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \phi_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_2\\ \end{array} \]
Alternative 22
Error42.6
Cost13252
\[\begin{array}{l} \mathbf{if}\;\lambda_1 \leq -844.8295220394822:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \left(\phi_2 - \phi_1\right)\\ \end{array} \]
Alternative 23
Error51.9
Cost13124
\[\begin{array}{l} \mathbf{if}\;\lambda_2 \leq 5.349019211088226 \cdot 10^{-19}:\\ \;\;\;\;\lambda_2 \cdot R - \lambda_1 \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_2\\ \end{array} \]
Alternative 24
Error47.7
Cost13124
\[\begin{array}{l} \mathbf{if}\;\lambda_2 \leq 4.6258579422656443 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \phi_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_2\\ \end{array} \]
Alternative 25
Error58.9
Cost832
\[\frac{\lambda_2 - \lambda_1}{\frac{\frac{\lambda_1 + \lambda_2}{R}}{\lambda_1 + \lambda_2}} \]
Alternative 26
Error59.5
Cost452
\[\begin{array}{l} \mathbf{if}\;\lambda_2 \leq 1.1148207114109132 \cdot 10^{-197}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\lambda_2 \cdot R\\ \end{array} \]
Alternative 27
Error58.9
Cost448
\[\lambda_2 \cdot R - \lambda_1 \cdot R \]
Alternative 28
Error59.2
Cost388
\[\begin{array}{l} \mathbf{if}\;\lambda_1 \leq -1.1384283968035681 \cdot 10^{-247}:\\ \;\;\;\;\lambda_1 \cdot \left(-R\right)\\ \mathbf{else}:\\ \;\;\;\;\lambda_2 \cdot R\\ \end{array} \]
Alternative 29
Error58.9
Cost320
\[R \cdot \left(\lambda_2 - \lambda_1\right) \]
Alternative 30
Error59.9
Cost192
\[\lambda_2 \cdot R \]

Error

Reproduce

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