Spherical law of cosines

Percentage Accurate: 73.4% → 96.4%
Time: 24.4s
Alternatives: 27
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \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 \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  (acos
   (+
    (* (sin phi1) (sin phi2))
    (* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2)))))
  R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * R;
}
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
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;
}
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
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 tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * R;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}

\\
\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
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 27 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 73.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \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 \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  (acos
   (+
    (* (sin phi1) (sin phi2))
    (* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2)))))
  R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * R;
}
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
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;
}
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
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 tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * R;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}

\\
\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
\end{array}

Alternative 1: 96.4% accurate, 0.4× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \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 2 \cdot 10^{-6}:\\ \;\;\;\;\left(\lambda_2 - \lambda_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t\_0 + t\_1 \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (sin phi1) (sin phi2))) (t_1 (* (cos phi1) (cos phi2))))
   (if (<= (acos (+ t_0 (* t_1 (cos (- lambda1 lambda2))))) 2e-6)
     (* (- lambda2 lambda1) R)
     (*
      R
      (acos
       (+
        t_0
        (*
         t_1
         (fma
          (sin lambda2)
          (sin lambda1)
          (* (cos lambda1) (cos lambda2))))))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(phi1) * sin(phi2);
	double t_1 = cos(phi1) * cos(phi2);
	double tmp;
	if (acos((t_0 + (t_1 * cos((lambda1 - lambda2))))) <= 2e-6) {
		tmp = (lambda2 - lambda1) * R;
	} else {
		tmp = R * acos((t_0 + (t_1 * fma(sin(lambda2), sin(lambda1), (cos(lambda1) * cos(lambda2))))));
	}
	return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(sin(phi1) * sin(phi2))
	t_1 = Float64(cos(phi1) * cos(phi2))
	tmp = 0.0
	if (acos(Float64(t_0 + Float64(t_1 * cos(Float64(lambda1 - lambda2))))) <= 2e-6)
		tmp = Float64(Float64(lambda2 - lambda1) * R);
	else
		tmp = Float64(R * acos(Float64(t_0 + Float64(t_1 * fma(sin(lambda2), sin(lambda1), Float64(cos(lambda1) * cos(lambda2)))))));
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[ArcCos[N[(t$95$0 + N[(t$95$1 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2e-6], N[(N[(lambda2 - lambda1), $MachinePrecision] * R), $MachinePrecision], N[(R * N[ArcCos[N[(t$95$0 + N[(t$95$1 * N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\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 2 \cdot 10^{-6}:\\
\;\;\;\;\left(\lambda_2 - \lambda_1\right) \cdot R\\

\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t\_0 + t\_1 \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\


\end{array}
\end{array}
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 6.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. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f646.4

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

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

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_2 - \lambda_1\right)} \cdot R \]
    7. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)} \cdot R \]
      2. remove-double-negN/A

        \[\leadsto \cos^{-1} \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      3. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_2}\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      4. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_2 + \lambda_1\right)\right)\right)} \cdot R \]
      5. +-commutativeN/A

        \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_1 + -1 \cdot \lambda_2\right)}\right)\right) \cdot R \]
      6. cos-negN/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      8. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\lambda_1 + \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)}\right) \cdot R \]
      9. unsub-negN/A

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

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

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)} \cdot R \]
    9. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)} \cdot R \]
      2. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \lambda_2 \cdot \cos \lambda_1} + \sin \lambda_1 \cdot \sin \lambda_2\right) \cdot R \]
      3. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \lambda_2 \cdot \cos \lambda_1 + \color{blue}{\sin \lambda_2 \cdot \sin \lambda_1}\right) \cdot R \]
      4. cos-diffN/A

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

        \[\leadsto \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot R \]
      6. --lowering--.f6444.4

        \[\leadsto \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot R \]
    10. Applied egg-rr44.4%

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

    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 74.7%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      2. +-commutativeN/A

        \[\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. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\color{blue}{\sin \lambda_2 \cdot \sin \lambda_1} + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      4. accelerator-lowering-fma.f64N/A

        \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_2}, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \color{blue}{\sin \lambda_1}, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right)\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

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

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

      \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
  3. Recombined 2 regimes into one program.
  4. Final simplification95.7%

    \[\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}:\\ \;\;\;\;\left(\lambda_2 - \lambda_1\right) \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 \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 96.4% accurate, 0.4× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \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}:\\ \;\;\;\;\left(\lambda_2 - \lambda_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, t\_0\right)\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(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 lambda1) R)
     (*
      R
      (acos
       (fma
        (*
         (cos phi2)
         (fma (sin lambda1) (sin lambda2) (* (cos lambda1) (cos lambda2))))
        (cos phi1)
        t_0))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
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 - lambda1) * R;
	} else {
		tmp = R * acos(fma((cos(phi2) * fma(sin(lambda1), sin(lambda2), (cos(lambda1) * cos(lambda2)))), cos(phi1), t_0));
	}
	return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
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 - lambda1) * R);
	else
		tmp = Float64(R * acos(fma(Float64(cos(phi2) * fma(sin(lambda1), sin(lambda2), Float64(cos(lambda1) * cos(lambda2)))), cos(phi1), t_0)));
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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 - lambda1), $MachinePrecision] * R), $MachinePrecision], N[(R * N[ArcCos[N[(N[(N[Cos[phi2], $MachinePrecision] * N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\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}:\\
\;\;\;\;\left(\lambda_2 - \lambda_1\right) \cdot R\\

\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, t\_0\right)\right)\\


\end{array}
\end{array}
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 6.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. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f646.4

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

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

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_2 - \lambda_1\right)} \cdot R \]
    7. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)} \cdot R \]
      2. remove-double-negN/A

        \[\leadsto \cos^{-1} \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      3. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_2}\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      4. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_2 + \lambda_1\right)\right)\right)} \cdot R \]
      5. +-commutativeN/A

        \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_1 + -1 \cdot \lambda_2\right)}\right)\right) \cdot R \]
      6. cos-negN/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      8. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\lambda_1 + \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)}\right) \cdot R \]
      9. unsub-negN/A

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

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

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)} \cdot R \]
    9. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)} \cdot R \]
      2. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \lambda_2 \cdot \cos \lambda_1} + \sin \lambda_1 \cdot \sin \lambda_2\right) \cdot R \]
      3. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \lambda_2 \cdot \cos \lambda_1 + \color{blue}{\sin \lambda_2 \cdot \sin \lambda_1}\right) \cdot R \]
      4. cos-diffN/A

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

        \[\leadsto \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot R \]
      6. --lowering--.f6444.4

        \[\leadsto \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot R \]
    10. Applied egg-rr44.4%

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

    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 74.7%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      2. +-commutativeN/A

        \[\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. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\color{blue}{\sin \lambda_2 \cdot \sin \lambda_1} + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      4. accelerator-lowering-fma.f64N/A

        \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_2}, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \color{blue}{\sin \lambda_1}, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right)\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

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

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

      \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
    5. Taylor expanded in phi1 around inf

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot \cos \phi_1} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      6. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_1}, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \color{blue}{\sin \lambda_2}, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      9. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1} \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      11. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \color{blue}{\cos \phi_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      13. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      14. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      15. sin-lowering-sin.f64N/A

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

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

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

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

Alternative 3: 83.0% accurate, 0.7× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_1 := \cos \left(\lambda_1 + \lambda_2\right)\\ t_2 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\phi_2 \leq -9 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t\_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\left(t\_0 \cdot t\_1\right) \cdot \frac{1}{t\_1}\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 1.36 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right), \sin \phi_1 \cdot \phi_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{fma}\left(\sqrt[3]{\pi \cdot \pi}, \sqrt[3]{\sqrt{\pi} \cdot \sqrt{\pi}} \cdot 0.5, -\sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot t\_0, t\_2\right)\right)\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (cos (- lambda1 lambda2)))
        (t_1 (cos (+ lambda1 lambda2)))
        (t_2 (* (sin phi1) (sin phi2))))
   (if (<= phi2 -9e-7)
     (*
      R
      (acos (+ t_2 (* (* (cos phi1) (cos phi2)) (* (* t_0 t_1) (/ 1.0 t_1))))))
     (if (<= phi2 1.36e-9)
       (*
        R
        (acos
         (fma
          (cos phi1)
          (fma (cos lambda1) (cos lambda2) (* (sin lambda2) (sin lambda1)))
          (* (sin phi1) phi2))))
       (*
        R
        (fma
         (cbrt (* PI PI))
         (* (cbrt (* (sqrt PI) (sqrt PI))) 0.5)
         (- (asin (fma (cos phi1) (* (cos phi2) t_0) t_2)))))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos((lambda1 - lambda2));
	double t_1 = cos((lambda1 + lambda2));
	double t_2 = sin(phi1) * sin(phi2);
	double tmp;
	if (phi2 <= -9e-7) {
		tmp = R * acos((t_2 + ((cos(phi1) * cos(phi2)) * ((t_0 * t_1) * (1.0 / t_1)))));
	} else if (phi2 <= 1.36e-9) {
		tmp = R * acos(fma(cos(phi1), fma(cos(lambda1), cos(lambda2), (sin(lambda2) * sin(lambda1))), (sin(phi1) * phi2)));
	} else {
		tmp = R * fma(cbrt((((double) M_PI) * ((double) M_PI))), (cbrt((sqrt(((double) M_PI)) * sqrt(((double) M_PI)))) * 0.5), -asin(fma(cos(phi1), (cos(phi2) * t_0), t_2)));
	}
	return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = cos(Float64(lambda1 - lambda2))
	t_1 = cos(Float64(lambda1 + lambda2))
	t_2 = Float64(sin(phi1) * sin(phi2))
	tmp = 0.0
	if (phi2 <= -9e-7)
		tmp = Float64(R * acos(Float64(t_2 + Float64(Float64(cos(phi1) * cos(phi2)) * Float64(Float64(t_0 * t_1) * Float64(1.0 / t_1))))));
	elseif (phi2 <= 1.36e-9)
		tmp = Float64(R * acos(fma(cos(phi1), fma(cos(lambda1), cos(lambda2), Float64(sin(lambda2) * sin(lambda1))), Float64(sin(phi1) * phi2))));
	else
		tmp = Float64(R * fma(cbrt(Float64(pi * pi)), Float64(cbrt(Float64(sqrt(pi) * sqrt(pi))) * 0.5), Float64(-asin(fma(cos(phi1), Float64(cos(phi2) * t_0), t_2)))));
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(lambda1 + lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -9e-7], N[(R * N[ArcCos[N[(t$95$2 + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[(N[(t$95$0 * t$95$1), $MachinePrecision] * N[(1.0 / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 1.36e-9], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision] + N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(N[Power[N[(Pi * Pi), $MachinePrecision], 1/3], $MachinePrecision] * N[(N[Power[N[(N[Sqrt[Pi], $MachinePrecision] * N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * 0.5), $MachinePrecision] + (-N[ArcSin[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
t_1 := \cos \left(\lambda_1 + \lambda_2\right)\\
t_2 := \sin \phi_1 \cdot \sin \phi_2\\
\mathbf{if}\;\phi_2 \leq -9 \cdot 10^{-7}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t\_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\left(t\_0 \cdot t\_1\right) \cdot \frac{1}{t\_1}\right)\right)\\

\mathbf{elif}\;\phi_2 \leq 1.36 \cdot 10^{-9}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right), \sin \phi_1 \cdot \phi_2\right)\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \mathsf{fma}\left(\sqrt[3]{\pi \cdot \pi}, \sqrt[3]{\sqrt{\pi} \cdot \sqrt{\pi}} \cdot 0.5, -\sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot t\_0, t\_2\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < -8.99999999999999959e-7

    1. Initial program 76.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. Add Preprocessing
    3. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      2. flip-+N/A

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

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \frac{\left(\cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2\right) - \left(\sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2\right)}{\color{blue}{\cos \left(\lambda_1 + \lambda_2\right)}}\right) \cdot R \]
      4. div-invN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\left(\left(\cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2\right) - \left(\sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot \frac{1}{\cos \left(\lambda_1 + \lambda_2\right)}\right)}\right) \cdot R \]
      5. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\left(\left(\cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2\right) - \left(\sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot \frac{1}{\cos \left(\lambda_1 + \lambda_2\right)}\right)}\right) \cdot R \]
    4. Applied egg-rr76.3%

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

    if -8.99999999999999959e-7 < phi2 < 1.36000000000000006e-9

    1. Initial program 62.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. Add Preprocessing
    3. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      2. +-commutativeN/A

        \[\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. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\color{blue}{\sin \lambda_2 \cdot \sin \lambda_1} + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      4. accelerator-lowering-fma.f64N/A

        \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_2}, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \color{blue}{\sin \lambda_1}, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right)\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

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

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right)\right) \cdot R \]
    4. Applied egg-rr86.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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
    5. Taylor expanded in phi1 around inf

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot \cos \phi_1} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      6. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_1}, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \color{blue}{\sin \lambda_2}, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      9. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1} \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      11. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \color{blue}{\cos \phi_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      13. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      14. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      15. sin-lowering-sin.f64N/A

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

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

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\phi_2 \cdot \sin \phi_1 + \cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
    9. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right) + \phi_2 \cdot \sin \phi_1\right)} \cdot R \]
      2. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_1}, \cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2, \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      4. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \color{blue}{\mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)}, \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\color{blue}{\cos \lambda_1}, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right), \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \color{blue}{\cos \lambda_2}, \sin \lambda_1 \cdot \sin \lambda_2\right), \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right), \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right), \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      9. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right), \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      10. *-lowering-*.f64N/A

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

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

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

    if 1.36000000000000006e-9 < phi2

    1. Initial program 78.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. Add Preprocessing
    3. Step-by-step derivation
      1. acos-asinN/A

        \[\leadsto \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{2} - \sin^{-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)\right)} \cdot R \]
      2. sub-negN/A

        \[\leadsto \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{2} + \left(\mathsf{neg}\left(\sin^{-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)\right)\right)\right)} \cdot R \]
      3. div-invN/A

        \[\leadsto \left(\color{blue}{\mathsf{PI}\left(\right) \cdot \frac{1}{2}} + \left(\mathsf{neg}\left(\sin^{-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)\right)\right)\right) \cdot R \]
      4. add-cube-cbrtN/A

        \[\leadsto \left(\color{blue}{\left(\left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right) \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right)} \cdot \frac{1}{2} + \left(\mathsf{neg}\left(\sin^{-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)\right)\right)\right) \cdot R \]
      5. associate-*l*N/A

        \[\leadsto \left(\color{blue}{\left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \frac{1}{2}\right)} + \left(\mathsf{neg}\left(\sin^{-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)\right)\right)\right) \cdot R \]
      6. accelerator-lowering-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}, \sqrt[3]{\mathsf{PI}\left(\right)} \cdot \frac{1}{2}, \mathsf{neg}\left(\sin^{-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)\right)\right)} \cdot R \]
    4. Applied egg-rr78.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\pi \cdot \pi}, \sqrt[3]{\pi} \cdot 0.5, -\sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_1 \cdot \sin \phi_2\right)\right)\right)} \cdot R \]
    5. Step-by-step derivation
      1. add-sqr-sqrtN/A

        \[\leadsto \mathsf{fma}\left(\sqrt[3]{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}, \sqrt[3]{\color{blue}{\sqrt{\mathsf{PI}\left(\right)} \cdot \sqrt{\mathsf{PI}\left(\right)}}} \cdot \frac{1}{2}, \mathsf{neg}\left(\sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_1 \cdot \sin \phi_2\right)\right)\right)\right) \cdot R \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\sqrt[3]{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}, \sqrt[3]{\color{blue}{\sqrt{\mathsf{PI}\left(\right)} \cdot \sqrt{\mathsf{PI}\left(\right)}}} \cdot \frac{1}{2}, \mathsf{neg}\left(\sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_1 \cdot \sin \phi_2\right)\right)\right)\right) \cdot R \]
      3. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\sqrt[3]{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}, \sqrt[3]{\color{blue}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \sqrt{\mathsf{PI}\left(\right)}} \cdot \frac{1}{2}, \mathsf{neg}\left(\sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_1 \cdot \sin \phi_2\right)\right)\right)\right) \cdot R \]
      4. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{fma}\left(\sqrt[3]{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}, \sqrt[3]{\sqrt{\color{blue}{\mathsf{PI}\left(\right)}} \cdot \sqrt{\mathsf{PI}\left(\right)}} \cdot \frac{1}{2}, \mathsf{neg}\left(\sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_1 \cdot \sin \phi_2\right)\right)\right)\right) \cdot R \]
      5. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\sqrt[3]{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}, \sqrt[3]{\sqrt{\mathsf{PI}\left(\right)} \cdot \color{blue}{\sqrt{\mathsf{PI}\left(\right)}}} \cdot \frac{1}{2}, \mathsf{neg}\left(\sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_1 \cdot \sin \phi_2\right)\right)\right)\right) \cdot R \]
      6. PI-lowering-PI.f6479.0

        \[\leadsto \mathsf{fma}\left(\sqrt[3]{\pi \cdot \pi}, \sqrt[3]{\sqrt{\pi} \cdot \sqrt{\color{blue}{\pi}}} \cdot 0.5, -\sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_1 \cdot \sin \phi_2\right)\right)\right) \cdot R \]
    6. Applied egg-rr79.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -9 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\lambda_1 + \lambda_2\right)\right) \cdot \frac{1}{\cos \left(\lambda_1 + \lambda_2\right)}\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 1.36 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right), \sin \phi_1 \cdot \phi_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{fma}\left(\sqrt[3]{\pi \cdot \pi}, \sqrt[3]{\sqrt{\pi} \cdot \sqrt{\pi}} \cdot 0.5, -\sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_1 \cdot \sin \phi_2\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 83.1% accurate, 0.7× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_1 := \cos \left(\lambda_1 + \lambda_2\right)\\ t_2 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\phi_2 \leq -2.8 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t\_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\left(t\_0 \cdot t\_1\right) \cdot \frac{1}{t\_1}\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 3.6 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right), \sin \phi_1 \cdot \phi_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\pi \cdot 0.5, R, \sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot t\_0, t\_2\right)\right) \cdot \left(-R\right)\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (cos (- lambda1 lambda2)))
        (t_1 (cos (+ lambda1 lambda2)))
        (t_2 (* (sin phi1) (sin phi2))))
   (if (<= phi2 -2.8e-6)
     (*
      R
      (acos (+ t_2 (* (* (cos phi1) (cos phi2)) (* (* t_0 t_1) (/ 1.0 t_1))))))
     (if (<= phi2 3.6e-6)
       (*
        R
        (acos
         (fma
          (cos phi1)
          (fma (cos lambda1) (cos lambda2) (* (sin lambda2) (sin lambda1)))
          (* (sin phi1) phi2))))
       (fma
        (* PI 0.5)
        R
        (* (asin (fma (cos phi1) (* (cos phi2) t_0) t_2)) (- R)))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos((lambda1 - lambda2));
	double t_1 = cos((lambda1 + lambda2));
	double t_2 = sin(phi1) * sin(phi2);
	double tmp;
	if (phi2 <= -2.8e-6) {
		tmp = R * acos((t_2 + ((cos(phi1) * cos(phi2)) * ((t_0 * t_1) * (1.0 / t_1)))));
	} else if (phi2 <= 3.6e-6) {
		tmp = R * acos(fma(cos(phi1), fma(cos(lambda1), cos(lambda2), (sin(lambda2) * sin(lambda1))), (sin(phi1) * phi2)));
	} else {
		tmp = fma((((double) M_PI) * 0.5), R, (asin(fma(cos(phi1), (cos(phi2) * t_0), t_2)) * -R));
	}
	return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = cos(Float64(lambda1 - lambda2))
	t_1 = cos(Float64(lambda1 + lambda2))
	t_2 = Float64(sin(phi1) * sin(phi2))
	tmp = 0.0
	if (phi2 <= -2.8e-6)
		tmp = Float64(R * acos(Float64(t_2 + Float64(Float64(cos(phi1) * cos(phi2)) * Float64(Float64(t_0 * t_1) * Float64(1.0 / t_1))))));
	elseif (phi2 <= 3.6e-6)
		tmp = Float64(R * acos(fma(cos(phi1), fma(cos(lambda1), cos(lambda2), Float64(sin(lambda2) * sin(lambda1))), Float64(sin(phi1) * phi2))));
	else
		tmp = fma(Float64(pi * 0.5), R, Float64(asin(fma(cos(phi1), Float64(cos(phi2) * t_0), t_2)) * Float64(-R)));
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(lambda1 + lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -2.8e-6], N[(R * N[ArcCos[N[(t$95$2 + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[(N[(t$95$0 * t$95$1), $MachinePrecision] * N[(1.0 / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 3.6e-6], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision] + N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(Pi * 0.5), $MachinePrecision] * R + N[(N[ArcSin[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision] * (-R)), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
t_1 := \cos \left(\lambda_1 + \lambda_2\right)\\
t_2 := \sin \phi_1 \cdot \sin \phi_2\\
\mathbf{if}\;\phi_2 \leq -2.8 \cdot 10^{-6}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t\_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\left(t\_0 \cdot t\_1\right) \cdot \frac{1}{t\_1}\right)\right)\\

\mathbf{elif}\;\phi_2 \leq 3.6 \cdot 10^{-6}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right), \sin \phi_1 \cdot \phi_2\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\pi \cdot 0.5, R, \sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot t\_0, t\_2\right)\right) \cdot \left(-R\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < -2.79999999999999987e-6

    1. Initial program 76.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. Add Preprocessing
    3. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      2. flip-+N/A

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

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \frac{\left(\cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2\right) - \left(\sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2\right)}{\color{blue}{\cos \left(\lambda_1 + \lambda_2\right)}}\right) \cdot R \]
      4. div-invN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\left(\left(\cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2\right) - \left(\sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot \frac{1}{\cos \left(\lambda_1 + \lambda_2\right)}\right)}\right) \cdot R \]
      5. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\left(\left(\cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2\right) - \left(\sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot \frac{1}{\cos \left(\lambda_1 + \lambda_2\right)}\right)}\right) \cdot R \]
    4. Applied egg-rr76.3%

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

    if -2.79999999999999987e-6 < phi2 < 3.59999999999999984e-6

    1. Initial program 62.8%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      2. +-commutativeN/A

        \[\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. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\color{blue}{\sin \lambda_2 \cdot \sin \lambda_1} + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      4. accelerator-lowering-fma.f64N/A

        \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_2}, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \color{blue}{\sin \lambda_1}, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right)\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1} \cdot \cos \lambda_2\right)\right) \cdot R \]
      9. cos-lowering-cos.f6486.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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right)\right) \cdot R \]
    4. Applied egg-rr86.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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
    5. Taylor expanded in phi1 around inf

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot \cos \phi_1} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      6. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_1}, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \color{blue}{\sin \lambda_2}, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      9. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1} \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      11. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \color{blue}{\cos \phi_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      13. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      14. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      15. sin-lowering-sin.f64N/A

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

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

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\phi_2 \cdot \sin \phi_1 + \cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
    9. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right) + \phi_2 \cdot \sin \phi_1\right)} \cdot R \]
      2. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_1}, \cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2, \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      4. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \color{blue}{\mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)}, \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\color{blue}{\cos \lambda_1}, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right), \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \color{blue}{\cos \lambda_2}, \sin \lambda_1 \cdot \sin \lambda_2\right), \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right), \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right), \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      9. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right), \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      10. *-lowering-*.f64N/A

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

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

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

    if 3.59999999999999984e-6 < phi2

    1. Initial program 78.6%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{R \cdot \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)} \]
      2. acos-asinN/A

        \[\leadsto R \cdot \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{2} - \sin^{-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)\right)} \]
      3. sub-negN/A

        \[\leadsto R \cdot \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{2} + \left(\mathsf{neg}\left(\sin^{-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)\right)\right)\right)} \]
      4. distribute-rgt-inN/A

        \[\leadsto \color{blue}{\frac{\mathsf{PI}\left(\right)}{2} \cdot R + \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R} \]
      5. accelerator-lowering-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\mathsf{PI}\left(\right)}{2}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right)} \]
      6. div-invN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right) \cdot \frac{1}{2}}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right) \cdot \frac{1}{2}}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right) \]
      8. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right)} \cdot \frac{1}{2}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot \color{blue}{\frac{1}{2}}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot \frac{1}{2}, R, \color{blue}{\left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R}\right) \]
    4. Applied egg-rr78.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -2.8 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\lambda_1 + \lambda_2\right)\right) \cdot \frac{1}{\cos \left(\lambda_1 + \lambda_2\right)}\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 3.6 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right), \sin \phi_1 \cdot \phi_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\pi \cdot 0.5, R, \sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot \left(-R\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 83.1% accurate, 0.8× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\phi_2 \leq -5.6 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot t\_0\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 5 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right), \sin \phi_1 \cdot \phi_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\pi \cdot 0.5, R, \sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, t\_0, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot \left(-R\right)\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (cos phi2) (cos (- lambda1 lambda2)))))
   (if (<= phi2 -5.6e-7)
     (* R (acos (fma (sin phi2) (sin phi1) (* (cos phi1) t_0))))
     (if (<= phi2 5e-5)
       (*
        R
        (acos
         (fma
          (cos phi1)
          (fma (cos lambda1) (cos lambda2) (* (sin lambda2) (sin lambda1)))
          (* (sin phi1) phi2))))
       (fma
        (* PI 0.5)
        R
        (* (asin (fma (cos phi1) t_0 (* (sin phi1) (sin phi2)))) (- R)))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos(phi2) * cos((lambda1 - lambda2));
	double tmp;
	if (phi2 <= -5.6e-7) {
		tmp = R * acos(fma(sin(phi2), sin(phi1), (cos(phi1) * t_0)));
	} else if (phi2 <= 5e-5) {
		tmp = R * acos(fma(cos(phi1), fma(cos(lambda1), cos(lambda2), (sin(lambda2) * sin(lambda1))), (sin(phi1) * phi2)));
	} else {
		tmp = fma((((double) M_PI) * 0.5), R, (asin(fma(cos(phi1), t_0, (sin(phi1) * sin(phi2)))) * -R));
	}
	return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(cos(phi2) * cos(Float64(lambda1 - lambda2)))
	tmp = 0.0
	if (phi2 <= -5.6e-7)
		tmp = Float64(R * acos(fma(sin(phi2), sin(phi1), Float64(cos(phi1) * t_0))));
	elseif (phi2 <= 5e-5)
		tmp = Float64(R * acos(fma(cos(phi1), fma(cos(lambda1), cos(lambda2), Float64(sin(lambda2) * sin(lambda1))), Float64(sin(phi1) * phi2))));
	else
		tmp = fma(Float64(pi * 0.5), R, Float64(asin(fma(cos(phi1), t_0, Float64(sin(phi1) * sin(phi2)))) * Float64(-R)));
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -5.6e-7], N[(R * N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 5e-5], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision] + N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(Pi * 0.5), $MachinePrecision] * R + N[(N[ArcSin[N[(N[Cos[phi1], $MachinePrecision] * t$95$0 + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-R)), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_2 \leq -5.6 \cdot 10^{-7}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot t\_0\right)\right)\\

\mathbf{elif}\;\phi_2 \leq 5 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right), \sin \phi_1 \cdot \phi_2\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\pi \cdot 0.5, R, \sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, t\_0, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot \left(-R\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < -5.60000000000000038e-7

    1. Initial program 76.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. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\sin \phi_2 \cdot \sin \phi_1} + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot R \]
      3. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\sin \phi_2}, \sin \phi_1, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right) \cdot R \]
      4. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \color{blue}{\sin \phi_1}, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right) \cdot R \]
      5. associate-*l*N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_1} \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right) \cdot R \]
      8. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

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

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

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

    if -5.60000000000000038e-7 < phi2 < 5.00000000000000024e-5

    1. Initial program 62.8%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      2. +-commutativeN/A

        \[\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. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\color{blue}{\sin \lambda_2 \cdot \sin \lambda_1} + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      4. accelerator-lowering-fma.f64N/A

        \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_2}, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \color{blue}{\sin \lambda_1}, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right)\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1} \cdot \cos \lambda_2\right)\right) \cdot R \]
      9. cos-lowering-cos.f6486.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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right)\right) \cdot R \]
    4. Applied egg-rr86.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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
    5. Taylor expanded in phi1 around inf

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot \cos \phi_1} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      6. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_1}, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \color{blue}{\sin \lambda_2}, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      9. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1} \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      11. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \color{blue}{\cos \phi_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      13. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      14. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      15. sin-lowering-sin.f64N/A

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

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

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\phi_2 \cdot \sin \phi_1 + \cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
    9. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right) + \phi_2 \cdot \sin \phi_1\right)} \cdot R \]
      2. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_1}, \cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2, \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      4. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \color{blue}{\mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)}, \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\color{blue}{\cos \lambda_1}, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right), \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \color{blue}{\cos \lambda_2}, \sin \lambda_1 \cdot \sin \lambda_2\right), \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right), \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right), \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      9. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right), \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      10. *-lowering-*.f64N/A

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

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

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

    if 5.00000000000000024e-5 < phi2

    1. Initial program 78.6%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{R \cdot \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)} \]
      2. acos-asinN/A

        \[\leadsto R \cdot \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{2} - \sin^{-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)\right)} \]
      3. sub-negN/A

        \[\leadsto R \cdot \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{2} + \left(\mathsf{neg}\left(\sin^{-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)\right)\right)\right)} \]
      4. distribute-rgt-inN/A

        \[\leadsto \color{blue}{\frac{\mathsf{PI}\left(\right)}{2} \cdot R + \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R} \]
      5. accelerator-lowering-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\mathsf{PI}\left(\right)}{2}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right)} \]
      6. div-invN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right) \cdot \frac{1}{2}}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right) \cdot \frac{1}{2}}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right) \]
      8. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right)} \cdot \frac{1}{2}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot \color{blue}{\frac{1}{2}}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot \frac{1}{2}, R, \color{blue}{\left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R}\right) \]
    4. Applied egg-rr78.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -5.6 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 5 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right), \sin \phi_1 \cdot \phi_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\pi \cdot 0.5, R, \sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot \left(-R\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 83.1% accurate, 0.8× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\phi_2 \leq -2.3 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot t\_0\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 2.5 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\phi_2, \sin \phi_1, \cos \phi_1 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\pi \cdot 0.5, R, \sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, t\_0, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot \left(-R\right)\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (cos phi2) (cos (- lambda1 lambda2)))))
   (if (<= phi2 -2.3e-6)
     (* R (acos (fma (sin phi2) (sin phi1) (* (cos phi1) t_0))))
     (if (<= phi2 2.5e-6)
       (*
        R
        (acos
         (fma
          phi2
          (sin phi1)
          (*
           (cos phi1)
           (fma
            (sin lambda1)
            (sin lambda2)
            (* (cos lambda1) (cos lambda2)))))))
       (fma
        (* PI 0.5)
        R
        (* (asin (fma (cos phi1) t_0 (* (sin phi1) (sin phi2)))) (- R)))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos(phi2) * cos((lambda1 - lambda2));
	double tmp;
	if (phi2 <= -2.3e-6) {
		tmp = R * acos(fma(sin(phi2), sin(phi1), (cos(phi1) * t_0)));
	} else if (phi2 <= 2.5e-6) {
		tmp = R * acos(fma(phi2, sin(phi1), (cos(phi1) * fma(sin(lambda1), sin(lambda2), (cos(lambda1) * cos(lambda2))))));
	} else {
		tmp = fma((((double) M_PI) * 0.5), R, (asin(fma(cos(phi1), t_0, (sin(phi1) * sin(phi2)))) * -R));
	}
	return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(cos(phi2) * cos(Float64(lambda1 - lambda2)))
	tmp = 0.0
	if (phi2 <= -2.3e-6)
		tmp = Float64(R * acos(fma(sin(phi2), sin(phi1), Float64(cos(phi1) * t_0))));
	elseif (phi2 <= 2.5e-6)
		tmp = Float64(R * acos(fma(phi2, sin(phi1), Float64(cos(phi1) * fma(sin(lambda1), sin(lambda2), Float64(cos(lambda1) * cos(lambda2)))))));
	else
		tmp = fma(Float64(pi * 0.5), R, Float64(asin(fma(cos(phi1), t_0, Float64(sin(phi1) * sin(phi2)))) * Float64(-R)));
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -2.3e-6], N[(R * N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 2.5e-6], N[(R * N[ArcCos[N[(phi2 * N[Sin[phi1], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(Pi * 0.5), $MachinePrecision] * R + N[(N[ArcSin[N[(N[Cos[phi1], $MachinePrecision] * t$95$0 + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-R)), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_2 \leq -2.3 \cdot 10^{-6}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot t\_0\right)\right)\\

\mathbf{elif}\;\phi_2 \leq 2.5 \cdot 10^{-6}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\phi_2, \sin \phi_1, \cos \phi_1 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\pi \cdot 0.5, R, \sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, t\_0, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot \left(-R\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < -2.3e-6

    1. Initial program 76.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. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\sin \phi_2 \cdot \sin \phi_1} + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot R \]
      3. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\sin \phi_2}, \sin \phi_1, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right) \cdot R \]
      4. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \color{blue}{\sin \phi_1}, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right) \cdot R \]
      5. associate-*l*N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_1} \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right) \cdot R \]
      8. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

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

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

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

    if -2.3e-6 < phi2 < 2.5000000000000002e-6

    1. Initial program 62.8%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      2. +-commutativeN/A

        \[\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. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\color{blue}{\sin \lambda_2 \cdot \sin \lambda_1} + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      4. accelerator-lowering-fma.f64N/A

        \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_2}, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \color{blue}{\sin \lambda_1}, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right)\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1} \cdot \cos \lambda_2\right)\right) \cdot R \]
      9. cos-lowering-cos.f6486.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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right)\right) \cdot R \]
    4. Applied egg-rr86.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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
    5. Taylor expanded in phi2 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\phi_2 \cdot \sin \phi_1 + \cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
    6. Step-by-step derivation
      1. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)} \cdot R \]
      2. sin-lowering-sin.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\phi_2, \sin \phi_1, \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_1}\right)\right) \cdot R \]
      4. *-lowering-*.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\phi_2, \sin \phi_1, \color{blue}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)} \cdot \cos \phi_1\right)\right) \cdot R \]
      6. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\phi_2, \sin \phi_1, \color{blue}{\mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right)} \cdot \cos \phi_1\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\phi_2, \sin \phi_1, \mathsf{fma}\left(\color{blue}{\sin \lambda_1}, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \cos \phi_1\right)\right) \cdot R \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\phi_2, \sin \phi_1, \mathsf{fma}\left(\sin \lambda_1, \color{blue}{\sin \lambda_2}, \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \cos \phi_1\right)\right) \cdot R \]
      9. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\phi_2, \sin \phi_1, \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right) \cdot \cos \phi_1\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\phi_2, \sin \phi_1, \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1} \cdot \cos \lambda_2\right) \cdot \cos \phi_1\right)\right) \cdot R \]
      11. cos-lowering-cos.f64N/A

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

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

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

    if 2.5000000000000002e-6 < phi2

    1. Initial program 78.6%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{R \cdot \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)} \]
      2. acos-asinN/A

        \[\leadsto R \cdot \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{2} - \sin^{-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)\right)} \]
      3. sub-negN/A

        \[\leadsto R \cdot \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{2} + \left(\mathsf{neg}\left(\sin^{-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)\right)\right)\right)} \]
      4. distribute-rgt-inN/A

        \[\leadsto \color{blue}{\frac{\mathsf{PI}\left(\right)}{2} \cdot R + \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R} \]
      5. accelerator-lowering-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\mathsf{PI}\left(\right)}{2}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right)} \]
      6. div-invN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right) \cdot \frac{1}{2}}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right) \cdot \frac{1}{2}}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right) \]
      8. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right)} \cdot \frac{1}{2}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot \color{blue}{\frac{1}{2}}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot \frac{1}{2}, R, \color{blue}{\left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R}\right) \]
    4. Applied egg-rr78.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -2.3 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 2.5 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\phi_2, \sin \phi_1, \cos \phi_1 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\pi \cdot 0.5, R, \sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot \left(-R\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 82.9% accurate, 1.0× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\phi_2 \leq -7 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot t\_0\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 1.25 \cdot 10^{-8}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\pi \cdot 0.5, R, \sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, t\_0, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot \left(-R\right)\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (cos phi2) (cos (- lambda1 lambda2)))))
   (if (<= phi2 -7e-9)
     (* R (acos (fma (sin phi2) (sin phi1) (* (cos phi1) t_0))))
     (if (<= phi2 1.25e-8)
       (*
        R
        (acos
         (*
          (cos phi1)
          (fma (cos lambda1) (cos lambda2) (* (sin lambda2) (sin lambda1))))))
       (fma
        (* PI 0.5)
        R
        (* (asin (fma (cos phi1) t_0 (* (sin phi1) (sin phi2)))) (- R)))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos(phi2) * cos((lambda1 - lambda2));
	double tmp;
	if (phi2 <= -7e-9) {
		tmp = R * acos(fma(sin(phi2), sin(phi1), (cos(phi1) * t_0)));
	} else if (phi2 <= 1.25e-8) {
		tmp = R * acos((cos(phi1) * fma(cos(lambda1), cos(lambda2), (sin(lambda2) * sin(lambda1)))));
	} else {
		tmp = fma((((double) M_PI) * 0.5), R, (asin(fma(cos(phi1), t_0, (sin(phi1) * sin(phi2)))) * -R));
	}
	return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(cos(phi2) * cos(Float64(lambda1 - lambda2)))
	tmp = 0.0
	if (phi2 <= -7e-9)
		tmp = Float64(R * acos(fma(sin(phi2), sin(phi1), Float64(cos(phi1) * t_0))));
	elseif (phi2 <= 1.25e-8)
		tmp = Float64(R * acos(Float64(cos(phi1) * fma(cos(lambda1), cos(lambda2), Float64(sin(lambda2) * sin(lambda1))))));
	else
		tmp = fma(Float64(pi * 0.5), R, Float64(asin(fma(cos(phi1), t_0, Float64(sin(phi1) * sin(phi2)))) * Float64(-R)));
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -7e-9], N[(R * N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 1.25e-8], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision] + N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(Pi * 0.5), $MachinePrecision] * R + N[(N[ArcSin[N[(N[Cos[phi1], $MachinePrecision] * t$95$0 + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-R)), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_2 \leq -7 \cdot 10^{-9}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot t\_0\right)\right)\\

\mathbf{elif}\;\phi_2 \leq 1.25 \cdot 10^{-8}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\pi \cdot 0.5, R, \sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, t\_0, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot \left(-R\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < -6.9999999999999998e-9

    1. Initial program 76.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. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\sin \phi_2 \cdot \sin \phi_1} + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot R \]
      3. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\sin \phi_2}, \sin \phi_1, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right) \cdot R \]
      4. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \color{blue}{\sin \phi_1}, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right) \cdot R \]
      5. associate-*l*N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_1} \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right) \cdot R \]
      8. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

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

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

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

    if -6.9999999999999998e-9 < phi2 < 1.2499999999999999e-8

    1. Initial program 62.8%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      2. +-commutativeN/A

        \[\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. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\color{blue}{\sin \lambda_2 \cdot \sin \lambda_1} + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      4. accelerator-lowering-fma.f64N/A

        \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_2}, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \color{blue}{\sin \lambda_1}, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right)\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1} \cdot \cos \lambda_2\right)\right) \cdot R \]
      9. cos-lowering-cos.f6486.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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right)\right) \cdot R \]
    4. Applied egg-rr86.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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
    5. Taylor expanded in phi1 around inf

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot \cos \phi_1} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      6. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_1}, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \color{blue}{\sin \lambda_2}, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      9. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1} \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      11. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \color{blue}{\cos \phi_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      13. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      14. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      15. sin-lowering-sin.f64N/A

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

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

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_1} \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      3. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \color{blue}{\mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\color{blue}{\cos \lambda_1}, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \color{blue}{\cos \lambda_2}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
      8. sin-lowering-sin.f6486.7

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right)\right) \cdot R \]
    10. Simplified86.7%

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

    if 1.2499999999999999e-8 < phi2

    1. Initial program 78.6%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{R \cdot \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)} \]
      2. acos-asinN/A

        \[\leadsto R \cdot \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{2} - \sin^{-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)\right)} \]
      3. sub-negN/A

        \[\leadsto R \cdot \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{2} + \left(\mathsf{neg}\left(\sin^{-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)\right)\right)\right)} \]
      4. distribute-rgt-inN/A

        \[\leadsto \color{blue}{\frac{\mathsf{PI}\left(\right)}{2} \cdot R + \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R} \]
      5. accelerator-lowering-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\mathsf{PI}\left(\right)}{2}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right)} \]
      6. div-invN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right) \cdot \frac{1}{2}}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right) \cdot \frac{1}{2}}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right) \]
      8. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right)} \cdot \frac{1}{2}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot \color{blue}{\frac{1}{2}}, R, \left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot \frac{1}{2}, R, \color{blue}{\left(\mathsf{neg}\left(\sin^{-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)\right)\right) \cdot R}\right) \]
    4. Applied egg-rr78.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -7 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 1.25 \cdot 10^{-8}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\pi \cdot 0.5, R, \sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot \left(-R\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 73.5% accurate, 1.0× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \sin \phi_1 \cdot \sin \phi_2\\ t_1 := \sin \lambda_2 \cdot \sin \lambda_1\\ \mathbf{if}\;\phi_1 \leq -9.8 \cdot 10^{+203}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_2, t\_0\right)\right)\\ \mathbf{elif}\;\phi_1 \leq -2.35 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, t\_1\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 1.26 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, t\_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_1, t\_0\right)\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (sin phi1) (sin phi2))) (t_1 (* (sin lambda2) (sin lambda1))))
   (if (<= phi1 -9.8e+203)
     (* R (acos (fma (cos phi2) (* (cos phi1) (cos lambda2)) t_0)))
     (if (<= phi1 -2.35e-6)
       (* R (acos (* (cos phi1) (fma (cos lambda1) (cos lambda2) t_1))))
       (if (<= phi1 1.26e-5)
         (* R (acos (* (cos phi2) (fma (cos lambda2) (cos lambda1) t_1))))
         (* R (acos (fma (cos phi2) (* (cos phi1) (cos lambda1)) t_0))))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(phi1) * sin(phi2);
	double t_1 = sin(lambda2) * sin(lambda1);
	double tmp;
	if (phi1 <= -9.8e+203) {
		tmp = R * acos(fma(cos(phi2), (cos(phi1) * cos(lambda2)), t_0));
	} else if (phi1 <= -2.35e-6) {
		tmp = R * acos((cos(phi1) * fma(cos(lambda1), cos(lambda2), t_1)));
	} else if (phi1 <= 1.26e-5) {
		tmp = R * acos((cos(phi2) * fma(cos(lambda2), cos(lambda1), t_1)));
	} else {
		tmp = R * acos(fma(cos(phi2), (cos(phi1) * cos(lambda1)), t_0));
	}
	return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(sin(phi1) * sin(phi2))
	t_1 = Float64(sin(lambda2) * sin(lambda1))
	tmp = 0.0
	if (phi1 <= -9.8e+203)
		tmp = Float64(R * acos(fma(cos(phi2), Float64(cos(phi1) * cos(lambda2)), t_0)));
	elseif (phi1 <= -2.35e-6)
		tmp = Float64(R * acos(Float64(cos(phi1) * fma(cos(lambda1), cos(lambda2), t_1))));
	elseif (phi1 <= 1.26e-5)
		tmp = Float64(R * acos(Float64(cos(phi2) * fma(cos(lambda2), cos(lambda1), t_1))));
	else
		tmp = Float64(R * acos(fma(cos(phi2), Float64(cos(phi1) * cos(lambda1)), t_0)));
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -9.8e+203], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, -2.35e-6], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 1.26e-5], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \sin \phi_1 \cdot \sin \phi_2\\
t_1 := \sin \lambda_2 \cdot \sin \lambda_1\\
\mathbf{if}\;\phi_1 \leq -9.8 \cdot 10^{+203}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_2, t\_0\right)\right)\\

