Spherical law of cosines

Percentage Accurate: 73.7% → 94.1%
Time: 24.7s
Alternatives: 29
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 29 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.7% accurate, 1.0× speedup?

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

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

Alternative 1: 94.1% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \phi_1 \cdot \sin \phi_2\\ t_1 := \cos \phi_1 \cdot \cos \phi_2\\ \mathbf{if}\;t\_0 + t\_1 \cdot \cos \left(\lambda_1 - \lambda_2\right) \leq 1:\\ \;\;\;\;\cos^{-1} \left(t\_0 + t\_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left|\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \left(2 \cdot \pi\right)\right)\right|\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (sin phi1) (sin phi2))) (t_1 (* (cos phi1) (cos phi2))))
   (if (<= (+ t_0 (* t_1 (cos (- lambda1 lambda2)))) 1.0)
     (*
      (acos
       (+
        t_0
        (*
         t_1
         (+ (* (sin lambda1) (sin lambda2)) (* (cos lambda1) (cos lambda2))))))
      R)
     (* R (fabs (remainder (- lambda2 lambda1) (* 2.0 PI)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(phi1) * sin(phi2);
	double t_1 = cos(phi1) * cos(phi2);
	double tmp;
	if ((t_0 + (t_1 * cos((lambda1 - lambda2)))) <= 1.0) {
		tmp = acos((t_0 + (t_1 * ((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2)))))) * R;
	} else {
		tmp = R * fabs(remainder((lambda2 - lambda1), (2.0 * ((double) M_PI))));
	}
	return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.sin(phi1) * Math.sin(phi2);
	double t_1 = Math.cos(phi1) * Math.cos(phi2);
	double tmp;
	if ((t_0 + (t_1 * Math.cos((lambda1 - lambda2)))) <= 1.0) {
		tmp = Math.acos((t_0 + (t_1 * ((Math.sin(lambda1) * Math.sin(lambda2)) + (Math.cos(lambda1) * Math.cos(lambda2)))))) * R;
	} else {
		tmp = R * Math.abs(Math.IEEEremainder((lambda2 - lambda1), (2.0 * Math.PI)));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(phi1) * math.sin(phi2)
	t_1 = math.cos(phi1) * math.cos(phi2)
	tmp = 0
	if (t_0 + (t_1 * math.cos((lambda1 - lambda2)))) <= 1.0:
		tmp = math.acos((t_0 + (t_1 * ((math.sin(lambda1) * math.sin(lambda2)) + (math.cos(lambda1) * math.cos(lambda2)))))) * R
	else:
		tmp = R * math.fabs(math.remainder((lambda2 - lambda1), (2.0 * math.pi)))
	return tmp
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 + N[(t$95$1 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0], N[(N[ArcCos[N[(t$95$0 + N[(t$95$1 * N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(R * N[Abs[N[With[{TMP1 = N[(lambda2 - lambda1), $MachinePrecision], TMP2 = N[(2.0 * Pi), $MachinePrecision]}, TMP1 - Round[TMP1 / TMP2] * TMP2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;R \cdot \left|\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \left(2 \cdot \pi\right)\right)\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (*.f64 (sin.f64 phi1) (sin.f64 phi2)) (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (cos.f64 (-.f64 lambda1 lambda2)))) < 1

    1. Initial program 71.5%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      2. +-commutativeN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. sin-lowering-sin.f64N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f6492.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr92.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_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]

    if 1 < (+.f64 (*.f64 (sin.f64 phi1) (sin.f64 phi2)) (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (cos.f64 (-.f64 lambda1 lambda2))))

    1. Initial program 71.5%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6440.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified40.5%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      2. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      3. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(\lambda_2\right)\right) + \lambda_1\right)\right)\right)\right), R\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      5. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)\right), R\right) \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right), R\right) \]
      8. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      10. --lowering--.f6426.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), R\right) \]
    8. Simplified26.5%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      3. remainder-lowering-remainder.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\left(\lambda_1 - \lambda_2\right), \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      4. acos-cos-sN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\cos^{-1} \cos \left(\lambda_1 - \lambda_2\right), \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      5. cos-diffN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\cos^{-1} \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right), \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\cos^{-1} \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_1 \cdot \sin \lambda_2\right), \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      7. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\cos^{-1} \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right), \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      8. cos-diffN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\cos^{-1} \cos \left(\lambda_2 - \lambda_1\right), \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      9. acos-cos-sN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\left(\lambda_2 - \lambda_1\right), \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      10. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right), \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right), \mathsf{*.f64}\left(2, \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      12. PI-lowering-PI.f6420.0%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right), \mathsf{*.f64}\left(2, \mathsf{PI.f64}\left(\right)\right)\right)\right), R\right) \]
    10. Applied egg-rr20.0%

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

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

