Spherical law of cosines

Percentage Accurate: 73.9% → 94.2%
Time: 21.6s
Alternatives: 28
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  (acos
   (+
    (* (sin phi1) (sin phi2))
    (* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2)))))
  R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * R;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * r
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return Math.acos(((Math.sin(phi1) * Math.sin(phi2)) + ((Math.cos(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2))))) * R;
}
def code(R, lambda1, lambda2, phi1, phi2):
	return math.acos(((math.sin(phi1) * math.sin(phi2)) + ((math.cos(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2))))) * R
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2))))) * R)
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * R;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}

\\
\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 28 alternatives:

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

Initial Program: 73.9% 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.2% accurate, 0.7× speedup?

\[\begin{array}{l} \\ R \cdot \cos^{-1} \left(\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + \sin \phi_2 \cdot \sin \phi_1\right) \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R
  (acos
   (+
    (*
     (+ (* (sin lambda1) (sin lambda2)) (* (cos lambda1) (cos lambda2)))
     (* (cos phi2) (cos phi1)))
    (* (sin phi2) (sin phi1))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * acos(((((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2))) * (cos(phi2) * cos(phi1))) + (sin(phi2) * sin(phi1))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = r * acos(((((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2))) * (cos(phi2) * cos(phi1))) + (sin(phi2) * sin(phi1))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * Math.acos(((((Math.sin(lambda1) * Math.sin(lambda2)) + (Math.cos(lambda1) * Math.cos(lambda2))) * (Math.cos(phi2) * Math.cos(phi1))) + (Math.sin(phi2) * Math.sin(phi1))));
}
def code(R, lambda1, lambda2, phi1, phi2):
	return R * math.acos(((((math.sin(lambda1) * math.sin(lambda2)) + (math.cos(lambda1) * math.cos(lambda2))) * (math.cos(phi2) * math.cos(phi1))) + (math.sin(phi2) * math.sin(phi1))))
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(R * acos(Float64(Float64(Float64(Float64(sin(lambda1) * sin(lambda2)) + Float64(cos(lambda1) * cos(lambda2))) * Float64(cos(phi2) * cos(phi1))) + Float64(sin(phi2) * sin(phi1)))))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = R * acos(((((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2))) * (cos(phi2) * cos(phi1))) + (sin(phi2) * sin(phi1))));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[ArcCos[N[(N[(N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
R \cdot \cos^{-1} \left(\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + \sin \phi_2 \cdot \sin \phi_1\right)
\end{array}
Derivation
  1. Initial program 74.6%

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

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

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

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

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

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

    \[\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_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \lambda_1\right)}\right) \cdot R \]
  5. Final simplification95.8%

    \[\leadsto R \cdot \cos^{-1} \left(\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + \sin \phi_2 \cdot \sin \phi_1\right) \]
  6. Add Preprocessing

Alternative 2: 94.2% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \cos^{-1} \left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + \sin \phi_2 \cdot \sin \phi_1\right) \cdot R \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  (acos
   (+
    (*
     (fma (sin lambda2) (sin lambda1) (* (cos lambda1) (cos lambda2)))
     (* (cos phi2) (cos phi1)))
    (* (sin phi2) (sin phi1))))
  R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return acos(((fma(sin(lambda2), sin(lambda1), (cos(lambda1) * cos(lambda2))) * (cos(phi2) * cos(phi1))) + (sin(phi2) * sin(phi1)))) * R;
}
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(acos(Float64(Float64(fma(sin(lambda2), sin(lambda1), Float64(cos(lambda1) * cos(lambda2))) * Float64(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[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}

\\
\cos^{-1} \left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right) + \sin \phi_2 \cdot \sin \phi_1\right) \cdot R
\end{array}
Derivation
  1. Initial program 74.6%

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

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\color{blue}{\sin \lambda_2 \cdot \sin \lambda_1} + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
    6. 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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
    7. 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(\color{blue}{\sin \lambda_2}, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
    8. 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(\sin \lambda_2, \color{blue}{\sin \lambda_1}, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
    9. *-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(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_2 \cdot \cos \lambda_1}\right)\right) \cdot R \]
    10. 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(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_2 \cdot \cos \lambda_1}\right)\right) \cdot R \]
    11. 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(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_2} \cdot \cos \lambda_1\right)\right) \cdot R \]
    12. lower-cos.f6495.8

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

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

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

Alternative 3: 94.2% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\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 lambda1) (cos lambda2)))
     (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(lambda1) * cos(lambda2))) * 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(lambda1) * cos(lambda2))) * 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[lambda1], $MachinePrecision] * N[Cos[lambda2], $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_1 \cdot \cos \lambda_2\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 74.6%

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

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

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

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

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

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

    \[\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_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \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 rewrites95.8%

    \[\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. Final simplification95.8%

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

Alternative 4: 84.2% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\\ t_1 := \sqrt{\mathsf{PI}\left(\right)}\\ \mathbf{if}\;\phi_1 \leq -16:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, R, \left(-R\right) \cdot t\_0\right)\\ \mathbf{elif}\;\phi_1 \leq 0.023:\\ \;\;\;\;\cos^{-1} \left(\left(\sin \phi_2 \cdot \phi_1\right) \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot \phi_1, \phi_1, 1\right) + \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left({\mathsf{PI}\left(\right)}^{0.6666666666666666}, \sqrt[3]{t\_1 \cdot t\_1} \cdot 0.5, -t\_0\right) \cdot R\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0
         (asin
          (fma
           (* (cos (- lambda2 lambda1)) (cos phi1))
           (cos phi2)
           (* (sin phi2) (sin phi1)))))
        (t_1 (sqrt (PI))))
   (if (<= phi1 -16.0)
     (fma (* (PI) 0.5) R (* (- R) t_0))
     (if (<= phi1 0.023)
       (*
        (acos
         (+
          (* (* (sin phi2) phi1) (fma (* -0.16666666666666666 phi1) phi1 1.0))
          (*
           (fma (sin lambda2) (sin lambda1) (* (cos lambda1) (cos lambda2)))
           (* (cos phi2) (cos phi1)))))
        R)
       (*
        (fma (pow (PI) 0.6666666666666666) (* (cbrt (* t_1 t_1)) 0.5) (- t_0))
        R)))))