\mathbf{elif}\;\phi_1 \leq -2.35 \cdot 10^{-6}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, t\_1\right)\right)\\

\mathbf{elif}\;\phi_1 \leq 1.26 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, t\_1\right)\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_1, t\_0\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if phi1 < -9.7999999999999995e203

    1. Initial program 75.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. Add Preprocessing
    3. Taylor expanded in lambda1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
    4. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      2. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\left(\cos \phi_2 \cdot \cos \phi_1\right)} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      3. associate-*l*N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      4. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right), \sin \phi_1 \cdot \sin \phi_2\right)\right)} \cdot R \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2}, \cos \phi_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right), \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right), \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \color{blue}{\cos \lambda_2}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \color{blue}{\cos \lambda_2}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      10. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_2, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      11. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_2, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      12. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_2, \color{blue}{\sin \phi_2} \cdot \sin \phi_1\right)\right) \cdot R \]
      13. sin-lowering-sin.f6456.5

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

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

    if -9.7999999999999995e203 < phi1 < -2.34999999999999995e-6

    1. Initial program 74.1%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      2. +-commutativeN/A

        \[\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. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\color{blue}{\sin \lambda_2 \cdot \sin \lambda_1} + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      4. accelerator-lowering-fma.f64N/A

        \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_2}, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \color{blue}{\sin \lambda_1}, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right)\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1} \cdot \cos \lambda_2\right)\right) \cdot R \]
      9. cos-lowering-cos.f6498.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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right)\right) \cdot R \]
    4. Applied egg-rr98.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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
    5. Taylor expanded in phi1 around inf

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot \cos \phi_1} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      6. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_1}, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \color{blue}{\sin \lambda_2}, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      9. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1} \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      11. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \color{blue}{\cos \phi_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      13. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      14. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      15. sin-lowering-sin.f64N/A

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

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

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_1} \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      3. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \color{blue}{\mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\color{blue}{\cos \lambda_1}, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \color{blue}{\cos \lambda_2}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
      8. sin-lowering-sin.f6459.7

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right)\right) \cdot R \]
    10. Simplified59.7%

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

    if -2.34999999999999995e-6 < phi1 < 1.25999999999999996e-5

    1. Initial program 62.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. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f6462.4

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)} \cdot R \]
    6. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right)}\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_2 \cdot \sin \lambda_1\right)}\right) \cdot R \]
      3. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_2 \cdot \sin \lambda_1\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_2 \cdot \sin \lambda_1\right)\right) \cdot R \]
      5. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_2 \cdot \sin \lambda_1}\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_2} \cdot \sin \lambda_1\right)\right) \cdot R \]
      7. sin-lowering-sin.f6486.9

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

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

    if 1.25999999999999996e-5 < phi1

    1. Initial program 83.1%

      \[\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. Add Preprocessing
    3. Taylor expanded in lambda2 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \lambda_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right) + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
    4. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\left(\cos \lambda_1 \cdot \cos \phi_1\right) \cdot \cos \phi_2} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      2. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \phi_1\right)} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      3. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\cos \phi_2, \cos \lambda_1 \cdot \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)} \cdot R \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2}, \cos \lambda_1 \cdot \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      5. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1 \cdot \cos \lambda_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1 \cdot \cos \lambda_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1} \cdot \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \color{blue}{\cos \lambda_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      9. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      10. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      11. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_1, \color{blue}{\sin \phi_2} \cdot \sin \phi_1\right)\right) \cdot R \]
      12. sin-lowering-sin.f6456.3

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_1, \sin \phi_2 \cdot \color{blue}{\sin \phi_1}\right)\right) \cdot R \]
    5. Simplified56.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -9.8 \cdot 10^{+203}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_2, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\ \mathbf{elif}\;\phi_1 \leq -2.35 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 1.26 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \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(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 82.9% accurate, 1.0× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\phi_2 \leq -2.6 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot t\_0\right)\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 2.8 \cdot 10^{-10}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\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} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (cos (- lambda1 lambda2))))
   (if (<= phi2 -2.6e-9)
     (* R (acos (fma (sin phi2) (sin phi1) (* (cos phi1) (* (cos phi2) t_0)))))
     (if (<= phi2 2.8e-10)
       (*
        R
        (acos
         (*
          (cos phi1)
          (fma (cos lambda1) (cos lambda2) (* (sin lambda2) (sin lambda1))))))
       (*
        (acos (+ (* (sin phi1) (sin phi2)) (* (* (cos phi1) (cos phi2)) t_0)))
        R)))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos((lambda1 - lambda2));
	double tmp;
	if (phi2 <= -2.6e-9) {
		tmp = R * acos(fma(sin(phi2), sin(phi1), (cos(phi1) * (cos(phi2) * t_0))));
	} else if (phi2 <= 2.8e-10) {
		tmp = R * acos((cos(phi1) * fma(cos(lambda1), cos(lambda2), (sin(lambda2) * sin(lambda1)))));
	} else {
		tmp = acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * t_0))) * R;
	}
	return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = cos(Float64(lambda1 - lambda2))
	tmp = 0.0
	if (phi2 <= -2.6e-9)
		tmp = Float64(R * acos(fma(sin(phi2), sin(phi1), Float64(cos(phi1) * Float64(cos(phi2) * t_0)))));
	elseif (phi2 <= 2.8e-10)
		tmp = Float64(R * acos(Float64(cos(phi1) * fma(cos(lambda1), cos(lambda2), Float64(sin(lambda2) * sin(lambda1))))));
	else
		tmp = Float64(acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * t_0))) * R);
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -2.6e-9], N[(R * N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 2.8e-10], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision] + N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 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] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_2 \leq -2.6 \cdot 10^{-9}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot t\_0\right)\right)\right)\\