Alternative 2: 83.5% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\\ \mathbf{if}\;\phi_1 \leq -0.11:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, t\_0\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-25}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\frac{\pi}{2} - \sin^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t\_0\right)\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (cos phi2) (* (cos phi1) (cos (- lambda1 lambda2))))))
   (if (<= phi1 -0.11)
     (* R (acos (fma (sin phi2) (sin phi1) t_0)))
     (if (<= phi1 3.4e-25)
       (*
        R
        (acos
         (+
          (* phi1 (sin phi2))
          (*
           (* (cos phi1) (cos phi2))
           (fma
            (cos lambda2)
            (cos lambda1)
            (* (sin lambda1) (sin lambda2)))))))
       (* R (- (/ PI 2.0) (asin (+ (* (sin phi1) (sin phi2)) t_0))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos(phi2) * (cos(phi1) * cos((lambda1 - lambda2)));
	double tmp;
	if (phi1 <= -0.11) {
		tmp = R * acos(fma(sin(phi2), sin(phi1), t_0));
	} else if (phi1 <= 3.4e-25) {
		tmp = R * acos(((phi1 * sin(phi2)) + ((cos(phi1) * cos(phi2)) * fma(cos(lambda2), cos(lambda1), (sin(lambda1) * sin(lambda2))))));
	} else {
		tmp = R * ((((double) M_PI) / 2.0) - asin(((sin(phi1) * sin(phi2)) + t_0)));
	}
	return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(cos(phi2) * Float64(cos(phi1) * cos(Float64(lambda1 - lambda2))))
	tmp = 0.0
	if (phi1 <= -0.11)
		tmp = Float64(R * acos(fma(sin(phi2), sin(phi1), t_0)));
	elseif (phi1 <= 3.4e-25)
		tmp = Float64(R * acos(Float64(Float64(phi1 * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * fma(cos(lambda2), cos(lambda1), Float64(sin(lambda1) * sin(lambda2)))))));
	else
		tmp = Float64(R * Float64(Float64(pi / 2.0) - asin(Float64(Float64(sin(phi1) * sin(phi2)) + t_0))));
	end
	return tmp
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -0.11], N[(R * N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 3.4e-25], N[(R * N[ArcCos[N[(N[(phi1 * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(N[(Pi / 2.0), $MachinePrecision] - N[ArcSin[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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

\mathbf{else}:\\
\;\;\;\;R \cdot \left(\frac{\pi}{2} - \sin^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t\_0\right)\right)\\


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

    1. Initial program 78.5%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\left(\sin \phi_2 \cdot \sin \phi_1 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. fma-defineN/A

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \left(\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot \cos \phi_1\right)\right)\right), R\right) \]
      8. associate-*l*N/A

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_1\right)\right)\right)\right), R\right) \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right), R\right) \]
      13. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right), R\right) \]
      14. cos-lowering-cos.f6478.6%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{cos.f64}\left(\phi_1\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr78.6%

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

    if -0.110000000000000001 < phi1 < 3.40000000000000002e-25

    1. Initial program 66.8%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      3. fma-defineN/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{fma.f64}\left(\cos \lambda_2, \cos \lambda_1, \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. cos-lowering-cos.f64N/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \mathsf{cos.f64}\left(\lambda_1\right), \mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \mathsf{cos.f64}\left(\lambda_1\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sin-lowering-sin.f6486.4%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \mathsf{cos.f64}\left(\lambda_1\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr86.4%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\phi_1, \sin \phi_2\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \mathsf{cos.f64}\left(\lambda_1\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      2. sin-lowering-sin.f6486.4%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\phi_1, \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \mathsf{cos.f64}\left(\lambda_1\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    7. Simplified86.4%

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

    if 3.40000000000000002e-25 < phi1

    1. Initial program 72.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. acos-asinN/A

        \[\leadsto \mathsf{*.f64}\left(\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), R\right) \]
      2. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{2}\right), \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), R\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI}\left(\right), 2\right), \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), R\right) \]
      4. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \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), R\right) \]
      5. asin-lowering-asin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\left(\sin \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), R\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\left(\sin \phi_1 \cdot \sin \phi_2\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \phi_1, \sin \phi_2\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \sin \phi_2\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      10. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot \cos \phi_1\right)\right)\right)\right), R\right) \]
      12. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \phi_2 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      13. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\cos \phi_2, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      14. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      15. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      16. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      17. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      18. cos-lowering-cos.f6472.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{cos.f64}\left(\phi_1\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr72.5%

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

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

Alternative 3: 83.5% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\\ \mathbf{if}\;\phi_1 \leq -0.105:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, t\_0\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-25}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right) + \phi_1 \cdot \sin \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\frac{\pi}{2} - \sin^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t\_0\right)\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (cos phi2) (* (cos phi1) (cos (- lambda1 lambda2))))))
   (if (<= phi1 -0.105)
     (* R (acos (fma (sin phi2) (sin phi1) t_0)))
     (if (<= phi1 3.4e-25)
       (*
        R
        (acos
         (+
          (*
           (* (cos phi1) (cos phi2))
           (+ (* (sin lambda1) (sin lambda2)) (* (cos lambda1) (cos lambda2))))
          (* phi1 (sin phi2)))))
       (* R (- (/ PI 2.0) (asin (+ (* (sin phi1) (sin phi2)) t_0))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos(phi2) * (cos(phi1) * cos((lambda1 - lambda2)));
	double tmp;
	if (phi1 <= -0.105) {
		tmp = R * acos(fma(sin(phi2), sin(phi1), t_0));
	} else if (phi1 <= 3.4e-25) {
		tmp = R * acos((((cos(phi1) * cos(phi2)) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2)))) + (phi1 * sin(phi2))));
	} else {
		tmp = R * ((((double) M_PI) / 2.0) - asin(((sin(phi1) * sin(phi2)) + t_0)));
	}
	return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(cos(phi2) * Float64(cos(phi1) * cos(Float64(lambda1 - lambda2))))
	tmp = 0.0
	if (phi1 <= -0.105)
		tmp = Float64(R * acos(fma(sin(phi2), sin(phi1), t_0)));
	elseif (phi1 <= 3.4e-25)
		tmp = Float64(R * acos(Float64(Float64(Float64(cos(phi1) * cos(phi2)) * Float64(Float64(sin(lambda1) * sin(lambda2)) + Float64(cos(lambda1) * cos(lambda2)))) + Float64(phi1 * sin(phi2)))));
	else
		tmp = Float64(R * Float64(Float64(pi / 2.0) - asin(Float64(Float64(sin(phi1) * sin(phi2)) + t_0))));
	end
	return tmp
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -0.105], N[(R * N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 3.4e-25], N[(R * N[ArcCos[N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(phi1 * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(N[(Pi / 2.0), $MachinePrecision] - N[ArcSin[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-25}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right) + \phi_1 \cdot \sin \phi_2\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(\frac{\pi}{2} - \sin^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t\_0\right)\right)\\


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

    1. Initial program 78.5%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\left(\sin \phi_2 \cdot \sin \phi_1 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. fma-defineN/A

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \left(\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot \cos \phi_1\right)\right)\right), R\right) \]
      8. associate-*l*N/A

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_1\right)\right)\right)\right), R\right) \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right), R\right) \]
      13. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right), R\right) \]
      14. cos-lowering-cos.f6478.6%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{cos.f64}\left(\phi_1\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr78.6%

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

    if -0.104999999999999996 < phi1 < 3.40000000000000002e-25

    1. Initial program 66.8%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      2. +-commutativeN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. sin-lowering-sin.f64N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f6486.4%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr86.4%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\phi_1, \sin \phi_2\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      2. sin-lowering-sin.f6486.4%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\phi_1, \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    7. Simplified86.4%

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

    if 3.40000000000000002e-25 < phi1

    1. Initial program 72.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. acos-asinN/A

        \[\leadsto \mathsf{*.f64}\left(\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), R\right) \]
      2. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{2}\right), \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), R\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI}\left(\right), 2\right), \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), R\right) \]
      4. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \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), R\right) \]
      5. asin-lowering-asin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\left(\sin \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), R\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\left(\sin \phi_1 \cdot \sin \phi_2\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \phi_1, \sin \phi_2\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \sin \phi_2\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      10. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot \cos \phi_1\right)\right)\right)\right), R\right) \]
      12. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \phi_2 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      13. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\cos \phi_2, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      14. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      15. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      16. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      17. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      18. cos-lowering-cos.f6472.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{cos.f64}\left(\phi_1\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr72.5%

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

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

Alternative 4: 83.5% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\\ \mathbf{if}\;\phi_1 \leq -0.000405:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, t\_0\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-25}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \left(1 + -0.5 \cdot \left(\phi_1 \cdot \phi_1\right)\right) \cdot \left(\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\frac{\pi}{2} - \sin^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t\_0\right)\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (cos phi2) (* (cos phi1) (cos (- lambda1 lambda2))))))
   (if (<= phi1 -0.000405)
     (* R (acos (fma (sin phi2) (sin phi1) t_0)))
     (if (<= phi1 3.4e-25)
       (*
        R
        (acos
         (+
          (* phi1 (sin phi2))
          (*
           (+ 1.0 (* -0.5 (* phi1 phi1)))
           (*
            (cos phi2)
            (+
             (* (sin lambda1) (sin lambda2))
             (* (cos lambda1) (cos lambda2))))))))
       (* R (- (/ PI 2.0) (asin (+ (* (sin phi1) (sin phi2)) t_0))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos(phi2) * (cos(phi1) * cos((lambda1 - lambda2)));
	double tmp;
	if (phi1 <= -0.000405) {
		tmp = R * acos(fma(sin(phi2), sin(phi1), t_0));
	} else if (phi1 <= 3.4e-25) {
		tmp = R * acos(((phi1 * sin(phi2)) + ((1.0 + (-0.5 * (phi1 * phi1))) * (cos(phi2) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2)))))));
	} else {
		tmp = R * ((((double) M_PI) / 2.0) - asin(((sin(phi1) * sin(phi2)) + t_0)));
	}
	return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(cos(phi2) * Float64(cos(phi1) * cos(Float64(lambda1 - lambda2))))
	tmp = 0.0
	if (phi1 <= -0.000405)
		tmp = Float64(R * acos(fma(sin(phi2), sin(phi1), t_0)));
	elseif (phi1 <= 3.4e-25)
		tmp = Float64(R * acos(Float64(Float64(phi1 * sin(phi2)) + Float64(Float64(1.0 + Float64(-0.5 * Float64(phi1 * phi1))) * Float64(cos(phi2) * Float64(Float64(sin(lambda1) * sin(lambda2)) + Float64(cos(lambda1) * cos(lambda2))))))));
	else
		tmp = Float64(R * Float64(Float64(pi / 2.0) - asin(Float64(Float64(sin(phi1) * sin(phi2)) + t_0))));
	end
	return tmp
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -0.000405], N[(R * N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 3.4e-25], N[(R * N[ArcCos[N[(N[(phi1 * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 + N[(-0.5 * N[(phi1 * phi1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(N[(Pi / 2.0), $MachinePrecision] - N[ArcSin[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-25}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \left(1 + -0.5 \cdot \left(\phi_1 \cdot \phi_1\right)\right) \cdot \left(\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(\frac{\pi}{2} - \sin^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t\_0\right)\right)\\


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

    1. Initial program 78.5%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\left(\sin \phi_2 \cdot \sin \phi_1 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. fma-defineN/A

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \left(\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot \cos \phi_1\right)\right)\right), R\right) \]
      8. associate-*l*N/A

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_1\right)\right)\right)\right), R\right) \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right), R\right) \]
      13. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right), R\right) \]
      14. cos-lowering-cos.f6478.6%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{cos.f64}\left(\phi_1\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr78.6%

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

    if -4.0499999999999998e-4 < phi1 < 3.40000000000000002e-25

    1. Initial program 66.8%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      3. fma-defineN/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{fma.f64}\left(\cos \lambda_2, \cos \lambda_1, \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. cos-lowering-cos.f64N/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \mathsf{cos.f64}\left(\lambda_1\right), \mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \mathsf{cos.f64}\left(\lambda_1\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sin-lowering-sin.f6486.4%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \mathsf{cos.f64}\left(\lambda_1\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr86.4%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\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)}\right), R\right) \]
    6. Step-by-step derivation
      1. distribute-rgt-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\left(\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)\right), R\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\left(\left(\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)\right), R\right) \]
      3. associate-+l+N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\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)\right), R\right) \]
    7. Simplified86.4%

      \[\leadsto \cos^{-1} \color{blue}{\left(\phi_1 \cdot \sin \phi_2 + \left(-0.5 \cdot \left(\phi_1 \cdot \phi_1\right) + 1\right) \cdot \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 \]

    if 3.40000000000000002e-25 < phi1

    1. Initial program 72.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. acos-asinN/A

        \[\leadsto \mathsf{*.f64}\left(\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), R\right) \]
      2. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{2}\right), \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), R\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI}\left(\right), 2\right), \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), R\right) \]
      4. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \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), R\right) \]
      5. asin-lowering-asin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\left(\sin \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), R\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\left(\sin \phi_1 \cdot \sin \phi_2\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \phi_1, \sin \phi_2\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \sin \phi_2\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      10. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot \cos \phi_1\right)\right)\right)\right), R\right) \]
      12. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \phi_2 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      13. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\cos \phi_2, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      14. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      15. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      16. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      17. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      18. cos-lowering-cos.f6472.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{cos.f64}\left(\phi_1\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr72.5%

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

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

Alternative 5: 83.5% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\\ \mathbf{if}\;\phi_1 \leq -8.8 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, t\_0\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-25}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\frac{\pi}{2} - \sin^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t\_0\right)\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (cos phi2) (* (cos phi1) (cos (- lambda1 lambda2))))))
   (if (<= phi1 -8.8e-5)
     (* R (acos (fma (sin phi2) (sin phi1) t_0)))
     (if (<= phi1 3.4e-25)
       (*
        R
        (acos
         (+
          (* phi1 (sin phi2))
          (*
           (cos phi2)
           (+
            (* (sin lambda1) (sin lambda2))
            (* (cos lambda1) (cos lambda2)))))))
       (* R (- (/ PI 2.0) (asin (+ (* (sin phi1) (sin phi2)) t_0))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos(phi2) * (cos(phi1) * cos((lambda1 - lambda2)));
	double tmp;
	if (phi1 <= -8.8e-5) {
		tmp = R * acos(fma(sin(phi2), sin(phi1), t_0));
	} else if (phi1 <= 3.4e-25) {
		tmp = R * acos(((phi1 * sin(phi2)) + (cos(phi2) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2))))));
	} else {
		tmp = R * ((((double) M_PI) / 2.0) - asin(((sin(phi1) * sin(phi2)) + t_0)));
	}
	return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(cos(phi2) * Float64(cos(phi1) * cos(Float64(lambda1 - lambda2))))
	tmp = 0.0
	if (phi1 <= -8.8e-5)
		tmp = Float64(R * acos(fma(sin(phi2), sin(phi1), t_0)));
	elseif (phi1 <= 3.4e-25)
		tmp = Float64(R * acos(Float64(Float64(phi1 * sin(phi2)) + Float64(cos(phi2) * Float64(Float64(sin(lambda1) * sin(lambda2)) + Float64(cos(lambda1) * cos(lambda2)))))));
	else
		tmp = Float64(R * Float64(Float64(pi / 2.0) - asin(Float64(Float64(sin(phi1) * sin(phi2)) + t_0))));
	end
	return tmp
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -8.8e-5], N[(R * N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 3.4e-25], N[(R * N[ArcCos[N[(N[(phi1 * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(N[(Pi / 2.0), $MachinePrecision] - N[ArcSin[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-25}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(\frac{\pi}{2} - \sin^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t\_0\right)\right)\\


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

    1. Initial program 78.5%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\left(\sin \phi_2 \cdot \sin \phi_1 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. fma-defineN/A

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \left(\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot \cos \phi_1\right)\right)\right), R\right) \]
      8. associate-*l*N/A

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_1\right)\right)\right)\right), R\right) \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right), R\right) \]
      13. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right), R\right) \]
      14. cos-lowering-cos.f6478.6%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{cos.f64}\left(\phi_1\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr78.6%

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

    if -8.7999999999999998e-5 < phi1 < 3.40000000000000002e-25

    1. Initial program 66.8%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      2. +-commutativeN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. sin-lowering-sin.f64N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f6486.4%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr86.4%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\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)}\right), R\right) \]
    6. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\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)\right), R\right) \]
      2. +-lowering-+.f64N/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right), \left(\phi_1 \cdot \sin \phi_2\right)\right)\right), R\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\left(\cos \lambda_1 \cdot \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), \left(\phi_1 \cdot \sin \phi_2\right)\right)\right), R\right) \]
      6. *-lowering-*.f64N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), \left(\phi_1 \cdot \sin \phi_2\right)\right)\right), R\right) \]
      8. cos-lowering-cos.f64N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right)\right)\right), \left(\phi_1 \cdot \sin \phi_2\right)\right)\right), R\right) \]
      10. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right)\right)\right), \left(\phi_1 \cdot \sin \phi_2\right)\right)\right), R\right) \]
      11. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right)\right)\right), \left(\phi_1 \cdot \sin \phi_2\right)\right)\right), R\right) \]
      12. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right)\right)\right), \mathsf{*.f64}\left(\phi_1, \sin \phi_2\right)\right)\right), R\right) \]
      13. sin-lowering-sin.f6486.4%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right)\right)\right), \mathsf{*.f64}\left(\phi_1, \mathsf{sin.f64}\left(\phi_2\right)\right)\right)\right), R\right) \]
    7. Simplified86.4%

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

    if 3.40000000000000002e-25 < phi1

    1. Initial program 72.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. acos-asinN/A

        \[\leadsto \mathsf{*.f64}\left(\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), R\right) \]
      2. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{2}\right), \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), R\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI}\left(\right), 2\right), \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), R\right) \]
      4. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \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), R\right) \]
      5. asin-lowering-asin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\left(\sin \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), R\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\left(\sin \phi_1 \cdot \sin \phi_2\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \phi_1, \sin \phi_2\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \sin \phi_2\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      10. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot \cos \phi_1\right)\right)\right)\right), R\right) \]
      12. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \phi_2 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      13. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\cos \phi_2, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      14. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      15. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      16. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      17. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      18. cos-lowering-cos.f6472.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{cos.f64}\left(\phi_1\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr72.5%

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

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

Alternative 6: 83.4% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\\ \mathbf{if}\;\phi_1 \leq -6.5 \cdot 10^{-15}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, t\_0\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-25}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\frac{\pi}{2} - \sin^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t\_0\right)\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (cos phi2) (* (cos phi1) (cos (- lambda1 lambda2))))))
   (if (<= phi1 -6.5e-15)
     (* R (acos (fma (sin phi2) (sin phi1) t_0)))
     (if (<= phi1 3.4e-25)
       (*
        R
        (acos
         (*
          (cos phi2)
          (+
           (* (sin lambda1) (sin lambda2))
           (* (cos lambda1) (cos lambda2))))))
       (* R (- (/ PI 2.0) (asin (+ (* (sin phi1) (sin phi2)) t_0))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos(phi2) * (cos(phi1) * cos((lambda1 - lambda2)));
	double tmp;
	if (phi1 <= -6.5e-15) {
		tmp = R * acos(fma(sin(phi2), sin(phi1), t_0));
	} else if (phi1 <= 3.4e-25) {
		tmp = R * acos((cos(phi2) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2)))));
	} else {
		tmp = R * ((((double) M_PI) / 2.0) - asin(((sin(phi1) * sin(phi2)) + t_0)));
	}
	return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(cos(phi2) * Float64(cos(phi1) * cos(Float64(lambda1 - lambda2))))
	tmp = 0.0
	if (phi1 <= -6.5e-15)
		tmp = Float64(R * acos(fma(sin(phi2), sin(phi1), t_0)));
	elseif (phi1 <= 3.4e-25)
		tmp = Float64(R * acos(Float64(cos(phi2) * Float64(Float64(sin(lambda1) * sin(lambda2)) + Float64(cos(lambda1) * cos(lambda2))))));
	else
		tmp = Float64(R * Float64(Float64(pi / 2.0) - asin(Float64(Float64(sin(phi1) * sin(phi2)) + t_0))));
	end
	return tmp
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -6.5e-15], N[(R * N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 3.4e-25], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(N[(Pi / 2.0), $MachinePrecision] - N[ArcSin[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-25}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(\frac{\pi}{2} - \sin^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t\_0\right)\right)\\


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

    1. Initial program 78.5%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\left(\sin \phi_2 \cdot \sin \phi_1 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. fma-defineN/A

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \left(\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot \cos \phi_1\right)\right)\right), R\right) \]
      8. associate-*l*N/A

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_1\right)\right)\right)\right), R\right) \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right), R\right) \]
      13. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right), R\right) \]
      14. cos-lowering-cos.f6478.6%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{fma.f64}\left(\mathsf{sin.f64}\left(\phi_2\right), \mathsf{sin.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{cos.f64}\left(\phi_1\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr78.6%

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

    if -6.49999999999999991e-15 < phi1 < 3.40000000000000002e-25

    1. Initial program 66.8%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      2. +-commutativeN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. sin-lowering-sin.f64N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f6486.4%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr86.4%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\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)}\right), R\right) \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_2, \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), R\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\left(\cos \lambda_1 \cdot \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right)\right)\right)\right), R\right) \]
      9. sin-lowering-sin.f6486.4%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    7. Simplified86.4%

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

    if 3.40000000000000002e-25 < phi1

    1. Initial program 72.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. acos-asinN/A

        \[\leadsto \mathsf{*.f64}\left(\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), R\right) \]
      2. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{2}\right), \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), R\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI}\left(\right), 2\right), \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), R\right) \]
      4. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \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), R\right) \]
      5. asin-lowering-asin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\left(\sin \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), R\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\left(\sin \phi_1 \cdot \sin \phi_2\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \phi_1, \sin \phi_2\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \sin \phi_2\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      10. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot \cos \phi_1\right)\right)\right)\right), R\right) \]
      12. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \phi_2 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      13. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\cos \phi_2, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      14. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      15. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      16. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      17. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      18. cos-lowering-cos.f6472.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{cos.f64}\left(\phi_1\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr72.5%

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

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

Alternative 7: 83.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\\ \mathbf{if}\;\phi_1 \leq -6.5 \cdot 10^{-15}:\\ \;\;\;\;R \cdot \cos^{-1} t\_0\\ \mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-25}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\frac{\pi}{2} - \sin^{-1} t\_0\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0
         (+
          (* (sin phi1) (sin phi2))
          (* (cos phi2) (* (cos phi1) (cos (- lambda1 lambda2)))))))
   (if (<= phi1 -6.5e-15)
     (* R (acos t_0))
     (if (<= phi1 3.4e-25)
       (*
        R
        (acos
         (*
          (cos phi2)
          (+
           (* (sin lambda1) (sin lambda2))
           (* (cos lambda1) (cos lambda2))))))
       (* R (- (/ PI 2.0) (asin t_0)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (sin(phi1) * sin(phi2)) + (cos(phi2) * (cos(phi1) * cos((lambda1 - lambda2))));
	double tmp;
	if (phi1 <= -6.5e-15) {
		tmp = R * acos(t_0);
	} else if (phi1 <= 3.4e-25) {
		tmp = R * acos((cos(phi2) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2)))));
	} else {
		tmp = R * ((((double) M_PI) / 2.0) - asin(t_0));
	}
	return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (Math.sin(phi1) * Math.sin(phi2)) + (Math.cos(phi2) * (Math.cos(phi1) * Math.cos((lambda1 - lambda2))));
	double tmp;
	if (phi1 <= -6.5e-15) {
		tmp = R * Math.acos(t_0);
	} else if (phi1 <= 3.4e-25) {
		tmp = R * Math.acos((Math.cos(phi2) * ((Math.sin(lambda1) * Math.sin(lambda2)) + (Math.cos(lambda1) * Math.cos(lambda2)))));
	} else {
		tmp = R * ((Math.PI / 2.0) - Math.asin(t_0));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = (math.sin(phi1) * math.sin(phi2)) + (math.cos(phi2) * (math.cos(phi1) * math.cos((lambda1 - lambda2))))
	tmp = 0
	if phi1 <= -6.5e-15:
		tmp = R * math.acos(t_0)
	elif phi1 <= 3.4e-25:
		tmp = R * math.acos((math.cos(phi2) * ((math.sin(lambda1) * math.sin(lambda2)) + (math.cos(lambda1) * math.cos(lambda2)))))
	else:
		tmp = R * ((math.pi / 2.0) - math.asin(t_0))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(Float64(sin(phi1) * sin(phi2)) + Float64(cos(phi2) * Float64(cos(phi1) * cos(Float64(lambda1 - lambda2)))))
	tmp = 0.0
	if (phi1 <= -6.5e-15)
		tmp = Float64(R * acos(t_0));
	elseif (phi1 <= 3.4e-25)
		tmp = Float64(R * acos(Float64(cos(phi2) * Float64(Float64(sin(lambda1) * sin(lambda2)) + Float64(cos(lambda1) * cos(lambda2))))));
	else
		tmp = Float64(R * Float64(Float64(pi / 2.0) - asin(t_0)));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = (sin(phi1) * sin(phi2)) + (cos(phi2) * (cos(phi1) * cos((lambda1 - lambda2))));
	tmp = 0.0;
	if (phi1 <= -6.5e-15)
		tmp = R * acos(t_0);
	elseif (phi1 <= 3.4e-25)
		tmp = R * acos((cos(phi2) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2)))));
	else
		tmp = R * ((pi / 2.0) - asin(t_0));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -6.5e-15], N[(R * N[ArcCos[t$95$0], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 3.4e-25], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(N[(Pi / 2.0), $MachinePrecision] - N[ArcSin[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\\
\mathbf{if}\;\phi_1 \leq -6.5 \cdot 10^{-15}:\\
\;\;\;\;R \cdot \cos^{-1} t\_0\\

\mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-25}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(\frac{\pi}{2} - \sin^{-1} t\_0\right)\\


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

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

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

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

    if -6.49999999999999991e-15 < phi1 < 3.40000000000000002e-25

    1. Initial program 66.8%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      2. +-commutativeN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. sin-lowering-sin.f64N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f6486.4%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr86.4%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\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)}\right), R\right) \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_2, \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), R\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\left(\cos \lambda_1 \cdot \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right)\right)\right)\right), R\right) \]
      9. sin-lowering-sin.f6486.4%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    7. Simplified86.4%

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

    if 3.40000000000000002e-25 < phi1

    1. Initial program 72.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. acos-asinN/A

        \[\leadsto \mathsf{*.f64}\left(\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), R\right) \]
      2. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{2}\right), \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), R\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI}\left(\right), 2\right), \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), R\right) \]
      4. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \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), R\right) \]
      5. asin-lowering-asin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\left(\sin \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), R\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\left(\sin \phi_1 \cdot \sin \phi_2\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \phi_1, \sin \phi_2\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \sin \phi_2\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right), R\right) \]
      10. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot \cos \phi_1\right)\right)\right)\right), R\right) \]
      12. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \phi_2 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      13. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\cos \phi_2, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      14. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      15. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      16. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      17. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \cos \phi_1\right)\right)\right)\right)\right), R\right) \]
      18. cos-lowering-cos.f6472.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right), \mathsf{cos.f64}\left(\phi_1\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr72.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -6.5 \cdot 10^{-15}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-25}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\frac{\pi}{2} - \sin^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 83.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\\ \mathbf{if}\;\phi_1 \leq -6.5 \cdot 10^{-15}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-25}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0
         (*
          R
          (acos
           (+
            (* (sin phi1) (sin phi2))
            (* (cos phi2) (* (cos phi1) (cos (- lambda1 lambda2)))))))))
   (if (<= phi1 -6.5e-15)
     t_0
     (if (<= phi1 3.4e-25)
       (*
        R
        (acos
         (*
          (cos phi2)
          (+
           (* (sin lambda1) (sin lambda2))
           (* (cos lambda1) (cos lambda2))))))
       t_0))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * acos(((sin(phi1) * sin(phi2)) + (cos(phi2) * (cos(phi1) * cos((lambda1 - lambda2))))));
	double tmp;
	if (phi1 <= -6.5e-15) {
		tmp = t_0;
	} else if (phi1 <= 3.4e-25) {
		tmp = R * acos((cos(phi2) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2)))));
	} else {
		tmp = t_0;
	}
	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 = r * acos(((sin(phi1) * sin(phi2)) + (cos(phi2) * (cos(phi1) * cos((lambda1 - lambda2))))))
    if (phi1 <= (-6.5d-15)) then
        tmp = t_0
    else if (phi1 <= 3.4d-25) then
        tmp = r * acos((cos(phi2) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2)))))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * Math.acos(((Math.sin(phi1) * Math.sin(phi2)) + (Math.cos(phi2) * (Math.cos(phi1) * Math.cos((lambda1 - lambda2))))));
	double tmp;
	if (phi1 <= -6.5e-15) {
		tmp = t_0;
	} else if (phi1 <= 3.4e-25) {
		tmp = R * Math.acos((Math.cos(phi2) * ((Math.sin(lambda1) * Math.sin(lambda2)) + (Math.cos(lambda1) * Math.cos(lambda2)))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = R * math.acos(((math.sin(phi1) * math.sin(phi2)) + (math.cos(phi2) * (math.cos(phi1) * math.cos((lambda1 - lambda2))))))
	tmp = 0
	if phi1 <= -6.5e-15:
		tmp = t_0
	elif phi1 <= 3.4e-25:
		tmp = R * math.acos((math.cos(phi2) * ((math.sin(lambda1) * math.sin(lambda2)) + (math.cos(lambda1) * math.cos(lambda2)))))
	else:
		tmp = t_0
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(R * acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(cos(phi2) * Float64(cos(phi1) * cos(Float64(lambda1 - lambda2)))))))
	tmp = 0.0
	if (phi1 <= -6.5e-15)
		tmp = t_0;
	elseif (phi1 <= 3.4e-25)
		tmp = Float64(R * acos(Float64(cos(phi2) * Float64(Float64(sin(lambda1) * sin(lambda2)) + Float64(cos(lambda1) * cos(lambda2))))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = R * acos(((sin(phi1) * sin(phi2)) + (cos(phi2) * (cos(phi1) * cos((lambda1 - lambda2))))));
	tmp = 0.0;
	if (phi1 <= -6.5e-15)
		tmp = t_0;
	elseif (phi1 <= 3.4e-25)
		tmp = R * acos((cos(phi2) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2)))));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(R * N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -6.5e-15], t$95$0, If[LessEqual[phi1, 3.4e-25], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\\
\mathbf{if}\;\phi_1 \leq -6.5 \cdot 10^{-15}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-25}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi1 < -6.49999999999999991e-15 or 3.40000000000000002e-25 < phi1

    1. Initial program 75.5%

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

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

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

    if -6.49999999999999991e-15 < phi1 < 3.40000000000000002e-25

    1. Initial program 66.8%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      2. +-commutativeN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. sin-lowering-sin.f64N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f6486.4%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr86.4%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\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)}\right), R\right) \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_2, \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), R\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\left(\cos \lambda_1 \cdot \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right)\right)\right)\right), R\right) \]
      9. sin-lowering-sin.f6486.4%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    7. Simplified86.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -6.5 \cdot 10^{-15}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-25}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 83.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\\ \mathbf{if}\;\phi_1 \leq -1.15 \cdot 10^{-15}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-25}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0
         (*
          R
          (acos
           (+
            (* (sin phi1) (sin phi2))
            (* (cos phi1) (* (cos phi2) (cos (- lambda2 lambda1)))))))))
   (if (<= phi1 -1.15e-15)
     t_0
     (if (<= phi1 3.4e-25)
       (*
        R
        (acos
         (*
          (cos phi2)
          (+
           (* (sin lambda1) (sin lambda2))
           (* (cos lambda1) (cos lambda2))))))
       t_0))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * acos(((sin(phi1) * sin(phi2)) + (cos(phi1) * (cos(phi2) * cos((lambda2 - lambda1))))));
	double tmp;
	if (phi1 <= -1.15e-15) {
		tmp = t_0;
	} else if (phi1 <= 3.4e-25) {
		tmp = R * acos((cos(phi2) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2)))));
	} else {
		tmp = t_0;
	}
	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 = r * acos(((sin(phi1) * sin(phi2)) + (cos(phi1) * (cos(phi2) * cos((lambda2 - lambda1))))))
    if (phi1 <= (-1.15d-15)) then
        tmp = t_0
    else if (phi1 <= 3.4d-25) then
        tmp = r * acos((cos(phi2) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2)))))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * Math.acos(((Math.sin(phi1) * Math.sin(phi2)) + (Math.cos(phi1) * (Math.cos(phi2) * Math.cos((lambda2 - lambda1))))));
	double tmp;
	if (phi1 <= -1.15e-15) {
		tmp = t_0;
	} else if (phi1 <= 3.4e-25) {
		tmp = R * Math.acos((Math.cos(phi2) * ((Math.sin(lambda1) * Math.sin(lambda2)) + (Math.cos(lambda1) * Math.cos(lambda2)))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = R * math.acos(((math.sin(phi1) * math.sin(phi2)) + (math.cos(phi1) * (math.cos(phi2) * math.cos((lambda2 - lambda1))))))
	tmp = 0
	if phi1 <= -1.15e-15:
		tmp = t_0
	elif phi1 <= 3.4e-25:
		tmp = R * math.acos((math.cos(phi2) * ((math.sin(lambda1) * math.sin(lambda2)) + (math.cos(lambda1) * math.cos(lambda2)))))
	else:
		tmp = t_0
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(R * acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(cos(phi1) * Float64(cos(phi2) * cos(Float64(lambda2 - lambda1)))))))
	tmp = 0.0
	if (phi1 <= -1.15e-15)
		tmp = t_0;
	elseif (phi1 <= 3.4e-25)
		tmp = Float64(R * acos(Float64(cos(phi2) * Float64(Float64(sin(lambda1) * sin(lambda2)) + Float64(cos(lambda1) * cos(lambda2))))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = R * acos(((sin(phi1) * sin(phi2)) + (cos(phi1) * (cos(phi2) * cos((lambda2 - lambda1))))));
	tmp = 0.0;
	if (phi1 <= -1.15e-15)
		tmp = t_0;
	elseif (phi1 <= 3.4e-25)
		tmp = R * acos((cos(phi2) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2)))));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(R * N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -1.15e-15], t$95$0, If[LessEqual[phi1, 3.4e-25], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\\
\mathbf{if}\;\phi_1 \leq -1.15 \cdot 10^{-15}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-25}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi1 < -1.14999999999999995e-15 or 3.40000000000000002e-25 < phi1

    1. Initial program 75.5%

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

      \[\leadsto \mathsf{*.f64}\left(\color{blue}{\cos^{-1} \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)}, R\right) \]
    4. Step-by-step derivation
      1. acos-lowering-acos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\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)\right), R\right) \]
      2. +-lowering-+.f64N/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right), \left(\sin \phi_1 \cdot \sin \phi_2\right)\right)\right), R\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\cos \phi_2, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), \left(\sin \phi_1 \cdot \sin \phi_2\right)\right)\right), R\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), \left(\sin \phi_1 \cdot \sin \phi_2\right)\right)\right), R\right) \]
      7. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), \left(\sin \phi_1 \cdot \sin \phi_2\right)\right)\right), R\right) \]
      8. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), \left(\sin \phi_1 \cdot \sin \phi_2\right)\right)\right), R\right) \]
      9. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), \left(\sin \phi_1 \cdot \sin \phi_2\right)\right)\right), R\right) \]
      10. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), \left(\sin \phi_1 \cdot \sin \phi_2\right)\right)\right), R\right) \]
      11. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), \left(\sin \phi_1 \cdot \sin \phi_2\right)\right)\right), R\right) \]
      12. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), \left(\sin \phi_1 \cdot \sin \phi_2\right)\right)\right), R\right) \]
      13. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), \left(\sin \phi_1 \cdot \sin \phi_2\right)\right)\right), R\right) \]
      14. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), \left(\sin \phi_1 \cdot \sin \phi_2\right)\right)\right), R\right) \]
      15. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), \left(\sin \phi_1 \cdot \sin \phi_2\right)\right)\right), R\right) \]
      16. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), \left(\sin \phi_1 \cdot \sin \phi_2\right)\right)\right), R\right) \]
      17. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), \mathsf{*.f64}\left(\sin \phi_1, \sin \phi_2\right)\right)\right), R\right) \]
    5. Simplified75.5%

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

    if -1.14999999999999995e-15 < phi1 < 3.40000000000000002e-25

    1. Initial program 66.8%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      2. +-commutativeN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. sin-lowering-sin.f64N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f6486.4%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr86.4%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\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)}\right), R\right) \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_2, \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), R\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\left(\cos \lambda_1 \cdot \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right)\right)\right)\right), R\right) \]
      9. sin-lowering-sin.f6486.4%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    7. Simplified86.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.15 \cdot 10^{-15}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\\ \mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-25}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 73.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\lambda_1 \leq -2.7 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t\_0 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \lambda_1\right)\right)\\ \mathbf{elif}\;\lambda_1 \leq 6.8 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t\_0 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (sin phi1) (sin phi2))))
   (if (<= lambda1 -2.7e-5)
     (* R (acos (+ t_0 (* (cos phi1) (* (cos phi2) (cos lambda1))))))
     (if (<= lambda1 6.8e-6)
       (* R (acos (+ t_0 (* (cos phi2) (* (cos phi1) (cos lambda2))))))
       (*
        R
        (acos
         (*
          (cos phi2)
          (+
           (* (sin lambda1) (sin lambda2))
           (* (cos lambda1) (cos lambda2))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(phi1) * sin(phi2);
	double tmp;
	if (lambda1 <= -2.7e-5) {
		tmp = R * acos((t_0 + (cos(phi1) * (cos(phi2) * cos(lambda1)))));
	} else if (lambda1 <= 6.8e-6) {
		tmp = R * acos((t_0 + (cos(phi2) * (cos(phi1) * cos(lambda2)))));
	} else {
		tmp = R * acos((cos(phi2) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2)))));
	}
	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 = sin(phi1) * sin(phi2)
    if (lambda1 <= (-2.7d-5)) then
        tmp = r * acos((t_0 + (cos(phi1) * (cos(phi2) * cos(lambda1)))))
    else if (lambda1 <= 6.8d-6) then
        tmp = r * acos((t_0 + (cos(phi2) * (cos(phi1) * cos(lambda2)))))
    else
        tmp = r * acos((cos(phi2) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2)))))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.sin(phi1) * Math.sin(phi2);
	double tmp;
	if (lambda1 <= -2.7e-5) {
		tmp = R * Math.acos((t_0 + (Math.cos(phi1) * (Math.cos(phi2) * Math.cos(lambda1)))));
	} else if (lambda1 <= 6.8e-6) {
		tmp = R * Math.acos((t_0 + (Math.cos(phi2) * (Math.cos(phi1) * Math.cos(lambda2)))));
	} else {
		tmp = R * Math.acos((Math.cos(phi2) * ((Math.sin(lambda1) * Math.sin(lambda2)) + (Math.cos(lambda1) * Math.cos(lambda2)))));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(phi1) * math.sin(phi2)
	tmp = 0
	if lambda1 <= -2.7e-5:
		tmp = R * math.acos((t_0 + (math.cos(phi1) * (math.cos(phi2) * math.cos(lambda1)))))
	elif lambda1 <= 6.8e-6:
		tmp = R * math.acos((t_0 + (math.cos(phi2) * (math.cos(phi1) * math.cos(lambda2)))))
	else:
		tmp = R * math.acos((math.cos(phi2) * ((math.sin(lambda1) * math.sin(lambda2)) + (math.cos(lambda1) * math.cos(lambda2)))))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(sin(phi1) * sin(phi2))
	tmp = 0.0
	if (lambda1 <= -2.7e-5)
		tmp = Float64(R * acos(Float64(t_0 + Float64(cos(phi1) * Float64(cos(phi2) * cos(lambda1))))));
	elseif (lambda1 <= 6.8e-6)
		tmp = Float64(R * acos(Float64(t_0 + Float64(cos(phi2) * Float64(cos(phi1) * cos(lambda2))))));
	else
		tmp = Float64(R * acos(Float64(cos(phi2) * Float64(Float64(sin(lambda1) * sin(lambda2)) + Float64(cos(lambda1) * cos(lambda2))))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(phi1) * sin(phi2);
	tmp = 0.0;
	if (lambda1 <= -2.7e-5)
		tmp = R * acos((t_0 + (cos(phi1) * (cos(phi2) * cos(lambda1)))));
	elseif (lambda1 <= 6.8e-6)
		tmp = R * acos((t_0 + (cos(phi2) * (cos(phi1) * cos(lambda2)))));
	else
		tmp = R * acos((cos(phi2) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2)))));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda1, -2.7e-5], N[(R * N[ArcCos[N[(t$95$0 + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda1, 6.8e-6], N[(R * N[ArcCos[N[(t$95$0 + N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \phi_1 \cdot \sin \phi_2\\
\mathbf{if}\;\lambda_1 \leq -2.7 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t\_0 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \lambda_1\right)\right)\\

\mathbf{elif}\;\lambda_1 \leq 6.8 \cdot 10^{-6}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t\_0 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \lambda_2\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if lambda1 < -2.6999999999999999e-5

    1. Initial program 61.5%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      2. +-commutativeN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. sin-lowering-sin.f64N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f6499.2%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr99.2%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\left(\sin \phi_1 \cdot \sin \phi_2 + \cos \lambda_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\right), R\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\left(\sin \phi_1 \cdot \sin \phi_2\right), \left(\cos \lambda_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\right)\right), R\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \phi_1, \sin \phi_2\right), \left(\cos \lambda_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\right)\right), R\right) \]
      4. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \sin \phi_2\right), \left(\cos \lambda_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\right)\right), R\right) \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\right)\right), R\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_1\right)\right)\right), R\right) \]
      7. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \lambda_1\right)\right)\right)\right), R\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\cos \phi_1, \left(\cos \phi_2 \cdot \cos \lambda_1\right)\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \phi_2 \cdot \cos \lambda_1\right)\right)\right)\right), R\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\cos \phi_2, \cos \lambda_1\right)\right)\right)\right), R\right) \]
      11. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \lambda_1\right)\right)\right)\right), R\right) \]
      12. cos-lowering-cos.f6459.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\lambda_1\right)\right)\right)\right)\right), R\right) \]
    7. Simplified59.8%

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

    if -2.6999999999999999e-5 < lambda1 < 6.80000000000000012e-6

    1. Initial program 84.8%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      2. +-commutativeN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. sin-lowering-sin.f64N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f6485.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr85.5%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\left(\sin \phi_1 \cdot \sin \phi_2 + \cos \lambda_2 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\right), R\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2\right)\right), R\right) \]
      3. associate-*r*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \lambda_2\right)\right)\right), R\right) \]
      4. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\left(\sin \phi_1 \cdot \sin \phi_2\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \phi_1, \sin \phi_2\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \sin \phi_2\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) \cdot \cos \phi_1\right)\right)\right), R\right) \]
      10. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\left(\cos \phi_2 \cdot \cos \lambda_2\right) \cdot \cos \phi_1\right)\right)\right), R\right) \]
      11. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \phi_2 \cdot \left(\cos \lambda_2 \cdot \cos \phi_1\right)\right)\right)\right), R\right) \]
      12. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\cos \phi_2, \left(\cos \lambda_2 \cdot \cos \phi_1\right)\right)\right)\right), R\right) \]
      13. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \lambda_2 \cdot \cos \phi_1\right)\right)\right)\right), R\right) \]
      14. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \phi_1 \cdot \cos \lambda_2\right)\right)\right)\right), R\right) \]
      15. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\cos \phi_1, \cos \lambda_2\right)\right)\right)\right), R\right) \]
      16. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \lambda_2\right)\right)\right)\right), R\right) \]
      17. cos-lowering-cos.f6484.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    7. Simplified84.8%

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

    if 6.80000000000000012e-6 < lambda1

    1. Initial program 58.7%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      2. +-commutativeN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. sin-lowering-sin.f64N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f6499.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr99.1%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\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)}\right), R\right) \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_2, \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), R\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\left(\cos \lambda_1 \cdot \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right)\right)\right)\right), R\right) \]
      9. sin-lowering-sin.f6456.7%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    7. Simplified56.7%

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

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

