?

Average Error: 16.8 → 2.3
Time: 1.1min
Precision: binary64
Cost: 97860

?

\[ \begin{array}{c}[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\ [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 \]
\[\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.0005:\\ \;\;\;\;\left(\lambda_2 - \lambda_1\right) \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)))))
        0.0005)
     (* (- lambda2 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))))) <= 0.0005) {
		tmp = (lambda2 - 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))))) <= 0.0005d0) then
        tmp = (lambda2 - 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))))) <= 0.0005) {
		tmp = (lambda2 - 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))))) <= 0.0005:
		tmp = (lambda2 - 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))))) <= 0.0005)
		tmp = Float64(Float64(lambda2 - 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))))) <= 0.0005)
		tmp = (lambda2 - 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], 0.0005], N[(N[(lambda2 - lambda1), $MachinePrecision] * R), $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 0.0005:\\
\;\;\;\;\left(\lambda_2 - \lambda_1\right) \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))))) < 5.0000000000000001e-4

    1. Initial program 53.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. Simplified53.2

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

      fma-def [=>]53.2

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

      \[ \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* [=>]53.2

      \[ \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 53.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 54.1

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

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

      [Start]54.1

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

      sub-neg [=>]54.1

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

      remove-double-neg [<=]54.1

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

      mul-1-neg [<=]54.1

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

      distribute-neg-in [<=]54.1

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

      cos-neg [=>]54.1

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

      +-commutative [=>]54.1

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

      mul-1-neg [=>]54.1

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

      unsub-neg [=>]54.1

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

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

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

      [Start]26.8

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

      +-commutative [=>]26.8

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

      mul-1-neg [=>]26.8

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

      sub-neg [<=]26.8

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

    if 5.0000000000000001e-4 < (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.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. Applied egg-rr0.6

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

      \[\leadsto \color{blue}{\cos^{-1} \left(\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) + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
  3. Recombined 2 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) \leq 0.0005:\\ \;\;\;\;\left(\lambda_2 - \lambda_1\right) \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
Error11.5
Cost58436
\[\begin{array}{l} t_0 := \sin \phi_1 \cdot \sin \phi_2\\ t_1 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_2 := \sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\\ t_3 := \cos \phi_1 \cdot \cos \phi_2\\ \mathbf{if}\;\phi_2 \leq -0.015:\\ \;\;\;\;R \cdot \cos^{-1} \log \left(e^{\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_1\right)\right)}\right)\\ \mathbf{elif}\;\phi_2 \leq 1.05 \cdot 10^{-29}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_2\right) + \sin \phi_1 \cdot \phi_2\right)\\ \mathbf{elif}\;\phi_2 \leq 1.5 \cdot 10^{+144}:\\ \;\;\;\;\cos^{-1} \left(t_0 + t_3 \cdot t_1\right) \cdot R\\ \mathbf{elif}\;\phi_2 \leq 4.5 \cdot 10^{+183}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot t_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_0 + t_3 \cdot \log \left(1 + \mathsf{expm1}\left(t_1\right)\right)\right)\\ \end{array} \]
Alternative 2
Error11.6
Cost52688
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_1 := \sin \phi_1 \cdot \sin \phi_2\\ t_2 := \cos \phi_1 \cdot \cos \phi_2\\ t_3 := \sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\\ \mathbf{if}\;\phi_2 \leq -1.65 \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 1.05 \cdot 10^{-29}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t_3\right)\\ \mathbf{elif}\;\phi_2 \leq 6.9 \cdot 10^{+142}:\\ \;\;\;\;\cos^{-1} \left(t_1 + t_2 \cdot t_0\right) \cdot R\\ \mathbf{elif}\;\phi_2 \leq 4.5 \cdot 10^{+183}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot t_3\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_1 + t_2 \cdot \log \left(1 + \mathsf{expm1}\left(t_0\right)\right)\right)\\ \end{array} \]
Alternative 3
Error11.5
Cost52688
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_1 := \sin \phi_1 \cdot \sin \phi_2\\ t_2 := \sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\\ t_3 := \cos \phi_1 \cdot \cos \phi_2\\ \mathbf{if}\;\phi_2 \leq -0.03:\\ \;\;\;\;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 1.05 \cdot 10^{-29}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \left(\cos \phi_1 \cdot t_2\right) + \sin \phi_1 \cdot \phi_2\right)\\ \mathbf{elif}\;\phi_2 \leq 1.5 \cdot 10^{+144}:\\ \;\;\;\;\cos^{-1} \left(t_1 + t_3 \cdot t_0\right) \cdot R\\ \mathbf{elif}\;\phi_2 \leq 4.5 \cdot 10^{+183}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot t_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_1 + t_3 \cdot \log \left(1 + \mathsf{expm1}\left(t_0\right)\right)\right)\\ \end{array} \]
Alternative 4
Error11.6
Cost46032
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_1 := 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)\\ t_2 := \sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\\ \mathbf{if}\;\phi_2 \leq -4.6 \cdot 10^{-9}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\phi_2 \leq 1.05 \cdot 10^{-29}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t_2\right)\\ \mathbf{elif}\;\phi_2 \leq 1.5 \cdot 10^{+144}:\\ \;\;\;\;\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\\ \mathbf{elif}\;\phi_2 \leq 4.5 \cdot 10^{+183}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot t_2\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error11.6
Cost39761
\[\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\\ t_1 := \sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\\ \mathbf{if}\;\phi_2 \leq -2.2 \cdot 10^{-10}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\phi_2 \leq 1.05 \cdot 10^{-29}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t_1\right)\\ \mathbf{elif}\;\phi_2 \leq 1.45 \cdot 10^{+144} \lor \neg \left(\phi_2 \leq 5.6 \cdot 10^{+183}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot t_1\right)\\ \end{array} \]
Alternative 6
Error17.4
Cost39632
\[\begin{array}{l} t_0 := \sin \phi_1 \cdot \sin \phi_2\\ t_1 := \sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\\ t_2 := R \cdot \cos^{-1} \left(\cos \phi_2 \cdot t_1\right)\\ \mathbf{if}\;\lambda_2 \leq -28000000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\lambda_2 \leq 1.05 \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_2 \leq 4.5 \cdot 10^{+134}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\lambda_2 \leq 2.9 \cdot 10^{+263}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_0 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2\right)\\ \end{array} \]
Alternative 7
Error20.0
Cost39368
\[\begin{array}{l} \mathbf{if}\;\phi_2 \leq -0.00175:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \cos \phi_2\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 100000:\\ \;\;\;\;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 \left(\pi \cdot 0.5\right) - R \cdot \sin^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\\ \end{array} \]
Alternative 8
Error16.7
Cost39368
\[\begin{array}{l} t_0 := \sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\\ \mathbf{if}\;\phi_2 \leq -0.015:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \cos \phi_2\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 100000:\\ \;\;\;\;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 9
Error15.9
Cost39368
\[\begin{array}{l} t_0 := \sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\\ \mathbf{if}\;\phi_2 \leq -1.6 \cdot 10^{-8}:\\ \;\;\;\;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{elif}\;\phi_2 \leq 100000:\\ \;\;\;\;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 10
Error25.9
Cost38980
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\phi_2 \leq -1.55:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 0.18:\\ \;\;\;\;R \cdot \cos^{-1} \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_0 + \sin \phi_1 \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\pi \cdot 0.5\right) - R \cdot \sin^{-1} \left(\cos \phi_2 \cdot t_0\right)\\ \end{array} \]
Alternative 11
Error25.9
Cost38980
\[\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 -1.2:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, t_0\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 0.18:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_0 \cdot t_1 + \sin \phi_1 \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\pi \cdot 0.5\right) - R \cdot \sin^{-1} \left(\cos \phi_2 \cdot t_1\right)\\ \end{array} \]
Alternative 12
Error25.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 -2.6:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t_0\right)\\ \mathbf{elif}\;\phi_2 \leq 0.18:\\ \;\;\;\;R \cdot \cos^{-1} \left(t_0 \cdot t_1 + \sin \phi_1 \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\pi \cdot 0.5\right) - R \cdot \sin^{-1} \left(\cos \phi_2 \cdot t_1\right)\\ \end{array} \]
Alternative 13
Error26.0
Cost32708
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\phi_2 \leq -0.0082:\\ \;\;\;\;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.033:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \phi_2 + \cos \phi_1 \cdot t_0\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\pi \cdot 0.5\right) - R \cdot \sin^{-1} \left(\cos \phi_2 \cdot t_0\right)\\ \end{array} \]
Alternative 14
Error27.2
Cost26500
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\phi_2 \leq 100000:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t_0\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\pi \cdot 0.5\right) - R \cdot \sin^{-1} \left(\cos \phi_2 \cdot t_0\right)\\ \end{array} \]
Alternative 15
Error27.2
Cost26372
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\phi_2 \leq 100000:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t_0\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\pi \cdot 0.5 - \sin^{-1} \left(\cos \phi_2 \cdot t_0\right)\right)\\ \end{array} \]
Alternative 16
Error37.2
Cost20048
\[\begin{array}{l} t_0 := R \cdot \cos^{-1} \cos \left(\lambda_2 - \lambda_1\right)\\ \mathbf{if}\;\phi_1 \leq -5.1 \cdot 10^{-10}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\ \mathbf{elif}\;\phi_1 \leq -3 \cdot 10^{-197}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\phi_1 \leq -1.6 \cdot 10^{-217}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \lambda_2\right)\\ \mathbf{elif}\;\phi_1 \leq -3.8 \cdot 10^{-294}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \lambda_1\right)\\ \end{array} \]
Alternative 17
Error37.3
Cost19784
\[\begin{array}{l} \mathbf{if}\;\phi_1 \leq -5.1 \cdot 10^{-10}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\ \mathbf{elif}\;\phi_1 \leq -1.9 \cdot 10^{-292}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \left(1 + -0.5 \cdot \left(\phi_1 \cdot \phi_1\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \lambda_1\right)\\ \end{array} \]
Alternative 18
Error30.1
Cost19780
\[\begin{array}{l} \mathbf{if}\;\phi_2 \leq 40000000:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \lambda_2\right)\\ \end{array} \]
Alternative 19
Error27.1
Cost19780
\[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\phi_2 \leq 100000:\\ \;\;\;\;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
Error39.8
Cost19652
\[\begin{array}{l} \mathbf{if}\;\phi_1 \leq -5.1 \cdot 10^{-10}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\ \mathbf{elif}\;\phi_1 \leq 5.7 \cdot 10^{-303}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \left(1 + -0.5 \cdot \left(\phi_1 \cdot \phi_1\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \phi_2\\ \end{array} \]
Alternative 21
Error36.5
Cost19652
\[\begin{array}{l} \mathbf{if}\;\lambda_1 \leq -8.6 \cdot 10^{-6}:\\ \;\;\;\;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
Error42.8
Cost13896
\[\begin{array}{l} \mathbf{if}\;\phi_1 \leq -0.43:\\ \;\;\;\;R \cdot \cos^{-1} \cos \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq 4.1 \cdot 10^{-303}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \left(1 + -0.5 \cdot \left(\phi_1 \cdot \phi_1\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \phi_2\\ \end{array} \]
Alternative 23
Error43.0
Cost13384
\[\begin{array}{l} \mathbf{if}\;\phi_1 \leq -0.0265:\\ \;\;\;\;R \cdot \cos^{-1} \cos \phi_1\\ \mathbf{elif}\;\phi_1 \leq 7.8 \cdot 10^{-303}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \left(\lambda_2 - \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \phi_2\\ \end{array} \]
Alternative 24
Error42.9
Cost13384
\[\begin{array}{l} \mathbf{if}\;\phi_1 \leq -0.008:\\ \;\;\;\;R \cdot \cos^{-1} \cos \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq 5.7 \cdot 10^{-303}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \left(\lambda_2 - \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \phi_2\\ \end{array} \]
Alternative 25
Error46.1
Cost13256
\[\begin{array}{l} \mathbf{if}\;\lambda_1 \leq -0.00092:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\ \mathbf{elif}\;\lambda_1 \leq 5.2 \cdot 10^{-231}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \phi_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_2\\ \end{array} \]
Alternative 26
Error46.1
Cost13256
\[\begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.52 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \phi_1\\ \mathbf{elif}\;\phi_1 \leq 4.8 \cdot 10^{-299}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \phi_2\\ \end{array} \]
Alternative 27
Error51.4
Cost13124
\[\begin{array}{l} \mathbf{if}\;\lambda_1 \leq -0.055:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\ \mathbf{else}:\\ \;\;\;\;\left(\lambda_2 - \lambda_1\right) \cdot R\\ \end{array} \]
Alternative 28
Error47.1
Cost13124
\[\begin{array}{l} \mathbf{if}\;\lambda_1 \leq -9 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_2\\ \end{array} \]
Alternative 29
Error59.2
Cost388
\[\begin{array}{l} \mathbf{if}\;\lambda_1 \leq -4.4 \cdot 10^{-64}:\\ \;\;\;\;\lambda_1 \cdot \left(-R\right)\\ \mathbf{else}:\\ \;\;\;\;\lambda_2 \cdot R\\ \end{array} \]
Alternative 30
Error58.9
Cost320
\[\left(\lambda_2 - \lambda_1\right) \cdot R \]
Alternative 31
Error59.8
Cost192
\[\lambda_2 \cdot R \]

Error

Reproduce?

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