Spherical law of cosines

Percentage Accurate: 74.1% → 94.1%
Time: 20.5s
Alternatives: 19
Speedup: 0.9×

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 19 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: 74.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: 94.1% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_1 \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right), \cos \lambda_2, \mathsf{fma}\left(\left(\sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right) \cdot R \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  (acos
   (fma
    (* (cos lambda1) (* (cos phi2) (cos phi1)))
    (cos lambda2)
    (fma
     (* (* (sin lambda1) (sin lambda2)) (cos phi1))
     (cos phi2)
     (* (sin phi2) (sin phi1)))))
  R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return acos(fma((cos(lambda1) * (cos(phi2) * cos(phi1))), cos(lambda2), fma(((sin(lambda1) * sin(lambda2)) * cos(phi1)), cos(phi2), (sin(phi2) * sin(phi1))))) * R;
}
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(acos(fma(Float64(cos(lambda1) * Float64(cos(phi2) * cos(phi1))), cos(lambda2), fma(Float64(Float64(sin(lambda1) * sin(lambda2)) * cos(phi1)), cos(phi2), Float64(sin(phi2) * sin(phi1))))) * R)
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[(N[(N[Cos[lambda1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[lambda2], $MachinePrecision] + N[(N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision] + N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}

\\
\cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_1 \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right), \cos \lambda_2, \mathsf{fma}\left(\left(\sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right) \cdot R
\end{array}
Derivation
  1. Initial program 73.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. lift-cos.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}{\cos \left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
    2. lift--.f64N/A

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \color{blue}{\left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
    3. 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 \]
    4. *-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 \]
    5. lower-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 \]
    6. lower-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 \]
    7. lower-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 \]
    8. *-commutativeN/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_2 \cdot \sin \lambda_1}\right)\right) \cdot R \]
    9. lower-*.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_2 \cdot \sin \lambda_1}\right)\right) \cdot R \]
    10. lower-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_2} \cdot \sin \lambda_1\right)\right) \cdot R \]
    11. lower-sin.f6494.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_2 \cdot \color{blue}{\sin \lambda_1}\right)\right) \cdot R \]
  4. Applied rewrites94.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_2 \cdot \sin \lambda_1\right)}\right) \cdot R \]
  5. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \cos^{-1} \color{blue}{\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_2 \cdot \sin \lambda_1\right)\right)} \cdot R \]
    2. +-commutativeN/A

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

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

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

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

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

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

Alternative 2: 94.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_2 \cdot \cos \lambda_1\right) \cdot \cos \phi_2, \cos \phi_1, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  (acos
   (fma
    (*
     (fma (sin lambda2) (sin lambda1) (* (cos lambda2) (cos lambda1)))
     (cos phi2))
    (cos phi1)
    (* (sin phi2) (sin phi1))))
  R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return acos(fma((fma(sin(lambda2), sin(lambda1), (cos(lambda2) * cos(lambda1))) * cos(phi2)), cos(phi1), (sin(phi2) * sin(phi1)))) * R;
}
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(acos(fma(Float64(fma(sin(lambda2), sin(lambda1), Float64(cos(lambda2) * cos(lambda1))) * cos(phi2)), cos(phi1), Float64(sin(phi2) * sin(phi1)))) * R)
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[(N[(N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision] + N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}

\\
\cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_2 \cdot \cos \lambda_1\right) \cdot \cos \phi_2, \cos \phi_1, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R
\end{array}
Derivation
  1. Initial program 73.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. lift-cos.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}{\cos \left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
    2. lift--.f64N/A

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \color{blue}{\left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
    3. 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 \]
    4. *-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 \]
    5. lower-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 \]
    6. lower-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 \]
    7. lower-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 \]
    8. *-commutativeN/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_2 \cdot \sin \lambda_1}\right)\right) \cdot R \]
    9. lower-*.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_2 \cdot \sin \lambda_1}\right)\right) \cdot R \]
    10. lower-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_2} \cdot \sin \lambda_1\right)\right) \cdot R \]
    11. lower-sin.f6494.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_2 \cdot \color{blue}{\sin \lambda_1}\right)\right) \cdot R \]
  4. Applied rewrites94.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_2 \cdot \sin \lambda_1\right)}\right) \cdot R \]
  5. Taylor expanded in lambda1 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. lower-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 \]
  7. Applied rewrites94.4%

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