\mathbf{elif}\;\phi_2 \leq 2.8 \cdot 10^{-10}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\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}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < -2.6000000000000001e-9

    1. Initial program 76.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. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\sin \phi_2 \cdot \sin \phi_1} + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot R \]
      3. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\sin \phi_2}, \sin \phi_1, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right) \cdot R \]
      4. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \color{blue}{\sin \phi_1}, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right) \cdot R \]
      5. associate-*l*N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_1} \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right) \cdot R \]
      8. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

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

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

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

    if -2.6000000000000001e-9 < phi2 < 2.80000000000000015e-10

    1. Initial program 62.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. Add Preprocessing
    3. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      2. +-commutativeN/A

        \[\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. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\color{blue}{\sin \lambda_2 \cdot \sin \lambda_1} + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      4. accelerator-lowering-fma.f64N/A

        \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_2}, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \color{blue}{\sin \lambda_1}, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right)\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

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

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right)\right) \cdot R \]
    4. Applied egg-rr86.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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
    5. Taylor expanded in phi1 around inf

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot \cos \phi_1} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      6. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_1}, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \color{blue}{\sin \lambda_2}, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      9. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1} \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      11. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \color{blue}{\cos \phi_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      13. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      14. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      15. sin-lowering-sin.f64N/A

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

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

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_1} \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      3. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \color{blue}{\mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\color{blue}{\cos \lambda_1}, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \color{blue}{\cos \lambda_2}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
      8. sin-lowering-sin.f6486.6

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right)\right) \cdot R \]
    10. Simplified86.6%

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

    if 2.80000000000000015e-10 < phi2

    1. Initial program 78.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. Add Preprocessing
  3. Recombined 3 regimes into one program.
  4. Final simplification81.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -2.6 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 2.8 \cdot 10^{-10}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\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\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 82.9% accurate, 1.0× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq -6.3 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 9.1 \cdot 10^{-10}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi2 -6.3e-9)
   (*
    R
    (acos
     (fma
      (sin phi2)
      (sin phi1)
      (* (cos phi1) (* (cos phi2) (cos (- lambda1 lambda2)))))))
   (if (<= phi2 9.1e-10)
     (*
      R
      (acos
       (*
        (cos phi1)
        (fma (cos lambda1) (cos lambda2) (* (sin lambda2) (sin lambda1))))))
     (*
      R
      (acos
       (fma
        (sin phi2)
        (sin phi1)
        (* (cos phi2) (* (cos phi1) (cos (- lambda2 lambda1))))))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= -6.3e-9) {
		tmp = R * acos(fma(sin(phi2), sin(phi1), (cos(phi1) * (cos(phi2) * cos((lambda1 - lambda2))))));
	} else if (phi2 <= 9.1e-10) {
		tmp = R * acos((cos(phi1) * fma(cos(lambda1), cos(lambda2), (sin(lambda2) * sin(lambda1)))));
	} else {
		tmp = R * acos(fma(sin(phi2), sin(phi1), (cos(phi2) * (cos(phi1) * cos((lambda2 - lambda1))))));
	}
	return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= -6.3e-9)
		tmp = Float64(R * acos(fma(sin(phi2), sin(phi1), Float64(cos(phi1) * Float64(cos(phi2) * cos(Float64(lambda1 - lambda2)))))));
	elseif (phi2 <= 9.1e-10)
		tmp = Float64(R * acos(Float64(cos(phi1) * fma(cos(lambda1), cos(lambda2), Float64(sin(lambda2) * sin(lambda1))))));
	else
		tmp = Float64(R * acos(fma(sin(phi2), sin(phi1), Float64(cos(phi2) * Float64(cos(phi1) * cos(Float64(lambda2 - lambda1)))))));
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, -6.3e-9], N[(R * N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 9.1e-10], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision] + N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq -6.3 \cdot 10^{-9}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\\

