Destination given bearing on a great circle

Percentage Accurate: 99.8% → 99.8%
Time: 13.0s
Alternatives: 11
Speedup: 1.2×

Specification

?
\[\begin{array}{l} \\ \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \end{array} \]
(FPCore (lambda1 phi1 phi2 delta theta)
 :precision binary64
 (+
  lambda1
  (atan2
   (* (* (sin theta) (sin delta)) (cos phi1))
   (-
    (cos delta)
    (*
     (sin phi1)
     (sin
      (asin
       (+
        (* (sin phi1) (cos delta))
        (* (* (cos phi1) (sin delta)) (cos theta))))))))))
double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))));
}
real(8) function code(lambda1, phi1, phi2, delta, theta)
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8), intent (in) :: delta
    real(8), intent (in) :: theta
    code = lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))))
end function
public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return lambda1 + Math.atan2(((Math.sin(theta) * Math.sin(delta)) * Math.cos(phi1)), (Math.cos(delta) - (Math.sin(phi1) * Math.sin(Math.asin(((Math.sin(phi1) * Math.cos(delta)) + ((Math.cos(phi1) * Math.sin(delta)) * Math.cos(theta))))))));
}
def code(lambda1, phi1, phi2, delta, theta):
	return lambda1 + math.atan2(((math.sin(theta) * math.sin(delta)) * math.cos(phi1)), (math.cos(delta) - (math.sin(phi1) * math.sin(math.asin(((math.sin(phi1) * math.cos(delta)) + ((math.cos(phi1) * math.sin(delta)) * math.cos(theta))))))))
function code(lambda1, phi1, phi2, delta, theta)
	return Float64(lambda1 + atan(Float64(Float64(sin(theta) * sin(delta)) * cos(phi1)), Float64(cos(delta) - Float64(sin(phi1) * sin(asin(Float64(Float64(sin(phi1) * cos(delta)) + Float64(Float64(cos(phi1) * sin(delta)) * cos(theta)))))))))
end
function tmp = code(lambda1, phi1, phi2, delta, theta)
	tmp = lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))));
end
code[lambda1_, phi1_, phi2_, delta_, theta_] := N[(lambda1 + N[ArcTan[N[(N[(N[Sin[theta], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[delta], $MachinePrecision] - N[(N[Sin[phi1], $MachinePrecision] * N[Sin[N[ArcSin[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Cos[delta], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] * N[Cos[theta], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)}
\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 11 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: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \end{array} \]
(FPCore (lambda1 phi1 phi2 delta theta)
 :precision binary64
 (+
  lambda1
  (atan2
   (* (* (sin theta) (sin delta)) (cos phi1))
   (-
    (cos delta)
    (*
     (sin phi1)
     (sin
      (asin
       (+
        (* (sin phi1) (cos delta))
        (* (* (cos phi1) (sin delta)) (cos theta))))))))))
double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))));
}
real(8) function code(lambda1, phi1, phi2, delta, theta)
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8), intent (in) :: delta
    real(8), intent (in) :: theta
    code = lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))))
end function
public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return lambda1 + Math.atan2(((Math.sin(theta) * Math.sin(delta)) * Math.cos(phi1)), (Math.cos(delta) - (Math.sin(phi1) * Math.sin(Math.asin(((Math.sin(phi1) * Math.cos(delta)) + ((Math.cos(phi1) * Math.sin(delta)) * Math.cos(theta))))))));
}
def code(lambda1, phi1, phi2, delta, theta):
	return lambda1 + math.atan2(((math.sin(theta) * math.sin(delta)) * math.cos(phi1)), (math.cos(delta) - (math.sin(phi1) * math.sin(math.asin(((math.sin(phi1) * math.cos(delta)) + ((math.cos(phi1) * math.sin(delta)) * math.cos(theta))))))))
function code(lambda1, phi1, phi2, delta, theta)
	return Float64(lambda1 + atan(Float64(Float64(sin(theta) * sin(delta)) * cos(phi1)), Float64(cos(delta) - Float64(sin(phi1) * sin(asin(Float64(Float64(sin(phi1) * cos(delta)) + Float64(Float64(cos(phi1) * sin(delta)) * cos(theta)))))))))
end
function tmp = code(lambda1, phi1, phi2, delta, theta)
	tmp = lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))));