Alternative 11: 73.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\lambda_1 \leq -3.5 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t\_0 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \lambda_1\right)\right)\\ \mathbf{elif}\;\lambda_1 \leq 8.2 \cdot 10^{-6}:\\ \;\;\;\;R \cdot \cos^{-1} \left(t\_0 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (sin phi1) (sin phi2))))
   (if (<= lambda1 -3.5e-6)
     (* R (acos (+ t_0 (* (cos phi1) (* (cos phi2) (cos lambda1))))))
     (if (<= lambda1 8.2e-6)
       (* R (acos (+ t_0 (* (cos phi1) (* (cos phi2) (cos lambda2))))))
       (*
        R
        (acos
         (*
          (cos phi2)
          (+
           (* (sin lambda1) (sin lambda2))
           (* (cos lambda1) (cos lambda2))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(phi1) * sin(phi2);
	double tmp;
	if (lambda1 <= -3.5e-6) {
		tmp = R * acos((t_0 + (cos(phi1) * (cos(phi2) * cos(lambda1)))));
	} else if (lambda1 <= 8.2e-6) {
		tmp = R * acos((t_0 + (cos(phi1) * (cos(phi2) * cos(lambda2)))));
	} else {
		tmp = R * acos((cos(phi2) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2)))));
	}
	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 = sin(phi1) * sin(phi2)
    if (lambda1 <= (-3.5d-6)) then
        tmp = r * acos((t_0 + (cos(phi1) * (cos(phi2) * cos(lambda1)))))
    else if (lambda1 <= 8.2d-6) then
        tmp = r * acos((t_0 + (cos(phi1) * (cos(phi2) * cos(lambda2)))))
    else
        tmp = r * acos((cos(phi2) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2)))))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.sin(phi1) * Math.sin(phi2);
	double tmp;
	if (lambda1 <= -3.5e-6) {
		tmp = R * Math.acos((t_0 + (Math.cos(phi1) * (Math.cos(phi2) * Math.cos(lambda1)))));
	} else if (lambda1 <= 8.2e-6) {
		tmp = R * Math.acos((t_0 + (Math.cos(phi1) * (Math.cos(phi2) * Math.cos(lambda2)))));
	} else {
		tmp = R * Math.acos((Math.cos(phi2) * ((Math.sin(lambda1) * Math.sin(lambda2)) + (Math.cos(lambda1) * Math.cos(lambda2)))));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.sin(phi1) * math.sin(phi2)
	tmp = 0
	if lambda1 <= -3.5e-6:
		tmp = R * math.acos((t_0 + (math.cos(phi1) * (math.cos(phi2) * math.cos(lambda1)))))
	elif lambda1 <= 8.2e-6:
		tmp = R * math.acos((t_0 + (math.cos(phi1) * (math.cos(phi2) * math.cos(lambda2)))))
	else:
		tmp = R * math.acos((math.cos(phi2) * ((math.sin(lambda1) * math.sin(lambda2)) + (math.cos(lambda1) * math.cos(lambda2)))))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(sin(phi1) * sin(phi2))
	tmp = 0.0
	if (lambda1 <= -3.5e-6)
		tmp = Float64(R * acos(Float64(t_0 + Float64(cos(phi1) * Float64(cos(phi2) * cos(lambda1))))));
	elseif (lambda1 <= 8.2e-6)
		tmp = Float64(R * acos(Float64(t_0 + Float64(cos(phi1) * Float64(cos(phi2) * cos(lambda2))))));
	else
		tmp = Float64(R * acos(Float64(cos(phi2) * Float64(Float64(sin(lambda1) * sin(lambda2)) + Float64(cos(lambda1) * cos(lambda2))))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(phi1) * sin(phi2);
	tmp = 0.0;
	if (lambda1 <= -3.5e-6)
		tmp = R * acos((t_0 + (cos(phi1) * (cos(phi2) * cos(lambda1)))));
	elseif (lambda1 <= 8.2e-6)
		tmp = R * acos((t_0 + (cos(phi1) * (cos(phi2) * cos(lambda2)))));
	else
		tmp = R * acos((cos(phi2) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2)))));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda1, -3.5e-6], N[(R * N[ArcCos[N[(t$95$0 + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda1, 8.2e-6], N[(R * N[ArcCos[N[(t$95$0 + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \phi_1 \cdot \sin \phi_2\\
\mathbf{if}\;\lambda_1 \leq -3.5 \cdot 10^{-6}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t\_0 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \lambda_1\right)\right)\\

\mathbf{elif}\;\lambda_1 \leq 8.2 \cdot 10^{-6}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t\_0 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \lambda_2\right)\right)\\

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


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

    1. Initial program 61.5%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      2. +-commutativeN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. sin-lowering-sin.f64N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f6499.2%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr99.2%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\left(\sin \phi_1 \cdot \sin \phi_2 + \cos \lambda_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\right), R\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\left(\sin \phi_1 \cdot \sin \phi_2\right), \left(\cos \lambda_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\right)\right), R\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \phi_1, \sin \phi_2\right), \left(\cos \lambda_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\right)\right), R\right) \]
      4. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \sin \phi_2\right), \left(\cos \lambda_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\right)\right), R\right) \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\right)\right), R\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_1\right)\right)\right), R\right) \]
      7. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \lambda_1\right)\right)\right)\right), R\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\cos \phi_1, \left(\cos \phi_2 \cdot \cos \lambda_1\right)\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \phi_2 \cdot \cos \lambda_1\right)\right)\right)\right), R\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\cos \phi_2, \cos \lambda_1\right)\right)\right)\right), R\right) \]
      11. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \lambda_1\right)\right)\right)\right), R\right) \]
      12. cos-lowering-cos.f6459.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\lambda_1\right)\right)\right)\right)\right), R\right) \]
    7. Simplified59.8%

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

    if -3.49999999999999995e-6 < lambda1 < 8.1999999999999994e-6

    1. Initial program 84.8%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\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)}\right), R\right) \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\left(\sin \phi_1 \cdot \sin \phi_2\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \phi_1, \sin \phi_2\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      4. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \sin \phi_2\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\cos \phi_1, \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\cos \phi_2, \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      10. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \lambda_2\right)\right)\right)\right), R\right) \]
      11. cos-lowering-cos.f6484.7%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    5. Simplified84.7%

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

    if 8.1999999999999994e-6 < lambda1

    1. Initial program 58.7%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      2. +-commutativeN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. sin-lowering-sin.f64N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f6499.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr99.1%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\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)}\right), R\right) \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_2, \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), R\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\left(\cos \lambda_1 \cdot \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right)\right)\right)\right), R\right) \]
      9. sin-lowering-sin.f6456.7%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    7. Simplified56.7%

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

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