\mathbf{elif}\;\phi_2 \leq 9.1 \cdot 10^{-10}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < -6.3000000000000002e-9

    1. Initial program 76.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. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\sin \phi_2 \cdot \sin \phi_1} + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot R \]
      3. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\sin \phi_2}, \sin \phi_1, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right) \cdot R \]
      4. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \color{blue}{\sin \phi_1}, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right) \cdot R \]
      5. associate-*l*N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_1} \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right) \cdot R \]
      8. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

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

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

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

    if -6.3000000000000002e-9 < phi2 < 9.0999999999999996e-10

    1. Initial program 62.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. Add Preprocessing
    3. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      2. +-commutativeN/A

        \[\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. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\color{blue}{\sin \lambda_2 \cdot \sin \lambda_1} + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      4. accelerator-lowering-fma.f64N/A

        \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_2}, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \color{blue}{\sin \lambda_1}, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right)\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

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

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right)\right) \cdot R \]
    4. Applied egg-rr86.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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
    5. Taylor expanded in phi1 around inf

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot \cos \phi_1} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      6. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_1}, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \color{blue}{\sin \lambda_2}, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      9. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1} \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      11. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \color{blue}{\cos \phi_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      13. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      14. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      15. sin-lowering-sin.f64N/A

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

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

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_1} \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      3. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \color{blue}{\mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\color{blue}{\cos \lambda_1}, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \color{blue}{\cos \lambda_2}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
      8. sin-lowering-sin.f6486.6

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right)\right) \cdot R \]
    10. Simplified86.6%

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

    if 9.0999999999999996e-10 < phi2

    1. Initial program 78.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. Add Preprocessing
    3. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      2. +-commutativeN/A

        \[\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. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\color{blue}{\sin \lambda_2 \cdot \sin \lambda_1} + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      4. accelerator-lowering-fma.f64N/A

        \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_2}, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \color{blue}{\sin \lambda_1}, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right)\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

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

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

      \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
    5. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\sin \phi_2 \cdot \sin \phi_1} + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\sin \phi_2}, \sin \phi_1, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right) \cdot R \]
      4. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \color{blue}{\sin \phi_1}, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right) \cdot R \]
      5. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\left(\cos \phi_2 \cdot \cos \phi_1\right)} \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right) \cdot R \]
      6. associate-*l*N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)}\right)\right) \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_2 \cdot \left(\cos \phi_1 \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)}\right)\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_2} \cdot \left(\cos \phi_1 \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right) \cdot R \]
      9. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_2 \cdot \color{blue}{\left(\cos \phi_1 \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)}\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_2 \cdot \sin \lambda_1\right)}\right)\right)\right) \cdot R \]
      12. *-commutativeN/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \color{blue}{\cos \left(\lambda_2 - \lambda_1\right)}\right)\right)\right) \cdot R \]
      14. cos-lowering-cos.f64N/A

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -6.3 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 9.1 \cdot 10^{-10}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 82.9% accurate, 1.0× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\\ \mathbf{if}\;\phi_2 \leq -2.8 \cdot 10^{-11}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_2 \leq 1.28 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0
         (*
          R
          (acos
           (fma
            (sin phi2)
            (sin phi1)
            (* (cos phi1) (* (cos phi2) (cos (- lambda1 lambda2)))))))))
   (if (<= phi2 -2.8e-11)
     t_0
     (if (<= phi2 1.28e-9)
       (*
        R
        (acos
         (*
          (cos phi1)
          (fma (cos lambda1) (cos lambda2) (* (sin lambda2) (sin lambda1))))))
       t_0))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * acos(fma(sin(phi2), sin(phi1), (cos(phi1) * (cos(phi2) * cos((lambda1 - lambda2))))));
	double tmp;
	if (phi2 <= -2.8e-11) {
		tmp = t_0;
	} else if (phi2 <= 1.28e-9) {
		tmp = R * acos((cos(phi1) * fma(cos(lambda1), cos(lambda2), (sin(lambda2) * sin(lambda1)))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(R * acos(fma(sin(phi2), sin(phi1), Float64(cos(phi1) * Float64(cos(phi2) * cos(Float64(lambda1 - lambda2)))))))
	tmp = 0.0
	if (phi2 <= -2.8e-11)
		tmp = t_0;
	elseif (phi2 <= 1.28e-9)
		tmp = Float64(R * acos(Float64(cos(phi1) * fma(cos(lambda1), cos(lambda2), Float64(sin(lambda2) * sin(lambda1))))));
	else
		tmp = t_0;
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(R * N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -2.8e-11], t$95$0, If[LessEqual[phi2, 1.28e-9], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision] + N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\\
\mathbf{if}\;\phi_2 \leq -2.8 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\phi_2 \leq 1.28 \cdot 10^{-9}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < -2.8e-11 or 1.27999999999999992e-9 < phi2

    1. Initial program 77.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. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\sin \phi_2 \cdot \sin \phi_1} + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot R \]
      3. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\sin \phi_2}, \sin \phi_1, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right) \cdot R \]
      4. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \color{blue}{\sin \phi_1}, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right) \cdot R \]
      5. associate-*l*N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \color{blue}{\cos \phi_1} \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right) \cdot R \]
      8. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

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

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

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

    if -2.8e-11 < phi2 < 1.27999999999999992e-9

    1. Initial program 62.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. Add Preprocessing
    3. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      2. +-commutativeN/A

        \[\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. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\color{blue}{\sin \lambda_2 \cdot \sin \lambda_1} + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      4. accelerator-lowering-fma.f64N/A

        \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_2}, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \color{blue}{\sin \lambda_1}, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right)\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

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

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right)\right) \cdot R \]
    4. Applied egg-rr86.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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
    5. Taylor expanded in phi1 around inf

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot \cos \phi_1} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      6. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_1}, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \color{blue}{\sin \lambda_2}, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      9. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1} \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      11. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \color{blue}{\cos \phi_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      13. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      14. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      15. sin-lowering-sin.f64N/A

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

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

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_1} \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      3. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \color{blue}{\mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\color{blue}{\cos \lambda_1}, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \color{blue}{\cos \lambda_2}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
      8. sin-lowering-sin.f6486.6

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right)\right) \cdot R \]
    10. Simplified86.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -2.8 \cdot 10^{-11}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 1.28 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 73.3% accurate, 1.0× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \sin \lambda_2 \cdot \sin \lambda_1\\ \mathbf{if}\;\phi_1 \leq -3 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, t\_0\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 1.3 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, t\_0\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (sin lambda2) (sin lambda1))))
   (if (<= phi1 -3e-6)
     (* R (acos (* (cos phi1) (fma (cos lambda1) (cos lambda2) t_0))))
     (if (<= phi1 1.3e-5)
       (* R (acos (* (cos phi2) (fma (cos lambda2) (cos lambda1) t_0))))
       (*
        R
        (acos
         (fma
          (cos phi2)
          (* (cos phi1) (cos lambda1))
          (* (sin phi1) (sin phi2)))))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(lambda2) * sin(lambda1);
	double tmp;
	if (phi1 <= -3e-6) {
		tmp = R * acos((cos(phi1) * fma(cos(lambda1), cos(lambda2), t_0)));
	} else if (phi1 <= 1.3e-5) {
		tmp = R * acos((cos(phi2) * fma(cos(lambda2), cos(lambda1), t_0)));
	} else {
		tmp = R * acos(fma(cos(phi2), (cos(phi1) * cos(lambda1)), (sin(phi1) * sin(phi2))));
	}
	return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(sin(lambda2) * sin(lambda1))
	tmp = 0.0
	if (phi1 <= -3e-6)
		tmp = Float64(R * acos(Float64(cos(phi1) * fma(cos(lambda1), cos(lambda2), t_0))));
	elseif (phi1 <= 1.3e-5)
		tmp = Float64(R * acos(Float64(cos(phi2) * fma(cos(lambda2), cos(lambda1), t_0))));
	else
		tmp = Float64(R * acos(fma(cos(phi2), Float64(cos(phi1) * cos(lambda1)), Float64(sin(phi1) * sin(phi2)))));
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -3e-6], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 1.3e-5], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \sin \lambda_2 \cdot \sin \lambda_1\\
\mathbf{if}\;\phi_1 \leq -3 \cdot 10^{-6}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, t\_0\right)\right)\\

