Destination given bearing on a great circle

Percentage Accurate: 99.8% → 99.7%
Time: 2.0min
Alternatives: 1

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))))))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(lambda1, phi1, phi2, delta, theta)
use fmin_fmax_functions
    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 1 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))))))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(lambda1, phi1, phi2, delta, theta)
use fmin_fmax_functions
    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.7% accurate, 0.2× speedup?

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

\\
\begin{array}{l}
t_1 := {\cos delta}^{2}\\
t_2 := \cos \phi_1 \cdot \sin delta\\
t_3 := \mathsf{fma}\left(\sin \phi_1, \cos delta, \cos theta \cdot t\_2\right) \cdot \sin \phi_1\\
t_4 := {t\_3}^{2} + \cos delta \cdot t\_3\\
\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\frac{\mathsf{fma}\left(t\_1, \cos delta, \left(-{\sin \phi_1}^{3}\right) \cdot {\left(\mathsf{fma}\left(\sin \phi_1, \cos delta, t\_2 \cdot \cos theta\right)\right)}^{3}\right)}{\frac{{t\_1}^{3} + {t\_4}^{3}}{\mathsf{fma}\left(t\_1, t\_1, t\_4 \cdot t\_4 - t\_1 \cdot t\_4\right)}}}
\end{array}
\end{array}
Derivation
  1. Initial program 99.9%

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

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

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

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

Reproduce

?
herbie shell --seed 2025059 
(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))))))))))