\begin{array}{l}

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

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left({\mathsf{PI}\left(\right)}^{0.6666666666666666}, \sqrt[3]{t\_1 \cdot t\_1} \cdot 0.5, -t\_0\right) \cdot R\\


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

    1. Initial program 77.3%

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

        \[\leadsto \color{blue}{\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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -16 < phi1 < 0.023

    1. Initial program 69.0%

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

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\color{blue}{\sin \lambda_2 \cdot \sin \lambda_1} + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      6. 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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
      7. 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(\color{blue}{\sin \lambda_2}, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      8. 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(\sin \lambda_2, \color{blue}{\sin \lambda_1}, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      9. *-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(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_2 \cdot \cos \lambda_1}\right)\right) \cdot R \]
      10. 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(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_2 \cdot \cos \lambda_1}\right)\right) \cdot R \]
      11. 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(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_2} \cdot \cos \lambda_1\right)\right) \cdot R \]
      12. lower-cos.f6492.0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.023 < phi1

    1. Initial program 82.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{{\mathsf{PI}\left(\right)}^{0.6666666666666666}}, \sqrt[3]{\mathsf{PI}\left(\right)} \cdot 0.5, -\sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right) \cdot R \]
    7. Step-by-step derivation
      1. lift-PI.f64N/A

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left({\mathsf{PI}\left(\right)}^{\frac{2}{3}}, \sqrt[3]{\sqrt{\mathsf{PI}\left(\right)} \cdot \sqrt{\color{blue}{\mathsf{PI}\left(\right)}}} \cdot \frac{1}{2}, -\sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right) \cdot R \]
      7. lower-sqrt.f6481.9

        \[\leadsto \mathsf{fma}\left({\mathsf{PI}\left(\right)}^{0.6666666666666666}, \sqrt[3]{\sqrt{\mathsf{PI}\left(\right)} \cdot \color{blue}{\sqrt{\mathsf{PI}\left(\right)}}} \cdot 0.5, -\sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right) \cdot R \]
    8. Applied rewrites81.9%

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

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