\mathbf{elif}\;\phi_1 \leq 1.3 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, t\_0\right)\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi1 < -3.0000000000000001e-6

    1. Initial program 74.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. Add Preprocessing
    3. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      2. +-commutativeN/A

        \[\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. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\color{blue}{\sin \lambda_2 \cdot \sin \lambda_1} + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      4. accelerator-lowering-fma.f64N/A

        \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_2}, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \color{blue}{\sin \lambda_1}, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right)\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

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

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

      \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
    5. Taylor expanded in phi1 around inf

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot \cos \phi_1} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      6. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_1}, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \color{blue}{\sin \lambda_2}, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      9. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1} \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      11. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \color{blue}{\cos \phi_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      13. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      14. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      15. sin-lowering-sin.f64N/A

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

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

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_1} \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      3. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \color{blue}{\mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\color{blue}{\cos \lambda_1}, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \color{blue}{\cos \lambda_2}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
      8. sin-lowering-sin.f6456.2

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right)\right) \cdot R \]
    10. Simplified56.2%

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

    if -3.0000000000000001e-6 < phi1 < 1.29999999999999992e-5

    1. Initial program 62.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. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f6462.4

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)} \cdot R \]
    6. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right)}\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_2 \cdot \sin \lambda_1\right)}\right) \cdot R \]
      3. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_2 \cdot \sin \lambda_1\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_2 \cdot \sin \lambda_1\right)\right) \cdot R \]
      5. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_2 \cdot \sin \lambda_1}\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_2} \cdot \sin \lambda_1\right)\right) \cdot R \]
      7. sin-lowering-sin.f6486.9

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

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

    if 1.29999999999999992e-5 < phi1

    1. Initial program 83.1%

      \[\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. Add Preprocessing
    3. Taylor expanded in lambda2 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \lambda_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right) + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
    4. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\left(\cos \lambda_1 \cdot \cos \phi_1\right) \cdot \cos \phi_2} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      2. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \phi_1\right)} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      3. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\cos \phi_2, \cos \lambda_1 \cdot \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)} \cdot R \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2}, \cos \lambda_1 \cdot \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      5. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1 \cdot \cos \lambda_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1 \cdot \cos \lambda_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1} \cdot \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \color{blue}{\cos \lambda_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      9. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      10. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      11. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_1, \color{blue}{\sin \phi_2} \cdot \sin \phi_1\right)\right) \cdot R \]
      12. sin-lowering-sin.f6456.3

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_1, \sin \phi_2 \cdot \color{blue}{\sin \phi_1}\right)\right) \cdot R \]
    5. Simplified56.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -3 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 1.3 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \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(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1 \cdot \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 67.6% accurate, 1.0× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \sin \lambda_2 \cdot \sin \lambda_1\\ \mathbf{if}\;\phi_2 \leq -0.01:\\ \;\;\;\;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 1.36 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, t\_0\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, t\_0\right)\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (sin lambda2) (sin lambda1))))
   (if (<= phi2 -0.01)
     (* R (acos (fma (cos phi2) (cos phi1) (* (sin phi1) (sin phi2)))))
     (if (<= phi2 1.36e-9)
       (* R (acos (* (cos phi1) (fma (cos lambda1) (cos lambda2) t_0))))
       (* R (acos (* (cos phi2) (fma (cos lambda2) (cos lambda1) t_0))))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(lambda2) * sin(lambda1);
	double tmp;
	if (phi2 <= -0.01) {
		tmp = R * acos(fma(cos(phi2), cos(phi1), (sin(phi1) * sin(phi2))));
	} else if (phi2 <= 1.36e-9) {
		tmp = R * acos((cos(phi1) * fma(cos(lambda1), cos(lambda2), t_0)));
	} else {
		tmp = R * acos((cos(phi2) * fma(cos(lambda2), cos(lambda1), t_0)));
	}
	return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(sin(lambda2) * sin(lambda1))
	tmp = 0.0
	if (phi2 <= -0.01)
		tmp = Float64(R * acos(fma(cos(phi2), cos(phi1), Float64(sin(phi1) * sin(phi2)))));
	elseif (phi2 <= 1.36e-9)
		tmp = Float64(R * acos(Float64(cos(phi1) * fma(cos(lambda1), cos(lambda2), t_0))));
	else
		tmp = Float64(R * acos(Float64(cos(phi2) * fma(cos(lambda2), cos(lambda1), t_0))));
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -0.01], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 1.36e-9], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \sin \lambda_2 \cdot \sin \lambda_1\\
\mathbf{if}\;\phi_2 \leq -0.01:\\
\;\;\;\;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 1.36 \cdot 10^{-9}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, t\_0\right)\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, t\_0\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < -0.0100000000000000002

    1. Initial program 76.8%

      \[\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. Add Preprocessing
    3. Taylor expanded in lambda2 around 0

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \lambda_1}\right) \cdot R \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f6463.1

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

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \lambda_1}\right) \cdot R \]
    6. Taylor expanded in lambda1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \cos \phi_2 + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
    7. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2 \cdot \cos \phi_1} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)} \cdot R \]
      3. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      5. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \color{blue}{\sin \phi_2} \cdot \sin \phi_1\right)\right) \cdot R \]
      8. sin-lowering-sin.f6442.5

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \sin \phi_2 \cdot \color{blue}{\sin \phi_1}\right)\right) \cdot R \]
    8. Simplified42.5%

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

    if -0.0100000000000000002 < phi2 < 1.36000000000000006e-9

    1. Initial program 62.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. Add Preprocessing
    3. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      2. +-commutativeN/A

        \[\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. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\color{blue}{\sin \lambda_2 \cdot \sin \lambda_1} + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      4. accelerator-lowering-fma.f64N/A

        \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_2}, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \color{blue}{\sin \lambda_1}, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right)\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

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

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

      \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
    5. Taylor expanded in phi1 around inf

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot \cos \phi_1} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      6. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_1}, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \color{blue}{\sin \lambda_2}, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      9. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1} \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      11. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \color{blue}{\cos \phi_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      13. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      14. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      15. sin-lowering-sin.f64N/A

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

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

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_1} \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      3. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \color{blue}{\mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\color{blue}{\cos \lambda_1}, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \color{blue}{\cos \lambda_2}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

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

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right)\right) \cdot R \]
    10. Simplified86.3%

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

    if 1.36000000000000006e-9 < phi2

    1. Initial program 78.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. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f6445.8

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)} \cdot R \]
    6. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right)}\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_2 \cdot \sin \lambda_1\right)}\right) \cdot R \]
      3. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_2 \cdot \sin \lambda_1\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_2 \cdot \sin \lambda_1\right)\right) \cdot R \]
      5. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_2 \cdot \sin \lambda_1}\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_2} \cdot \sin \lambda_1\right)\right) \cdot R \]
      7. sin-lowering-sin.f6453.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -0.01:\\ \;\;\;\;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 1.36 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 65.1% accurate, 1.0× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq -0.058:\\ \;\;\;\;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 1.36 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{R}{\frac{1}{\cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}}\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi2 -0.058)
   (* R (acos (fma (cos phi2) (cos phi1) (* (sin phi1) (sin phi2)))))
   (if (<= phi2 1.36e-9)
     (*
      R
      (acos
       (*
        (cos phi1)
        (fma (cos lambda1) (cos lambda2) (* (sin lambda2) (sin lambda1))))))
     (/ R (/ 1.0 (acos (* (cos phi2) (cos (- lambda2 lambda1)))))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= -0.058) {
		tmp = R * acos(fma(cos(phi2), cos(phi1), (sin(phi1) * sin(phi2))));
	} else if (phi2 <= 1.36e-9) {
		tmp = R * acos((cos(phi1) * fma(cos(lambda1), cos(lambda2), (sin(lambda2) * sin(lambda1)))));
	} else {
		tmp = R / (1.0 / acos((cos(phi2) * cos((lambda2 - lambda1)))));
	}
	return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= -0.058)
		tmp = Float64(R * acos(fma(cos(phi2), cos(phi1), Float64(sin(phi1) * sin(phi2)))));
	elseif (phi2 <= 1.36e-9)
		tmp = Float64(R * acos(Float64(cos(phi1) * fma(cos(lambda1), cos(lambda2), Float64(sin(lambda2) * sin(lambda1))))));
	else
		tmp = Float64(R / Float64(1.0 / acos(Float64(cos(phi2) * cos(Float64(lambda2 - lambda1))))));
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, -0.058], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 1.36e-9], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision] + N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R / N[(1.0 / N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq -0.058:\\
\;\;\;\;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 1.36 \cdot 10^{-9}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{R}{\frac{1}{\cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < -0.0580000000000000029

    1. Initial program 76.8%

      \[\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. Add Preprocessing
    3. Taylor expanded in lambda2 around 0

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \lambda_1}\right) \cdot R \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f6463.1

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

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \lambda_1}\right) \cdot R \]
    6. Taylor expanded in lambda1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \cos \phi_2 + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
    7. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2 \cdot \cos \phi_1} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)} \cdot R \]
      3. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      5. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \color{blue}{\sin \phi_2} \cdot \sin \phi_1\right)\right) \cdot R \]
      8. sin-lowering-sin.f6442.5

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \sin \phi_2 \cdot \color{blue}{\sin \phi_1}\right)\right) \cdot R \]
    8. Simplified42.5%

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

    if -0.0580000000000000029 < phi2 < 1.36000000000000006e-9

    1. Initial program 62.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. Add Preprocessing
    3. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      2. +-commutativeN/A

        \[\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. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\color{blue}{\sin \lambda_2 \cdot \sin \lambda_1} + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      4. accelerator-lowering-fma.f64N/A

        \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_2}, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \color{blue}{\sin \lambda_1}, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      7. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right)\right) \cdot R \]
      8. cos-lowering-cos.f64N/A

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

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

      \[\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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
    5. Taylor expanded in phi1 around inf

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\left(\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot \cos \phi_1} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

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

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      6. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right)}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\color{blue}{\sin \lambda_1}, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \color{blue}{\sin \lambda_2}, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      9. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \color{blue}{\cos \lambda_1} \cdot \cos \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      11. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \color{blue}{\cos \phi_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      13. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      14. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      15. sin-lowering-sin.f64N/A

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

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

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_1} \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      3. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \color{blue}{\mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\color{blue}{\cos \lambda_1}, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \color{blue}{\cos \lambda_2}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

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

        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right)\right) \cdot R \]
    10. Simplified86.3%

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

    if 1.36000000000000006e-9 < phi2

    1. Initial program 78.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. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f6445.8

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)} \cdot R \]
    6. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right)}\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_2 \cdot \sin \lambda_1\right)}\right) \cdot R \]
      3. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_2 \cdot \sin \lambda_1\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_2 \cdot \sin \lambda_1\right)\right) \cdot R \]
      5. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_2 \cdot \sin \lambda_1}\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_2} \cdot \sin \lambda_1\right)\right) \cdot R \]
      7. sin-lowering-sin.f6453.2

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

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_2 \cdot \sin \lambda_1\right)}\right) \cdot R \]
    8. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right)\right)} \]
      2. acos-asinN/A

        \[\leadsto R \cdot \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{2} - \sin^{-1} \left(\cos \phi_2 \cdot \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\right)} \]
      3. div-invN/A

        \[\leadsto R \cdot \left(\color{blue}{\mathsf{PI}\left(\right) \cdot \frac{1}{2}} - \sin^{-1} \left(\cos \phi_2 \cdot \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\right) \]
      4. metadata-evalN/A

        \[\leadsto R \cdot \left(\mathsf{PI}\left(\right) \cdot \color{blue}{\frac{1}{2}} - \sin^{-1} \left(\cos \phi_2 \cdot \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\right) \]
      5. cos-diffN/A

        \[\leadsto R \cdot \left(\mathsf{PI}\left(\right) \cdot \frac{1}{2} - \sin^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 - \lambda_1\right)}\right)\right) \]
      6. flip--N/A

        \[\leadsto R \cdot \color{blue}{\frac{\left(\mathsf{PI}\left(\right) \cdot \frac{1}{2}\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \frac{1}{2}\right) - \sin^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right) \cdot \sin^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}{\mathsf{PI}\left(\right) \cdot \frac{1}{2} + \sin^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}} \]
      7. unpow2N/A

        \[\leadsto R \cdot \frac{\left(\mathsf{PI}\left(\right) \cdot \frac{1}{2}\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \frac{1}{2}\right) - \color{blue}{{\sin^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}{\mathsf{PI}\left(\right) \cdot \frac{1}{2} + \sin^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)} \]
    9. Applied egg-rr45.8%

      \[\leadsto \color{blue}{\frac{R}{\frac{1}{\cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification64.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -0.058:\\ \;\;\;\;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 1.36 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{R}{\frac{1}{\cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 56.4% accurate, 1.2× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -0.9:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 0.1:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(-0.5, \phi_1 \cdot \phi_1, 1\right), \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_2 \cdot \left(\phi_1 \cdot \mathsf{fma}\left(\phi_1, \phi_1 \cdot -0.16666666666666666, 1\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi1 -0.9)
   (* R (acos (* (cos phi1) (cos (- lambda2 lambda1)))))
   (if (<= phi1 0.1)
     (*
      R
      (acos
       (fma
        (* (cos phi2) (fma -0.5 (* phi1 phi1) 1.0))
        (cos (- lambda1 lambda2))
        (* (sin phi2) (* phi1 (fma phi1 (* phi1 -0.16666666666666666) 1.0))))))
     (* R (acos (fma (cos phi2) (cos phi1) (* (sin phi1) (sin phi2))))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -0.9) {
		tmp = R * acos((cos(phi1) * cos((lambda2 - lambda1))));
	} else if (phi1 <= 0.1) {
		tmp = R * acos(fma((cos(phi2) * fma(-0.5, (phi1 * phi1), 1.0)), cos((lambda1 - lambda2)), (sin(phi2) * (phi1 * fma(phi1, (phi1 * -0.16666666666666666), 1.0)))));
	} else {
		tmp = R * acos(fma(cos(phi2), cos(phi1), (sin(phi1) * sin(phi2))));
	}
	return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -0.9)
		tmp = Float64(R * acos(Float64(cos(phi1) * cos(Float64(lambda2 - lambda1)))));
	elseif (phi1 <= 0.1)
		tmp = Float64(R * acos(fma(Float64(cos(phi2) * fma(-0.5, Float64(phi1 * phi1), 1.0)), cos(Float64(lambda1 - lambda2)), Float64(sin(phi2) * Float64(phi1 * fma(phi1, Float64(phi1 * -0.16666666666666666), 1.0))))));
	else
		tmp = Float64(R * acos(fma(cos(phi2), cos(phi1), Float64(sin(phi1) * sin(phi2)))));
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -0.9], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 0.1], N[(R * N[ArcCos[N[(N[(N[Cos[phi2], $MachinePrecision] * N[(-0.5 * N[(phi1 * phi1), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] + N[(N[Sin[phi2], $MachinePrecision] * N[(phi1 * N[(phi1 * N[(phi1 * -0.16666666666666666), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -0.9:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\\

\mathbf{elif}\;\phi_1 \leq 0.1:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(-0.5, \phi_1 \cdot \phi_1, 1\right), \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_2 \cdot \left(\phi_1 \cdot \mathsf{fma}\left(\phi_1, \phi_1 \cdot -0.16666666666666666, 1\right)\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi1 < -0.900000000000000022

    1. Initial program 74.1%

      \[\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. Add Preprocessing
    3. Taylor expanded in phi2 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)} \cdot R \]
      2. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)} \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right) \cdot \cos \phi_1\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right) \cdot \cos \phi_1\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
      12. --lowering--.f64N/A

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

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

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

    if -0.900000000000000022 < phi1 < 0.10000000000000001

    1. Initial program 63.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 \]
    2. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\phi_1 \cdot \left(\sin \phi_2 + \phi_1 \cdot \left(\frac{-1}{2} \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) + \frac{-1}{6} \cdot \left(\phi_1 \cdot \sin \phi_2\right)\right)\right) + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Simplified63.0%

      \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\mathsf{fma}\left(\phi_1, \phi_1 \cdot -0.5, 1\right), \cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right), \mathsf{fma}\left(\phi_1, \phi_1 \cdot -0.16666666666666666, 1\right) \cdot \left(\phi_1 \cdot \sin \phi_2\right)\right)\right)} \cdot R \]
    5. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\left(\left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{2}\right) + 1\right) \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_2 - \lambda_1\right)} + \left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{6}\right) + 1\right) \cdot \left(\phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      2. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\left(\left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{2}\right) + 1\right) \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right)} + \left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{6}\right) + 1\right) \cdot \left(\phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      3. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\left(\left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{2}\right) + 1\right) \cdot \cos \phi_2\right) \cdot \left(\color{blue}{\cos \lambda_1 \cdot \cos \lambda_2} + \sin \lambda_2 \cdot \sin \lambda_1\right) + \left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{6}\right) + 1\right) \cdot \left(\phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      4. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\left(\left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{2}\right) + 1\right) \cdot \cos \phi_2\right) \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right) + \left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{6}\right) + 1\right) \cdot \left(\phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      5. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\left(\left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{2}\right) + 1\right) \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)} + \left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{6}\right) + 1\right) \cdot \left(\phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      6. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{2}\right) + 1\right) \cdot \cos \phi_2, \cos \left(\lambda_1 - \lambda_2\right), \left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{6}\right) + 1\right) \cdot \left(\phi_1 \cdot \sin \phi_2\right)\right)\right)} \cdot R \]
      7. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2 \cdot \left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{2}\right) + 1\right)}, \cos \left(\lambda_1 - \lambda_2\right), \left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{6}\right) + 1\right) \cdot \left(\phi_1 \cdot \sin \phi_2\right)\right)\right) \cdot R \]
      8. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2 \cdot \left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{2}\right) + 1\right)}, \cos \left(\lambda_1 - \lambda_2\right), \left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{6}\right) + 1\right) \cdot \left(\phi_1 \cdot \sin \phi_2\right)\right)\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2} \cdot \left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{2}\right) + 1\right), \cos \left(\lambda_1 - \lambda_2\right), \left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{6}\right) + 1\right) \cdot \left(\phi_1 \cdot \sin \phi_2\right)\right)\right) \cdot R \]
      10. associate-*r*N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \left(\color{blue}{\left(\phi_1 \cdot \phi_1\right) \cdot \frac{-1}{2}} + 1\right), \cos \left(\lambda_1 - \lambda_2\right), \left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{6}\right) + 1\right) \cdot \left(\phi_1 \cdot \sin \phi_2\right)\right)\right) \cdot R \]
      11. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \left(\color{blue}{\frac{-1}{2} \cdot \left(\phi_1 \cdot \phi_1\right)} + 1\right), \cos \left(\lambda_1 - \lambda_2\right), \left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{6}\right) + 1\right) \cdot \left(\phi_1 \cdot \sin \phi_2\right)\right)\right) \cdot R \]
      12. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\frac{-1}{2}, \phi_1 \cdot \phi_1, 1\right)}, \cos \left(\lambda_1 - \lambda_2\right), \left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{6}\right) + 1\right) \cdot \left(\phi_1 \cdot \sin \phi_2\right)\right)\right) \cdot R \]
      13. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\frac{-1}{2}, \color{blue}{\phi_1 \cdot \phi_1}, 1\right), \cos \left(\lambda_1 - \lambda_2\right), \left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{6}\right) + 1\right) \cdot \left(\phi_1 \cdot \sin \phi_2\right)\right)\right) \cdot R \]
      14. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\frac{-1}{2}, \phi_1 \cdot \phi_1, 1\right), \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)}, \left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{6}\right) + 1\right) \cdot \left(\phi_1 \cdot \sin \phi_2\right)\right)\right) \cdot R \]
      15. --lowering--.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\frac{-1}{2}, \phi_1 \cdot \phi_1, 1\right), \cos \color{blue}{\left(\lambda_1 - \lambda_2\right)}, \left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{6}\right) + 1\right) \cdot \left(\phi_1 \cdot \sin \phi_2\right)\right)\right) \cdot R \]
      16. associate-*r*N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(\frac{-1}{2}, \phi_1 \cdot \phi_1, 1\right), \cos \left(\lambda_1 - \lambda_2\right), \color{blue}{\left(\left(\phi_1 \cdot \left(\phi_1 \cdot \frac{-1}{6}\right) + 1\right) \cdot \phi_1\right) \cdot \sin \phi_2}\right)\right) \cdot R \]
    6. Applied egg-rr63.0%

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

    if 0.10000000000000001 < phi1

    1. Initial program 82.8%

      \[\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. Add Preprocessing
    3. Taylor expanded in lambda2 around 0

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \lambda_1}\right) \cdot R \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f6456.9

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

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \lambda_1}\right) \cdot R \]
    6. Taylor expanded in lambda1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \cos \phi_2 + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
    7. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2 \cdot \cos \phi_1} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)} \cdot R \]
      3. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \phi_2}, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
      5. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \color{blue}{\sin \phi_2 \cdot \sin \phi_1}\right)\right) \cdot R \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \color{blue}{\sin \phi_2} \cdot \sin \phi_1\right)\right) \cdot R \]
      8. sin-lowering-sin.f6443.6

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \sin \phi_2 \cdot \color{blue}{\sin \phi_1}\right)\right) \cdot R \]
    8. Simplified43.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -0.9:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 0.1:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \mathsf{fma}\left(-0.5, \phi_1 \cdot \phi_1, 1\right), \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_2 \cdot \left(\phi_1 \cdot \mathsf{fma}\left(\phi_1, \phi_1 \cdot -0.16666666666666666, 1\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 16: 50.1% accurate, 1.9× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \cos \left(\lambda_2 - \lambda_1\right)\\ \mathbf{if}\;\phi_1 \leq -1.5 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{R}{\frac{1}{\cos^{-1} \left(\cos \phi_2 \cdot t\_0\right)}}\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (cos (- lambda2 lambda1))))
   (if (<= phi1 -1.5e-6)
     (* R (acos (* (cos phi1) t_0)))
     (/ R (/ 1.0 (acos (* (cos phi2) t_0)))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos((lambda2 - lambda1));
	double tmp;
	if (phi1 <= -1.5e-6) {
		tmp = R * acos((cos(phi1) * t_0));
	} else {
		tmp = R / (1.0 / acos((cos(phi2) * t_0)));
	}
	return tmp;
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this 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 = cos((lambda2 - lambda1))
    if (phi1 <= (-1.5d-6)) then
        tmp = r * acos((cos(phi1) * t_0))
    else
        tmp = r / (1.0d0 / acos((cos(phi2) * t_0)))
    end if
    code = tmp
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.cos((lambda2 - lambda1));
	double tmp;
	if (phi1 <= -1.5e-6) {
		tmp = R * Math.acos((Math.cos(phi1) * t_0));
	} else {
		tmp = R / (1.0 / Math.acos((Math.cos(phi2) * t_0)));
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.cos((lambda2 - lambda1))
	tmp = 0
	if phi1 <= -1.5e-6:
		tmp = R * math.acos((math.cos(phi1) * t_0))
	else:
		tmp = R / (1.0 / math.acos((math.cos(phi2) * t_0)))
	return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = cos(Float64(lambda2 - lambda1))
	tmp = 0.0
	if (phi1 <= -1.5e-6)
		tmp = Float64(R * acos(Float64(cos(phi1) * t_0)));
	else
		tmp = Float64(R / Float64(1.0 / acos(Float64(cos(phi2) * t_0))));
	end
	return tmp
end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = cos((lambda2 - lambda1));
	tmp = 0.0;
	if (phi1 <= -1.5e-6)
		tmp = R * acos((cos(phi1) * t_0));
	else
		tmp = R / (1.0 / acos((cos(phi2) * t_0)));
	end
	tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi1, -1.5e-6], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R / N[(1.0 / N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_2 - \lambda_1\right)\\
\mathbf{if}\;\phi_1 \leq -1.5 \cdot 10^{-6}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t\_0\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{R}{\frac{1}{\cos^{-1} \left(\cos \phi_2 \cdot t\_0\right)}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi1 < -1.5e-6

    1. Initial program 74.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. Add Preprocessing
    3. Taylor expanded in phi2 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)} \cdot R \]
      2. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)} \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right) \cdot \cos \phi_1\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right) \cdot \cos \phi_1\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
      12. --lowering--.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
      13. cos-lowering-cos.f6447.3

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

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

    if -1.5e-6 < phi1

    1. Initial program 69.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 \]
    2. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f6448.9

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)} \cdot R \]
    6. Step-by-step derivation
      1. cos-diffN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right)}\right) \cdot R \]
      2. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_2 \cdot \sin \lambda_1\right)}\right) \cdot R \]
      3. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_2 \cdot \sin \lambda_1\right)\right) \cdot R \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_2 \cdot \sin \lambda_1\right)\right) \cdot R \]
      5. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_2 \cdot \sin \lambda_1}\right)\right) \cdot R \]
      6. sin-lowering-sin.f64N/A

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

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

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_2 \cdot \sin \lambda_1\right)}\right) \cdot R \]
    8. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right)\right)} \]
      2. acos-asinN/A

        \[\leadsto R \cdot \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{2} - \sin^{-1} \left(\cos \phi_2 \cdot \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\right)} \]
      3. div-invN/A

        \[\leadsto R \cdot \left(\color{blue}{\mathsf{PI}\left(\right) \cdot \frac{1}{2}} - \sin^{-1} \left(\cos \phi_2 \cdot \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\right) \]
      4. metadata-evalN/A

        \[\leadsto R \cdot \left(\mathsf{PI}\left(\right) \cdot \color{blue}{\frac{1}{2}} - \sin^{-1} \left(\cos \phi_2 \cdot \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\right) \]
      5. cos-diffN/A

        \[\leadsto R \cdot \left(\mathsf{PI}\left(\right) \cdot \frac{1}{2} - \sin^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 - \lambda_1\right)}\right)\right) \]
      6. flip--N/A

        \[\leadsto R \cdot \color{blue}{\frac{\left(\mathsf{PI}\left(\right) \cdot \frac{1}{2}\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \frac{1}{2}\right) - \sin^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right) \cdot \sin^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}{\mathsf{PI}\left(\right) \cdot \frac{1}{2} + \sin^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}} \]
      7. unpow2N/A

        \[\leadsto R \cdot \frac{\left(\mathsf{PI}\left(\right) \cdot \frac{1}{2}\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \frac{1}{2}\right) - \color{blue}{{\sin^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}{\mathsf{PI}\left(\right) \cdot \frac{1}{2} + \sin^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)} \]
    9. Applied egg-rr48.9%

      \[\leadsto \color{blue}{\frac{R}{\frac{1}{\cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification48.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.5 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{R}{\frac{1}{\cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 17: 35.5% accurate, 1.9× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -8.8 \cdot 10^{-8}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\ \mathbf{elif}\;\phi_1 \leq -3.4 \cdot 10^{-173}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \lambda_1\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi1 -8.8e-8)
   (* R (acos (* (cos phi1) (cos lambda1))))
   (if (<= phi1 -3.4e-173)
     (* R (acos (cos (- lambda1 lambda2))))
     (* R (acos (* (cos phi2) (cos lambda1)))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -8.8e-8) {
		tmp = R * acos((cos(phi1) * cos(lambda1)));
	} else if (phi1 <= -3.4e-173) {
		tmp = R * acos(cos((lambda1 - lambda2)));
	} else {
		tmp = R * acos((cos(phi2) * cos(lambda1)));
	}
	return tmp;
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this 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) :: tmp
    if (phi1 <= (-8.8d-8)) then
        tmp = r * acos((cos(phi1) * cos(lambda1)))
    else if (phi1 <= (-3.4d-173)) then
        tmp = r * acos(cos((lambda1 - lambda2)))
    else
        tmp = r * acos((cos(phi2) * cos(lambda1)))
    end if
    code = tmp
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -8.8e-8) {
		tmp = R * Math.acos((Math.cos(phi1) * Math.cos(lambda1)));
	} else if (phi1 <= -3.4e-173) {
		tmp = R * Math.acos(Math.cos((lambda1 - lambda2)));
	} else {
		tmp = R * Math.acos((Math.cos(phi2) * Math.cos(lambda1)));
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -8.8e-8:
		tmp = R * math.acos((math.cos(phi1) * math.cos(lambda1)))
	elif phi1 <= -3.4e-173:
		tmp = R * math.acos(math.cos((lambda1 - lambda2)))
	else:
		tmp = R * math.acos((math.cos(phi2) * math.cos(lambda1)))
	return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -8.8e-8)
		tmp = Float64(R * acos(Float64(cos(phi1) * cos(lambda1))));
	elseif (phi1 <= -3.4e-173)
		tmp = Float64(R * acos(cos(Float64(lambda1 - lambda2))));
	else
		tmp = Float64(R * acos(Float64(cos(phi2) * cos(lambda1))));
	end
	return tmp
end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi1 <= -8.8e-8)
		tmp = R * acos((cos(phi1) * cos(lambda1)));
	elseif (phi1 <= -3.4e-173)
		tmp = R * acos(cos((lambda1 - lambda2)));
	else
		tmp = R * acos((cos(phi2) * cos(lambda1)));
	end
	tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -8.8e-8], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, -3.4e-173], N[(R * N[ArcCos[N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -8.8 \cdot 10^{-8}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\

\mathbf{elif}\;\phi_1 \leq -3.4 \cdot 10^{-173}:\\
\;\;\;\;R \cdot \cos^{-1} \cos \left(\lambda_1 - \lambda_2\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \lambda_1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi1 < -8.7999999999999994e-8

    1. Initial program 74.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. Add Preprocessing
    3. Taylor expanded in lambda2 around 0

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \lambda_1}\right) \cdot R \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f6453.8

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

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \lambda_1}\right) \cdot R \]
    6. Taylor expanded in phi2 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \lambda_1 \cdot \cos \phi_1\right)} \cdot R \]
    7. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \lambda_1 \cdot \cos \phi_1\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \lambda_1} \cdot \cos \phi_1\right) \cdot R \]
      3. cos-lowering-cos.f6434.0

        \[\leadsto \cos^{-1} \left(\cos \lambda_1 \cdot \color{blue}{\cos \phi_1}\right) \cdot R \]
    8. Simplified34.0%

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

    if -8.7999999999999994e-8 < phi1 < -3.3999999999999999e-173

    1. Initial program 56.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. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f6455.9

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

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

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_2 - \lambda_1\right)} \cdot R \]
    7. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)} \cdot R \]
      2. remove-double-negN/A

        \[\leadsto \cos^{-1} \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      3. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_2}\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      4. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_2 + \lambda_1\right)\right)\right)} \cdot R \]
      5. +-commutativeN/A

        \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_1 + -1 \cdot \lambda_2\right)}\right)\right) \cdot R \]
      6. cos-negN/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      8. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\lambda_1 + \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)}\right) \cdot R \]
      9. unsub-negN/A

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

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

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

    if -3.3999999999999999e-173 < phi1

    1. Initial program 72.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. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f6447.0

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

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)} \cdot R \]
    7. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \lambda_1}\right) \cdot R \]
      2. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \lambda_1\right)} \cdot R \]
      3. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \lambda_1\right) \cdot R \]
      4. cos-lowering-cos.f6433.0

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \lambda_1}\right) \cdot R \]
    8. Simplified33.0%

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \lambda_1\right)} \cdot R \]
  3. Recombined 3 regimes into one program.
  4. Final simplification33.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -8.8 \cdot 10^{-8}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\ \mathbf{elif}\;\phi_1 \leq -3.4 \cdot 10^{-173}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \lambda_1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 18: 50.1% accurate, 2.0× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \cos \left(\lambda_2 - \lambda_1\right)\\ \mathbf{if}\;\phi_1 \leq -2.5 \cdot 10^{-6}:\\ \;\;\;\;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} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (cos (- lambda2 lambda1))))
   (if (<= phi1 -2.5e-6)
     (* R (acos (* (cos phi1) t_0)))
     (* R (acos (* (cos phi2) t_0))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos((lambda2 - lambda1));
	double tmp;
	if (phi1 <= -2.5e-6) {
		tmp = R * acos((cos(phi1) * t_0));
	} else {
		tmp = R * acos((cos(phi2) * t_0));
	}
	return tmp;
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this 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 = cos((lambda2 - lambda1))
    if (phi1 <= (-2.5d-6)) then
        tmp = r * acos((cos(phi1) * t_0))
    else
        tmp = r * acos((cos(phi2) * t_0))
    end if
    code = tmp
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.cos((lambda2 - lambda1));
	double tmp;
	if (phi1 <= -2.5e-6) {
		tmp = R * Math.acos((Math.cos(phi1) * t_0));
	} else {
		tmp = R * Math.acos((Math.cos(phi2) * t_0));
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.cos((lambda2 - lambda1))
	tmp = 0
	if phi1 <= -2.5e-6:
		tmp = R * math.acos((math.cos(phi1) * t_0))
	else:
		tmp = R * math.acos((math.cos(phi2) * t_0))
	return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = cos(Float64(lambda2 - lambda1))
	tmp = 0.0
	if (phi1 <= -2.5e-6)
		tmp = Float64(R * acos(Float64(cos(phi1) * t_0)));
	else
		tmp = Float64(R * acos(Float64(cos(phi2) * t_0)));
	end
	return tmp
end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = cos((lambda2 - lambda1));
	tmp = 0.0;
	if (phi1 <= -2.5e-6)
		tmp = R * acos((cos(phi1) * t_0));
	else
		tmp = R * acos((cos(phi2) * t_0));
	end
	tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi1, -2.5e-6], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_2 - \lambda_1\right)\\
\mathbf{if}\;\phi_1 \leq -2.5 \cdot 10^{-6}:\\
\;\;\;\;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}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi1 < -2.5000000000000002e-6

    1. Initial program 74.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. Add Preprocessing
    3. Taylor expanded in phi2 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)} \cdot R \]
      2. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)} \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right) \cdot \cos \phi_1\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right) \cdot \cos \phi_1\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
      12. --lowering--.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
      13. cos-lowering-cos.f6447.3

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

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

    if -2.5000000000000002e-6 < phi1

    1. Initial program 69.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 \]
    2. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f6448.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -2.5 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \left(\lambda_2 - \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} \]
  5. Add Preprocessing

