Spherical law of cosines

Percentage Accurate: 73.1% → 96.3%
Time: 25.9s
Alternatives: 34
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 34 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.1% 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.3% 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 0:\\ \;\;\;\;\left(\lambda_2 - \lambda_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t\_0 + t\_1 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\ \end{array} \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))))) 0.0)
     (* (- lambda2 lambda1) R)
     (*
      R
      (acos
       (+
        t_0
        (*
         t_1
         (fma
          (cos lambda2)
          (cos lambda1)
          (* (sin lambda1) (sin 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))))) <= 0.0) {
		tmp = (lambda2 - lambda1) * R;
	} else {
		tmp = R * acos((t_0 + (t_1 * fma(cos(lambda2), cos(lambda1), (sin(lambda1) * sin(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))))) <= 0.0)
		tmp = Float64(Float64(lambda2 - lambda1) * R);
	else
		tmp = Float64(R * acos(Float64(t_0 + Float64(t_1 * fma(cos(lambda2), cos(lambda1), Float64(sin(lambda1) * sin(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], 0.0], N[(N[(lambda2 - lambda1), $MachinePrecision] * R), $MachinePrecision], N[(R * N[ArcCos[N[(t$95$0 + N[(t$95$1 * N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[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 0:\\
\;\;\;\;\left(\lambda_2 - \lambda_1\right) \cdot R\\

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


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

    1. Initial program 17.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 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--.f6417.8

        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
    5. Simplified17.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} \left(\color{blue}{1} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right) \cdot R \]
    7. Step-by-step derivation
      1. Simplified17.8%

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

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

          \[\leadsto \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot R \]
        3. *-lowering-*.f64N/A

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

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

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

      if 0.0 < (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 77.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 \left(\color{blue}{\cos \lambda_2 \cdot \cos \lambda_1} + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
        3. 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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
        4. 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(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
        5. 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(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
        6. *-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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
        7. 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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
        8. sin-lowering-sin.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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \color{blue}{\sin \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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
    8. Recombined 2 regimes into one program.
    9. Final simplification95.1%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \leq 0:\\ \;\;\;\;\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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\ \end{array} \]
    10. Add Preprocessing

    Alternative 2: 96.3% 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 0:\\ \;\;\;\;\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_2 \cdot \cos \lambda_1\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)))))
            0.0)
         (* (- lambda2 lambda1) R)
         (*
          R
          (acos
           (fma
            (*
             (cos phi2)
             (fma (sin lambda1) (sin lambda2) (* (cos lambda2) (cos lambda1))))
            (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))))) <= 0.0) {
    		tmp = (lambda2 - lambda1) * R;
    	} else {
    		tmp = R * acos(fma((cos(phi2) * fma(sin(lambda1), sin(lambda2), (cos(lambda2) * cos(lambda1)))), 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))))) <= 0.0)
    		tmp = Float64(Float64(lambda2 - lambda1) * R);
    	else
    		tmp = Float64(R * acos(fma(Float64(cos(phi2) * fma(sin(lambda1), sin(lambda2), Float64(cos(lambda2) * cos(lambda1)))), 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], 0.0], 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[lambda2], $MachinePrecision] * N[Cos[lambda1], $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 0:\\
    \;\;\;\;\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_2 \cdot \cos \lambda_1\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))))) < 0.0

      1. Initial program 17.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 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--.f6417.8

          \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
      5. Simplified17.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} \left(\color{blue}{1} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right) \cdot R \]
      7. Step-by-step derivation
        1. Simplified17.8%

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

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

            \[\leadsto \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot R \]
          3. *-lowering-*.f64N/A

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

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

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

        if 0.0 < (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 77.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 \left(\color{blue}{\cos \lambda_2 \cdot \cos \lambda_1} + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          3. 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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
          4. 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(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          5. 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(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          6. *-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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
          7. 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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
          8. sin-lowering-sin.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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \color{blue}{\sin \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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \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 \]
      8. Recombined 2 regimes into one program.
      9. Final simplification95.1%

        \[\leadsto \begin{array}{l} \mathbf{if}\;\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \leq 0:\\ \;\;\;\;\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_2 \cdot \cos \lambda_1\right), \cos \phi_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\ \end{array} \]
      10. Add Preprocessing

      Alternative 3: 83.6% accurate, 0.7× 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 := R \cdot \cos^{-1} \left(\mathsf{fma}\left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2, \cos \lambda_1, t\_0\right)\right)\\ \mathbf{if}\;\phi_2 \leq -0.058:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\phi_2 \leq 0.125:\\ \;\;\;\;R \cdot \cos^{-1} \left(t\_0 + \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(-0.001388888888888889, \phi_2 \cdot \phi_2, 0.041666666666666664\right), -0.5\right), 1\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \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
               (*
                R
                (acos
                 (fma
                  (* (* (cos phi1) (cos phi2)) (cos lambda2))
                  (cos lambda1)
                  t_0)))))
         (if (<= phi2 -0.058)
           t_1
           (if (<= phi2 0.125)
             (*
              R
              (acos
               (+
                t_0
                (*
                 (fma (cos lambda2) (cos lambda1) (* (sin lambda1) (sin lambda2)))
                 (*
                  (cos phi1)
                  (fma
                   (* phi2 phi2)
                   (fma
                    (* phi2 phi2)
                    (fma -0.001388888888888889 (* phi2 phi2) 0.041666666666666664)
                    -0.5)
                   1.0))))))
             t_1))))
      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 = R * acos(fma(((cos(phi1) * cos(phi2)) * cos(lambda2)), cos(lambda1), t_0));
      	double tmp;
      	if (phi2 <= -0.058) {
      		tmp = t_1;
      	} else if (phi2 <= 0.125) {
      		tmp = R * acos((t_0 + (fma(cos(lambda2), cos(lambda1), (sin(lambda1) * sin(lambda2))) * (cos(phi1) * fma((phi2 * phi2), fma((phi2 * phi2), fma(-0.001388888888888889, (phi2 * phi2), 0.041666666666666664), -0.5), 1.0)))));
      	} else {
      		tmp = t_1;
      	}
      	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(R * acos(fma(Float64(Float64(cos(phi1) * cos(phi2)) * cos(lambda2)), cos(lambda1), t_0)))
      	tmp = 0.0
      	if (phi2 <= -0.058)
      		tmp = t_1;
      	elseif (phi2 <= 0.125)
      		tmp = Float64(R * acos(Float64(t_0 + Float64(fma(cos(lambda2), cos(lambda1), Float64(sin(lambda1) * sin(lambda2))) * Float64(cos(phi1) * fma(Float64(phi2 * phi2), fma(Float64(phi2 * phi2), fma(-0.001388888888888889, Float64(phi2 * phi2), 0.041666666666666664), -0.5), 1.0))))));
      	else
      		tmp = t_1;
      	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[(R * N[ArcCos[N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -0.058], t$95$1, If[LessEqual[phi2, 0.125], N[(R * N[ArcCos[N[(t$95$0 + N[(N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[(N[(phi2 * phi2), $MachinePrecision] * N[(N[(phi2 * phi2), $MachinePrecision] * N[(-0.001388888888888889 * N[(phi2 * phi2), $MachinePrecision] + 0.041666666666666664), $MachinePrecision] + -0.5), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$1]]]]
      
      \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 := R \cdot \cos^{-1} \left(\mathsf{fma}\left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2, \cos \lambda_1, t\_0\right)\right)\\
      \mathbf{if}\;\phi_2 \leq -0.058:\\
      \;\;\;\;t\_1\\
      
      \mathbf{elif}\;\phi_2 \leq 0.125:\\
      \;\;\;\;R \cdot \cos^{-1} \left(t\_0 + \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(-0.001388888888888889, \phi_2 \cdot \phi_2, 0.041666666666666664\right), -0.5\right), 1\right)\right)\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_1\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if phi2 < -0.0580000000000000029 or 0.125 < phi2

        1. Initial program 82.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. Step-by-step derivation
          1. +-commutativeN/A

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

            \[\leadsto \cos^{-1} \left(\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)} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
          3. distribute-lft-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -0.0580000000000000029 < phi2 < 0.125

        1. Initial program 63.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 \left(\color{blue}{\cos \lambda_2 \cdot \cos \lambda_1} + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          3. 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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
          4. 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(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          5. 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(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          6. *-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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
          7. 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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
          8. sin-lowering-sin.f6487.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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right)\right) \cdot R \]
        4. Applied egg-rr87.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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
        5. Taylor expanded in phi2 around 0

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

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

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

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

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

            \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \color{blue}{{\phi_2}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_2}^{2}\right) + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}, 1\right)\right) \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          6. metadata-evalN/A

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

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

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

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

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

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

            \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\frac{-1}{720}, \color{blue}{\phi_2 \cdot \phi_2}, \frac{1}{24}\right), \frac{-1}{2}\right), 1\right)\right) \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          13. *-lowering-*.f6487.1

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

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

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

      Alternative 4: 83.6% accurate, 0.7× 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 := R \cdot \cos^{-1} \left(\mathsf{fma}\left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2, \cos \lambda_1, t\_0\right)\right)\\ \mathbf{if}\;\phi_2 \leq -0.1:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\phi_2 \leq 0.13:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_2 \cdot \cos \lambda_1\right) \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\phi_2, \phi_2 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), \cos \phi_1, t\_0\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \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
               (*
                R
                (acos
                 (fma
                  (* (* (cos phi1) (cos phi2)) (cos lambda2))
                  (cos lambda1)
                  t_0)))))
         (if (<= phi2 -0.1)
           t_1
           (if (<= phi2 0.13)
             (*
              R
              (acos
               (fma
                (*
                 (fma (sin lambda1) (sin lambda2) (* (cos lambda2) (cos lambda1)))
                 (fma
                  (* phi2 phi2)
                  (fma
                   phi2
                   (*
                    phi2
                    (fma (* phi2 phi2) -0.001388888888888889 0.041666666666666664))
                   -0.5)
                  1.0))
                (cos phi1)
                t_0)))
             t_1))))
      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 = R * acos(fma(((cos(phi1) * cos(phi2)) * cos(lambda2)), cos(lambda1), t_0));
      	double tmp;
      	if (phi2 <= -0.1) {
      		tmp = t_1;
      	} else if (phi2 <= 0.13) {
      		tmp = R * acos(fma((fma(sin(lambda1), sin(lambda2), (cos(lambda2) * cos(lambda1))) * fma((phi2 * phi2), fma(phi2, (phi2 * fma((phi2 * phi2), -0.001388888888888889, 0.041666666666666664)), -0.5), 1.0)), cos(phi1), t_0));
      	} else {
      		tmp = t_1;
      	}
      	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(R * acos(fma(Float64(Float64(cos(phi1) * cos(phi2)) * cos(lambda2)), cos(lambda1), t_0)))
      	tmp = 0.0
      	if (phi2 <= -0.1)
      		tmp = t_1;
      	elseif (phi2 <= 0.13)
      		tmp = Float64(R * acos(fma(Float64(fma(sin(lambda1), sin(lambda2), Float64(cos(lambda2) * cos(lambda1))) * fma(Float64(phi2 * phi2), fma(phi2, Float64(phi2 * fma(Float64(phi2 * phi2), -0.001388888888888889, 0.041666666666666664)), -0.5), 1.0)), cos(phi1), t_0)));
      	else
      		tmp = t_1;
      	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[(R * N[ArcCos[N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -0.1], t$95$1, If[LessEqual[phi2, 0.13], N[(R * N[ArcCos[N[(N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision] + N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(phi2 * phi2), $MachinePrecision] * N[(phi2 * N[(phi2 * N[(N[(phi2 * phi2), $MachinePrecision] * -0.001388888888888889 + 0.041666666666666664), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$1]]]]
      
      \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 := R \cdot \cos^{-1} \left(\mathsf{fma}\left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2, \cos \lambda_1, t\_0\right)\right)\\
      \mathbf{if}\;\phi_2 \leq -0.1:\\
      \;\;\;\;t\_1\\
      
      \mathbf{elif}\;\phi_2 \leq 0.13:\\
      \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_2 \cdot \cos \lambda_1\right) \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\phi_2, \phi_2 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), \cos \phi_1, t\_0\right)\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_1\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if phi2 < -0.10000000000000001 or 0.13 < phi2

        1. Initial program 82.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. Step-by-step derivation
          1. +-commutativeN/A

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

            \[\leadsto \cos^{-1} \left(\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)} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
          3. distribute-lft-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -0.10000000000000001 < phi2 < 0.13

        1. Initial program 63.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 \left(\color{blue}{\cos \lambda_2 \cdot \cos \lambda_1} + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          3. 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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
          4. 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(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          5. 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(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          6. *-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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
          7. 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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
          8. sin-lowering-sin.f6487.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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right)\right) \cdot R \]
        4. Applied egg-rr87.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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \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.f6487.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. Simplified87.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 \]
        8. Taylor expanded in phi2 around 0

          \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\left(1 + {\phi_2}^{2} \cdot \left({\phi_2}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_2}^{2}\right) - \frac{1}{2}\right)\right)} \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 \]
        9. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\left({\phi_2}^{2} \cdot \left({\phi_2}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_2}^{2}\right) - \frac{1}{2}\right) + 1\right)} \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 \]
          2. accelerator-lowering-fma.f64N/A

            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left({\phi_2}^{2}, {\phi_2}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_2}^{2}\right) - \frac{1}{2}, 1\right)} \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. unpow2N/A

            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\phi_2 \cdot \phi_2}, {\phi_2}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_2}^{2}\right) - \frac{1}{2}, 1\right) \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 \]
          4. *-lowering-*.f64N/A

            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\phi_2 \cdot \phi_2}, {\phi_2}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_2}^{2}\right) - \frac{1}{2}, 1\right) \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 \]
          5. sub-negN/A

            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\phi_2 \cdot \phi_2, \color{blue}{{\phi_2}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_2}^{2}\right) + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}, 1\right) \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 \]
          6. unpow2N/A

            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\phi_2 \cdot \phi_2, \color{blue}{\left(\phi_2 \cdot \phi_2\right)} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_2}^{2}\right) + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right), 1\right) \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 \]
          7. associate-*l*N/A

            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\phi_2 \cdot \phi_2, \color{blue}{\phi_2 \cdot \left(\phi_2 \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_2}^{2}\right)\right)} + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right), 1\right) \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. metadata-evalN/A

            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\phi_2 \cdot \phi_2, \phi_2 \cdot \left(\phi_2 \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_2}^{2}\right)\right) + \color{blue}{\frac{-1}{2}}, 1\right) \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 \]
          9. accelerator-lowering-fma.f64N/A

            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\phi_2 \cdot \phi_2, \color{blue}{\mathsf{fma}\left(\phi_2, \phi_2 \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_2}^{2}\right), \frac{-1}{2}\right)}, 1\right) \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 \]
          10. *-lowering-*.f64N/A

            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\phi_2, \color{blue}{\phi_2 \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_2}^{2}\right)}, \frac{-1}{2}\right), 1\right) \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 \]
          11. +-commutativeN/A

            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\phi_2, \phi_2 \cdot \color{blue}{\left(\frac{-1}{720} \cdot {\phi_2}^{2} + \frac{1}{24}\right)}, \frac{-1}{2}\right), 1\right) \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 \]
          12. *-commutativeN/A

            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\phi_2, \phi_2 \cdot \left(\color{blue}{{\phi_2}^{2} \cdot \frac{-1}{720}} + \frac{1}{24}\right), \frac{-1}{2}\right), 1\right) \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 \]
          13. accelerator-lowering-fma.f64N/A

            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\phi_2, \phi_2 \cdot \color{blue}{\mathsf{fma}\left({\phi_2}^{2}, \frac{-1}{720}, \frac{1}{24}\right)}, \frac{-1}{2}\right), 1\right) \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 \]
          14. unpow2N/A

            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\phi_2, \phi_2 \cdot \mathsf{fma}\left(\color{blue}{\phi_2 \cdot \phi_2}, \frac{-1}{720}, \frac{1}{24}\right), \frac{-1}{2}\right), 1\right) \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 \]
          15. *-lowering-*.f6487.1

            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\phi_2, \phi_2 \cdot \mathsf{fma}\left(\color{blue}{\phi_2 \cdot \phi_2}, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right) \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 \]
        10. Simplified87.1%

          \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\phi_2, \phi_2 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right)} \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 simplification84.7%

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

      Alternative 5: 83.6% accurate, 0.8× 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(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2, \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\ \mathbf{if}\;\phi_2 \leq -0.056:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_2 \leq 0.029:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \left(\phi_2 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\phi_2 \cdot \phi_2, 0.008333333333333333, -0.16666666666666666\right), 1\right)\right) + \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(0.041666666666666664, \phi_2 \cdot \phi_2, -0.5\right), 1\right)\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
                  (* (* (cos phi1) (cos phi2)) (cos lambda2))
                  (cos lambda1)
                  (* (sin phi1) (sin phi2)))))))
         (if (<= phi2 -0.056)
           t_0
           (if (<= phi2 0.029)
             (*
              R
              (acos
               (+
                (*
                 (sin phi1)
                 (*
                  phi2
                  (fma
                   (* phi2 phi2)
                   (fma (* phi2 phi2) 0.008333333333333333 -0.16666666666666666)
                   1.0)))
                (*
                 (fma (cos lambda2) (cos lambda1) (* (sin lambda1) (sin lambda2)))
                 (*
                  (cos phi1)
                  (fma
                   (* phi2 phi2)
                   (fma 0.041666666666666664 (* phi2 phi2) -0.5)
                   1.0))))))
             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(((cos(phi1) * cos(phi2)) * cos(lambda2)), cos(lambda1), (sin(phi1) * sin(phi2))));
      	double tmp;
      	if (phi2 <= -0.056) {
      		tmp = t_0;
      	} else if (phi2 <= 0.029) {
      		tmp = R * acos(((sin(phi1) * (phi2 * fma((phi2 * phi2), fma((phi2 * phi2), 0.008333333333333333, -0.16666666666666666), 1.0))) + (fma(cos(lambda2), cos(lambda1), (sin(lambda1) * sin(lambda2))) * (cos(phi1) * fma((phi2 * phi2), fma(0.041666666666666664, (phi2 * phi2), -0.5), 1.0)))));
      	} 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(Float64(Float64(cos(phi1) * cos(phi2)) * cos(lambda2)), cos(lambda1), Float64(sin(phi1) * sin(phi2)))))
      	tmp = 0.0
      	if (phi2 <= -0.056)
      		tmp = t_0;
      	elseif (phi2 <= 0.029)
      		tmp = Float64(R * acos(Float64(Float64(sin(phi1) * Float64(phi2 * fma(Float64(phi2 * phi2), fma(Float64(phi2 * phi2), 0.008333333333333333, -0.16666666666666666), 1.0))) + Float64(fma(cos(lambda2), cos(lambda1), Float64(sin(lambda1) * sin(lambda2))) * Float64(cos(phi1) * fma(Float64(phi2 * phi2), fma(0.041666666666666664, Float64(phi2 * phi2), -0.5), 1.0))))));
      	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[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -0.056], t$95$0, If[LessEqual[phi2, 0.029], N[(R * N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[(phi2 * N[(N[(phi2 * phi2), $MachinePrecision] * N[(N[(phi2 * phi2), $MachinePrecision] * 0.008333333333333333 + -0.16666666666666666), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[(N[(phi2 * phi2), $MachinePrecision] * N[(0.041666666666666664 * N[(phi2 * phi2), $MachinePrecision] + -0.5), $MachinePrecision] + 1.0), $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(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2, \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\
      \mathbf{if}\;\phi_2 \leq -0.056:\\
      \;\;\;\;t\_0\\
      
      \mathbf{elif}\;\phi_2 \leq 0.029:\\
      \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \left(\phi_2 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\phi_2 \cdot \phi_2, 0.008333333333333333, -0.16666666666666666\right), 1\right)\right) + \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(0.041666666666666664, \phi_2 \cdot \phi_2, -0.5\right), 1\right)\right)\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_0\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if phi2 < -0.0560000000000000012 or 0.0290000000000000015 < phi2

        1. Initial program 82.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. Step-by-step derivation
          1. +-commutativeN/A

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

            \[\leadsto \cos^{-1} \left(\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)} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
          3. distribute-lft-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -0.0560000000000000012 < phi2 < 0.0290000000000000015

        1. Initial program 63.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 \left(\color{blue}{\cos \lambda_2 \cdot \cos \lambda_1} + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          3. 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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
          4. 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(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          5. 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(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          6. *-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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
          7. 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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
          8. sin-lowering-sin.f6487.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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right)\right) \cdot R \]
        4. Applied egg-rr87.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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
        5. Taylor expanded in phi2 around 0

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

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

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

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

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

            \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \color{blue}{\frac{1}{24} \cdot {\phi_2}^{2} + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}, 1\right)\right) \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          6. metadata-evalN/A

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

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

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

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

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

          \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + {\phi_2}^{2} \cdot \left(\frac{1}{120} \cdot {\phi_2}^{2} - \frac{1}{6}\right)\right)\right)} + \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\frac{1}{24}, \phi_2 \cdot \phi_2, \frac{-1}{2}\right), 1\right)\right) \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
        9. Step-by-step derivation
          1. *-lowering-*.f64N/A

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

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

            \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \left(\phi_2 \cdot \color{blue}{\mathsf{fma}\left({\phi_2}^{2}, \frac{1}{120} \cdot {\phi_2}^{2} - \frac{1}{6}, 1\right)}\right) + \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\frac{1}{24}, \phi_2 \cdot \phi_2, \frac{-1}{2}\right), 1\right)\right) \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          4. unpow2N/A

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

            \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \left(\phi_2 \cdot \mathsf{fma}\left(\color{blue}{\phi_2 \cdot \phi_2}, \frac{1}{120} \cdot {\phi_2}^{2} - \frac{1}{6}, 1\right)\right) + \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\frac{1}{24}, \phi_2 \cdot \phi_2, \frac{-1}{2}\right), 1\right)\right) \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          6. sub-negN/A

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

            \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \left(\phi_2 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \color{blue}{{\phi_2}^{2} \cdot \frac{1}{120}} + \left(\mathsf{neg}\left(\frac{1}{6}\right)\right), 1\right)\right) + \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\frac{1}{24}, \phi_2 \cdot \phi_2, \frac{-1}{2}\right), 1\right)\right) \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          8. metadata-evalN/A

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

            \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \left(\phi_2 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \color{blue}{\mathsf{fma}\left({\phi_2}^{2}, \frac{1}{120}, \frac{-1}{6}\right)}, 1\right)\right) + \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\frac{1}{24}, \phi_2 \cdot \phi_2, \frac{-1}{2}\right), 1\right)\right) \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          10. unpow2N/A

            \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \left(\phi_2 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\color{blue}{\phi_2 \cdot \phi_2}, \frac{1}{120}, \frac{-1}{6}\right), 1\right)\right) + \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\frac{1}{24}, \phi_2 \cdot \phi_2, \frac{-1}{2}\right), 1\right)\right) \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          11. *-lowering-*.f6487.1

            \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \left(\phi_2 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\color{blue}{\phi_2 \cdot \phi_2}, 0.008333333333333333, -0.16666666666666666\right), 1\right)\right) + \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(0.041666666666666664, \phi_2 \cdot \phi_2, -0.5\right), 1\right)\right) \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
        10. Simplified87.1%

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

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

      Alternative 6: 83.6% accurate, 0.8× 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(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2, \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\ \mathbf{if}\;\phi_2 \leq -0.0023:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_2 \leq 0.037:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(0.041666666666666664, \phi_2 \cdot \phi_2, -0.5\right), 1\right)\right) + \sin \phi_1 \cdot \left(\phi_2 \cdot \mathsf{fma}\left(-0.16666666666666666, \phi_2 \cdot \phi_2, 1\right)\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
                  (* (* (cos phi1) (cos phi2)) (cos lambda2))
                  (cos lambda1)
                  (* (sin phi1) (sin phi2)))))))
         (if (<= phi2 -0.0023)
           t_0
           (if (<= phi2 0.037)
             (*
              R
              (acos
               (+
                (*
                 (fma (cos lambda2) (cos lambda1) (* (sin lambda1) (sin lambda2)))
                 (*
                  (cos phi1)
                  (fma
                   (* phi2 phi2)
                   (fma 0.041666666666666664 (* phi2 phi2) -0.5)
                   1.0)))
                (*
                 (sin phi1)
                 (* phi2 (fma -0.16666666666666666 (* phi2 phi2) 1.0))))))
             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(((cos(phi1) * cos(phi2)) * cos(lambda2)), cos(lambda1), (sin(phi1) * sin(phi2))));
      	double tmp;
      	if (phi2 <= -0.0023) {
      		tmp = t_0;
      	} else if (phi2 <= 0.037) {
      		tmp = R * acos(((fma(cos(lambda2), cos(lambda1), (sin(lambda1) * sin(lambda2))) * (cos(phi1) * fma((phi2 * phi2), fma(0.041666666666666664, (phi2 * phi2), -0.5), 1.0))) + (sin(phi1) * (phi2 * fma(-0.16666666666666666, (phi2 * phi2), 1.0)))));
      	} 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(Float64(Float64(cos(phi1) * cos(phi2)) * cos(lambda2)), cos(lambda1), Float64(sin(phi1) * sin(phi2)))))
      	tmp = 0.0
      	if (phi2 <= -0.0023)
      		tmp = t_0;
      	elseif (phi2 <= 0.037)
      		tmp = Float64(R * acos(Float64(Float64(fma(cos(lambda2), cos(lambda1), Float64(sin(lambda1) * sin(lambda2))) * Float64(cos(phi1) * fma(Float64(phi2 * phi2), fma(0.041666666666666664, Float64(phi2 * phi2), -0.5), 1.0))) + Float64(sin(phi1) * Float64(phi2 * fma(-0.16666666666666666, Float64(phi2 * phi2), 1.0))))));
      	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[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -0.0023], t$95$0, If[LessEqual[phi2, 0.037], N[(R * N[ArcCos[N[(N[(N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[(N[(phi2 * phi2), $MachinePrecision] * N[(0.041666666666666664 * N[(phi2 * phi2), $MachinePrecision] + -0.5), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * N[(phi2 * N[(-0.16666666666666666 * N[(phi2 * phi2), $MachinePrecision] + 1.0), $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(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2, \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\
      \mathbf{if}\;\phi_2 \leq -0.0023:\\
      \;\;\;\;t\_0\\
      
      \mathbf{elif}\;\phi_2 \leq 0.037:\\
      \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(0.041666666666666664, \phi_2 \cdot \phi_2, -0.5\right), 1\right)\right) + \sin \phi_1 \cdot \left(\phi_2 \cdot \mathsf{fma}\left(-0.16666666666666666, \phi_2 \cdot \phi_2, 1\right)\right)\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_0\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if phi2 < -0.0023 or 0.0369999999999999982 < phi2

        1. Initial program 82.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. Step-by-step derivation
          1. +-commutativeN/A

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

            \[\leadsto \cos^{-1} \left(\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)} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
          3. distribute-lft-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -0.0023 < phi2 < 0.0369999999999999982

        1. Initial program 63.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 \left(\color{blue}{\cos \lambda_2 \cdot \cos \lambda_1} + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          3. 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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
          4. 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(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          5. 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(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          6. *-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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
          7. 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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
          8. sin-lowering-sin.f6487.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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right)\right) \cdot R \]
        4. Applied egg-rr87.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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
        5. Taylor expanded in phi2 around 0

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

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

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

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

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

            \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \color{blue}{\frac{1}{24} \cdot {\phi_2}^{2} + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}, 1\right)\right) \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          6. metadata-evalN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 7: 83.5% accurate, 0.8× 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(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2, \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\ \mathbf{if}\;\phi_2 \leq -0.00044:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_2 \leq 0.014:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(0.041666666666666664, \phi_2 \cdot \phi_2, -0.5\right), 1\right)\right) + \sin \phi_1 \cdot \phi_2\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
                  (* (* (cos phi1) (cos phi2)) (cos lambda2))
                  (cos lambda1)
                  (* (sin phi1) (sin phi2)))))))
         (if (<= phi2 -0.00044)
           t_0
           (if (<= phi2 0.014)
             (*
              R
              (acos
               (+
                (*
                 (fma (cos lambda2) (cos lambda1) (* (sin lambda1) (sin lambda2)))
                 (*
                  (cos phi1)
                  (fma
                   (* phi2 phi2)
                   (fma 0.041666666666666664 (* phi2 phi2) -0.5)
                   1.0)))
                (* (sin phi1) 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 = R * acos(fma(((cos(phi1) * cos(phi2)) * cos(lambda2)), cos(lambda1), (sin(phi1) * sin(phi2))));
      	double tmp;
      	if (phi2 <= -0.00044) {
      		tmp = t_0;
      	} else if (phi2 <= 0.014) {
      		tmp = R * acos(((fma(cos(lambda2), cos(lambda1), (sin(lambda1) * sin(lambda2))) * (cos(phi1) * fma((phi2 * phi2), fma(0.041666666666666664, (phi2 * phi2), -0.5), 1.0))) + (sin(phi1) * phi2)));
      	} 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(Float64(Float64(cos(phi1) * cos(phi2)) * cos(lambda2)), cos(lambda1), Float64(sin(phi1) * sin(phi2)))))
      	tmp = 0.0
      	if (phi2 <= -0.00044)
      		tmp = t_0;
      	elseif (phi2 <= 0.014)
      		tmp = Float64(R * acos(Float64(Float64(fma(cos(lambda2), cos(lambda1), Float64(sin(lambda1) * sin(lambda2))) * Float64(cos(phi1) * fma(Float64(phi2 * phi2), fma(0.041666666666666664, Float64(phi2 * phi2), -0.5), 1.0))) + Float64(sin(phi1) * phi2))));
      	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[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -0.00044], t$95$0, If[LessEqual[phi2, 0.014], N[(R * N[ArcCos[N[(N[(N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[(N[(phi2 * phi2), $MachinePrecision] * N[(0.041666666666666664 * N[(phi2 * phi2), $MachinePrecision] + -0.5), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * phi2), $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(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2, \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\
      \mathbf{if}\;\phi_2 \leq -0.00044:\\
      \;\;\;\;t\_0\\
      
      \mathbf{elif}\;\phi_2 \leq 0.014:\\
      \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(0.041666666666666664, \phi_2 \cdot \phi_2, -0.5\right), 1\right)\right) + \sin \phi_1 \cdot \phi_2\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_0\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if phi2 < -4.40000000000000016e-4 or 0.0140000000000000003 < phi2

        1. Initial program 82.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. Step-by-step derivation
          1. +-commutativeN/A

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

            \[\leadsto \cos^{-1} \left(\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)} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
          3. distribute-lft-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -4.40000000000000016e-4 < phi2 < 0.0140000000000000003

        1. Initial program 63.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 \left(\color{blue}{\cos \lambda_2 \cdot \cos \lambda_1} + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          3. 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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
          4. 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(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          5. 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(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          6. *-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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
          7. 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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
          8. sin-lowering-sin.f6487.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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right)\right) \cdot R \]
        4. Applied egg-rr87.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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
        5. Taylor expanded in phi2 around 0

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

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

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

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

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

            \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \color{blue}{\frac{1}{24} \cdot {\phi_2}^{2} + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}, 1\right)\right) \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          6. metadata-evalN/A

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

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

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

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

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

          \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \color{blue}{\phi_2} + \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(\frac{1}{24}, \phi_2 \cdot \phi_2, \frac{-1}{2}\right), 1\right)\right) \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
        9. Step-by-step derivation
          1. Simplified86.7%

            \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \color{blue}{\phi_2} + \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(0.041666666666666664, \phi_2 \cdot \phi_2, -0.5\right), 1\right)\right) \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
        10. Recombined 2 regimes into one program.
        11. Final simplification84.6%

          \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -0.00044:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2, \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 0.014:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \left(\cos \phi_1 \cdot \mathsf{fma}\left(\phi_2 \cdot \phi_2, \mathsf{fma}\left(0.041666666666666664, \phi_2 \cdot \phi_2, -0.5\right), 1\right)\right) + \sin \phi_1 \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2, \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\ \end{array} \]
        12. Add Preprocessing

        Alternative 8: 83.5% accurate, 0.8× 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(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2, \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\ \mathbf{if}\;\phi_2 \leq -8.8 \cdot 10^{-5}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_2 \leq 0.014:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\phi_2, \sin \phi_1, \mathsf{fma}\left(-0.5, \phi_2 \cdot \phi_2, 1\right) \cdot \left(\cos \phi_1 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\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
                    (* (* (cos phi1) (cos phi2)) (cos lambda2))
                    (cos lambda1)
                    (* (sin phi1) (sin phi2)))))))
           (if (<= phi2 -8.8e-5)
             t_0
             (if (<= phi2 0.014)
               (*
                R
                (acos
                 (fma
                  phi2
                  (sin phi1)
                  (*
                   (fma -0.5 (* phi2 phi2) 1.0)
                   (*
                    (cos phi1)
                    (fma
                     (sin lambda1)
                     (sin lambda2)
                     (* (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 = R * acos(fma(((cos(phi1) * cos(phi2)) * cos(lambda2)), cos(lambda1), (sin(phi1) * sin(phi2))));
        	double tmp;
        	if (phi2 <= -8.8e-5) {
        		tmp = t_0;
        	} else if (phi2 <= 0.014) {
        		tmp = R * acos(fma(phi2, sin(phi1), (fma(-0.5, (phi2 * phi2), 1.0) * (cos(phi1) * fma(sin(lambda1), sin(lambda2), (cos(lambda2) * cos(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(Float64(Float64(cos(phi1) * cos(phi2)) * cos(lambda2)), cos(lambda1), Float64(sin(phi1) * sin(phi2)))))
        	tmp = 0.0
        	if (phi2 <= -8.8e-5)
        		tmp = t_0;
        	elseif (phi2 <= 0.014)
        		tmp = Float64(R * acos(fma(phi2, sin(phi1), Float64(fma(-0.5, Float64(phi2 * phi2), 1.0) * Float64(cos(phi1) * fma(sin(lambda1), sin(lambda2), Float64(cos(lambda2) * cos(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[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -8.8e-5], t$95$0, If[LessEqual[phi2, 0.014], N[(R * N[ArcCos[N[(phi2 * N[Sin[phi1], $MachinePrecision] + N[(N[(-0.5 * N[(phi2 * phi2), $MachinePrecision] + 1.0), $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision] + N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $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(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2, \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\
        \mathbf{if}\;\phi_2 \leq -8.8 \cdot 10^{-5}:\\
        \;\;\;\;t\_0\\
        
        \mathbf{elif}\;\phi_2 \leq 0.014:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\phi_2, \sin \phi_1, \mathsf{fma}\left(-0.5, \phi_2 \cdot \phi_2, 1\right) \cdot \left(\cos \phi_1 \cdot \mathsf{fma}\left(\sin \lambda_1, \sin \lambda_2, \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\right)\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_0\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if phi2 < -8.7999999999999998e-5 or 0.0140000000000000003 < phi2

          1. Initial program 82.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. +-commutativeN/A

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

              \[\leadsto \cos^{-1} \left(\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)} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
            3. distribute-lft-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

          if -8.7999999999999998e-5 < phi2 < 0.0140000000000000003

          1. Initial program 63.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 \cos^{-1} \color{blue}{\left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right) + \sin \phi_1 \cdot \sin \phi_2\right)} \cdot R \]
            2. cos-diffN/A

              \[\leadsto \cos^{-1} \left(\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)} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
            3. distribute-lft-inN/A

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

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

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

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

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

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

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

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

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

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

        Alternative 9: 83.4% accurate, 0.8× 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(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2, \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\ \mathbf{if}\;\phi_2 \leq -1.2 \cdot 10^{-6}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_2 \leq 1.3 \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_2 \cdot \cos \lambda_1\right)\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
                    (* (* (cos phi1) (cos phi2)) (cos lambda2))
                    (cos lambda1)
                    (* (sin phi1) (sin phi2)))))))
           (if (<= phi2 -1.2e-6)
             t_0
             (if (<= phi2 1.3e-6)
               (*
                R
                (acos
                 (fma
                  phi2
                  (sin phi1)
                  (*
                   (cos phi1)
                   (fma
                    (sin lambda1)
                    (sin lambda2)
                    (* (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 = R * acos(fma(((cos(phi1) * cos(phi2)) * cos(lambda2)), cos(lambda1), (sin(phi1) * sin(phi2))));
        	double tmp;
        	if (phi2 <= -1.2e-6) {
        		tmp = t_0;
        	} else if (phi2 <= 1.3e-6) {
        		tmp = R * acos(fma(phi2, sin(phi1), (cos(phi1) * fma(sin(lambda1), sin(lambda2), (cos(lambda2) * cos(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(Float64(Float64(cos(phi1) * cos(phi2)) * cos(lambda2)), cos(lambda1), Float64(sin(phi1) * sin(phi2)))))
        	tmp = 0.0
        	if (phi2 <= -1.2e-6)
        		tmp = t_0;
        	elseif (phi2 <= 1.3e-6)
        		tmp = Float64(R * acos(fma(phi2, sin(phi1), Float64(cos(phi1) * fma(sin(lambda1), sin(lambda2), Float64(cos(lambda2) * cos(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[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -1.2e-6], t$95$0, If[LessEqual[phi2, 1.3e-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[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $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(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2, \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\
        \mathbf{if}\;\phi_2 \leq -1.2 \cdot 10^{-6}:\\
        \;\;\;\;t\_0\\
        
        \mathbf{elif}\;\phi_2 \leq 1.3 \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_2 \cdot \cos \lambda_1\right)\right)\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_0\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if phi2 < -1.1999999999999999e-6 or 1.30000000000000005e-6 < phi2

          1. Initial program 81.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. +-commutativeN/A

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

              \[\leadsto \cos^{-1} \left(\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)} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
            3. distribute-lft-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

          if -1.1999999999999999e-6 < phi2 < 1.30000000000000005e-6

          1. Initial program 63.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. +-commutativeN/A

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

              \[\leadsto \cos^{-1} \left(\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)} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
            3. distribute-lft-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \cos^{-1} \left(\phi_2 \cdot \sin \phi_1 + \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 \]
            6. 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 \]
            7. 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 \]
            8. *-lowering-*.f64N/A

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

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

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

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

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

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

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

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

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

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

        Alternative 10: 83.2% accurate, 0.8× 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(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2, \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\ \mathbf{if}\;\phi_2 \leq -2.45 \cdot 10^{-14}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_2 \leq 3.5 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \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
                    (* (* (cos phi1) (cos phi2)) (cos lambda2))
                    (cos lambda1)
                    (* (sin phi1) (sin phi2)))))))
           (if (<= phi2 -2.45e-14)
             t_0
             (if (<= phi2 3.5e-7)
               (*
                R
                (acos
                 (*
                  (cos phi1)
                  (fma (cos lambda2) (cos lambda1) (* (sin lambda1) (sin lambda2))))))
               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(((cos(phi1) * cos(phi2)) * cos(lambda2)), cos(lambda1), (sin(phi1) * sin(phi2))));
        	double tmp;
        	if (phi2 <= -2.45e-14) {
        		tmp = t_0;
        	} else if (phi2 <= 3.5e-7) {
        		tmp = R * acos((cos(phi1) * fma(cos(lambda2), cos(lambda1), (sin(lambda1) * sin(lambda2)))));
        	} 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(Float64(Float64(cos(phi1) * cos(phi2)) * cos(lambda2)), cos(lambda1), Float64(sin(phi1) * sin(phi2)))))
        	tmp = 0.0
        	if (phi2 <= -2.45e-14)
        		tmp = t_0;
        	elseif (phi2 <= 3.5e-7)
        		tmp = Float64(R * acos(Float64(cos(phi1) * fma(cos(lambda2), cos(lambda1), Float64(sin(lambda1) * sin(lambda2))))));
        	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[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -2.45e-14], t$95$0, If[LessEqual[phi2, 3.5e-7], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $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(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2, \cos \lambda_1, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\
        \mathbf{if}\;\phi_2 \leq -2.45 \cdot 10^{-14}:\\
        \;\;\;\;t\_0\\
        
        \mathbf{elif}\;\phi_2 \leq 3.5 \cdot 10^{-7}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_0\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if phi2 < -2.44999999999999997e-14 or 3.49999999999999984e-7 < phi2

          1. Initial program 81.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. +-commutativeN/A

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

              \[\leadsto \cos^{-1} \left(\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)} + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
            3. distribute-lft-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

          if -2.44999999999999997e-14 < phi2 < 3.49999999999999984e-7

          1. Initial program 63.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 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.f6463.2

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

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

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

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

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

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

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

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

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

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

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

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

        Alternative 11: 83.1% 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)\\ t_1 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\phi_2 \leq -1.42 \cdot 10^{-8}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1 \cdot \cos \phi_2, t\_0, t\_1\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 3.8 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\pi \cdot 0.5, R, \sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot t\_0, t\_1\right)\right) \cdot \left(0 - 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 (* (sin phi1) (sin phi2))))
           (if (<= phi2 -1.42e-8)
             (* R (acos (fma (* (cos phi1) (cos phi2)) t_0 t_1)))
             (if (<= phi2 3.8e-7)
               (*
                R
                (acos
                 (*
                  (cos phi1)
                  (fma (cos lambda2) (cos lambda1) (* (sin lambda1) (sin lambda2))))))
               (fma
                (* PI 0.5)
                R
                (* (asin (fma (cos phi1) (* (cos phi2) t_0) t_1)) (- 0.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 t_1 = sin(phi1) * sin(phi2);
        	double tmp;
        	if (phi2 <= -1.42e-8) {
        		tmp = R * acos(fma((cos(phi1) * cos(phi2)), t_0, t_1));
        	} else if (phi2 <= 3.8e-7) {
        		tmp = R * acos((cos(phi1) * fma(cos(lambda2), cos(lambda1), (sin(lambda1) * sin(lambda2)))));
        	} else {
        		tmp = fma((((double) M_PI) * 0.5), R, (asin(fma(cos(phi1), (cos(phi2) * t_0), t_1)) * (0.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))
        	t_1 = Float64(sin(phi1) * sin(phi2))
        	tmp = 0.0
        	if (phi2 <= -1.42e-8)
        		tmp = Float64(R * acos(fma(Float64(cos(phi1) * cos(phi2)), t_0, t_1)));
        	elseif (phi2 <= 3.8e-7)
        		tmp = Float64(R * acos(Float64(cos(phi1) * fma(cos(lambda2), cos(lambda1), Float64(sin(lambda1) * sin(lambda2))))));
        	else
        		tmp = fma(Float64(pi * 0.5), R, Float64(asin(fma(cos(phi1), Float64(cos(phi2) * t_0), t_1)) * Float64(0.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]}, Block[{t$95$1 = N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -1.42e-8], N[(R * N[ArcCos[N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 3.8e-7], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $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$1), $MachinePrecision]], $MachinePrecision] * N[(0.0 - R), $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 := \sin \phi_1 \cdot \sin \phi_2\\
        \mathbf{if}\;\phi_2 \leq -1.42 \cdot 10^{-8}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1 \cdot \cos \phi_2, t\_0, t\_1\right)\right)\\
        
        \mathbf{elif}\;\phi_2 \leq 3.8 \cdot 10^{-7}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;\mathsf{fma}\left(\pi \cdot 0.5, R, \sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot t\_0, t\_1\right)\right) \cdot \left(0 - R\right)\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if phi2 < -1.41999999999999998e-8

          1. Initial program 79.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. Step-by-step derivation
            1. +-commutativeN/A

              \[\leadsto \cos^{-1} \color{blue}{\left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right) + \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_1 \cdot \cos \phi_2, \cos \left(\lambda_1 - \lambda_2\right), \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_1 \cdot \cos \phi_2}, \cos \left(\lambda_1 - \lambda_2\right), \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_1} \cdot \cos \phi_2, \cos \left(\lambda_1 - \lambda_2\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(\cos \phi_1 \cdot \color{blue}{\cos \phi_2}, \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
            6. cos-lowering-cos.f64N/A

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

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

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

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

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

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

          if -1.41999999999999998e-8 < phi2 < 3.80000000000000015e-7

          1. Initial program 63.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 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.f6462.8

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

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

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

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

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

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

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

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

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

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

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

          if 3.80000000000000015e-7 < phi2

          1. Initial program 84.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. *-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-rr84.9%

            \[\leadsto \color{blue}{\mathsf{fma}\left(\pi \cdot 0.5, R, \left(0 - \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 simplification84.1%

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

        Alternative 12: 83.1% 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 -1.25 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1 \cdot \cos \phi_2, t\_0, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 3.5 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot t\_0\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 (<= phi2 -1.25e-9)
             (* R (acos (fma (* (cos phi1) (cos phi2)) t_0 (* (sin phi1) (sin phi2)))))
             (if (<= phi2 3.5e-7)
               (*
                R
                (acos
                 (*
                  (cos phi1)
                  (fma (cos lambda2) (cos lambda1) (* (sin lambda1) (sin lambda2))))))
               (*
                R
                (acos
                 (fma (sin phi2) (sin phi1) (* (cos phi1) (* (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((lambda1 - lambda2));
        	double tmp;
        	if (phi2 <= -1.25e-9) {
        		tmp = R * acos(fma((cos(phi1) * cos(phi2)), t_0, (sin(phi1) * sin(phi2))));
        	} else if (phi2 <= 3.5e-7) {
        		tmp = R * acos((cos(phi1) * fma(cos(lambda2), cos(lambda1), (sin(lambda1) * sin(lambda2)))));
        	} else {
        		tmp = R * acos(fma(sin(phi2), sin(phi1), (cos(phi1) * (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(lambda1 - lambda2))
        	tmp = 0.0
        	if (phi2 <= -1.25e-9)
        		tmp = Float64(R * acos(fma(Float64(cos(phi1) * cos(phi2)), t_0, Float64(sin(phi1) * sin(phi2)))));
        	elseif (phi2 <= 3.5e-7)
        		tmp = Float64(R * acos(Float64(cos(phi1) * fma(cos(lambda2), cos(lambda1), Float64(sin(lambda1) * sin(lambda2))))));
        	else
        		tmp = Float64(R * acos(fma(sin(phi2), sin(phi1), Float64(cos(phi1) * Float64(cos(phi2) * 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[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -1.25e-9], N[(R * N[ArcCos[N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0 + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 3.5e-7], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 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]]]]
        
        \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 -1.25 \cdot 10^{-9}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1 \cdot \cos \phi_2, t\_0, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\
        
        \mathbf{elif}\;\phi_2 \leq 3.5 \cdot 10^{-7}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot t\_0\right)\right)\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if phi2 < -1.25e-9

          1. Initial program 79.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. Step-by-step derivation
            1. +-commutativeN/A

              \[\leadsto \cos^{-1} \color{blue}{\left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right) + \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_1 \cdot \cos \phi_2, \cos \left(\lambda_1 - \lambda_2\right), \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_1 \cdot \cos \phi_2}, \cos \left(\lambda_1 - \lambda_2\right), \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_1} \cdot \cos \phi_2, \cos \left(\lambda_1 - \lambda_2\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(\cos \phi_1 \cdot \color{blue}{\cos \phi_2}, \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
            6. cos-lowering-cos.f64N/A

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

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

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

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

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

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

          if -1.25e-9 < phi2 < 3.49999999999999984e-7

          1. Initial program 63.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 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.f6462.8

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

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

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

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

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

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

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

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

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

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

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

          if 3.49999999999999984e-7 < phi2

          1. Initial program 84.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. *-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--.f6484.9

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

            \[\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 \]
        3. Recombined 3 regimes into one program.
        4. Final simplification84.1%

          \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -1.25 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1 \cdot \cos \phi_2, \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_1 \cdot \sin \phi_2\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 3.5 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\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 13: 83.1% 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 -1.02 \cdot 10^{-7}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_2 \leq 3.5 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \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 -1.02e-7)
             t_0
             (if (<= phi2 3.5e-7)
               (*
                R
                (acos
                 (*
                  (cos phi1)
                  (fma (cos lambda2) (cos lambda1) (* (sin lambda1) (sin lambda2))))))
               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 <= -1.02e-7) {
        		tmp = t_0;
        	} else if (phi2 <= 3.5e-7) {
        		tmp = R * acos((cos(phi1) * fma(cos(lambda2), cos(lambda1), (sin(lambda1) * sin(lambda2)))));
        	} 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 <= -1.02e-7)
        		tmp = t_0;
        	elseif (phi2 <= 3.5e-7)
        		tmp = Float64(R * acos(Float64(cos(phi1) * fma(cos(lambda2), cos(lambda1), Float64(sin(lambda1) * sin(lambda2))))));
        	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, -1.02e-7], t$95$0, If[LessEqual[phi2, 3.5e-7], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $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 -1.02 \cdot 10^{-7}:\\
        \;\;\;\;t\_0\\
        
        \mathbf{elif}\;\phi_2 \leq 3.5 \cdot 10^{-7}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_0\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if phi2 < -1.02e-7 or 3.49999999999999984e-7 < phi2

          1. Initial program 81.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. *-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--.f6481.9

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

            \[\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 -1.02e-7 < phi2 < 3.49999999999999984e-7

          1. Initial program 63.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 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.f6462.8

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -1.02 \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 3.5 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\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 14: 75.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 \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\lambda_1 \leq -2 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_1, \cos \phi_1 \cdot \cos \phi_2, t\_0\right)\right)\\ \mathbf{elif}\;\lambda_1 \leq 1.75 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \cos \lambda_2, t\_0\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\ \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 (<= lambda1 -2e-6)
             (* R (acos (fma (cos lambda1) (* (cos phi1) (cos phi2)) t_0)))
             (if (<= lambda1 1.75e-6)
               (* R (acos (fma (cos phi1) (* (cos phi2) (cos lambda2)) t_0)))
               (*
                R
                (acos
                 (*
                  (cos phi1)
                  (fma
                   (cos lambda2)
                   (cos lambda1)
                   (* (sin lambda1) (sin 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 tmp;
        	if (lambda1 <= -2e-6) {
        		tmp = R * acos(fma(cos(lambda1), (cos(phi1) * cos(phi2)), t_0));
        	} else if (lambda1 <= 1.75e-6) {
        		tmp = R * acos(fma(cos(phi1), (cos(phi2) * cos(lambda2)), t_0));
        	} else {
        		tmp = R * acos((cos(phi1) * fma(cos(lambda2), cos(lambda1), (sin(lambda1) * sin(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))
        	tmp = 0.0
        	if (lambda1 <= -2e-6)
        		tmp = Float64(R * acos(fma(cos(lambda1), Float64(cos(phi1) * cos(phi2)), t_0)));
        	elseif (lambda1 <= 1.75e-6)
        		tmp = Float64(R * acos(fma(cos(phi1), Float64(cos(phi2) * cos(lambda2)), t_0)));
        	else
        		tmp = Float64(R * acos(Float64(cos(phi1) * fma(cos(lambda2), cos(lambda1), Float64(sin(lambda1) * sin(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]}, If[LessEqual[lambda1, -2e-6], N[(R * N[ArcCos[N[(N[Cos[lambda1], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda1, 1.75e-6], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $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\\
        \mathbf{if}\;\lambda_1 \leq -2 \cdot 10^{-6}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_1, \cos \phi_1 \cdot \cos \phi_2, t\_0\right)\right)\\
        
        \mathbf{elif}\;\lambda_1 \leq 1.75 \cdot 10^{-6}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \cos \lambda_2, t\_0\right)\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if lambda1 < -1.99999999999999991e-6

          1. Initial program 60.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 \left(\color{blue}{\cos \lambda_2 \cdot \cos \lambda_1} + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            3. 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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
            4. 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(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            5. 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(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            6. *-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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
            7. 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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
            8. sin-lowering-sin.f6499.6

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

            \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
          5. 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 \]
          6. Step-by-step derivation
            1. accelerator-lowering-fma.f64N/A

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

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

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

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

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

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

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

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

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

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

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

          if -1.99999999999999991e-6 < lambda1 < 1.74999999999999997e-6

          1. Initial program 86.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 \left(\color{blue}{\cos \lambda_2 \cdot \cos \lambda_1} + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            3. 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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
            4. 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(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            5. 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(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            6. *-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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
            7. 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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
            8. sin-lowering-sin.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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \color{blue}{\sin \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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \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 lambda1 around 0

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

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

              \[\leadsto \cos^{-1} \left(\color{blue}{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \lambda_2\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_1, \cos \phi_2 \cdot \cos \lambda_2, \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_1}, \cos \phi_2 \cdot \cos \lambda_2, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
            5. *-lowering-*.f64N/A

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

              \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \color{blue}{\cos \phi_2} \cdot \cos \lambda_2, \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_1, \cos \phi_2 \cdot \color{blue}{\cos \lambda_2}, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R \]
            8. *-lowering-*.f64N/A

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

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

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

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

          if 1.74999999999999997e-6 < lambda1

          1. Initial program 57.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 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.f6432.2

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

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

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

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

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

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

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

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

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

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

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

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

        Alternative 15: 75.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 := \cos \phi_1 \cdot \cos \phi_2\\ \mathbf{if}\;\lambda_1 \leq -3.2 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_1, t\_1, t\_0\right)\right)\\ \mathbf{elif}\;\lambda_1 \leq 3.2 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_2, t\_1, t\_0\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\ \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 (<= lambda1 -3.2e-5)
             (* R (acos (fma (cos lambda1) t_1 t_0)))
             (if (<= lambda1 3.2e-6)
               (* R (acos (fma (cos lambda2) t_1 t_0)))
               (*
                R
                (acos
                 (*
                  (cos phi1)
                  (fma
                   (cos lambda2)
                   (cos lambda1)
                   (* (sin lambda1) (sin 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 (lambda1 <= -3.2e-5) {
        		tmp = R * acos(fma(cos(lambda1), t_1, t_0));
        	} else if (lambda1 <= 3.2e-6) {
        		tmp = R * acos(fma(cos(lambda2), t_1, t_0));
        	} else {
        		tmp = R * acos((cos(phi1) * fma(cos(lambda2), cos(lambda1), (sin(lambda1) * sin(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 (lambda1 <= -3.2e-5)
        		tmp = Float64(R * acos(fma(cos(lambda1), t_1, t_0)));
        	elseif (lambda1 <= 3.2e-6)
        		tmp = Float64(R * acos(fma(cos(lambda2), t_1, t_0)));
        	else
        		tmp = Float64(R * acos(Float64(cos(phi1) * fma(cos(lambda2), cos(lambda1), Float64(sin(lambda1) * sin(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[lambda1, -3.2e-5], N[(R * N[ArcCos[N[(N[Cos[lambda1], $MachinePrecision] * t$95$1 + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda1, 3.2e-6], N[(R * N[ArcCos[N[(N[Cos[lambda2], $MachinePrecision] * t$95$1 + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $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}\;\lambda_1 \leq -3.2 \cdot 10^{-5}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_1, t\_1, t\_0\right)\right)\\
        
        \mathbf{elif}\;\lambda_1 \leq 3.2 \cdot 10^{-6}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_2, t\_1, t\_0\right)\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if lambda1 < -3.19999999999999986e-5

          1. Initial program 60.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 \left(\color{blue}{\cos \lambda_2 \cdot \cos \lambda_1} + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            3. 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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
            4. 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(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            5. 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(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            6. *-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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
            7. 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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
            8. sin-lowering-sin.f6499.6

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

            \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
          5. 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 \]
          6. Step-by-step derivation
            1. accelerator-lowering-fma.f64N/A

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

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

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

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

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

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

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

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

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

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

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

          if -3.19999999999999986e-5 < lambda1 < 3.1999999999999999e-6

          1. Initial program 86.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 \left(\color{blue}{\cos \lambda_2 \cdot \cos \lambda_1} + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            3. 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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
            4. 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(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            5. 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(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            6. *-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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
            7. 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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
            8. sin-lowering-sin.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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \color{blue}{\sin \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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
          5. Taylor expanded in lambda1 around 0

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_2, \cos \phi_2 \cdot \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 \lambda_2, \cos \phi_2 \cdot \cos \phi_1, \sin \phi_2 \cdot \sin \phi_1\right)\right)} \cdot R \]

          if 3.1999999999999999e-6 < lambda1

          1. Initial program 57.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 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.f6432.2

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

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

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

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

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

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

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

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

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

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

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

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

        Alternative 16: 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 := \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\\ \mathbf{if}\;\phi_1 \leq -4.3 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t\_0\right)\\ \mathbf{elif}\;\phi_1 \leq 0.00026:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_1, \cos \phi_1 \cdot \cos \phi_2, \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
                 (fma (cos lambda2) (cos lambda1) (* (sin lambda1) (sin lambda2)))))
           (if (<= phi1 -4.3e-6)
             (* R (acos (* (cos phi1) t_0)))
             (if (<= phi1 0.00026)
               (* R (acos (* (cos phi2) t_0)))
               (*
                R
                (acos
                 (fma
                  (cos lambda1)
                  (* (cos phi1) (cos phi2))
                  (* (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 = fma(cos(lambda2), cos(lambda1), (sin(lambda1) * sin(lambda2)));
        	double tmp;
        	if (phi1 <= -4.3e-6) {
        		tmp = R * acos((cos(phi1) * t_0));
        	} else if (phi1 <= 0.00026) {
        		tmp = R * acos((cos(phi2) * t_0));
        	} else {
        		tmp = R * acos(fma(cos(lambda1), (cos(phi1) * cos(phi2)), (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 = fma(cos(lambda2), cos(lambda1), Float64(sin(lambda1) * sin(lambda2)))
        	tmp = 0.0
        	if (phi1 <= -4.3e-6)
        		tmp = Float64(R * acos(Float64(cos(phi1) * t_0)));
        	elseif (phi1 <= 0.00026)
        		tmp = Float64(R * acos(Float64(cos(phi2) * t_0)));
        	else
        		tmp = Float64(R * acos(fma(cos(lambda1), Float64(cos(phi1) * cos(phi2)), 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[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -4.3e-6], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 0.00026], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[lambda1], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $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 := \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\\
        \mathbf{if}\;\phi_1 \leq -4.3 \cdot 10^{-6}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t\_0\right)\\
        
        \mathbf{elif}\;\phi_1 \leq 0.00026:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot t\_0\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_1, \cos \phi_1 \cdot \cos \phi_2, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if phi1 < -4.30000000000000033e-6

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

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

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

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

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

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

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

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

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

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

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

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

          if -4.30000000000000033e-6 < phi1 < 2.59999999999999977e-4

          1. Initial program 67.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 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--.f6466.8

              \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
          5. Simplified66.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. *-commutativeN/A

              \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \left(\cos \lambda_2 \cdot \cos \lambda_1 + \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
            3. 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_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
            4. 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_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            5. 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_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            6. *-lowering-*.f64N/A

              \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \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_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
            8. sin-lowering-sin.f6485.7

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

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

          if 2.59999999999999977e-4 < phi1

          1. Initial program 78.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. 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 \left(\color{blue}{\cos \lambda_2 \cdot \cos \lambda_1} + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            3. 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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
            4. 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(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            5. 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(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            6. *-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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
            7. 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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
            8. sin-lowering-sin.f6499.4

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

            \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
          5. 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 \]
          6. Step-by-step derivation
            1. accelerator-lowering-fma.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

        Alternative 17: 63.0% accurate, 1.0× speedup?

        \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\\ \mathbf{if}\;\phi_1 \leq -4 \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
                 (fma (cos lambda2) (cos lambda1) (* (sin lambda1) (sin lambda2)))))
           (if (<= phi1 -4e-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 = fma(cos(lambda2), cos(lambda1), (sin(lambda1) * sin(lambda2)));
        	double tmp;
        	if (phi1 <= -4e-6) {
        		tmp = R * acos((cos(phi1) * t_0));
        	} else {
        		tmp = R * acos((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 = fma(cos(lambda2), cos(lambda1), Float64(sin(lambda1) * sin(lambda2)))
        	tmp = 0.0
        	if (phi1 <= -4e-6)
        		tmp = Float64(R * acos(Float64(cos(phi1) * t_0)));
        	else
        		tmp = Float64(R * acos(Float64(cos(phi2) * 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[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -4e-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 := \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\\
        \mathbf{if}\;\phi_1 \leq -4 \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 < -3.99999999999999982e-6

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

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

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

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

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

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

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

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

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

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

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

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

          if -3.99999999999999982e-6 < phi1

          1. Initial program 71.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--.f6451.5

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

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

              \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \left(\cos \lambda_2 \cdot \cos \lambda_1 + \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
            3. 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_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
            4. 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_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            5. 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_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            6. *-lowering-*.f64N/A

              \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \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_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
            8. sin-lowering-sin.f6464.3

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

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

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

        Alternative 18: 60.2% 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_1 \leq -5 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \cos \left(\lambda_2 - \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_1 \cdot \sin \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
         (if (<= phi1 -5e-6)
           (*
            R
            (acos
             (+ (* (sin phi1) (sin phi2)) (* (cos phi1) (cos (- lambda2 lambda1))))))
           (*
            R
            (acos
             (*
              (cos phi2)
              (fma (cos lambda2) (cos lambda1) (* (sin lambda1) (sin 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 (phi1 <= -5e-6) {
        		tmp = R * acos(((sin(phi1) * sin(phi2)) + (cos(phi1) * cos((lambda2 - lambda1)))));
        	} else {
        		tmp = R * acos((cos(phi2) * fma(cos(lambda2), cos(lambda1), (sin(lambda1) * sin(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 (phi1 <= -5e-6)
        		tmp = Float64(R * acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(cos(phi1) * cos(Float64(lambda2 - lambda1))))));
        	else
        		tmp = Float64(R * acos(Float64(cos(phi2) * fma(cos(lambda2), cos(lambda1), Float64(sin(lambda1) * sin(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_] := If[LessEqual[phi1, -5e-6], N[(R * N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $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_1 \leq -5 \cdot 10^{-6}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \cos \left(\lambda_2 - \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_1 \cdot \sin \lambda_2\right)\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if phi1 < -5.00000000000000041e-6

          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. Taylor expanded in phi2 around 0

            \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \color{blue}{\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} \left(\sin \phi_1 \cdot \sin \phi_2 + \color{blue}{\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1}\right) \cdot R \]
            2. *-lowering-*.f64N/A

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

              \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \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(\sin \phi_1 \cdot \sin \phi_2 + \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(\sin \phi_1 \cdot \sin \phi_2 + \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(\sin \phi_1 \cdot \sin \phi_2 + \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(\sin \phi_1 \cdot \sin \phi_2 + \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(\sin \phi_1 \cdot \sin \phi_2 + \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(\sin \phi_1 \cdot \sin \phi_2 + \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(\sin \phi_1 \cdot \sin \phi_2 + \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(\sin \phi_1 \cdot \sin \phi_2 + \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
            12. --lowering--.f64N/A

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

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

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

          if -5.00000000000000041e-6 < phi1

          1. Initial program 71.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--.f6451.5

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

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

              \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \left(\cos \lambda_2 \cdot \cos \lambda_1 + \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
            3. 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_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
            4. 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_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            5. 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_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            6. *-lowering-*.f64N/A

              \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \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_2 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
            8. sin-lowering-sin.f6464.3

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

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

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

        Alternative 19: 62.6% accurate, 1.2× speedup?

        \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_1 - \lambda_2 \leq -4 \cdot 10^{-10}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(0, 0.5, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(-0.5, \lambda_1 \cdot \lambda_1, 1\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 lambda2) -4e-10)
           (*
            R
            (acos
             (fma 0.0 0.5 (* (cos phi1) (* (cos phi2) (cos (- lambda2 lambda1)))))))
           (*
            R
            (acos
             (fma
              (sin phi2)
              (sin phi1)
              (* (* (cos phi1) (cos phi2)) (fma -0.5 (* lambda1 lambda1) 1.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 - lambda2) <= -4e-10) {
        		tmp = R * acos(fma(0.0, 0.5, (cos(phi1) * (cos(phi2) * cos((lambda2 - lambda1))))));
        	} else {
        		tmp = R * acos(fma(sin(phi2), sin(phi1), ((cos(phi1) * cos(phi2)) * fma(-0.5, (lambda1 * lambda1), 1.0))));
        	}
        	return tmp;
        }
        
        R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
        function code(R, lambda1, lambda2, phi1, phi2)
        	tmp = 0.0
        	if (Float64(lambda1 - lambda2) <= -4e-10)
        		tmp = Float64(R * acos(fma(0.0, 0.5, Float64(cos(phi1) * Float64(cos(phi2) * cos(Float64(lambda2 - lambda1)))))));
        	else
        		tmp = Float64(R * acos(fma(sin(phi2), sin(phi1), Float64(Float64(cos(phi1) * cos(phi2)) * fma(-0.5, Float64(lambda1 * lambda1), 1.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_] := If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -4e-10], N[(R * N[ArcCos[N[(0.0 * 0.5 + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[(-0.5 * N[(lambda1 * lambda1), $MachinePrecision] + 1.0), $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}\;\lambda_1 - \lambda_2 \leq -4 \cdot 10^{-10}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(0, 0.5, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(-0.5, \lambda_1 \cdot \lambda_1, 1\right)\right)\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (-.f64 lambda1 lambda2) < -4.00000000000000015e-10

          1. Initial program 75.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. *-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}{\cos \lambda_2 \cdot \cos \lambda_1} + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            3. 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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
            4. 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(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            5. 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(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            6. *-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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
            7. 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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
            8. sin-lowering-sin.f6499.4

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

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

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

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

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

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

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

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

              \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\cos \left(\phi_1 - \phi_2\right) - \cos \left(\phi_1 + \phi_2\right), \frac{1}{2}, \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(\color{blue}{\cos \left(\phi_1 - \phi_2\right) - \cos \left(\phi_1 + \phi_2\right)}, \frac{1}{2}, \cos \phi_1 \cdot \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(\color{blue}{\cos \left(\phi_1 - \phi_2\right)} - \cos \left(\phi_1 + \phi_2\right), \frac{1}{2}, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right) \cdot R \]
            10. --lowering--.f64N/A

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

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

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

              \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \left(\phi_1 - \phi_2\right) - \cos \left(\phi_1 + \phi_2\right), \frac{1}{2}, \color{blue}{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
          6. Applied egg-rr56.3%

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

            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \left(\mathsf{neg}\left(\phi_2\right)\right) - \cos \phi_2}, \frac{1}{2}, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\right) \cdot R \]
          8. Step-by-step derivation
            1. cos-negN/A

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

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

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

          if -4.00000000000000015e-10 < (-.f64 lambda1 lambda2)

          1. Initial program 71.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} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \lambda_1 \cdot \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)}\right) \cdot R \]
          4. Step-by-step derivation
            1. +-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(\lambda_1 \cdot \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) + \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
            2. 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(\lambda_1, \lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right), \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
          5. Simplified45.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(\lambda_1, \mathsf{fma}\left(0 - \sin \lambda_2, \mathsf{fma}\left(\lambda_1, \mathsf{fma}\left(\lambda_1, 0.16666666666666666, 0\right), -1\right), \mathsf{fma}\left(\lambda_1, -0.5 \cdot \cos \lambda_2, 0\right)\right), \cos \lambda_2\right)}\right) \cdot R \]
          6. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        Alternative 20: 62.7% accurate, 1.2× speedup?

        \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_1 - \lambda_2 \leq -2 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(0, 0.5, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_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 (<= (- lambda1 lambda2) -2e-7)
           (*
            R
            (acos
             (fma 0.0 0.5 (* (cos phi1) (* (cos phi2) (cos (- lambda2 lambda1)))))))
           (* 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 ((lambda1 - lambda2) <= -2e-7) {
        		tmp = R * acos(fma(0.0, 0.5, (cos(phi1) * (cos(phi2) * cos((lambda2 - lambda1))))));
        	} 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 (Float64(lambda1 - lambda2) <= -2e-7)
        		tmp = Float64(R * acos(fma(0.0, 0.5, Float64(cos(phi1) * Float64(cos(phi2) * cos(Float64(lambda2 - lambda1)))))));
        	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[N[(lambda1 - lambda2), $MachinePrecision], -2e-7], N[(R * N[ArcCos[N[(0.0 * 0.5 + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $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}\;\lambda_1 - \lambda_2 \leq -2 \cdot 10^{-7}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(0, 0.5, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_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 2 regimes
        2. if (-.f64 lambda1 lambda2) < -1.9999999999999999e-7

          1. Initial program 75.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. *-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}{\cos \lambda_2 \cdot \cos \lambda_1} + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            3. 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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
            4. 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(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            5. 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(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
            6. *-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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
            7. 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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
            8. sin-lowering-sin.f6499.4

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

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

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

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

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

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

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

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

              \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\cos \left(\phi_1 - \phi_2\right) - \cos \left(\phi_1 + \phi_2\right), \frac{1}{2}, \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(\color{blue}{\cos \left(\phi_1 - \phi_2\right) - \cos \left(\phi_1 + \phi_2\right)}, \frac{1}{2}, \cos \phi_1 \cdot \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(\color{blue}{\cos \left(\phi_1 - \phi_2\right)} - \cos \left(\phi_1 + \phi_2\right), \frac{1}{2}, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right) \cdot R \]
            10. --lowering--.f64N/A

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

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

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

              \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \left(\phi_1 - \phi_2\right) - \cos \left(\phi_1 + \phi_2\right), \frac{1}{2}, \color{blue}{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
          6. Applied egg-rr56.3%

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

            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \left(\mathsf{neg}\left(\phi_2\right)\right) - \cos \phi_2}, \frac{1}{2}, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\right) \cdot R \]
          8. Step-by-step derivation
            1. cos-negN/A

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

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

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

          if -1.9999999999999999e-7 < (-.f64 lambda1 lambda2)

          1. Initial program 71.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} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \lambda_1 \cdot \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)}\right) \cdot R \]
          4. Step-by-step derivation
            1. +-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(\lambda_1 \cdot \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) + \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
            2. 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(\lambda_1, \lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right), \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
          5. Simplified45.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(\lambda_1, \mathsf{fma}\left(0 - \sin \lambda_2, \mathsf{fma}\left(\lambda_1, \mathsf{fma}\left(\lambda_1, 0.16666666666666666, 0\right), -1\right), \mathsf{fma}\left(\lambda_1, -0.5 \cdot \cos \lambda_2, 0\right)\right), \cos \lambda_2\right)}\right) \cdot R \]
          6. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot \mathsf{fma}\left(-0.5, \lambda_1 \cdot \lambda_1, 1\right)\right)\right)} \cdot R \]
          9. 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 \]
          10. 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.f6438.3

              \[\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 \]
          11. Simplified38.3%

            \[\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 2 regimes into one program.
        4. Final simplification44.4%

          \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 - \lambda_2 \leq -2 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(0, 0.5, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_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 21: 57.9% accurate, 1.5× speedup?

        \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ R \cdot \cos^{-1} \left(\mathsf{fma}\left(0, 0.5, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\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
          (acos
           (fma 0.0 0.5 (* (cos phi1) (* (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) {
        	return R * acos(fma(0.0, 0.5, (cos(phi1) * (cos(phi2) * cos((lambda2 - lambda1))))));
        }
        
        R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
        function code(R, lambda1, lambda2, phi1, phi2)
        	return Float64(R * acos(fma(0.0, 0.5, Float64(cos(phi1) * Float64(cos(phi2) * cos(Float64(lambda2 - lambda1)))))))
        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[(R * N[ArcCos[N[(0.0 * 0.5 + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $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])\\
        \\
        R \cdot \cos^{-1} \left(\mathsf{fma}\left(0, 0.5, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\right)
        \end{array}
        
        Derivation
        1. Initial program 72.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 \left(\color{blue}{\cos \lambda_2 \cdot \cos \lambda_1} + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          3. 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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
          4. 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(\color{blue}{\cos \lambda_2}, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          5. 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(\cos \lambda_2, \color{blue}{\cos \lambda_1}, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R \]
          6. *-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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1 \cdot \sin \lambda_2}\right)\right) \cdot R \]
          7. 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(\cos \lambda_2, \cos \lambda_1, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)\right) \cdot R \]
          8. sin-lowering-sin.f6493.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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right)\right) \cdot R \]
        4. Applied egg-rr93.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(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)}\right) \cdot R \]
        5. Step-by-step derivation
          1. sin-multN/A

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

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

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

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

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

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

            \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\cos \left(\phi_1 - \phi_2\right) - \cos \left(\phi_1 + \phi_2\right), \frac{1}{2}, \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(\color{blue}{\cos \left(\phi_1 - \phi_2\right) - \cos \left(\phi_1 + \phi_2\right)}, \frac{1}{2}, \cos \phi_1 \cdot \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(\color{blue}{\cos \left(\phi_1 - \phi_2\right)} - \cos \left(\phi_1 + \phi_2\right), \frac{1}{2}, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right) \cdot R \]
          10. --lowering--.f64N/A

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

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

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

            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \left(\phi_1 - \phi_2\right) - \cos \left(\phi_1 + \phi_2\right), \frac{1}{2}, \color{blue}{\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right)\right) \cdot R \]
        6. Applied egg-rr57.3%

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

          \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{\cos \left(\mathsf{neg}\left(\phi_2\right)\right) - \cos \phi_2}, \frac{1}{2}, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\right) \cdot R \]
        8. Step-by-step derivation
          1. cos-negN/A

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

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

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

          \[\leadsto R \cdot \cos^{-1} \left(\mathsf{fma}\left(0, 0.5, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\right) \]
        11. Add Preprocessing

        Alternative 22: 49.9% 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 -5.6 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{fma}\left(\pi, 0.5, 0 - \sin^{-1} \left(\cos \phi_2 \cdot 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 (cos (- lambda2 lambda1))))
           (if (<= phi1 -5.6e-6)
             (* R (acos (* (cos phi1) t_0)))
             (* R (fma PI 0.5 (- 0.0 (asin (* (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 <= -5.6e-6) {
        		tmp = R * acos((cos(phi1) * t_0));
        	} else {
        		tmp = R * fma(((double) M_PI), 0.5, (0.0 - asin((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 <= -5.6e-6)
        		tmp = Float64(R * acos(Float64(cos(phi1) * t_0)));
        	else
        		tmp = Float64(R * fma(pi, 0.5, Float64(0.0 - asin(Float64(cos(phi2) * 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[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi1, -5.6e-6], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(Pi * 0.5 + N[(0.0 - N[ArcSin[N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $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 := \cos \left(\lambda_2 - \lambda_1\right)\\
        \mathbf{if}\;\phi_1 \leq -5.6 \cdot 10^{-6}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t\_0\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;R \cdot \mathsf{fma}\left(\pi, 0.5, 0 - \sin^{-1} \left(\cos \phi_2 \cdot t\_0\right)\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if phi1 < -5.59999999999999975e-6

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

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

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

          if -5.59999999999999975e-6 < phi1

          1. Initial program 71.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--.f6451.5

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

            \[\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. acos-asinN/A

              \[\leadsto \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{2} - \sin^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\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(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\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(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\right)\right) \cdot R \]
            4. metadata-evalN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        Alternative 23: 36.4% 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_2 \leq -5.8 \cdot 10^{-244}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_2\right)\\ \mathbf{elif}\;\phi_2 \leq 5.8 \cdot 10^{-17}:\\ \;\;\;\;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 (<= phi2 -5.8e-244)
           (* R (acos (* (cos phi1) (cos lambda2))))
           (if (<= phi2 5.8e-17)
             (* 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 (phi2 <= -5.8e-244) {
        		tmp = R * acos((cos(phi1) * cos(lambda2)));
        	} else if (phi2 <= 5.8e-17) {
        		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 (phi2 <= (-5.8d-244)) then
                tmp = r * acos((cos(phi1) * cos(lambda2)))
            else if (phi2 <= 5.8d-17) 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 (phi2 <= -5.8e-244) {
        		tmp = R * Math.acos((Math.cos(phi1) * Math.cos(lambda2)));
        	} else if (phi2 <= 5.8e-17) {
        		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 phi2 <= -5.8e-244:
        		tmp = R * math.acos((math.cos(phi1) * math.cos(lambda2)))
        	elif phi2 <= 5.8e-17:
        		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 (phi2 <= -5.8e-244)
        		tmp = Float64(R * acos(Float64(cos(phi1) * cos(lambda2))));
        	elseif (phi2 <= 5.8e-17)
        		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 (phi2 <= -5.8e-244)
        		tmp = R * acos((cos(phi1) * cos(lambda2)));
        	elseif (phi2 <= 5.8e-17)
        		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[phi2, -5.8e-244], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 5.8e-17], 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}\;\phi_2 \leq -5.8 \cdot 10^{-244}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_2\right)\\
        
        \mathbf{elif}\;\phi_2 \leq 5.8 \cdot 10^{-17}:\\
        \;\;\;\;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 3 regimes
        2. if phi2 < -5.79999999999999992e-244

          1. Initial program 70.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 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.f6435.3

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

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

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

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

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

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

              \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \color{blue}{\cos \lambda_2}\right) \cdot R \]
          8. Simplified27.5%

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

          if -5.79999999999999992e-244 < phi2 < 5.8000000000000006e-17

          1. Initial program 65.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.f6465.5

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

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

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

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

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

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

              \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \color{blue}{\cos \lambda_1}\right) \cdot R \]
          8. Simplified44.7%

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

          if 5.8000000000000006e-17 < phi2

          1. Initial program 85.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--.f6450.3

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

            \[\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} \left(\cos \phi_2 \cdot \color{blue}{\cos \lambda_2}\right) \cdot R \]
          7. Step-by-step derivation
            1. cos-lowering-cos.f6438.6

              \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \lambda_2}\right) \cdot R \]
          8. Simplified38.6%

            \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \color{blue}{\cos \lambda_2}\right) \cdot R \]
        3. Recombined 3 regimes into one program.
        4. Final simplification35.4%

          \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -5.8 \cdot 10^{-244}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_2\right)\\ \mathbf{elif}\;\phi_2 \leq 5.8 \cdot 10^{-17}:\\ \;\;\;\;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 24: 49.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_2 - \lambda_1\right)\\ \mathbf{if}\;\phi_1 \leq -1.16 \cdot 10^{-5}:\\ \;\;\;\;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 -1.16e-5)
             (* 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 <= -1.16e-5) {
        		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 <= (-1.16d-5)) 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 <= -1.16e-5) {
        		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 <= -1.16e-5:
        		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 <= -1.16e-5)
        		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 <= -1.16e-5)
        		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, -1.16e-5], 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 -1.16 \cdot 10^{-5}:\\
        \;\;\;\;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 < -1.1600000000000001e-5

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

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

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

          if -1.1600000000000001e-5 < phi1

          1. Initial program 71.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--.f6451.5

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

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

          \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.16 \cdot 10^{-5}:\\ \;\;\;\;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 25: 47.6% 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 -0.00024:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\\ \end{array} \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.00024)
           (* R (acos (* (cos phi1) (cos lambda2))))
           (* 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 <= -0.00024) {
        		tmp = R * acos((cos(phi1) * cos(lambda2)));
        	} 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 <= (-0.00024d0)) then
                tmp = r * acos((cos(phi1) * cos(lambda2)))
            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 <= -0.00024) {
        		tmp = R * Math.acos((Math.cos(phi1) * Math.cos(lambda2)));
        	} 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 <= -0.00024:
        		tmp = R * math.acos((math.cos(phi1) * math.cos(lambda2)))
        	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 <= -0.00024)
        		tmp = Float64(R * acos(Float64(cos(phi1) * cos(lambda2))));
        	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 <= -0.00024)
        		tmp = R * acos((cos(phi1) * cos(lambda2)));
        	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, -0.00024], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[Cos[lambda2], $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 -0.00024:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_2\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if phi1 < -2.40000000000000006e-4

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

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

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

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

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

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

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

              \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \color{blue}{\cos \lambda_2}\right) \cdot R \]
          8. Simplified41.0%

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

          if -2.40000000000000006e-4 < phi1

          1. Initial program 71.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--.f6451.5

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

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

          \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -0.00024:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\\ \end{array} \]
        5. Add Preprocessing

        Alternative 26: 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_1 \leq -2.6 \cdot 10^{-17}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \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 (<= lambda1 -2.6e-17)
           (* R (acos (* (cos phi2) (cos lambda1))))
           (* R (acos (* (cos phi1) (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 <= -2.6e-17) {
        		tmp = R * acos((cos(phi2) * cos(lambda1)));
        	} else {
        		tmp = R * acos((cos(phi1) * 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 (lambda1 <= (-2.6d-17)) then
                tmp = r * acos((cos(phi2) * cos(lambda1)))
            else
                tmp = r * acos((cos(phi1) * 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 (lambda1 <= -2.6e-17) {
        		tmp = R * Math.acos((Math.cos(phi2) * Math.cos(lambda1)));
        	} else {
        		tmp = R * Math.acos((Math.cos(phi1) * 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 <= -2.6e-17:
        		tmp = R * math.acos((math.cos(phi2) * math.cos(lambda1)))
        	else:
        		tmp = R * math.acos((math.cos(phi1) * 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 (lambda1 <= -2.6e-17)
        		tmp = Float64(R * acos(Float64(cos(phi2) * cos(lambda1))));
        	else
        		tmp = Float64(R * acos(Float64(cos(phi1) * 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 (lambda1 <= -2.6e-17)
        		tmp = R * acos((cos(phi2) * cos(lambda1)));
        	else
        		tmp = R * acos((cos(phi1) * 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[lambda1, -2.6e-17], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi1], $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_1 \leq -2.6 \cdot 10^{-17}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \lambda_1\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_2\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if lambda1 < -2.60000000000000003e-17

          1. Initial program 60.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. 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--.f6435.7

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

            \[\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} \left(\cos \phi_2 \cdot \color{blue}{\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. cos-lowering-cos.f6436.1

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

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

          if -2.60000000000000003e-17 < lambda1

          1. Initial program 75.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.f6441.4

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

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

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

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

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

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

              \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \color{blue}{\cos \lambda_2}\right) \cdot R \]
          8. Simplified35.6%

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

          \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -2.6 \cdot 10^{-17}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_2\right)\\ \end{array} \]
        5. Add Preprocessing

        Alternative 27: 42.1% 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 6.2 \cdot 10^{-22}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_2\right)\\ \end{array} \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 6.2e-22)
           (* R (acos (* (cos phi1) (cos lambda1))))
           (* R (acos (* (cos phi1) (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 <= 6.2e-22) {
        		tmp = R * acos((cos(phi1) * cos(lambda1)));
        	} else {
        		tmp = R * acos((cos(phi1) * 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 <= 6.2d-22) then
                tmp = r * acos((cos(phi1) * cos(lambda1)))
            else
                tmp = r * acos((cos(phi1) * 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 <= 6.2e-22) {
        		tmp = R * Math.acos((Math.cos(phi1) * Math.cos(lambda1)));
        	} else {
        		tmp = R * Math.acos((Math.cos(phi1) * 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 <= 6.2e-22:
        		tmp = R * math.acos((math.cos(phi1) * math.cos(lambda1)))
        	else:
        		tmp = R * math.acos((math.cos(phi1) * 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 <= 6.2e-22)
        		tmp = Float64(R * acos(Float64(cos(phi1) * cos(lambda1))));
        	else
        		tmp = Float64(R * acos(Float64(cos(phi1) * 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 <= 6.2e-22)
        		tmp = R * acos((cos(phi1) * cos(lambda1)));
        	else
        		tmp = R * acos((cos(phi1) * 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, 6.2e-22], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi1], $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 6.2 \cdot 10^{-22}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_2\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if lambda2 < 6.20000000000000025e-22

          1. Initial program 76.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. 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.f6442.6

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

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

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

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

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

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

              \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \color{blue}{\cos \lambda_1}\right) \cdot R \]
          8. Simplified33.7%

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

          if 6.20000000000000025e-22 < lambda2

          1. Initial program 62.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 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.f6436.3

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

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

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

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

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

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

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

            \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_1 \cdot \cos \lambda_2\right)} \cdot R \]
        3. Recombined 2 regimes into one program.
        4. Final simplification34.5%

          \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 6.2 \cdot 10^{-22}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_2\right)\\ \end{array} \]
        5. Add Preprocessing

        Alternative 28: 32.0% 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 -5 \cdot 10^{-8}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \left(\lambda_2 - \lambda_1\right)\\ \end{array} \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 -5e-8)
           (* R (acos (* (cos phi1) (cos lambda1))))
           (* R (acos (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 <= -5e-8) {
        		tmp = R * acos((cos(phi1) * cos(lambda1)));
        	} else {
        		tmp = R * acos(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 <= (-5d-8)) then
                tmp = r * acos((cos(phi1) * cos(lambda1)))
            else
                tmp = r * acos(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 <= -5e-8) {
        		tmp = R * Math.acos((Math.cos(phi1) * Math.cos(lambda1)));
        	} else {
        		tmp = R * Math.acos(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 <= -5e-8:
        		tmp = R * math.acos((math.cos(phi1) * math.cos(lambda1)))
        	else:
        		tmp = R * math.acos(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 <= -5e-8)
        		tmp = Float64(R * acos(Float64(cos(phi1) * cos(lambda1))));
        	else
        		tmp = Float64(R * acos(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 <= -5e-8)
        		tmp = R * acos((cos(phi1) * cos(lambda1)));
        	else
        		tmp = R * acos(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, -5e-8], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[Cos[N[(lambda2 - 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 -5 \cdot 10^{-8}:\\
        \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;R \cdot \cos^{-1} \cos \left(\lambda_2 - \lambda_1\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if phi1 < -4.9999999999999998e-8

          1. Initial program 78.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 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.f6450.1

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

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

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

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

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

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

              \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \color{blue}{\cos \lambda_1}\right) \cdot R \]
          8. Simplified43.5%

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

          if -4.9999999999999998e-8 < phi1

          1. Initial program 70.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 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--.f6451.5

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

            \[\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} \left(\color{blue}{1} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right) \cdot R \]
          7. Step-by-step derivation
            1. Simplified29.6%

              \[\leadsto \cos^{-1} \left(\color{blue}{1} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right) \cdot R \]
          8. Recombined 2 regimes into one program.
          9. Final simplification33.2%

            \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -5 \cdot 10^{-8}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \left(\lambda_2 - \lambda_1\right)\\ \end{array} \]
          10. Add Preprocessing

          Alternative 29: 32.8% accurate, 2.7× speedup?

          \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_1 - \lambda_2 \leq -2 \cdot 10^{-7}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \left(\lambda_2 - \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(-0.5, \lambda_1 \cdot \lambda_1, 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 (<= (- lambda1 lambda2) -2e-7)
             (* R (acos (cos (- lambda2 lambda1))))
             (* R (acos (* (cos phi1) (fma -0.5 (* lambda1 lambda1) 1.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 - lambda2) <= -2e-7) {
          		tmp = R * acos(cos((lambda2 - lambda1)));
          	} else {
          		tmp = R * acos((cos(phi1) * fma(-0.5, (lambda1 * lambda1), 1.0)));
          	}
          	return tmp;
          }
          
          R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
          function code(R, lambda1, lambda2, phi1, phi2)
          	tmp = 0.0
          	if (Float64(lambda1 - lambda2) <= -2e-7)
          		tmp = Float64(R * acos(cos(Float64(lambda2 - lambda1))));
          	else
          		tmp = Float64(R * acos(Float64(cos(phi1) * fma(-0.5, Float64(lambda1 * lambda1), 1.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_] := If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -2e-7], N[(R * N[ArcCos[N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(-0.5 * N[(lambda1 * lambda1), $MachinePrecision] + 1.0), $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_1 - \lambda_2 \leq -2 \cdot 10^{-7}:\\
          \;\;\;\;R \cdot \cos^{-1} \cos \left(\lambda_2 - \lambda_1\right)\\
          
          \mathbf{else}:\\
          \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(-0.5, \lambda_1 \cdot \lambda_1, 1\right)\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (-.f64 lambda1 lambda2) < -1.9999999999999999e-7

            1. Initial program 75.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--.f6447.3

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

              \[\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} \left(\color{blue}{1} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right) \cdot R \]
            7. Step-by-step derivation
              1. Simplified34.0%

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

              if -1.9999999999999999e-7 < (-.f64 lambda1 lambda2)

              1. Initial program 71.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} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \lambda_1 \cdot \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)}\right) \cdot R \]
              4. Step-by-step derivation
                1. +-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(\lambda_1 \cdot \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) + \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
                2. 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(\lambda_1, \lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right), \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}\right) \cdot R \]
              5. Simplified45.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(\lambda_1, \mathsf{fma}\left(0 - \sin \lambda_2, \mathsf{fma}\left(\lambda_1, \mathsf{fma}\left(\lambda_1, 0.16666666666666666, 0\right), -1\right), \mathsf{fma}\left(\lambda_1, -0.5 \cdot \cos \lambda_2, 0\right)\right), \cos \lambda_2\right)}\right) \cdot R \]
              6. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \color{blue}{\mathsf{fma}\left(\frac{-1}{2}, {\lambda_1}^{2}, 1\right)}\right) \cdot R \]
                5. unpow2N/A

                  \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(\frac{-1}{2}, \color{blue}{\lambda_1 \cdot \lambda_1}, 1\right)\right) \cdot R \]
                6. *-lowering-*.f6415.5

                  \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \mathsf{fma}\left(-0.5, \color{blue}{\lambda_1 \cdot \lambda_1}, 1\right)\right) \cdot R \]
              11. Simplified15.5%

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

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

            Alternative 30: 24.8% 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 -1.08 \cdot 10^{+14}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left|\left(\left(\lambda_2 - \lambda_1\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 -1.08e+14)
               (* R (acos (cos lambda1)))
               (* R (fabs (remainder (- lambda2 lambda1) (* 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 <= -1.08e+14) {
            		tmp = R * acos(cos(lambda1));
            	} else {
            		tmp = R * fabs(remainder((lambda2 - lambda1), (((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 <= -1.08e+14) {
            		tmp = R * Math.acos(Math.cos(lambda1));
            	} else {
            		tmp = R * Math.abs(Math.IEEEremainder((lambda2 - lambda1), (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 <= -1.08e+14:
            		tmp = R * math.acos(math.cos(lambda1))
            	else:
            		tmp = R * math.fabs(math.remainder((lambda2 - lambda1), (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, -1.08e+14], N[(R * N[ArcCos[N[Cos[lambda1], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[Abs[N[With[{TMP1 = N[(lambda2 - lambda1), $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 -1.08 \cdot 10^{+14}:\\
            \;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\
            
            \mathbf{else}:\\
            \;\;\;\;R \cdot \left|\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right|\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if lambda1 < -1.08e14

              1. Initial program 59.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--.f6435.8

                  \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
              5. Simplified35.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} \left(\color{blue}{1} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right) \cdot R \]
              7. Step-by-step derivation
                1. Simplified30.4%

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

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

                    \[\leadsto \cos^{-1} \color{blue}{\cos \lambda_1} \cdot R \]
                  2. cos-lowering-cos.f6431.0

                    \[\leadsto \cos^{-1} \color{blue}{\cos \lambda_1} \cdot R \]
                4. Simplified31.0%

                  \[\leadsto \cos^{-1} \color{blue}{\cos \lambda_1} \cdot R \]

                if -1.08e14 < lambda1

                1. Initial program 75.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. 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--.f6444.5

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

                  \[\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} \left(\color{blue}{1} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right) \cdot R \]
                7. Step-by-step derivation
                  1. Simplified25.2%

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

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

                      \[\leadsto \color{blue}{\left|\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right|} \cdot R \]
                    3. fabs-lowering-fabs.f64N/A

                      \[\leadsto \color{blue}{\left|\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right|} \cdot R \]
                    4. remainder-lowering-remainder.f64N/A

                      \[\leadsto \left|\color{blue}{\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)}\right| \cdot R \]
                    5. --lowering--.f64N/A

                      \[\leadsto \left|\left(\color{blue}{\left(\lambda_2 - \lambda_1\right)} \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right| \cdot R \]
                    6. *-lowering-*.f64N/A

                      \[\leadsto \left|\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \color{blue}{\left(2 \cdot \mathsf{PI}\left(\right)\right)}\right)\right| \cdot R \]
                    7. PI-lowering-PI.f6422.1

                      \[\leadsto \left|\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \left(2 \cdot \color{blue}{\pi}\right)\right)\right| \cdot R \]
                  3. Applied egg-rr22.1%

                    \[\leadsto \color{blue}{\left|\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \left(2 \cdot \pi\right)\right)\right|} \cdot R \]
                8. Recombined 2 regimes into one program.
                9. Final simplification23.7%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -1.08 \cdot 10^{+14}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left|\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right|\\ \end{array} \]
                10. Add Preprocessing

                Alternative 31: 26.4% accurate, 3.0× speedup?

                \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ R \cdot \cos^{-1} \cos \left(\lambda_2 - \lambda_1\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 (acos (cos (- lambda2 lambda1)))))
                assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                	return R * acos(cos((lambda2 - lambda1)));
                }
                
                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 = r * acos(cos((lambda2 - lambda1)))
                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 R * Math.acos(Math.cos((lambda2 - lambda1)));
                }
                
                [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
                def code(R, lambda1, lambda2, phi1, phi2):
                	return R * math.acos(math.cos((lambda2 - lambda1)))
                
                R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                function code(R, lambda1, lambda2, phi1, phi2)
                	return Float64(R * acos(cos(Float64(lambda2 - lambda1))))
                end
                
                R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
                function tmp = code(R, lambda1, lambda2, phi1, phi2)
                	tmp = R * acos(cos((lambda2 - lambda1)));
                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[(R * N[ArcCos[N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
                
                \begin{array}{l}
                [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                \\
                R \cdot \cos^{-1} \cos \left(\lambda_2 - \lambda_1\right)
                \end{array}
                
                Derivation
                1. Initial program 72.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. 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.0

                    \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
                5. Simplified43.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} \left(\color{blue}{1} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right) \cdot R \]
                7. Step-by-step derivation
                  1. Simplified26.2%

                    \[\leadsto \cos^{-1} \left(\color{blue}{1} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right) \cdot R \]
                  2. Final simplification26.2%

                    \[\leadsto R \cdot \cos^{-1} \cos \left(\lambda_2 - \lambda_1\right) \]
                  3. Add Preprocessing

                  Alternative 32: 20.0% 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_2 - \lambda_1\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 (- lambda2 lambda1) (* 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((lambda2 - lambda1), (((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((lambda2 - lambda1), (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((lambda2 - lambda1), (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[(lambda2 - lambda1), $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_2 - \lambda_1\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right|
                  \end{array}
                  
                  Derivation
                  1. Initial program 72.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. 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.0

                      \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
                  5. Simplified43.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} \left(\color{blue}{1} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right) \cdot R \]
                  7. Step-by-step derivation
                    1. Simplified26.2%

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

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

                        \[\leadsto \color{blue}{\left|\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right|} \cdot R \]
                      3. fabs-lowering-fabs.f64N/A

                        \[\leadsto \color{blue}{\left|\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right|} \cdot R \]
                      4. remainder-lowering-remainder.f64N/A

                        \[\leadsto \left|\color{blue}{\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)}\right| \cdot R \]
                      5. --lowering--.f64N/A

                        \[\leadsto \left|\left(\color{blue}{\left(\lambda_2 - \lambda_1\right)} \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right| \cdot R \]
                      6. *-lowering-*.f64N/A

                        \[\leadsto \left|\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \color{blue}{\left(2 \cdot \mathsf{PI}\left(\right)\right)}\right)\right| \cdot R \]
                      7. PI-lowering-PI.f6421.8

                        \[\leadsto \left|\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \left(2 \cdot \color{blue}{\pi}\right)\right)\right| \cdot R \]
                    3. Applied egg-rr21.8%

                      \[\leadsto \color{blue}{\left|\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \left(2 \cdot \pi\right)\right)\right|} \cdot R \]
                    4. Final simplification21.8%

                      \[\leadsto R \cdot \left|\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \left(\pi \cdot 2\right)\right)\right| \]
                    5. Add Preprocessing

                    Alternative 33: 9.3% 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 72.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. 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.0

                        \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
                    5. Simplified43.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} \left(\color{blue}{1} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right) \cdot R \]
                    7. Step-by-step derivation
                      1. Simplified26.2%

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

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

                          \[\leadsto \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot R \]
                        3. *-lowering-*.f64N/A

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

                          \[\leadsto \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot R \]
                      3. Applied egg-rr6.7%

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

                      Alternative 34: 7.1% accurate, 104.5× speedup?

                      \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \lambda_2 \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 R))
                      assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                      double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                      	return lambda2 * 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 * 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 * R;
                      }
                      
                      [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
                      def code(R, lambda1, lambda2, phi1, phi2):
                      	return lambda2 * R
                      
                      R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                      function code(R, lambda1, lambda2, phi1, phi2)
                      	return Float64(lambda2 * R)
                      end
                      
                      R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
                      function tmp = code(R, lambda1, lambda2, phi1, phi2)
                      	tmp = lambda2 * 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[(lambda2 * R), $MachinePrecision]
                      
                      \begin{array}{l}
                      [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                      \\
                      \lambda_2 \cdot R
                      \end{array}
                      
                      Derivation
                      1. Initial program 72.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. 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.0

                          \[\leadsto \cos^{-1} \left(\cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right) \cdot R \]
                      5. Simplified43.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} \left(\color{blue}{1} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right) \cdot R \]
                      7. Step-by-step derivation
                        1. Simplified26.2%

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

                          \[\leadsto \color{blue}{R \cdot \lambda_2} \]
                        3. Step-by-step derivation
                          1. *-commutativeN/A

                            \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
                          2. *-lowering-*.f646.3

                            \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
                        4. Simplified6.3%

                          \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
                        5. Add Preprocessing

                        Reproduce

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