Alternative 12: 73.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\\ \mathbf{if}\;\phi_2 \leq -0.028:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \lambda_1\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 5.9 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot t\_0\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0
         (+ (* (sin lambda1) (sin lambda2)) (* (cos lambda1) (cos lambda2)))))
   (if (<= phi2 -0.028)
     (*
      R
      (acos
       (+
        (* (sin phi1) (sin phi2))
        (* (cos phi1) (* (cos phi2) (cos lambda1))))))
     (if (<= phi2 5.9e-5)
       (* R (acos (* (cos phi1) t_0)))
       (* R (acos (* (cos phi2) t_0)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2));
	double tmp;
	if (phi2 <= -0.028) {
		tmp = R * acos(((sin(phi1) * sin(phi2)) + (cos(phi1) * (cos(phi2) * cos(lambda1)))));
	} else if (phi2 <= 5.9e-5) {
		tmp = R * acos((cos(phi1) * t_0));
	} else {
		tmp = R * acos((cos(phi2) * t_0));
	}
	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 = (sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2))
    if (phi2 <= (-0.028d0)) then
        tmp = r * acos(((sin(phi1) * sin(phi2)) + (cos(phi1) * (cos(phi2) * cos(lambda1)))))
    else if (phi2 <= 5.9d-5) then
        tmp = r * acos((cos(phi1) * t_0))
    else
        tmp = r * acos((cos(phi2) * t_0))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (Math.sin(lambda1) * Math.sin(lambda2)) + (Math.cos(lambda1) * Math.cos(lambda2));
	double tmp;
	if (phi2 <= -0.028) {
		tmp = R * Math.acos(((Math.sin(phi1) * Math.sin(phi2)) + (Math.cos(phi1) * (Math.cos(phi2) * Math.cos(lambda1)))));
	} else if (phi2 <= 5.9e-5) {
		tmp = R * Math.acos((Math.cos(phi1) * t_0));
	} else {
		tmp = R * Math.acos((Math.cos(phi2) * t_0));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = (math.sin(lambda1) * math.sin(lambda2)) + (math.cos(lambda1) * math.cos(lambda2))
	tmp = 0
	if phi2 <= -0.028:
		tmp = R * math.acos(((math.sin(phi1) * math.sin(phi2)) + (math.cos(phi1) * (math.cos(phi2) * math.cos(lambda1)))))
	elif phi2 <= 5.9e-5:
		tmp = R * math.acos((math.cos(phi1) * t_0))
	else:
		tmp = R * math.acos((math.cos(phi2) * t_0))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(Float64(sin(lambda1) * sin(lambda2)) + Float64(cos(lambda1) * cos(lambda2)))
	tmp = 0.0
	if (phi2 <= -0.028)
		tmp = Float64(R * acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(cos(phi1) * Float64(cos(phi2) * cos(lambda1))))));
	elseif (phi2 <= 5.9e-5)
		tmp = Float64(R * acos(Float64(cos(phi1) * t_0)));
	else
		tmp = Float64(R * acos(Float64(cos(phi2) * t_0)));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = (sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2));
	tmp = 0.0;
	if (phi2 <= -0.028)
		tmp = R * acos(((sin(phi1) * sin(phi2)) + (cos(phi1) * (cos(phi2) * cos(lambda1)))));
	elseif (phi2 <= 5.9e-5)
		tmp = R * acos((cos(phi1) * t_0));
	else
		tmp = R * acos((cos(phi2) * t_0));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -0.028], N[(R * N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 5.9e-5], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\\
\mathbf{if}\;\phi_2 \leq -0.028:\\
\;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \lambda_1\right)\right)\\

\mathbf{elif}\;\phi_2 \leq 5.9 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t\_0\right)\\

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


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

    1. Initial program 74.8%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      2. +-commutativeN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. sin-lowering-sin.f64N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f6498.9%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr98.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_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
    5. Taylor expanded in lambda2 around 0

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\left(\sin \phi_1 \cdot \sin \phi_2 + \cos \lambda_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\right), R\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\left(\sin \phi_1 \cdot \sin \phi_2\right), \left(\cos \lambda_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\right)\right), R\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \phi_1, \sin \phi_2\right), \left(\cos \lambda_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\right)\right), R\right) \]
      4. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \sin \phi_2\right), \left(\cos \lambda_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\right)\right), R\right) \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\right)\right), R\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_1\right)\right)\right), R\right) \]
      7. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \lambda_1\right)\right)\right)\right), R\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\cos \phi_1, \left(\cos \phi_2 \cdot \cos \lambda_1\right)\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \phi_2 \cdot \cos \lambda_1\right)\right)\right)\right), R\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\cos \phi_2, \cos \lambda_1\right)\right)\right)\right), R\right) \]
      11. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \lambda_1\right)\right)\right)\right), R\right) \]
      12. cos-lowering-cos.f6459.2%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\lambda_1\right)\right)\right)\right)\right), R\right) \]
    7. Simplified59.2%

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

    if -0.0280000000000000006 < phi2 < 5.8999999999999998e-5

    1. Initial program 63.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 \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\color{blue}{\left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right), R\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6460.9%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified60.9%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\right), R\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\right), R\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), R\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right), R\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\left(\sin \lambda_1 \cdot \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right), R\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right), R\right) \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right), R\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right)\right)\right)\right), R\right) \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right)\right)\right)\right), R\right) \]
      11. cos-lowering-cos.f6483.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    7. Applied egg-rr83.8%

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

    if 5.8999999999999998e-5 < phi2

    1. Initial program 84.9%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      2. +-commutativeN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. sin-lowering-sin.f64N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f6498.9%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr98.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_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
    5. Taylor expanded in phi1 around 0

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\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)}\right), R\right) \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_2, \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), R\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\left(\cos \lambda_1 \cdot \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right)\right)\right)\right), R\right) \]
      9. sin-lowering-sin.f6457.6%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    7. Simplified57.6%

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

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

Alternative 13: 63.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\\ \mathbf{if}\;\phi_2 \leq 5.4 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot t\_0\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0
         (+ (* (sin lambda1) (sin lambda2)) (* (cos lambda1) (cos lambda2)))))
   (if (<= phi2 5.4e-5)
     (* R (acos (* (cos phi1) t_0)))
     (* R (acos (* (cos phi2) t_0))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2));
	double tmp;
	if (phi2 <= 5.4e-5) {
		tmp = R * acos((cos(phi1) * t_0));
	} else {
		tmp = R * acos((cos(phi2) * t_0));
	}
	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 = (sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2))
    if (phi2 <= 5.4d-5) then
        tmp = r * acos((cos(phi1) * t_0))
    else
        tmp = r * acos((cos(phi2) * t_0))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (Math.sin(lambda1) * Math.sin(lambda2)) + (Math.cos(lambda1) * Math.cos(lambda2));
	double tmp;
	if (phi2 <= 5.4e-5) {
		tmp = R * Math.acos((Math.cos(phi1) * t_0));
	} else {
		tmp = R * Math.acos((Math.cos(phi2) * t_0));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = (math.sin(lambda1) * math.sin(lambda2)) + (math.cos(lambda1) * math.cos(lambda2))
	tmp = 0
	if phi2 <= 5.4e-5:
		tmp = R * math.acos((math.cos(phi1) * t_0))
	else:
		tmp = R * math.acos((math.cos(phi2) * t_0))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(Float64(sin(lambda1) * sin(lambda2)) + Float64(cos(lambda1) * cos(lambda2)))
	tmp = 0.0
	if (phi2 <= 5.4e-5)
		tmp = Float64(R * acos(Float64(cos(phi1) * t_0)));
	else
		tmp = Float64(R * acos(Float64(cos(phi2) * t_0)));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = (sin(lambda1) * sin(lambda2)) + (cos(lambda1) * cos(lambda2));
	tmp = 0.0;
	if (phi2 <= 5.4e-5)
		tmp = R * acos((cos(phi1) * t_0));
	else
		tmp = R * acos((cos(phi2) * t_0));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, 5.4e-5], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\\
