Destination given bearing on a great circle

Percentage Accurate: 99.8% → 99.8%
Time: 16.6s
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))))))));
}
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 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))))))));
}
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.8% accurate, 1.2× speedup?

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

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

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

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

Alternative 2: 99.8% accurate, 1.2× speedup?

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

\\
\tan^{-1}_* \frac{\left(\cos \phi_1 \cdot \sin theta\right) \cdot \sin delta}{\cos delta - \mathsf{fma}\left(\cos \phi_1 \cdot \sin delta, \cos theta, \sin \phi_1 \cdot \cos delta\right) \cdot \sin \phi_1} + \lambda_1
\end{array}
Derivation
  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. Applied rewrites99.8%

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

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

Alternative 3: 99.8% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \mathsf{fma}\left(\cos theta, \cos \phi_1 \cdot \sin delta, \sin \phi_1 \cdot \cos 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 (cos theta) (* (cos phi1) (sin delta)) (* (sin phi1) (cos 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(cos(theta), (cos(phi1) * sin(delta)), (sin(phi1) * cos(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(cos(theta), Float64(cos(phi1) * sin(delta)), Float64(sin(phi1) * cos(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[Cos[theta], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * N[Cos[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(\cos theta, \cos \phi_1 \cdot \sin delta, \sin \phi_1 \cdot \cos delta\right) \cdot \sin \phi_1} + \lambda_1
\end{array}
Derivation
  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. Applied rewrites99.7%

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

Alternative 4: 94.8% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_1 := \cos \phi_1 \cdot \sin delta\\
\lambda_1 + \tan^{-1}_* \frac{t\_1 \cdot \sin theta}{\cos delta - \mathsf{fma}\left(\sin \phi_1, \cos delta, t\_1\right) \cdot \sin \phi_1}
\end{array}
\end{array}
Derivation
  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. Step-by-step derivation
    1. lift-varN/A

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin \color{blue}{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. lift-sin.f64N/A

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\color{blue}{\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. lift-varN/A

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin \color{blue}{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)} \]
    4. lift-sin.f64N/A

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \color{blue}{\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)} \]
    5. lift-*.f64N/A

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\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)} \]
    6. lift-varN/A

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \color{blue}{\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)} \]
    7. lift-cos.f64N/A

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \color{blue}{\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)} \]
    8. lift-*.f64N/A

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\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)} \]
    9. lower-*.f64N/A

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\left(\cos \phi_1 \cdot \sin delta\right) \cdot \sin theta}}{\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)} \]
  4. Applied rewrites99.8%

    \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\left(\cos \phi_1 \cdot \sin delta\right) \cdot \sin theta}}{\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)} \]
  5. Applied rewrites99.7%

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

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

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

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

    Alternative 5: 92.3% accurate, 1.9× speedup?

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

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

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

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

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

        Alternative 6: 92.3% accurate, 1.9× 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 \phi_1} \end{array} \]
        (FPCore (lambda1 phi1 phi2 delta theta)
         :precision binary64
         (+
          lambda1
          (atan2
           (* (* (sin theta) (sin delta)) (cos phi1))
           (- (cos delta) (* (sin phi1) (sin phi1))))))
        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(phi1))));
        }
        
        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(phi1))))
        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(phi1))));
        }
        
        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(phi1))))
        
        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(phi1)))))
        end
        
        function tmp = code(lambda1, phi1, phi2, delta, theta)
        	tmp = lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(phi1))));
        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[phi1], $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 \phi_1}
        \end{array}
        
        Derivation
        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 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. Applied rewrites94.7%

            \[\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 \sin \phi_1}} \]
          2. Add Preprocessing

          Alternative 7: 91.6% accurate, 2.1× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;delta \leq -3.7:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta}\\ \mathbf{elif}\;delta \leq 0.00029:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\left(\cos \phi_1 \cdot \sin delta\right) \cdot \sin theta}{\cos \phi_1 \cdot \cos \phi_1}\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \phi_1 \cdot \phi_1} + \lambda_1\\ \end{array} \end{array} \]
          (FPCore (lambda1 phi1 phi2 delta theta)
           :precision binary64
           (if (<= delta -3.7)
             (+ lambda1 (atan2 (* (* (sin theta) (sin delta)) (cos phi1)) (cos delta)))
             (if (<= delta 0.00029)
               (+
                lambda1
                (atan2
                 (* (* (cos phi1) (sin delta)) (sin theta))
                 (* (cos phi1) (cos phi1))))
               (+
                (atan2
                 (* (cos phi1) (* (sin delta) (sin theta)))
                 (- (cos delta) (* phi1 phi1)))
                lambda1))))
          double code(double lambda1, double phi1, double phi2, double delta, double theta) {
          	double tmp;
          	if (delta <= -3.7) {
          		tmp = lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), cos(delta));
          	} else if (delta <= 0.00029) {
          		tmp = lambda1 + atan2(((cos(phi1) * sin(delta)) * sin(theta)), (cos(phi1) * cos(phi1)));
          	} else {
          		tmp = atan2((cos(phi1) * (sin(delta) * sin(theta))), (cos(delta) - (phi1 * phi1))) + lambda1;
          	}
          	return tmp;
          }
          
          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
              real(8) :: tmp
              if (delta <= (-3.7d0)) then
                  tmp = lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), cos(delta))
              else if (delta <= 0.00029d0) then
                  tmp = lambda1 + atan2(((cos(phi1) * sin(delta)) * sin(theta)), (cos(phi1) * cos(phi1)))
              else
                  tmp = atan2((cos(phi1) * (sin(delta) * sin(theta))), (cos(delta) - (phi1 * phi1))) + lambda1
              end if
              code = tmp
          end function
          
          public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
          	double tmp;
          	if (delta <= -3.7) {
          		tmp = lambda1 + Math.atan2(((Math.sin(theta) * Math.sin(delta)) * Math.cos(phi1)), Math.cos(delta));
          	} else if (delta <= 0.00029) {
          		tmp = lambda1 + Math.atan2(((Math.cos(phi1) * Math.sin(delta)) * Math.sin(theta)), (Math.cos(phi1) * Math.cos(phi1)));
          	} else {
          		tmp = Math.atan2((Math.cos(phi1) * (Math.sin(delta) * Math.sin(theta))), (Math.cos(delta) - (phi1 * phi1))) + lambda1;
          	}
          	return tmp;
          }
          
          def code(lambda1, phi1, phi2, delta, theta):
          	tmp = 0
          	if delta <= -3.7:
          		tmp = lambda1 + math.atan2(((math.sin(theta) * math.sin(delta)) * math.cos(phi1)), math.cos(delta))
          	elif delta <= 0.00029:
          		tmp = lambda1 + math.atan2(((math.cos(phi1) * math.sin(delta)) * math.sin(theta)), (math.cos(phi1) * math.cos(phi1)))
          	else:
          		tmp = math.atan2((math.cos(phi1) * (math.sin(delta) * math.sin(theta))), (math.cos(delta) - (phi1 * phi1))) + lambda1
          	return tmp
          
          function code(lambda1, phi1, phi2, delta, theta)
          	tmp = 0.0
          	if (delta <= -3.7)
          		tmp = Float64(lambda1 + atan(Float64(Float64(sin(theta) * sin(delta)) * cos(phi1)), cos(delta)));
          	elseif (delta <= 0.00029)
          		tmp = Float64(lambda1 + atan(Float64(Float64(cos(phi1) * sin(delta)) * sin(theta)), Float64(cos(phi1) * cos(phi1))));
          	else
          		tmp = Float64(atan(Float64(cos(phi1) * Float64(sin(delta) * sin(theta))), Float64(cos(delta) - Float64(phi1 * phi1))) + lambda1);
          	end
          	return tmp
          end
          
          function tmp_2 = code(lambda1, phi1, phi2, delta, theta)
          	tmp = 0.0;
          	if (delta <= -3.7)
          		tmp = lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), cos(delta));
          	elseif (delta <= 0.00029)
          		tmp = lambda1 + atan2(((cos(phi1) * sin(delta)) * sin(theta)), (cos(phi1) * cos(phi1)));
          	else
          		tmp = atan2((cos(phi1) * (sin(delta) * sin(theta))), (cos(delta) - (phi1 * phi1))) + lambda1;
          	end
          	tmp_2 = tmp;
          end
          
          code[lambda1_, phi1_, phi2_, delta_, theta_] := If[LessEqual[delta, -3.7], N[(lambda1 + N[ArcTan[N[(N[(N[Sin[theta], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] / N[Cos[delta], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[delta, 0.00029], N[(lambda1 + N[ArcTan[N[(N[(N[Cos[phi1], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] * N[Sin[theta], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 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[(phi1 * phi1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + lambda1), $MachinePrecision]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;delta \leq -3.7:\\
          \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta}\\
          
          \mathbf{elif}\;delta \leq 0.00029:\\
          \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\left(\cos \phi_1 \cdot \sin delta\right) \cdot \sin theta}{\cos \phi_1 \cdot \cos \phi_1}\\
          
          \mathbf{else}:\\
          \;\;\;\;\tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \phi_1 \cdot \phi_1} + \lambda_1\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 3 regimes
          2. if delta < -3.7000000000000002

            1. Initial program 99.6%

              \[\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. Applied rewrites85.3%

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

              if -3.7000000000000002 < delta < 2.9e-4

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

                  \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin \color{blue}{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. lift-sin.f64N/A

                  \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\color{blue}{\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. lift-varN/A

                  \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin \color{blue}{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)} \]
                4. lift-sin.f64N/A

                  \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \color{blue}{\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)} \]
                5. lift-*.f64N/A

                  \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\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)} \]
                6. lift-varN/A

                  \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \color{blue}{\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)} \]
                7. lift-cos.f64N/A

                  \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \color{blue}{\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)} \]
                8. lift-*.f64N/A

                  \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\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)} \]
                9. lower-*.f64N/A

                  \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\left(\cos \phi_1 \cdot \sin delta\right) \cdot \sin theta}}{\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)} \]
              4. Applied rewrites99.8%

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\left(\cos \phi_1 \cdot \sin delta\right) \cdot \sin theta}}{\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)} \]
              5. Applied rewrites99.8%

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

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

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

                if 2.9e-4 < delta

                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 \color{blue}{\tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \mathsf{fma}\left(\cos theta, \cos \phi_1 \cdot \sin delta, \sin \phi_1 \cdot \cos delta\right) \cdot \sin \phi_1} + \lambda_1} \]
                4. Taylor expanded in delta around 0

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

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

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

                      \[\leadsto \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \phi_1 \cdot \color{blue}{\phi_1}} + \lambda_1 \]
                  4. Recombined 3 regimes into one program.
                  5. Final simplification94.5%

                    \[\leadsto \begin{array}{l} \mathbf{if}\;delta \leq -3.7:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta}\\ \mathbf{elif}\;delta \leq 0.00029:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\left(\cos \phi_1 \cdot \sin delta\right) \cdot \sin theta}{\cos \phi_1 \cdot \cos \phi_1}\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \phi_1 \cdot \phi_1} + \lambda_1\\ \end{array} \]
                  6. Add Preprocessing

                  Alternative 8: 89.0% accurate, 2.6× speedup?

                  \[\begin{array}{l} \\ \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta} \end{array} \]
                  (FPCore (lambda1 phi1 phi2 delta theta)
                   :precision binary64
                   (+ lambda1 (atan2 (* (* (sin theta) (sin delta)) (cos phi1)) (cos delta))))
                  double code(double lambda1, double phi1, double phi2, double delta, double theta) {
                  	return lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), cos(delta));
                  }
                  
                  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))
                  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));
                  }
                  
                  def code(lambda1, phi1, phi2, delta, theta):
                  	return lambda1 + math.atan2(((math.sin(theta) * math.sin(delta)) * math.cos(phi1)), math.cos(delta))
                  
                  function code(lambda1, phi1, phi2, delta, theta)
                  	return Float64(lambda1 + atan(Float64(Float64(sin(theta) * sin(delta)) * cos(phi1)), cos(delta)))
                  end
                  
                  function tmp = code(lambda1, phi1, phi2, delta, theta)
                  	tmp = lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), cos(delta));
                  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[Cos[delta], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
                  
                  \begin{array}{l}
                  
                  \\
                  \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta}
                  \end{array}
                  
                  Derivation
                  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. Applied rewrites90.1%

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

                    Alternative 9: 82.2% accurate, 3.1× speedup?

                    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;delta \leq -118000 \lor \neg \left(delta \leq 3.3 \cdot 10^{-29}\right):\\ \;\;\;\;\tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot theta\right)}{\cos delta} + \lambda_1\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin theta \cdot delta\right)}{\cos delta} + \lambda_1\\ \end{array} \end{array} \]
                    (FPCore (lambda1 phi1 phi2 delta theta)
                     :precision binary64
                     (if (or (<= delta -118000.0) (not (<= delta 3.3e-29)))
                       (+ (atan2 (* (cos phi1) (* (sin delta) theta)) (cos delta)) lambda1)
                       (+ (atan2 (* (cos phi1) (* (sin theta) delta)) (cos delta)) lambda1)))
                    double code(double lambda1, double phi1, double phi2, double delta, double theta) {
                    	double tmp;
                    	if ((delta <= -118000.0) || !(delta <= 3.3e-29)) {
                    		tmp = atan2((cos(phi1) * (sin(delta) * theta)), cos(delta)) + lambda1;
                    	} else {
                    		tmp = atan2((cos(phi1) * (sin(theta) * delta)), cos(delta)) + lambda1;
                    	}
                    	return tmp;
                    }
                    
                    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
                        real(8) :: tmp
                        if ((delta <= (-118000.0d0)) .or. (.not. (delta <= 3.3d-29))) then
                            tmp = atan2((cos(phi1) * (sin(delta) * theta)), cos(delta)) + lambda1
                        else
                            tmp = atan2((cos(phi1) * (sin(theta) * delta)), cos(delta)) + lambda1
                        end if
                        code = tmp
                    end function
                    
                    public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
                    	double tmp;
                    	if ((delta <= -118000.0) || !(delta <= 3.3e-29)) {
                    		tmp = Math.atan2((Math.cos(phi1) * (Math.sin(delta) * theta)), Math.cos(delta)) + lambda1;
                    	} else {
                    		tmp = Math.atan2((Math.cos(phi1) * (Math.sin(theta) * delta)), Math.cos(delta)) + lambda1;
                    	}
                    	return tmp;
                    }
                    
                    def code(lambda1, phi1, phi2, delta, theta):
                    	tmp = 0
                    	if (delta <= -118000.0) or not (delta <= 3.3e-29):
                    		tmp = math.atan2((math.cos(phi1) * (math.sin(delta) * theta)), math.cos(delta)) + lambda1
                    	else:
                    		tmp = math.atan2((math.cos(phi1) * (math.sin(theta) * delta)), math.cos(delta)) + lambda1
                    	return tmp
                    
                    function code(lambda1, phi1, phi2, delta, theta)
                    	tmp = 0.0
                    	if ((delta <= -118000.0) || !(delta <= 3.3e-29))
                    		tmp = Float64(atan(Float64(cos(phi1) * Float64(sin(delta) * theta)), cos(delta)) + lambda1);
                    	else
                    		tmp = Float64(atan(Float64(cos(phi1) * Float64(sin(theta) * delta)), cos(delta)) + lambda1);
                    	end
                    	return tmp
                    end
                    
                    function tmp_2 = code(lambda1, phi1, phi2, delta, theta)
                    	tmp = 0.0;
                    	if ((delta <= -118000.0) || ~((delta <= 3.3e-29)))
                    		tmp = atan2((cos(phi1) * (sin(delta) * theta)), cos(delta)) + lambda1;
                    	else
                    		tmp = atan2((cos(phi1) * (sin(theta) * delta)), cos(delta)) + lambda1;
                    	end
                    	tmp_2 = tmp;
                    end
                    
                    code[lambda1_, phi1_, phi2_, delta_, theta_] := If[Or[LessEqual[delta, -118000.0], N[Not[LessEqual[delta, 3.3e-29]], $MachinePrecision]], N[(N[ArcTan[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Sin[delta], $MachinePrecision] * theta), $MachinePrecision]), $MachinePrecision] / N[Cos[delta], $MachinePrecision]], $MachinePrecision] + lambda1), $MachinePrecision], N[(N[ArcTan[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Sin[theta], $MachinePrecision] * delta), $MachinePrecision]), $MachinePrecision] / N[Cos[delta], $MachinePrecision]], $MachinePrecision] + lambda1), $MachinePrecision]]
                    
                    \begin{array}{l}
                    
                    \\
                    \begin{array}{l}
                    \mathbf{if}\;delta \leq -118000 \lor \neg \left(delta \leq 3.3 \cdot 10^{-29}\right):\\
                    \;\;\;\;\tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot theta\right)}{\cos delta} + \lambda_1\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;\tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin theta \cdot delta\right)}{\cos delta} + \lambda_1\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 2 regimes
                    2. if delta < -118000 or 3.30000000000000028e-29 < delta

                      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. Applied rewrites99.7%

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

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

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

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

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

                          if -118000 < delta < 3.30000000000000028e-29

                          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. Applied rewrites99.7%

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

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

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

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

                                \[\leadsto \tan^{-1}_* \frac{\cos \phi_1 \cdot \color{blue}{\left(\sin theta \cdot delta\right)}}{\cos delta} + \lambda_1 \]
                            4. Recombined 2 regimes into one program.
                            5. Final simplification82.2%

                              \[\leadsto \begin{array}{l} \mathbf{if}\;delta \leq -118000 \lor \neg \left(delta \leq 3.3 \cdot 10^{-29}\right):\\ \;\;\;\;\tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot theta\right)}{\cos delta} + \lambda_1\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin theta \cdot delta\right)}{\cos delta} + \lambda_1\\ \end{array} \]
                            6. Add Preprocessing

                            Alternative 10: 74.7% accurate, 3.2× speedup?

                            \[\begin{array}{l} \\ \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot theta\right)}{\cos delta} + \lambda_1 \end{array} \]
                            (FPCore (lambda1 phi1 phi2 delta theta)
                             :precision binary64
                             (+ (atan2 (* (cos phi1) (* (sin delta) theta)) (cos delta)) lambda1))
                            double code(double lambda1, double phi1, double phi2, double delta, double theta) {
                            	return atan2((cos(phi1) * (sin(delta) * theta)), cos(delta)) + lambda1;
                            }
                            
                            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 = atan2((cos(phi1) * (sin(delta) * 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) * theta)), Math.cos(delta)) + lambda1;
                            }
                            
                            def code(lambda1, phi1, phi2, delta, theta):
                            	return math.atan2((math.cos(phi1) * (math.sin(delta) * theta)), math.cos(delta)) + lambda1
                            
                            function code(lambda1, phi1, phi2, delta, theta)
                            	return Float64(atan(Float64(cos(phi1) * Float64(sin(delta) * theta)), cos(delta)) + lambda1)
                            end
                            
                            function tmp = code(lambda1, phi1, phi2, delta, theta)
                            	tmp = atan2((cos(phi1) * (sin(delta) * theta)), cos(delta)) + lambda1;
                            end
                            
                            code[lambda1_, phi1_, phi2_, delta_, theta_] := N[(N[ArcTan[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Sin[delta], $MachinePrecision] * theta), $MachinePrecision]), $MachinePrecision] / N[Cos[delta], $MachinePrecision]], $MachinePrecision] + lambda1), $MachinePrecision]
                            
                            \begin{array}{l}
                            
                            \\
                            \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot theta\right)}{\cos delta} + \lambda_1
                            \end{array}
                            
                            Derivation
                            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. Applied rewrites99.7%

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

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

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

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

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

                                Alternative 11: 70.4% accurate, 1341.0× speedup?

                                \[\begin{array}{l} \\ \lambda_1 \end{array} \]
                                (FPCore (lambda1 phi1 phi2 delta theta) :precision binary64 lambda1)
                                double code(double lambda1, double phi1, double phi2, double delta, double theta) {
                                	return lambda1;
                                }
                                
                                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
                                end function
                                
                                public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
                                	return lambda1;
                                }
                                
                                def code(lambda1, phi1, phi2, delta, theta):
                                	return lambda1
                                
                                function code(lambda1, phi1, phi2, delta, theta)
                                	return lambda1
                                end
                                
                                function tmp = code(lambda1, phi1, phi2, delta, theta)
                                	tmp = lambda1;
                                end
                                
                                code[lambda1_, phi1_, phi2_, delta_, theta_] := lambda1
                                
                                \begin{array}{l}
                                
                                \\
                                \lambda_1
                                \end{array}
                                
                                Derivation
                                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 lambda1 around inf

                                  \[\leadsto \color{blue}{\lambda_1} \]
                                4. Step-by-step derivation
                                  1. Applied rewrites67.5%

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

                                  Reproduce

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