end
code[lambda1_, phi1_, phi2_, delta_, theta_] := N[(lambda1 + N[ArcTan[N[(N[(N[Sin[theta], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[delta], $MachinePrecision] - N[(N[Sin[phi1], $MachinePrecision] * N[Sin[N[ArcSin[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Cos[delta], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] * N[Cos[theta], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)}
\end{array}

Alternative 1: 99.8% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := -\sin \phi_1\\ \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\mathsf{fma}\left(\cos theta \cdot t\_1, \cos \phi_1 \cdot \sin delta, \mathsf{fma}\left(\cos delta \cdot t\_1, \sin \phi_1, \cos delta\right)\right)} + \lambda_1 \end{array} \end{array} \]
(FPCore (lambda1 phi1 phi2 delta theta)
 :precision binary64
 (let* ((t_1 (- (sin phi1))))
   (+
    (atan2
     (* (cos phi1) (* (sin delta) (sin theta)))
     (fma
      (* (cos theta) t_1)
      (* (cos phi1) (sin delta))
      (fma (* (cos delta) t_1) (sin phi1) (cos delta))))
    lambda1)))
double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	double t_1 = -sin(phi1);
	return atan2((cos(phi1) * (sin(delta) * sin(theta))), fma((cos(theta) * t_1), (cos(phi1) * sin(delta)), fma((cos(delta) * t_1), sin(phi1), cos(delta)))) + lambda1;
}
function code(lambda1, phi1, phi2, delta, theta)
	t_1 = Float64(-sin(phi1))
	return Float64(atan(Float64(cos(phi1) * Float64(sin(delta) * sin(theta))), fma(Float64(cos(theta) * t_1), Float64(cos(phi1) * sin(delta)), fma(Float64(cos(delta) * t_1), sin(phi1), cos(delta)))) + lambda1)
end
code[lambda1_, phi1_, phi2_, delta_, theta_] := Block[{t$95$1 = (-N[Sin[phi1], $MachinePrecision])}, N[(N[ArcTan[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Sin[delta], $MachinePrecision] * N[Sin[theta], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[theta], $MachinePrecision] * t$95$1), $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[delta], $MachinePrecision] * t$95$1), $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[Cos[delta], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + lambda1), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := -\sin \phi_1\\
\tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\mathsf{fma}\left(\cos theta \cdot t\_1, \cos \phi_1 \cdot \sin delta, \mathsf{fma}\left(\cos delta \cdot t\_1, \sin \phi_1, \cos delta\right)\right)} + \lambda_1
\end{array}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \]
  2. Add Preprocessing
  3. Applied rewrites99.8%

    \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\color{blue}{\mathsf{fma}\left(\left(-\sin \phi_1\right) \cdot \cos theta, \sin delta \cdot \cos \phi_1, \mathsf{fma}\left(\left(-\sin \phi_1\right) \cdot \cos delta, \sin \phi_1, \cos delta\right)\right)}} \]
  4. Final simplification99.8%

    \[\leadsto \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\mathsf{fma}\left(\cos theta \cdot \left(-\sin \phi_1\right), \cos \phi_1 \cdot \sin delta, \mathsf{fma}\left(\cos delta \cdot \left(-\sin \phi_1\right), \sin \phi_1, \cos delta\right)\right)} + \lambda_1 \]
  5. Add Preprocessing

Alternative 2: 74.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \sin \sin^{-1} \left(\left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta + \cos delta \cdot \sin \phi_1\right) \cdot \sin \phi_1}\\ t_2 := \tan^{-1}_* \frac{\left(\mathsf{fma}\left(\phi_1 \cdot \phi_1, -0.5, 1\right) \cdot theta\right) \cdot \sin delta}{\cos delta} + \lambda_1\\ \mathbf{if}\;t\_1 \leq -1 \cdot 10^{-161}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_1 \leq 10^{-61}:\\ \;\;\;\;\frac{1}{\frac{1}{\lambda_1}}\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (lambda1 phi1 phi2 delta theta)
 :precision binary64
 (let* ((t_1
         (atan2
          (* (cos phi1) (* (sin delta) (sin theta)))
          (-
           (cos delta)
           (*
            (sin
             (asin
              (+
               (* (* (cos phi1) (sin delta)) (cos theta))
               (* (cos delta) (sin phi1)))))
            (sin phi1)))))
        (t_2
         (+
          (atan2
           (* (* (fma (* phi1 phi1) -0.5 1.0) theta) (sin delta))
           (cos delta))
          lambda1)))
   (if (<= t_1 -1e-161) t_2 (if (<= t_1 1e-61) (/ 1.0 (/ 1.0 lambda1)) t_2))))
double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	double t_1 = atan2((cos(phi1) * (sin(delta) * sin(theta))), (cos(delta) - (sin(asin((((cos(phi1) * sin(delta)) * cos(theta)) + (cos(delta) * sin(phi1))))) * sin(phi1))));
	double t_2 = atan2(((fma((phi1 * phi1), -0.5, 1.0) * theta) * sin(delta)), cos(delta)) + lambda1;
	double tmp;
	if (t_1 <= -1e-161) {
		tmp = t_2;
	} else if (t_1 <= 1e-61) {
		tmp = 1.0 / (1.0 / lambda1);
	} else {
		tmp = t_2;
	}
	return tmp;
}
function code(lambda1, phi1, phi2, delta, theta)
	t_1 = atan(Float64(cos(phi1) * Float64(sin(delta) * sin(theta))), Float64(cos(delta) - Float64(sin(asin(Float64(Float64(Float64(cos(phi1) * sin(delta)) * cos(theta)) + Float64(cos(delta) * sin(phi1))))) * sin(phi1))))
	t_2 = Float64(atan(Float64(Float64(fma(Float64(phi1 * phi1), -0.5, 1.0) * theta) * sin(delta)), cos(delta)) + lambda1)
	tmp = 0.0
	if (t_1 <= -1e-161)
		tmp = t_2;
	elseif (t_1 <= 1e-61)
		tmp = Float64(1.0 / Float64(1.0 / lambda1));
	else
		tmp = t_2;
	end
	return tmp
end
code[lambda1_, phi1_, phi2_, delta_, theta_] := Block[{t$95$1 = N[ArcTan[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Sin[delta], $MachinePrecision] * N[Sin[theta], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[delta], $MachinePrecision] - N[(N[Sin[N[ArcSin[N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] * N[Cos[theta], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[delta], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[ArcTan[N[(N[(N[(N[(phi1 * phi1), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] * theta), $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] / N[Cos[delta], $MachinePrecision]], $MachinePrecision] + lambda1), $MachinePrecision]}, If[LessEqual[t$95$1, -1e-161], t$95$2, If[LessEqual[t$95$1, 1e-61], N[(1.0 / N[(1.0 / lambda1), $MachinePrecision]), $MachinePrecision], t$95$2]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \sin \sin^{-1} \left(\left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta + \cos delta \cdot \sin \phi_1\right) \cdot \sin \phi_1}\\
t_2 := \tan^{-1}_* \frac{\left(\mathsf{fma}\left(\phi_1 \cdot \phi_1, -0.5, 1\right) \cdot theta\right) \cdot \sin delta}{\cos delta} + \lambda_1\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{-161}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_1 \leq 10^{-61}:\\
\;\;\;\;\frac{1}{\frac{1}{\lambda_1}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (atan2.f64 (*.f64 (*.f64 (sin.f64 theta) (sin.f64 delta)) (cos.f64 phi1)) (-.f64 (cos.f64 delta) (*.f64 (sin.f64 phi1) (sin.f64 (asin.f64 (+.f64 (*.f64 (sin.f64 phi1) (cos.f64 delta)) (*.f64 (*.f64 (cos.f64 phi1) (sin.f64 delta)) (cos.f64 theta)))))))) < -1.00000000000000003e-161 or 1e-61 < (atan2.f64 (*.f64 (*.f64 (sin.f64 theta) (sin.f64 delta)) (cos.f64 phi1)) (-.f64 (cos.f64 delta) (*.f64 (sin.f64 phi1) (sin.f64 (asin.f64 (+.f64 (*.f64 (sin.f64 phi1) (cos.f64 delta)) (*.f64 (*.f64 (cos.f64 phi1) (sin.f64 delta)) (cos.f64 theta))))))))

    1. Initial program 99.7%

      \[\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\color{blue}{\cos delta}} \]
    4. Step-by-step derivation
      1. lower-cos.f6485.2

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\color{blue}{\cos delta}} \]
    5. Applied rewrites85.2%

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\color{blue}{\cos delta}} \]
    6. Taylor expanded in phi1 around 0

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\frac{-1}{2} \cdot \left({\phi_1}^{2} \cdot \left(\sin delta \cdot \sin theta\right)\right) + \sin delta \cdot \sin theta}}{\cos delta} \]
    7. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\left(\frac{-1}{2} \cdot {\phi_1}^{2}\right) \cdot \left(\sin delta \cdot \sin theta\right)} + \sin delta \cdot \sin theta}{\cos delta} \]
      2. distribute-lft1-inN/A

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

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\left(\frac{-1}{2} \cdot {\phi_1}^{2} + 1\right) \cdot \left(\sin delta \cdot \sin theta\right)}}{\cos delta} \]
      4. lower-fma.f64N/A

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\mathsf{fma}\left(\frac{-1}{2}, {\phi_1}^{2}, 1\right)} \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta} \]
      5. unpow2N/A

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

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

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\mathsf{fma}\left(\frac{-1}{2}, \phi_1 \cdot \phi_1, 1\right) \cdot \color{blue}{\left(\sin theta \cdot \sin delta\right)}}{\cos delta} \]
      8. lower-*.f64N/A

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

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\mathsf{fma}\left(\frac{-1}{2}, \phi_1 \cdot \phi_1, 1\right) \cdot \left(\color{blue}{\sin theta} \cdot \sin delta\right)}{\cos delta} \]
      10. lower-sin.f6478.9

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\mathsf{fma}\left(-0.5, \phi_1 \cdot \phi_1, 1\right) \cdot \left(\sin theta \cdot \color{blue}{\sin delta}\right)}{\cos delta} \]
    8. Applied rewrites78.9%

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\mathsf{fma}\left(-0.5, \phi_1 \cdot \phi_1, 1\right) \cdot \left(\sin theta \cdot \sin delta\right)}}{\cos delta} \]
    9. Taylor expanded in theta around 0

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{theta \cdot \color{blue}{\left(\sin delta \cdot \left(1 + \frac{-1}{2} \cdot {\phi_1}^{2}\right)\right)}}{\cos delta} \]
    10. Step-by-step derivation
      1. Applied rewrites64.5%

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(theta \cdot \mathsf{fma}\left(\phi_1 \cdot \phi_1, -0.5, 1\right)\right) \cdot \color{blue}{\sin delta}}{\cos delta} \]

      if -1.00000000000000003e-161 < (atan2.f64 (*.f64 (*.f64 (sin.f64 theta) (sin.f64 delta)) (cos.f64 phi1)) (-.f64 (cos.f64 delta) (*.f64 (sin.f64 phi1) (sin.f64 (asin.f64 (+.f64 (*.f64 (sin.f64 phi1) (cos.f64 delta)) (*.f64 (*.f64 (cos.f64 phi1) (sin.f64 delta)) (cos.f64 theta)))))))) < 1e-61

      1. Initial program 99.8%

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

          \[\leadsto \color{blue}{\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)}} \]
        2. flip3-+N/A

          \[\leadsto \color{blue}{\frac{{\lambda_1}^{3} + {\tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)}}^{3}}{\lambda_1 \cdot \lambda_1 + \left(\tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \cdot \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} - \lambda_1 \cdot \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)}\right)}} \]
      4. Applied rewrites99.5%

        \[\leadsto \color{blue}{\frac{1}{\frac{1}{\tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \mathsf{fma}\left(\cos theta, \sin delta \cdot \cos \phi_1, \cos delta \cdot \sin \phi_1\right) \cdot \sin \phi_1} + \lambda_1}}} \]
      5. Taylor expanded in lambda1 around inf

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{\lambda_1}}} \]
      6. Step-by-step derivation
        1. lower-/.f6494.6

          \[\leadsto \frac{1}{\color{blue}{\frac{1}{\lambda_1}}} \]
      7. Applied rewrites94.6%

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{\lambda_1}}} \]
    11. Recombined 2 regimes into one program.
    12. Final simplification79.5%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \sin \sin^{-1} \left(\left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta + \cos delta \cdot \sin \phi_1\right) \cdot \sin \phi_1} \leq -1 \cdot 10^{-161}:\\ \;\;\;\;\tan^{-1}_* \frac{\left(\mathsf{fma}\left(\phi_1 \cdot \phi_1, -0.5, 1\right) \cdot theta\right) \cdot \sin delta}{\cos delta} + \lambda_1\\ \mathbf{elif}\;\tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \sin \sin^{-1} \left(\left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta + \cos delta \cdot \sin \phi_1\right) \cdot \sin \phi_1} \leq 10^{-61}:\\ \;\;\;\;\frac{1}{\frac{1}{\lambda_1}}\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1}_* \frac{\left(\mathsf{fma}\left(\phi_1 \cdot \phi_1, -0.5, 1\right) \cdot theta\right) \cdot \sin delta}{\cos delta} + \lambda_1\\ \end{array} \]
    13. Add Preprocessing

    Alternative 3: 99.8% accurate, 1.2× speedup?

    \[\begin{array}{l} \\ \tan^{-1}_* \frac{\left(\cos \phi_1 \cdot \sin delta\right) \cdot \sin theta}{\mathsf{fma}\left(\mathsf{fma}\left(\cos theta \cdot \cos \phi_1, \sin delta, \cos delta \cdot \sin \phi_1\right), -\sin \phi_1, \cos delta\right)} + \lambda_1 \end{array} \]
    (FPCore (lambda1 phi1 phi2 delta theta)
     :precision binary64
     (+
      (atan2
       (* (* (cos phi1) (sin delta)) (sin theta))
       (fma
        (fma (* (cos theta) (cos phi1)) (sin delta) (* (cos delta) (sin phi1)))
        (- (sin phi1))
        (cos delta)))
      lambda1))
    double code(double lambda1, double phi1, double phi2, double delta, double theta) {
    	return atan2(((cos(phi1) * sin(delta)) * sin(theta)), fma(fma((cos(theta) * cos(phi1)), sin(delta), (cos(delta) * sin(phi1))), -sin(phi1), cos(delta))) + lambda1;
    }
    
    function code(lambda1, phi1, phi2, delta, theta)
    	return Float64(atan(Float64(Float64(cos(phi1) * sin(delta)) * sin(theta)), fma(fma(Float64(cos(theta) * cos(phi1)), sin(delta), Float64(cos(delta) * sin(phi1))), Float64(-sin(phi1)), cos(delta))) + lambda1)
    end
    
    code[lambda1_, phi1_, phi2_, delta_, theta_] := N[(N[ArcTan[N[(N[(N[Cos[phi1], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] * N[Sin[theta], $MachinePrecision]), $MachinePrecision] / N[(N[(N[(N[Cos[theta], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[Sin[delta], $MachinePrecision] + N[(N[Cos[delta], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * (-N[Sin[phi1], $MachinePrecision]) + N[Cos[delta], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + lambda1), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \tan^{-1}_* \frac{\left(\cos \phi_1 \cdot \sin delta\right) \cdot \sin theta}{\mathsf{fma}\left(\mathsf{fma}\left(\cos theta \cdot \cos \phi_1, \sin delta, \cos delta \cdot \sin \phi_1\right), -\sin \phi_1, \cos delta\right)} + \lambda_1
    \end{array}
    
    Derivation
    1. Initial program 99.8%

      \[\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \]
    2. Add Preprocessing
    3. Applied rewrites99.8%

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\color{blue}{\mathsf{fma}\left(\left(-\sin \phi_1\right) \cdot \cos theta, \sin delta \cdot \cos \phi_1, \mathsf{fma}\left(\left(-\sin \phi_1\right) \cdot \cos delta, \sin \phi_1, \cos delta\right)\right)}} \]
    4. Applied rewrites99.8%

      \[\leadsto \color{blue}{\tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\mathsf{fma}\left(\mathsf{fma}\left(\cos theta \cdot \cos \phi_1, \sin delta, \cos delta \cdot \sin \phi_1\right), -\sin \phi_1, \cos delta\right)} + \lambda_1} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}}{\mathsf{fma}\left(\mathsf{fma}\left(\cos theta \cdot \cos \phi_1, \sin delta, \cos delta \cdot \sin \phi_1\right), -\sin \phi_1, \cos delta\right)} + \lambda_1 \]
      2. *-commutativeN/A

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\cos \phi_1 \cdot \left(\sin theta \cdot \sin delta\right)}}{\mathsf{fma}\left(\mathsf{fma}\left(\cos theta \cdot \cos \phi_1, \sin delta, \cos delta \cdot \sin \phi_1\right), -\sin \phi_1, \cos delta\right)} + \lambda_1 \]
      3. lift-*.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\cos \phi_1 \cdot \color{blue}{\left(\sin theta \cdot \sin delta\right)}}{\mathsf{fma}\left(\mathsf{fma}\left(\cos theta \cdot \cos \phi_1, \sin delta, \cos delta \cdot \sin \phi_1\right), -\sin \phi_1, \cos delta\right)} + \lambda_1 \]
      4. *-commutativeN/A

        \[\leadsto \tan^{-1}_* \frac{\cos \phi_1 \cdot \color{blue}{\left(\sin delta \cdot \sin theta\right)}}{\mathsf{fma}\left(\mathsf{fma}\left(\cos theta \cdot \cos \phi_1, \sin delta, \cos delta \cdot \sin \phi_1\right), -\sin \phi_1, \cos delta\right)} + \lambda_1 \]
      5. associate-*l*N/A

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\cos \phi_1 \cdot \sin delta\right) \cdot \sin theta}}{\mathsf{fma}\left(\mathsf{fma}\left(\cos theta \cdot \cos \phi_1, \sin delta, \cos delta \cdot \sin \phi_1\right), -\sin \phi_1, \cos delta\right)} + \lambda_1 \]
      6. lift-*.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\cos \phi_1 \cdot \sin delta\right)} \cdot \sin theta}{\mathsf{fma}\left(\mathsf{fma}\left(\cos theta \cdot \cos \phi_1, \sin delta, \cos delta \cdot \sin \phi_1\right), -\sin \phi_1, \cos delta\right)} + \lambda_1 \]
      7. lift-*.f6499.8

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\cos \phi_1 \cdot \sin delta\right) \cdot \sin theta}}{\mathsf{fma}\left(\mathsf{fma}\left(\cos theta \cdot \cos \phi_1, \sin delta, \cos delta \cdot \sin \phi_1\right), -\sin \phi_1, \cos delta\right)} + \lambda_1 \]
    6. Applied rewrites99.8%

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\cos \phi_1 \cdot \sin delta\right) \cdot \sin theta}}{\mathsf{fma}\left(\mathsf{fma}\left(\cos theta \cdot \cos \phi_1, \sin delta, \cos delta \cdot \sin \phi_1\right), -\sin \phi_1, \cos delta\right)} + \lambda_1 \]
    7. Add Preprocessing

    Alternative 4: 99.8% accurate, 1.2× speedup?

    \[\begin{array}{l} \\ \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\cos theta, \cos \phi_1 \cdot \sin delta, \cos delta \cdot \sin \phi_1\right), -\sin \phi_1, \cos delta\right)} + \lambda_1 \end{array} \]
    (FPCore (lambda1 phi1 phi2 delta theta)
     :precision binary64
     (+
      (atan2
       (* (cos phi1) (* (sin delta) (sin theta)))
       (fma
        (fma (cos theta) (* (cos phi1) (sin delta)) (* (cos delta) (sin phi1)))
        (- (sin phi1))
        (cos delta)))
      lambda1))
    double code(double lambda1, double phi1, double phi2, double delta, double theta) {
    	return atan2((cos(phi1) * (sin(delta) * sin(theta))), fma(fma(cos(theta), (cos(phi1) * sin(delta)), (cos(delta) * sin(phi1))), -sin(phi1), cos(delta))) + lambda1;
    }
    
    function code(lambda1, phi1, phi2, delta, theta)
    	return Float64(atan(Float64(cos(phi1) * Float64(sin(delta) * sin(theta))), fma(fma(cos(theta), Float64(cos(phi1) * sin(delta)), Float64(cos(delta) * sin(phi1))), Float64(-sin(phi1)), cos(delta))) + lambda1)
    end
    
    code[lambda1_, phi1_, phi2_, delta_, theta_] := N[(N[ArcTan[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Sin[delta], $MachinePrecision] * N[Sin[theta], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[theta], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[delta], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * (-N[Sin[phi1], $MachinePrecision]) + N[Cos[delta], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + lambda1), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\cos theta, \cos \phi_1 \cdot \sin delta, \cos delta \cdot \sin \phi_1\right), -\sin \phi_1, \cos delta\right)} + \lambda_1
    \end{array}
    
    Derivation
    1. Initial program 99.8%

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

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\color{blue}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)}} \]
      2. sub-negN/A

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\color{blue}{\cos delta + \left(\mathsf{neg}\left(\sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)\right)\right)}} \]
      3. +-commutativeN/A

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\color{blue}{\left(\mathsf{neg}\left(\sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)\right)\right) + \cos delta}} \]
    4. Applied rewrites99.8%

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\cos theta, \sin delta \cdot \cos \phi_1, \cos delta \cdot \sin \phi_1\right), -\sin \phi_1, \cos delta\right)}} \]
    5. Final simplification99.8%

      \[\leadsto \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\cos theta, \cos \phi_1 \cdot \sin delta, \cos delta \cdot \sin \phi_1\right), -\sin \phi_1, \cos delta\right)} + \lambda_1 \]
    6. Add Preprocessing

    Alternative 5: 94.9% accurate, 1.3× speedup?

    \[\begin{array}{l} \\ \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\sin \phi_1, \cos delta, \cos \phi_1 \cdot \sin delta\right), -\sin \phi_1, \cos delta\right)} + \lambda_1 \end{array} \]
    (FPCore (lambda1 phi1 phi2 delta theta)
     :precision binary64
     (+
      (atan2
       (* (cos phi1) (* (sin delta) (sin theta)))
       (fma
        (fma (sin phi1) (cos delta) (* (cos phi1) (sin delta)))
        (- (sin phi1))
        (cos delta)))
      lambda1))
    double code(double lambda1, double phi1, double phi2, double delta, double theta) {
    	return atan2((cos(phi1) * (sin(delta) * sin(theta))), fma(fma(sin(phi1), cos(delta), (cos(phi1) * sin(delta))), -sin(phi1), cos(delta))) + lambda1;
    }
    
    function code(lambda1, phi1, phi2, delta, theta)
    	return Float64(atan(Float64(cos(phi1) * Float64(sin(delta) * sin(theta))), fma(fma(sin(phi1), cos(delta), Float64(cos(phi1) * sin(delta))), Float64(-sin(phi1)), cos(delta))) + lambda1)
    end
    
    code[lambda1_, phi1_, phi2_, delta_, theta_] := N[(N[ArcTan[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Sin[delta], $MachinePrecision] * N[Sin[theta], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Sin[phi1], $MachinePrecision] * N[Cos[delta], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * (-N[Sin[phi1], $MachinePrecision]) + N[Cos[delta], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + lambda1), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\sin \phi_1, \cos delta, \cos \phi_1 \cdot \sin delta\right), -\sin \phi_1, \cos delta\right)} + \lambda_1
    \end{array}
    
    Derivation
    1. Initial program 99.8%

      \[\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \]
    2. Add Preprocessing
    3. Applied rewrites99.8%

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\color{blue}{\mathsf{fma}\left(\left(-\sin \phi_1\right) \cdot \cos theta, \sin delta \cdot \cos \phi_1, \mathsf{fma}\left(\left(-\sin \phi_1\right) \cdot \cos delta, \sin \phi_1, \cos delta\right)\right)}} \]
    4. Applied rewrites99.8%

      \[\leadsto \color{blue}{\tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\mathsf{fma}\left(\mathsf{fma}\left(\cos theta \cdot \cos \phi_1, \sin delta, \cos delta \cdot \sin \phi_1\right), -\sin \phi_1, \cos delta\right)} + \lambda_1} \]
    5. Taylor expanded in theta around 0

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

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

        \[\leadsto \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\sin \phi_1, \cos delta, \cos \phi_1 \cdot \sin delta\right)}, -\sin \phi_1, \cos delta\right)} + \lambda_1 \]
      3. lower-sin.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\sin \phi_1}, \cos delta, \cos \phi_1 \cdot \sin delta\right), -\sin \phi_1, \cos delta\right)} + \lambda_1 \]
      4. lower-cos.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\mathsf{fma}\left(\mathsf{fma}\left(\sin \phi_1, \color{blue}{\cos delta}, \cos \phi_1 \cdot \sin delta\right), -\sin \phi_1, \cos delta\right)} + \lambda_1 \]
      5. lower-*.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\mathsf{fma}\left(\mathsf{fma}\left(\sin \phi_1, \cos delta, \color{blue}{\cos \phi_1 \cdot \sin delta}\right), -\sin \phi_1, \cos delta\right)} + \lambda_1 \]
      6. lower-cos.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\mathsf{fma}\left(\mathsf{fma}\left(\sin \phi_1, \cos delta, \color{blue}{\cos \phi_1} \cdot \sin delta\right), -\sin \phi_1, \cos delta\right)} + \lambda_1 \]
      7. lower-sin.f6494.8

        \[\leadsto \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\mathsf{fma}\left(\mathsf{fma}\left(\sin \phi_1, \cos delta, \cos \phi_1 \cdot \color{blue}{\sin delta}\right), -\sin \phi_1, \cos delta\right)} + \lambda_1 \]
    7. Applied rewrites94.8%

      \[\leadsto \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\sin \phi_1, \cos delta, \cos \phi_1 \cdot \sin delta\right)}, -\sin \phi_1, \cos delta\right)} + \lambda_1 \]
    8. Final simplification94.8%

      \[\leadsto \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\sin \phi_1, \cos delta, \cos \phi_1 \cdot \sin delta\right), -\sin \phi_1, \cos delta\right)} + \lambda_1 \]
    9. Add Preprocessing

    Alternative 6: 94.8% accurate, 1.3× speedup?

    \[\begin{array}{l} \\ \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \mathsf{fma}\left(\sin \phi_1, \cos delta, \cos \phi_1 \cdot \sin delta\right) \cdot \sin \phi_1} + \lambda_1 \end{array} \]
    (FPCore (lambda1 phi1 phi2 delta theta)
     :precision binary64
     (+
      (atan2
       (* (cos phi1) (* (sin delta) (sin theta)))
       (-
        (cos delta)
        (* (fma (sin phi1) (cos delta) (* (cos phi1) (sin delta))) (sin phi1))))
      lambda1))
    double code(double lambda1, double phi1, double phi2, double delta, double theta) {
    	return atan2((cos(phi1) * (sin(delta) * sin(theta))), (cos(delta) - (fma(sin(phi1), cos(delta), (cos(phi1) * sin(delta))) * sin(phi1)))) + lambda1;
    }
    
    function code(lambda1, phi1, phi2, delta, theta)
    	return Float64(atan(Float64(cos(phi1) * Float64(sin(delta) * sin(theta))), Float64(cos(delta) - Float64(fma(sin(phi1), cos(delta), Float64(cos(phi1) * sin(delta))) * sin(phi1)))) + lambda1)
    end
    
    code[lambda1_, phi1_, phi2_, delta_, theta_] := N[(N[ArcTan[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Sin[delta], $MachinePrecision] * N[Sin[theta], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[delta], $MachinePrecision] - N[(N[(N[Sin[phi1], $MachinePrecision] * N[Cos[delta], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + lambda1), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \mathsf{fma}\left(\sin \phi_1, \cos delta, \cos \phi_1 \cdot \sin delta\right) \cdot \sin \phi_1} + \lambda_1
    \end{array}
    
    Derivation
    1. Initial program 99.8%

      \[\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in theta around 0

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

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

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \color{blue}{\left(\cos delta \cdot \sin \phi_1 + \cos \phi_1 \cdot \sin delta\right) \cdot \sin \phi_1}} \]
      3. *-commutativeN/A

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \left(\color{blue}{\sin \phi_1 \cdot \cos delta} + \cos \phi_1 \cdot \sin delta\right) \cdot \sin \phi_1} \]
      4. lower-fma.f64N/A

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \color{blue}{\mathsf{fma}\left(\sin \phi_1, \cos delta, \cos \phi_1 \cdot \sin delta\right)} \cdot \sin \phi_1} \]
      5. lower-sin.f64N/A

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \mathsf{fma}\left(\color{blue}{\sin \phi_1}, \cos delta, \cos \phi_1 \cdot \sin delta\right) \cdot \sin \phi_1} \]
      6. lower-cos.f64N/A

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \mathsf{fma}\left(\sin \phi_1, \color{blue}{\cos delta}, \cos \phi_1 \cdot \sin delta\right) \cdot \sin \phi_1} \]
      7. *-commutativeN/A

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \mathsf{fma}\left(\sin \phi_1, \cos delta, \color{blue}{\sin delta \cdot \cos \phi_1}\right) \cdot \sin \phi_1} \]
      8. lower-*.f64N/A

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

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \mathsf{fma}\left(\sin \phi_1, \cos delta, \color{blue}{\sin delta} \cdot \cos \phi_1\right) \cdot \sin \phi_1} \]
      10. lower-cos.f64N/A

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \mathsf{fma}\left(\sin \phi_1, \cos delta, \sin delta \cdot \color{blue}{\cos \phi_1}\right) \cdot \sin \phi_1} \]
      11. lower-sin.f6494.8

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \mathsf{fma}\left(\sin \phi_1, \cos delta, \sin delta \cdot \cos \phi_1\right) \cdot \color{blue}{\sin \phi_1}} \]
    5. Applied rewrites94.8%

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \color{blue}{\mathsf{fma}\left(\sin \phi_1, \cos delta, \sin delta \cdot \cos \phi_1\right) \cdot \sin \phi_1}} \]
    6. Final simplification94.8%

      \[\leadsto \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \mathsf{fma}\left(\sin \phi_1, \cos delta, \cos \phi_1 \cdot \sin delta\right) \cdot \sin \phi_1} + \lambda_1 \]
    7. Add Preprocessing

    Alternative 7: 92.5% accurate, 1.9× speedup?

    \[\begin{array}{l} \\ \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - {\sin \phi_1}^{2}} + \lambda_1 \end{array} \]
    (FPCore (lambda1 phi1 phi2 delta theta)
     :precision binary64
     (+
      (atan2
       (* (cos phi1) (* (sin delta) (sin theta)))
       (- (cos delta) (pow (sin phi1) 2.0)))
      lambda1))
    double code(double lambda1, double phi1, double phi2, double delta, double theta) {
    	return atan2((cos(phi1) * (sin(delta) * sin(theta))), (cos(delta) - pow(sin(phi1), 2.0))) + lambda1;
    }
    
    real(8) function code(lambda1, phi1, phi2, delta, theta)
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8), intent (in) :: delta
        real(8), intent (in) :: theta
        code = atan2((cos(phi1) * (sin(delta) * sin(theta))), (cos(delta) - (sin(phi1) ** 2.0d0))) + lambda1
    end function
    
    public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
    	return Math.atan2((Math.cos(phi1) * (Math.sin(delta) * Math.sin(theta))), (Math.cos(delta) - Math.pow(Math.sin(phi1), 2.0))) + lambda1;
    }
    
    def code(lambda1, phi1, phi2, delta, theta):
    	return math.atan2((math.cos(phi1) * (math.sin(delta) * math.sin(theta))), (math.cos(delta) - math.pow(math.sin(phi1), 2.0))) + lambda1
    
    function code(lambda1, phi1, phi2, delta, theta)
    	return Float64(atan(Float64(cos(phi1) * Float64(sin(delta) * sin(theta))), Float64(cos(delta) - (sin(phi1) ^ 2.0))) + lambda1)
    end
    
    function tmp = code(lambda1, phi1, phi2, delta, theta)
    	tmp = atan2((cos(phi1) * (sin(delta) * sin(theta))), (cos(delta) - (sin(phi1) ^ 2.0))) + lambda1;
    end
    
    code[lambda1_, phi1_, phi2_, delta_, theta_] := N[(N[ArcTan[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Sin[delta], $MachinePrecision] * N[Sin[theta], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[delta], $MachinePrecision] - N[Power[N[Sin[phi1], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + lambda1), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - {\sin \phi_1}^{2}} + \lambda_1
    \end{array}
    
    Derivation
    1. Initial program 99.8%

      \[\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in delta around 0

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \color{blue}{{\sin \phi_1}^{2}}} \]
    4. Step-by-step derivation
      1. lower-pow.f64N/A

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \color{blue}{{\sin \phi_1}^{2}}} \]
      2. lower-sin.f6493.0

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - {\color{blue}{\sin \phi_1}}^{2}} \]
    5. Applied rewrites93.0%

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \color{blue}{{\sin \phi_1}^{2}}} \]
    6. Final simplification93.0%

      \[\leadsto \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - {\sin \phi_1}^{2}} + \lambda_1 \]
    7. Add Preprocessing

    Alternative 8: 88.8% accurate, 2.6× speedup?

    \[\begin{array}{l} \\ \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta} + \lambda_1 \end{array} \]
    (FPCore (lambda1 phi1 phi2 delta theta)
     :precision binary64
     (+ (atan2 (* (cos phi1) (* (sin delta) (sin theta))) (cos delta)) lambda1))
    double code(double lambda1, double phi1, double phi2, double delta, double theta) {
    	return atan2((cos(phi1) * (sin(delta) * sin(theta))), cos(delta)) + lambda1;
    }
    
    real(8) function code(lambda1, phi1, phi2, delta, theta)
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8), intent (in) :: delta
        real(8), intent (in) :: theta
        code = atan2((cos(phi1) * (sin(delta) * sin(theta))), cos(delta)) + lambda1
    end function
    
    public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
    	return Math.atan2((Math.cos(phi1) * (Math.sin(delta) * Math.sin(theta))), Math.cos(delta)) + lambda1;
    }
    
    def code(lambda1, phi1, phi2, delta, theta):
    	return math.atan2((math.cos(phi1) * (math.sin(delta) * math.sin(theta))), math.cos(delta)) + lambda1
    
    function code(lambda1, phi1, phi2, delta, theta)
    	return Float64(atan(Float64(cos(phi1) * Float64(sin(delta) * sin(theta))), cos(delta)) + lambda1)
    end
    
    function tmp = code(lambda1, phi1, phi2, delta, theta)
    	tmp = atan2((cos(phi1) * (sin(delta) * sin(theta))), cos(delta)) + lambda1;
    end
    
    code[lambda1_, phi1_, phi2_, delta_, theta_] := N[(N[ArcTan[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Sin[delta], $MachinePrecision] * N[Sin[theta], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Cos[delta], $MachinePrecision]], $MachinePrecision] + lambda1), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta} + \lambda_1
    \end{array}
    
    Derivation
    1. Initial program 99.8%

      \[\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\color{blue}{\cos delta}} \]
    4. Step-by-step derivation
      1. lower-cos.f6490.3

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\color{blue}{\cos delta}} \]
    5. Applied rewrites90.3%

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\color{blue}{\cos delta}} \]
    6. Final simplification90.3%

      \[\leadsto \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta} + \lambda_1 \]
    7. Add Preprocessing

    Alternative 9: 86.8% accurate, 3.3× speedup?

    \[\begin{array}{l} \\ \tan^{-1}_* \frac{\sin delta \cdot \sin theta}{\cos delta} + \lambda_1 \end{array} \]
    (FPCore (lambda1 phi1 phi2 delta theta)
     :precision binary64
     (+ (atan2 (* (sin delta) (sin theta)) (cos delta)) lambda1))
    double code(double lambda1, double phi1, double phi2, double delta, double theta) {
    	return atan2((sin(delta) * sin(theta)), cos(delta)) + lambda1;
    }
    
    real(8) function code(lambda1, phi1, phi2, delta, theta)
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8), intent (in) :: delta
        real(8), intent (in) :: theta
        code = atan2((sin(delta) * sin(theta)), cos(delta)) + lambda1
    end function
    
    public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
    	return Math.atan2((Math.sin(delta) * Math.sin(theta)), Math.cos(delta)) + lambda1;
    }
    
    def code(lambda1, phi1, phi2, delta, theta):
    	return math.atan2((math.sin(delta) * math.sin(theta)), math.cos(delta)) + lambda1
    
    function code(lambda1, phi1, phi2, delta, theta)
    	return Float64(atan(Float64(sin(delta) * sin(theta)), cos(delta)) + lambda1)
    end
    
    function tmp = code(lambda1, phi1, phi2, delta, theta)
    	tmp = atan2((sin(delta) * sin(theta)), cos(delta)) + lambda1;
    end
    
    code[lambda1_, phi1_, phi2_, delta_, theta_] := N[(N[ArcTan[N[(N[Sin[delta], $MachinePrecision] * N[Sin[theta], $MachinePrecision]), $MachinePrecision] / N[Cos[delta], $MachinePrecision]], $MachinePrecision] + lambda1), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \tan^{-1}_* \frac{\sin delta \cdot \sin theta}{\cos delta} + \lambda_1
    \end{array}
    
    Derivation
    1. Initial program 99.8%

      \[\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\color{blue}{\cos delta}} \]
    4. Step-by-step derivation
      1. lower-cos.f6490.3

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\color{blue}{\cos delta}} \]
    5. Applied rewrites90.3%

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\color{blue}{\cos delta}} \]
    6. Taylor expanded in phi1 around 0

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\sin delta \cdot \sin theta}}{\cos delta} \]
    7. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\sin theta \cdot \sin delta}}{\cos delta} \]
      2. lower-*.f64N/A

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\sin theta \cdot \sin delta}}{\cos delta} \]
      3. lower-sin.f64N/A

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\sin theta} \cdot \sin delta}{\cos delta} \]
      4. lower-sin.f6487.2

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\sin theta \cdot \color{blue}{\sin delta}}{\cos delta} \]
    8. Applied rewrites87.2%

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\sin theta \cdot \sin delta}}{\cos delta} \]
    9. Final simplification87.2%

      \[\leadsto \tan^{-1}_* \frac{\sin delta \cdot \sin theta}{\cos delta} + \lambda_1 \]
    10. Add Preprocessing

    Alternative 10: 70.7% accurate, 58.3× speedup?

    \[\begin{array}{l} \\ \frac{1}{\frac{1}{\lambda_1}} \end{array} \]
    (FPCore (lambda1 phi1 phi2 delta theta)
     :precision binary64
     (/ 1.0 (/ 1.0 lambda1)))
    double code(double lambda1, double phi1, double phi2, double delta, double theta) {
    	return 1.0 / (1.0 / lambda1);
    }
    
    real(8) function code(lambda1, phi1, phi2, delta, theta)
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8), intent (in) :: delta
        real(8), intent (in) :: theta
        code = 1.0d0 / (1.0d0 / lambda1)
    end function
    
    public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
    	return 1.0 / (1.0 / lambda1);
    }
    
    def code(lambda1, phi1, phi2, delta, theta):
    	return 1.0 / (1.0 / lambda1)
    
    function code(lambda1, phi1, phi2, delta, theta)
    	return Float64(1.0 / Float64(1.0 / lambda1))
    end
    
    function tmp = code(lambda1, phi1, phi2, delta, theta)
    	tmp = 1.0 / (1.0 / lambda1);
    end
    
    code[lambda1_, phi1_, phi2_, delta_, theta_] := N[(1.0 / N[(1.0 / lambda1), $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \frac{1}{\frac{1}{\lambda_1}}
    \end{array}
    
    Derivation
    1. Initial program 99.8%

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

        \[\leadsto \color{blue}{\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)}} \]
      2. flip3-+N/A

        \[\leadsto \color{blue}{\frac{{\lambda_1}^{3} + {\tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)}}^{3}}{\lambda_1 \cdot \lambda_1 + \left(\tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \cdot \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} - \lambda_1 \cdot \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)}\right)}} \]
    4. Applied rewrites99.5%

      \[\leadsto \color{blue}{\frac{1}{\frac{1}{\tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \mathsf{fma}\left(\cos theta, \sin delta \cdot \cos \phi_1, \cos delta \cdot \sin \phi_1\right) \cdot \sin \phi_1} + \lambda_1}}} \]
    5. Taylor expanded in lambda1 around inf

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{\lambda_1}}} \]
    6. Step-by-step derivation
      1. lower-/.f6472.8

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{\lambda_1}}} \]
    7. Applied rewrites72.8%

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{\lambda_1}}} \]
    8. Add Preprocessing

    Alternative 11: 2.2% accurate, 58.3× speedup?

    \[\begin{array}{l} \\ \frac{1}{\frac{-1}{\lambda_1}} \end{array} \]
    (FPCore (lambda1 phi1 phi2 delta theta)
     :precision binary64
     (/ 1.0 (/ -1.0 lambda1)))
    double code(double lambda1, double phi1, double phi2, double delta, double theta) {
    	return 1.0 / (-1.0 / lambda1);
    }
    
    real(8) function code(lambda1, phi1, phi2, delta, theta)
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8), intent (in) :: delta
        real(8), intent (in) :: theta
        code = 1.0d0 / ((-1.0d0) / lambda1)
    end function
    
    public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
    	return 1.0 / (-1.0 / lambda1);
    }
    
    def code(lambda1, phi1, phi2, delta, theta):
    	return 1.0 / (-1.0 / lambda1)
    
    function code(lambda1, phi1, phi2, delta, theta)
    	return Float64(1.0 / Float64(-1.0 / lambda1))
    end
    
    function tmp = code(lambda1, phi1, phi2, delta, theta)
    	tmp = 1.0 / (-1.0 / lambda1);
    end
    
    code[lambda1_, phi1_, phi2_, delta_, theta_] := N[(1.0 / N[(-1.0 / lambda1), $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \frac{1}{\frac{-1}{\lambda_1}}
    \end{array}
    
    Derivation
    1. Initial program 99.8%

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

        \[\leadsto \color{blue}{\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)}} \]
      2. flip3-+N/A

        \[\leadsto \color{blue}{\frac{{\lambda_1}^{3} + {\tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)}}^{3}}{\lambda_1 \cdot \lambda_1 + \left(\tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \cdot \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} - \lambda_1 \cdot \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)}\right)}} \]
    4. Applied rewrites99.5%

      \[\leadsto \color{blue}{\frac{1}{\frac{1}{\tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \mathsf{fma}\left(\cos theta, \sin delta \cdot \cos \phi_1, \cos delta \cdot \sin \phi_1\right) \cdot \sin \phi_1} + \lambda_1}}} \]
    5. Taylor expanded in lambda1 around inf

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{\lambda_1}}} \]
    6. Step-by-step derivation
      1. lower-/.f6472.8

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{\lambda_1}}} \]
    7. Applied rewrites72.8%

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{\lambda_1}}} \]
    8. Step-by-step derivation
      1. Applied rewrites27.4%

        \[\leadsto \frac{1}{{\left(\lambda_1 \cdot \lambda_1\right)}^{\color{blue}{-0.5}}} \]
      2. Taylor expanded in lambda1 around -inf

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\lambda_1}}} \]
      3. Step-by-step derivation
        1. Applied rewrites2.2%

          \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\lambda_1}}} \]
        2. Add Preprocessing

        Reproduce

        ?
        herbie shell --seed 2024297 
        (FPCore (lambda1 phi1 phi2 delta theta)
          :name "Destination given bearing on a great circle"
          :precision binary64
          (+ lambda1 (atan2 (* (* (sin theta) (sin delta)) (cos phi1)) (- (cos delta) (* (sin phi1) (sin (asin (+ (* (sin phi1) (cos delta)) (* (* (cos phi1) (sin delta)) (cos theta))))))))))