Alternative 19: 47.7% accurate, 2.0× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -3.7 \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_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi1 -3.7e-6)
   (* R (acos (* (cos phi1) (cos lambda1))))
   (* R (acos (* (cos phi2) (cos (- lambda2 lambda1)))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -3.7e-6) {
		tmp = R * acos((cos(phi1) * cos(lambda1)));
	} else {
		tmp = R * acos((cos(phi2) * cos((lambda2 - lambda1))));
	}
	return tmp;
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this 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) :: tmp
    if (phi1 <= (-3.7d-6)) then
        tmp = r * acos((cos(phi1) * cos(lambda1)))
    else
        tmp = r * acos((cos(phi2) * cos((lambda2 - lambda1))))
    end if
    code = tmp
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -3.7e-6) {
		tmp = R * Math.acos((Math.cos(phi1) * Math.cos(lambda1)));
	} else {
		tmp = R * Math.acos((Math.cos(phi2) * Math.cos((lambda2 - lambda1))));
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -3.7e-6:
		tmp = R * math.acos((math.cos(phi1) * math.cos(lambda1)))
	else:
		tmp = R * math.acos((math.cos(phi2) * math.cos((lambda2 - lambda1))))
	return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -3.7e-6)
		tmp = Float64(R * acos(Float64(cos(phi1) * cos(lambda1))));
	else
		tmp = Float64(R * acos(Float64(cos(phi2) * cos(Float64(lambda2 - lambda1)))));
	end
	return tmp