\mathbf{if}\;\phi_2 \leq 5.4 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t\_0\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < 5.3999999999999998e-5

    1. Initial program 66.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 \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\color{blue}{\left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right), R\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6448.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified48.1%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\right), R\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\right), R\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), R\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right), R\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\left(\sin \lambda_1 \cdot \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right), R\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right), R\right) \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right), R\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right)\right)\right)\right), R\right) \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right)\right)\right)\right), R\right) \]
      11. cos-lowering-cos.f6464.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    7. Applied egg-rr64.3%

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

    if 5.3999999999999998e-5 < phi2

    1. Initial program 84.9%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      2. +-commutativeN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. sin-lowering-sin.f64N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f6498.9%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    4. Applied egg-rr98.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_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}\right) \cdot R \]
    5. Taylor expanded in phi1 around 0

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\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)}\right), R\right) \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_2, \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), R\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\left(\cos \lambda_1 \cdot \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right)\right)\right)\right), R\right) \]
      9. sin-lowering-sin.f6457.6%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    7. Simplified57.6%

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

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

Alternative 14: 60.6% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 0.0001:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < 1.00000000000000005e-4

    1. Initial program 66.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 \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\color{blue}{\left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right), R\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6448.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified48.1%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\right), R\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\right), R\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), R\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right), R\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\left(\sin \lambda_1 \cdot \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right), R\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\sin \lambda_1, \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right), R\right) \]
      7. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \sin \lambda_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right), R\right) \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \left(\cos \lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right), R\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\cos \lambda_1, \cos \lambda_2\right)\right)\right)\right), R\right) \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \cos \lambda_2\right)\right)\right)\right), R\right) \]
      11. cos-lowering-cos.f6464.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\lambda_1\right), \mathsf{sin.f64}\left(\lambda_2\right)\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    7. Applied egg-rr64.3%

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

    if 1.00000000000000005e-4 < phi2

    1. Initial program 84.9%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_2, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6450.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified50.3%

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

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

Alternative 15: 53.8% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\\ \mathbf{if}\;\phi_2 \leq -9000000:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(1 + -0.5 \cdot \left(\lambda_1 \cdot \lambda_1\right)\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 2.95:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t\_0 + \phi_2 \cdot \left(\sin \phi_1 \cdot \left(1 + \left(\phi_2 \cdot \phi_2\right) \cdot \left(-0.16666666666666666 + \phi_2 \cdot \left(\phi_2 \cdot 0.008333333333333333\right)\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} t\_0\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (cos phi2) (cos (- lambda2 lambda1)))))
   (if (<= phi2 -9000000.0)
     (*
      R
      (acos
       (+
        (* (sin phi1) (sin phi2))
        (* (* (cos phi1) (cos phi2)) (+ 1.0 (* -0.5 (* lambda1 lambda1)))))))
     (if (<= phi2 2.95)
       (*
        R
        (acos
         (+
          (* (cos phi1) t_0)
          (*
           phi2
           (*
            (sin phi1)
            (+
             1.0
             (*
              (* phi2 phi2)
              (+
               -0.16666666666666666
               (* phi2 (* phi2 0.008333333333333333))))))))))
       (* R (acos t_0))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos(phi2) * cos((lambda2 - lambda1));
	double tmp;
	if (phi2 <= -9000000.0) {
		tmp = R * acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * (1.0 + (-0.5 * (lambda1 * lambda1))))));
	} else if (phi2 <= 2.95) {
		tmp = R * acos(((cos(phi1) * t_0) + (phi2 * (sin(phi1) * (1.0 + ((phi2 * phi2) * (-0.16666666666666666 + (phi2 * (phi2 * 0.008333333333333333)))))))));
	} else {
		tmp = R * acos(t_0);
	}
	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(phi2) * cos((lambda2 - lambda1))
    if (phi2 <= (-9000000.0d0)) then
        tmp = r * acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * (1.0d0 + ((-0.5d0) * (lambda1 * lambda1))))))
    else if (phi2 <= 2.95d0) then
        tmp = r * acos(((cos(phi1) * t_0) + (phi2 * (sin(phi1) * (1.0d0 + ((phi2 * phi2) * ((-0.16666666666666666d0) + (phi2 * (phi2 * 0.008333333333333333d0)))))))))
    else
        tmp = r * acos(t_0)
    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(phi2) * Math.cos((lambda2 - lambda1));
	double tmp;
	if (phi2 <= -9000000.0) {
		tmp = R * Math.acos(((Math.sin(phi1) * Math.sin(phi2)) + ((Math.cos(phi1) * Math.cos(phi2)) * (1.0 + (-0.5 * (lambda1 * lambda1))))));
	} else if (phi2 <= 2.95) {
		tmp = R * Math.acos(((Math.cos(phi1) * t_0) + (phi2 * (Math.sin(phi1) * (1.0 + ((phi2 * phi2) * (-0.16666666666666666 + (phi2 * (phi2 * 0.008333333333333333)))))))));
	} else {
		tmp = R * Math.acos(t_0);
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.cos(phi2) * math.cos((lambda2 - lambda1))
	tmp = 0
	if phi2 <= -9000000.0:
		tmp = R * math.acos(((math.sin(phi1) * math.sin(phi2)) + ((math.cos(phi1) * math.cos(phi2)) * (1.0 + (-0.5 * (lambda1 * lambda1))))))
	elif phi2 <= 2.95:
		tmp = R * math.acos(((math.cos(phi1) * t_0) + (phi2 * (math.sin(phi1) * (1.0 + ((phi2 * phi2) * (-0.16666666666666666 + (phi2 * (phi2 * 0.008333333333333333)))))))))
	else:
		tmp = R * math.acos(t_0)
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(cos(phi2) * cos(Float64(lambda2 - lambda1)))
	tmp = 0.0
	if (phi2 <= -9000000.0)
		tmp = Float64(R * acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * Float64(1.0 + Float64(-0.5 * Float64(lambda1 * lambda1)))))));
	elseif (phi2 <= 2.95)
		tmp = Float64(R * acos(Float64(Float64(cos(phi1) * t_0) + Float64(phi2 * Float64(sin(phi1) * Float64(1.0 + Float64(Float64(phi2 * phi2) * Float64(-0.16666666666666666 + Float64(phi2 * Float64(phi2 * 0.008333333333333333))))))))));
	else
		tmp = Float64(R * acos(t_0));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = cos(phi2) * cos((lambda2 - lambda1));
	tmp = 0.0;
	if (phi2 <= -9000000.0)
		tmp = R * acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * (1.0 + (-0.5 * (lambda1 * lambda1))))));
	elseif (phi2 <= 2.95)
		tmp = R * acos(((cos(phi1) * t_0) + (phi2 * (sin(phi1) * (1.0 + ((phi2 * phi2) * (-0.16666666666666666 + (phi2 * (phi2 * 0.008333333333333333)))))))));
	else
		tmp = R * acos(t_0);
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -9000000.0], N[(R * 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[(1.0 + N[(-0.5 * N[(lambda1 * lambda1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 2.95], N[(R * N[ArcCos[N[(N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision] + N[(phi2 * N[(N[Sin[phi1], $MachinePrecision] * N[(1.0 + N[(N[(phi2 * phi2), $MachinePrecision] * N[(-0.16666666666666666 + N[(phi2 * N[(phi2 * 0.008333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[t$95$0], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\\
\mathbf{if}\;\phi_2 \leq -9000000:\\
\;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(1 + -0.5 \cdot \left(\lambda_1 \cdot \lambda_1\right)\right)\right)\\

\mathbf{elif}\;\phi_2 \leq 2.95:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t\_0 + \phi_2 \cdot \left(\sin \phi_1 \cdot \left(1 + \left(\phi_2 \cdot \phi_2\right) \cdot \left(-0.16666666666666666 + \phi_2 \cdot \left(\phi_2 \cdot 0.008333333333333333\right)\right)\right)\right)\right)\\

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


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

    1. Initial program 75.9%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\cos \left(\mathsf{neg}\left(\lambda_2\right)\right), \left(\lambda_1 \cdot \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      2. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\cos \lambda_2, \left(\lambda_1 \cdot \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      3. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \left(\lambda_1 \cdot \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \mathsf{*.f64}\left(\lambda_1, \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      5. distribute-lft-inN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \mathsf{*.f64}\left(\lambda_1, \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) + \left(\left(\frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot \lambda_1 - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \mathsf{*.f64}\left(\lambda_1, \mathsf{+.f64}\left(\left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right), \left(\left(\frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot \lambda_1 - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
    5. Simplified48.3%

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left({\lambda_1}^{2}\right)\right)\right)\right)\right)\right), R\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(\lambda_1 \cdot \lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      4. *-lowering-*.f6432.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(\lambda_1, \lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
    8. Simplified32.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(1 + -0.5 \cdot \left(\lambda_1 \cdot \lambda_1\right)\right)}\right) \cdot R \]

    if -9e6 < phi2 < 2.9500000000000002

    1. Initial program 63.5%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\phi_2, \left(\sin \phi_1 + {\phi_2}^{2} \cdot \left(\frac{-1}{6} \cdot \sin \phi_1 + \frac{1}{120} \cdot \left({\phi_2}^{2} \cdot \sin \phi_1\right)\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right)\right)\right), R\right) \]
      2. distribute-rgt-inN/A

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\phi_2, \left(\left(\sin \phi_1 + \left(\frac{-1}{6} \cdot {\phi_2}^{2}\right) \cdot \sin \phi_1\right) + \left(\frac{1}{120} \cdot \left({\phi_2}^{2} \cdot \sin \phi_1\right)\right) \cdot {\phi_2}^{2}\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. distribute-rgt1-inN/A

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\phi_2, \left(\left(\frac{-1}{6} \cdot {\phi_2}^{2} + 1\right) \cdot \sin \phi_1 + {\phi_2}^{2} \cdot \left(\frac{1}{120} \cdot \left(\sin \phi_1 \cdot {\phi_2}^{2}\right)\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right)\right)\right), R\right) \]
      12. *-commutativeN/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\phi_2, \left(\left(\frac{-1}{6} \cdot {\phi_2}^{2} + 1\right) \cdot \sin \phi_1 + {\phi_2}^{2} \cdot \left(\left(\frac{1}{120} \cdot {\phi_2}^{2}\right) \cdot \sin \phi_1\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right)\right)\right), R\right) \]
    5. Simplified63.5%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right), \left(\phi_2 \cdot \left(\sin \phi_1 \cdot \left(\left(1 + \frac{-1}{6} \cdot \left(\phi_2 \cdot \phi_2\right)\right) + \left(\phi_2 \cdot \phi_2\right) \cdot \left(\frac{1}{120} \cdot \left(\phi_2 \cdot \phi_2\right)\right)\right)\right)\right)\right)\right), R\right) \]
      3. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right), \left(\phi_2 \cdot \left(\sin \phi_1 \cdot \left(\left(1 + \frac{-1}{6} \cdot \left(\phi_2 \cdot \phi_2\right)\right) + \left(\phi_2 \cdot \phi_2\right) \cdot \left(\frac{1}{120} \cdot \left(\phi_2 \cdot \phi_2\right)\right)\right)\right)\right)\right)\right), R\right) \]
      4. *-lowering-*.f64N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right), \left(\phi_2 \cdot \left(\sin \phi_1 \cdot \left(\left(1 + \frac{-1}{6} \cdot \left(\phi_2 \cdot \phi_2\right)\right) + \left(\phi_2 \cdot \phi_2\right) \cdot \left(\frac{1}{120} \cdot \left(\phi_2 \cdot \phi_2\right)\right)\right)\right)\right)\right)\right), R\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\cos \phi_2, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), \left(\phi_2 \cdot \left(\sin \phi_1 \cdot \left(\left(1 + \frac{-1}{6} \cdot \left(\phi_2 \cdot \phi_2\right)\right) + \left(\phi_2 \cdot \phi_2\right) \cdot \left(\frac{1}{120} \cdot \left(\phi_2 \cdot \phi_2\right)\right)\right)\right)\right)\right)\right), R\right) \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), \left(\phi_2 \cdot \left(\sin \phi_1 \cdot \left(\left(1 + \frac{-1}{6} \cdot \left(\phi_2 \cdot \phi_2\right)\right) + \left(\phi_2 \cdot \phi_2\right) \cdot \left(\frac{1}{120} \cdot \left(\phi_2 \cdot \phi_2\right)\right)\right)\right)\right)\right)\right), R\right) \]
      8. cos-diffN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), \left(\phi_2 \cdot \left(\sin \phi_1 \cdot \left(\left(1 + \frac{-1}{6} \cdot \left(\phi_2 \cdot \phi_2\right)\right) + \left(\phi_2 \cdot \phi_2\right) \cdot \left(\frac{1}{120} \cdot \left(\phi_2 \cdot \phi_2\right)\right)\right)\right)\right)\right)\right), R\right) \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right), \left(\phi_2 \cdot \left(\sin \phi_1 \cdot \left(\left(1 + \frac{-1}{6} \cdot \left(\phi_2 \cdot \phi_2\right)\right) + \left(\phi_2 \cdot \phi_2\right) \cdot \left(\frac{1}{120} \cdot \left(\phi_2 \cdot \phi_2\right)\right)\right)\right)\right)\right)\right), R\right) \]
      10. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right)\right)\right), \left(\phi_2 \cdot \left(\sin \phi_1 \cdot \left(\left(1 + \frac{-1}{6} \cdot \left(\phi_2 \cdot \phi_2\right)\right) + \left(\phi_2 \cdot \phi_2\right) \cdot \left(\frac{1}{120} \cdot \left(\phi_2 \cdot \phi_2\right)\right)\right)\right)\right)\right)\right), R\right) \]
      11. cos-diffN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_2 - \lambda_1\right)\right)\right), \left(\phi_2 \cdot \left(\sin \phi_1 \cdot \left(\left(1 + \frac{-1}{6} \cdot \left(\phi_2 \cdot \phi_2\right)\right) + \left(\phi_2 \cdot \phi_2\right) \cdot \left(\frac{1}{120} \cdot \left(\phi_2 \cdot \phi_2\right)\right)\right)\right)\right)\right)\right), R\right) \]
      12. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), \left(\phi_2 \cdot \left(\sin \phi_1 \cdot \left(\left(1 + \frac{-1}{6} \cdot \left(\phi_2 \cdot \phi_2\right)\right) + \left(\phi_2 \cdot \phi_2\right) \cdot \left(\frac{1}{120} \cdot \left(\phi_2 \cdot \phi_2\right)\right)\right)\right)\right)\right)\right), R\right) \]
      13. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), \left(\phi_2 \cdot \left(\sin \phi_1 \cdot \left(\left(1 + \frac{-1}{6} \cdot \left(\phi_2 \cdot \phi_2\right)\right) + \left(\phi_2 \cdot \phi_2\right) \cdot \left(\frac{1}{120} \cdot \left(\phi_2 \cdot \phi_2\right)\right)\right)\right)\right)\right)\right), R\right) \]
      14. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), \mathsf{*.f64}\left(\phi_2, \left(\sin \phi_1 \cdot \left(\left(1 + \frac{-1}{6} \cdot \left(\phi_2 \cdot \phi_2\right)\right) + \left(\phi_2 \cdot \phi_2\right) \cdot \left(\frac{1}{120} \cdot \left(\phi_2 \cdot \phi_2\right)\right)\right)\right)\right)\right)\right), R\right) \]
    7. Applied egg-rr63.5%

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

    if 2.9500000000000002 < phi2

    1. Initial program 84.4%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_2, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6450.0%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified50.0%

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

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

