Destination given bearing on a great circle

Percentage Accurate: 99.8% → 99.8%
Time: 30.6s
Alternatives: 15
Speedup: 1.1×

Specification

?
\[\begin{array}{l} \\ \lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \end{array} \]
(FPCore (lambda1 phi1 phi2 delta theta)
 :precision binary64
 (+
  lambda1
  (atan2
   (* (* (sin theta) (sin delta)) (cos phi1))
   (-
    (cos delta)
    (*
     (sin phi1)
     (sin
      (asin
       (+
        (* (sin phi1) (cos delta))
        (* (* (cos phi1) (sin delta)) (cos theta))))))))))
double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(lambda1, phi1, phi2, delta, theta)
use fmin_fmax_functions
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8), intent (in) :: delta
    real(8), intent (in) :: theta
    code = lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))))
end function
public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return lambda1 + Math.atan2(((Math.sin(theta) * Math.sin(delta)) * Math.cos(phi1)), (Math.cos(delta) - (Math.sin(phi1) * Math.sin(Math.asin(((Math.sin(phi1) * Math.cos(delta)) + ((Math.cos(phi1) * Math.sin(delta)) * Math.cos(theta))))))));
}
def code(lambda1, phi1, phi2, delta, theta):
	return lambda1 + math.atan2(((math.sin(theta) * math.sin(delta)) * math.cos(phi1)), (math.cos(delta) - (math.sin(phi1) * math.sin(math.asin(((math.sin(phi1) * math.cos(delta)) + ((math.cos(phi1) * math.sin(delta)) * math.cos(theta))))))))
function code(lambda1, phi1, phi2, delta, theta)
	return Float64(lambda1 + atan(Float64(Float64(sin(theta) * sin(delta)) * cos(phi1)), Float64(cos(delta) - Float64(sin(phi1) * sin(asin(Float64(Float64(sin(phi1) * cos(delta)) + Float64(Float64(cos(phi1) * sin(delta)) * cos(theta)))))))))
end
function tmp = code(lambda1, phi1, phi2, delta, theta)
	tmp = lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))));