Alternative 3: 81.5% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1\right) \cdot \cos \phi_2\right)\right) \cdot R\\ t_1 := \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_2 \cdot \cos \lambda_1\right)\\ t_2 := \cos^{-1} \left(t\_1 \cdot \cos \phi_2\right) \cdot R\\ \mathbf{if}\;\phi_2 \leq -7000000000000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_2 \leq 5.6 \cdot 10^{-33}:\\ \;\;\;\;\cos^{-1} \left(t\_1 \cdot \cos \phi_1\right) \cdot R\\ \mathbf{elif}\;\phi_2 \leq 6.5 \cdot 10^{+17}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;\phi_2 \leq 4.2 \cdot 10^{+247}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_2 \leq 2.1 \cdot 10^{+255}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;\phi_2 \leq 1.1 \cdot 10^{+301}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0
         (*
          (acos
           (fma
            (sin phi2)
            (sin phi1)
            (* (* (cos (- lambda2 lambda1)) (cos phi1)) (cos phi2))))
          R))
        (t_1 (fma (sin lambda2) (sin lambda1) (* (cos lambda2) (cos lambda1))))
        (t_2 (* (acos (* t_1 (cos phi2))) R)))
   (if (<= phi2 -7000000000000.0)
     t_0
     (if (<= phi2 5.6e-33)
       (* (acos (* t_1 (cos phi1))) R)
       (if (<= phi2 6.5e+17)
         t_2
         (if (<= phi2 4.2e+247)
           t_0
           (if (<= phi2 2.1e+255)
             t_2
             (if (<= phi2 1.1e+301) t_0 (* (acos (cos phi1)) R)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = acos(fma(sin(phi2), sin(phi1), ((cos((lambda2 - lambda1)) * cos(phi1)) * cos(phi2)))) * R;
	double t_1 = fma(sin(lambda2), sin(lambda1), (cos(lambda2) * cos(lambda1)));
	double t_2 = acos((t_1 * cos(phi2))) * R;
	double tmp;
	if (phi2 <= -7000000000000.0) {
		tmp = t_0;
	} else if (phi2 <= 5.6e-33) {
		tmp = acos((t_1 * cos(phi1))) * R;
	} else if (phi2 <= 6.5e+17) {
		tmp = t_2;
	} else if (phi2 <= 4.2e+247) {
		tmp = t_0;
	} else if (phi2 <= 2.1e+255) {
		tmp = t_2;
	} else if (phi2 <= 1.1e+301) {
		tmp = t_0;
	} else {
		tmp = acos(cos(phi1)) * R;
	}
	return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(acos(fma(sin(phi2), sin(phi1), Float64(Float64(cos(Float64(lambda2 - lambda1)) * cos(phi1)) * cos(phi2)))) * R)
	t_1 = fma(sin(lambda2), sin(lambda1), Float64(cos(lambda2) * cos(lambda1)))
	t_2 = Float64(acos(Float64(t_1 * cos(phi2))) * R)
	tmp = 0.0
	if (phi2 <= -7000000000000.0)
		tmp = t_0;
	elseif (phi2 <= 5.6e-33)
		tmp = Float64(acos(Float64(t_1 * cos(phi1))) * R);
	elseif (phi2 <= 6.5e+17)
		tmp = t_2;
	elseif (phi2 <= 4.2e+247)
		tmp = t_0;
	elseif (phi2 <= 2.1e+255)
		tmp = t_2;
	elseif (phi2 <= 1.1e+301)
		tmp = t_0;
	else
		tmp = Float64(acos(cos(phi1)) * R);
	end
	return tmp
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[(N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision] + N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[ArcCos[N[(t$95$1 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]}, If[LessEqual[phi2, -7000000000000.0], t$95$0, If[LessEqual[phi2, 5.6e-33], N[(N[ArcCos[N[(t$95$1 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi2, 6.5e+17], t$95$2, If[LessEqual[phi2, 4.2e+247], t$95$0, If[LessEqual[phi2, 2.1e+255], t$95$2, If[LessEqual[phi2, 1.1e+301], t$95$0, N[(N[ArcCos[N[Cos[phi1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1\right) \cdot \cos \phi_2\right)\right) \cdot R\\
t_1 := \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_2 \cdot \cos \lambda_1\right)\\
t_2 := \cos^{-1} \left(t\_1 \cdot \cos \phi_2\right) \cdot R\\
\mathbf{if}\;\phi_2 \leq -7000000000000:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\phi_2 \leq 5.6 \cdot 10^{-33}:\\
\;\;\;\;\cos^{-1} \left(t\_1 \cdot \cos \phi_1\right) \cdot R\\

\mathbf{elif}\;\phi_2 \leq 6.5 \cdot 10^{+17}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;\phi_2 \leq 4.2 \cdot 10^{+247}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\phi_2 \leq 2.1 \cdot 10^{+255}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;\phi_2 \leq 1.1 \cdot 10^{+301}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if phi2 < -7e12 or 6.5e17 < phi2 < 4.2e247 or 2.1e255 < phi2 < 1.1e301

    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. lift-+.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\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. lift-*.f64N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\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 \]
      3. *-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 \]
      4. lower-fma.f6477.1

        \[\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 \]
      5. lift-*.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 \cos \left(\lambda_1 - \lambda_2\right)}\right)\right) \cdot R \]
      6. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7e12 < phi2 < 5.6e-33

    1. Initial program 69.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. lift-cos.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}{\cos \left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
      2. lift--.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \color{blue}{\left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
      3. 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 \]
      4. *-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 \]
      5. lower-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 \]
      6. lower-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 \]
      7. lower-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 \]
      8. *-commutativeN/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_2 \cdot \sin \lambda_1}\right)\right) \cdot R \]
      9. lower-*.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_2 \cdot \sin \lambda_1}\right)\right) \cdot R \]
      10. lower-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_2} \cdot \sin \lambda_1\right)\right) \cdot R \]
      11. lower-sin.f6490.2

        \[\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_2 \cdot \color{blue}{\sin \lambda_1}\right)\right) \cdot R \]
    4. Applied rewrites90.2%

      \[\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_2 \cdot \sin \lambda_1\right)}\right) \cdot R \]
    5. Taylor expanded in phi2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.6e-33 < phi2 < 6.5e17 or 4.2e247 < phi2 < 2.1e255

    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. Step-by-step derivation
      1. lift-cos.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}{\cos \left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
      2. lift--.f64N/A

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \color{blue}{\left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
      3. 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 \]
      4. *-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 \]
      5. lower-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 \]
      6. lower-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 \]
      7. lower-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 \]
      8. *-commutativeN/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_2 \cdot \sin \lambda_1}\right)\right) \cdot R \]
      9. lower-*.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_2 \cdot \sin \lambda_1}\right)\right) \cdot R \]
      10. lower-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_2} \cdot \sin \lambda_1\right)\right) \cdot R \]
      11. lower-sin.f6492.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_2 \cdot \color{blue}{\sin \lambda_1}\right)\right) \cdot R \]
    4. Applied rewrites92.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_2 \cdot \sin \lambda_1\right)}\right) \cdot R \]
    5. Taylor expanded in phi1 around 0

      \[\leadsto \cos^{-1} \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 R \]
    6. Step-by-step derivation
      1. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.1e301 < phi2

    1. Initial program 66.3%

      \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
    2. Add Preprocessing
    3. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
    7. Step-by-step derivation
      1. Applied rewrites26.8%

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
      2. Step-by-step derivation
        1. Applied rewrites19.6%

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

          \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot R \]
        3. Step-by-step derivation
          1. Applied rewrites18.9%

            \[\leadsto \cos^{-1} \cos \phi_1 \cdot R \]
        4. Recombined 4 regimes into one program.
        5. Add Preprocessing

        Alternative 4: 73.3% accurate, 1.0× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos^{-1} \left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_2 \cdot \cos \lambda_1\right) \cdot \cos \phi_1\right) \cdot R\\ t_1 := \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \lambda_1 \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right)\right)\right) \cdot R\\ \mathbf{if}\;\lambda_1 \leq -1.25 \cdot 10^{-7}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\lambda_1 \leq 7.8 \cdot 10^{-26}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_2 \cdot \cos \phi_2, \cos \phi_1, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R\\ \mathbf{elif}\;\lambda_1 \leq 2.6 \cdot 10^{+40}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\lambda_1 \leq 2.2 \cdot 10^{+237}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\lambda_1 \leq 1.9 \cdot 10^{+252}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\lambda_1 \leq 2.2 \cdot 10^{+306}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\ \end{array} \end{array} \]
        (FPCore (R lambda1 lambda2 phi1 phi2)
         :precision binary64
         (let* ((t_0
                 (*
                  (acos
                   (*
                    (fma (sin lambda2) (sin lambda1) (* (cos lambda2) (cos lambda1)))
                    (cos phi1)))
                  R))
                (t_1
                 (*
                  (acos
                   (fma
                    (sin phi2)
                    (sin phi1)
                    (* (cos lambda1) (* (cos phi2) (cos phi1)))))
                  R)))
           (if (<= lambda1 -1.25e-7)
             t_1
             (if (<= lambda1 7.8e-26)
               (*
                (acos
                 (fma
                  (* (cos lambda2) (cos phi2))
                  (cos phi1)
                  (* (sin phi2) (sin phi1))))
                R)
               (if (<= lambda1 2.6e+40)
                 t_0
                 (if (<= lambda1 2.2e+237)
                   t_1
                   (if (<= lambda1 1.9e+252)
                     t_0
                     (if (<= lambda1 2.2e+306) t_1 (* (acos (cos phi1)) R)))))))))
        double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
        	double t_0 = acos((fma(sin(lambda2), sin(lambda1), (cos(lambda2) * cos(lambda1))) * cos(phi1))) * R;
        	double t_1 = acos(fma(sin(phi2), sin(phi1), (cos(lambda1) * (cos(phi2) * cos(phi1))))) * R;
        	double tmp;
        	if (lambda1 <= -1.25e-7) {
        		tmp = t_1;
        	} else if (lambda1 <= 7.8e-26) {
        		tmp = acos(fma((cos(lambda2) * cos(phi2)), cos(phi1), (sin(phi2) * sin(phi1)))) * R;
        	} else if (lambda1 <= 2.6e+40) {
        		tmp = t_0;
        	} else if (lambda1 <= 2.2e+237) {
        		tmp = t_1;
        	} else if (lambda1 <= 1.9e+252) {
        		tmp = t_0;
        	} else if (lambda1 <= 2.2e+306) {
        		tmp = t_1;
        	} else {
        		tmp = acos(cos(phi1)) * R;
        	}
        	return tmp;
        }
        
        function code(R, lambda1, lambda2, phi1, phi2)
        	t_0 = Float64(acos(Float64(fma(sin(lambda2), sin(lambda1), Float64(cos(lambda2) * cos(lambda1))) * cos(phi1))) * R)
        	t_1 = Float64(acos(fma(sin(phi2), sin(phi1), Float64(cos(lambda1) * Float64(cos(phi2) * cos(phi1))))) * R)
        	tmp = 0.0
        	if (lambda1 <= -1.25e-7)
        		tmp = t_1;
        	elseif (lambda1 <= 7.8e-26)
        		tmp = Float64(acos(fma(Float64(cos(lambda2) * cos(phi2)), cos(phi1), Float64(sin(phi2) * sin(phi1)))) * R);
        	elseif (lambda1 <= 2.6e+40)
        		tmp = t_0;
        	elseif (lambda1 <= 2.2e+237)
        		tmp = t_1;
        	elseif (lambda1 <= 1.9e+252)
        		tmp = t_0;
        	elseif (lambda1 <= 2.2e+306)
        		tmp = t_1;
        	else
        		tmp = Float64(acos(cos(phi1)) * R);
        	end
        	return tmp
        end
        
        code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[ArcCos[N[(N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision] + N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]}, Block[{t$95$1 = N[(N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]}, If[LessEqual[lambda1, -1.25e-7], t$95$1, If[LessEqual[lambda1, 7.8e-26], N[(N[ArcCos[N[(N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[lambda1, 2.6e+40], t$95$0, If[LessEqual[lambda1, 2.2e+237], t$95$1, If[LessEqual[lambda1, 1.9e+252], t$95$0, If[LessEqual[lambda1, 2.2e+306], t$95$1, N[(N[ArcCos[N[Cos[phi1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]]]]]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_0 := \cos^{-1} \left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_2 \cdot \cos \lambda_1\right) \cdot \cos \phi_1\right) \cdot R\\
        t_1 := \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \lambda_1 \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right)\right)\right) \cdot R\\
        \mathbf{if}\;\lambda_1 \leq -1.25 \cdot 10^{-7}:\\
        \;\;\;\;t\_1\\
        
        \mathbf{elif}\;\lambda_1 \leq 7.8 \cdot 10^{-26}:\\
        \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_2 \cdot \cos \phi_2, \cos \phi_1, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R\\
        
        \mathbf{elif}\;\lambda_1 \leq 2.6 \cdot 10^{+40}:\\
        \;\;\;\;t\_0\\
        
        \mathbf{elif}\;\lambda_1 \leq 2.2 \cdot 10^{+237}:\\
        \;\;\;\;t\_1\\
        
        \mathbf{elif}\;\lambda_1 \leq 1.9 \cdot 10^{+252}:\\
        \;\;\;\;t\_0\\
        
        \mathbf{elif}\;\lambda_1 \leq 2.2 \cdot 10^{+306}:\\
        \;\;\;\;t\_1\\
        
        \mathbf{else}:\\
        \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 4 regimes
        2. if lambda1 < -1.24999999999999994e-7 or 2.6000000000000001e40 < lambda1 < 2.2e237 or 1.89999999999999986e252 < lambda1 < 2.2e306

          1. Initial program 62.9%

            \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
          2. Add Preprocessing
          3. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\cos \phi_2 \cdot \cos \phi_1, \cos \lambda_1, \sin \phi_2 \cdot \sin \phi_1\right)\right)} \cdot R \]
          6. Step-by-step derivation
            1. Applied rewrites62.8%

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

            if -1.24999999999999994e-7 < lambda1 < 7.79999999999999973e-26

            1. Initial program 87.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 lambda1 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if 7.79999999999999973e-26 < lambda1 < 2.6000000000000001e40 or 2.2e237 < lambda1 < 1.89999999999999986e252

            1. Initial program 67.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. lift-cos.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}{\cos \left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
              2. lift--.f64N/A

                \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \color{blue}{\left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
              3. 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 \]
              4. *-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 \]
              5. lower-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 \]
              6. lower-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 \]
              7. lower-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 \]
              8. *-commutativeN/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_2 \cdot \sin \lambda_1}\right)\right) \cdot R \]
              9. lower-*.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_2 \cdot \sin \lambda_1}\right)\right) \cdot R \]
              10. lower-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_2} \cdot \sin \lambda_1\right)\right) \cdot R \]
              11. lower-sin.f6499.2

                \[\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_2 \cdot \color{blue}{\sin \lambda_1}\right)\right) \cdot R \]
            4. Applied rewrites99.2%

              \[\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_2 \cdot \sin \lambda_1\right)}\right) \cdot R \]
            5. Taylor expanded in phi2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if 2.2e306 < lambda1

            1. Initial program 60.0%

              \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
            2. Add Preprocessing
            3. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
            7. Step-by-step derivation
              1. Applied rewrites25.8%

                \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
              2. Step-by-step derivation
                1. Applied rewrites19.3%

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

                  \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot R \]
                3. Step-by-step derivation
                  1. Applied rewrites19.3%

                    \[\leadsto \cos^{-1} \cos \phi_1 \cdot R \]
                4. Recombined 4 regimes into one program.
                5. Add Preprocessing

                Alternative 5: 73.3% accurate, 1.0× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \lambda_1 \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right)\right)\right) \cdot R\\ \mathbf{if}\;\lambda_1 \leq -1.25 \cdot 10^{-7}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\lambda_1 \leq 7.8 \cdot 10^{-26}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_2 \cdot \cos \phi_2, \cos \phi_1, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R\\ \mathbf{elif}\;\lambda_1 \leq 2.2 \cdot 10^{+306}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\ \end{array} \end{array} \]
                (FPCore (R lambda1 lambda2 phi1 phi2)
                 :precision binary64
                 (let* ((t_0
                         (*
                          (acos
                           (fma
                            (sin phi2)
                            (sin phi1)
                            (* (cos lambda1) (* (cos phi2) (cos phi1)))))
                          R)))
                   (if (<= lambda1 -1.25e-7)
                     t_0
                     (if (<= lambda1 7.8e-26)
                       (*
                        (acos
                         (fma
                          (* (cos lambda2) (cos phi2))
                          (cos phi1)
                          (* (sin phi2) (sin phi1))))
                        R)
                       (if (<= lambda1 2.2e+306) t_0 (* (acos (cos phi1)) R))))))
                double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                	double t_0 = acos(fma(sin(phi2), sin(phi1), (cos(lambda1) * (cos(phi2) * cos(phi1))))) * R;
                	double tmp;
                	if (lambda1 <= -1.25e-7) {
                		tmp = t_0;
                	} else if (lambda1 <= 7.8e-26) {
                		tmp = acos(fma((cos(lambda2) * cos(phi2)), cos(phi1), (sin(phi2) * sin(phi1)))) * R;
                	} else if (lambda1 <= 2.2e+306) {
                		tmp = t_0;
                	} else {
                		tmp = acos(cos(phi1)) * R;
                	}
                	return tmp;
                }
                
                function code(R, lambda1, lambda2, phi1, phi2)
                	t_0 = Float64(acos(fma(sin(phi2), sin(phi1), Float64(cos(lambda1) * Float64(cos(phi2) * cos(phi1))))) * R)
                	tmp = 0.0
                	if (lambda1 <= -1.25e-7)
                		tmp = t_0;
                	elseif (lambda1 <= 7.8e-26)
                		tmp = Float64(acos(fma(Float64(cos(lambda2) * cos(phi2)), cos(phi1), Float64(sin(phi2) * sin(phi1)))) * R);
                	elseif (lambda1 <= 2.2e+306)
                		tmp = t_0;
                	else
                		tmp = Float64(acos(cos(phi1)) * R);
                	end
                	return tmp
                end
                
                code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]}, If[LessEqual[lambda1, -1.25e-7], t$95$0, If[LessEqual[lambda1, 7.8e-26], N[(N[ArcCos[N[(N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[lambda1, 2.2e+306], t$95$0, N[(N[ArcCos[N[Cos[phi1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                t_0 := \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \lambda_1 \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right)\right)\right) \cdot R\\
                \mathbf{if}\;\lambda_1 \leq -1.25 \cdot 10^{-7}:\\
                \;\;\;\;t\_0\\
                
                \mathbf{elif}\;\lambda_1 \leq 7.8 \cdot 10^{-26}:\\
                \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_2 \cdot \cos \phi_2, \cos \phi_1, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R\\
                
                \mathbf{elif}\;\lambda_1 \leq 2.2 \cdot 10^{+306}:\\
                \;\;\;\;t\_0\\
                
                \mathbf{else}:\\
                \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 3 regimes
                2. if lambda1 < -1.24999999999999994e-7 or 7.79999999999999973e-26 < lambda1 < 2.2e306

                  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 lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\cos \phi_2 \cdot \cos \phi_1, \cos \lambda_1, \sin \phi_2 \cdot \sin \phi_1\right)\right)} \cdot R \]
                  6. Step-by-step derivation
                    1. Applied rewrites62.8%

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

                    if -1.24999999999999994e-7 < lambda1 < 7.79999999999999973e-26

                    1. Initial program 87.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 lambda1 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    if 2.2e306 < lambda1

                    1. Initial program 60.0%

                      \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                    2. Add Preprocessing
                    3. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
                    7. Step-by-step derivation
                      1. Applied rewrites25.8%

                        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
                      2. Step-by-step derivation
                        1. Applied rewrites19.3%

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

                          \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot R \]
                        3. Step-by-step derivation
                          1. Applied rewrites19.3%

                            \[\leadsto \cos^{-1} \cos \phi_1 \cdot R \]
                        4. Recombined 3 regimes into one program.
                        5. Add Preprocessing

                        Alternative 6: 63.6% accurate, 1.0× speedup?

                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\lambda_2 \leq -0.00088:\\ \;\;\;\;\cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1\right) \cdot R\\ \mathbf{elif}\;\lambda_2 \leq 2 \cdot 10^{-7}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \lambda_1 \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right)\right)\right) \cdot R\\ \mathbf{elif}\;\lambda_2 \leq 1.95 \cdot 10^{+220}:\\ \;\;\;\;\cos^{-1} \left(\cos \lambda_2 \cdot \cos \phi_1\right) \cdot R\\ \mathbf{elif}\;\lambda_2 \leq 7.5 \cdot 10^{+291}:\\ \;\;\;\;\cos^{-1} \left(\cos \lambda_2 \cdot \cos \phi_2\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\ \end{array} \end{array} \]
                        (FPCore (R lambda1 lambda2 phi1 phi2)
                         :precision binary64
                         (if (<= lambda2 -0.00088)
                           (* (acos (* (cos (- lambda2 lambda1)) (cos phi1))) R)
                           (if (<= lambda2 2e-7)
                             (*
                              (acos
                               (fma (sin phi2) (sin phi1) (* (cos lambda1) (* (cos phi2) (cos phi1)))))
                              R)
                             (if (<= lambda2 1.95e+220)
                               (* (acos (* (cos lambda2) (cos phi1))) R)
                               (if (<= lambda2 7.5e+291)
                                 (* (acos (* (cos lambda2) (cos phi2))) R)
                                 (* (acos (cos phi1)) R))))))
                        double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                        	double tmp;
                        	if (lambda2 <= -0.00088) {
                        		tmp = acos((cos((lambda2 - lambda1)) * cos(phi1))) * R;
                        	} else if (lambda2 <= 2e-7) {
                        		tmp = acos(fma(sin(phi2), sin(phi1), (cos(lambda1) * (cos(phi2) * cos(phi1))))) * R;
                        	} else if (lambda2 <= 1.95e+220) {
                        		tmp = acos((cos(lambda2) * cos(phi1))) * R;
                        	} else if (lambda2 <= 7.5e+291) {
                        		tmp = acos((cos(lambda2) * cos(phi2))) * R;
                        	} else {
                        		tmp = acos(cos(phi1)) * R;
                        	}
                        	return tmp;
                        }
                        
                        function code(R, lambda1, lambda2, phi1, phi2)
                        	tmp = 0.0
                        	if (lambda2 <= -0.00088)
                        		tmp = Float64(acos(Float64(cos(Float64(lambda2 - lambda1)) * cos(phi1))) * R);
                        	elseif (lambda2 <= 2e-7)
                        		tmp = Float64(acos(fma(sin(phi2), sin(phi1), Float64(cos(lambda1) * Float64(cos(phi2) * cos(phi1))))) * R);
                        	elseif (lambda2 <= 1.95e+220)
                        		tmp = Float64(acos(Float64(cos(lambda2) * cos(phi1))) * R);
                        	elseif (lambda2 <= 7.5e+291)
                        		tmp = Float64(acos(Float64(cos(lambda2) * cos(phi2))) * R);
                        	else
                        		tmp = Float64(acos(cos(phi1)) * R);
                        	end
                        	return tmp
                        end
                        
                        code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda2, -0.00088], N[(N[ArcCos[N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[lambda2, 2e-7], N[(N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[lambda2, 1.95e+220], N[(N[ArcCos[N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[lambda2, 7.5e+291], N[(N[ArcCos[N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[Cos[phi1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]]]
                        
                        \begin{array}{l}
                        
                        \\
                        \begin{array}{l}
                        \mathbf{if}\;\lambda_2 \leq -0.00088:\\
                        \;\;\;\;\cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1\right) \cdot R\\
                        
                        \mathbf{elif}\;\lambda_2 \leq 2 \cdot 10^{-7}:\\
                        \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \lambda_1 \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right)\right)\right) \cdot R\\
                        
                        \mathbf{elif}\;\lambda_2 \leq 1.95 \cdot 10^{+220}:\\
                        \;\;\;\;\cos^{-1} \left(\cos \lambda_2 \cdot \cos \phi_1\right) \cdot R\\
                        
                        \mathbf{elif}\;\lambda_2 \leq 7.5 \cdot 10^{+291}:\\
                        \;\;\;\;\cos^{-1} \left(\cos \lambda_2 \cdot \cos \phi_2\right) \cdot R\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 5 regimes
                        2. if lambda2 < -8.80000000000000031e-4

                          1. Initial program 50.9%

                            \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                          2. Add Preprocessing
                          3. Taylor expanded in 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. lower-*.f64N/A

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

                              \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
                            4. *-lft-identityN/A

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

                              \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
                            6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                              \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
                            14. fp-cancel-sign-sub-invN/A

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

                              \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_1\right) \cdot R \]
                            16. *-lft-identityN/A

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

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

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

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

                          if -8.80000000000000031e-4 < lambda2 < 1.9999999999999999e-7

                          1. Initial program 89.1%

                            \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                          2. Add Preprocessing
                          3. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

                            \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(\cos \phi_2 \cdot \cos \phi_1, \cos \lambda_1, \sin \phi_2 \cdot \sin \phi_1\right)\right)} \cdot R \]
                          6. Step-by-step derivation
                            1. Applied rewrites89.1%

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

                            if 1.9999999999999999e-7 < lambda2 < 1.95000000000000008e220

                            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. lower-*.f64N/A

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

                                \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
                              4. *-lft-identityN/A

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

                                \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
                              6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
                              14. fp-cancel-sign-sub-invN/A

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

                                \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_1\right) \cdot R \]
                              16. *-lft-identityN/A

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

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

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

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

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

                              if 1.95000000000000008e220 < lambda2 < 7.5000000000000001e291

                              1. Initial program 57.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. lift-cos.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}{\cos \left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
                                2. lift--.f64N/A

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

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

                                  \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\frac{\left(\sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2\right) - \left(\cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2\right)}{\sin \lambda_1 \cdot \sin \lambda_2 - \cos \lambda_1 \cdot \cos \lambda_2}}\right) \cdot R \]
                                6. lower-/.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}{\frac{\left(\sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2\right) - \left(\cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2\right)}{\sin \lambda_1 \cdot \sin \lambda_2 - \cos \lambda_1 \cdot \cos \lambda_2}}\right) \cdot R \]
                              4. Applied rewrites99.4%

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

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

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

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

                                \[\leadsto \cos^{-1} \left(\cos \lambda_2 \cdot \color{blue}{\cos \phi_2}\right) \cdot R \]
                              9. Step-by-step derivation
                                1. Applied rewrites34.8%

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

                                if 7.5000000000000001e291 < lambda2

                                1. Initial program 44.0%

                                  \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                2. Add Preprocessing
                                3. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                  \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
                                7. Step-by-step derivation
                                  1. Applied rewrites9.4%

                                    \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
                                  2. Step-by-step derivation
                                    1. Applied rewrites9.4%

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

                                      \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot R \]
                                    3. Step-by-step derivation
                                      1. Applied rewrites3.2%

                                        \[\leadsto \cos^{-1} \cos \phi_1 \cdot R \]
                                    4. Recombined 5 regimes into one program.
                                    5. Add Preprocessing

                                    Alternative 7: 53.5% accurate, 1.5× speedup?

                                    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\lambda_2 - \lambda_1\right)\\ t_1 := t\_0 \cdot \cos \phi_2\\ \mathbf{if}\;\phi_1 \leq -15.5:\\ \;\;\;\;\cos^{-1} \left(t\_0 \cdot \cos \phi_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq -2 \cdot 10^{-70}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \phi_1, t\_1\right)\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq 0.0155:\\ \;\;\;\;\cos^{-1} t\_1 \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\ \end{array} \end{array} \]
                                    (FPCore (R lambda1 lambda2 phi1 phi2)
                                     :precision binary64
                                     (let* ((t_0 (cos (- lambda2 lambda1))) (t_1 (* t_0 (cos phi2))))
                                       (if (<= phi1 -15.5)
                                         (* (acos (* t_0 (cos phi1))) R)
                                         (if (<= phi1 -2e-70)
                                           (* (acos (fma (sin phi2) phi1 t_1)) R)
                                           (if (<= phi1 0.0155) (* (acos t_1) R) (* (acos (cos phi1)) R))))))
                                    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                    	double t_0 = cos((lambda2 - lambda1));
                                    	double t_1 = t_0 * cos(phi2);
                                    	double tmp;
                                    	if (phi1 <= -15.5) {
                                    		tmp = acos((t_0 * cos(phi1))) * R;
                                    	} else if (phi1 <= -2e-70) {
                                    		tmp = acos(fma(sin(phi2), phi1, t_1)) * R;
                                    	} else if (phi1 <= 0.0155) {
                                    		tmp = acos(t_1) * R;
                                    	} else {
                                    		tmp = acos(cos(phi1)) * R;
                                    	}
                                    	return tmp;
                                    }
                                    
                                    function code(R, lambda1, lambda2, phi1, phi2)
                                    	t_0 = cos(Float64(lambda2 - lambda1))
                                    	t_1 = Float64(t_0 * cos(phi2))
                                    	tmp = 0.0
                                    	if (phi1 <= -15.5)
                                    		tmp = Float64(acos(Float64(t_0 * cos(phi1))) * R);
                                    	elseif (phi1 <= -2e-70)
                                    		tmp = Float64(acos(fma(sin(phi2), phi1, t_1)) * R);
                                    	elseif (phi1 <= 0.0155)
                                    		tmp = Float64(acos(t_1) * R);
                                    	else
                                    		tmp = Float64(acos(cos(phi1)) * R);
                                    	end
                                    	return tmp
                                    end
                                    
                                    code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -15.5], N[(N[ArcCos[N[(t$95$0 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi1, -2e-70], N[(N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * phi1 + t$95$1), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi1, 0.0155], N[(N[ArcCos[t$95$1], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[Cos[phi1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]]]]
                                    
                                    \begin{array}{l}
                                    
                                    \\
                                    \begin{array}{l}
                                    t_0 := \cos \left(\lambda_2 - \lambda_1\right)\\
                                    t_1 := t\_0 \cdot \cos \phi_2\\
                                    \mathbf{if}\;\phi_1 \leq -15.5:\\
                                    \;\;\;\;\cos^{-1} \left(t\_0 \cdot \cos \phi_1\right) \cdot R\\
                                    
                                    \mathbf{elif}\;\phi_1 \leq -2 \cdot 10^{-70}:\\
                                    \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \phi_1, t\_1\right)\right) \cdot R\\
                                    
                                    \mathbf{elif}\;\phi_1 \leq 0.0155:\\
                                    \;\;\;\;\cos^{-1} t\_1 \cdot R\\
                                    
                                    \mathbf{else}:\\
                                    \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\
                                    
                                    
                                    \end{array}
                                    \end{array}
                                    
                                    Derivation
                                    1. Split input into 4 regimes
                                    2. if phi1 < -15.5

                                      1. Initial program 84.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. lower-*.f64N/A

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

                                          \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
                                        4. *-lft-identityN/A

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

                                          \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
                                        6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                          \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
                                        14. fp-cancel-sign-sub-invN/A

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

                                          \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_1\right) \cdot R \]
                                        16. *-lft-identityN/A

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

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

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

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

                                      if -15.5 < phi1 < -1.99999999999999999e-70

                                      1. Initial program 58.6%

                                        \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                      2. Add Preprocessing
                                      3. Taylor expanded in phi1 around 0

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

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

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

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

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

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

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

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

                                          \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \phi_1, \cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_2\right)\right) \cdot R \]
                                        9. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                          \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \phi_1, \cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_2\right)\right) \cdot R \]
                                        17. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

                                      if -1.99999999999999999e-70 < phi1 < 0.0155

                                      1. Initial program 67.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. *-commutativeN/A

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

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

                                          \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_2\right) \cdot R \]
                                        4. *-lft-identityN/A

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

                                          \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_2\right) \cdot R \]
                                        6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                          \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_2\right) \cdot R \]
                                        14. fp-cancel-sign-sub-invN/A

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

                                          \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_2\right) \cdot R \]
                                        16. *-lft-identityN/A

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

                                          \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot \cos \phi_2\right) \cdot R \]
                                        18. lower-cos.f6467.7

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

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

                                      if 0.0155 < phi1

                                      1. Initial program 74.5%

                                        \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                      2. Add Preprocessing
                                      3. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
                                      7. Step-by-step derivation
                                        1. Applied rewrites27.9%

                                          \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
                                        2. Step-by-step derivation
                                          1. Applied rewrites22.3%

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

                                            \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot R \]
                                          3. Step-by-step derivation
                                            1. Applied rewrites22.2%

                                              \[\leadsto \cos^{-1} \cos \phi_1 \cdot R \]
                                          4. Recombined 4 regimes into one program.
                                          5. Add Preprocessing

                                          Alternative 8: 48.6% accurate, 1.5× speedup?

                                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\lambda_1 - \lambda_2\right) \leq 0.99998:\\ \;\;\;\;\cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \cos \left(\phi_2 - \phi_1\right) \cdot R\\ \end{array} \end{array} \]
                                          (FPCore (R lambda1 lambda2 phi1 phi2)
                                           :precision binary64
                                           (if (<= (cos (- lambda1 lambda2)) 0.99998)
                                             (* (acos (* (cos (- lambda2 lambda1)) (cos phi1))) R)
                                             (* (acos (cos (- phi2 phi1))) R)))
                                          double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                          	double tmp;
                                          	if (cos((lambda1 - lambda2)) <= 0.99998) {
                                          		tmp = acos((cos((lambda2 - lambda1)) * cos(phi1))) * R;
                                          	} else {
                                          		tmp = acos(cos((phi2 - phi1))) * R;
                                          	}
                                          	return tmp;
                                          }
                                          
                                          real(8) function code(r, lambda1, lambda2, phi1, phi2)
                                              real(8), intent (in) :: r
                                              real(8), intent (in) :: lambda1
                                              real(8), intent (in) :: lambda2
                                              real(8), intent (in) :: phi1
                                              real(8), intent (in) :: phi2
                                              real(8) :: tmp
                                              if (cos((lambda1 - lambda2)) <= 0.99998d0) then
                                                  tmp = acos((cos((lambda2 - lambda1)) * cos(phi1))) * r
                                              else
                                                  tmp = acos(cos((phi2 - phi1))) * r
                                              end if
                                              code = tmp
                                          end function
                                          
                                          public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                          	double tmp;
                                          	if (Math.cos((lambda1 - lambda2)) <= 0.99998) {
                                          		tmp = Math.acos((Math.cos((lambda2 - lambda1)) * Math.cos(phi1))) * R;
                                          	} else {
                                          		tmp = Math.acos(Math.cos((phi2 - phi1))) * R;
                                          	}
                                          	return tmp;
                                          }
                                          
                                          def code(R, lambda1, lambda2, phi1, phi2):
                                          	tmp = 0
                                          	if math.cos((lambda1 - lambda2)) <= 0.99998:
                                          		tmp = math.acos((math.cos((lambda2 - lambda1)) * math.cos(phi1))) * R
                                          	else:
                                          		tmp = math.acos(math.cos((phi2 - phi1))) * R
                                          	return tmp
                                          
                                          function code(R, lambda1, lambda2, phi1, phi2)
                                          	tmp = 0.0
                                          	if (cos(Float64(lambda1 - lambda2)) <= 0.99998)
                                          		tmp = Float64(acos(Float64(cos(Float64(lambda2 - lambda1)) * cos(phi1))) * R);
                                          	else
                                          		tmp = Float64(acos(cos(Float64(phi2 - phi1))) * R);
                                          	end
                                          	return tmp
                                          end
                                          
                                          function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
                                          	tmp = 0.0;
                                          	if (cos((lambda1 - lambda2)) <= 0.99998)
                                          		tmp = acos((cos((lambda2 - lambda1)) * cos(phi1))) * R;
                                          	else
                                          		tmp = acos(cos((phi2 - phi1))) * R;
                                          	end
                                          	tmp_2 = tmp;
                                          end
                                          
                                          code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision], 0.99998], N[(N[ArcCos[N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[Cos[N[(phi2 - phi1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]
                                          
                                          \begin{array}{l}
                                          
                                          \\
                                          \begin{array}{l}
                                          \mathbf{if}\;\cos \left(\lambda_1 - \lambda_2\right) \leq 0.99998:\\
                                          \;\;\;\;\cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1\right) \cdot R\\
                                          
                                          \mathbf{else}:\\
                                          \;\;\;\;\cos^{-1} \cos \left(\phi_2 - \phi_1\right) \cdot R\\
                                          
                                          
                                          \end{array}
                                          \end{array}
                                          
                                          Derivation
                                          1. Split input into 2 regimes
                                          2. if (cos.f64 (-.f64 lambda1 lambda2)) < 0.99997999999999998

                                            1. Initial program 72.1%

                                              \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                            2. Add Preprocessing
                                            3. Taylor expanded in phi2 around 0

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

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

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

                                                \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
                                              4. *-lft-identityN/A

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

                                                \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
                                              6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                                \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
                                              14. fp-cancel-sign-sub-invN/A

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

                                                \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_1\right) \cdot R \]
                                              16. *-lft-identityN/A

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

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

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

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

                                            if 0.99997999999999998 < (cos.f64 (-.f64 lambda1 lambda2))

                                            1. Initial program 76.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 lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                              \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
                                            7. Step-by-step derivation
                                              1. Applied rewrites73.4%

                                                \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
                                              2. Step-by-step derivation
                                                1. Applied rewrites51.3%

                                                  \[\leadsto \color{blue}{\cos^{-1} \cos \left(\phi_2 - \phi_1\right) \cdot R} \]
                                              3. Recombined 2 regimes into one program.
                                              4. Add Preprocessing

                                              Alternative 9: 39.2% accurate, 1.7× speedup?

                                              \[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(-0.5, \phi_1 \cdot \phi_1, 1\right)\\ t_1 := \cos^{-1} \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot R\\ t_2 := \cos^{-1} \left(t\_0 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{if}\;\phi_1 \leq -32500:\\ \;\;\;\;\cos^{-1} \left(\cos \lambda_2 \cdot \cos \phi_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq -8 \cdot 10^{-47}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\phi_1 \leq -3.3 \cdot 10^{-63}:\\ \;\;\;\;\cos^{-1} \left(t\_0 \cdot \cos \lambda_2\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq -1.9 \cdot 10^{-283}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\phi_1 \leq 7.2 \cdot 10^{-308}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;\phi_1 \leq 2.35 \cdot 10^{-263}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\phi_1 \leq 3.6 \cdot 10^{-239}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;\phi_1 \leq 2.1 \cdot 10^{-16}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\ \end{array} \end{array} \]
                                              (FPCore (R lambda1 lambda2 phi1 phi2)
                                               :precision binary64
                                               (let* ((t_0 (fma -0.5 (* phi1 phi1) 1.0))
                                                      (t_1 (* (acos (* (cos lambda1) (cos phi2))) R))
                                                      (t_2 (* (acos (* t_0 (cos (- lambda1 lambda2)))) R)))
                                                 (if (<= phi1 -32500.0)
                                                   (* (acos (* (cos lambda2) (cos phi1))) R)
                                                   (if (<= phi1 -8e-47)
                                                     t_1
                                                     (if (<= phi1 -3.3e-63)
                                                       (* (acos (* t_0 (cos lambda2))) R)
                                                       (if (<= phi1 -1.9e-283)
                                                         t_1
                                                         (if (<= phi1 7.2e-308)
                                                           t_2
                                                           (if (<= phi1 2.35e-263)
                                                             t_1
                                                             (if (<= phi1 3.6e-239)
                                                               t_2
                                                               (if (<= phi1 2.1e-16) t_1 (* (acos (cos phi1)) R)))))))))))
                                              double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                              	double t_0 = fma(-0.5, (phi1 * phi1), 1.0);
                                              	double t_1 = acos((cos(lambda1) * cos(phi2))) * R;
                                              	double t_2 = acos((t_0 * cos((lambda1 - lambda2)))) * R;
                                              	double tmp;
                                              	if (phi1 <= -32500.0) {
                                              		tmp = acos((cos(lambda2) * cos(phi1))) * R;
                                              	} else if (phi1 <= -8e-47) {
                                              		tmp = t_1;
                                              	} else if (phi1 <= -3.3e-63) {
                                              		tmp = acos((t_0 * cos(lambda2))) * R;
                                              	} else if (phi1 <= -1.9e-283) {
                                              		tmp = t_1;
                                              	} else if (phi1 <= 7.2e-308) {
                                              		tmp = t_2;
                                              	} else if (phi1 <= 2.35e-263) {
                                              		tmp = t_1;
                                              	} else if (phi1 <= 3.6e-239) {
                                              		tmp = t_2;
                                              	} else if (phi1 <= 2.1e-16) {
                                              		tmp = t_1;
                                              	} else {
                                              		tmp = acos(cos(phi1)) * R;
                                              	}
                                              	return tmp;
                                              }
                                              
                                              function code(R, lambda1, lambda2, phi1, phi2)
                                              	t_0 = fma(-0.5, Float64(phi1 * phi1), 1.0)
                                              	t_1 = Float64(acos(Float64(cos(lambda1) * cos(phi2))) * R)
                                              	t_2 = Float64(acos(Float64(t_0 * cos(Float64(lambda1 - lambda2)))) * R)
                                              	tmp = 0.0
                                              	if (phi1 <= -32500.0)
                                              		tmp = Float64(acos(Float64(cos(lambda2) * cos(phi1))) * R);
                                              	elseif (phi1 <= -8e-47)
                                              		tmp = t_1;
                                              	elseif (phi1 <= -3.3e-63)
                                              		tmp = Float64(acos(Float64(t_0 * cos(lambda2))) * R);
                                              	elseif (phi1 <= -1.9e-283)
                                              		tmp = t_1;
                                              	elseif (phi1 <= 7.2e-308)
                                              		tmp = t_2;
                                              	elseif (phi1 <= 2.35e-263)
                                              		tmp = t_1;
                                              	elseif (phi1 <= 3.6e-239)
                                              		tmp = t_2;
                                              	elseif (phi1 <= 2.1e-16)
                                              		tmp = t_1;
                                              	else
                                              		tmp = Float64(acos(cos(phi1)) * R);
                                              	end
                                              	return tmp
                                              end
                                              
                                              code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(-0.5 * N[(phi1 * phi1), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[ArcCos[N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]}, Block[{t$95$2 = N[(N[ArcCos[N[(t$95$0 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]}, If[LessEqual[phi1, -32500.0], N[(N[ArcCos[N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi1, -8e-47], t$95$1, If[LessEqual[phi1, -3.3e-63], N[(N[ArcCos[N[(t$95$0 * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi1, -1.9e-283], t$95$1, If[LessEqual[phi1, 7.2e-308], t$95$2, If[LessEqual[phi1, 2.35e-263], t$95$1, If[LessEqual[phi1, 3.6e-239], t$95$2, If[LessEqual[phi1, 2.1e-16], t$95$1, N[(N[ArcCos[N[Cos[phi1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]]]]]]]]]]
                                              
                                              \begin{array}{l}
                                              
                                              \\
                                              \begin{array}{l}
                                              t_0 := \mathsf{fma}\left(-0.5, \phi_1 \cdot \phi_1, 1\right)\\
                                              t_1 := \cos^{-1} \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot R\\
                                              t_2 := \cos^{-1} \left(t\_0 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
                                              \mathbf{if}\;\phi_1 \leq -32500:\\
                                              \;\;\;\;\cos^{-1} \left(\cos \lambda_2 \cdot \cos \phi_1\right) \cdot R\\
                                              
                                              \mathbf{elif}\;\phi_1 \leq -8 \cdot 10^{-47}:\\
                                              \;\;\;\;t\_1\\
                                              
                                              \mathbf{elif}\;\phi_1 \leq -3.3 \cdot 10^{-63}:\\
                                              \;\;\;\;\cos^{-1} \left(t\_0 \cdot \cos \lambda_2\right) \cdot R\\
                                              
                                              \mathbf{elif}\;\phi_1 \leq -1.9 \cdot 10^{-283}:\\
                                              \;\;\;\;t\_1\\
                                              
                                              \mathbf{elif}\;\phi_1 \leq 7.2 \cdot 10^{-308}:\\
                                              \;\;\;\;t\_2\\
                                              
                                              \mathbf{elif}\;\phi_1 \leq 2.35 \cdot 10^{-263}:\\
                                              \;\;\;\;t\_1\\
                                              
                                              \mathbf{elif}\;\phi_1 \leq 3.6 \cdot 10^{-239}:\\
                                              \;\;\;\;t\_2\\
                                              
                                              \mathbf{elif}\;\phi_1 \leq 2.1 \cdot 10^{-16}:\\
                                              \;\;\;\;t\_1\\
                                              
                                              \mathbf{else}:\\
                                              \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\
                                              
                                              
                                              \end{array}
                                              \end{array}
                                              
                                              Derivation
                                              1. Split input into 5 regimes
                                              2. if phi1 < -32500

                                                1. Initial program 84.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. lower-*.f64N/A

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

                                                    \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                  4. *-lft-identityN/A

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

                                                    \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
                                                  6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                                    \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                  14. fp-cancel-sign-sub-invN/A

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

                                                    \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_1\right) \cdot R \]
                                                  16. *-lft-identityN/A

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

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

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

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

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

                                                  if -32500 < phi1 < -7.9999999999999998e-47 or -3.29999999999999994e-63 < phi1 < -1.9000000000000001e-283 or 7.1999999999999997e-308 < phi1 < 2.34999999999999985e-263 or 3.6000000000000001e-239 < phi1 < 2.1000000000000001e-16

                                                  1. Initial program 65.9%

                                                    \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                                  2. Add Preprocessing
                                                  3. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                    \[\leadsto \cos^{-1} \left(\cos \lambda_1 \cdot \color{blue}{\cos \phi_2}\right) \cdot R \]
                                                  7. Step-by-step derivation
                                                    1. Applied rewrites49.8%

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

                                                    if -7.9999999999999998e-47 < phi1 < -3.29999999999999994e-63

                                                    1. Initial program 51.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. lower-*.f64N/A

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

                                                        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                      4. *-lft-identityN/A

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

                                                        \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
                                                      6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                                        \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                      14. fp-cancel-sign-sub-invN/A

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

                                                        \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_1\right) \cdot R \]
                                                      16. *-lft-identityN/A

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

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

                                                        \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \color{blue}{\cos \phi_1}\right) \cdot R \]
                                                    5. Applied rewrites36.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 phi1 around 0

                                                      \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) + \color{blue}{\frac{-1}{2} \cdot \left({\phi_1}^{2} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}\right) \cdot R \]
                                                    7. Step-by-step derivation
                                                      1. Applied rewrites36.4%

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

                                                        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\frac{-1}{2}, \phi_1 \cdot \phi_1, 1\right) \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) \cdot R \]
                                                      3. Step-by-step derivation
                                                        1. Applied rewrites36.2%

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

                                                        if -1.9000000000000001e-283 < phi1 < 7.1999999999999997e-308 or 2.34999999999999985e-263 < phi1 < 3.6000000000000001e-239

                                                        1. Initial program 72.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. lower-*.f64N/A

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

                                                            \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                          4. *-lft-identityN/A

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

                                                            \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
                                                          6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                                            \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                          14. fp-cancel-sign-sub-invN/A

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

                                                            \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_1\right) \cdot R \]
                                                          16. *-lft-identityN/A

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

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

                                                            \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \color{blue}{\cos \phi_1}\right) \cdot R \]
                                                        5. Applied rewrites54.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 phi1 around 0

                                                          \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) + \color{blue}{\frac{-1}{2} \cdot \left({\phi_1}^{2} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}\right) \cdot R \]
                                                        7. Step-by-step derivation
                                                          1. Applied rewrites54.1%

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

                                                          if 2.1000000000000001e-16 < phi1

                                                          1. Initial program 75.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 lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                            \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
                                                          7. Step-by-step derivation
                                                            1. Applied rewrites27.4%

                                                              \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
                                                            2. Step-by-step derivation
                                                              1. Applied rewrites22.0%

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

                                                                \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot R \]
                                                              3. Step-by-step derivation
                                                                1. Applied rewrites21.7%

                                                                  \[\leadsto \cos^{-1} \cos \phi_1 \cdot R \]
                                                              4. Recombined 5 regimes into one program.
                                                              5. Add Preprocessing

                                                              Alternative 10: 40.1% accurate, 1.8× speedup?

                                                              \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos^{-1} \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot R\\ \mathbf{if}\;\phi_1 \leq -15.5:\\ \;\;\;\;\cos^{-1} \left(\cos \lambda_1 \cdot \cos \phi_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq -1.9 \cdot 10^{-283}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_1 \leq 7.2 \cdot 10^{-308}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(-0.5, \phi_1 \cdot \phi_1, 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq 2.35 \cdot 10^{-263}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_1 \leq 9.5 \cdot 10^{-216}:\\ \;\;\;\;\cos^{-1} \left(\cos \lambda_2 \cdot \cos \phi_2\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq 0.0155:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\ \end{array} \end{array} \]
                                                              (FPCore (R lambda1 lambda2 phi1 phi2)
                                                               :precision binary64
                                                               (let* ((t_0 (* (acos (* (cos lambda1) (cos phi2))) R)))
                                                                 (if (<= phi1 -15.5)
                                                                   (* (acos (* (cos lambda1) (cos phi1))) R)
                                                                   (if (<= phi1 -1.9e-283)
                                                                     t_0
                                                                     (if (<= phi1 7.2e-308)
                                                                       (*
                                                                        (acos (* (fma -0.5 (* phi1 phi1) 1.0) (cos (- lambda1 lambda2))))
                                                                        R)
                                                                       (if (<= phi1 2.35e-263)
                                                                         t_0
                                                                         (if (<= phi1 9.5e-216)
                                                                           (* (acos (* (cos lambda2) (cos phi2))) R)
                                                                           (if (<= phi1 0.0155) t_0 (* (acos (cos phi1)) R)))))))))
                                                              double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                                              	double t_0 = acos((cos(lambda1) * cos(phi2))) * R;
                                                              	double tmp;
                                                              	if (phi1 <= -15.5) {
                                                              		tmp = acos((cos(lambda1) * cos(phi1))) * R;
                                                              	} else if (phi1 <= -1.9e-283) {
                                                              		tmp = t_0;
                                                              	} else if (phi1 <= 7.2e-308) {
                                                              		tmp = acos((fma(-0.5, (phi1 * phi1), 1.0) * cos((lambda1 - lambda2)))) * R;
                                                              	} else if (phi1 <= 2.35e-263) {
                                                              		tmp = t_0;
                                                              	} else if (phi1 <= 9.5e-216) {
                                                              		tmp = acos((cos(lambda2) * cos(phi2))) * R;
                                                              	} else if (phi1 <= 0.0155) {
                                                              		tmp = t_0;
                                                              	} else {
                                                              		tmp = acos(cos(phi1)) * R;
                                                              	}
                                                              	return tmp;
                                                              }
                                                              
                                                              function code(R, lambda1, lambda2, phi1, phi2)
                                                              	t_0 = Float64(acos(Float64(cos(lambda1) * cos(phi2))) * R)
                                                              	tmp = 0.0
                                                              	if (phi1 <= -15.5)
                                                              		tmp = Float64(acos(Float64(cos(lambda1) * cos(phi1))) * R);
                                                              	elseif (phi1 <= -1.9e-283)
                                                              		tmp = t_0;
                                                              	elseif (phi1 <= 7.2e-308)
                                                              		tmp = Float64(acos(Float64(fma(-0.5, Float64(phi1 * phi1), 1.0) * cos(Float64(lambda1 - lambda2)))) * R);
                                                              	elseif (phi1 <= 2.35e-263)
                                                              		tmp = t_0;
                                                              	elseif (phi1 <= 9.5e-216)
                                                              		tmp = Float64(acos(Float64(cos(lambda2) * cos(phi2))) * R);
                                                              	elseif (phi1 <= 0.0155)
                                                              		tmp = t_0;
                                                              	else
                                                              		tmp = Float64(acos(cos(phi1)) * R);
                                                              	end
                                                              	return tmp
                                                              end
                                                              
                                                              code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[ArcCos[N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]}, If[LessEqual[phi1, -15.5], N[(N[ArcCos[N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi1, -1.9e-283], t$95$0, If[LessEqual[phi1, 7.2e-308], N[(N[ArcCos[N[(N[(-0.5 * N[(phi1 * phi1), $MachinePrecision] + 1.0), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi1, 2.35e-263], t$95$0, If[LessEqual[phi1, 9.5e-216], N[(N[ArcCos[N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi1, 0.0155], t$95$0, N[(N[ArcCos[N[Cos[phi1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]]]]]]
                                                              
                                                              \begin{array}{l}
                                                              
                                                              \\
                                                              \begin{array}{l}
                                                              t_0 := \cos^{-1} \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot R\\
                                                              \mathbf{if}\;\phi_1 \leq -15.5:\\
                                                              \;\;\;\;\cos^{-1} \left(\cos \lambda_1 \cdot \cos \phi_1\right) \cdot R\\
                                                              
                                                              \mathbf{elif}\;\phi_1 \leq -1.9 \cdot 10^{-283}:\\
                                                              \;\;\;\;t\_0\\
                                                              
                                                              \mathbf{elif}\;\phi_1 \leq 7.2 \cdot 10^{-308}:\\
                                                              \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(-0.5, \phi_1 \cdot \phi_1, 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
                                                              
                                                              \mathbf{elif}\;\phi_1 \leq 2.35 \cdot 10^{-263}:\\
                                                              \;\;\;\;t\_0\\
                                                              
                                                              \mathbf{elif}\;\phi_1 \leq 9.5 \cdot 10^{-216}:\\
                                                              \;\;\;\;\cos^{-1} \left(\cos \lambda_2 \cdot \cos \phi_2\right) \cdot R\\
                                                              
                                                              \mathbf{elif}\;\phi_1 \leq 0.0155:\\
                                                              \;\;\;\;t\_0\\
                                                              
                                                              \mathbf{else}:\\
                                                              \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\
                                                              
                                                              
                                                              \end{array}
                                                              \end{array}
                                                              
                                                              Derivation
                                                              1. Split input into 5 regimes
                                                              2. if phi1 < -15.5

                                                                1. Initial program 84.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. lower-*.f64N/A

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

                                                                    \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                  4. *-lft-identityN/A

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

                                                                    \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                  6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                                                    \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                  14. fp-cancel-sign-sub-invN/A

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

                                                                    \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                  16. *-lft-identityN/A

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

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

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

                                                                  \[\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} \left(\cos \left(\mathsf{neg}\left(\lambda_1\right)\right) \cdot \cos \color{blue}{\phi_1}\right) \cdot R \]
                                                                7. Step-by-step derivation
                                                                  1. Applied rewrites41.7%

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

                                                                  if -15.5 < phi1 < -1.9000000000000001e-283 or 7.1999999999999997e-308 < phi1 < 2.34999999999999985e-263 or 9.49999999999999943e-216 < phi1 < 0.0155

                                                                  1. Initial program 64.9%

                                                                    \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                                                  2. Add Preprocessing
                                                                  3. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                    \[\leadsto \cos^{-1} \left(\cos \lambda_1 \cdot \color{blue}{\cos \phi_2}\right) \cdot R \]
                                                                  7. Step-by-step derivation
                                                                    1. Applied rewrites49.3%

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

                                                                    if -1.9000000000000001e-283 < phi1 < 7.1999999999999997e-308

                                                                    1. Initial program 83.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. lower-*.f64N/A

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

                                                                        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                      4. *-lft-identityN/A

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

                                                                        \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                      6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                                                        \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                      14. fp-cancel-sign-sub-invN/A

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

                                                                        \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                      16. *-lft-identityN/A

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

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

                                                                        \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \color{blue}{\cos \phi_1}\right) \cdot R \]
                                                                    5. Applied rewrites68.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 phi1 around 0

                                                                      \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) + \color{blue}{\frac{-1}{2} \cdot \left({\phi_1}^{2} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}\right) \cdot R \]
                                                                    7. Step-by-step derivation
                                                                      1. Applied rewrites68.6%

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

                                                                      if 2.34999999999999985e-263 < phi1 < 9.49999999999999943e-216

                                                                      1. Initial program 74.5%

                                                                        \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                                                      2. Add Preprocessing
                                                                      3. Step-by-step derivation
                                                                        1. lift-cos.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}{\cos \left(\lambda_1 - \lambda_2\right)}\right) \cdot R \]
                                                                        2. lift--.f64N/A

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

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

                                                                          \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\frac{\left(\sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2\right) - \left(\cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2\right)}{\sin \lambda_1 \cdot \sin \lambda_2 - \cos \lambda_1 \cdot \cos \lambda_2}}\right) \cdot R \]
                                                                        6. lower-/.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}{\frac{\left(\sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2\right) - \left(\cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2\right)}{\sin \lambda_1 \cdot \sin \lambda_2 - \cos \lambda_1 \cdot \cos \lambda_2}}\right) \cdot R \]
                                                                      4. Applied rewrites99.3%

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

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

                                                                          \[\leadsto \cos^{-1} \color{blue}{\left(\frac{\cos \phi_2 \cdot \left({\sin \lambda_1}^{2} \cdot {\sin \lambda_2}^{2} - {\cos \lambda_1}^{2} \cdot {\cos \lambda_2}^{2}\right)}{\sin \lambda_1 \cdot \sin \lambda_2 - \cos \lambda_1 \cdot \cos \lambda_2}\right)} \cdot R \]
                                                                      7. Applied rewrites99.3%

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

                                                                        \[\leadsto \cos^{-1} \left(\cos \lambda_2 \cdot \color{blue}{\cos \phi_2}\right) \cdot R \]
                                                                      9. Step-by-step derivation
                                                                        1. Applied rewrites53.0%

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

                                                                        if 0.0155 < phi1

                                                                        1. Initial program 74.5%

                                                                          \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                                                        2. Add Preprocessing
                                                                        3. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                          \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
                                                                        7. Step-by-step derivation
                                                                          1. Applied rewrites27.9%

                                                                            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
                                                                          2. Step-by-step derivation
                                                                            1. Applied rewrites22.3%

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

                                                                              \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot R \]
                                                                            3. Step-by-step derivation
                                                                              1. Applied rewrites22.2%

                                                                                \[\leadsto \cos^{-1} \cos \phi_1 \cdot R \]
                                                                            4. Recombined 5 regimes into one program.
                                                                            5. Add Preprocessing

                                                                            Alternative 11: 39.4% accurate, 1.8× speedup?

                                                                            \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos^{-1} \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot R\\ t_1 := \cos^{-1} \left(\mathsf{fma}\left(-0.5, \phi_1 \cdot \phi_1, 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{if}\;\phi_1 \leq -15.5:\\ \;\;\;\;\cos^{-1} \left(\cos \lambda_1 \cdot \cos \phi_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq -1.9 \cdot 10^{-283}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_1 \leq 7.2 \cdot 10^{-308}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\phi_1 \leq 2.35 \cdot 10^{-263}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_1 \leq 3.6 \cdot 10^{-239}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\phi_1 \leq 2.1 \cdot 10^{-16}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\ \end{array} \end{array} \]
                                                                            (FPCore (R lambda1 lambda2 phi1 phi2)
                                                                             :precision binary64
                                                                             (let* ((t_0 (* (acos (* (cos lambda1) (cos phi2))) R))
                                                                                    (t_1
                                                                                     (*
                                                                                      (acos (* (fma -0.5 (* phi1 phi1) 1.0) (cos (- lambda1 lambda2))))
                                                                                      R)))
                                                                               (if (<= phi1 -15.5)
                                                                                 (* (acos (* (cos lambda1) (cos phi1))) R)
                                                                                 (if (<= phi1 -1.9e-283)
                                                                                   t_0
                                                                                   (if (<= phi1 7.2e-308)
                                                                                     t_1
                                                                                     (if (<= phi1 2.35e-263)
                                                                                       t_0
                                                                                       (if (<= phi1 3.6e-239)
                                                                                         t_1
                                                                                         (if (<= phi1 2.1e-16) t_0 (* (acos (cos phi1)) R)))))))))
                                                                            double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                                                            	double t_0 = acos((cos(lambda1) * cos(phi2))) * R;
                                                                            	double t_1 = acos((fma(-0.5, (phi1 * phi1), 1.0) * cos((lambda1 - lambda2)))) * R;
                                                                            	double tmp;
                                                                            	if (phi1 <= -15.5) {
                                                                            		tmp = acos((cos(lambda1) * cos(phi1))) * R;
                                                                            	} else if (phi1 <= -1.9e-283) {
                                                                            		tmp = t_0;
                                                                            	} else if (phi1 <= 7.2e-308) {
                                                                            		tmp = t_1;
                                                                            	} else if (phi1 <= 2.35e-263) {
                                                                            		tmp = t_0;
                                                                            	} else if (phi1 <= 3.6e-239) {
                                                                            		tmp = t_1;
                                                                            	} else if (phi1 <= 2.1e-16) {
                                                                            		tmp = t_0;
                                                                            	} else {
                                                                            		tmp = acos(cos(phi1)) * R;
                                                                            	}
                                                                            	return tmp;
                                                                            }
                                                                            
                                                                            function code(R, lambda1, lambda2, phi1, phi2)
                                                                            	t_0 = Float64(acos(Float64(cos(lambda1) * cos(phi2))) * R)
                                                                            	t_1 = Float64(acos(Float64(fma(-0.5, Float64(phi1 * phi1), 1.0) * cos(Float64(lambda1 - lambda2)))) * R)
                                                                            	tmp = 0.0
                                                                            	if (phi1 <= -15.5)
                                                                            		tmp = Float64(acos(Float64(cos(lambda1) * cos(phi1))) * R);
                                                                            	elseif (phi1 <= -1.9e-283)
                                                                            		tmp = t_0;
                                                                            	elseif (phi1 <= 7.2e-308)
                                                                            		tmp = t_1;
                                                                            	elseif (phi1 <= 2.35e-263)
                                                                            		tmp = t_0;
                                                                            	elseif (phi1 <= 3.6e-239)
                                                                            		tmp = t_1;
                                                                            	elseif (phi1 <= 2.1e-16)
                                                                            		tmp = t_0;
                                                                            	else
                                                                            		tmp = Float64(acos(cos(phi1)) * R);
                                                                            	end
                                                                            	return tmp
                                                                            end
                                                                            
                                                                            code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[ArcCos[N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]}, Block[{t$95$1 = N[(N[ArcCos[N[(N[(-0.5 * N[(phi1 * phi1), $MachinePrecision] + 1.0), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]}, If[LessEqual[phi1, -15.5], N[(N[ArcCos[N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi1, -1.9e-283], t$95$0, If[LessEqual[phi1, 7.2e-308], t$95$1, If[LessEqual[phi1, 2.35e-263], t$95$0, If[LessEqual[phi1, 3.6e-239], t$95$1, If[LessEqual[phi1, 2.1e-16], t$95$0, N[(N[ArcCos[N[Cos[phi1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]]]]]]]
                                                                            
                                                                            \begin{array}{l}
                                                                            
                                                                            \\
                                                                            \begin{array}{l}
                                                                            t_0 := \cos^{-1} \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot R\\
                                                                            t_1 := \cos^{-1} \left(\mathsf{fma}\left(-0.5, \phi_1 \cdot \phi_1, 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
                                                                            \mathbf{if}\;\phi_1 \leq -15.5:\\
                                                                            \;\;\;\;\cos^{-1} \left(\cos \lambda_1 \cdot \cos \phi_1\right) \cdot R\\
                                                                            
                                                                            \mathbf{elif}\;\phi_1 \leq -1.9 \cdot 10^{-283}:\\
                                                                            \;\;\;\;t\_0\\
                                                                            
                                                                            \mathbf{elif}\;\phi_1 \leq 7.2 \cdot 10^{-308}:\\
                                                                            \;\;\;\;t\_1\\
                                                                            
                                                                            \mathbf{elif}\;\phi_1 \leq 2.35 \cdot 10^{-263}:\\
                                                                            \;\;\;\;t\_0\\
                                                                            
                                                                            \mathbf{elif}\;\phi_1 \leq 3.6 \cdot 10^{-239}:\\
                                                                            \;\;\;\;t\_1\\
                                                                            
                                                                            \mathbf{elif}\;\phi_1 \leq 2.1 \cdot 10^{-16}:\\
                                                                            \;\;\;\;t\_0\\
                                                                            
                                                                            \mathbf{else}:\\
                                                                            \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\
                                                                            
                                                                            
                                                                            \end{array}
                                                                            \end{array}
                                                                            
                                                                            Derivation
                                                                            1. Split input into 4 regimes
                                                                            2. if phi1 < -15.5

                                                                              1. Initial program 84.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. lower-*.f64N/A

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

                                                                                  \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                                4. *-lft-identityN/A

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

                                                                                  \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                                6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                                                                  \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                                14. fp-cancel-sign-sub-invN/A

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

                                                                                  \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                                16. *-lft-identityN/A

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

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

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

                                                                                \[\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} \left(\cos \left(\mathsf{neg}\left(\lambda_1\right)\right) \cdot \cos \color{blue}{\phi_1}\right) \cdot R \]
                                                                              7. Step-by-step derivation
                                                                                1. Applied rewrites41.7%

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

                                                                                if -15.5 < phi1 < -1.9000000000000001e-283 or 7.1999999999999997e-308 < phi1 < 2.34999999999999985e-263 or 3.6000000000000001e-239 < phi1 < 2.1000000000000001e-16

                                                                                1. Initial program 65.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 lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                                  \[\leadsto \cos^{-1} \left(\cos \lambda_1 \cdot \color{blue}{\cos \phi_2}\right) \cdot R \]
                                                                                7. Step-by-step derivation
                                                                                  1. Applied rewrites48.3%

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

                                                                                  if -1.9000000000000001e-283 < phi1 < 7.1999999999999997e-308 or 2.34999999999999985e-263 < phi1 < 3.6000000000000001e-239

                                                                                  1. Initial program 72.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. lower-*.f64N/A

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

                                                                                      \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                                    4. *-lft-identityN/A

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

                                                                                      \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                                    6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                                                                      \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                                    14. fp-cancel-sign-sub-invN/A

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

                                                                                      \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                                    16. *-lft-identityN/A

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

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

                                                                                      \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \color{blue}{\cos \phi_1}\right) \cdot R \]
                                                                                  5. Applied rewrites54.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 phi1 around 0

                                                                                    \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) + \color{blue}{\frac{-1}{2} \cdot \left({\phi_1}^{2} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}\right) \cdot R \]
                                                                                  7. Step-by-step derivation
                                                                                    1. Applied rewrites54.1%

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

                                                                                    if 2.1000000000000001e-16 < phi1

                                                                                    1. Initial program 75.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 lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                                      \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
                                                                                    7. Step-by-step derivation
                                                                                      1. Applied rewrites27.4%

                                                                                        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
                                                                                      2. Step-by-step derivation
                                                                                        1. Applied rewrites22.0%

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

                                                                                          \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot R \]
                                                                                        3. Step-by-step derivation
                                                                                          1. Applied rewrites21.7%

                                                                                            \[\leadsto \cos^{-1} \cos \phi_1 \cdot R \]
                                                                                        4. Recombined 4 regimes into one program.
                                                                                        5. Add Preprocessing

                                                                                        Alternative 12: 52.5% accurate, 1.9× speedup?

                                                                                        \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\lambda_2 - \lambda_1\right)\\ \mathbf{if}\;\phi_1 \leq -15.5:\\ \;\;\;\;\cos^{-1} \left(t\_0 \cdot \cos \phi_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq 1.55 \cdot 10^{-27}:\\ \;\;\;\;\cos^{-1} \left(t\_0 \cdot \cos \phi_2\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\ \end{array} \end{array} \]
                                                                                        (FPCore (R lambda1 lambda2 phi1 phi2)
                                                                                         :precision binary64
                                                                                         (let* ((t_0 (cos (- lambda2 lambda1))))
                                                                                           (if (<= phi1 -15.5)
                                                                                             (* (acos (* t_0 (cos phi1))) R)
                                                                                             (if (<= phi1 1.55e-27)
                                                                                               (* (acos (* t_0 (cos phi2))) R)
                                                                                               (* (acos (cos phi1)) R)))))
                                                                                        double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                                                                        	double t_0 = cos((lambda2 - lambda1));
                                                                                        	double tmp;
                                                                                        	if (phi1 <= -15.5) {
                                                                                        		tmp = acos((t_0 * cos(phi1))) * R;
                                                                                        	} else if (phi1 <= 1.55e-27) {
                                                                                        		tmp = acos((t_0 * cos(phi2))) * R;
                                                                                        	} else {
                                                                                        		tmp = acos(cos(phi1)) * R;
                                                                                        	}
                                                                                        	return tmp;
                                                                                        }
                                                                                        
                                                                                        real(8) function code(r, lambda1, lambda2, phi1, phi2)
                                                                                            real(8), intent (in) :: r
                                                                                            real(8), intent (in) :: lambda1
                                                                                            real(8), intent (in) :: lambda2
                                                                                            real(8), intent (in) :: phi1
                                                                                            real(8), intent (in) :: phi2
                                                                                            real(8) :: t_0
                                                                                            real(8) :: tmp
                                                                                            t_0 = cos((lambda2 - lambda1))
                                                                                            if (phi1 <= (-15.5d0)) then
                                                                                                tmp = acos((t_0 * cos(phi1))) * r
                                                                                            else if (phi1 <= 1.55d-27) then
                                                                                                tmp = acos((t_0 * cos(phi2))) * r
                                                                                            else
                                                                                                tmp = acos(cos(phi1)) * r
                                                                                            end if
                                                                                            code = tmp
                                                                                        end function
                                                                                        
                                                                                        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 <= -15.5) {
                                                                                        		tmp = Math.acos((t_0 * Math.cos(phi1))) * R;
                                                                                        	} else if (phi1 <= 1.55e-27) {
                                                                                        		tmp = Math.acos((t_0 * Math.cos(phi2))) * R;
                                                                                        	} else {
                                                                                        		tmp = Math.acos(Math.cos(phi1)) * R;
                                                                                        	}
                                                                                        	return tmp;
                                                                                        }
                                                                                        
                                                                                        def code(R, lambda1, lambda2, phi1, phi2):
                                                                                        	t_0 = math.cos((lambda2 - lambda1))
                                                                                        	tmp = 0
                                                                                        	if phi1 <= -15.5:
                                                                                        		tmp = math.acos((t_0 * math.cos(phi1))) * R
                                                                                        	elif phi1 <= 1.55e-27:
                                                                                        		tmp = math.acos((t_0 * math.cos(phi2))) * R
                                                                                        	else:
                                                                                        		tmp = math.acos(math.cos(phi1)) * R
                                                                                        	return tmp
                                                                                        
                                                                                        function code(R, lambda1, lambda2, phi1, phi2)
                                                                                        	t_0 = cos(Float64(lambda2 - lambda1))
                                                                                        	tmp = 0.0
                                                                                        	if (phi1 <= -15.5)
                                                                                        		tmp = Float64(acos(Float64(t_0 * cos(phi1))) * R);
                                                                                        	elseif (phi1 <= 1.55e-27)
                                                                                        		tmp = Float64(acos(Float64(t_0 * cos(phi2))) * R);
                                                                                        	else
                                                                                        		tmp = Float64(acos(cos(phi1)) * R);
                                                                                        	end
                                                                                        	return tmp
                                                                                        end
                                                                                        
                                                                                        function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
                                                                                        	t_0 = cos((lambda2 - lambda1));
                                                                                        	tmp = 0.0;
                                                                                        	if (phi1 <= -15.5)
                                                                                        		tmp = acos((t_0 * cos(phi1))) * R;
                                                                                        	elseif (phi1 <= 1.55e-27)
                                                                                        		tmp = acos((t_0 * cos(phi2))) * R;
                                                                                        	else
                                                                                        		tmp = acos(cos(phi1)) * R;
                                                                                        	end
                                                                                        	tmp_2 = tmp;
                                                                                        end
                                                                                        
                                                                                        code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi1, -15.5], N[(N[ArcCos[N[(t$95$0 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi1, 1.55e-27], N[(N[ArcCos[N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[Cos[phi1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]]
                                                                                        
                                                                                        \begin{array}{l}
                                                                                        
                                                                                        \\
                                                                                        \begin{array}{l}
                                                                                        t_0 := \cos \left(\lambda_2 - \lambda_1\right)\\
                                                                                        \mathbf{if}\;\phi_1 \leq -15.5:\\
                                                                                        \;\;\;\;\cos^{-1} \left(t\_0 \cdot \cos \phi_1\right) \cdot R\\
                                                                                        
                                                                                        \mathbf{elif}\;\phi_1 \leq 1.55 \cdot 10^{-27}:\\
                                                                                        \;\;\;\;\cos^{-1} \left(t\_0 \cdot \cos \phi_2\right) \cdot R\\
                                                                                        
                                                                                        \mathbf{else}:\\
                                                                                        \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\
                                                                                        
                                                                                        
                                                                                        \end{array}
                                                                                        \end{array}
                                                                                        
                                                                                        Derivation
                                                                                        1. Split input into 3 regimes
                                                                                        2. if phi1 < -15.5

                                                                                          1. Initial program 84.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. lower-*.f64N/A

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

                                                                                              \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                                            4. *-lft-identityN/A

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

                                                                                              \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                                            6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                                                                              \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                                            14. fp-cancel-sign-sub-invN/A

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

                                                                                              \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                                            16. *-lft-identityN/A

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

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

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

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

                                                                                          if -15.5 < phi1 < 1.5499999999999999e-27

                                                                                          1. Initial program 65.4%

                                                                                            \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                                                                          2. Add Preprocessing
                                                                                          3. Taylor expanded in phi1 around 0

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

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

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

                                                                                              \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_2\right) \cdot R \]
                                                                                            4. *-lft-identityN/A

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

                                                                                              \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_2\right) \cdot R \]
                                                                                            6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                                                                              \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_2\right) \cdot R \]
                                                                                            14. fp-cancel-sign-sub-invN/A

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

                                                                                              \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_2\right) \cdot R \]
                                                                                            16. *-lft-identityN/A

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

                                                                                              \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 - \lambda_1\right)} \cdot \cos \phi_2\right) \cdot R \]
                                                                                            18. lower-cos.f6465.2

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

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

                                                                                          if 1.5499999999999999e-27 < phi1

                                                                                          1. Initial program 75.9%

                                                                                            \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                                                                          2. Add Preprocessing
                                                                                          3. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                                            \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
                                                                                          7. Step-by-step derivation
                                                                                            1. Applied rewrites26.7%

                                                                                              \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
                                                                                            2. Step-by-step derivation
                                                                                              1. Applied rewrites21.5%

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

                                                                                                \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot R \]
                                                                                              3. Step-by-step derivation
                                                                                                1. Applied rewrites21.1%

                                                                                                  \[\leadsto \cos^{-1} \cos \phi_1 \cdot R \]
                                                                                              4. Recombined 3 regimes into one program.
                                                                                              5. Add Preprocessing

                                                                                              Alternative 13: 33.1% accurate, 2.0× speedup?

                                                                                              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -32500:\\ \;\;\;\;\cos^{-1} \left(\cos \lambda_2 \cdot \cos \phi_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq 2.6 \cdot 10^{-127}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(-0.5, \phi_1 \cdot \phi_1, 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\ \end{array} \end{array} \]
                                                                                              (FPCore (R lambda1 lambda2 phi1 phi2)
                                                                                               :precision binary64
                                                                                               (if (<= phi1 -32500.0)
                                                                                                 (* (acos (* (cos lambda2) (cos phi1))) R)
                                                                                                 (if (<= phi1 2.6e-127)
                                                                                                   (* (acos (* (fma -0.5 (* phi1 phi1) 1.0) (cos (- lambda1 lambda2)))) R)
                                                                                                   (* (acos (cos phi1)) R))))
                                                                                              double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                                                                              	double tmp;
                                                                                              	if (phi1 <= -32500.0) {
                                                                                              		tmp = acos((cos(lambda2) * cos(phi1))) * R;
                                                                                              	} else if (phi1 <= 2.6e-127) {
                                                                                              		tmp = acos((fma(-0.5, (phi1 * phi1), 1.0) * cos((lambda1 - lambda2)))) * R;
                                                                                              	} else {
                                                                                              		tmp = acos(cos(phi1)) * R;
                                                                                              	}
                                                                                              	return tmp;
                                                                                              }
                                                                                              
                                                                                              function code(R, lambda1, lambda2, phi1, phi2)
                                                                                              	tmp = 0.0
                                                                                              	if (phi1 <= -32500.0)
                                                                                              		tmp = Float64(acos(Float64(cos(lambda2) * cos(phi1))) * R);
                                                                                              	elseif (phi1 <= 2.6e-127)
                                                                                              		tmp = Float64(acos(Float64(fma(-0.5, Float64(phi1 * phi1), 1.0) * cos(Float64(lambda1 - lambda2)))) * R);
                                                                                              	else
                                                                                              		tmp = Float64(acos(cos(phi1)) * R);
                                                                                              	end
                                                                                              	return tmp
                                                                                              end
                                                                                              
                                                                                              code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -32500.0], N[(N[ArcCos[N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi1, 2.6e-127], N[(N[ArcCos[N[(N[(-0.5 * N[(phi1 * phi1), $MachinePrecision] + 1.0), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[Cos[phi1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]
                                                                                              
                                                                                              \begin{array}{l}
                                                                                              
                                                                                              \\
                                                                                              \begin{array}{l}
                                                                                              \mathbf{if}\;\phi_1 \leq -32500:\\
                                                                                              \;\;\;\;\cos^{-1} \left(\cos \lambda_2 \cdot \cos \phi_1\right) \cdot R\\
                                                                                              
                                                                                              \mathbf{elif}\;\phi_1 \leq 2.6 \cdot 10^{-127}:\\
                                                                                              \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(-0.5, \phi_1 \cdot \phi_1, 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
                                                                                              
                                                                                              \mathbf{else}:\\
                                                                                              \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\
                                                                                              
                                                                                              
                                                                                              \end{array}
                                                                                              \end{array}
                                                                                              
                                                                                              Derivation
                                                                                              1. Split input into 3 regimes
                                                                                              2. if phi1 < -32500

                                                                                                1. Initial program 84.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. lower-*.f64N/A

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

                                                                                                    \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                                                  4. *-lft-identityN/A

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

                                                                                                    \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                                                  6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                                                                                    \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                                                  14. fp-cancel-sign-sub-invN/A

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

                                                                                                    \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                                                  16. *-lft-identityN/A

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

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

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

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

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

                                                                                                  if -32500 < phi1 < 2.59999999999999991e-127

                                                                                                  1. Initial program 66.6%

                                                                                                    \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                                                                                  2. Add Preprocessing
                                                                                                  3. Taylor expanded in 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. lower-*.f64N/A

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

                                                                                                      \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                                                    4. *-lft-identityN/A

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

                                                                                                      \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                                                    6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                                                                                      \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                                                    14. fp-cancel-sign-sub-invN/A

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

                                                                                                      \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                                                    16. *-lft-identityN/A

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

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

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

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

                                                                                                    \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) + \color{blue}{\frac{-1}{2} \cdot \left({\phi_1}^{2} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}\right) \cdot R \]
                                                                                                  7. Step-by-step derivation
                                                                                                    1. Applied rewrites38.5%

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

                                                                                                    if 2.59999999999999991e-127 < phi1

                                                                                                    1. Initial program 72.1%

                                                                                                      \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                                                                                    2. Add Preprocessing
                                                                                                    3. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                                                      \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
                                                                                                    7. Step-by-step derivation
                                                                                                      1. Applied rewrites25.6%

                                                                                                        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
                                                                                                      2. Step-by-step derivation
                                                                                                        1. Applied rewrites21.6%

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

                                                                                                          \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot R \]
                                                                                                        3. Step-by-step derivation
                                                                                                          1. Applied rewrites17.6%

                                                                                                            \[\leadsto \cos^{-1} \cos \phi_1 \cdot R \]
                                                                                                        4. Recombined 3 regimes into one program.
                                                                                                        5. Add Preprocessing

                                                                                                        Alternative 14: 24.8% accurate, 2.6× speedup?

                                                                                                        \[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(-0.5, \phi_1 \cdot \phi_1, 1\right)\\ t_1 := \cos^{-1} \cos \phi_1 \cdot R\\ \mathbf{if}\;\phi_1 \leq -0.54:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\phi_1 \leq 6.2 \cdot 10^{-284}:\\ \;\;\;\;\cos^{-1} \left(t\_0 \cdot \cos \lambda_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq 4.6 \cdot 10^{-235}:\\ \;\;\;\;\cos^{-1} \left(t\_0 \cdot \cos \lambda_2\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq 1.05 \cdot 10^{-114}:\\ \;\;\;\;\cos^{-1} \cos \phi_2 \cdot R\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
                                                                                                        (FPCore (R lambda1 lambda2 phi1 phi2)
                                                                                                         :precision binary64
                                                                                                         (let* ((t_0 (fma -0.5 (* phi1 phi1) 1.0)) (t_1 (* (acos (cos phi1)) R)))
                                                                                                           (if (<= phi1 -0.54)
                                                                                                             t_1
                                                                                                             (if (<= phi1 6.2e-284)
                                                                                                               (* (acos (* t_0 (cos lambda1))) R)
                                                                                                               (if (<= phi1 4.6e-235)
                                                                                                                 (* (acos (* t_0 (cos lambda2))) R)
                                                                                                                 (if (<= phi1 1.05e-114) (* (acos (cos phi2)) R) t_1))))))
                                                                                                        double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                                                                                        	double t_0 = fma(-0.5, (phi1 * phi1), 1.0);
                                                                                                        	double t_1 = acos(cos(phi1)) * R;
                                                                                                        	double tmp;
                                                                                                        	if (phi1 <= -0.54) {
                                                                                                        		tmp = t_1;
                                                                                                        	} else if (phi1 <= 6.2e-284) {
                                                                                                        		tmp = acos((t_0 * cos(lambda1))) * R;
                                                                                                        	} else if (phi1 <= 4.6e-235) {
                                                                                                        		tmp = acos((t_0 * cos(lambda2))) * R;
                                                                                                        	} else if (phi1 <= 1.05e-114) {
                                                                                                        		tmp = acos(cos(phi2)) * R;
                                                                                                        	} else {
                                                                                                        		tmp = t_1;
                                                                                                        	}
                                                                                                        	return tmp;
                                                                                                        }
                                                                                                        
                                                                                                        function code(R, lambda1, lambda2, phi1, phi2)
                                                                                                        	t_0 = fma(-0.5, Float64(phi1 * phi1), 1.0)
                                                                                                        	t_1 = Float64(acos(cos(phi1)) * R)
                                                                                                        	tmp = 0.0
                                                                                                        	if (phi1 <= -0.54)
                                                                                                        		tmp = t_1;
                                                                                                        	elseif (phi1 <= 6.2e-284)
                                                                                                        		tmp = Float64(acos(Float64(t_0 * cos(lambda1))) * R);
                                                                                                        	elseif (phi1 <= 4.6e-235)
                                                                                                        		tmp = Float64(acos(Float64(t_0 * cos(lambda2))) * R);
                                                                                                        	elseif (phi1 <= 1.05e-114)
                                                                                                        		tmp = Float64(acos(cos(phi2)) * R);
                                                                                                        	else
                                                                                                        		tmp = t_1;
                                                                                                        	end
                                                                                                        	return tmp
                                                                                                        end
                                                                                                        
                                                                                                        code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(-0.5 * N[(phi1 * phi1), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[ArcCos[N[Cos[phi1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]}, If[LessEqual[phi1, -0.54], t$95$1, If[LessEqual[phi1, 6.2e-284], N[(N[ArcCos[N[(t$95$0 * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi1, 4.6e-235], N[(N[ArcCos[N[(t$95$0 * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi1, 1.05e-114], N[(N[ArcCos[N[Cos[phi2], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], t$95$1]]]]]]
                                                                                                        
                                                                                                        \begin{array}{l}
                                                                                                        
                                                                                                        \\
                                                                                                        \begin{array}{l}
                                                                                                        t_0 := \mathsf{fma}\left(-0.5, \phi_1 \cdot \phi_1, 1\right)\\
                                                                                                        t_1 := \cos^{-1} \cos \phi_1 \cdot R\\
                                                                                                        \mathbf{if}\;\phi_1 \leq -0.54:\\
                                                                                                        \;\;\;\;t\_1\\
                                                                                                        
                                                                                                        \mathbf{elif}\;\phi_1 \leq 6.2 \cdot 10^{-284}:\\
                                                                                                        \;\;\;\;\cos^{-1} \left(t\_0 \cdot \cos \lambda_1\right) \cdot R\\
                                                                                                        
                                                                                                        \mathbf{elif}\;\phi_1 \leq 4.6 \cdot 10^{-235}:\\
                                                                                                        \;\;\;\;\cos^{-1} \left(t\_0 \cdot \cos \lambda_2\right) \cdot R\\
                                                                                                        
                                                                                                        \mathbf{elif}\;\phi_1 \leq 1.05 \cdot 10^{-114}:\\
                                                                                                        \;\;\;\;\cos^{-1} \cos \phi_2 \cdot R\\
                                                                                                        
                                                                                                        \mathbf{else}:\\
                                                                                                        \;\;\;\;t\_1\\
                                                                                                        
                                                                                                        
                                                                                                        \end{array}
                                                                                                        \end{array}
                                                                                                        
                                                                                                        Derivation
                                                                                                        1. Split input into 4 regimes
                                                                                                        2. if phi1 < -0.54000000000000004 or 1.04999999999999996e-114 < phi1

                                                                                                          1. Initial program 76.5%

                                                                                                            \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                                                                                          2. Add Preprocessing
                                                                                                          3. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                                                            \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
                                                                                                          7. Step-by-step derivation
                                                                                                            1. Applied rewrites32.5%

                                                                                                              \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
                                                                                                            2. Step-by-step derivation
                                                                                                              1. Applied rewrites24.0%

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

                                                                                                                \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot R \]
                                                                                                              3. Step-by-step derivation
                                                                                                                1. Applied rewrites22.2%

                                                                                                                  \[\leadsto \cos^{-1} \cos \phi_1 \cdot R \]

                                                                                                                if -0.54000000000000004 < phi1 < 6.1999999999999996e-284

                                                                                                                1. Initial program 69.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. lower-*.f64N/A

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

                                                                                                                    \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                                                                  4. *-lft-identityN/A

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

                                                                                                                    \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                                                                  6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                                                                                                    \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                                                                  14. fp-cancel-sign-sub-invN/A

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

                                                                                                                    \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                                                                  16. *-lft-identityN/A

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

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

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

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

                                                                                                                  \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) + \color{blue}{\frac{-1}{2} \cdot \left({\phi_1}^{2} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}\right) \cdot R \]
                                                                                                                7. Step-by-step derivation
                                                                                                                  1. Applied rewrites39.9%

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

                                                                                                                    \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\frac{-1}{2}, \phi_1 \cdot \phi_1, 1\right) \cdot \cos \lambda_1\right) \cdot R \]
                                                                                                                  3. Step-by-step derivation
                                                                                                                    1. Applied rewrites31.7%

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

                                                                                                                    if 6.1999999999999996e-284 < phi1 < 4.59999999999999995e-235

                                                                                                                    1. Initial program 61.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. lower-*.f64N/A

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

                                                                                                                        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                                                                      4. *-lft-identityN/A

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

                                                                                                                        \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                                                                      6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                                                                                                        \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                                                                      14. fp-cancel-sign-sub-invN/A

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

                                                                                                                        \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                                                                      16. *-lft-identityN/A

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

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

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

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

                                                                                                                      \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) + \color{blue}{\frac{-1}{2} \cdot \left({\phi_1}^{2} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}\right) \cdot R \]
                                                                                                                    7. Step-by-step derivation
                                                                                                                      1. Applied rewrites43.9%

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

                                                                                                                        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\frac{-1}{2}, \phi_1 \cdot \phi_1, 1\right) \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) \cdot R \]
                                                                                                                      3. Step-by-step derivation
                                                                                                                        1. Applied rewrites23.9%

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

                                                                                                                        if 4.59999999999999995e-235 < phi1 < 1.04999999999999996e-114

                                                                                                                        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 lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                                                                          \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
                                                                                                                        7. Step-by-step derivation
                                                                                                                          1. Applied rewrites26.9%

                                                                                                                            \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
                                                                                                                          2. Step-by-step derivation
                                                                                                                            1. Applied rewrites26.9%

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

                                                                                                                              \[\leadsto \cos^{-1} \cos \phi_2 \cdot R \]
                                                                                                                            3. Step-by-step derivation
                                                                                                                              1. Applied rewrites26.9%

                                                                                                                                \[\leadsto \cos^{-1} \cos \phi_2 \cdot R \]
                                                                                                                            4. Recombined 4 regimes into one program.
                                                                                                                            5. Add Preprocessing

                                                                                                                            Alternative 15: 30.4% accurate, 2.6× speedup?

                                                                                                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -32500 \lor \neg \left(\phi_1 \leq 1.32 \cdot 10^{-129}\right):\\ \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(-0.5, \phi_1 \cdot \phi_1, 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \end{array} \end{array} \]
                                                                                                                            (FPCore (R lambda1 lambda2 phi1 phi2)
                                                                                                                             :precision binary64
                                                                                                                             (if (or (<= phi1 -32500.0) (not (<= phi1 1.32e-129)))
                                                                                                                               (* (acos (cos phi1)) R)
                                                                                                                               (* (acos (* (fma -0.5 (* phi1 phi1) 1.0) (cos (- lambda1 lambda2)))) R)))
                                                                                                                            double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                                                                                                            	double tmp;
                                                                                                                            	if ((phi1 <= -32500.0) || !(phi1 <= 1.32e-129)) {
                                                                                                                            		tmp = acos(cos(phi1)) * R;
                                                                                                                            	} else {
                                                                                                                            		tmp = acos((fma(-0.5, (phi1 * phi1), 1.0) * cos((lambda1 - lambda2)))) * R;
                                                                                                                            	}
                                                                                                                            	return tmp;
                                                                                                                            }
                                                                                                                            
                                                                                                                            function code(R, lambda1, lambda2, phi1, phi2)
                                                                                                                            	tmp = 0.0
                                                                                                                            	if ((phi1 <= -32500.0) || !(phi1 <= 1.32e-129))
                                                                                                                            		tmp = Float64(acos(cos(phi1)) * R);
                                                                                                                            	else
                                                                                                                            		tmp = Float64(acos(Float64(fma(-0.5, Float64(phi1 * phi1), 1.0) * cos(Float64(lambda1 - lambda2)))) * R);
                                                                                                                            	end
                                                                                                                            	return tmp
                                                                                                                            end
                                                                                                                            
                                                                                                                            code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[Or[LessEqual[phi1, -32500.0], N[Not[LessEqual[phi1, 1.32e-129]], $MachinePrecision]], N[(N[ArcCos[N[Cos[phi1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[(N[(-0.5 * N[(phi1 * phi1), $MachinePrecision] + 1.0), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]
                                                                                                                            
                                                                                                                            \begin{array}{l}
                                                                                                                            
                                                                                                                            \\
                                                                                                                            \begin{array}{l}
                                                                                                                            \mathbf{if}\;\phi_1 \leq -32500 \lor \neg \left(\phi_1 \leq 1.32 \cdot 10^{-129}\right):\\
                                                                                                                            \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\
                                                                                                                            
                                                                                                                            \mathbf{else}:\\
                                                                                                                            \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(-0.5, \phi_1 \cdot \phi_1, 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
                                                                                                                            
                                                                                                                            
                                                                                                                            \end{array}
                                                                                                                            \end{array}
                                                                                                                            
                                                                                                                            Derivation
                                                                                                                            1. Split input into 2 regimes
                                                                                                                            2. if phi1 < -32500 or 1.31999999999999992e-129 < phi1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                                                                                \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
                                                                                                                              7. Step-by-step derivation
                                                                                                                                1. Applied rewrites32.8%

                                                                                                                                  \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
                                                                                                                                2. Step-by-step derivation
                                                                                                                                  1. Applied rewrites24.3%

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

                                                                                                                                    \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot R \]
                                                                                                                                  3. Step-by-step derivation
                                                                                                                                    1. Applied rewrites22.0%

                                                                                                                                      \[\leadsto \cos^{-1} \cos \phi_1 \cdot R \]

                                                                                                                                    if -32500 < phi1 < 1.31999999999999992e-129

                                                                                                                                    1. Initial program 66.6%

                                                                                                                                      \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                                                                                                                    2. Add Preprocessing
                                                                                                                                    3. Taylor expanded in 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. lower-*.f64N/A

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

                                                                                                                                        \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                                                                                      4. *-lft-identityN/A

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

                                                                                                                                        \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                                                                                      6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                                                                                                                        \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                                                                                      14. fp-cancel-sign-sub-invN/A

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

                                                                                                                                        \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                                                                                      16. *-lft-identityN/A

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

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

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

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

                                                                                                                                      \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) + \color{blue}{\frac{-1}{2} \cdot \left({\phi_1}^{2} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}\right) \cdot R \]
                                                                                                                                    7. Step-by-step derivation
                                                                                                                                      1. Applied rewrites38.5%

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

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

                                                                                                                                    Alternative 16: 25.8% accurate, 2.7× speedup?

                                                                                                                                    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos^{-1} \cos \phi_1 \cdot R\\ \mathbf{if}\;\phi_1 \leq -0.54:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_1 \leq 3.15 \cdot 10^{-217}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(-0.5, \phi_1 \cdot \phi_1, 1\right) \cdot \cos \lambda_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-36}:\\ \;\;\;\;\cos^{-1} \cos \phi_2 \cdot R\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
                                                                                                                                    (FPCore (R lambda1 lambda2 phi1 phi2)
                                                                                                                                     :precision binary64
                                                                                                                                     (let* ((t_0 (* (acos (cos phi1)) R)))
                                                                                                                                       (if (<= phi1 -0.54)
                                                                                                                                         t_0
                                                                                                                                         (if (<= phi1 3.15e-217)
                                                                                                                                           (* (acos (* (fma -0.5 (* phi1 phi1) 1.0) (cos lambda1))) R)
                                                                                                                                           (if (<= phi1 3.4e-36) (* (acos (cos phi2)) R) t_0)))))
                                                                                                                                    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                                                                                                                    	double t_0 = acos(cos(phi1)) * R;
                                                                                                                                    	double tmp;
                                                                                                                                    	if (phi1 <= -0.54) {
                                                                                                                                    		tmp = t_0;
                                                                                                                                    	} else if (phi1 <= 3.15e-217) {
                                                                                                                                    		tmp = acos((fma(-0.5, (phi1 * phi1), 1.0) * cos(lambda1))) * R;
                                                                                                                                    	} else if (phi1 <= 3.4e-36) {
                                                                                                                                    		tmp = acos(cos(phi2)) * R;
                                                                                                                                    	} else {
                                                                                                                                    		tmp = t_0;
                                                                                                                                    	}
                                                                                                                                    	return tmp;
                                                                                                                                    }
                                                                                                                                    
                                                                                                                                    function code(R, lambda1, lambda2, phi1, phi2)
                                                                                                                                    	t_0 = Float64(acos(cos(phi1)) * R)
                                                                                                                                    	tmp = 0.0
                                                                                                                                    	if (phi1 <= -0.54)
                                                                                                                                    		tmp = t_0;
                                                                                                                                    	elseif (phi1 <= 3.15e-217)
                                                                                                                                    		tmp = Float64(acos(Float64(fma(-0.5, Float64(phi1 * phi1), 1.0) * cos(lambda1))) * R);
                                                                                                                                    	elseif (phi1 <= 3.4e-36)
                                                                                                                                    		tmp = Float64(acos(cos(phi2)) * R);
                                                                                                                                    	else
                                                                                                                                    		tmp = t_0;
                                                                                                                                    	end
                                                                                                                                    	return tmp
                                                                                                                                    end
                                                                                                                                    
                                                                                                                                    code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[ArcCos[N[Cos[phi1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]}, If[LessEqual[phi1, -0.54], t$95$0, If[LessEqual[phi1, 3.15e-217], N[(N[ArcCos[N[(N[(-0.5 * N[(phi1 * phi1), $MachinePrecision] + 1.0), $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi1, 3.4e-36], N[(N[ArcCos[N[Cos[phi2], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], t$95$0]]]]
                                                                                                                                    
                                                                                                                                    \begin{array}{l}
                                                                                                                                    
                                                                                                                                    \\
                                                                                                                                    \begin{array}{l}
                                                                                                                                    t_0 := \cos^{-1} \cos \phi_1 \cdot R\\
                                                                                                                                    \mathbf{if}\;\phi_1 \leq -0.54:\\
                                                                                                                                    \;\;\;\;t\_0\\
                                                                                                                                    
                                                                                                                                    \mathbf{elif}\;\phi_1 \leq 3.15 \cdot 10^{-217}:\\
                                                                                                                                    \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(-0.5, \phi_1 \cdot \phi_1, 1\right) \cdot \cos \lambda_1\right) \cdot R\\
                                                                                                                                    
                                                                                                                                    \mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-36}:\\
                                                                                                                                    \;\;\;\;\cos^{-1} \cos \phi_2 \cdot R\\
                                                                                                                                    
                                                                                                                                    \mathbf{else}:\\
                                                                                                                                    \;\;\;\;t\_0\\
                                                                                                                                    
                                                                                                                                    
                                                                                                                                    \end{array}
                                                                                                                                    \end{array}
                                                                                                                                    
                                                                                                                                    Derivation
                                                                                                                                    1. Split input into 3 regimes
                                                                                                                                    2. if phi1 < -0.54000000000000004 or 3.4000000000000003e-36 < phi1

                                                                                                                                      1. Initial program 79.1%

                                                                                                                                        \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                                                                                                                      2. Add Preprocessing
                                                                                                                                      3. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                                                                                        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
                                                                                                                                      7. Step-by-step derivation
                                                                                                                                        1. Applied rewrites34.2%

                                                                                                                                          \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
                                                                                                                                        2. Step-by-step derivation
                                                                                                                                          1. Applied rewrites24.6%

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

                                                                                                                                            \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot R \]
                                                                                                                                          3. Step-by-step derivation
                                                                                                                                            1. Applied rewrites24.2%

                                                                                                                                              \[\leadsto \cos^{-1} \cos \phi_1 \cdot R \]

                                                                                                                                            if -0.54000000000000004 < phi1 < 3.14999999999999999e-217

                                                                                                                                            1. Initial program 69.3%

                                                                                                                                              \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                                                                                                                            2. Add Preprocessing
                                                                                                                                            3. Taylor expanded in 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. lower-*.f64N/A

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

                                                                                                                                                \[\leadsto \cos^{-1} \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \lambda_2\right)\right)\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                                                                                              4. *-lft-identityN/A

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

                                                                                                                                                \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right)\right)\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                                                                                              6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                                                                                                                                \[\leadsto \cos^{-1} \left(\cos \color{blue}{\left(\lambda_2 + -1 \cdot \lambda_1\right)} \cdot \cos \phi_1\right) \cdot R \]
                                                                                                                                              14. fp-cancel-sign-sub-invN/A

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

                                                                                                                                                \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \color{blue}{1} \cdot \lambda_1\right) \cdot \cos \phi_1\right) \cdot R \]
                                                                                                                                              16. *-lft-identityN/A

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

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

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

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

                                                                                                                                              \[\leadsto \cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) + \color{blue}{\frac{-1}{2} \cdot \left({\phi_1}^{2} \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}\right) \cdot R \]
                                                                                                                                            7. Step-by-step derivation
                                                                                                                                              1. Applied rewrites39.9%

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

                                                                                                                                                \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\frac{-1}{2}, \phi_1 \cdot \phi_1, 1\right) \cdot \cos \lambda_1\right) \cdot R \]
                                                                                                                                              3. Step-by-step derivation
                                                                                                                                                1. Applied rewrites30.5%

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

                                                                                                                                                if 3.14999999999999999e-217 < phi1 < 3.4000000000000003e-36

                                                                                                                                                1. Initial program 58.1%

                                                                                                                                                  \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                                                                                                                                2. Add Preprocessing
                                                                                                                                                3. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                                                                                                  \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
                                                                                                                                                7. Step-by-step derivation
                                                                                                                                                  1. Applied rewrites21.6%

                                                                                                                                                    \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
                                                                                                                                                  2. Step-by-step derivation
                                                                                                                                                    1. Applied rewrites21.6%

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

                                                                                                                                                      \[\leadsto \cos^{-1} \cos \phi_2 \cdot R \]
                                                                                                                                                    3. Step-by-step derivation
                                                                                                                                                      1. Applied rewrites21.6%

                                                                                                                                                        \[\leadsto \cos^{-1} \cos \phi_2 \cdot R \]
                                                                                                                                                    4. Recombined 3 regimes into one program.
                                                                                                                                                    5. Add Preprocessing

                                                                                                                                                    Alternative 17: 24.1% accurate, 2.9× speedup?

                                                                                                                                                    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -15.5 \lor \neg \left(\phi_1 \leq 3 \cdot 10^{-158}\right):\\ \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \cos \phi_2 \cdot R\\ \end{array} \end{array} \]
                                                                                                                                                    (FPCore (R lambda1 lambda2 phi1 phi2)
                                                                                                                                                     :precision binary64
                                                                                                                                                     (if (or (<= phi1 -15.5) (not (<= phi1 3e-158)))
                                                                                                                                                       (* (acos (cos phi1)) R)
                                                                                                                                                       (* (acos (cos phi2)) R)))
                                                                                                                                                    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                                                                                                                                    	double tmp;
                                                                                                                                                    	if ((phi1 <= -15.5) || !(phi1 <= 3e-158)) {
                                                                                                                                                    		tmp = acos(cos(phi1)) * R;
                                                                                                                                                    	} else {
                                                                                                                                                    		tmp = acos(cos(phi2)) * R;
                                                                                                                                                    	}
                                                                                                                                                    	return tmp;
                                                                                                                                                    }
                                                                                                                                                    
                                                                                                                                                    real(8) function code(r, lambda1, lambda2, phi1, phi2)
                                                                                                                                                        real(8), intent (in) :: r
                                                                                                                                                        real(8), intent (in) :: lambda1
                                                                                                                                                        real(8), intent (in) :: lambda2
                                                                                                                                                        real(8), intent (in) :: phi1
                                                                                                                                                        real(8), intent (in) :: phi2
                                                                                                                                                        real(8) :: tmp
                                                                                                                                                        if ((phi1 <= (-15.5d0)) .or. (.not. (phi1 <= 3d-158))) then
                                                                                                                                                            tmp = acos(cos(phi1)) * r
                                                                                                                                                        else
                                                                                                                                                            tmp = acos(cos(phi2)) * r
                                                                                                                                                        end if
                                                                                                                                                        code = tmp
                                                                                                                                                    end function
                                                                                                                                                    
                                                                                                                                                    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                                                                                                                                    	double tmp;
                                                                                                                                                    	if ((phi1 <= -15.5) || !(phi1 <= 3e-158)) {
                                                                                                                                                    		tmp = Math.acos(Math.cos(phi1)) * R;
                                                                                                                                                    	} else {
                                                                                                                                                    		tmp = Math.acos(Math.cos(phi2)) * R;
                                                                                                                                                    	}
                                                                                                                                                    	return tmp;
                                                                                                                                                    }
                                                                                                                                                    
                                                                                                                                                    def code(R, lambda1, lambda2, phi1, phi2):
                                                                                                                                                    	tmp = 0
                                                                                                                                                    	if (phi1 <= -15.5) or not (phi1 <= 3e-158):
                                                                                                                                                    		tmp = math.acos(math.cos(phi1)) * R
                                                                                                                                                    	else:
                                                                                                                                                    		tmp = math.acos(math.cos(phi2)) * R
                                                                                                                                                    	return tmp
                                                                                                                                                    
                                                                                                                                                    function code(R, lambda1, lambda2, phi1, phi2)
                                                                                                                                                    	tmp = 0.0
                                                                                                                                                    	if ((phi1 <= -15.5) || !(phi1 <= 3e-158))
                                                                                                                                                    		tmp = Float64(acos(cos(phi1)) * R);
                                                                                                                                                    	else
                                                                                                                                                    		tmp = Float64(acos(cos(phi2)) * R);
                                                                                                                                                    	end
                                                                                                                                                    	return tmp
                                                                                                                                                    end
                                                                                                                                                    
                                                                                                                                                    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
                                                                                                                                                    	tmp = 0.0;
                                                                                                                                                    	if ((phi1 <= -15.5) || ~((phi1 <= 3e-158)))
                                                                                                                                                    		tmp = acos(cos(phi1)) * R;
                                                                                                                                                    	else
                                                                                                                                                    		tmp = acos(cos(phi2)) * R;
                                                                                                                                                    	end
                                                                                                                                                    	tmp_2 = tmp;
                                                                                                                                                    end
                                                                                                                                                    
                                                                                                                                                    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[Or[LessEqual[phi1, -15.5], N[Not[LessEqual[phi1, 3e-158]], $MachinePrecision]], N[(N[ArcCos[N[Cos[phi1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[Cos[phi2], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]
                                                                                                                                                    
                                                                                                                                                    \begin{array}{l}
                                                                                                                                                    
                                                                                                                                                    \\
                                                                                                                                                    \begin{array}{l}
                                                                                                                                                    \mathbf{if}\;\phi_1 \leq -15.5 \lor \neg \left(\phi_1 \leq 3 \cdot 10^{-158}\right):\\
                                                                                                                                                    \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\
                                                                                                                                                    
                                                                                                                                                    \mathbf{else}:\\
                                                                                                                                                    \;\;\;\;\cos^{-1} \cos \phi_2 \cdot R\\
                                                                                                                                                    
                                                                                                                                                    
                                                                                                                                                    \end{array}
                                                                                                                                                    \end{array}
                                                                                                                                                    
                                                                                                                                                    Derivation
                                                                                                                                                    1. Split input into 2 regimes
                                                                                                                                                    2. if phi1 < -15.5 or 3e-158 < phi1

                                                                                                                                                      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 lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                                                                                                        \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
                                                                                                                                                      7. Step-by-step derivation
                                                                                                                                                        1. Applied rewrites31.3%

                                                                                                                                                          \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
                                                                                                                                                        2. Step-by-step derivation
                                                                                                                                                          1. Applied rewrites23.3%

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

                                                                                                                                                            \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot R \]
                                                                                                                                                          3. Step-by-step derivation
                                                                                                                                                            1. Applied rewrites21.0%

                                                                                                                                                              \[\leadsto \cos^{-1} \cos \phi_1 \cdot R \]

                                                                                                                                                            if -15.5 < phi1 < 3e-158

                                                                                                                                                            1. Initial program 68.5%

                                                                                                                                                              \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                                                                                                                                            2. Add Preprocessing
                                                                                                                                                            3. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                                                                                                              \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
                                                                                                                                                            7. Step-by-step derivation
                                                                                                                                                              1. Applied rewrites23.4%

                                                                                                                                                                \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
                                                                                                                                                              2. Step-by-step derivation
                                                                                                                                                                1. Applied rewrites23.0%

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

                                                                                                                                                                  \[\leadsto \cos^{-1} \cos \phi_2 \cdot R \]
                                                                                                                                                                3. Step-by-step derivation
                                                                                                                                                                  1. Applied rewrites22.8%

                                                                                                                                                                    \[\leadsto \cos^{-1} \cos \phi_2 \cdot R \]
                                                                                                                                                                4. Recombined 2 regimes into one program.
                                                                                                                                                                5. Final simplification21.7%

                                                                                                                                                                  \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -15.5 \lor \neg \left(\phi_1 \leq 3 \cdot 10^{-158}\right):\\ \;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \cos \phi_2 \cdot R\\ \end{array} \]
                                                                                                                                                                6. Add Preprocessing

                                                                                                                                                                Alternative 18: 26.2% accurate, 3.0× speedup?

                                                                                                                                                                \[\begin{array}{l} \\ \cos^{-1} \cos \left(\phi_2 - \phi_1\right) \cdot R \end{array} \]
                                                                                                                                                                (FPCore (R lambda1 lambda2 phi1 phi2)
                                                                                                                                                                 :precision binary64
                                                                                                                                                                 (* (acos (cos (- phi2 phi1))) R))
                                                                                                                                                                double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                                                                                                                                                	return acos(cos((phi2 - phi1))) * 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(cos((phi2 - phi1))) * r
                                                                                                                                                                end function
                                                                                                                                                                
                                                                                                                                                                public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                                                                                                                                                	return Math.acos(Math.cos((phi2 - phi1))) * R;
                                                                                                                                                                }
                                                                                                                                                                
                                                                                                                                                                def code(R, lambda1, lambda2, phi1, phi2):
                                                                                                                                                                	return math.acos(math.cos((phi2 - phi1))) * R
                                                                                                                                                                
                                                                                                                                                                function code(R, lambda1, lambda2, phi1, phi2)
                                                                                                                                                                	return Float64(acos(cos(Float64(phi2 - phi1))) * R)
                                                                                                                                                                end
                                                                                                                                                                
                                                                                                                                                                function tmp = code(R, lambda1, lambda2, phi1, phi2)
                                                                                                                                                                	tmp = acos(cos((phi2 - phi1))) * R;
                                                                                                                                                                end
                                                                                                                                                                
                                                                                                                                                                code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[Cos[N[(phi2 - phi1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
                                                                                                                                                                
                                                                                                                                                                \begin{array}{l}
                                                                                                                                                                
                                                                                                                                                                \\
                                                                                                                                                                \cos^{-1} \cos \left(\phi_2 - \phi_1\right) \cdot R
                                                                                                                                                                \end{array}
                                                                                                                                                                
                                                                                                                                                                Derivation
                                                                                                                                                                1. Initial program 73.0%

                                                                                                                                                                  \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                                                                                                                                                2. Add Preprocessing
                                                                                                                                                                3. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                                                                                                                  \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
                                                                                                                                                                7. Step-by-step derivation
                                                                                                                                                                  1. Applied rewrites28.5%

                                                                                                                                                                    \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
                                                                                                                                                                  2. Step-by-step derivation
                                                                                                                                                                    1. Applied rewrites23.2%

                                                                                                                                                                      \[\leadsto \color{blue}{\cos^{-1} \cos \left(\phi_2 - \phi_1\right) \cdot R} \]
                                                                                                                                                                    2. Add Preprocessing

                                                                                                                                                                    Alternative 19: 17.6% accurate, 3.0× speedup?

                                                                                                                                                                    \[\begin{array}{l} \\ \cos^{-1} \cos \phi_1 \cdot R \end{array} \]
                                                                                                                                                                    (FPCore (R lambda1 lambda2 phi1 phi2)
                                                                                                                                                                     :precision binary64
                                                                                                                                                                     (* (acos (cos phi1)) R))
                                                                                                                                                                    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                                                                                                                                                    	return acos(cos(phi1)) * 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(cos(phi1)) * r
                                                                                                                                                                    end function
                                                                                                                                                                    
                                                                                                                                                                    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                                                                                                                                                    	return Math.acos(Math.cos(phi1)) * R;
                                                                                                                                                                    }
                                                                                                                                                                    
                                                                                                                                                                    def code(R, lambda1, lambda2, phi1, phi2):
                                                                                                                                                                    	return math.acos(math.cos(phi1)) * R
                                                                                                                                                                    
                                                                                                                                                                    function code(R, lambda1, lambda2, phi1, phi2)
                                                                                                                                                                    	return Float64(acos(cos(phi1)) * R)
                                                                                                                                                                    end
                                                                                                                                                                    
                                                                                                                                                                    function tmp = code(R, lambda1, lambda2, phi1, phi2)
                                                                                                                                                                    	tmp = acos(cos(phi1)) * R;
                                                                                                                                                                    end
                                                                                                                                                                    
                                                                                                                                                                    code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[Cos[phi1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
                                                                                                                                                                    
                                                                                                                                                                    \begin{array}{l}
                                                                                                                                                                    
                                                                                                                                                                    \\
                                                                                                                                                                    \cos^{-1} \cos \phi_1 \cdot R
                                                                                                                                                                    \end{array}
                                                                                                                                                                    
                                                                                                                                                                    Derivation
                                                                                                                                                                    1. Initial program 73.0%

                                                                                                                                                                      \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                                                                                                                                                    2. Add Preprocessing
                                                                                                                                                                    3. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                                                                                                                      \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \cos \phi_2 + \color{blue}{\sin \phi_1 \cdot \sin \phi_2}\right) \cdot R \]
                                                                                                                                                                    7. Step-by-step derivation
                                                                                                                                                                      1. Applied rewrites28.5%

                                                                                                                                                                        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2, \color{blue}{\cos \phi_1}, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R \]
                                                                                                                                                                      2. Step-by-step derivation
                                                                                                                                                                        1. Applied rewrites23.2%

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

                                                                                                                                                                          \[\leadsto \cos^{-1} \cos \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot R \]
                                                                                                                                                                        3. Step-by-step derivation
                                                                                                                                                                          1. Applied rewrites15.8%

                                                                                                                                                                            \[\leadsto \cos^{-1} \cos \phi_1 \cdot R \]
                                                                                                                                                                          2. Add Preprocessing

                                                                                                                                                                          Reproduce

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