Alternative 16: 53.7% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \phi_1 \cdot \cos \phi_2\\ \mathbf{if}\;\phi_2 \leq -46000:\\ \;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t\_0 \cdot \left(1 + -0.5 \cdot \left(\lambda_1 \cdot \lambda_1\right)\right)\right)\\ \mathbf{elif}\;\phi_2 \leq 2.5:\\ \;\;\;\;R \cdot \cos^{-1} \left(t\_0 \cdot \cos \left(\lambda_1 - \lambda_2\right) + \phi_2 \cdot \left(\sin \phi_1 \cdot \left(1 + \left(\phi_2 \cdot \phi_2\right) \cdot -0.16666666666666666\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (cos phi1) (cos phi2))))
   (if (<= phi2 -46000.0)
     (*
      R
      (acos
       (+
        (* (sin phi1) (sin phi2))
        (* t_0 (+ 1.0 (* -0.5 (* lambda1 lambda1)))))))
     (if (<= phi2 2.5)
       (*
        R
        (acos
         (+
          (* t_0 (cos (- lambda1 lambda2)))
          (*
           phi2
           (* (sin phi1) (+ 1.0 (* (* phi2 phi2) -0.16666666666666666)))))))
       (* R (acos (* (cos phi2) (cos (- lambda2 lambda1)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos(phi1) * cos(phi2);
	double tmp;
	if (phi2 <= -46000.0) {
		tmp = R * acos(((sin(phi1) * sin(phi2)) + (t_0 * (1.0 + (-0.5 * (lambda1 * lambda1))))));
	} else if (phi2 <= 2.5) {
		tmp = R * acos(((t_0 * cos((lambda1 - lambda2))) + (phi2 * (sin(phi1) * (1.0 + ((phi2 * phi2) * -0.16666666666666666))))));
	} else {
		tmp = R * acos((cos(phi2) * cos((lambda2 - lambda1))));
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: tmp
    t_0 = cos(phi1) * cos(phi2)
    if (phi2 <= (-46000.0d0)) then
        tmp = r * acos(((sin(phi1) * sin(phi2)) + (t_0 * (1.0d0 + ((-0.5d0) * (lambda1 * lambda1))))))
    else if (phi2 <= 2.5d0) then
        tmp = r * acos(((t_0 * cos((lambda1 - lambda2))) + (phi2 * (sin(phi1) * (1.0d0 + ((phi2 * phi2) * (-0.16666666666666666d0)))))))
    else
        tmp = r * acos((cos(phi2) * cos((lambda2 - lambda1))))
    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(phi1) * Math.cos(phi2);
	double tmp;
	if (phi2 <= -46000.0) {
		tmp = R * Math.acos(((Math.sin(phi1) * Math.sin(phi2)) + (t_0 * (1.0 + (-0.5 * (lambda1 * lambda1))))));
	} else if (phi2 <= 2.5) {
		tmp = R * Math.acos(((t_0 * Math.cos((lambda1 - lambda2))) + (phi2 * (Math.sin(phi1) * (1.0 + ((phi2 * phi2) * -0.16666666666666666))))));
	} else {
		tmp = R * Math.acos((Math.cos(phi2) * Math.cos((lambda2 - lambda1))));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.cos(phi1) * math.cos(phi2)
	tmp = 0
	if phi2 <= -46000.0:
		tmp = R * math.acos(((math.sin(phi1) * math.sin(phi2)) + (t_0 * (1.0 + (-0.5 * (lambda1 * lambda1))))))
	elif phi2 <= 2.5:
		tmp = R * math.acos(((t_0 * math.cos((lambda1 - lambda2))) + (phi2 * (math.sin(phi1) * (1.0 + ((phi2 * phi2) * -0.16666666666666666))))))
	else:
		tmp = R * math.acos((math.cos(phi2) * math.cos((lambda2 - lambda1))))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(cos(phi1) * cos(phi2))
	tmp = 0.0
	if (phi2 <= -46000.0)
		tmp = Float64(R * acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(t_0 * Float64(1.0 + Float64(-0.5 * Float64(lambda1 * lambda1)))))));
	elseif (phi2 <= 2.5)
		tmp = Float64(R * acos(Float64(Float64(t_0 * cos(Float64(lambda1 - lambda2))) + Float64(phi2 * Float64(sin(phi1) * Float64(1.0 + Float64(Float64(phi2 * phi2) * -0.16666666666666666)))))));
	else
		tmp = Float64(R * acos(Float64(cos(phi2) * cos(Float64(lambda2 - lambda1)))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = cos(phi1) * cos(phi2);
	tmp = 0.0;
	if (phi2 <= -46000.0)
		tmp = R * acos(((sin(phi1) * sin(phi2)) + (t_0 * (1.0 + (-0.5 * (lambda1 * lambda1))))));
	elseif (phi2 <= 2.5)
		tmp = R * acos(((t_0 * cos((lambda1 - lambda2))) + (phi2 * (sin(phi1) * (1.0 + ((phi2 * phi2) * -0.16666666666666666))))));
	else
		tmp = R * acos((cos(phi2) * cos((lambda2 - lambda1))));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -46000.0], N[(R * N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(t$95$0 * N[(1.0 + N[(-0.5 * N[(lambda1 * lambda1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 2.5], N[(R * N[ArcCos[N[(N[(t$95$0 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(phi2 * N[(N[Sin[phi1], $MachinePrecision] * N[(1.0 + N[(N[(phi2 * phi2), $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \phi_1 \cdot \cos \phi_2\\
\mathbf{if}\;\phi_2 \leq -46000:\\
\;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + t\_0 \cdot \left(1 + -0.5 \cdot \left(\lambda_1 \cdot \lambda_1\right)\right)\right)\\

\mathbf{elif}\;\phi_2 \leq 2.5:\\
\;\;\;\;R \cdot \cos^{-1} \left(t\_0 \cdot \cos \left(\lambda_1 - \lambda_2\right) + \phi_2 \cdot \left(\sin \phi_1 \cdot \left(1 + \left(\phi_2 \cdot \phi_2\right) \cdot -0.16666666666666666\right)\right)\right)\\

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


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

    1. Initial program 75.9%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\cos \left(\mathsf{neg}\left(\lambda_2\right)\right), \left(\lambda_1 \cdot \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      2. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\cos \lambda_2, \left(\lambda_1 \cdot \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      3. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \left(\lambda_1 \cdot \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \mathsf{*.f64}\left(\lambda_1, \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) + \frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      5. distribute-lft-inN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \mathsf{*.f64}\left(\lambda_1, \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) + \left(\left(\frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot \lambda_1 - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \mathsf{*.f64}\left(\lambda_1, \mathsf{+.f64}\left(\left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right), \left(\left(\frac{1}{6} \cdot \left(\lambda_1 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) \cdot \lambda_1 - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
    5. Simplified48.3%

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left({\lambda_1}^{2}\right)\right)\right)\right)\right)\right), R\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(\lambda_1 \cdot \lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      4. *-lowering-*.f6432.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{sin.f64}\left(\phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(\lambda_1, \lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
    8. Simplified32.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(1 + -0.5 \cdot \left(\lambda_1 \cdot \lambda_1\right)\right)}\right) \cdot R \]

    if -46000 < phi2 < 2.5

    1. Initial program 63.5%

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\left(\phi_2 \cdot \left(\sin \phi_1 + \left(\frac{-1}{6} \cdot \sin \phi_1\right) \cdot {\phi_2}^{2}\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right)\right)\right), R\right) \]
      3. *-lowering-*.f64N/A

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\phi_2, \left(\sin \phi_1 + \left(\frac{-1}{6} \cdot {\phi_2}^{2}\right) \cdot \sin \phi_1\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. distribute-rgt1-inN/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\phi_2, \left(\sin \phi_1 \cdot \left(\frac{-1}{6} \cdot {\phi_2}^{2} + 1\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\phi_2, \mathsf{*.f64}\left(\sin \phi_1, \left(\frac{-1}{6} \cdot {\phi_2}^{2} + 1\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right)\right)\right), R\right) \]
      10. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\phi_2, \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \left(\frac{-1}{6} \cdot {\phi_2}^{2} + 1\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right)\right)\right), R\right) \]
      11. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\phi_2, \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \left(\frac{-1}{6} \cdot {\phi_2}^{2} + \left(\mathsf{neg}\left(-1\right)\right)\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right)\right)\right), R\right) \]
      12. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\phi_2, \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \left(\left(\mathsf{neg}\left(-1\right)\right) + \frac{-1}{6} \cdot {\phi_2}^{2}\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right)\right)\right), R\right) \]
      13. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\phi_2, \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\left(\mathsf{neg}\left(-1\right)\right), \left(\frac{-1}{6} \cdot {\phi_2}^{2}\right)\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right)\right)\right), R\right) \]
      14. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\phi_2, \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{+.f64}\left(1, \left(\frac{-1}{6} \cdot {\phi_2}^{2}\right)\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right)\right)\right), R\right) \]
      15. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\phi_2, \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{6}, \left({\phi_2}^{2}\right)\right)\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right)\right)\right), R\right) \]
      16. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\phi_2, \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{6}, \left(\phi_2 \cdot \phi_2\right)\right)\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right)\right)\right), R\right) \]
      17. *-lowering-*.f6463.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\phi_2, \mathsf{*.f64}\left(\mathsf{sin.f64}\left(\phi_1\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{6}, \mathsf{*.f64}\left(\phi_2, \phi_2\right)\right)\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\phi_2\right)\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right)\right)\right), R\right) \]
    5. Simplified63.3%

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

    if 2.5 < phi2

    1. Initial program 84.4%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_2, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6450.0%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified50.0%

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

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

Alternative 17: 33.3% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;t\_0 \leq 0.99999:\\
\;\;\;\;R \cdot \cos^{-1} t\_0\\

\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(1 + \lambda_1 \cdot \left(\lambda_1 \cdot -0.5\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (-.f64 lambda1 lambda2)) < 0.999990000000000046

    1. Initial program 72.1%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6445.7%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified45.7%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      2. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      3. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(\lambda_2\right)\right) + \lambda_1\right)\right)\right)\right), R\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      5. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)\right), R\right) \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right), R\right) \]
      8. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      10. --lowering--.f6432.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), R\right) \]
    8. Simplified32.3%

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

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

    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 \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\color{blue}{\left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right), R\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6421.7%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified21.7%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \color{blue}{\left(\cos \lambda_2 + \lambda_1 \cdot \left(\frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \lambda_2\right) - -1 \cdot \sin \lambda_2\right)\right)}\right)\right), R\right) \]
    7. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \lambda_2 + \lambda_1 \cdot \left(\frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) - -1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \lambda_2 + \lambda_1 \cdot \left(\frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) - \left(\mathsf{neg}\left(\sin \lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      3. sin-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \lambda_2 + \lambda_1 \cdot \left(\frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      4. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\cos \lambda_2, \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right), R\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right), R\right) \]
      6. fmm-defN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \left(\lambda_1 \cdot \mathsf{fma}\left(\frac{-1}{2}, \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right), \mathsf{neg}\left(\sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      7. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \left(\lambda_1 \cdot \mathsf{fma}\left(\frac{-1}{2}, \lambda_1 \cdot \cos \lambda_2, \mathsf{neg}\left(\sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      8. fma-undefineN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \lambda_2\right) + \left(\mathsf{neg}\left(\sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      9. sin-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \lambda_2\right) + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\sin \lambda_2\right)\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      10. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \lambda_2\right) + \sin \lambda_2\right)\right)\right)\right)\right), R\right) \]
      11. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \left(\lambda_1 \cdot \left(\sin \lambda_2 + \frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      12. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \mathsf{*.f64}\left(\lambda_1, \left(\sin \lambda_2 + \frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    8. Simplified21.7%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(1, \left(\frac{-1}{2} \cdot {\lambda_1}^{2}\right)\right)\right)\right), R\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(1, \left({\lambda_1}^{2} \cdot \frac{-1}{2}\right)\right)\right)\right), R\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(1, \left(\left(\lambda_1 \cdot \lambda_1\right) \cdot \frac{-1}{2}\right)\right)\right)\right), R\right) \]
      4. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(1, \left(\lambda_1 \cdot \left(\lambda_1 \cdot \frac{-1}{2}\right)\right)\right)\right)\right), R\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\lambda_1, \left(\lambda_1 \cdot \frac{-1}{2}\right)\right)\right)\right)\right), R\right) \]
      6. *-lowering-*.f6420.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_1, \frac{-1}{2}\right)\right)\right)\right)\right), R\right) \]
    11. Simplified20.8%

      \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \color{blue}{\left(1 + \lambda_1 \cdot \left(\lambda_1 \cdot -0.5\right)\right)}\right) \cdot R \]
  3. Recombined 2 regimes into one program.
  4. Final simplification29.9%

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