end
code[lambda1_, phi1_, phi2_, delta_, theta_] := N[(lambda1 + N[ArcTan[N[(N[(N[Sin[theta], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[delta], $MachinePrecision] - N[(N[Sin[phi1], $MachinePrecision] * N[Sin[N[ArcSin[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Cos[delta], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] * N[Cos[theta], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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 15 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, 0.5× speedup?

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

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

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

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

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

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

Alternative 2: 99.8% accurate, 1.1× speedup?

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

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

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

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

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

Alternative 3: 99.7% accurate, 1.1× 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 \mathsf{fma}\left(\sin \phi_1, \cos delta, \left(\sin delta \cdot \cos \phi_1\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)
     (fma
      (sin phi1)
      (cos delta)
      (* (* (sin delta) (cos phi1)) (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) * fma(sin(phi1), cos(delta), ((sin(delta) * cos(phi1)) * 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) * fma(sin(phi1), cos(delta), Float64(Float64(sin(delta) * cos(phi1)) * 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[(N[Sin[phi1], $MachinePrecision] * N[Cos[delta], $MachinePrecision] + N[(N[(N[Sin[delta], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[Cos[theta], $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 \mathsf{fma}\left(\sin \phi_1, \cos delta, \left(\sin delta \cdot \cos \phi_1\right) \cdot \cos theta\right)}
\end{array}
Derivation
  1. Initial program 99.8%

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

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

Alternative 4: 96.5% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;t\_4 \leq 5:\\
\;\;\;\;\tan^{-1}_* \frac{t\_1 \cdot \sin delta}{\cos delta - \mathsf{fma}\left(\cos \phi_1, \sin delta \cdot \cos theta, t\_2\right) \cdot \sin \phi_1}\\

\mathbf{else}:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_3 \cdot 1}{\cos delta}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 lambda1 (atan2.f64 (*.f64 (*.f64 (sin.f64 theta) (sin.f64 delta)) (cos.f64 phi1)) (-.f64 (cos.f64 delta) (*.f64 (sin.f64 phi1) (sin.f64 (asin.f64 (+.f64 (*.f64 (sin.f64 phi1) (cos.f64 delta)) (*.f64 (*.f64 (cos.f64 phi1) (sin.f64 delta)) (cos.f64 theta))))))))) < 9.9999999999999995e-8

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

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

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

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

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

    if 9.9999999999999995e-8 < (+.f64 lambda1 (atan2.f64 (*.f64 (*.f64 (sin.f64 theta) (sin.f64 delta)) (cos.f64 phi1)) (-.f64 (cos.f64 delta) (*.f64 (sin.f64 phi1) (sin.f64 (asin.f64 (+.f64 (*.f64 (sin.f64 phi1) (cos.f64 delta)) (*.f64 (*.f64 (cos.f64 phi1) (sin.f64 delta)) (cos.f64 theta))))))))) < 5

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

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

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

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

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

    if 5 < (+.f64 lambda1 (atan2.f64 (*.f64 (*.f64 (sin.f64 theta) (sin.f64 delta)) (cos.f64 phi1)) (-.f64 (cos.f64 delta) (*.f64 (sin.f64 phi1) (sin.f64 (asin.f64 (+.f64 (*.f64 (sin.f64 phi1) (cos.f64 delta)) (*.f64 (*.f64 (cos.f64 phi1) (sin.f64 delta)) (cos.f64 theta)))))))))

    1. Initial program 100.0%

      \[\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. Applied rewrites100.0%

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

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

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

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

Alternative 5: 96.5% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;t\_4 \leq 5:\\
\;\;\;\;\tan^{-1}_* \frac{t\_1 \cdot \sin theta}{\cos delta - \sin \phi_1 \cdot \mathsf{fma}\left(\cos \phi_1, \sin delta \cdot \cos theta, t\_2\right)}\\

\mathbf{else}:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_3 \cdot 1}{\cos delta}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 lambda1 (atan2.f64 (*.f64 (*.f64 (sin.f64 theta) (sin.f64 delta)) (cos.f64 phi1)) (-.f64 (cos.f64 delta) (*.f64 (sin.f64 phi1) (sin.f64 (asin.f64 (+.f64 (*.f64 (sin.f64 phi1) (cos.f64 delta)) (*.f64 (*.f64 (cos.f64 phi1) (sin.f64 delta)) (cos.f64 theta))))))))) < 9.9999999999999995e-8

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

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

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

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

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

    if 9.9999999999999995e-8 < (+.f64 lambda1 (atan2.f64 (*.f64 (*.f64 (sin.f64 theta) (sin.f64 delta)) (cos.f64 phi1)) (-.f64 (cos.f64 delta) (*.f64 (sin.f64 phi1) (sin.f64 (asin.f64 (+.f64 (*.f64 (sin.f64 phi1) (cos.f64 delta)) (*.f64 (*.f64 (cos.f64 phi1) (sin.f64 delta)) (cos.f64 theta))))))))) < 5

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

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

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

    if 5 < (+.f64 lambda1 (atan2.f64 (*.f64 (*.f64 (sin.f64 theta) (sin.f64 delta)) (cos.f64 phi1)) (-.f64 (cos.f64 delta) (*.f64 (sin.f64 phi1) (sin.f64 (asin.f64 (+.f64 (*.f64 (sin.f64 phi1) (cos.f64 delta)) (*.f64 (*.f64 (cos.f64 phi1) (sin.f64 delta)) (cos.f64 theta)))))))))

    1. Initial program 100.0%

      \[\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. Applied rewrites100.0%

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

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

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

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

Alternative 6: 94.8% accurate, 1.2× speedup?

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

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

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

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

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

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

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

Alternative 7: 92.5% accurate, 2.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}^{2}} \end{array} \]
(FPCore (lambda1 phi1 phi2 delta theta)
 :precision binary64
 (+
  lambda1
  (atan2
   (* (* (sin theta) (sin delta)) (cos phi1))
   (- (cos delta) (pow (sin phi1) 2.0)))))
double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - pow(sin(phi1), 2.0)));
}
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) ** 2.0d0)))
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.pow(Math.sin(phi1), 2.0)));
}
def code(lambda1, phi1, phi2, delta, theta):
	return lambda1 + math.atan2(((math.sin(theta) * math.sin(delta)) * math.cos(phi1)), (math.cos(delta) - math.pow(math.sin(phi1), 2.0)))
function code(lambda1, phi1, phi2, delta, theta)
	return Float64(lambda1 + atan(Float64(Float64(sin(theta) * sin(delta)) * cos(phi1)), Float64(cos(delta) - (sin(phi1) ^ 2.0))))
end
function tmp = code(lambda1, phi1, phi2, delta, theta)
	tmp = lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) ^ 2.0)));
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[Power[N[Sin[phi1], $MachinePrecision], 2.0], $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}^{2}}
\end{array}
Derivation
  1. Initial program 99.8%

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

    \[\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. Add Preprocessing

Alternative 8: 92.1% accurate, 2.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1\\ t_2 := \lambda_1 + \tan^{-1}_* \frac{t\_1}{\cos delta}\\ \mathbf{if}\;delta \leq -3200:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;delta \leq 1.75 \cdot 10^{-17}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_1}{1 - {\sin \phi_1}^{2}}\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (lambda1 phi1 phi2 delta theta)
 :precision binary64
 (let* ((t_1 (* (* (sin theta) (sin delta)) (cos phi1)))
        (t_2 (+ lambda1 (atan2 t_1 (cos delta)))))
   (if (<= delta -3200.0)
     t_2
     (if (<= delta 1.75e-17)
       (+ lambda1 (atan2 t_1 (- 1.0 (pow (sin phi1) 2.0))))
       t_2))))
double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	double t_1 = (sin(theta) * sin(delta)) * cos(phi1);
	double t_2 = lambda1 + atan2(t_1, cos(delta));
	double tmp;
	if (delta <= -3200.0) {
		tmp = t_2;
	} else if (delta <= 1.75e-17) {
		tmp = lambda1 + atan2(t_1, (1.0 - pow(sin(phi1), 2.0)));
	} else {
		tmp = t_2;
	}
	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) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = (sin(theta) * sin(delta)) * cos(phi1)
    t_2 = lambda1 + atan2(t_1, cos(delta))
    if (delta <= (-3200.0d0)) then
        tmp = t_2
    else if (delta <= 1.75d-17) then
        tmp = lambda1 + atan2(t_1, (1.0d0 - (sin(phi1) ** 2.0d0)))
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	double t_1 = (Math.sin(theta) * Math.sin(delta)) * Math.cos(phi1);
	double t_2 = lambda1 + Math.atan2(t_1, Math.cos(delta));
	double tmp;
	if (delta <= -3200.0) {
		tmp = t_2;
	} else if (delta <= 1.75e-17) {
		tmp = lambda1 + Math.atan2(t_1, (1.0 - Math.pow(Math.sin(phi1), 2.0)));
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(lambda1, phi1, phi2, delta, theta):
	t_1 = (math.sin(theta) * math.sin(delta)) * math.cos(phi1)
	t_2 = lambda1 + math.atan2(t_1, math.cos(delta))
	tmp = 0
	if delta <= -3200.0:
		tmp = t_2
	elif delta <= 1.75e-17:
		tmp = lambda1 + math.atan2(t_1, (1.0 - math.pow(math.sin(phi1), 2.0)))
	else:
		tmp = t_2
	return tmp
function code(lambda1, phi1, phi2, delta, theta)
	t_1 = Float64(Float64(sin(theta) * sin(delta)) * cos(phi1))
	t_2 = Float64(lambda1 + atan(t_1, cos(delta)))
	tmp = 0.0
	if (delta <= -3200.0)
		tmp = t_2;
	elseif (delta <= 1.75e-17)
		tmp = Float64(lambda1 + atan(t_1, Float64(1.0 - (sin(phi1) ^ 2.0))));
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(lambda1, phi1, phi2, delta, theta)
	t_1 = (sin(theta) * sin(delta)) * cos(phi1);
	t_2 = lambda1 + atan2(t_1, cos(delta));
	tmp = 0.0;
	if (delta <= -3200.0)
		tmp = t_2;
	elseif (delta <= 1.75e-17)
		tmp = lambda1 + atan2(t_1, (1.0 - (sin(phi1) ^ 2.0)));
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[lambda1_, phi1_, phi2_, delta_, theta_] := Block[{t$95$1 = N[(N[(N[Sin[theta], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(lambda1 + N[ArcTan[t$95$1 / N[Cos[delta], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[delta, -3200.0], t$95$2, If[LessEqual[delta, 1.75e-17], N[(lambda1 + N[ArcTan[t$95$1 / N[(1.0 - N[Power[N[Sin[phi1], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$2]]]]
\begin{array}{l}

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

\mathbf{elif}\;delta \leq 1.75 \cdot 10^{-17}:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_1}{1 - {\sin \phi_1}^{2}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if delta < -3200 or 1.7500000000000001e-17 < delta

    1. Initial program 99.8%

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

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

    if -3200 < delta < 1.7500000000000001e-17

    1. Initial program 99.8%

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

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

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

Alternative 9: 88.9% 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.8%

    \[\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \]
  2. 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}} \]
  3. Applied rewrites88.9%

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

Alternative 10: 86.8% accurate, 3.3× speedup?

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

\\
\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot 1}{\cos delta}
\end{array}
Derivation
  1. Initial program 99.8%

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

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

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

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

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

Alternative 11: 80.9% accurate, 3.7× speedup?

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

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

\mathbf{elif}\;theta \leq 1.15 \cdot 10^{+63}:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\left(\left(\mathsf{fma}\left(theta \cdot theta, -0.16666666666666666, 1\right) \cdot theta\right) \cdot \sin delta\right) \cdot 1}{\cos delta}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if theta < -5.00000000000000022e92 or 1.14999999999999997e63 < theta

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

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

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

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

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

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

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

    if -5.00000000000000022e92 < theta < 1.14999999999999997e63

    1. Initial program 99.8%

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

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

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

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

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

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

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\left(\color{blue}{\left(\mathsf{fma}\left(theta \cdot theta, -0.16666666666666666, 1\right) \cdot theta\right)} \cdot \sin delta\right) \cdot 1}{\cos delta} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 12: 79.3% accurate, 3.8× speedup?

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

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

\mathbf{elif}\;theta \leq 1.72 \cdot 10^{-29}:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\left(\sin delta \cdot theta\right) \cdot 1}{\cos delta}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if theta < -1.65e6 or 1.71999999999999986e-29 < theta

    1. Initial program 99.7%

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

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

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

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

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

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

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

    if -1.65e6 < theta < 1.71999999999999986e-29

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

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

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

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

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

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

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

Alternative 13: 79.2% accurate, 4.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \lambda_1 + \tan^{-1}_* \frac{\left(\sin delta \cdot theta\right) \cdot 1}{\cos delta}\\ \mathbf{if}\;delta \leq -2.55 \cdot 10^{+14}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;delta \leq 3.6 \cdot 10^{+127}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot delta\right) \cdot 1}{\cos delta}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (lambda1 phi1 phi2 delta theta)
 :precision binary64
 (let* ((t_1 (+ lambda1 (atan2 (* (* (sin delta) theta) 1.0) (cos delta)))))
   (if (<= delta -2.55e+14)
     t_1
     (if (<= delta 3.6e+127)
       (+ lambda1 (atan2 (* (* (sin theta) delta) 1.0) (cos delta)))
       t_1))))
double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	double t_1 = lambda1 + atan2(((sin(delta) * theta) * 1.0), cos(delta));
	double tmp;
	if (delta <= -2.55e+14) {
		tmp = t_1;
	} else if (delta <= 3.6e+127) {
		tmp = lambda1 + atan2(((sin(theta) * delta) * 1.0), cos(delta));
	} else {
		tmp = t_1;
	}
	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) :: t_1
    real(8) :: tmp
    t_1 = lambda1 + atan2(((sin(delta) * theta) * 1.0d0), cos(delta))
    if (delta <= (-2.55d+14)) then
        tmp = t_1
    else if (delta <= 3.6d+127) then
        tmp = lambda1 + atan2(((sin(theta) * delta) * 1.0d0), cos(delta))
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	double t_1 = lambda1 + Math.atan2(((Math.sin(delta) * theta) * 1.0), Math.cos(delta));
	double tmp;
	if (delta <= -2.55e+14) {
		tmp = t_1;
	} else if (delta <= 3.6e+127) {
		tmp = lambda1 + Math.atan2(((Math.sin(theta) * delta) * 1.0), Math.cos(delta));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(lambda1, phi1, phi2, delta, theta):
	t_1 = lambda1 + math.atan2(((math.sin(delta) * theta) * 1.0), math.cos(delta))
	tmp = 0
	if delta <= -2.55e+14:
		tmp = t_1
	elif delta <= 3.6e+127:
		tmp = lambda1 + math.atan2(((math.sin(theta) * delta) * 1.0), math.cos(delta))
	else:
		tmp = t_1
	return tmp
function code(lambda1, phi1, phi2, delta, theta)
	t_1 = Float64(lambda1 + atan(Float64(Float64(sin(delta) * theta) * 1.0), cos(delta)))
	tmp = 0.0
	if (delta <= -2.55e+14)
		tmp = t_1;
	elseif (delta <= 3.6e+127)
		tmp = Float64(lambda1 + atan(Float64(Float64(sin(theta) * delta) * 1.0), cos(delta)));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(lambda1, phi1, phi2, delta, theta)
	t_1 = lambda1 + atan2(((sin(delta) * theta) * 1.0), cos(delta));
	tmp = 0.0;
	if (delta <= -2.55e+14)
		tmp = t_1;
	elseif (delta <= 3.6e+127)
		tmp = lambda1 + atan2(((sin(theta) * delta) * 1.0), cos(delta));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[lambda1_, phi1_, phi2_, delta_, theta_] := Block[{t$95$1 = N[(lambda1 + N[ArcTan[N[(N[(N[Sin[delta], $MachinePrecision] * theta), $MachinePrecision] * 1.0), $MachinePrecision] / N[Cos[delta], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[delta, -2.55e+14], t$95$1, If[LessEqual[delta, 3.6e+127], N[(lambda1 + N[ArcTan[N[(N[(N[Sin[theta], $MachinePrecision] * delta), $MachinePrecision] * 1.0), $MachinePrecision] / N[Cos[delta], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \lambda_1 + \tan^{-1}_* \frac{\left(\sin delta \cdot theta\right) \cdot 1}{\cos delta}\\
\mathbf{if}\;delta \leq -2.55 \cdot 10^{+14}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;delta \leq 3.6 \cdot 10^{+127}:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot delta\right) \cdot 1}{\cos delta}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if delta < -2.55e14 or 3.59999999999999979e127 < delta

    1. Initial program 99.8%

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

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

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

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

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

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

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

    if -2.55e14 < delta < 3.59999999999999979e127

    1. Initial program 99.8%

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

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

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

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

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

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

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

Alternative 14: 75.9% accurate, 4.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \lambda_1 + \tan^{-1}_* \frac{\left(\sin delta \cdot theta\right) \cdot 1}{\cos delta}\\ \mathbf{if}\;delta \leq -2.05 \cdot 10^{-179}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;delta \leq 10^{-33}:\\ \;\;\;\;\lambda_1\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (lambda1 phi1 phi2 delta theta)
 :precision binary64
 (let* ((t_1 (+ lambda1 (atan2 (* (* (sin delta) theta) 1.0) (cos delta)))))
   (if (<= delta -2.05e-179) t_1 (if (<= delta 1e-33) lambda1 t_1))))
double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	double t_1 = lambda1 + atan2(((sin(delta) * theta) * 1.0), cos(delta));
	double tmp;
	if (delta <= -2.05e-179) {
		tmp = t_1;
	} else if (delta <= 1e-33) {
		tmp = lambda1;
	} else {
		tmp = t_1;
	}
	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) :: t_1
    real(8) :: tmp
    t_1 = lambda1 + atan2(((sin(delta) * theta) * 1.0d0), cos(delta))
    if (delta <= (-2.05d-179)) then
        tmp = t_1
    else if (delta <= 1d-33) then
        tmp = lambda1
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	double t_1 = lambda1 + Math.atan2(((Math.sin(delta) * theta) * 1.0), Math.cos(delta));
	double tmp;
	if (delta <= -2.05e-179) {
		tmp = t_1;
	} else if (delta <= 1e-33) {
		tmp = lambda1;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(lambda1, phi1, phi2, delta, theta):
	t_1 = lambda1 + math.atan2(((math.sin(delta) * theta) * 1.0), math.cos(delta))
	tmp = 0
	if delta <= -2.05e-179:
		tmp = t_1
	elif delta <= 1e-33:
		tmp = lambda1
	else:
		tmp = t_1
	return tmp
function code(lambda1, phi1, phi2, delta, theta)
	t_1 = Float64(lambda1 + atan(Float64(Float64(sin(delta) * theta) * 1.0), cos(delta)))
	tmp = 0.0
	if (delta <= -2.05e-179)
		tmp = t_1;
	elseif (delta <= 1e-33)
		tmp = lambda1;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(lambda1, phi1, phi2, delta, theta)
	t_1 = lambda1 + atan2(((sin(delta) * theta) * 1.0), cos(delta));
	tmp = 0.0;
	if (delta <= -2.05e-179)
		tmp = t_1;
	elseif (delta <= 1e-33)
		tmp = lambda1;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[lambda1_, phi1_, phi2_, delta_, theta_] := Block[{t$95$1 = N[(lambda1 + N[ArcTan[N[(N[(N[Sin[delta], $MachinePrecision] * theta), $MachinePrecision] * 1.0), $MachinePrecision] / N[Cos[delta], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[delta, -2.05e-179], t$95$1, If[LessEqual[delta, 1e-33], lambda1, t$95$1]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \lambda_1 + \tan^{-1}_* \frac{\left(\sin delta \cdot theta\right) \cdot 1}{\cos delta}\\
\mathbf{if}\;delta \leq -2.05 \cdot 10^{-179}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;delta \leq 10^{-33}:\\
\;\;\;\;\lambda_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if delta < -2.05e-179 or 1.0000000000000001e-33 < 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. Applied rewrites99.7%

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

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

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

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

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

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

    if -2.05e-179 < delta < 1.0000000000000001e-33

    1. Initial program 99.8%

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

      \[\leadsto \color{blue}{\lambda_1} \]
    3. Applied rewrites88.1%

      \[\leadsto \color{blue}{\lambda_1} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 15: 69.8% accurate, 396.9× 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.8%

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

    \[\leadsto \color{blue}{\lambda_1} \]
  3. Applied rewrites69.8%

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

Reproduce

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