end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi1 <= -3.7e-6)
		tmp = R * acos((cos(phi1) * cos(lambda1)));
	else
		tmp = R * acos((cos(phi2) * cos((lambda2 - lambda1))));
	end
	tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -3.7e-6], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -3.7 \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_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi1 < -3.7000000000000002e-6

    1. Initial program 74.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. Add Preprocessing
    3. Taylor expanded in lambda2 around 0

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \lambda_1}\right) \cdot R \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f6453.8

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

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \lambda_1}\right) \cdot R \]
    6. Taylor expanded in phi2 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \lambda_1 \cdot \cos \phi_1\right)} \cdot R \]
    7. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \lambda_1 \cdot \cos \phi_1\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \lambda_1} \cdot \cos \phi_1\right) \cdot R \]
      3. cos-lowering-cos.f6434.0

        \[\leadsto \cos^{-1} \left(\cos \lambda_1 \cdot \color{blue}{\cos \phi_1}\right) \cdot R \]
    8. Simplified34.0%

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

    if -3.7000000000000002e-6 < phi1

    1. Initial program 69.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 \]
    2. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f6448.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -3.7 \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_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 20: 28.9% accurate, 2.0× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;t\_0 \leq 0.995:\\ \;\;\;\;R \cdot \cos^{-1} t\_0\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right|\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (cos (- lambda1 lambda2))))
   (if (<= t_0 0.995)
     (* R (acos t_0))
     (* R (fabs (remainder (- lambda1 lambda2) (* PI 2.0)))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos((lambda1 - lambda2));
	double tmp;
	if (t_0 <= 0.995) {
		tmp = R * acos(t_0);
	} else {
		tmp = R * fabs(remainder((lambda1 - lambda2), (((double) M_PI) * 2.0)));
	}
	return tmp;
}
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.cos((lambda1 - lambda2));
	double tmp;
	if (t_0 <= 0.995) {
		tmp = R * Math.acos(t_0);
	} else {
		tmp = R * Math.abs(Math.IEEEremainder((lambda1 - lambda2), (Math.PI * 2.0)));
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.cos((lambda1 - lambda2))
	tmp = 0
	if t_0 <= 0.995:
		tmp = R * math.acos(t_0)
	else:
		tmp = R * math.fabs(math.remainder((lambda1 - lambda2), (math.pi * 2.0)))
	return tmp
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.995], N[(R * N[ArcCos[t$95$0], $MachinePrecision]), $MachinePrecision], N[(R * N[Abs[N[With[{TMP1 = N[(lambda1 - lambda2), $MachinePrecision], TMP2 = N[(Pi * 2.0), $MachinePrecision]}, TMP1 - Round[TMP1 / TMP2] * TMP2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;t\_0 \leq 0.995:\\
\;\;\;\;R \cdot \cos^{-1} t\_0\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (-.f64 lambda1 lambda2)) < 0.994999999999999996

    1. Initial program 69.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. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f6445.1

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

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

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_2 - \lambda_1\right)} \cdot R \]
    7. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)} \cdot R \]
      2. remove-double-negN/A

        \[\leadsto \cos^{-1} \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      3. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_2}\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      4. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_2 + \lambda_1\right)\right)\right)} \cdot R \]
      5. +-commutativeN/A

        \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_1 + -1 \cdot \lambda_2\right)}\right)\right) \cdot R \]
      6. cos-negN/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      8. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\lambda_1 + \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)}\right) \cdot R \]
      9. unsub-negN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot R \]
      10. --lowering--.f6431.8

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

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

    if 0.994999999999999996 < (cos.f64 (-.f64 lambda1 lambda2))

    1. Initial program 73.6%

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f6429.4

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

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

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_2 - \lambda_1\right)} \cdot R \]
    7. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)} \cdot R \]
      2. remove-double-negN/A

        \[\leadsto \cos^{-1} \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      3. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_2}\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      4. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_2 + \lambda_1\right)\right)\right)} \cdot R \]
      5. +-commutativeN/A

        \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_1 + -1 \cdot \lambda_2\right)}\right)\right) \cdot R \]
      6. cos-negN/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      8. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\lambda_1 + \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)}\right) \cdot R \]
      9. unsub-negN/A

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

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

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)} \cdot R \]
    9. Step-by-step derivation
      1. acos-cosN/A

        \[\leadsto \color{blue}{\left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right|} \cdot R \]
      2. fabs-lowering-fabs.f64N/A

        \[\leadsto \color{blue}{\left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right|} \cdot R \]
      3. remainder-lowering-remainder.f64N/A

        \[\leadsto \left|\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)}\right| \cdot R \]
      4. --lowering--.f64N/A

        \[\leadsto \left|\left(\color{blue}{\left(\lambda_1 - \lambda_2\right)} \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right| \cdot R \]
      5. *-commutativeN/A

        \[\leadsto \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \color{blue}{\left(\mathsf{PI}\left(\right) \cdot 2\right)}\right)\right| \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \color{blue}{\left(\mathsf{PI}\left(\right) \cdot 2\right)}\right)\right| \cdot R \]
      7. PI-lowering-PI.f6420.7

        \[\leadsto \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\color{blue}{\pi} \cdot 2\right)\right)\right| \cdot R \]
    10. Applied egg-rr20.7%

      \[\leadsto \color{blue}{\left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right|} \cdot R \]
  3. Recombined 2 regimes into one program.
  4. Final simplification28.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\lambda_1 - \lambda_2\right) \leq 0.995:\\ \;\;\;\;R \cdot \cos^{-1} \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 21: 42.4% accurate, 2.0× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 0.105:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \lambda_2\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= lambda2 0.105)
   (* R (acos (* (cos phi1) (cos lambda1))))
   (* R (acos (* (cos phi2) (cos lambda2))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda2 <= 0.105) {
		tmp = R * acos((cos(phi1) * cos(lambda1)));
	} else {
		tmp = R * acos((cos(phi2) * cos(lambda2)));
	}
	return tmp;
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this 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) :: tmp
    if (lambda2 <= 0.105d0) then
        tmp = r * acos((cos(phi1) * cos(lambda1)))
    else
        tmp = r * acos((cos(phi2) * cos(lambda2)))
    end if
    code = tmp
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda2 <= 0.105) {
		tmp = R * Math.acos((Math.cos(phi1) * Math.cos(lambda1)));
	} else {
		tmp = R * Math.acos((Math.cos(phi2) * Math.cos(lambda2)));
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if lambda2 <= 0.105:
		tmp = R * math.acos((math.cos(phi1) * math.cos(lambda1)))
	else:
		tmp = R * math.acos((math.cos(phi2) * math.cos(lambda2)))
	return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (lambda2 <= 0.105)
		tmp = Float64(R * acos(Float64(cos(phi1) * cos(lambda1))));
	else
		tmp = Float64(R * acos(Float64(cos(phi2) * cos(lambda2))));
	end
	return tmp
end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (lambda2 <= 0.105)
		tmp = R * acos((cos(phi1) * cos(lambda1)));
	else
		tmp = R * acos((cos(phi2) * cos(lambda2)));
	end
	tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda2, 0.105], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq 0.105:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \lambda_2\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda2 < 0.104999999999999996

    1. Initial program 74.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 \]
    2. Add Preprocessing
    3. Taylor expanded in lambda2 around 0

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \lambda_1}\right) \cdot R \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f6459.1

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

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \lambda_1}\right) \cdot R \]
    6. Taylor expanded in phi2 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \lambda_1 \cdot \cos \phi_1\right)} \cdot R \]
    7. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \lambda_1 \cdot \cos \phi_1\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \lambda_1} \cdot \cos \phi_1\right) \cdot R \]
      3. cos-lowering-cos.f6431.5

        \[\leadsto \cos^{-1} \left(\cos \lambda_1 \cdot \color{blue}{\cos \phi_1}\right) \cdot R \]
    8. Simplified31.5%

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

    if 0.104999999999999996 < lambda2

    1. Initial program 59.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. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f6441.2

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

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \lambda_2 \cdot \cos \phi_2\right)} \cdot R \]
    7. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \lambda_2\right)} \cdot R \]
      2. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \lambda_2\right)} \cdot R \]
      3. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \lambda_2\right) \cdot R \]
      4. cos-lowering-cos.f6441.3

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \lambda_2}\right) \cdot R \]
    8. Simplified41.3%

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \lambda_2\right)} \cdot R \]
  3. Recombined 2 regimes into one program.
  4. Final simplification34.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 0.105:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \lambda_2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 22: 37.3% accurate, 2.0× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 0.0115:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \left(\lambda_1 - \lambda_2\right)\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= lambda2 0.0115)
   (* R (acos (* (cos phi1) (cos lambda1))))
   (* R (acos (cos (- lambda1 lambda2))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda2 <= 0.0115) {
		tmp = R * acos((cos(phi1) * cos(lambda1)));
	} else {
		tmp = R * acos(cos((lambda1 - lambda2)));
	}
	return tmp;
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this 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) :: tmp
    if (lambda2 <= 0.0115d0) then
        tmp = r * acos((cos(phi1) * cos(lambda1)))
    else
        tmp = r * acos(cos((lambda1 - lambda2)))
    end if
    code = tmp
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda2 <= 0.0115) {
		tmp = R * Math.acos((Math.cos(phi1) * Math.cos(lambda1)));
	} else {
		tmp = R * Math.acos(Math.cos((lambda1 - lambda2)));
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if lambda2 <= 0.0115:
		tmp = R * math.acos((math.cos(phi1) * math.cos(lambda1)))
	else:
		tmp = R * math.acos(math.cos((lambda1 - lambda2)))
	return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (lambda2 <= 0.0115)
		tmp = Float64(R * acos(Float64(cos(phi1) * cos(lambda1))));
	else
		tmp = Float64(R * acos(cos(Float64(lambda1 - lambda2))));
	end
	return tmp
end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (lambda2 <= 0.0115)
		tmp = R * acos((cos(phi1) * cos(lambda1)));
	else
		tmp = R * acos(cos((lambda1 - lambda2)));
	end
	tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda2, 0.0115], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq 0.0115:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda2 < 0.0115

    1. Initial program 74.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. Add Preprocessing
    3. Taylor expanded in lambda2 around 0

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \lambda_1}\right) \cdot R \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f6459.3

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

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \lambda_1}\right) \cdot R \]
    6. Taylor expanded in phi2 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \lambda_1 \cdot \cos \phi_1\right)} \cdot R \]
    7. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \lambda_1 \cdot \cos \phi_1\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \lambda_1} \cdot \cos \phi_1\right) \cdot R \]
      3. cos-lowering-cos.f6431.5

        \[\leadsto \cos^{-1} \left(\cos \lambda_1 \cdot \color{blue}{\cos \phi_1}\right) \cdot R \]
    8. Simplified31.5%

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

    if 0.0115 < lambda2

    1. Initial program 59.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. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f6440.9

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

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

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_2 - \lambda_1\right)} \cdot R \]
    7. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)} \cdot R \]
      2. remove-double-negN/A

        \[\leadsto \cos^{-1} \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      3. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_2}\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      4. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_2 + \lambda_1\right)\right)\right)} \cdot R \]
      5. +-commutativeN/A

        \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_1 + -1 \cdot \lambda_2\right)}\right)\right) \cdot R \]
      6. cos-negN/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      8. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\lambda_1 + \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)}\right) \cdot R \]
      9. unsub-negN/A

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 0.0115:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \left(\lambda_1 - \lambda_2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 23: 26.9% accurate, 2.9× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -0.00095:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\ \mathbf{elif}\;\lambda_1 \leq -3.3 \cdot 10^{-77}:\\ \;\;\;\;R \cdot \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right|\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_2\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= lambda1 -0.00095)
   (* R (acos (cos lambda1)))
   (if (<= lambda1 -3.3e-77)
     (* R (fabs (remainder (- lambda1 lambda2) (* PI 2.0))))
     (* R (acos (cos lambda2))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda1 <= -0.00095) {
		tmp = R * acos(cos(lambda1));
	} else if (lambda1 <= -3.3e-77) {
		tmp = R * fabs(remainder((lambda1 - lambda2), (((double) M_PI) * 2.0)));
	} else {
		tmp = R * acos(cos(lambda2));
	}
	return tmp;
}
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda1 <= -0.00095) {
		tmp = R * Math.acos(Math.cos(lambda1));
	} else if (lambda1 <= -3.3e-77) {
		tmp = R * Math.abs(Math.IEEEremainder((lambda1 - lambda2), (Math.PI * 2.0)));
	} else {
		tmp = R * Math.acos(Math.cos(lambda2));
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if lambda1 <= -0.00095:
		tmp = R * math.acos(math.cos(lambda1))
	elif lambda1 <= -3.3e-77:
		tmp = R * math.fabs(math.remainder((lambda1 - lambda2), (math.pi * 2.0)))
	else:
		tmp = R * math.acos(math.cos(lambda2))
	return tmp
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda1, -0.00095], N[(R * N[ArcCos[N[Cos[lambda1], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda1, -3.3e-77], N[(R * N[Abs[N[With[{TMP1 = N[(lambda1 - lambda2), $MachinePrecision], TMP2 = N[(Pi * 2.0), $MachinePrecision]}, TMP1 - Round[TMP1 / TMP2] * TMP2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[Cos[lambda2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 \leq -0.00095:\\
\;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\

\mathbf{elif}\;\lambda_1 \leq -3.3 \cdot 10^{-77}:\\
\;\;\;\;R \cdot \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right|\\

\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \cos \lambda_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if lambda1 < -9.49999999999999998e-4

    1. Initial program 53.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. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f6436.1

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

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

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_2 - \lambda_1\right)} \cdot R \]
    7. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)} \cdot R \]
      2. remove-double-negN/A

        \[\leadsto \cos^{-1} \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      3. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_2}\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      4. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_2 + \lambda_1\right)\right)\right)} \cdot R \]
      5. +-commutativeN/A

        \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_1 + -1 \cdot \lambda_2\right)}\right)\right) \cdot R \]
      6. cos-negN/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      8. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\lambda_1 + \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)}\right) \cdot R \]
      9. unsub-negN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot R \]
      10. --lowering--.f6426.6

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot R \]
    8. Simplified26.6%

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

      \[\leadsto \cos^{-1} \color{blue}{\cos \lambda_1} \cdot R \]
    10. Step-by-step derivation
      1. cos-lowering-cos.f6426.6

        \[\leadsto \cos^{-1} \color{blue}{\cos \lambda_1} \cdot R \]
    11. Simplified26.6%

      \[\leadsto \cos^{-1} \color{blue}{\cos \lambda_1} \cdot R \]

    if -9.49999999999999998e-4 < lambda1 < -3.29999999999999991e-77

    1. Initial program 66.6%

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f6428.4

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

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

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_2 - \lambda_1\right)} \cdot R \]
    7. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)} \cdot R \]
      2. remove-double-negN/A

        \[\leadsto \cos^{-1} \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      3. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_2}\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      4. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_2 + \lambda_1\right)\right)\right)} \cdot R \]
      5. +-commutativeN/A

        \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_1 + -1 \cdot \lambda_2\right)}\right)\right) \cdot R \]
      6. cos-negN/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      8. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\lambda_1 + \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)}\right) \cdot R \]
      9. unsub-negN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot R \]
      10. --lowering--.f6417.9

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot R \]
    8. Simplified17.9%

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)} \cdot R \]
    9. Step-by-step derivation
      1. acos-cosN/A

        \[\leadsto \color{blue}{\left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right|} \cdot R \]
      2. fabs-lowering-fabs.f64N/A

        \[\leadsto \color{blue}{\left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right|} \cdot R \]
      3. remainder-lowering-remainder.f64N/A

        \[\leadsto \left|\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)}\right| \cdot R \]
      4. --lowering--.f64N/A

        \[\leadsto \left|\left(\color{blue}{\left(\lambda_1 - \lambda_2\right)} \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right| \cdot R \]
      5. *-commutativeN/A

        \[\leadsto \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \color{blue}{\left(\mathsf{PI}\left(\right) \cdot 2\right)}\right)\right| \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \color{blue}{\left(\mathsf{PI}\left(\right) \cdot 2\right)}\right)\right| \cdot R \]
      7. PI-lowering-PI.f6445.0

        \[\leadsto \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\color{blue}{\pi} \cdot 2\right)\right)\right| \cdot R \]
    10. Applied egg-rr45.0%

      \[\leadsto \color{blue}{\left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right|} \cdot R \]

    if -3.29999999999999991e-77 < lambda1

    1. Initial program 76.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. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f6443.8

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

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

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_2 - \lambda_1\right)} \cdot R \]
    7. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)} \cdot R \]
      2. remove-double-negN/A

        \[\leadsto \cos^{-1} \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      3. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_2}\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      4. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_2 + \lambda_1\right)\right)\right)} \cdot R \]
      5. +-commutativeN/A

        \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_1 + -1 \cdot \lambda_2\right)}\right)\right) \cdot R \]
      6. cos-negN/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      8. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\lambda_1 + \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)}\right) \cdot R \]
      9. unsub-negN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot R \]
      10. --lowering--.f6425.2

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot R \]
    8. Simplified25.2%

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

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} \cdot R \]
    10. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \lambda_2} \cdot R \]
      2. cos-lowering-cos.f6419.2

        \[\leadsto \cos^{-1} \color{blue}{\cos \lambda_2} \cdot R \]
    11. Simplified19.2%

      \[\leadsto \cos^{-1} \color{blue}{\cos \lambda_2} \cdot R \]
  3. Recombined 3 regimes into one program.
  4. Final simplification22.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -0.00095:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\ \mathbf{elif}\;\lambda_1 \leq -3.3 \cdot 10^{-77}:\\ \;\;\;\;R \cdot \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right|\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 24: 24.4% accurate, 3.0× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -0.00095:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right|\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= lambda1 -0.00095)
   (* R (acos (cos lambda1)))
   (* R (fabs (remainder (- lambda1 lambda2) (* PI 2.0))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda1 <= -0.00095) {
		tmp = R * acos(cos(lambda1));
	} else {
		tmp = R * fabs(remainder((lambda1 - lambda2), (((double) M_PI) * 2.0)));
	}
	return tmp;
}
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda1 <= -0.00095) {
		tmp = R * Math.acos(Math.cos(lambda1));
	} else {
		tmp = R * Math.abs(Math.IEEEremainder((lambda1 - lambda2), (Math.PI * 2.0)));
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if lambda1 <= -0.00095:
		tmp = R * math.acos(math.cos(lambda1))
	else:
		tmp = R * math.fabs(math.remainder((lambda1 - lambda2), (math.pi * 2.0)))
	return tmp
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda1, -0.00095], N[(R * N[ArcCos[N[Cos[lambda1], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[Abs[N[With[{TMP1 = N[(lambda1 - lambda2), $MachinePrecision], TMP2 = N[(Pi * 2.0), $MachinePrecision]}, TMP1 - Round[TMP1 / TMP2] * TMP2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 \leq -0.00095:\\
\;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda1 < -9.49999999999999998e-4

    1. Initial program 53.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. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f6436.1

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

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

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_2 - \lambda_1\right)} \cdot R \]
    7. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)} \cdot R \]
      2. remove-double-negN/A

        \[\leadsto \cos^{-1} \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      3. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_2}\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      4. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_2 + \lambda_1\right)\right)\right)} \cdot R \]
      5. +-commutativeN/A

        \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_1 + -1 \cdot \lambda_2\right)}\right)\right) \cdot R \]
      6. cos-negN/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      8. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\lambda_1 + \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)}\right) \cdot R \]
      9. unsub-negN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot R \]
      10. --lowering--.f6426.6

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot R \]
    8. Simplified26.6%

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

      \[\leadsto \cos^{-1} \color{blue}{\cos \lambda_1} \cdot R \]
    10. Step-by-step derivation
      1. cos-lowering-cos.f6426.6

        \[\leadsto \cos^{-1} \color{blue}{\cos \lambda_1} \cdot R \]
    11. Simplified26.6%

      \[\leadsto \cos^{-1} \color{blue}{\cos \lambda_1} \cdot R \]

    if -9.49999999999999998e-4 < lambda1

    1. Initial program 76.1%

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. sub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
      4. remove-double-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      5. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
      6. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
      7. +-commutativeN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
      8. cos-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
      10. mul-1-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
      11. unsub-negN/A

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      12. --lowering--.f6442.6

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

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

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_2 - \lambda_1\right)} \cdot R \]
    7. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)} \cdot R \]
      2. remove-double-negN/A

        \[\leadsto \cos^{-1} \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      3. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_2}\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
      4. distribute-neg-inN/A

        \[\leadsto \cos^{-1} \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_2 + \lambda_1\right)\right)\right)} \cdot R \]
      5. +-commutativeN/A

        \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_1 + -1 \cdot \lambda_2\right)}\right)\right) \cdot R \]
      6. cos-negN/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
      8. mul-1-negN/A

        \[\leadsto \cos^{-1} \cos \left(\lambda_1 + \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)}\right) \cdot R \]
      9. unsub-negN/A

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

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

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)} \cdot R \]
    9. Step-by-step derivation
      1. acos-cosN/A

        \[\leadsto \color{blue}{\left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right|} \cdot R \]
      2. fabs-lowering-fabs.f64N/A

        \[\leadsto \color{blue}{\left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right|} \cdot R \]
      3. remainder-lowering-remainder.f64N/A

        \[\leadsto \left|\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)}\right| \cdot R \]
      4. --lowering--.f64N/A

        \[\leadsto \left|\left(\color{blue}{\left(\lambda_1 - \lambda_2\right)} \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right| \cdot R \]
      5. *-commutativeN/A

        \[\leadsto \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \color{blue}{\left(\mathsf{PI}\left(\right) \cdot 2\right)}\right)\right| \cdot R \]
      6. *-lowering-*.f64N/A

        \[\leadsto \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \color{blue}{\left(\mathsf{PI}\left(\right) \cdot 2\right)}\right)\right| \cdot R \]
      7. PI-lowering-PI.f6420.2

        \[\leadsto \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\color{blue}{\pi} \cdot 2\right)\right)\right| \cdot R \]
    10. Applied egg-rr20.2%

      \[\leadsto \color{blue}{\left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right|} \cdot R \]
  3. Recombined 2 regimes into one program.
  4. Final simplification21.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -0.00095:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 25: 19.8% accurate, 5.4× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ R \cdot \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right| \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (* R (fabs (remainder (- lambda1 lambda2) (* PI 2.0)))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * fabs(remainder((lambda1 - lambda2), (((double) M_PI) * 2.0)));
}
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * Math.abs(Math.IEEEremainder((lambda1 - lambda2), (Math.PI * 2.0)));
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	return R * math.fabs(math.remainder((lambda1 - lambda2), (math.pi * 2.0)))
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[Abs[N[With[{TMP1 = N[(lambda1 - lambda2), $MachinePrecision], TMP2 = N[(Pi * 2.0), $MachinePrecision]}, TMP1 - Round[TMP1 / TMP2] * TMP2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
R \cdot \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right|
\end{array}
Derivation
  1. Initial program 70.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. Add Preprocessing
  3. Taylor expanded in phi1 around 0

    \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
  4. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    2. cos-lowering-cos.f64N/A

      \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
    3. sub-negN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
    4. remove-double-negN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
    5. mul-1-negN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
    6. distribute-neg-inN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
    7. +-commutativeN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
    8. cos-negN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
    9. cos-lowering-cos.f64N/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
    10. mul-1-negN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
    11. unsub-negN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
    12. --lowering--.f6441.0

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

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

    \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_2 - \lambda_1\right)} \cdot R \]
  7. Step-by-step derivation
    1. sub-negN/A

      \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)} \cdot R \]
    2. remove-double-negN/A

      \[\leadsto \cos^{-1} \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
    3. mul-1-negN/A

      \[\leadsto \cos^{-1} \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_2}\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
    4. distribute-neg-inN/A

      \[\leadsto \cos^{-1} \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_2 + \lambda_1\right)\right)\right)} \cdot R \]
    5. +-commutativeN/A

      \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_1 + -1 \cdot \lambda_2\right)}\right)\right) \cdot R \]
    6. cos-negN/A

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
    7. cos-lowering-cos.f64N/A

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
    8. mul-1-negN/A

      \[\leadsto \cos^{-1} \cos \left(\lambda_1 + \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)}\right) \cdot R \]
    9. unsub-negN/A

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

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

    \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)} \cdot R \]
  9. Step-by-step derivation
    1. acos-cosN/A

      \[\leadsto \color{blue}{\left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right|} \cdot R \]
    2. fabs-lowering-fabs.f64N/A

      \[\leadsto \color{blue}{\left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right|} \cdot R \]
    3. remainder-lowering-remainder.f64N/A

      \[\leadsto \left|\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)}\right| \cdot R \]
    4. --lowering--.f64N/A

      \[\leadsto \left|\left(\color{blue}{\left(\lambda_1 - \lambda_2\right)} \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right| \cdot R \]
    5. *-commutativeN/A

      \[\leadsto \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \color{blue}{\left(\mathsf{PI}\left(\right) \cdot 2\right)}\right)\right| \cdot R \]
    6. *-lowering-*.f64N/A

      \[\leadsto \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \color{blue}{\left(\mathsf{PI}\left(\right) \cdot 2\right)}\right)\right| \cdot R \]
    7. PI-lowering-PI.f6420.2

      \[\leadsto \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\color{blue}{\pi} \cdot 2\right)\right)\right| \cdot R \]
  10. Applied egg-rr20.2%

    \[\leadsto \color{blue}{\left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right|} \cdot R \]
  11. Final simplification20.2%

    \[\leadsto R \cdot \left|\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right| \]
  12. Add Preprocessing