Alternative 18: 50.7% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\lambda_2 - \lambda_1\right)\\ \mathbf{if}\;\phi_2 \leq 5 \cdot 10^{-5}:\\ \;\;\;\;\frac{R}{\frac{1}{\cos^{-1} \left(\cos \phi_1 \cdot t\_0\right)}}\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot t\_0\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (cos (- lambda2 lambda1))))
   (if (<= phi2 5e-5)
     (/ R (/ 1.0 (acos (* (cos phi1) t_0))))
     (* R (acos (* (cos phi2) t_0))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos((lambda2 - lambda1));
	double tmp;
	if (phi2 <= 5e-5) {
		tmp = R / (1.0 / acos((cos(phi1) * t_0)));
	} else {
		tmp = R * acos((cos(phi2) * t_0));
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: tmp
    t_0 = cos((lambda2 - lambda1))
    if (phi2 <= 5d-5) then
        tmp = r / (1.0d0 / acos((cos(phi1) * t_0)))
    else
        tmp = r * acos((cos(phi2) * t_0))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.cos((lambda2 - lambda1));
	double tmp;
	if (phi2 <= 5e-5) {
		tmp = R / (1.0 / Math.acos((Math.cos(phi1) * t_0)));
	} else {
		tmp = R * Math.acos((Math.cos(phi2) * t_0));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.cos((lambda2 - lambda1))
	tmp = 0
	if phi2 <= 5e-5:
		tmp = R / (1.0 / math.acos((math.cos(phi1) * t_0)))
	else:
		tmp = R * math.acos((math.cos(phi2) * t_0))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = cos(Float64(lambda2 - lambda1))
	tmp = 0.0
	if (phi2 <= 5e-5)
		tmp = Float64(R / Float64(1.0 / acos(Float64(cos(phi1) * t_0))));
	else
		tmp = Float64(R * acos(Float64(cos(phi2) * t_0)));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = cos((lambda2 - lambda1));
	tmp = 0.0;
	if (phi2 <= 5e-5)
		tmp = R / (1.0 / acos((cos(phi1) * t_0)));
	else
		tmp = R * acos((cos(phi2) * t_0));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, 5e-5], N[(R / N[(1.0 / N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\lambda_2 - \lambda_1\right)\\
\mathbf{if}\;\phi_2 \leq 5 \cdot 10^{-5}:\\
\;\;\;\;\frac{R}{\frac{1}{\cos^{-1} \left(\cos \phi_1 \cdot t\_0\right)}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < 5.00000000000000024e-5

    1. Initial program 66.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 \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\color{blue}{\left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right), R\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6448.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified48.1%

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

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{2} - \sin^{-1} \left(\cos \phi_1 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right), R\right) \]
      2. flip--N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{2} \cdot \frac{\mathsf{PI}\left(\right)}{2} - \sin^{-1} \left(\cos \phi_1 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right) \cdot \sin^{-1} \left(\cos \phi_1 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right), \left(\frac{\mathsf{PI}\left(\right)}{2} + \sin^{-1} \left(\cos \phi_1 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
    7. Applied egg-rr48.0%

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

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

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

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

        \[\leadsto \mathsf{/.f64}\left(R, \color{blue}{\left(\frac{\frac{\mathsf{PI}\left(\right)}{2} + \sin^{-1} \left(\cos \phi_1 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}{\frac{\mathsf{PI}\left(\right)}{2} \cdot \frac{\mathsf{PI}\left(\right)}{2} - \sin^{-1} \left(\cos \phi_1 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right) \cdot \sin^{-1} \left(\cos \phi_1 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)}\right)}\right) \]
    9. Applied egg-rr48.1%

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

    if 5.00000000000000024e-5 < phi2

    1. Initial program 84.9%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_2, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6450.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified50.3%

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

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

Alternative 19: 50.7% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\lambda_2 - \lambda_1\right)\\ \mathbf{if}\;\phi_2 \leq 5.5 \cdot 10^{-5}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot t\_0\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (cos (- lambda2 lambda1))))
   (if (<= phi2 5.5e-5)
     (* R (acos (* (cos phi1) t_0)))
     (* R (acos (* (cos phi2) t_0))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos((lambda2 - lambda1));
	double tmp;
	if (phi2 <= 5.5e-5) {
		tmp = R * acos((cos(phi1) * t_0));
	} else {
		tmp = R * acos((cos(phi2) * t_0));
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: tmp
    t_0 = cos((lambda2 - lambda1))
    if (phi2 <= 5.5d-5) then
        tmp = r * acos((cos(phi1) * t_0))
    else
        tmp = r * acos((cos(phi2) * t_0))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.cos((lambda2 - lambda1));
	double tmp;
	if (phi2 <= 5.5e-5) {
		tmp = R * Math.acos((Math.cos(phi1) * t_0));
	} else {
		tmp = R * Math.acos((Math.cos(phi2) * t_0));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = math.cos((lambda2 - lambda1))
	tmp = 0
	if phi2 <= 5.5e-5:
		tmp = R * math.acos((math.cos(phi1) * t_0))
	else:
		tmp = R * math.acos((math.cos(phi2) * t_0))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = cos(Float64(lambda2 - lambda1))
	tmp = 0.0
	if (phi2 <= 5.5e-5)
		tmp = Float64(R * acos(Float64(cos(phi1) * t_0)));
	else
		tmp = Float64(R * acos(Float64(cos(phi2) * t_0)));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = cos((lambda2 - lambda1));
	tmp = 0.0;
	if (phi2 <= 5.5e-5)
		tmp = R * acos((cos(phi1) * t_0));
	else
		tmp = R * acos((cos(phi2) * t_0));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, 5.5e-5], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\lambda_2 - \lambda_1\right)\\
\mathbf{if}\;\phi_2 \leq 5.5 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot t\_0\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < 5.5000000000000002e-5

    1. Initial program 66.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 \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\color{blue}{\left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right), R\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6448.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified48.1%

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

    if 5.5000000000000002e-5 < phi2

    1. Initial program 84.9%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_2, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6450.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_2\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified50.3%

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

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

Alternative 20: 28.0% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;t\_0 \leq 0.99999999999998:\\
\;\;\;\;R \cdot \cos^{-1} t\_0\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (-.f64 lambda1 lambda2)) < 0.99999999999998002

    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 \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\color{blue}{\left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right), R\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6445.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified45.5%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      2. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      3. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(\lambda_2\right)\right) + \lambda_1\right)\right)\right)\right), R\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      5. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)\right), R\right) \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right), R\right) \]
      8. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      10. --lowering--.f6432.0%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), R\right) \]
    8. Simplified32.0%

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

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

    1. Initial program 67.1%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6420.6%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified20.6%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      2. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      3. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(\lambda_2\right)\right) + \lambda_1\right)\right)\right)\right), R\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      5. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)\right), R\right) \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right), R\right) \]
      8. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      10. --lowering--.f644.6%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), R\right) \]
    8. Simplified4.6%

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

        \[\leadsto \left(\lambda_1 - \lambda_2\right) \cdot R \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \color{blue}{R}\right) \]
      3. acos-cos-sN/A

        \[\leadsto \mathsf{*.f64}\left(\cos^{-1} \cos \left(\lambda_1 - \lambda_2\right), R\right) \]
      4. cos-diffN/A

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

        \[\leadsto \mathsf{*.f64}\left(\cos^{-1} \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_1 \cdot \sin \lambda_2\right), R\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\cos^{-1} \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right), R\right) \]
      7. cos-diffN/A

        \[\leadsto \mathsf{*.f64}\left(\cos^{-1} \cos \left(\lambda_2 - \lambda_1\right), R\right) \]
      8. acos-cos-sN/A

        \[\leadsto \mathsf{*.f64}\left(\left(\lambda_2 - \lambda_1\right), R\right) \]
      9. --lowering--.f6416.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right), R\right) \]
    10. Applied egg-rr16.3%

      \[\leadsto \color{blue}{\left(\lambda_2 - \lambda_1\right) \cdot R} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification28.8%

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

Alternative 21: 37.7% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 \leq -2.3 \cdot 10^{-7}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_2\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda1 < -2.29999999999999995e-7

    1. Initial program 61.5%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6443.0%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified43.0%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\left(\cos \phi_1 \cdot \cos \lambda_1\right)\right), R\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \lambda_1\right)\right), R\right) \]
      3. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \lambda_1\right)\right), R\right) \]
      4. cos-lowering-cos.f6441.9%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\lambda_1\right)\right)\right), R\right) \]
    8. Simplified41.9%

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

    if -2.29999999999999995e-7 < lambda1

    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 \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\color{blue}{\left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right), R\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6439.7%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified39.7%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\left(\cos \phi_1 \cdot \cos \lambda_2\right)\right), R\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \lambda_2\right)\right), R\right) \]
      3. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \lambda_2\right)\right), R\right) \]
      4. cos-lowering-cos.f6430.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\lambda_2\right)\right)\right), R\right) \]
    8. Simplified30.5%

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

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

Alternative 22: 35.2% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq 0.000245:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_1\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \cos \left(\lambda_1 - \lambda_2\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda2 < 2.4499999999999999e-4

    1. Initial program 75.9%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6442.0%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified42.0%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\left(\cos \phi_1 \cdot \cos \lambda_1\right)\right), R\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \lambda_1\right)\right), R\right) \]
      3. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \lambda_1\right)\right), R\right) \]
      4. cos-lowering-cos.f6434.9%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\lambda_1\right)\right)\right), R\right) \]
    8. Simplified34.9%

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

    if 2.4499999999999999e-4 < lambda2

    1. Initial program 61.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 \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\color{blue}{\left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right), R\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6436.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified36.8%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      2. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      3. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(\lambda_2\right)\right) + \lambda_1\right)\right)\right)\right), R\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      5. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)\right), R\right) \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right), R\right) \]
      8. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      10. --lowering--.f6425.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), R\right) \]
    8. Simplified25.8%

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

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

Alternative 23: 43.4% accurate, 2.0× speedup?

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
    2. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
    3. sub-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    4. remove-double-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    5. mul-1-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    6. distribute-neg-inN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
    7. +-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
    8. cos-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
    9. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
    10. mul-1-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
    11. unsub-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
    12. --lowering--.f6440.5%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
  5. Simplified40.5%

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

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

Alternative 24: 21.4% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 - \lambda_2 \leq -2:\\
\;\;\;\;R \cdot \cos^{-1} \cos \left(\lambda_1 - \lambda_2\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\lambda_1 \cdot \left(\lambda_1 \cdot -0.5\right) + \left(1 + \lambda_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(-0.5 + \left(\lambda_1 \cdot \lambda_1\right) \cdot 0.25\right)\right)\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 lambda1 lambda2) < -2

    1. Initial program 71.9%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6444.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified44.3%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      2. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      3. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(\lambda_2\right)\right) + \lambda_1\right)\right)\right)\right), R\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      5. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)\right), R\right) \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right), R\right) \]
      8. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      10. --lowering--.f6432.0%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), R\right) \]
    8. Simplified32.0%

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

    if -2 < (-.f64 lambda1 lambda2)

    1. Initial program 71.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 \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\color{blue}{\left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right), R\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6437.9%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified37.9%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \color{blue}{\left(\cos \lambda_2 + \lambda_1 \cdot \left(\frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \lambda_2\right) - -1 \cdot \sin \lambda_2\right)\right)}\right)\right), R\right) \]
    7. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \lambda_2 + \lambda_1 \cdot \left(\frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) - -1 \cdot \sin \lambda_2\right)\right)\right)\right), R\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \lambda_2 + \lambda_1 \cdot \left(\frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) - \left(\mathsf{neg}\left(\sin \lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      3. sin-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\cos \lambda_2 + \lambda_1 \cdot \left(\frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      4. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\cos \lambda_2, \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right), R\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right) - \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right), R\right) \]
      6. fmm-defN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \left(\lambda_1 \cdot \mathsf{fma}\left(\frac{-1}{2}, \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right), \mathsf{neg}\left(\sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      7. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \left(\lambda_1 \cdot \mathsf{fma}\left(\frac{-1}{2}, \lambda_1 \cdot \cos \lambda_2, \mathsf{neg}\left(\sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      8. fma-undefineN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \lambda_2\right) + \left(\mathsf{neg}\left(\sin \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      9. sin-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \lambda_2\right) + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\sin \lambda_2\right)\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      10. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \left(\lambda_1 \cdot \left(\frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \lambda_2\right) + \sin \lambda_2\right)\right)\right)\right)\right), R\right) \]
      11. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \left(\lambda_1 \cdot \left(\sin \lambda_2 + \frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      12. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right), \mathsf{*.f64}\left(\lambda_1, \left(\sin \lambda_2 + \frac{-1}{2} \cdot \left(\lambda_1 \cdot \cos \lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    8. Simplified19.8%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \color{blue}{\left(1 + \left(\frac{-1}{2} \cdot {\lambda_1}^{2} + \lambda_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\frac{1}{4} \cdot {\lambda_1}^{2} - \frac{1}{2}\right)\right)\right)\right)}\right)\right), R\right) \]
    10. Step-by-step derivation
      1. associate-+r+N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\left(1 + \frac{-1}{2} \cdot {\lambda_1}^{2}\right) + \lambda_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\frac{1}{4} \cdot {\lambda_1}^{2} - \frac{1}{2}\right)\right)\right)\right)\right), R\right) \]
      2. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\left(\frac{-1}{2} \cdot {\lambda_1}^{2} + 1\right) + \lambda_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\frac{1}{4} \cdot {\lambda_1}^{2} - \frac{1}{2}\right)\right)\right)\right)\right), R\right) \]
      3. associate-+l+N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \left(\frac{-1}{2} \cdot {\lambda_1}^{2} + \left(1 + \lambda_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\frac{1}{4} \cdot {\lambda_1}^{2} - \frac{1}{2}\right)\right)\right)\right)\right)\right), R\right) \]
      4. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\left(\frac{-1}{2} \cdot {\lambda_1}^{2}\right), \left(1 + \lambda_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\frac{1}{4} \cdot {\lambda_1}^{2} - \frac{1}{2}\right)\right)\right)\right)\right)\right), R\right) \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\left({\lambda_1}^{2} \cdot \frac{-1}{2}\right), \left(1 + \lambda_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\frac{1}{4} \cdot {\lambda_1}^{2} - \frac{1}{2}\right)\right)\right)\right)\right)\right), R\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\left(\left(\lambda_1 \cdot \lambda_1\right) \cdot \frac{-1}{2}\right), \left(1 + \lambda_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\frac{1}{4} \cdot {\lambda_1}^{2} - \frac{1}{2}\right)\right)\right)\right)\right)\right), R\right) \]
      7. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\left(\lambda_1 \cdot \left(\lambda_1 \cdot \frac{-1}{2}\right)\right), \left(1 + \lambda_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\frac{1}{4} \cdot {\lambda_1}^{2} - \frac{1}{2}\right)\right)\right)\right)\right)\right), R\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\lambda_1, \left(\lambda_1 \cdot \frac{-1}{2}\right)\right), \left(1 + \lambda_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\frac{1}{4} \cdot {\lambda_1}^{2} - \frac{1}{2}\right)\right)\right)\right)\right)\right), R\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_1, \frac{-1}{2}\right)\right), \left(1 + \lambda_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\frac{1}{4} \cdot {\lambda_1}^{2} - \frac{1}{2}\right)\right)\right)\right)\right)\right), R\right) \]
      10. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_1, \frac{-1}{2}\right)\right), \mathsf{+.f64}\left(1, \left(\lambda_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\frac{1}{4} \cdot {\lambda_1}^{2} - \frac{1}{2}\right)\right)\right)\right)\right)\right)\right), R\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_1, \frac{-1}{2}\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\lambda_2, \left(\lambda_1 + \lambda_2 \cdot \left(\frac{1}{4} \cdot {\lambda_1}^{2} - \frac{1}{2}\right)\right)\right)\right)\right)\right)\right), R\right) \]
      12. +-lowering-+.f64N/A

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_1, \frac{-1}{2}\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\lambda_2, \mathsf{+.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_2, \left(\frac{1}{4} \cdot {\lambda_1}^{2} - \frac{1}{2}\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      14. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_1, \frac{-1}{2}\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\lambda_2, \mathsf{+.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_2, \left(\frac{1}{4} \cdot {\lambda_1}^{2} + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      15. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_1, \frac{-1}{2}\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\lambda_2, \mathsf{+.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_2, \left(\frac{1}{4} \cdot {\lambda_1}^{2} + \frac{-1}{2}\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      16. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_1, \frac{-1}{2}\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\lambda_2, \mathsf{+.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_2, \left(\frac{-1}{2} + \frac{1}{4} \cdot {\lambda_1}^{2}\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      17. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_1, \frac{-1}{2}\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\lambda_2, \mathsf{+.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_2, \mathsf{+.f64}\left(\frac{-1}{2}, \left(\frac{1}{4} \cdot {\lambda_1}^{2}\right)\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      18. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_1, \frac{-1}{2}\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\lambda_2, \mathsf{+.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_2, \mathsf{+.f64}\left(\frac{-1}{2}, \left({\lambda_1}^{2} \cdot \frac{1}{4}\right)\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      19. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_1, \frac{-1}{2}\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\lambda_2, \mathsf{+.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_2, \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(\left({\lambda_1}^{2}\right), \frac{1}{4}\right)\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      20. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_1, \frac{-1}{2}\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\lambda_2, \mathsf{+.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_2, \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(\left(\lambda_1 \cdot \lambda_1\right), \frac{1}{4}\right)\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
      21. *-lowering-*.f648.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_1, \frac{-1}{2}\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\lambda_2, \mathsf{+.f64}\left(\lambda_1, \mathsf{*.f64}\left(\lambda_2, \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(\lambda_1, \lambda_1\right), \frac{1}{4}\right)\right)\right)\right)\right)\right)\right)\right)\right), R\right) \]
    11. Simplified8.1%

      \[\leadsto \cos^{-1} \left(\cos \phi_1 \cdot \color{blue}{\left(\lambda_1 \cdot \left(\lambda_1 \cdot -0.5\right) + \left(1 + \lambda_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(-0.5 + \left(\lambda_1 \cdot \lambda_1\right) \cdot 0.25\right)\right)\right)\right)}\right) \cdot R \]
  3. Recombined 2 regimes into one program.
  4. Final simplification17.8%

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

Alternative 25: 24.7% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\lambda_1 - \lambda_2 \leq -5 \cdot 10^{+37}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left|\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \left(2 \cdot \pi\right)\right)\right|\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= (- lambda1 lambda2) -5e+37)
   (* R (acos (cos (- lambda1 lambda2))))
   (* R (fabs (remainder (- lambda2 lambda1) (* 2.0 PI))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if ((lambda1 - lambda2) <= -5e+37) {
		tmp = R * acos(cos((lambda1 - lambda2)));
	} else {
		tmp = R * fabs(remainder((lambda2 - lambda1), (2.0 * ((double) M_PI))));
	}
	return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if ((lambda1 - lambda2) <= -5e+37) {
		tmp = R * Math.acos(Math.cos((lambda1 - lambda2)));
	} else {
		tmp = R * Math.abs(Math.IEEEremainder((lambda2 - lambda1), (2.0 * Math.PI)));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if (lambda1 - lambda2) <= -5e+37:
		tmp = R * math.acos(math.cos((lambda1 - lambda2)))
	else:
		tmp = R * math.fabs(math.remainder((lambda2 - lambda1), (2.0 * math.pi)))
	return tmp
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -5e+37], N[(R * N[ArcCos[N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[Abs[N[With[{TMP1 = N[(lambda2 - lambda1), $MachinePrecision], TMP2 = N[(2.0 * Pi), $MachinePrecision]}, TMP1 - Round[TMP1 / TMP2] * TMP2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 - \lambda_2 \leq -5 \cdot 10^{+37}:\\
\;\;\;\;R \cdot \cos^{-1} \cos \left(\lambda_1 - \lambda_2\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left|\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \left(2 \cdot \pi\right)\right)\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 lambda1 lambda2) < -4.99999999999999989e37

    1. Initial program 71.4%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6444.2%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified44.2%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      2. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      3. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(\lambda_2\right)\right) + \lambda_1\right)\right)\right)\right), R\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      5. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)\right), R\right) \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right), R\right) \]
      8. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      10. --lowering--.f6432.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), R\right) \]
    8. Simplified32.8%

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

    if -4.99999999999999989e37 < (-.f64 lambda1 lambda2)

    1. Initial program 71.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 \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\color{blue}{\left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right), R\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6438.2%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified38.2%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      2. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      3. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(\lambda_2\right)\right) + \lambda_1\right)\right)\right)\right), R\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      5. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)\right), R\right) \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right), R\right) \]
      8. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      10. --lowering--.f6422.6%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), R\right) \]
    8. Simplified22.6%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \mathsf{rem} \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      3. remainder-lowering-remainder.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\left(\lambda_1 - \lambda_2\right), \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      4. acos-cos-sN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\cos^{-1} \cos \left(\lambda_1 - \lambda_2\right), \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      5. cos-diffN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\cos^{-1} \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right), \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\cos^{-1} \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_1 \cdot \sin \lambda_2\right), \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      7. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\cos^{-1} \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right), \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      8. cos-diffN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\cos^{-1} \cos \left(\lambda_2 - \lambda_1\right), \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      9. acos-cos-sN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\left(\lambda_2 - \lambda_1\right), \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      10. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right), \left(2 \cdot \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right), \mathsf{*.f64}\left(2, \mathsf{PI}\left(\right)\right)\right)\right), R\right) \]
      12. PI-lowering-PI.f6420.2%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fabs.f64}\left(\mathsf{remainder.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right), \mathsf{*.f64}\left(2, \mathsf{PI.f64}\left(\right)\right)\right)\right), R\right) \]
    10. Applied egg-rr20.2%

      \[\leadsto \color{blue}{\left|\left(\left(\lambda_2 - \lambda_1\right) \mathsf{rem} \left(2 \cdot \pi\right)\right)\right|} \cdot R \]
  3. Recombined 2 regimes into one program.
  4. Final simplification25.0%

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