Alternative 5: 84.2% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -16:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, R, \left(-R\right) \cdot \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 0.023:\\ \;\;\;\;\cos^{-1} \left(\left(\sin \phi_2 \cdot \phi_1\right) \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot \phi_1, \phi_1, 1\right) + \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)\right) \cdot R\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi1 -16.0)
   (fma
    (* (PI) 0.5)
    R
    (*
     (- R)
     (asin
      (fma
       (* (cos (- lambda2 lambda1)) (cos phi1))
       (cos phi2)
       (* (sin phi2) (sin phi1))))))
   (if (<= phi1 0.023)
     (*
      (acos
       (+
        (* (* (sin phi2) phi1) (fma (* -0.16666666666666666 phi1) phi1 1.0))
        (*
         (fma (sin lambda2) (sin lambda1) (* (cos lambda1) (cos lambda2)))
         (* (cos phi2) (cos phi1)))))
      R)
     (*
      (acos
       (fma
        (sin phi2)
        (sin phi1)
        (* (* (cos (- lambda1 lambda2)) (cos phi2)) (cos phi1))))
      R))))
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -16:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, R, \left(-R\right) \cdot \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right)\\

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

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


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

    1. Initial program 77.3%

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

        \[\leadsto \color{blue}{\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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -16 < phi1 < 0.023

    1. Initial program 69.0%

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

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\color{blue}{\sin \lambda_2 \cdot \sin \lambda_1} + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      6. 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(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
      7. 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(\color{blue}{\sin \lambda_2}, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      8. 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(\sin \lambda_2, \color{blue}{\sin \lambda_1}, \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R \]
      9. *-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(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_2 \cdot \cos \lambda_1}\right)\right) \cdot R \]
      10. 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(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_2 \cdot \cos \lambda_1}\right)\right) \cdot R \]
      11. 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(\sin \lambda_2, \sin \lambda_1, \color{blue}{\cos \lambda_2} \cdot \cos \lambda_1\right)\right) \cdot R \]
      12. lower-cos.f6492.0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.023 < phi1

    1. Initial program 82.0%

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 84.2% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -16:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, R, \left(-R\right) \cdot \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 0.023:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \cos \phi_2, \cos \phi_1, \left(\sin \phi_2 \cdot \phi_1\right) \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot \phi_1, \phi_1, 1\right)\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)\right) \cdot R\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi1 -16.0)
   (fma
    (* (PI) 0.5)
    R
    (*
     (- R)
     (asin
      (fma
       (* (cos (- lambda2 lambda1)) (cos phi1))
       (cos phi2)
       (* (sin phi2) (sin phi1))))))
   (if (<= phi1 0.023)
     (*
      (acos
       (fma
        (*
         (fma (sin lambda2) (sin lambda1) (* (cos lambda1) (cos lambda2)))
         (cos phi2))
        (cos phi1)
        (* (* (sin phi2) phi1) (fma (* -0.16666666666666666 phi1) phi1 1.0))))
      R)
     (*
      (acos
       (fma
        (sin phi2)
        (sin phi1)
        (* (* (cos (- lambda1 lambda2)) (cos phi2)) (cos phi1))))
      R))))
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -16:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, R, \left(-R\right) \cdot \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right)\\

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

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


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

    1. Initial program 77.3%

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

        \[\leadsto \color{blue}{\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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -16 < phi1 < 0.023

    1. Initial program 69.0%

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

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

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

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

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

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

      \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \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 rewrites91.9%

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

      \[\leadsto \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, \phi_1 \cdot \left(\sin \phi_2 + \frac{-1}{6} \cdot \left({\phi_1}^{2} \cdot \sin \phi_2\right)\right)\right)\right) \cdot R \]
    9. Step-by-step derivation
      1. Applied rewrites91.6%

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

      if 0.023 < phi1

      1. Initial program 82.0%

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

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

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

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

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

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

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

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

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

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

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

    Alternative 7: 84.2% accurate, 0.7× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \phi_2 \cdot \sin \phi_1\\ \mathbf{if}\;\phi_1 \leq -0.075:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, R, \left(-R\right) \cdot \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, t\_0\right)\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 0.0027:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(-0.5 \cdot \phi_1, \phi_1, 1\right) \cdot \left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \cos \phi_2\right) + t\_0\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)\right) \cdot R\\ \end{array} \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (let* ((t_0 (* (sin phi2) (sin phi1))))
       (if (<= phi1 -0.075)
         (fma
          (* (PI) 0.5)
          R
          (*
           (- R)
           (asin (fma (* (cos (- lambda2 lambda1)) (cos phi1)) (cos phi2) t_0))))
         (if (<= phi1 0.0027)
           (*
            (acos
             (+
              (*
               (fma (* -0.5 phi1) phi1 1.0)
               (*
                (fma (sin lambda2) (sin lambda1) (* (cos lambda1) (cos lambda2)))
                (cos phi2)))
              t_0))
            R)
           (*
            (acos
             (fma
              (sin phi2)
              (sin phi1)
              (* (* (cos (- lambda1 lambda2)) (cos phi2)) (cos phi1))))
            R)))))
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \sin \phi_2 \cdot \sin \phi_1\\
    \mathbf{if}\;\phi_1 \leq -0.075:\\
    \;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, R, \left(-R\right) \cdot \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, t\_0\right)\right)\right)\\
    
    \mathbf{elif}\;\phi_1 \leq 0.0027:\\
    \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(-0.5 \cdot \phi_1, \phi_1, 1\right) \cdot \left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \cos \phi_2\right) + t\_0\right) \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)\right) \cdot R\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if phi1 < -0.0749999999999999972

      1. Initial program 77.3%

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

          \[\leadsto \color{blue}{\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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -0.0749999999999999972 < phi1 < 0.0027000000000000001

      1. Initial program 69.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. 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}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
        6. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 0.0027000000000000001 < phi1

      1. Initial program 81.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 lambda1 around inf

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

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

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

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

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

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

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

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

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

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

    Alternative 8: 84.2% accurate, 0.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -0.075:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, R, \left(-R\right) \cdot \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 0.0027:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(-0.5 \cdot \phi_1, \phi_1, 1\right) \cdot \left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \cos \phi_2\right) + \left(\sin \phi_2 \cdot \phi_1\right) \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot \phi_1, \phi_1, 1\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)\right) \cdot R\\ \end{array} \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (<= phi1 -0.075)
       (fma
        (* (PI) 0.5)
        R
        (*
         (- R)
         (asin
          (fma
           (* (cos (- lambda2 lambda1)) (cos phi1))
           (cos phi2)
           (* (sin phi2) (sin phi1))))))
       (if (<= phi1 0.0027)
         (*
          (acos
           (+
            (*
             (fma (* -0.5 phi1) phi1 1.0)
             (*
              (fma (sin lambda2) (sin lambda1) (* (cos lambda1) (cos lambda2)))
              (cos phi2)))
            (* (* (sin phi2) phi1) (fma (* -0.16666666666666666 phi1) phi1 1.0))))
          R)
         (*
          (acos
           (fma
            (sin phi2)
            (sin phi1)
            (* (* (cos (- lambda1 lambda2)) (cos phi2)) (cos phi1))))
          R))))
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\phi_1 \leq -0.075:\\
    \;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, R, \left(-R\right) \cdot \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right)\\
    
    \mathbf{elif}\;\phi_1 \leq 0.0027:\\
    \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(-0.5 \cdot \phi_1, \phi_1, 1\right) \cdot \left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \cos \phi_2\right) + \left(\sin \phi_2 \cdot \phi_1\right) \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot \phi_1, \phi_1, 1\right)\right) \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)\right) \cdot R\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if phi1 < -0.0749999999999999972

      1. Initial program 77.3%

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

          \[\leadsto \color{blue}{\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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -0.0749999999999999972 < phi1 < 0.0027000000000000001

      1. Initial program 69.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. 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}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
        6. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 0.0027000000000000001 < phi1

      1. Initial program 81.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 lambda1 around inf

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

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

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

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

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

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

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

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

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

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

    Alternative 9: 84.2% accurate, 0.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -0.075:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, R, \left(-R\right) \cdot \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 0.0024:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \phi_1, \mathsf{fma}\left(-0.5 \cdot \phi_1, \phi_1, 1\right) \cdot \left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \cos \phi_2\right)\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)\right) \cdot R\\ \end{array} \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (<= phi1 -0.075)
       (fma
        (* (PI) 0.5)
        R
        (*
         (- R)
         (asin
          (fma
           (* (cos (- lambda2 lambda1)) (cos phi1))
           (cos phi2)
           (* (sin phi2) (sin phi1))))))
       (if (<= phi1 0.0024)
         (*
          (acos
           (fma
            (sin phi2)
            phi1
            (*
             (fma (* -0.5 phi1) phi1 1.0)
             (*
              (fma (sin lambda2) (sin lambda1) (* (cos lambda1) (cos lambda2)))
              (cos phi2)))))
          R)
         (*
          (acos
           (fma
            (sin phi2)
            (sin phi1)
            (* (* (cos (- lambda1 lambda2)) (cos phi2)) (cos phi1))))
          R))))
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\phi_1 \leq -0.075:\\
    \;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, R, \left(-R\right) \cdot \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right)\\
    
    \mathbf{elif}\;\phi_1 \leq 0.0024:\\
    \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \phi_1, \mathsf{fma}\left(-0.5 \cdot \phi_1, \phi_1, 1\right) \cdot \left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \cos \phi_2\right)\right)\right) \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)\right) \cdot R\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if phi1 < -0.0749999999999999972

      1. Initial program 77.3%

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

          \[\leadsto \color{blue}{\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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -0.0749999999999999972 < phi1 < 0.00239999999999999979

      1. Initial program 69.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. 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}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
        6. *-commutativeN/A

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

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

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

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

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

        \[\leadsto \cos^{-1} \color{blue}{\left(\phi_1 \cdot \left(\sin \phi_2 + \frac{-1}{2} \cdot \left(\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)\right)\right) + \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. distribute-rgt-inN/A

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

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

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

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

      if 0.00239999999999999979 < phi1

      1. Initial program 81.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 lambda1 around inf

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

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

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

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

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

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

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

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

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

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

    Alternative 10: 83.6% accurate, 0.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -4.6 \cdot 10^{-36}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, R, \left(-R\right) \cdot \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 0.00042:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_2, \sin \phi_2 \cdot \phi_1\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)\right) \cdot R\\ \end{array} \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (<= phi1 -4.6e-36)
       (fma
        (* (PI) 0.5)
        R
        (*
         (- R)
         (asin
          (fma
           (* (cos (- lambda2 lambda1)) (cos phi1))
           (cos phi2)
           (* (sin phi2) (sin phi1))))))
       (if (<= phi1 0.00042)
         (*
          (acos
           (fma
            (fma (sin lambda2) (sin lambda1) (* (cos lambda1) (cos lambda2)))
            (cos phi2)
            (* (sin phi2) phi1)))
          R)
         (*
          (acos
           (fma
            (sin phi2)
            (sin phi1)
            (* (* (cos (- lambda1 lambda2)) (cos phi2)) (cos phi1))))
          R))))
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\phi_1 \leq -4.6 \cdot 10^{-36}:\\
    \;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, R, \left(-R\right) \cdot \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right)\\
    
    \mathbf{elif}\;\phi_1 \leq 0.00042:\\
    \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right), \cos \phi_2, \sin \phi_2 \cdot \phi_1\right)\right) \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)\right) \cdot R\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if phi1 < -4.59999999999999993e-36

      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. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \color{blue}{\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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -4.59999999999999993e-36 < phi1 < 4.2000000000000002e-4

      1. Initial program 69.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. 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}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
        6. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\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), \cos \phi_2, \sin \phi_2 \cdot \phi_1\right)\right)} \cdot R \]

      if 4.2000000000000002e-4 < phi1

      1. Initial program 81.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 lambda1 around inf

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

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

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

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

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

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

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

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

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

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

    Alternative 11: 83.6% accurate, 0.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -4.6 \cdot 10^{-36}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, R, \left(-R\right) \cdot \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 0.00042:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right), \cos \phi_2, \sin \phi_2 \cdot \phi_1\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)\right) \cdot R\\ \end{array} \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (<= phi1 -4.6e-36)
       (fma
        (* (PI) 0.5)
        R
        (*
         (- R)
         (asin
          (fma
           (* (cos (- lambda2 lambda1)) (cos phi1))
           (cos phi2)
           (* (sin phi2) (sin phi1))))))
       (if (<= phi1 0.00042)
         (*
          (acos
           (fma
            (fma (cos lambda2) (cos lambda1) (* (sin lambda1) (sin lambda2)))
            (cos phi2)
            (* (sin phi2) phi1)))
          R)
         (*
          (acos
           (fma
            (sin phi2)
            (sin phi1)
            (* (* (cos (- lambda1 lambda2)) (cos phi2)) (cos phi1))))
          R))))
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\phi_1 \leq -4.6 \cdot 10^{-36}:\\
    \;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, R, \left(-R\right) \cdot \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right)\\
    
    \mathbf{elif}\;\phi_1 \leq 0.00042:\\
    \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right), \cos \phi_2, \sin \phi_2 \cdot \phi_1\right)\right) \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)\right) \cdot R\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if phi1 < -4.59999999999999993e-36

      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. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \color{blue}{\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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -4.59999999999999993e-36 < phi1 < 4.2000000000000002e-4

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 4.2000000000000002e-4 < phi1

      1. Initial program 81.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 lambda1 around inf

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

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

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

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

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

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

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

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

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

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

    Alternative 12: 83.5% accurate, 1.0× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -4.6 \cdot 10^{-36}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, R, \left(-R\right) \cdot \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 0.00042:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \cos \phi_2\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)\right) \cdot R\\ \end{array} \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (<= phi1 -4.6e-36)
       (fma
        (* (PI) 0.5)
        R
        (*
         (- R)
         (asin
          (fma
           (* (cos (- lambda2 lambda1)) (cos phi1))
           (cos phi2)
           (* (sin phi2) (sin phi1))))))
       (if (<= phi1 0.00042)
         (*
          (acos
           (*
            (fma (sin lambda2) (sin lambda1) (* (cos lambda1) (cos lambda2)))
            (cos phi2)))
          R)
         (*
          (acos
           (fma
            (sin phi2)
            (sin phi1)
            (* (* (cos (- lambda1 lambda2)) (cos phi2)) (cos phi1))))
          R))))
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\phi_1 \leq -4.6 \cdot 10^{-36}:\\
    \;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, R, \left(-R\right) \cdot \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right) \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right)\\
    
    \mathbf{elif}\;\phi_1 \leq 0.00042:\\
    \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \cos \phi_2\right) \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)\right) \cdot R\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if phi1 < -4.59999999999999993e-36

      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. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \color{blue}{\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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -4.59999999999999993e-36 < phi1 < 4.2000000000000002e-4

      1. Initial program 69.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. 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}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
        6. *-commutativeN/A

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

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

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

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

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

        \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \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.f6491.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 rewrites91.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 4.2000000000000002e-4 < phi1

      1. Initial program 81.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 lambda1 around inf

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

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

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

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

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

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

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

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

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

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

    Alternative 13: 74.1% accurate, 1.0× speedup?

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

      1. Initial program 76.7%

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

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

        \[\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 -1.6500000000000001e157 < phi1 < -0.0749999999999999972

      1. Initial program 78.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. sub-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -0.0749999999999999972 < phi1 < 4.2000000000000002e-4

        1. Initial program 69.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. 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}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
          6. *-commutativeN/A

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

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

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

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

            \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \color{blue}{\cos \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}{\left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \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.f6490.6

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

          \[\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 4.2000000000000002e-4 < phi1

        1. Initial program 81.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.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 rewrites61.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 \]
      7. Recombined 4 regimes into one program.
      8. Final simplification75.7%

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

      Alternative 14: 74.1% accurate, 1.0× speedup?

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

        1. Initial program 76.7%

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

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

          \[\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 -1.6500000000000001e157 < phi1 < -0.0749999999999999972

        1. Initial program 78.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. sub-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          if -0.0749999999999999972 < phi1 < 4.2000000000000002e-4

          1. Initial program 69.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. 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}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
            6. *-commutativeN/A

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

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

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

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

              \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \color{blue}{\cos \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}{\left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \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.f6490.6

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

            \[\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 4.2000000000000002e-4 < phi1

          1. Initial program 81.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.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 rewrites61.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 \]
        7. Recombined 4 regimes into one program.
        8. Final simplification75.7%

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

        Alternative 15: 83.8% accurate, 1.0× 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_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)\right) \cdot R\\ \mathbf{if}\;\phi_1 \leq -2.8 \cdot 10^{-10}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_1 \leq 0.00042:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \cos \phi_2\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
        (FPCore (R lambda1 lambda2 phi1 phi2)
         :precision binary64
         (let* ((t_0
                 (*
                  (acos
                   (fma
                    (sin phi2)
                    (sin phi1)
                    (* (* (cos (- lambda1 lambda2)) (cos phi2)) (cos phi1))))
                  R)))
           (if (<= phi1 -2.8e-10)
             t_0
             (if (<= phi1 0.00042)
               (*
                (acos
                 (*
                  (fma (sin lambda2) (sin lambda1) (* (cos lambda1) (cos lambda2)))
                  (cos phi2)))
                R)
               t_0))))
        double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
        	double t_0 = acos(fma(sin(phi2), sin(phi1), ((cos((lambda1 - lambda2)) * cos(phi2)) * cos(phi1)))) * R;
        	double tmp;
        	if (phi1 <= -2.8e-10) {
        		tmp = t_0;
        	} else if (phi1 <= 0.00042) {
        		tmp = acos((fma(sin(lambda2), sin(lambda1), (cos(lambda1) * cos(lambda2))) * cos(phi2))) * R;
        	} else {
        		tmp = t_0;
        	}
        	return tmp;
        }
        
        function code(R, lambda1, lambda2, phi1, phi2)
        	t_0 = Float64(acos(fma(sin(phi2), sin(phi1), Float64(Float64(cos(Float64(lambda1 - lambda2)) * cos(phi2)) * cos(phi1)))) * R)
        	tmp = 0.0
        	if (phi1 <= -2.8e-10)
        		tmp = t_0;
        	elseif (phi1 <= 0.00042)
        		tmp = Float64(acos(Float64(fma(sin(lambda2), sin(lambda1), Float64(cos(lambda1) * cos(lambda2))) * 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[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[(N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]}, If[LessEqual[phi1, -2.8e-10], t$95$0, If[LessEqual[phi1, 0.00042], N[(N[ArcCos[N[(N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], t$95$0]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_0 := \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)\right) \cdot R\\
        \mathbf{if}\;\phi_1 \leq -2.8 \cdot 10^{-10}:\\
        \;\;\;\;t\_0\\
        
        \mathbf{elif}\;\phi_1 \leq 0.00042:\\
        \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right) \cdot \cos \phi_2\right) \cdot R\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_0\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if phi1 < -2.80000000000000015e-10 or 4.2000000000000002e-4 < phi1

          1. Initial program 79.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 lambda1 around inf

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

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

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

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

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

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

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

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

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

          if -2.80000000000000015e-10 < phi1 < 4.2000000000000002e-4

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

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

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

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

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

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

            \[\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_2 \cdot \sin \lambda_1 + \cos \lambda_2 \cdot \cos \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.f6491.8

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

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

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

        Alternative 16: 74.1% accurate, 1.0× speedup?

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

          1. Initial program 59.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if -4.5e-10 < lambda2 < 2.50000000000000012e-5

            1. Initial program 91.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.f6491.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 rewrites91.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 \]

            if 2.50000000000000012e-5 < lambda2

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

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

              \[\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 \]
          7. Recombined 3 regimes into one program.
          8. Add Preprocessing

          Alternative 17: 73.0% accurate, 1.0× speedup?

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

            1. Initial program 62.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. sub-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              if -2.9e-5 < lambda1 < 9.99999999999999943e-30

              1. Initial program 90.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 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.f6490.9

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

                \[\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 \]
            7. Recombined 2 regimes into one program.
            8. Add Preprocessing

            Alternative 18: 73.0% accurate, 1.0× speedup?

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

              1. Initial program 62.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. sub-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                if -2.9e-5 < lambda1 < 9.99999999999999943e-30

                1. Initial program 90.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 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.f6490.9

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

                  \[\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 \]
                6. Step-by-step derivation
                  1. Applied rewrites90.9%

                    \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \color{blue}{\sin \phi_1}, \left(\cos \lambda_2 \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)\right) \cdot R \]
                7. Recombined 2 regimes into one program.
                8. Add Preprocessing

                Alternative 19: 61.2% accurate, 1.0× speedup?

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

                  1. Initial program 72.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. sub-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    if 26000 < phi2

                    1. Initial program 82.6%

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

                      \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
                    4. Step-by-step derivation
                      1. *-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. sub-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  Alternative 20: 56.7% accurate, 1.2× speedup?

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

                    1. Initial program 79.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 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.f6455.9

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

                      \[\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 \]
                    6. Taylor expanded in lambda2 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 rewrites40.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 \]

                      if -0.340000000000000024 < phi2 < 0.0140000000000000003

                      1. Initial program 69.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(\phi_2 \cdot \left(\sin \phi_1 + \phi_2 \cdot \left(\frac{-1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) + \frac{-1}{6} \cdot \left(\phi_2 \cdot \sin \phi_1\right)\right)\right) + \cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
                      4. Applied rewrites69.1%

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

                      if 0.0140000000000000003 < phi2

                      1. Initial program 81.8%

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

                        \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
                      4. Step-by-step derivation
                        1. *-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. sub-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    Alternative 21: 35.4% accurate, 1.9× speedup?

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

                      1. Initial program 77.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. sub-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \cos^{-1} \left(\cos \left(\mathsf{neg}\left(\lambda_2\right)\right) \cdot \cos \color{blue}{\phi_1}\right) \cdot R \]
                      7. Step-by-step derivation
                        1. Applied rewrites35.4%

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

                        if -0.0749999999999999972 < phi1 < -1.14999999999999998e-180

                        1. Initial program 69.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. sub-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                          if -1.14999999999999998e-180 < 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 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.f6451.5

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

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

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

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

                          Alternative 22: 50.9% accurate, 2.0× speedup?

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

                            1. Initial program 72.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. sub-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            if 145000 < phi2

                            1. Initial program 82.6%

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

                              \[\leadsto \cos^{-1} \color{blue}{\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)} \cdot R \]
                            4. Step-by-step derivation
                              1. *-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. sub-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                          Alternative 23: 48.3% accurate, 2.0× speedup?

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

                            1. Initial program 72.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. sub-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            if 215000 < phi2

                            1. Initial program 82.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 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.f6459.8

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

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

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

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

                            Alternative 24: 37.2% accurate, 2.0× speedup?

                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 0.00021:\\ \;\;\;\;\cos^{-1} \left(\cos \lambda_1 \cdot \cos \phi_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(\cos \lambda_2 \cdot \cos \phi_2\right) \cdot R\\ \end{array} \end{array} \]
                            (FPCore (R lambda1 lambda2 phi1 phi2)
                             :precision binary64
                             (if (<= lambda2 0.00021)
                               (* (acos (* (cos lambda1) (cos phi1))) R)
                               (* (acos (* (cos lambda2) (cos phi2))) R)))
                            double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                            	double tmp;
                            	if (lambda2 <= 0.00021) {
                            		tmp = acos((cos(lambda1) * cos(phi1))) * R;
                            	} else {
                            		tmp = acos((cos(lambda2) * 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 (lambda2 <= 0.00021d0) then
                                    tmp = acos((cos(lambda1) * cos(phi1))) * r
                                else
                                    tmp = acos((cos(lambda2) * 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 (lambda2 <= 0.00021) {
                            		tmp = Math.acos((Math.cos(lambda1) * Math.cos(phi1))) * R;
                            	} else {
                            		tmp = Math.acos((Math.cos(lambda2) * Math.cos(phi2))) * R;
                            	}
                            	return tmp;
                            }
                            
                            def code(R, lambda1, lambda2, phi1, phi2):
                            	tmp = 0
                            	if lambda2 <= 0.00021:
                            		tmp = math.acos((math.cos(lambda1) * math.cos(phi1))) * R
                            	else:
                            		tmp = math.acos((math.cos(lambda2) * math.cos(phi2))) * R
                            	return tmp
                            
                            function code(R, lambda1, lambda2, phi1, phi2)
                            	tmp = 0.0
                            	if (lambda2 <= 0.00021)
                            		tmp = Float64(acos(Float64(cos(lambda1) * cos(phi1))) * R);
                            	else
                            		tmp = Float64(acos(Float64(cos(lambda2) * cos(phi2))) * R);
                            	end
                            	return tmp
                            end
                            
                            function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
                            	tmp = 0.0;
                            	if (lambda2 <= 0.00021)
                            		tmp = acos((cos(lambda1) * cos(phi1))) * R;
                            	else
                            		tmp = acos((cos(lambda2) * cos(phi2))) * R;
                            	end
                            	tmp_2 = tmp;
                            end
                            
                            code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda2, 0.00021], N[(N[ArcCos[N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]
                            
                            \begin{array}{l}
                            
                            \\
                            \begin{array}{l}
                            \mathbf{if}\;\lambda_2 \leq 0.00021:\\
                            \;\;\;\;\cos^{-1} \left(\cos \lambda_1 \cdot \cos \phi_1\right) \cdot R\\
                            
                            \mathbf{else}:\\
                            \;\;\;\;\cos^{-1} \left(\cos \lambda_2 \cdot \cos \phi_2\right) \cdot R\\
                            
                            
                            \end{array}
                            \end{array}
                            
                            Derivation
                            1. Split input into 2 regimes
                            2. if lambda2 < 2.1000000000000001e-4

                              1. Initial program 79.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. sub-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                if 2.1000000000000001e-4 < lambda2

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

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

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

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

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

                                Alternative 25: 34.6% accurate, 2.0× speedup?

                                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -2.8 \cdot 10^{-5}:\\ \;\;\;\;\cos^{-1} \cos \left(\lambda_1 - \lambda_2\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(\cos \lambda_2 \cdot \cos \phi_2\right) \cdot R\\ \end{array} \end{array} \]
                                (FPCore (R lambda1 lambda2 phi1 phi2)
                                 :precision binary64
                                 (if (<= lambda1 -2.8e-5)
                                   (* (acos (cos (- lambda1 lambda2))) R)
                                   (* (acos (* (cos lambda2) (cos phi2))) R)))
                                double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                	double tmp;
                                	if (lambda1 <= -2.8e-5) {
                                		tmp = acos(cos((lambda1 - lambda2))) * R;
                                	} else {
                                		tmp = acos((cos(lambda2) * 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 (lambda1 <= (-2.8d-5)) then
                                        tmp = acos(cos((lambda1 - lambda2))) * r
                                    else
                                        tmp = acos((cos(lambda2) * 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 (lambda1 <= -2.8e-5) {
                                		tmp = Math.acos(Math.cos((lambda1 - lambda2))) * R;
                                	} else {
                                		tmp = Math.acos((Math.cos(lambda2) * Math.cos(phi2))) * R;
                                	}
                                	return tmp;
                                }
                                
                                def code(R, lambda1, lambda2, phi1, phi2):
                                	tmp = 0
                                	if lambda1 <= -2.8e-5:
                                		tmp = math.acos(math.cos((lambda1 - lambda2))) * R
                                	else:
                                		tmp = math.acos((math.cos(lambda2) * math.cos(phi2))) * R
                                	return tmp
                                
                                function code(R, lambda1, lambda2, phi1, phi2)
                                	tmp = 0.0
                                	if (lambda1 <= -2.8e-5)
                                		tmp = Float64(acos(cos(Float64(lambda1 - lambda2))) * R);
                                	else
                                		tmp = Float64(acos(Float64(cos(lambda2) * cos(phi2))) * R);
                                	end
                                	return tmp
                                end
                                
                                function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
                                	tmp = 0.0;
                                	if (lambda1 <= -2.8e-5)
                                		tmp = acos(cos((lambda1 - lambda2))) * R;
                                	else
                                		tmp = acos((cos(lambda2) * cos(phi2))) * R;
                                	end
                                	tmp_2 = tmp;
                                end
                                
                                code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda1, -2.8e-5], N[(N[ArcCos[N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]
                                
                                \begin{array}{l}
                                
                                \\
                                \begin{array}{l}
                                \mathbf{if}\;\lambda_1 \leq -2.8 \cdot 10^{-5}:\\
                                \;\;\;\;\cos^{-1} \cos \left(\lambda_1 - \lambda_2\right) \cdot R\\
                                
                                \mathbf{else}:\\
                                \;\;\;\;\cos^{-1} \left(\cos \lambda_2 \cdot \cos \phi_2\right) \cdot R\\
                                
                                
                                \end{array}
                                \end{array}
                                
                                Derivation
                                1. Split input into 2 regimes
                                2. if lambda1 < -2.79999999999999996e-5

                                  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. sub-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                    if -2.79999999999999996e-5 < lambda1

                                    1. Initial program 78.6%

                                      \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                    2. Add Preprocessing
                                    3. 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.f6462.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 rewrites62.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 \]
                                    6. Taylor expanded in phi1 around 0

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

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

                                    Alternative 26: 22.1% accurate, 3.0× speedup?

                                    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -1.35 \cdot 10^{-8}:\\ \;\;\;\;\cos^{-1} \cos \lambda_1 \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \cos \lambda_2 \cdot R\\ \end{array} \end{array} \]
                                    (FPCore (R lambda1 lambda2 phi1 phi2)
                                     :precision binary64
                                     (if (<= lambda1 -1.35e-8)
                                       (* (acos (cos lambda1)) R)
                                       (* (acos (cos lambda2)) R)))
                                    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                    	double tmp;
                                    	if (lambda1 <= -1.35e-8) {
                                    		tmp = acos(cos(lambda1)) * R;
                                    	} else {
                                    		tmp = acos(cos(lambda2)) * 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 (lambda1 <= (-1.35d-8)) then
                                            tmp = acos(cos(lambda1)) * r
                                        else
                                            tmp = acos(cos(lambda2)) * r
                                        end if
                                        code = tmp
                                    end function
                                    
                                    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                    	double tmp;
                                    	if (lambda1 <= -1.35e-8) {
                                    		tmp = Math.acos(Math.cos(lambda1)) * R;
                                    	} else {
                                    		tmp = Math.acos(Math.cos(lambda2)) * R;
                                    	}
                                    	return tmp;
                                    }
                                    
                                    def code(R, lambda1, lambda2, phi1, phi2):
                                    	tmp = 0
                                    	if lambda1 <= -1.35e-8:
                                    		tmp = math.acos(math.cos(lambda1)) * R
                                    	else:
                                    		tmp = math.acos(math.cos(lambda2)) * R
                                    	return tmp
                                    
                                    function code(R, lambda1, lambda2, phi1, phi2)
                                    	tmp = 0.0
                                    	if (lambda1 <= -1.35e-8)
                                    		tmp = Float64(acos(cos(lambda1)) * R);
                                    	else
                                    		tmp = Float64(acos(cos(lambda2)) * R);
                                    	end
                                    	return tmp
                                    end
                                    
                                    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
                                    	tmp = 0.0;
                                    	if (lambda1 <= -1.35e-8)
                                    		tmp = acos(cos(lambda1)) * R;
                                    	else
                                    		tmp = acos(cos(lambda2)) * R;
                                    	end
                                    	tmp_2 = tmp;
                                    end
                                    
                                    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda1, -1.35e-8], N[(N[ArcCos[N[Cos[lambda1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[Cos[lambda2], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]
                                    
                                    \begin{array}{l}
                                    
                                    \\
                                    \begin{array}{l}
                                    \mathbf{if}\;\lambda_1 \leq -1.35 \cdot 10^{-8}:\\
                                    \;\;\;\;\cos^{-1} \cos \lambda_1 \cdot R\\
                                    
                                    \mathbf{else}:\\
                                    \;\;\;\;\cos^{-1} \cos \lambda_2 \cdot R\\
                                    
                                    
                                    \end{array}
                                    \end{array}
                                    
                                    Derivation
                                    1. Split input into 2 regimes
                                    2. if lambda1 < -1.35000000000000001e-8

                                      1. Initial program 63.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. sub-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                        \[\leadsto \cos^{-1} \cos \left(\lambda_1 - \lambda_2\right) \cdot R \]
                                      7. Step-by-step derivation
                                        1. Applied rewrites27.2%

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

                                          \[\leadsto \cos^{-1} \cos \lambda_1 \cdot R \]
                                        3. Step-by-step derivation
                                          1. Applied rewrites25.9%

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

                                          if -1.35000000000000001e-8 < lambda1

                                          1. Initial program 78.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                            \[\leadsto \cos^{-1} \cos \left(\lambda_1 - \lambda_2\right) \cdot R \]
                                          7. Step-by-step derivation
                                            1. Applied rewrites26.9%

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

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

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

                                            Alternative 27: 26.7% accurate, 3.0× speedup?

                                            \[\begin{array}{l} \\ \cos^{-1} \cos \left(\lambda_1 - \lambda_2\right) \cdot R \end{array} \]
                                            (FPCore (R lambda1 lambda2 phi1 phi2)
                                             :precision binary64
                                             (* (acos (cos (- lambda1 lambda2))) R))
                                            double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                            	return acos(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(cos((lambda1 - lambda2))) * r
                                            end function
                                            
                                            public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                            	return Math.acos(Math.cos((lambda1 - lambda2))) * R;
                                            }
                                            
                                            def code(R, lambda1, lambda2, phi1, phi2):
                                            	return math.acos(math.cos((lambda1 - lambda2))) * R
                                            
                                            function code(R, lambda1, lambda2, phi1, phi2)
                                            	return Float64(acos(cos(Float64(lambda1 - lambda2))) * R)
                                            end
                                            
                                            function tmp = code(R, lambda1, lambda2, phi1, phi2)
                                            	tmp = acos(cos((lambda1 - lambda2))) * R;
                                            end
                                            
                                            code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \cos^{-1} \cos \left(\lambda_1 - \lambda_2\right) \cdot R
                                            \end{array}
                                            
                                            Derivation
                                            1. Initial program 74.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. sub-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                              \[\leadsto \cos^{-1} \cos \left(\lambda_1 - \lambda_2\right) \cdot R \]
                                            7. Step-by-step derivation
                                              1. Applied rewrites26.9%

                                                \[\leadsto \cos^{-1} \cos \left(\lambda_1 - \lambda_2\right) \cdot R \]
                                              2. Add Preprocessing

                                              Alternative 28: 17.6% accurate, 3.0× speedup?

                                              \[\begin{array}{l} \\ \cos^{-1} \cos \lambda_1 \cdot R \end{array} \]
                                              (FPCore (R lambda1 lambda2 phi1 phi2)
                                               :precision binary64
                                               (* (acos (cos lambda1)) R))
                                              double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                              	return acos(cos(lambda1)) * 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(lambda1)) * r
                                              end function
                                              
                                              public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                              	return Math.acos(Math.cos(lambda1)) * R;
                                              }
                                              
                                              def code(R, lambda1, lambda2, phi1, phi2):
                                              	return math.acos(math.cos(lambda1)) * R
                                              
                                              function code(R, lambda1, lambda2, phi1, phi2)
                                              	return Float64(acos(cos(lambda1)) * R)
                                              end
                                              
                                              function tmp = code(R, lambda1, lambda2, phi1, phi2)
                                              	tmp = acos(cos(lambda1)) * R;
                                              end
                                              
                                              code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[Cos[lambda1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
                                              
                                              \begin{array}{l}
                                              
                                              \\
                                              \cos^{-1} \cos \lambda_1 \cdot R
                                              \end{array}
                                              
                                              Derivation
                                              1. Initial program 74.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. sub-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                \[\leadsto \cos^{-1} \cos \left(\lambda_1 - \lambda_2\right) \cdot R \]
                                              7. Step-by-step derivation
                                                1. Applied rewrites26.9%

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

                                                  \[\leadsto \cos^{-1} \cos \lambda_1 \cdot R \]
                                                3. Step-by-step derivation
                                                  1. Applied rewrites17.2%

                                                    \[\leadsto \cos^{-1} \cos \lambda_1 \cdot R \]
                                                  2. Add Preprocessing

                                                  Reproduce

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