Alternative 26: 9.2% accurate, 69.7× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \left(\lambda_2 - \lambda_1\right) \cdot R \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (* (- lambda2 lambda1) R))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return (lambda2 - lambda1) * R;
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this 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
    code = (lambda2 - lambda1) * r
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return (lambda2 - lambda1) * R;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	return (lambda2 - lambda1) * R
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(Float64(lambda2 - lambda1) * R)
end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = (lambda2 - lambda1) * R;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[(lambda2 - lambda1), $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\left(\lambda_2 - \lambda_1\right) \cdot R
\end{array}
Derivation
  1. Initial program 70.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. Add Preprocessing
  3. Taylor expanded in phi1 around 0

    \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
  4. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    2. cos-lowering-cos.f64N/A

      \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
    3. sub-negN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
    4. remove-double-negN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
    5. mul-1-negN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
    6. distribute-neg-inN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
    7. +-commutativeN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
    8. cos-negN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
    9. cos-lowering-cos.f64N/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
    10. mul-1-negN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
    11. unsub-negN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
    12. --lowering--.f6441.0

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

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

    \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_2 - \lambda_1\right)} \cdot R \]
  7. Step-by-step derivation
    1. sub-negN/A

      \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)} \cdot R \]
    2. remove-double-negN/A

      \[\leadsto \cos^{-1} \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
    3. mul-1-negN/A

      \[\leadsto \cos^{-1} \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_2}\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
    4. distribute-neg-inN/A

      \[\leadsto \cos^{-1} \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_2 + \lambda_1\right)\right)\right)} \cdot R \]
    5. +-commutativeN/A

      \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_1 + -1 \cdot \lambda_2\right)}\right)\right) \cdot R \]
    6. cos-negN/A

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
    7. cos-lowering-cos.f64N/A

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
    8. mul-1-negN/A

      \[\leadsto \cos^{-1} \cos \left(\lambda_1 + \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)}\right) \cdot R \]
    9. unsub-negN/A

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

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

    \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)} \cdot R \]
  9. Step-by-step derivation
    1. cos-diffN/A

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)} \cdot R \]
    2. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\color{blue}{\cos \lambda_2 \cdot \cos \lambda_1} + \sin \lambda_1 \cdot \sin \lambda_2\right) \cdot R \]
    3. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\cos \lambda_2 \cdot \cos \lambda_1 + \color{blue}{\sin \lambda_2 \cdot \sin \lambda_1}\right) \cdot R \]
    4. cos-diffN/A

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

      \[\leadsto \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot R \]
    6. --lowering--.f646.2

      \[\leadsto \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot R \]
  10. Applied egg-rr6.2%

    \[\leadsto \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot R \]
  11. Add Preprocessing

Alternative 27: 3.6% accurate, 104.5× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \lambda_1 \cdot R \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* lambda1 R))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return lambda1 * R;
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this 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
    code = lambda1 * r
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return lambda1 * R;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	return lambda1 * R
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(lambda1 * R)
end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = lambda1 * R;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(lambda1 * R), $MachinePrecision]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\lambda_1 \cdot R
\end{array}
Derivation
  1. Initial program 70.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. Add Preprocessing
  3. Taylor expanded in phi1 around 0

    \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
  4. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
    2. cos-lowering-cos.f64N/A

      \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_2} \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
    3. sub-negN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
    4. remove-double-negN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
    5. mul-1-negN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_1}\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot R \]
    6. distribute-neg-inN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)}\right) \cdot R \]
    7. +-commutativeN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)}\right)\right)\right) \cdot R \]
    8. cos-negN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
    9. cos-lowering-cos.f64N/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \left(\lambda_2 + -1 \cdot \lambda_1\right)}\right) \cdot R \]
    10. mul-1-negN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 + \color{blue}{\left(\mathsf{neg}\left(\lambda_1\right)\right)}\right)\right) \cdot R \]
    11. unsub-negN/A

      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
    12. --lowering--.f6441.0

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

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

    \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_2 - \lambda_1\right)} \cdot R \]
  7. Step-by-step derivation
    1. sub-negN/A

      \[\leadsto \cos^{-1} \cos \color{blue}{\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)} \cdot R \]
    2. remove-double-negN/A

      \[\leadsto \cos^{-1} \cos \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
    3. mul-1-negN/A

      \[\leadsto \cos^{-1} \cos \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \lambda_2}\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right) \cdot R \]
    4. distribute-neg-inN/A

      \[\leadsto \cos^{-1} \cos \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \lambda_2 + \lambda_1\right)\right)\right)} \cdot R \]
    5. +-commutativeN/A

      \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\color{blue}{\left(\lambda_1 + -1 \cdot \lambda_2\right)}\right)\right) \cdot R \]
    6. cos-negN/A

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
    7. cos-lowering-cos.f64N/A

      \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)} \cdot R \]
    8. mul-1-negN/A

      \[\leadsto \cos^{-1} \cos \left(\lambda_1 + \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)}\right) \cdot R \]
    9. unsub-negN/A

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

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

    \[\leadsto \cos^{-1} \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)} \cdot R \]
  9. Taylor expanded in lambda1 around inf

    \[\leadsto \color{blue}{\lambda_1} \cdot R \]
  10. Step-by-step derivation
    1. Simplified4.2%

      \[\leadsto \color{blue}{\lambda_1} \cdot R \]
    2. Add Preprocessing

    Reproduce

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