Alternative 26: 22.2% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -9.2 \cdot 10^{-8}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= lambda1 -9.2e-8)
   (* R (acos (cos lambda1)))
   (* R (acos (cos lambda2)))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda1 <= -9.2e-8) {
		tmp = R * acos(cos(lambda1));
	} else {
		tmp = R * acos(cos(lambda2));
	}
	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 <= (-9.2d-8)) then
        tmp = r * acos(cos(lambda1))
    else
        tmp = r * acos(cos(lambda2))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda1 <= -9.2e-8) {
		tmp = R * Math.acos(Math.cos(lambda1));
	} else {
		tmp = R * Math.acos(Math.cos(lambda2));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if lambda1 <= -9.2e-8:
		tmp = R * math.acos(math.cos(lambda1))
	else:
		tmp = R * math.acos(math.cos(lambda2))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (lambda1 <= -9.2e-8)
		tmp = Float64(R * acos(cos(lambda1)));
	else
		tmp = Float64(R * acos(cos(lambda2)));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (lambda1 <= -9.2e-8)
		tmp = R * acos(cos(lambda1));
	else
		tmp = R * acos(cos(lambda2));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda1, -9.2e-8], N[(R * N[ArcCos[N[Cos[lambda1], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[Cos[lambda2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 \leq -9.2 \cdot 10^{-8}:\\
\;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda1 < -9.2000000000000003e-8

    1. Initial program 61.5%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6443.0%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified43.0%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      2. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      3. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(\lambda_2\right)\right) + \lambda_1\right)\right)\right)\right), R\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      5. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)\right), R\right) \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right), R\right) \]
      8. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      10. --lowering--.f6434.0%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), R\right) \]
    8. Simplified34.0%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\color{blue}{\cos \lambda_1}\right), R\right) \]
    10. Step-by-step derivation
      1. cos-lowering-cos.f6433.0%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right)\right), R\right) \]
    11. Simplified33.0%

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

    if -9.2000000000000003e-8 < lambda1

    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 \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\color{blue}{\left(\cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)}\right), R\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6439.7%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified39.7%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      2. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      3. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(\lambda_2\right)\right) + \lambda_1\right)\right)\right)\right), R\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      5. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)\right), R\right) \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right), R\right) \]
      8. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      10. --lowering--.f6424.2%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), R\right) \]
    8. Simplified24.2%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)}\right), R\right) \]
    10. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \lambda_2\right), R\right) \]
      2. cos-lowering-cos.f6417.6%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\lambda_2\right)\right), R\right) \]
    11. Simplified17.6%

      \[\leadsto \cos^{-1} \color{blue}{\cos \lambda_2} \cdot R \]
  3. Recombined 2 regimes into one program.
  4. Final simplification21.3%

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

Alternative 27: 12.1% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -1.12 \cdot 10^{-8}:\\ \;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= lambda1 -1.12e-8)
   (* R (acos (cos lambda1)))
   (* R (- lambda2 lambda1))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda1 <= -1.12e-8) {
		tmp = R * acos(cos(lambda1));
	} else {
		tmp = R * (lambda2 - lambda1);
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: tmp
    if (lambda1 <= (-1.12d-8)) then
        tmp = r * acos(cos(lambda1))
    else
        tmp = r * (lambda2 - lambda1)
    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.12e-8) {
		tmp = R * Math.acos(Math.cos(lambda1));
	} else {
		tmp = R * (lambda2 - lambda1);
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if lambda1 <= -1.12e-8:
		tmp = R * math.acos(math.cos(lambda1))
	else:
		tmp = R * (lambda2 - lambda1)
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (lambda1 <= -1.12e-8)
		tmp = Float64(R * acos(cos(lambda1)));
	else
		tmp = Float64(R * Float64(lambda2 - lambda1));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (lambda1 <= -1.12e-8)
		tmp = R * acos(cos(lambda1));
	else
		tmp = R * (lambda2 - lambda1);
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda1, -1.12e-8], N[(R * N[ArcCos[N[Cos[lambda1], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 \leq -1.12 \cdot 10^{-8}:\\
\;\;\;\;R \cdot \cos^{-1} \cos \lambda_1\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda1 < -1.11999999999999994e-8

    1. Initial program 61.5%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6443.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified43.3%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      2. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      3. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(\lambda_2\right)\right) + \lambda_1\right)\right)\right)\right), R\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      5. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)\right), R\right) \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right), R\right) \]
      8. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      10. --lowering--.f6433.7%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), R\right) \]
    8. Simplified33.7%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\color{blue}{\cos \lambda_1}\right), R\right) \]
    10. Step-by-step derivation
      1. cos-lowering-cos.f6432.7%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\lambda_1\right)\right), R\right) \]
    11. Simplified32.7%

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

    if -1.11999999999999994e-8 < lambda1

    1. Initial program 74.7%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      4. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
      8. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
      9. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
      12. --lowering--.f6439.6%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
    5. Simplified39.6%

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      2. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
      3. distribute-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(\lambda_2\right)\right) + \lambda_1\right)\right)\right)\right), R\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
      5. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right)\right), R\right) \]
      6. cos-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)\right), R\right) \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right), R\right) \]
      8. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
      9. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
      10. --lowering--.f6424.2%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), R\right) \]
    8. Simplified24.2%

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

        \[\leadsto \left(\lambda_1 - \lambda_2\right) \cdot R \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \color{blue}{R}\right) \]
      3. acos-cos-sN/A

        \[\leadsto \mathsf{*.f64}\left(\cos^{-1} \cos \left(\lambda_1 - \lambda_2\right), R\right) \]
      4. cos-diffN/A

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

        \[\leadsto \mathsf{*.f64}\left(\cos^{-1} \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_1 \cdot \sin \lambda_2\right), R\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\cos^{-1} \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right), R\right) \]
      7. cos-diffN/A

        \[\leadsto \mathsf{*.f64}\left(\cos^{-1} \cos \left(\lambda_2 - \lambda_1\right), R\right) \]
      8. acos-cos-sN/A

        \[\leadsto \mathsf{*.f64}\left(\left(\lambda_2 - \lambda_1\right), R\right) \]
      9. --lowering--.f646.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right), R\right) \]
    10. Applied egg-rr6.8%

      \[\leadsto \color{blue}{\left(\lambda_2 - \lambda_1\right) \cdot R} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification13.0%

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

Alternative 28: 5.8% accurate, 122.6× speedup?

\[\begin{array}{l} \\ R \cdot \left(\lambda_2 - \lambda_1\right) \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (* R (- lambda2 lambda1)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * (lambda2 - lambda1);
}
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 * (lambda2 - lambda1)
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * (lambda2 - lambda1);
}
def code(R, lambda1, lambda2, phi1, phi2):
	return R * (lambda2 - lambda1)
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(R * Float64(lambda2 - lambda1))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = R * (lambda2 - lambda1);
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
R \cdot \left(\lambda_2 - \lambda_1\right)
\end{array}
Derivation
  1. Initial program 71.5%

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

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
    2. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
    3. sub-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    4. remove-double-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    5. mul-1-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    6. distribute-neg-inN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
    7. +-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
    8. cos-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
    9. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
    10. mul-1-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
    11. unsub-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
    12. --lowering--.f6440.5%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
  5. Simplified40.5%

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

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
    2. remove-double-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
    3. distribute-neg-inN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(\lambda_2\right)\right) + \lambda_1\right)\right)\right)\right), R\right) \]
    4. +-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    5. neg-mul-1N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right)\right), R\right) \]
    6. cos-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)\right), R\right) \]
    7. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right), R\right) \]
    8. neg-mul-1N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    9. sub-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
    10. --lowering--.f6426.5%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), R\right) \]
  8. Simplified26.5%

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

      \[\leadsto \left(\lambda_1 - \lambda_2\right) \cdot R \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \color{blue}{R}\right) \]
    3. acos-cos-sN/A

      \[\leadsto \mathsf{*.f64}\left(\cos^{-1} \cos \left(\lambda_1 - \lambda_2\right), R\right) \]
    4. cos-diffN/A

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

      \[\leadsto \mathsf{*.f64}\left(\cos^{-1} \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_1 \cdot \sin \lambda_2\right), R\right) \]
    6. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(\cos^{-1} \left(\cos \lambda_2 \cdot \cos \lambda_1 + \sin \lambda_2 \cdot \sin \lambda_1\right), R\right) \]
    7. cos-diffN/A

      \[\leadsto \mathsf{*.f64}\left(\cos^{-1} \cos \left(\lambda_2 - \lambda_1\right), R\right) \]
    8. acos-cos-sN/A

      \[\leadsto \mathsf{*.f64}\left(\left(\lambda_2 - \lambda_1\right), R\right) \]
    9. --lowering--.f646.3%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right), R\right) \]
  10. Applied egg-rr6.3%

    \[\leadsto \color{blue}{\left(\lambda_2 - \lambda_1\right) \cdot R} \]
  11. Final simplification6.3%

    \[\leadsto R \cdot \left(\lambda_2 - \lambda_1\right) \]
  12. Add Preprocessing

Alternative 29: 5.2% accurate, 204.3× speedup?

\[\begin{array}{l} \\ \lambda_1 \cdot R \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* lambda1 R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return 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 = lambda1 * r
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return lambda1 * R;
}
def code(R, lambda1, lambda2, phi1, phi2):
	return lambda1 * R
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(lambda1 * R)
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = lambda1 * R;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(lambda1 * R), $MachinePrecision]
\begin{array}{l}

\\
\lambda_1 \cdot R
\end{array}
Derivation
  1. Initial program 71.5%

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

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\cos \phi_1, \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
    2. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
    3. sub-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    4. remove-double-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    5. mul-1-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\left(\mathsf{neg}\left(-1 \cdot \lambda_1\right)\right) + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    6. distribute-neg-inN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(-1 \cdot \lambda_1 + \lambda_2\right)\right)\right)\right)\right), R\right) \]
    7. +-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\mathsf{neg}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right)\right), R\right) \]
    8. cos-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \cos \left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right), R\right) \]
    9. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + -1 \cdot \lambda_1\right)\right)\right)\right), R\right) \]
    10. mul-1-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right)\right)\right), R\right) \]
    11. unsub-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\left(\lambda_2 - \lambda_1\right)\right)\right)\right), R\right) \]
    12. --lowering--.f6440.5%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\phi_1\right), \mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_2, \lambda_1\right)\right)\right)\right), R\right) \]
  5. Simplified40.5%

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

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_2 + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
    2. remove-double-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right) + \left(\mathsf{neg}\left(\lambda_1\right)\right)\right)\right), R\right) \]
    3. distribute-neg-inN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(\lambda_2\right)\right) + \lambda_1\right)\right)\right)\right), R\right) \]
    4. +-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right)\right), R\right) \]
    5. neg-mul-1N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\mathsf{neg}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right)\right), R\right) \]
    6. cos-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\cos \left(\lambda_1 + -1 \cdot \lambda_2\right)\right), R\right) \]
    7. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + -1 \cdot \lambda_2\right)\right)\right), R\right) \]
    8. neg-mul-1N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 + \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)\right)\right), R\right) \]
    9. sub-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\left(\lambda_1 - \lambda_2\right)\right)\right), R\right) \]
    10. --lowering--.f6426.5%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{acos.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right)\right)\right), R\right) \]
  8. Simplified26.5%

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

    \[\leadsto \color{blue}{R \cdot \lambda_1} \]
  10. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \lambda_1 \cdot \color{blue}{R} \]
    2. *-lowering-*.f644.1%

      \[\leadsto \mathsf{*.f64}\left(\lambda_1, \color{blue}{R}\right) \]
  11. Simplified4.1%

    \[\leadsto \color{blue}{\lambda_1 \cdot R} \]
  12. Add Preprocessing

Reproduce

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