Bearing on a great circle

Percentage Accurate: 79.1% → 99.7%
Time: 17.6s
Alternatives: 32
Speedup: 0.9×

Specification

?
\[\begin{array}{l} \\ \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \end{array} \]
(FPCore (lambda1 lambda2 phi1 phi2)
 :precision binary64
 (atan2
  (* (sin (- lambda1 lambda2)) (cos phi2))
  (-
   (* (cos phi1) (sin phi2))
   (* (* (sin phi1) (cos phi2)) (cos (- lambda1 lambda2))))))
double code(double lambda1, double lambda2, double phi1, double phi2) {
	return atan2((sin((lambda1 - lambda2)) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))));
}
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, lambda2, phi1, phi2)
use fmin_fmax_functions
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = atan2((sin((lambda1 - lambda2)) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))))
end function
public static double code(double lambda1, double lambda2, double phi1, double phi2) {
	return Math.atan2((Math.sin((lambda1 - lambda2)) * Math.cos(phi2)), ((Math.cos(phi1) * Math.sin(phi2)) - ((Math.sin(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2)))));
}
def code(lambda1, lambda2, phi1, phi2):
	return math.atan2((math.sin((lambda1 - lambda2)) * math.cos(phi2)), ((math.cos(phi1) * math.sin(phi2)) - ((math.sin(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2)))))
function code(lambda1, lambda2, phi1, phi2)
	return atan(Float64(sin(Float64(lambda1 - lambda2)) * cos(phi2)), Float64(Float64(cos(phi1) * sin(phi2)) - Float64(Float64(sin(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2)))))
end
function tmp = code(lambda1, lambda2, phi1, phi2)
	tmp = atan2((sin((lambda1 - lambda2)) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))));
end
code[lambda1_, lambda2_, phi1_, phi2_] := N[ArcTan[N[(N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Sin[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\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 32 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: 79.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \end{array} \]
(FPCore (lambda1 lambda2 phi1 phi2)
 :precision binary64
 (atan2
  (* (sin (- lambda1 lambda2)) (cos phi2))
  (-
   (* (cos phi1) (sin phi2))
   (* (* (sin phi1) (cos phi2)) (cos (- lambda1 lambda2))))))
double code(double lambda1, double lambda2, double phi1, double phi2) {
	return atan2((sin((lambda1 - lambda2)) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))));
}
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, lambda2, phi1, phi2)
use fmin_fmax_functions
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = atan2((sin((lambda1 - lambda2)) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))))
end function
public static double code(double lambda1, double lambda2, double phi1, double phi2) {
	return Math.atan2((Math.sin((lambda1 - lambda2)) * Math.cos(phi2)), ((Math.cos(phi1) * Math.sin(phi2)) - ((Math.sin(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2)))));
}
def code(lambda1, lambda2, phi1, phi2):
	return math.atan2((math.sin((lambda1 - lambda2)) * math.cos(phi2)), ((math.cos(phi1) * math.sin(phi2)) - ((math.sin(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2)))))
function code(lambda1, lambda2, phi1, phi2)
	return atan(Float64(sin(Float64(lambda1 - lambda2)) * cos(phi2)), Float64(Float64(cos(phi1) * sin(phi2)) - Float64(Float64(sin(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2)))))
end
function tmp = code(lambda1, lambda2, phi1, phi2)
	tmp = atan2((sin((lambda1 - lambda2)) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))));
end
code[lambda1_, lambda2_, phi1_, phi2_] := N[ArcTan[N[(N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Sin[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 99.7% accurate, 0.6× speedup?

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

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

    \[\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
  2. Step-by-step derivation
    1. lift--.f64N/A

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

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

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    4. cos-negN/A

      \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    5. mul-1-negN/A

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

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \left(-1 \cdot \lambda_2\right) - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    7. mul-1-negN/A

      \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    8. lower-*.f64N/A

      \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    9. lower-sin.f64N/A

      \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    10. cos-negN/A

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

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

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

      \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\cos \lambda_1} \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    14. lower-sin.f6489.3

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 94.5% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \phi_1 \cdot \sin \phi_2\\ t_1 := \sin \phi_1 \cdot \cos \phi_2\\ t_2 := \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{t\_0 - t\_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\ \mathbf{if}\;\phi_2 \leq -4 \cdot 10^{-7}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;\phi_2 \leq 2 \cdot 10^{-14}:\\ \;\;\;\;\tan^{-1}_* \frac{\mathsf{fma}\left(\cos \lambda_2, \sin \lambda_1, \left(-\cos \lambda_1\right) \cdot \sin \lambda_2\right)}{t\_0 - t\_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (cos phi1) (sin phi2)))
        (t_1 (* (sin phi1) (cos phi2)))
        (t_2
         (atan2
          (*
           (- (* (sin lambda1) (cos lambda2)) (* (cos lambda1) (sin lambda2)))
           (cos phi2))
          (- t_0 (* t_1 (cos (- lambda1 lambda2)))))))
   (if (<= phi2 -4e-7)
     t_2
     (if (<= phi2 2e-14)
       (atan2
        (fma (cos lambda2) (sin lambda1) (* (- (cos lambda1)) (sin lambda2)))
        (-
         t_0
         (*
          t_1
          (fma (cos lambda1) (cos lambda2) (* (sin lambda1) (sin lambda2))))))
       t_2))))
double code(double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos(phi1) * sin(phi2);
	double t_1 = sin(phi1) * cos(phi2);
	double t_2 = atan2((((sin(lambda1) * cos(lambda2)) - (cos(lambda1) * sin(lambda2))) * cos(phi2)), (t_0 - (t_1 * cos((lambda1 - lambda2)))));
	double tmp;
	if (phi2 <= -4e-7) {
		tmp = t_2;
	} else if (phi2 <= 2e-14) {
		tmp = atan2(fma(cos(lambda2), sin(lambda1), (-cos(lambda1) * sin(lambda2))), (t_0 - (t_1 * fma(cos(lambda1), cos(lambda2), (sin(lambda1) * sin(lambda2))))));
	} else {
		tmp = t_2;
	}
	return tmp;
}
function code(lambda1, lambda2, phi1, phi2)
	t_0 = Float64(cos(phi1) * sin(phi2))
	t_1 = Float64(sin(phi1) * cos(phi2))
	t_2 = atan(Float64(Float64(Float64(sin(lambda1) * cos(lambda2)) - Float64(cos(lambda1) * sin(lambda2))) * cos(phi2)), Float64(t_0 - Float64(t_1 * cos(Float64(lambda1 - lambda2)))))
	tmp = 0.0
	if (phi2 <= -4e-7)
		tmp = t_2;
	elseif (phi2 <= 2e-14)
		tmp = atan(fma(cos(lambda2), sin(lambda1), Float64(Float64(-cos(lambda1)) * sin(lambda2))), Float64(t_0 - Float64(t_1 * fma(cos(lambda1), cos(lambda2), Float64(sin(lambda1) * sin(lambda2))))));
	else
		tmp = t_2;
	end
	return tmp
end
code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[ArcTan[N[(N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(t$95$0 - N[(t$95$1 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -4e-7], t$95$2, If[LessEqual[phi2, 2e-14], N[ArcTan[N[(N[Cos[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision] + N[((-N[Cos[lambda1], $MachinePrecision]) * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 - N[(t$95$1 * N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$2]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \phi_1 \cdot \sin \phi_2\\
t_1 := \sin \phi_1 \cdot \cos \phi_2\\
t_2 := \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{t\_0 - t\_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\
\mathbf{if}\;\phi_2 \leq -4 \cdot 10^{-7}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;\phi_2 \leq 2 \cdot 10^{-14}:\\
\;\;\;\;\tan^{-1}_* \frac{\mathsf{fma}\left(\cos \lambda_2, \sin \lambda_1, \left(-\cos \lambda_1\right) \cdot \sin \lambda_2\right)}{t\_0 - t\_1 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < -3.9999999999999998e-7 or 2e-14 < phi2

    1. Initial program 76.7%

      \[\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    2. Step-by-step derivation
      1. lift--.f64N/A

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

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

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      4. cos-negN/A

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      5. mul-1-negN/A

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

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \left(-1 \cdot \lambda_2\right) - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      7. mul-1-negN/A

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      8. lower-*.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      9. lower-sin.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      10. cos-negN/A

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

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

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

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\cos \lambda_1} \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      14. lower-sin.f6489.6

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

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

    if -3.9999999999999998e-7 < phi2 < 2e-14

    1. Initial program 81.6%

      \[\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    2. Step-by-step derivation
      1. lift--.f64N/A

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

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

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      4. cos-negN/A

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      5. mul-1-negN/A

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

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \left(-1 \cdot \lambda_2\right) - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      7. mul-1-negN/A

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      8. lower-*.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      9. lower-sin.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      10. cos-negN/A

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

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

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

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\cos \lambda_1} \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      14. lower-sin.f6489.1

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

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

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

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

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

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

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

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

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

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \color{blue}{\sin \lambda_1} \cdot \sin \lambda_2\right)} \]
      9. lift-sin.f6499.9

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

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

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\cos \lambda_2 \cdot \sin \lambda_1 - \cos \lambda_1 \cdot \sin \lambda_2}}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)} \]
    7. Step-by-step derivation
      1. sin-diff-revN/A

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\cos \lambda_2} \cdot \sin \lambda_1 - \cos \lambda_1 \cdot \sin \lambda_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)} \]
      2. fp-cancel-sub-sign-invN/A

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

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

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

        \[\leadsto \tan^{-1}_* \frac{\mathsf{fma}\left(\cos \lambda_2, \sin \lambda_1, \left(\mathsf{neg}\left(\cos \lambda_1\right)\right) \cdot \sin \lambda_2\right)}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)} \]
      6. lower-*.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\mathsf{fma}\left(\cos \lambda_2, \sin \lambda_1, \left(\mathsf{neg}\left(\cos \lambda_1\right)\right) \cdot \sin \lambda_2\right)}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)} \]
      7. lower-neg.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\mathsf{fma}\left(\cos \lambda_2, \sin \lambda_1, \left(-\cos \lambda_1\right) \cdot \sin \lambda_2\right)}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)} \]
      8. lift-cos.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\mathsf{fma}\left(\cos \lambda_2, \sin \lambda_1, \left(-\cos \lambda_1\right) \cdot \sin \lambda_2\right)}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)} \]
      9. lift-sin.f6499.9

        \[\leadsto \tan^{-1}_* \frac{\mathsf{fma}\left(\cos \lambda_2, \sin \lambda_1, \left(-\cos \lambda_1\right) \cdot \sin \lambda_2\right)}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)} \]
    8. Applied rewrites99.9%

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

Alternative 3: 89.3% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \phi_1 \cdot \sin \phi_2\\ t_1 := \left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2\\ t_2 := \sin \phi_1 \cdot \cos \phi_2\\ t_3 := \tan^{-1}_* \frac{t\_1}{t\_0 - t\_2 \cdot \cos \lambda_1}\\ \mathbf{if}\;\lambda_1 \leq -8500000000000:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;\lambda_1 \leq 1.75 \cdot 10^{-9}:\\ \;\;\;\;\tan^{-1}_* \frac{t\_1}{t\_0 - t\_2 \cdot \cos \lambda_2}\\ \mathbf{else}:\\ \;\;\;\;t\_3\\ \end{array} \end{array} \]
(FPCore (lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (cos phi1) (sin phi2)))
        (t_1
         (*
          (- (* (sin lambda1) (cos lambda2)) (* (cos lambda1) (sin lambda2)))
          (cos phi2)))
        (t_2 (* (sin phi1) (cos phi2)))
        (t_3 (atan2 t_1 (- t_0 (* t_2 (cos lambda1))))))
   (if (<= lambda1 -8500000000000.0)
     t_3
     (if (<= lambda1 1.75e-9) (atan2 t_1 (- t_0 (* t_2 (cos lambda2)))) t_3))))
double code(double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos(phi1) * sin(phi2);
	double t_1 = ((sin(lambda1) * cos(lambda2)) - (cos(lambda1) * sin(lambda2))) * cos(phi2);
	double t_2 = sin(phi1) * cos(phi2);
	double t_3 = atan2(t_1, (t_0 - (t_2 * cos(lambda1))));
	double tmp;
	if (lambda1 <= -8500000000000.0) {
		tmp = t_3;
	} else if (lambda1 <= 1.75e-9) {
		tmp = atan2(t_1, (t_0 - (t_2 * cos(lambda2))));
	} else {
		tmp = t_3;
	}
	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, lambda2, phi1, phi2)
use fmin_fmax_functions
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: tmp
    t_0 = cos(phi1) * sin(phi2)
    t_1 = ((sin(lambda1) * cos(lambda2)) - (cos(lambda1) * sin(lambda2))) * cos(phi2)
    t_2 = sin(phi1) * cos(phi2)
    t_3 = atan2(t_1, (t_0 - (t_2 * cos(lambda1))))
    if (lambda1 <= (-8500000000000.0d0)) then
        tmp = t_3
    else if (lambda1 <= 1.75d-9) then
        tmp = atan2(t_1, (t_0 - (t_2 * cos(lambda2))))
    else
        tmp = t_3
    end if
    code = tmp
end function
public static double code(double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.cos(phi1) * Math.sin(phi2);
	double t_1 = ((Math.sin(lambda1) * Math.cos(lambda2)) - (Math.cos(lambda1) * Math.sin(lambda2))) * Math.cos(phi2);
	double t_2 = Math.sin(phi1) * Math.cos(phi2);
	double t_3 = Math.atan2(t_1, (t_0 - (t_2 * Math.cos(lambda1))));
	double tmp;
	if (lambda1 <= -8500000000000.0) {
		tmp = t_3;
	} else if (lambda1 <= 1.75e-9) {
		tmp = Math.atan2(t_1, (t_0 - (t_2 * Math.cos(lambda2))));
	} else {
		tmp = t_3;
	}
	return tmp;
}
def code(lambda1, lambda2, phi1, phi2):
	t_0 = math.cos(phi1) * math.sin(phi2)
	t_1 = ((math.sin(lambda1) * math.cos(lambda2)) - (math.cos(lambda1) * math.sin(lambda2))) * math.cos(phi2)
	t_2 = math.sin(phi1) * math.cos(phi2)
	t_3 = math.atan2(t_1, (t_0 - (t_2 * math.cos(lambda1))))
	tmp = 0
	if lambda1 <= -8500000000000.0:
		tmp = t_3
	elif lambda1 <= 1.75e-9:
		tmp = math.atan2(t_1, (t_0 - (t_2 * math.cos(lambda2))))
	else:
		tmp = t_3
	return tmp
function code(lambda1, lambda2, phi1, phi2)
	t_0 = Float64(cos(phi1) * sin(phi2))
	t_1 = Float64(Float64(Float64(sin(lambda1) * cos(lambda2)) - Float64(cos(lambda1) * sin(lambda2))) * cos(phi2))
	t_2 = Float64(sin(phi1) * cos(phi2))
	t_3 = atan(t_1, Float64(t_0 - Float64(t_2 * cos(lambda1))))
	tmp = 0.0
	if (lambda1 <= -8500000000000.0)
		tmp = t_3;
	elseif (lambda1 <= 1.75e-9)
		tmp = atan(t_1, Float64(t_0 - Float64(t_2 * cos(lambda2))));
	else
		tmp = t_3;
	end
	return tmp
end
function tmp_2 = code(lambda1, lambda2, phi1, phi2)
	t_0 = cos(phi1) * sin(phi2);
	t_1 = ((sin(lambda1) * cos(lambda2)) - (cos(lambda1) * sin(lambda2))) * cos(phi2);
	t_2 = sin(phi1) * cos(phi2);
	t_3 = atan2(t_1, (t_0 - (t_2 * cos(lambda1))));
	tmp = 0.0;
	if (lambda1 <= -8500000000000.0)
		tmp = t_3;
	elseif (lambda1 <= 1.75e-9)
		tmp = atan2(t_1, (t_0 - (t_2 * cos(lambda2))));
	else
		tmp = t_3;
	end
	tmp_2 = tmp;
end
code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[ArcTan[t$95$1 / N[(t$95$0 - N[(t$95$2 * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[lambda1, -8500000000000.0], t$95$3, If[LessEqual[lambda1, 1.75e-9], N[ArcTan[t$95$1 / N[(t$95$0 - N[(t$95$2 * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$3]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \phi_1 \cdot \sin \phi_2\\
t_1 := \left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2\\
t_2 := \sin \phi_1 \cdot \cos \phi_2\\
t_3 := \tan^{-1}_* \frac{t\_1}{t\_0 - t\_2 \cdot \cos \lambda_1}\\
\mathbf{if}\;\lambda_1 \leq -8500000000000:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;\lambda_1 \leq 1.75 \cdot 10^{-9}:\\
\;\;\;\;\tan^{-1}_* \frac{t\_1}{t\_0 - t\_2 \cdot \cos \lambda_2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda1 < -8.5e12 or 1.75e-9 < lambda1

    1. Initial program 59.4%

      \[\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    2. Step-by-step derivation
      1. lift--.f64N/A

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

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

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      4. cos-negN/A

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      5. mul-1-negN/A

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

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \left(-1 \cdot \lambda_2\right) - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      7. mul-1-negN/A

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      8. lower-*.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      9. lower-sin.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      10. cos-negN/A

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

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

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

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\cos \lambda_1} \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      14. lower-sin.f6479.3

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    3. Applied rewrites79.3%

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    4. Taylor expanded in lambda1 around inf

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

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

      if -8.5e12 < lambda1 < 1.75e-9

      1. Initial program 98.4%

        \[\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      2. Step-by-step derivation
        1. lift--.f64N/A

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

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

          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        4. cos-negN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        5. mul-1-negN/A

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

          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \left(-1 \cdot \lambda_2\right) - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        7. mul-1-negN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        8. lower-*.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        9. lower-sin.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        10. cos-negN/A

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

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

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

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\cos \lambda_1} \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        14. lower-sin.f6499.2

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

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

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)}} \]
      5. Step-by-step derivation
        1. cos-neg-revN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2} \]
        2. lift-cos.f6498.6

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2} \]
      6. Applied rewrites98.6%

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \lambda_2}} \]
    6. Recombined 2 regimes into one program.
    7. Add Preprocessing

    Alternative 4: 89.1% accurate, 0.8× speedup?

    \[\begin{array}{l} \\ \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \end{array} \]
    (FPCore (lambda1 lambda2 phi1 phi2)
     :precision binary64
     (atan2
      (*
       (- (* (sin lambda1) (cos lambda2)) (* (cos lambda1) (sin lambda2)))
       (cos phi2))
      (-
       (* (cos phi1) (sin phi2))
       (* (* (sin phi1) (cos phi2)) (cos (- lambda1 lambda2))))))
    double code(double lambda1, double lambda2, double phi1, double phi2) {
    	return atan2((((sin(lambda1) * cos(lambda2)) - (cos(lambda1) * sin(lambda2))) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))));
    }
    
    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, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        code = atan2((((sin(lambda1) * cos(lambda2)) - (cos(lambda1) * sin(lambda2))) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))))
    end function
    
    public static double code(double lambda1, double lambda2, double phi1, double phi2) {
    	return Math.atan2((((Math.sin(lambda1) * Math.cos(lambda2)) - (Math.cos(lambda1) * Math.sin(lambda2))) * Math.cos(phi2)), ((Math.cos(phi1) * Math.sin(phi2)) - ((Math.sin(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2)))));
    }
    
    def code(lambda1, lambda2, phi1, phi2):
    	return math.atan2((((math.sin(lambda1) * math.cos(lambda2)) - (math.cos(lambda1) * math.sin(lambda2))) * math.cos(phi2)), ((math.cos(phi1) * math.sin(phi2)) - ((math.sin(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2)))))
    
    function code(lambda1, lambda2, phi1, phi2)
    	return atan(Float64(Float64(Float64(sin(lambda1) * cos(lambda2)) - Float64(cos(lambda1) * sin(lambda2))) * cos(phi2)), Float64(Float64(cos(phi1) * sin(phi2)) - Float64(Float64(sin(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2)))))
    end
    
    function tmp = code(lambda1, lambda2, phi1, phi2)
    	tmp = atan2((((sin(lambda1) * cos(lambda2)) - (cos(lambda1) * sin(lambda2))) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))));
    end
    
    code[lambda1_, lambda2_, phi1_, phi2_] := N[ArcTan[N[(N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Sin[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)}
    \end{array}
    
    Derivation
    1. Initial program 79.1%

      \[\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    2. Step-by-step derivation
      1. lift--.f64N/A

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

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

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      4. cos-negN/A

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      5. mul-1-negN/A

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

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \left(-1 \cdot \lambda_2\right) - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      7. mul-1-negN/A

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      8. lower-*.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      9. lower-sin.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      10. cos-negN/A

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

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

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

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\cos \lambda_1} \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      14. lower-sin.f6489.3

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

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

    Alternative 5: 89.0% accurate, 0.6× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \phi_1 \cdot \sin \phi_2\\ t_1 := \sin \phi_1 \cdot \cos \phi_2\\ t_2 := \sin \lambda_1 \cdot \cos \lambda_2\\ t_3 := \tan^{-1}_* \frac{\left(t\_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{t\_0 - t\_1 \cdot \cos \lambda_2}\\ \mathbf{if}\;\lambda_2 \leq -17:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;\lambda_2 \leq 0.0001:\\ \;\;\;\;\tan^{-1}_* \frac{\left(t\_2 - \sin \lambda_2\right) \cdot \cos \phi_2}{t\_0 - t\_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_3\\ \end{array} \end{array} \]
    (FPCore (lambda1 lambda2 phi1 phi2)
     :precision binary64
     (let* ((t_0 (* (cos phi1) (sin phi2)))
            (t_1 (* (sin phi1) (cos phi2)))
            (t_2 (* (sin lambda1) (cos lambda2)))
            (t_3
             (atan2
              (* (- t_2 (* (cos lambda1) (sin lambda2))) (cos phi2))
              (- t_0 (* t_1 (cos lambda2))))))
       (if (<= lambda2 -17.0)
         t_3
         (if (<= lambda2 0.0001)
           (atan2
            (* (- t_2 (sin lambda2)) (cos phi2))
            (- t_0 (* t_1 (cos (- lambda1 lambda2)))))
           t_3))))
    double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = cos(phi1) * sin(phi2);
    	double t_1 = sin(phi1) * cos(phi2);
    	double t_2 = sin(lambda1) * cos(lambda2);
    	double t_3 = atan2(((t_2 - (cos(lambda1) * sin(lambda2))) * cos(phi2)), (t_0 - (t_1 * cos(lambda2))));
    	double tmp;
    	if (lambda2 <= -17.0) {
    		tmp = t_3;
    	} else if (lambda2 <= 0.0001) {
    		tmp = atan2(((t_2 - sin(lambda2)) * cos(phi2)), (t_0 - (t_1 * cos((lambda1 - lambda2)))));
    	} else {
    		tmp = t_3;
    	}
    	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, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: t_0
        real(8) :: t_1
        real(8) :: t_2
        real(8) :: t_3
        real(8) :: tmp
        t_0 = cos(phi1) * sin(phi2)
        t_1 = sin(phi1) * cos(phi2)
        t_2 = sin(lambda1) * cos(lambda2)
        t_3 = atan2(((t_2 - (cos(lambda1) * sin(lambda2))) * cos(phi2)), (t_0 - (t_1 * cos(lambda2))))
        if (lambda2 <= (-17.0d0)) then
            tmp = t_3
        else if (lambda2 <= 0.0001d0) then
            tmp = atan2(((t_2 - sin(lambda2)) * cos(phi2)), (t_0 - (t_1 * cos((lambda1 - lambda2)))))
        else
            tmp = t_3
        end if
        code = tmp
    end function
    
    public static double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = Math.cos(phi1) * Math.sin(phi2);
    	double t_1 = Math.sin(phi1) * Math.cos(phi2);
    	double t_2 = Math.sin(lambda1) * Math.cos(lambda2);
    	double t_3 = Math.atan2(((t_2 - (Math.cos(lambda1) * Math.sin(lambda2))) * Math.cos(phi2)), (t_0 - (t_1 * Math.cos(lambda2))));
    	double tmp;
    	if (lambda2 <= -17.0) {
    		tmp = t_3;
    	} else if (lambda2 <= 0.0001) {
    		tmp = Math.atan2(((t_2 - Math.sin(lambda2)) * Math.cos(phi2)), (t_0 - (t_1 * Math.cos((lambda1 - lambda2)))));
    	} else {
    		tmp = t_3;
    	}
    	return tmp;
    }
    
    def code(lambda1, lambda2, phi1, phi2):
    	t_0 = math.cos(phi1) * math.sin(phi2)
    	t_1 = math.sin(phi1) * math.cos(phi2)
    	t_2 = math.sin(lambda1) * math.cos(lambda2)
    	t_3 = math.atan2(((t_2 - (math.cos(lambda1) * math.sin(lambda2))) * math.cos(phi2)), (t_0 - (t_1 * math.cos(lambda2))))
    	tmp = 0
    	if lambda2 <= -17.0:
    		tmp = t_3
    	elif lambda2 <= 0.0001:
    		tmp = math.atan2(((t_2 - math.sin(lambda2)) * math.cos(phi2)), (t_0 - (t_1 * math.cos((lambda1 - lambda2)))))
    	else:
    		tmp = t_3
    	return tmp
    
    function code(lambda1, lambda2, phi1, phi2)
    	t_0 = Float64(cos(phi1) * sin(phi2))
    	t_1 = Float64(sin(phi1) * cos(phi2))
    	t_2 = Float64(sin(lambda1) * cos(lambda2))
    	t_3 = atan(Float64(Float64(t_2 - Float64(cos(lambda1) * sin(lambda2))) * cos(phi2)), Float64(t_0 - Float64(t_1 * cos(lambda2))))
    	tmp = 0.0
    	if (lambda2 <= -17.0)
    		tmp = t_3;
    	elseif (lambda2 <= 0.0001)
    		tmp = atan(Float64(Float64(t_2 - sin(lambda2)) * cos(phi2)), Float64(t_0 - Float64(t_1 * cos(Float64(lambda1 - lambda2)))));
    	else
    		tmp = t_3;
    	end
    	return tmp
    end
    
    function tmp_2 = code(lambda1, lambda2, phi1, phi2)
    	t_0 = cos(phi1) * sin(phi2);
    	t_1 = sin(phi1) * cos(phi2);
    	t_2 = sin(lambda1) * cos(lambda2);
    	t_3 = atan2(((t_2 - (cos(lambda1) * sin(lambda2))) * cos(phi2)), (t_0 - (t_1 * cos(lambda2))));
    	tmp = 0.0;
    	if (lambda2 <= -17.0)
    		tmp = t_3;
    	elseif (lambda2 <= 0.0001)
    		tmp = atan2(((t_2 - sin(lambda2)) * cos(phi2)), (t_0 - (t_1 * cos((lambda1 - lambda2)))));
    	else
    		tmp = t_3;
    	end
    	tmp_2 = tmp;
    end
    
    code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[ArcTan[N[(N[(t$95$2 - N[(N[Cos[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(t$95$0 - N[(t$95$1 * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[lambda2, -17.0], t$95$3, If[LessEqual[lambda2, 0.0001], N[ArcTan[N[(N[(t$95$2 - N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(t$95$0 - N[(t$95$1 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$3]]]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \cos \phi_1 \cdot \sin \phi_2\\
    t_1 := \sin \phi_1 \cdot \cos \phi_2\\
    t_2 := \sin \lambda_1 \cdot \cos \lambda_2\\
    t_3 := \tan^{-1}_* \frac{\left(t\_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{t\_0 - t\_1 \cdot \cos \lambda_2}\\
    \mathbf{if}\;\lambda_2 \leq -17:\\
    \;\;\;\;t\_3\\
    
    \mathbf{elif}\;\lambda_2 \leq 0.0001:\\
    \;\;\;\;\tan^{-1}_* \frac{\left(t\_2 - \sin \lambda_2\right) \cdot \cos \phi_2}{t\_0 - t\_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_3\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if lambda2 < -17 or 1.00000000000000005e-4 < lambda2

      1. Initial program 59.8%

        \[\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      2. Step-by-step derivation
        1. lift--.f64N/A

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

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

          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        4. cos-negN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        5. mul-1-negN/A

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

          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \left(-1 \cdot \lambda_2\right) - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        7. mul-1-negN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        8. lower-*.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        9. lower-sin.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        10. cos-negN/A

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

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

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

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\cos \lambda_1} \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        14. lower-sin.f6479.6

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      3. Applied rewrites79.6%

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

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)}} \]
      5. Step-by-step derivation
        1. cos-neg-revN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2} \]
        2. lift-cos.f6479.6

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2} \]
      6. Applied rewrites79.6%

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

      if -17 < lambda2 < 1.00000000000000005e-4

      1. Initial program 99.1%

        \[\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      2. Step-by-step derivation
        1. lift--.f64N/A

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

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

          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        4. cos-negN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        5. mul-1-negN/A

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

          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \left(-1 \cdot \lambda_2\right) - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        7. mul-1-negN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        8. lower-*.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        9. lower-sin.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        10. cos-negN/A

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

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

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

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\cos \lambda_1} \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        14. lower-sin.f6499.4

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

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

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\sin \lambda_2}\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      5. Step-by-step derivation
        1. lift-sin.f6499.1

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      6. Applied rewrites99.1%

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

    Alternative 6: 88.2% accurate, 0.7× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \lambda_1 \cdot \sin \lambda_2\\ t_1 := \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\\ t_2 := \cos \phi_1 \cdot \sin \phi_2 - t\_1\\ t_3 := \sin \lambda_1 \cdot \cos \lambda_2\\ \mathbf{if}\;\phi_1 \leq -9 \cdot 10^{-6}:\\ \;\;\;\;\tan^{-1}_* \frac{\left(t\_3 - \sin \lambda_2\right) \cdot \cos \phi_2}{t\_2}\\ \mathbf{elif}\;\phi_1 \leq 3.05 \cdot 10^{-16}:\\ \;\;\;\;\tan^{-1}_* \frac{\left(t\_3 - t\_0\right) \cdot \cos \phi_2}{\sin \phi_2 - t\_1}\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1}_* \frac{\left(\sin \lambda_1 - t\_0\right) \cdot \cos \phi_2}{t\_2}\\ \end{array} \end{array} \]
    (FPCore (lambda1 lambda2 phi1 phi2)
     :precision binary64
     (let* ((t_0 (* (cos lambda1) (sin lambda2)))
            (t_1 (* (* (sin phi1) (cos phi2)) (cos (- lambda1 lambda2))))
            (t_2 (- (* (cos phi1) (sin phi2)) t_1))
            (t_3 (* (sin lambda1) (cos lambda2))))
       (if (<= phi1 -9e-6)
         (atan2 (* (- t_3 (sin lambda2)) (cos phi2)) t_2)
         (if (<= phi1 3.05e-16)
           (atan2 (* (- t_3 t_0) (cos phi2)) (- (sin phi2) t_1))
           (atan2 (* (- (sin lambda1) t_0) (cos phi2)) t_2)))))
    double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = cos(lambda1) * sin(lambda2);
    	double t_1 = (sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2));
    	double t_2 = (cos(phi1) * sin(phi2)) - t_1;
    	double t_3 = sin(lambda1) * cos(lambda2);
    	double tmp;
    	if (phi1 <= -9e-6) {
    		tmp = atan2(((t_3 - sin(lambda2)) * cos(phi2)), t_2);
    	} else if (phi1 <= 3.05e-16) {
    		tmp = atan2(((t_3 - t_0) * cos(phi2)), (sin(phi2) - t_1));
    	} else {
    		tmp = atan2(((sin(lambda1) - t_0) * cos(phi2)), 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, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: t_0
        real(8) :: t_1
        real(8) :: t_2
        real(8) :: t_3
        real(8) :: tmp
        t_0 = cos(lambda1) * sin(lambda2)
        t_1 = (sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2))
        t_2 = (cos(phi1) * sin(phi2)) - t_1
        t_3 = sin(lambda1) * cos(lambda2)
        if (phi1 <= (-9d-6)) then
            tmp = atan2(((t_3 - sin(lambda2)) * cos(phi2)), t_2)
        else if (phi1 <= 3.05d-16) then
            tmp = atan2(((t_3 - t_0) * cos(phi2)), (sin(phi2) - t_1))
        else
            tmp = atan2(((sin(lambda1) - t_0) * cos(phi2)), t_2)
        end if
        code = tmp
    end function
    
    public static double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = Math.cos(lambda1) * Math.sin(lambda2);
    	double t_1 = (Math.sin(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2));
    	double t_2 = (Math.cos(phi1) * Math.sin(phi2)) - t_1;
    	double t_3 = Math.sin(lambda1) * Math.cos(lambda2);
    	double tmp;
    	if (phi1 <= -9e-6) {
    		tmp = Math.atan2(((t_3 - Math.sin(lambda2)) * Math.cos(phi2)), t_2);
    	} else if (phi1 <= 3.05e-16) {
    		tmp = Math.atan2(((t_3 - t_0) * Math.cos(phi2)), (Math.sin(phi2) - t_1));
    	} else {
    		tmp = Math.atan2(((Math.sin(lambda1) - t_0) * Math.cos(phi2)), t_2);
    	}
    	return tmp;
    }
    
    def code(lambda1, lambda2, phi1, phi2):
    	t_0 = math.cos(lambda1) * math.sin(lambda2)
    	t_1 = (math.sin(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2))
    	t_2 = (math.cos(phi1) * math.sin(phi2)) - t_1
    	t_3 = math.sin(lambda1) * math.cos(lambda2)
    	tmp = 0
    	if phi1 <= -9e-6:
    		tmp = math.atan2(((t_3 - math.sin(lambda2)) * math.cos(phi2)), t_2)
    	elif phi1 <= 3.05e-16:
    		tmp = math.atan2(((t_3 - t_0) * math.cos(phi2)), (math.sin(phi2) - t_1))
    	else:
    		tmp = math.atan2(((math.sin(lambda1) - t_0) * math.cos(phi2)), t_2)
    	return tmp
    
    function code(lambda1, lambda2, phi1, phi2)
    	t_0 = Float64(cos(lambda1) * sin(lambda2))
    	t_1 = Float64(Float64(sin(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2)))
    	t_2 = Float64(Float64(cos(phi1) * sin(phi2)) - t_1)
    	t_3 = Float64(sin(lambda1) * cos(lambda2))
    	tmp = 0.0
    	if (phi1 <= -9e-6)
    		tmp = atan(Float64(Float64(t_3 - sin(lambda2)) * cos(phi2)), t_2);
    	elseif (phi1 <= 3.05e-16)
    		tmp = atan(Float64(Float64(t_3 - t_0) * cos(phi2)), Float64(sin(phi2) - t_1));
    	else
    		tmp = atan(Float64(Float64(sin(lambda1) - t_0) * cos(phi2)), t_2);
    	end
    	return tmp
    end
    
    function tmp_2 = code(lambda1, lambda2, phi1, phi2)
    	t_0 = cos(lambda1) * sin(lambda2);
    	t_1 = (sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2));
    	t_2 = (cos(phi1) * sin(phi2)) - t_1;
    	t_3 = sin(lambda1) * cos(lambda2);
    	tmp = 0.0;
    	if (phi1 <= -9e-6)
    		tmp = atan2(((t_3 - sin(lambda2)) * cos(phi2)), t_2);
    	elseif (phi1 <= 3.05e-16)
    		tmp = atan2(((t_3 - t_0) * cos(phi2)), (sin(phi2) - t_1));
    	else
    		tmp = atan2(((sin(lambda1) - t_0) * cos(phi2)), t_2);
    	end
    	tmp_2 = tmp;
    end
    
    code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Sin[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] - t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(N[Sin[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -9e-6], N[ArcTan[N[(N[(t$95$3 - N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / t$95$2], $MachinePrecision], If[LessEqual[phi1, 3.05e-16], N[ArcTan[N[(N[(t$95$3 - t$95$0), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(N[Sin[phi2], $MachinePrecision] - t$95$1), $MachinePrecision]], $MachinePrecision], N[ArcTan[N[(N[(N[Sin[lambda1], $MachinePrecision] - t$95$0), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / t$95$2], $MachinePrecision]]]]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \cos \lambda_1 \cdot \sin \lambda_2\\
    t_1 := \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\\
    t_2 := \cos \phi_1 \cdot \sin \phi_2 - t\_1\\
    t_3 := \sin \lambda_1 \cdot \cos \lambda_2\\
    \mathbf{if}\;\phi_1 \leq -9 \cdot 10^{-6}:\\
    \;\;\;\;\tan^{-1}_* \frac{\left(t\_3 - \sin \lambda_2\right) \cdot \cos \phi_2}{t\_2}\\
    
    \mathbf{elif}\;\phi_1 \leq 3.05 \cdot 10^{-16}:\\
    \;\;\;\;\tan^{-1}_* \frac{\left(t\_3 - t\_0\right) \cdot \cos \phi_2}{\sin \phi_2 - t\_1}\\
    
    \mathbf{else}:\\
    \;\;\;\;\tan^{-1}_* \frac{\left(\sin \lambda_1 - t\_0\right) \cdot \cos \phi_2}{t\_2}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if phi1 < -9.00000000000000023e-6

      1. Initial program 76.7%

        \[\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      2. Step-by-step derivation
        1. lift--.f64N/A

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

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

          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        4. cos-negN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        5. mul-1-negN/A

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

          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \left(-1 \cdot \lambda_2\right) - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        7. mul-1-negN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        8. lower-*.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        9. lower-sin.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        10. cos-negN/A

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

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

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

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\cos \lambda_1} \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        14. lower-sin.f6479.7

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      3. Applied rewrites79.7%

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

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\sin \lambda_2}\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      5. Step-by-step derivation
        1. lift-sin.f6477.7

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      6. Applied rewrites77.7%

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

      if -9.00000000000000023e-6 < phi1 < 3.04999999999999976e-16

      1. Initial program 82.2%

        \[\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      2. Step-by-step derivation
        1. lift--.f64N/A

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

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

          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        4. cos-negN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        5. mul-1-negN/A

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

          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \left(-1 \cdot \lambda_2\right) - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        7. mul-1-negN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        8. lower-*.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        9. lower-sin.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        10. cos-negN/A

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

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

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

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\cos \lambda_1} \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        14. lower-sin.f6499.7

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

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

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2} - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      5. Step-by-step derivation
        1. lift-sin.f6499.7

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      6. Applied rewrites99.7%

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

      if 3.04999999999999976e-16 < phi1

      1. Initial program 75.4%

        \[\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      2. Step-by-step derivation
        1. lift--.f64N/A

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

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

          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        4. cos-negN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        5. mul-1-negN/A

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

          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \left(-1 \cdot \lambda_2\right) - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        7. mul-1-negN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        8. lower-*.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        9. lower-sin.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        10. cos-negN/A

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

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

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

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\cos \lambda_1} \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        14. lower-sin.f6479.0

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \color{blue}{\sin \lambda_2}\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      3. Applied rewrites79.0%

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      4. Taylor expanded in lambda2 around 0

        \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      5. Step-by-step derivation
        1. lift-sin.f6476.5

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      6. Applied rewrites76.5%

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

    Alternative 7: 83.1% accurate, 0.7× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_1 := \cos \lambda_1 \cdot \sin \lambda_2\\ t_2 := \tan^{-1}_* \frac{\left(\sin \lambda_1 - t\_1\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot t\_0}\\ \mathbf{if}\;\phi_2 \leq -2.7 \cdot 10^{-7}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;\phi_2 \leq 2.45 \cdot 10^{-85}:\\ \;\;\;\;\tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - t\_1\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - t\_0 \cdot \sin \phi_1}\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
    (FPCore (lambda1 lambda2 phi1 phi2)
     :precision binary64
     (let* ((t_0 (cos (- lambda1 lambda2)))
            (t_1 (* (cos lambda1) (sin lambda2)))
            (t_2
             (atan2
              (* (- (sin lambda1) t_1) (cos phi2))
              (- (* (cos phi1) (sin phi2)) (* (* (sin phi1) (cos phi2)) t_0)))))
       (if (<= phi2 -2.7e-7)
         t_2
         (if (<= phi2 2.45e-85)
           (atan2
            (* (- (* (sin lambda1) (cos lambda2)) t_1) (cos phi2))
            (- (* (cos phi1) phi2) (* t_0 (sin phi1))))
           t_2))))
    double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = cos((lambda1 - lambda2));
    	double t_1 = cos(lambda1) * sin(lambda2);
    	double t_2 = atan2(((sin(lambda1) - t_1) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((sin(phi1) * cos(phi2)) * t_0)));
    	double tmp;
    	if (phi2 <= -2.7e-7) {
    		tmp = t_2;
    	} else if (phi2 <= 2.45e-85) {
    		tmp = atan2((((sin(lambda1) * cos(lambda2)) - t_1) * cos(phi2)), ((cos(phi1) * phi2) - (t_0 * sin(phi1))));
    	} 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, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: t_0
        real(8) :: t_1
        real(8) :: t_2
        real(8) :: tmp
        t_0 = cos((lambda1 - lambda2))
        t_1 = cos(lambda1) * sin(lambda2)
        t_2 = atan2(((sin(lambda1) - t_1) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((sin(phi1) * cos(phi2)) * t_0)))
        if (phi2 <= (-2.7d-7)) then
            tmp = t_2
        else if (phi2 <= 2.45d-85) then
            tmp = atan2((((sin(lambda1) * cos(lambda2)) - t_1) * cos(phi2)), ((cos(phi1) * phi2) - (t_0 * sin(phi1))))
        else
            tmp = t_2
        end if
        code = tmp
    end function
    
    public static double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = Math.cos((lambda1 - lambda2));
    	double t_1 = Math.cos(lambda1) * Math.sin(lambda2);
    	double t_2 = Math.atan2(((Math.sin(lambda1) - t_1) * Math.cos(phi2)), ((Math.cos(phi1) * Math.sin(phi2)) - ((Math.sin(phi1) * Math.cos(phi2)) * t_0)));
    	double tmp;
    	if (phi2 <= -2.7e-7) {
    		tmp = t_2;
    	} else if (phi2 <= 2.45e-85) {
    		tmp = Math.atan2((((Math.sin(lambda1) * Math.cos(lambda2)) - t_1) * Math.cos(phi2)), ((Math.cos(phi1) * phi2) - (t_0 * Math.sin(phi1))));
    	} else {
    		tmp = t_2;
    	}
    	return tmp;
    }
    
    def code(lambda1, lambda2, phi1, phi2):
    	t_0 = math.cos((lambda1 - lambda2))
    	t_1 = math.cos(lambda1) * math.sin(lambda2)
    	t_2 = math.atan2(((math.sin(lambda1) - t_1) * math.cos(phi2)), ((math.cos(phi1) * math.sin(phi2)) - ((math.sin(phi1) * math.cos(phi2)) * t_0)))
    	tmp = 0
    	if phi2 <= -2.7e-7:
    		tmp = t_2
    	elif phi2 <= 2.45e-85:
    		tmp = math.atan2((((math.sin(lambda1) * math.cos(lambda2)) - t_1) * math.cos(phi2)), ((math.cos(phi1) * phi2) - (t_0 * math.sin(phi1))))
    	else:
    		tmp = t_2
    	return tmp
    
    function code(lambda1, lambda2, phi1, phi2)
    	t_0 = cos(Float64(lambda1 - lambda2))
    	t_1 = Float64(cos(lambda1) * sin(lambda2))
    	t_2 = atan(Float64(Float64(sin(lambda1) - t_1) * cos(phi2)), Float64(Float64(cos(phi1) * sin(phi2)) - Float64(Float64(sin(phi1) * cos(phi2)) * t_0)))
    	tmp = 0.0
    	if (phi2 <= -2.7e-7)
    		tmp = t_2;
    	elseif (phi2 <= 2.45e-85)
    		tmp = atan(Float64(Float64(Float64(sin(lambda1) * cos(lambda2)) - t_1) * cos(phi2)), Float64(Float64(cos(phi1) * phi2) - Float64(t_0 * sin(phi1))));
    	else
    		tmp = t_2;
    	end
    	return tmp
    end
    
    function tmp_2 = code(lambda1, lambda2, phi1, phi2)
    	t_0 = cos((lambda1 - lambda2));
    	t_1 = cos(lambda1) * sin(lambda2);
    	t_2 = atan2(((sin(lambda1) - t_1) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((sin(phi1) * cos(phi2)) * t_0)));
    	tmp = 0.0;
    	if (phi2 <= -2.7e-7)
    		tmp = t_2;
    	elseif (phi2 <= 2.45e-85)
    		tmp = atan2((((sin(lambda1) * cos(lambda2)) - t_1) * cos(phi2)), ((cos(phi1) * phi2) - (t_0 * sin(phi1))));
    	else
    		tmp = t_2;
    	end
    	tmp_2 = tmp;
    end
    
    code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[ArcTan[N[(N[(N[Sin[lambda1], $MachinePrecision] - t$95$1), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Sin[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -2.7e-7], t$95$2, If[LessEqual[phi2, 2.45e-85], N[ArcTan[N[(N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] - t$95$1), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[phi1], $MachinePrecision] * phi2), $MachinePrecision] - N[(t$95$0 * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$2]]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
    t_1 := \cos \lambda_1 \cdot \sin \lambda_2\\
    t_2 := \tan^{-1}_* \frac{\left(\sin \lambda_1 - t\_1\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot t\_0}\\
    \mathbf{if}\;\phi_2 \leq -2.7 \cdot 10^{-7}:\\
    \;\;\;\;t\_2\\
    
    \mathbf{elif}\;\phi_2 \leq 2.45 \cdot 10^{-85}:\\
    \;\;\;\;\tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - t\_1\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - t\_0 \cdot \sin \phi_1}\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_2\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if phi2 < -2.70000000000000009e-7 or 2.45000000000000007e-85 < phi2

      1. Initial program 77.3%

        \[\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      2. Step-by-step derivation
        1. lift--.f64N/A

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

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

          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        4. cos-negN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        5. mul-1-negN/A

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

          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \left(-1 \cdot \lambda_2\right) - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        7. mul-1-negN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        8. lower-*.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        9. lower-sin.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        10. cos-negN/A

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

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

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

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\cos \lambda_1} \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        14. lower-sin.f6489.5

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

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      4. Taylor expanded in lambda2 around 0

        \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      5. Step-by-step derivation
        1. lift-sin.f6478.7

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      6. Applied rewrites78.7%

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

      if -2.70000000000000009e-7 < phi2 < 2.45000000000000007e-85

      1. Initial program 81.5%

        \[\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      2. Step-by-step derivation
        1. lift--.f64N/A

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

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

          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        4. cos-negN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        5. mul-1-negN/A

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

          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \left(-1 \cdot \lambda_2\right) - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        7. mul-1-negN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        8. lower-*.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        9. lower-sin.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        10. cos-negN/A

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

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

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

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\cos \lambda_1} \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        14. lower-sin.f6489.1

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

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      4. Taylor expanded in phi2 around 0

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\phi_2 \cdot \cos \phi_1 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1}} \]
      5. Step-by-step derivation
        1. lower--.f64N/A

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

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

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)} \cdot \sin \phi_1} \]
        4. lift-cos.f64N/A

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

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\sin \phi_1}} \]
        6. lift-cos.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \color{blue}{\phi_1}} \]
        7. lift--.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
        8. lift-sin.f6489.1

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
      6. Applied rewrites89.1%

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

    Alternative 8: 82.7% accurate, 0.7× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \phi_1 \cdot \cos \phi_2\\ t_1 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_2 := \sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\\ \mathbf{if}\;\phi_2 \leq -2.7 \cdot 10^{-7}:\\ \;\;\;\;\tan^{-1}_* \frac{t\_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(-t\_0\right) \cdot t\_1\right)}\\ \mathbf{elif}\;\phi_2 \leq 2 \cdot 10^{-14}:\\ \;\;\;\;\tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - t\_1 \cdot \sin \phi_1}\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1}_* \frac{t\_2}{\cos \phi_1 \cdot \sin \phi_2 - t\_0 \cdot t\_1}\\ \end{array} \end{array} \]
    (FPCore (lambda1 lambda2 phi1 phi2)
     :precision binary64
     (let* ((t_0 (* (sin phi1) (cos phi2)))
            (t_1 (cos (- lambda1 lambda2)))
            (t_2 (* (sin (- lambda1 lambda2)) (cos phi2))))
       (if (<= phi2 -2.7e-7)
         (atan2 t_2 (fma (sin phi2) (cos phi1) (* (- t_0) t_1)))
         (if (<= phi2 2e-14)
           (atan2
            (*
             (- (* (sin lambda1) (cos lambda2)) (* (cos lambda1) (sin lambda2)))
             (cos phi2))
            (- (* (cos phi1) phi2) (* t_1 (sin phi1))))
           (atan2 t_2 (- (* (cos phi1) (sin phi2)) (* t_0 t_1)))))))
    double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = sin(phi1) * cos(phi2);
    	double t_1 = cos((lambda1 - lambda2));
    	double t_2 = sin((lambda1 - lambda2)) * cos(phi2);
    	double tmp;
    	if (phi2 <= -2.7e-7) {
    		tmp = atan2(t_2, fma(sin(phi2), cos(phi1), (-t_0 * t_1)));
    	} else if (phi2 <= 2e-14) {
    		tmp = atan2((((sin(lambda1) * cos(lambda2)) - (cos(lambda1) * sin(lambda2))) * cos(phi2)), ((cos(phi1) * phi2) - (t_1 * sin(phi1))));
    	} else {
    		tmp = atan2(t_2, ((cos(phi1) * sin(phi2)) - (t_0 * t_1)));
    	}
    	return tmp;
    }
    
    function code(lambda1, lambda2, phi1, phi2)
    	t_0 = Float64(sin(phi1) * cos(phi2))
    	t_1 = cos(Float64(lambda1 - lambda2))
    	t_2 = Float64(sin(Float64(lambda1 - lambda2)) * cos(phi2))
    	tmp = 0.0
    	if (phi2 <= -2.7e-7)
    		tmp = atan(t_2, fma(sin(phi2), cos(phi1), Float64(Float64(-t_0) * t_1)));
    	elseif (phi2 <= 2e-14)
    		tmp = atan(Float64(Float64(Float64(sin(lambda1) * cos(lambda2)) - Float64(cos(lambda1) * sin(lambda2))) * cos(phi2)), Float64(Float64(cos(phi1) * phi2) - Float64(t_1 * sin(phi1))));
    	else
    		tmp = atan(t_2, Float64(Float64(cos(phi1) * sin(phi2)) - Float64(t_0 * t_1)));
    	end
    	return tmp
    end
    
    code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Sin[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -2.7e-7], N[ArcTan[t$95$2 / N[(N[Sin[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[((-t$95$0) * t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[phi2, 2e-14], N[ArcTan[N[(N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[phi1], $MachinePrecision] * phi2), $MachinePrecision] - N[(t$95$1 * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[t$95$2 / N[(N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] - N[(t$95$0 * t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \sin \phi_1 \cdot \cos \phi_2\\
    t_1 := \cos \left(\lambda_1 - \lambda_2\right)\\
    t_2 := \sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\\
    \mathbf{if}\;\phi_2 \leq -2.7 \cdot 10^{-7}:\\
    \;\;\;\;\tan^{-1}_* \frac{t\_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(-t\_0\right) \cdot t\_1\right)}\\
    
    \mathbf{elif}\;\phi_2 \leq 2 \cdot 10^{-14}:\\
    \;\;\;\;\tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - t\_1 \cdot \sin \phi_1}\\
    
    \mathbf{else}:\\
    \;\;\;\;\tan^{-1}_* \frac{t\_2}{\cos \phi_1 \cdot \sin \phi_2 - t\_0 \cdot t\_1}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if phi2 < -2.70000000000000009e-7

      1. Initial program 77.3%

        \[\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      2. Step-by-step derivation
        1. lift--.f64N/A

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

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\cos \phi_1 \cdot \sin \phi_2} - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        3. lift-cos.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\cos \phi_1} \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        4. lift-sin.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \color{blue}{\sin \phi_2} - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        5. lift-*.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \color{blue}{\left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)}} \]
        6. lift-*.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \color{blue}{\left(\sin \phi_1 \cdot \cos \phi_2\right)} \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        7. lift-sin.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\color{blue}{\sin \phi_1} \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        8. lift-cos.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \color{blue}{\cos \phi_2}\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        9. lift--.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \color{blue}{\left(\lambda_1 - \lambda_2\right)}} \]
        10. lift-cos.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)}} \]
        11. fp-cancel-sub-sign-invN/A

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

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

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

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

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

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \color{blue}{\left(\mathsf{neg}\left(\sin \phi_1 \cdot \cos \phi_2\right)\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)}\right)} \]
      3. Applied rewrites77.3%

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

      if -2.70000000000000009e-7 < phi2 < 2e-14

      1. Initial program 81.6%

        \[\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      2. Step-by-step derivation
        1. lift--.f64N/A

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

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

          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        4. cos-negN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        5. mul-1-negN/A

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

          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \left(-1 \cdot \lambda_2\right) - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        7. mul-1-negN/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        8. lower-*.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        9. lower-sin.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        10. cos-negN/A

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

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

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

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\cos \lambda_1} \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        14. lower-sin.f6489.1

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

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      4. Taylor expanded in phi2 around 0

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\phi_2 \cdot \cos \phi_1 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1}} \]
      5. Step-by-step derivation
        1. lower--.f64N/A

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

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

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)} \cdot \sin \phi_1} \]
        4. lift-cos.f64N/A

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

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\sin \phi_1}} \]
        6. lift-cos.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \color{blue}{\phi_1}} \]
        7. lift--.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
        8. lift-sin.f6489.1

          \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
      6. Applied rewrites89.1%

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

      if 2e-14 < phi2

      1. Initial program 76.2%

        \[\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    3. Recombined 3 regimes into one program.
    4. Add Preprocessing

    Alternative 9: 80.8% accurate, 0.9× speedup?

    \[\begin{array}{l} \\ \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \end{array} \]
    (FPCore (lambda1 lambda2 phi1 phi2)
     :precision binary64
     (atan2
      (* (- (* (sin lambda1) (cos lambda2)) (sin lambda2)) (cos phi2))
      (-
       (* (cos phi1) (sin phi2))
       (* (* (sin phi1) (cos phi2)) (cos (- lambda1 lambda2))))))
    double code(double lambda1, double lambda2, double phi1, double phi2) {
    	return atan2((((sin(lambda1) * cos(lambda2)) - sin(lambda2)) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))));
    }
    
    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, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        code = atan2((((sin(lambda1) * cos(lambda2)) - sin(lambda2)) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))))
    end function
    
    public static double code(double lambda1, double lambda2, double phi1, double phi2) {
    	return Math.atan2((((Math.sin(lambda1) * Math.cos(lambda2)) - Math.sin(lambda2)) * Math.cos(phi2)), ((Math.cos(phi1) * Math.sin(phi2)) - ((Math.sin(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2)))));
    }
    
    def code(lambda1, lambda2, phi1, phi2):
    	return math.atan2((((math.sin(lambda1) * math.cos(lambda2)) - math.sin(lambda2)) * math.cos(phi2)), ((math.cos(phi1) * math.sin(phi2)) - ((math.sin(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2)))))
    
    function code(lambda1, lambda2, phi1, phi2)
    	return atan(Float64(Float64(Float64(sin(lambda1) * cos(lambda2)) - sin(lambda2)) * cos(phi2)), Float64(Float64(cos(phi1) * sin(phi2)) - Float64(Float64(sin(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2)))))
    end
    
    function tmp = code(lambda1, lambda2, phi1, phi2)
    	tmp = atan2((((sin(lambda1) * cos(lambda2)) - sin(lambda2)) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))));
    end
    
    code[lambda1_, lambda2_, phi1_, phi2_] := N[ArcTan[N[(N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] - N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Sin[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)}
    \end{array}
    
    Derivation
    1. Initial program 79.1%

      \[\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    2. Step-by-step derivation
      1. lift--.f64N/A

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

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

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      4. cos-negN/A

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      5. mul-1-negN/A

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

        \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(\sin \lambda_1 \cdot \cos \left(-1 \cdot \lambda_2\right) - \cos \lambda_1 \cdot \sin \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      7. mul-1-negN/A

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \color{blue}{\left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      8. lower-*.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      9. lower-sin.f64N/A

        \[\leadsto \tan^{-1}_* \frac{\left(\color{blue}{\sin \lambda_1} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right) - \cos \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      10. cos-negN/A

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

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

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

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\cos \lambda_1} \cdot \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      14. lower-sin.f6489.3

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

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

      \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\sin \lambda_2}\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    5. Step-by-step derivation
      1. lift-sin.f6480.8

        \[\leadsto \tan^{-1}_* \frac{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    6. Applied rewrites80.8%

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

    Alternative 10: 79.1% accurate, 0.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \phi_1 \cdot \sin \phi_2\\ t_1 := \sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\\ \mathbf{if}\;\lambda_2 \leq -7.6 \cdot 10^{-5}:\\ \;\;\;\;\tan^{-1}_* \frac{t\_1}{t\_0 - \left(\cos \lambda_2 \cdot \sin \phi_1\right) \cdot \cos \phi_2}\\ \mathbf{elif}\;\lambda_2 \leq 9.6 \cdot 10^{-5}:\\ \;\;\;\;\tan^{-1}_* \frac{t\_1}{t\_0 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1}\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1}_* \frac{\sin \left(-\lambda_2\right) \cdot \cos \phi_2}{t\_0 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\ \end{array} \end{array} \]
    (FPCore (lambda1 lambda2 phi1 phi2)
     :precision binary64
     (let* ((t_0 (* (cos phi1) (sin phi2)))
            (t_1 (* (sin (- lambda1 lambda2)) (cos phi2))))
       (if (<= lambda2 -7.6e-5)
         (atan2 t_1 (- t_0 (* (* (cos lambda2) (sin phi1)) (cos phi2))))
         (if (<= lambda2 9.6e-5)
           (atan2 t_1 (- t_0 (* (* (cos lambda1) (cos phi2)) (sin phi1))))
           (atan2
            (* (sin (- lambda2)) (cos phi2))
            (- t_0 (* (* (sin phi1) (cos phi2)) (cos (- lambda1 lambda2)))))))))
    double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = cos(phi1) * sin(phi2);
    	double t_1 = sin((lambda1 - lambda2)) * cos(phi2);
    	double tmp;
    	if (lambda2 <= -7.6e-5) {
    		tmp = atan2(t_1, (t_0 - ((cos(lambda2) * sin(phi1)) * cos(phi2))));
    	} else if (lambda2 <= 9.6e-5) {
    		tmp = atan2(t_1, (t_0 - ((cos(lambda1) * cos(phi2)) * sin(phi1))));
    	} else {
    		tmp = atan2((sin(-lambda2) * cos(phi2)), (t_0 - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))));
    	}
    	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, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: t_0
        real(8) :: t_1
        real(8) :: tmp
        t_0 = cos(phi1) * sin(phi2)
        t_1 = sin((lambda1 - lambda2)) * cos(phi2)
        if (lambda2 <= (-7.6d-5)) then
            tmp = atan2(t_1, (t_0 - ((cos(lambda2) * sin(phi1)) * cos(phi2))))
        else if (lambda2 <= 9.6d-5) then
            tmp = atan2(t_1, (t_0 - ((cos(lambda1) * cos(phi2)) * sin(phi1))))
        else
            tmp = atan2((sin(-lambda2) * cos(phi2)), (t_0 - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))))
        end if
        code = tmp
    end function
    
    public static double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = Math.cos(phi1) * Math.sin(phi2);
    	double t_1 = Math.sin((lambda1 - lambda2)) * Math.cos(phi2);
    	double tmp;
    	if (lambda2 <= -7.6e-5) {
    		tmp = Math.atan2(t_1, (t_0 - ((Math.cos(lambda2) * Math.sin(phi1)) * Math.cos(phi2))));
    	} else if (lambda2 <= 9.6e-5) {
    		tmp = Math.atan2(t_1, (t_0 - ((Math.cos(lambda1) * Math.cos(phi2)) * Math.sin(phi1))));
    	} else {
    		tmp = Math.atan2((Math.sin(-lambda2) * Math.cos(phi2)), (t_0 - ((Math.sin(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2)))));
    	}
    	return tmp;
    }
    
    def code(lambda1, lambda2, phi1, phi2):
    	t_0 = math.cos(phi1) * math.sin(phi2)
    	t_1 = math.sin((lambda1 - lambda2)) * math.cos(phi2)
    	tmp = 0
    	if lambda2 <= -7.6e-5:
    		tmp = math.atan2(t_1, (t_0 - ((math.cos(lambda2) * math.sin(phi1)) * math.cos(phi2))))
    	elif lambda2 <= 9.6e-5:
    		tmp = math.atan2(t_1, (t_0 - ((math.cos(lambda1) * math.cos(phi2)) * math.sin(phi1))))
    	else:
    		tmp = math.atan2((math.sin(-lambda2) * math.cos(phi2)), (t_0 - ((math.sin(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2)))))
    	return tmp
    
    function code(lambda1, lambda2, phi1, phi2)
    	t_0 = Float64(cos(phi1) * sin(phi2))
    	t_1 = Float64(sin(Float64(lambda1 - lambda2)) * cos(phi2))
    	tmp = 0.0
    	if (lambda2 <= -7.6e-5)
    		tmp = atan(t_1, Float64(t_0 - Float64(Float64(cos(lambda2) * sin(phi1)) * cos(phi2))));
    	elseif (lambda2 <= 9.6e-5)
    		tmp = atan(t_1, Float64(t_0 - Float64(Float64(cos(lambda1) * cos(phi2)) * sin(phi1))));
    	else
    		tmp = atan(Float64(sin(Float64(-lambda2)) * cos(phi2)), Float64(t_0 - Float64(Float64(sin(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2)))));
    	end
    	return tmp
    end
    
    function tmp_2 = code(lambda1, lambda2, phi1, phi2)
    	t_0 = cos(phi1) * sin(phi2);
    	t_1 = sin((lambda1 - lambda2)) * cos(phi2);
    	tmp = 0.0;
    	if (lambda2 <= -7.6e-5)
    		tmp = atan2(t_1, (t_0 - ((cos(lambda2) * sin(phi1)) * cos(phi2))));
    	elseif (lambda2 <= 9.6e-5)
    		tmp = atan2(t_1, (t_0 - ((cos(lambda1) * cos(phi2)) * sin(phi1))));
    	else
    		tmp = atan2((sin(-lambda2) * cos(phi2)), (t_0 - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))));
    	end
    	tmp_2 = tmp;
    end
    
    code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda2, -7.6e-5], N[ArcTan[t$95$1 / N[(t$95$0 - N[(N[(N[Cos[lambda2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[lambda2, 9.6e-5], N[ArcTan[t$95$1 / N[(t$95$0 - N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[N[(N[Sin[(-lambda2)], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(t$95$0 - N[(N[(N[Sin[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \cos \phi_1 \cdot \sin \phi_2\\
    t_1 := \sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\\
    \mathbf{if}\;\lambda_2 \leq -7.6 \cdot 10^{-5}:\\
    \;\;\;\;\tan^{-1}_* \frac{t\_1}{t\_0 - \left(\cos \lambda_2 \cdot \sin \phi_1\right) \cdot \cos \phi_2}\\
    
    \mathbf{elif}\;\lambda_2 \leq 9.6 \cdot 10^{-5}:\\
    \;\;\;\;\tan^{-1}_* \frac{t\_1}{t\_0 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1}\\
    
    \mathbf{else}:\\
    \;\;\;\;\tan^{-1}_* \frac{\sin \left(-\lambda_2\right) \cdot \cos \phi_2}{t\_0 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if lambda2 < -7.6000000000000004e-5

      1. Initial program 60.4%

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

        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \color{blue}{\cos \phi_2 \cdot \left(\cos \left(\mathsf{neg}\left(\lambda_2\right)\right) \cdot \sin \phi_1\right)}} \]
      3. Step-by-step derivation
        1. *-commutativeN/A

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

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \left(\mathsf{neg}\left(\lambda_2\right)\right) \cdot \sin \phi_1\right) \cdot \color{blue}{\cos \phi_2}} \]
        3. lower-*.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \left(\mathsf{neg}\left(\lambda_2\right)\right) \cdot \sin \phi_1\right) \cdot \cos \color{blue}{\phi_2}} \]
        4. cos-negN/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_2 \cdot \sin \phi_1\right) \cdot \cos \phi_2} \]
        5. lower-cos.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_2 \cdot \sin \phi_1\right) \cdot \cos \phi_2} \]
        6. lift-sin.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_2 \cdot \sin \phi_1\right) \cdot \cos \phi_2} \]
        7. lift-cos.f6460.3

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_2 \cdot \sin \phi_1\right) \cdot \cos \phi_2} \]
      4. Applied rewrites60.3%

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

      if -7.6000000000000004e-5 < lambda2 < 9.6000000000000002e-5

      1. Initial program 99.4%

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

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

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

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

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

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
        5. lift-cos.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
        6. lift-sin.f6499.3

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
      4. Applied rewrites99.3%

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

      if 9.6000000000000002e-5 < lambda2

      1. Initial program 59.4%

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

        \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\left(-1 \cdot \lambda_2\right)} \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      3. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\mathsf{neg}\left(\lambda_2\right)\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        2. lower-neg.f6458.9

          \[\leadsto \tan^{-1}_* \frac{\sin \left(-\lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      4. Applied rewrites58.9%

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

    Alternative 11: 79.1% accurate, 0.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \phi_1 \cdot \sin \phi_2\\ t_1 := \sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\\ \mathbf{if}\;\lambda_1 \leq -8500000000000:\\ \;\;\;\;\tan^{-1}_* \frac{t\_1}{t\_0 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1}\\ \mathbf{elif}\;\lambda_1 \leq 7.5 \cdot 10^{+41}:\\ \;\;\;\;\tan^{-1}_* \frac{t\_1}{t\_0 - \left(\cos \lambda_2 \cdot \sin \phi_1\right) \cdot \cos \phi_2}\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1}_* \frac{\sin \lambda_1 \cdot \cos \phi_2}{t\_0 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\ \end{array} \end{array} \]
    (FPCore (lambda1 lambda2 phi1 phi2)
     :precision binary64
     (let* ((t_0 (* (cos phi1) (sin phi2)))
            (t_1 (* (sin (- lambda1 lambda2)) (cos phi2))))
       (if (<= lambda1 -8500000000000.0)
         (atan2 t_1 (- t_0 (* (* (cos lambda1) (cos phi2)) (sin phi1))))
         (if (<= lambda1 7.5e+41)
           (atan2 t_1 (- t_0 (* (* (cos lambda2) (sin phi1)) (cos phi2))))
           (atan2
            (* (sin lambda1) (cos phi2))
            (- t_0 (* (* (sin phi1) (cos phi2)) (cos (- lambda1 lambda2)))))))))
    double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = cos(phi1) * sin(phi2);
    	double t_1 = sin((lambda1 - lambda2)) * cos(phi2);
    	double tmp;
    	if (lambda1 <= -8500000000000.0) {
    		tmp = atan2(t_1, (t_0 - ((cos(lambda1) * cos(phi2)) * sin(phi1))));
    	} else if (lambda1 <= 7.5e+41) {
    		tmp = atan2(t_1, (t_0 - ((cos(lambda2) * sin(phi1)) * cos(phi2))));
    	} else {
    		tmp = atan2((sin(lambda1) * cos(phi2)), (t_0 - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))));
    	}
    	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, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: t_0
        real(8) :: t_1
        real(8) :: tmp
        t_0 = cos(phi1) * sin(phi2)
        t_1 = sin((lambda1 - lambda2)) * cos(phi2)
        if (lambda1 <= (-8500000000000.0d0)) then
            tmp = atan2(t_1, (t_0 - ((cos(lambda1) * cos(phi2)) * sin(phi1))))
        else if (lambda1 <= 7.5d+41) then
            tmp = atan2(t_1, (t_0 - ((cos(lambda2) * sin(phi1)) * cos(phi2))))
        else
            tmp = atan2((sin(lambda1) * cos(phi2)), (t_0 - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))))
        end if
        code = tmp
    end function
    
    public static double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = Math.cos(phi1) * Math.sin(phi2);
    	double t_1 = Math.sin((lambda1 - lambda2)) * Math.cos(phi2);
    	double tmp;
    	if (lambda1 <= -8500000000000.0) {
    		tmp = Math.atan2(t_1, (t_0 - ((Math.cos(lambda1) * Math.cos(phi2)) * Math.sin(phi1))));
    	} else if (lambda1 <= 7.5e+41) {
    		tmp = Math.atan2(t_1, (t_0 - ((Math.cos(lambda2) * Math.sin(phi1)) * Math.cos(phi2))));
    	} else {
    		tmp = Math.atan2((Math.sin(lambda1) * Math.cos(phi2)), (t_0 - ((Math.sin(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2)))));
    	}
    	return tmp;
    }
    
    def code(lambda1, lambda2, phi1, phi2):
    	t_0 = math.cos(phi1) * math.sin(phi2)
    	t_1 = math.sin((lambda1 - lambda2)) * math.cos(phi2)
    	tmp = 0
    	if lambda1 <= -8500000000000.0:
    		tmp = math.atan2(t_1, (t_0 - ((math.cos(lambda1) * math.cos(phi2)) * math.sin(phi1))))
    	elif lambda1 <= 7.5e+41:
    		tmp = math.atan2(t_1, (t_0 - ((math.cos(lambda2) * math.sin(phi1)) * math.cos(phi2))))
    	else:
    		tmp = math.atan2((math.sin(lambda1) * math.cos(phi2)), (t_0 - ((math.sin(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2)))))
    	return tmp
    
    function code(lambda1, lambda2, phi1, phi2)
    	t_0 = Float64(cos(phi1) * sin(phi2))
    	t_1 = Float64(sin(Float64(lambda1 - lambda2)) * cos(phi2))
    	tmp = 0.0
    	if (lambda1 <= -8500000000000.0)
    		tmp = atan(t_1, Float64(t_0 - Float64(Float64(cos(lambda1) * cos(phi2)) * sin(phi1))));
    	elseif (lambda1 <= 7.5e+41)
    		tmp = atan(t_1, Float64(t_0 - Float64(Float64(cos(lambda2) * sin(phi1)) * cos(phi2))));
    	else
    		tmp = atan(Float64(sin(lambda1) * cos(phi2)), Float64(t_0 - Float64(Float64(sin(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2)))));
    	end
    	return tmp
    end
    
    function tmp_2 = code(lambda1, lambda2, phi1, phi2)
    	t_0 = cos(phi1) * sin(phi2);
    	t_1 = sin((lambda1 - lambda2)) * cos(phi2);
    	tmp = 0.0;
    	if (lambda1 <= -8500000000000.0)
    		tmp = atan2(t_1, (t_0 - ((cos(lambda1) * cos(phi2)) * sin(phi1))));
    	elseif (lambda1 <= 7.5e+41)
    		tmp = atan2(t_1, (t_0 - ((cos(lambda2) * sin(phi1)) * cos(phi2))));
    	else
    		tmp = atan2((sin(lambda1) * cos(phi2)), (t_0 - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))));
    	end
    	tmp_2 = tmp;
    end
    
    code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda1, -8500000000000.0], N[ArcTan[t$95$1 / N[(t$95$0 - N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[lambda1, 7.5e+41], N[ArcTan[t$95$1 / N[(t$95$0 - N[(N[(N[Cos[lambda2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[N[(N[Sin[lambda1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(t$95$0 - N[(N[(N[Sin[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \cos \phi_1 \cdot \sin \phi_2\\
    t_1 := \sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\\
    \mathbf{if}\;\lambda_1 \leq -8500000000000:\\
    \;\;\;\;\tan^{-1}_* \frac{t\_1}{t\_0 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1}\\
    
    \mathbf{elif}\;\lambda_1 \leq 7.5 \cdot 10^{+41}:\\
    \;\;\;\;\tan^{-1}_* \frac{t\_1}{t\_0 - \left(\cos \lambda_2 \cdot \sin \phi_1\right) \cdot \cos \phi_2}\\
    
    \mathbf{else}:\\
    \;\;\;\;\tan^{-1}_* \frac{\sin \lambda_1 \cdot \cos \phi_2}{t\_0 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if lambda1 < -8.5e12

      1. Initial program 58.8%

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

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

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

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

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

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
        5. lift-cos.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
        6. lift-sin.f6458.8

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
      4. Applied rewrites58.8%

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

      if -8.5e12 < lambda1 < 7.50000000000000072e41

      1. Initial program 95.9%

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

        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \color{blue}{\cos \phi_2 \cdot \left(\cos \left(\mathsf{neg}\left(\lambda_2\right)\right) \cdot \sin \phi_1\right)}} \]
      3. Step-by-step derivation
        1. *-commutativeN/A

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

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \left(\mathsf{neg}\left(\lambda_2\right)\right) \cdot \sin \phi_1\right) \cdot \color{blue}{\cos \phi_2}} \]
        3. lower-*.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \left(\mathsf{neg}\left(\lambda_2\right)\right) \cdot \sin \phi_1\right) \cdot \cos \color{blue}{\phi_2}} \]
        4. cos-negN/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_2 \cdot \sin \phi_1\right) \cdot \cos \phi_2} \]
        5. lower-cos.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_2 \cdot \sin \phi_1\right) \cdot \cos \phi_2} \]
        6. lift-sin.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_2 \cdot \sin \phi_1\right) \cdot \cos \phi_2} \]
        7. lift-cos.f6493.9

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_2 \cdot \sin \phi_1\right) \cdot \cos \phi_2} \]
      4. Applied rewrites93.9%

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

      if 7.50000000000000072e41 < lambda1

      1. Initial program 59.1%

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

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

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

      Alternative 12: 78.9% accurate, 1.0× speedup?

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

        \[\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      2. Step-by-step derivation
        1. lift--.f64N/A

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

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\cos \phi_1 \cdot \sin \phi_2} - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        3. lift-cos.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\cos \phi_1} \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        4. lift-sin.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \color{blue}{\sin \phi_2} - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        5. lift-*.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \color{blue}{\left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)}} \]
        6. lift-*.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \color{blue}{\left(\sin \phi_1 \cdot \cos \phi_2\right)} \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        7. lift-sin.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\color{blue}{\sin \phi_1} \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        8. lift-cos.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \color{blue}{\cos \phi_2}\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        9. lift--.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \color{blue}{\left(\lambda_1 - \lambda_2\right)}} \]
        10. lift-cos.f64N/A

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)}} \]
        11. fp-cancel-sub-sign-invN/A

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

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

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

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

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

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \color{blue}{\left(\mathsf{neg}\left(\sin \phi_1 \cdot \cos \phi_2\right)\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)}\right)} \]
      3. Applied rewrites79.1%

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

      Alternative 13: 78.1% accurate, 1.0× speedup?

      \[\begin{array}{l} \\ \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \end{array} \]
      (FPCore (lambda1 lambda2 phi1 phi2)
       :precision binary64
       (atan2
        (* (sin (- lambda1 lambda2)) (cos phi2))
        (-
         (* (cos phi1) (sin phi2))
         (* (* (sin phi1) (cos phi2)) (cos (- lambda1 lambda2))))))
      double code(double lambda1, double lambda2, double phi1, double phi2) {
      	return atan2((sin((lambda1 - lambda2)) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))));
      }
      
      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, lambda2, phi1, phi2)
      use fmin_fmax_functions
          real(8), intent (in) :: lambda1
          real(8), intent (in) :: lambda2
          real(8), intent (in) :: phi1
          real(8), intent (in) :: phi2
          code = atan2((sin((lambda1 - lambda2)) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))))
      end function
      
      public static double code(double lambda1, double lambda2, double phi1, double phi2) {
      	return Math.atan2((Math.sin((lambda1 - lambda2)) * Math.cos(phi2)), ((Math.cos(phi1) * Math.sin(phi2)) - ((Math.sin(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2)))));
      }
      
      def code(lambda1, lambda2, phi1, phi2):
      	return math.atan2((math.sin((lambda1 - lambda2)) * math.cos(phi2)), ((math.cos(phi1) * math.sin(phi2)) - ((math.sin(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2)))))
      
      function code(lambda1, lambda2, phi1, phi2)
      	return atan(Float64(sin(Float64(lambda1 - lambda2)) * cos(phi2)), Float64(Float64(cos(phi1) * sin(phi2)) - Float64(Float64(sin(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2)))))
      end
      
      function tmp = code(lambda1, lambda2, phi1, phi2)
      	tmp = atan2((sin((lambda1 - lambda2)) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))));
      end
      
      code[lambda1_, lambda2_, phi1_, phi2_] := N[ArcTan[N[(N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Sin[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)}
      \end{array}
      
      Derivation
      1. Initial program 79.1%

        \[\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      2. Add Preprocessing

      Alternative 14: 72.9% accurate, 0.8× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\\ t_1 := \cos \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\phi_2 \leq -9 \cdot 10^{+31}:\\ \;\;\;\;\tan^{-1}_* \frac{t\_0}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(-\cos \lambda_1\right) \cdot \left(\sin \phi_1 \cdot \cos \phi_2\right)\right)}\\ \mathbf{elif}\;\phi_2 \leq 2.2 \cdot 10^{+34}:\\ \;\;\;\;\tan^{-1}_* \frac{t\_0}{t\_1 - \sin \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1}_* \frac{t\_0}{t\_1 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1}\\ \end{array} \end{array} \]
      (FPCore (lambda1 lambda2 phi1 phi2)
       :precision binary64
       (let* ((t_0 (* (sin (- lambda1 lambda2)) (cos phi2)))
              (t_1 (* (cos phi1) (sin phi2))))
         (if (<= phi2 -9e+31)
           (atan2
            t_0
            (fma
             (sin phi2)
             (cos phi1)
             (* (- (cos lambda1)) (* (sin phi1) (cos phi2)))))
           (if (<= phi2 2.2e+34)
             (atan2 t_0 (- t_1 (* (sin phi1) (cos (- lambda1 lambda2)))))
             (atan2 t_0 (- t_1 (* (* (cos lambda1) (cos phi2)) (sin phi1))))))))
      double code(double lambda1, double lambda2, double phi1, double phi2) {
      	double t_0 = sin((lambda1 - lambda2)) * cos(phi2);
      	double t_1 = cos(phi1) * sin(phi2);
      	double tmp;
      	if (phi2 <= -9e+31) {
      		tmp = atan2(t_0, fma(sin(phi2), cos(phi1), (-cos(lambda1) * (sin(phi1) * cos(phi2)))));
      	} else if (phi2 <= 2.2e+34) {
      		tmp = atan2(t_0, (t_1 - (sin(phi1) * cos((lambda1 - lambda2)))));
      	} else {
      		tmp = atan2(t_0, (t_1 - ((cos(lambda1) * cos(phi2)) * sin(phi1))));
      	}
      	return tmp;
      }
      
      function code(lambda1, lambda2, phi1, phi2)
      	t_0 = Float64(sin(Float64(lambda1 - lambda2)) * cos(phi2))
      	t_1 = Float64(cos(phi1) * sin(phi2))
      	tmp = 0.0
      	if (phi2 <= -9e+31)
      		tmp = atan(t_0, fma(sin(phi2), cos(phi1), Float64(Float64(-cos(lambda1)) * Float64(sin(phi1) * cos(phi2)))));
      	elseif (phi2 <= 2.2e+34)
      		tmp = atan(t_0, Float64(t_1 - Float64(sin(phi1) * cos(Float64(lambda1 - lambda2)))));
      	else
      		tmp = atan(t_0, Float64(t_1 - Float64(Float64(cos(lambda1) * cos(phi2)) * sin(phi1))));
      	end
      	return tmp
      end
      
      code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -9e+31], N[ArcTan[t$95$0 / N[(N[Sin[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[((-N[Cos[lambda1], $MachinePrecision]) * N[(N[Sin[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[phi2, 2.2e+34], N[ArcTan[t$95$0 / N[(t$95$1 - N[(N[Sin[phi1], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[t$95$0 / N[(t$95$1 - N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := \sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\\
      t_1 := \cos \phi_1 \cdot \sin \phi_2\\
      \mathbf{if}\;\phi_2 \leq -9 \cdot 10^{+31}:\\
      \;\;\;\;\tan^{-1}_* \frac{t\_0}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(-\cos \lambda_1\right) \cdot \left(\sin \phi_1 \cdot \cos \phi_2\right)\right)}\\
      
      \mathbf{elif}\;\phi_2 \leq 2.2 \cdot 10^{+34}:\\
      \;\;\;\;\tan^{-1}_* \frac{t\_0}{t\_1 - \sin \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\
      
      \mathbf{else}:\\
      \;\;\;\;\tan^{-1}_* \frac{t\_0}{t\_1 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if phi2 < -8.9999999999999992e31

        1. Initial program 77.1%

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

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\cos \phi_1 \cdot \sin \phi_2 - \cos \lambda_1 \cdot \left(\cos \phi_2 \cdot \sin \phi_1\right)}} \]
        3. Step-by-step derivation
          1. fp-cancel-sub-sign-invN/A

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

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

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

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

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(\mathsf{neg}\left(\cos \lambda_1\right)\right) \cdot \left(\cos \phi_2 \cdot \sin \phi_1\right)\right)} \]
          6. mul-1-negN/A

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

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

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(-1 \cdot \cos \lambda_1\right) \cdot \left(\sin \phi_1 \cdot \cos \phi_2\right)\right)} \]
          9. mul-1-negN/A

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(\mathsf{neg}\left(\cos \lambda_1\right)\right) \cdot \left(\sin \phi_1 \cdot \cos \phi_2\right)\right)} \]
          10. lower-neg.f64N/A

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(-\cos \lambda_1\right) \cdot \left(\sin \phi_1 \cdot \cos \phi_2\right)\right)} \]
          11. lower-cos.f64N/A

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(-\cos \lambda_1\right) \cdot \left(\sin \phi_1 \cdot \cos \phi_2\right)\right)} \]
          12. lift-sin.f64N/A

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(-\cos \lambda_1\right) \cdot \left(\sin \phi_1 \cdot \cos \phi_2\right)\right)} \]
          13. lift-cos.f64N/A

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(-\cos \lambda_1\right) \cdot \left(\sin \phi_1 \cdot \cos \phi_2\right)\right)} \]
          14. lift-*.f6467.7

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(-\cos \lambda_1\right) \cdot \left(\sin \phi_1 \cdot \cos \phi_2\right)\right)} \]
        4. Applied rewrites67.7%

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

        if -8.9999999999999992e31 < phi2 < 2.2000000000000002e34

        1. Initial program 81.1%

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

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \color{blue}{\sin \phi_1} \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        3. Step-by-step derivation
          1. lift-sin.f6477.8

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \sin \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        4. Applied rewrites77.8%

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

        if 2.2000000000000002e34 < phi2

        1. Initial program 76.0%

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

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

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

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

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

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
          5. lift-cos.f64N/A

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
          6. lift-sin.f6465.7

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
        4. Applied rewrites65.7%

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

      Alternative 15: 72.9% accurate, 0.8× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\\ t_1 := \tan^{-1}_* \frac{t\_0}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(-\cos \lambda_1\right) \cdot \left(\sin \phi_1 \cdot \cos \phi_2\right)\right)}\\ \mathbf{if}\;\phi_2 \leq -9 \cdot 10^{+31}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\phi_2 \leq 2.2 \cdot 10^{+34}:\\ \;\;\;\;\tan^{-1}_* \frac{t\_0}{\cos \phi_1 \cdot \sin \phi_2 - \sin \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
      (FPCore (lambda1 lambda2 phi1 phi2)
       :precision binary64
       (let* ((t_0 (* (sin (- lambda1 lambda2)) (cos phi2)))
              (t_1
               (atan2
                t_0
                (fma
                 (sin phi2)
                 (cos phi1)
                 (* (- (cos lambda1)) (* (sin phi1) (cos phi2)))))))
         (if (<= phi2 -9e+31)
           t_1
           (if (<= phi2 2.2e+34)
             (atan2
              t_0
              (- (* (cos phi1) (sin phi2)) (* (sin phi1) (cos (- lambda1 lambda2)))))
             t_1))))
      double code(double lambda1, double lambda2, double phi1, double phi2) {
      	double t_0 = sin((lambda1 - lambda2)) * cos(phi2);
      	double t_1 = atan2(t_0, fma(sin(phi2), cos(phi1), (-cos(lambda1) * (sin(phi1) * cos(phi2)))));
      	double tmp;
      	if (phi2 <= -9e+31) {
      		tmp = t_1;
      	} else if (phi2 <= 2.2e+34) {
      		tmp = atan2(t_0, ((cos(phi1) * sin(phi2)) - (sin(phi1) * cos((lambda1 - lambda2)))));
      	} else {
      		tmp = t_1;
      	}
      	return tmp;
      }
      
      function code(lambda1, lambda2, phi1, phi2)
      	t_0 = Float64(sin(Float64(lambda1 - lambda2)) * cos(phi2))
      	t_1 = atan(t_0, fma(sin(phi2), cos(phi1), Float64(Float64(-cos(lambda1)) * Float64(sin(phi1) * cos(phi2)))))
      	tmp = 0.0
      	if (phi2 <= -9e+31)
      		tmp = t_1;
      	elseif (phi2 <= 2.2e+34)
      		tmp = atan(t_0, Float64(Float64(cos(phi1) * sin(phi2)) - Float64(sin(phi1) * cos(Float64(lambda1 - lambda2)))));
      	else
      		tmp = t_1;
      	end
      	return tmp
      end
      
      code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[ArcTan[t$95$0 / N[(N[Sin[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[((-N[Cos[lambda1], $MachinePrecision]) * N[(N[Sin[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -9e+31], t$95$1, If[LessEqual[phi2, 2.2e+34], N[ArcTan[t$95$0 / N[(N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[phi1], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$1]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := \sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\\
      t_1 := \tan^{-1}_* \frac{t\_0}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(-\cos \lambda_1\right) \cdot \left(\sin \phi_1 \cdot \cos \phi_2\right)\right)}\\
      \mathbf{if}\;\phi_2 \leq -9 \cdot 10^{+31}:\\
      \;\;\;\;t\_1\\
      
      \mathbf{elif}\;\phi_2 \leq 2.2 \cdot 10^{+34}:\\
      \;\;\;\;\tan^{-1}_* \frac{t\_0}{\cos \phi_1 \cdot \sin \phi_2 - \sin \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_1\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if phi2 < -8.9999999999999992e31 or 2.2000000000000002e34 < phi2

        1. Initial program 76.5%

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

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\cos \phi_1 \cdot \sin \phi_2 - \cos \lambda_1 \cdot \left(\cos \phi_2 \cdot \sin \phi_1\right)}} \]
        3. Step-by-step derivation
          1. fp-cancel-sub-sign-invN/A

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

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

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

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

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(\mathsf{neg}\left(\cos \lambda_1\right)\right) \cdot \left(\cos \phi_2 \cdot \sin \phi_1\right)\right)} \]
          6. mul-1-negN/A

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

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

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(-1 \cdot \cos \lambda_1\right) \cdot \left(\sin \phi_1 \cdot \cos \phi_2\right)\right)} \]
          9. mul-1-negN/A

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(\mathsf{neg}\left(\cos \lambda_1\right)\right) \cdot \left(\sin \phi_1 \cdot \cos \phi_2\right)\right)} \]
          10. lower-neg.f64N/A

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(-\cos \lambda_1\right) \cdot \left(\sin \phi_1 \cdot \cos \phi_2\right)\right)} \]
          11. lower-cos.f64N/A

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(-\cos \lambda_1\right) \cdot \left(\sin \phi_1 \cdot \cos \phi_2\right)\right)} \]
          12. lift-sin.f64N/A

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(-\cos \lambda_1\right) \cdot \left(\sin \phi_1 \cdot \cos \phi_2\right)\right)} \]
          13. lift-cos.f64N/A

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(-\cos \lambda_1\right) \cdot \left(\sin \phi_1 \cdot \cos \phi_2\right)\right)} \]
          14. lift-*.f6466.7

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\mathsf{fma}\left(\sin \phi_2, \cos \phi_1, \left(-\cos \lambda_1\right) \cdot \left(\sin \phi_1 \cdot \cos \phi_2\right)\right)} \]
        4. Applied rewrites66.7%

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

        if -8.9999999999999992e31 < phi2 < 2.2000000000000002e34

        1. Initial program 81.1%

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

          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \color{blue}{\sin \phi_1} \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        3. Step-by-step derivation
          1. lift-sin.f6477.8

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \sin \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        4. Applied rewrites77.8%

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

      Alternative 16: 70.3% accurate, 0.8× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_1 := \cos \phi_1 \cdot \sin \phi_2\\ t_2 := \tan^{-1}_* \frac{\sin \lambda_1 \cdot \cos \phi_2}{t\_1 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot t\_0}\\ \mathbf{if}\;\lambda_1 \leq -0.0044:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;\lambda_1 \leq 8.2 \cdot 10^{+53}:\\ \;\;\;\;\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{t\_1 - \sin \phi_1 \cdot t\_0}\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
      (FPCore (lambda1 lambda2 phi1 phi2)
       :precision binary64
       (let* ((t_0 (cos (- lambda1 lambda2)))
              (t_1 (* (cos phi1) (sin phi2)))
              (t_2
               (atan2
                (* (sin lambda1) (cos phi2))
                (- t_1 (* (* (sin phi1) (cos phi2)) t_0)))))
         (if (<= lambda1 -0.0044)
           t_2
           (if (<= lambda1 8.2e+53)
             (atan2
              (* (sin (- lambda1 lambda2)) (cos phi2))
              (- t_1 (* (sin phi1) t_0)))
             t_2))))
      double code(double lambda1, double lambda2, double phi1, double phi2) {
      	double t_0 = cos((lambda1 - lambda2));
      	double t_1 = cos(phi1) * sin(phi2);
      	double t_2 = atan2((sin(lambda1) * cos(phi2)), (t_1 - ((sin(phi1) * cos(phi2)) * t_0)));
      	double tmp;
      	if (lambda1 <= -0.0044) {
      		tmp = t_2;
      	} else if (lambda1 <= 8.2e+53) {
      		tmp = atan2((sin((lambda1 - lambda2)) * cos(phi2)), (t_1 - (sin(phi1) * t_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, lambda2, phi1, phi2)
      use fmin_fmax_functions
          real(8), intent (in) :: lambda1
          real(8), intent (in) :: lambda2
          real(8), intent (in) :: phi1
          real(8), intent (in) :: phi2
          real(8) :: t_0
          real(8) :: t_1
          real(8) :: t_2
          real(8) :: tmp
          t_0 = cos((lambda1 - lambda2))
          t_1 = cos(phi1) * sin(phi2)
          t_2 = atan2((sin(lambda1) * cos(phi2)), (t_1 - ((sin(phi1) * cos(phi2)) * t_0)))
          if (lambda1 <= (-0.0044d0)) then
              tmp = t_2
          else if (lambda1 <= 8.2d+53) then
              tmp = atan2((sin((lambda1 - lambda2)) * cos(phi2)), (t_1 - (sin(phi1) * t_0)))
          else
              tmp = t_2
          end if
          code = tmp
      end function
      
      public static double code(double lambda1, double lambda2, double phi1, double phi2) {
      	double t_0 = Math.cos((lambda1 - lambda2));
      	double t_1 = Math.cos(phi1) * Math.sin(phi2);
      	double t_2 = Math.atan2((Math.sin(lambda1) * Math.cos(phi2)), (t_1 - ((Math.sin(phi1) * Math.cos(phi2)) * t_0)));
      	double tmp;
      	if (lambda1 <= -0.0044) {
      		tmp = t_2;
      	} else if (lambda1 <= 8.2e+53) {
      		tmp = Math.atan2((Math.sin((lambda1 - lambda2)) * Math.cos(phi2)), (t_1 - (Math.sin(phi1) * t_0)));
      	} else {
      		tmp = t_2;
      	}
      	return tmp;
      }
      
      def code(lambda1, lambda2, phi1, phi2):
      	t_0 = math.cos((lambda1 - lambda2))
      	t_1 = math.cos(phi1) * math.sin(phi2)
      	t_2 = math.atan2((math.sin(lambda1) * math.cos(phi2)), (t_1 - ((math.sin(phi1) * math.cos(phi2)) * t_0)))
      	tmp = 0
      	if lambda1 <= -0.0044:
      		tmp = t_2
      	elif lambda1 <= 8.2e+53:
      		tmp = math.atan2((math.sin((lambda1 - lambda2)) * math.cos(phi2)), (t_1 - (math.sin(phi1) * t_0)))
      	else:
      		tmp = t_2
      	return tmp
      
      function code(lambda1, lambda2, phi1, phi2)
      	t_0 = cos(Float64(lambda1 - lambda2))
      	t_1 = Float64(cos(phi1) * sin(phi2))
      	t_2 = atan(Float64(sin(lambda1) * cos(phi2)), Float64(t_1 - Float64(Float64(sin(phi1) * cos(phi2)) * t_0)))
      	tmp = 0.0
      	if (lambda1 <= -0.0044)
      		tmp = t_2;
      	elseif (lambda1 <= 8.2e+53)
      		tmp = atan(Float64(sin(Float64(lambda1 - lambda2)) * cos(phi2)), Float64(t_1 - Float64(sin(phi1) * t_0)));
      	else
      		tmp = t_2;
      	end
      	return tmp
      end
      
      function tmp_2 = code(lambda1, lambda2, phi1, phi2)
      	t_0 = cos((lambda1 - lambda2));
      	t_1 = cos(phi1) * sin(phi2);
      	t_2 = atan2((sin(lambda1) * cos(phi2)), (t_1 - ((sin(phi1) * cos(phi2)) * t_0)));
      	tmp = 0.0;
      	if (lambda1 <= -0.0044)
      		tmp = t_2;
      	elseif (lambda1 <= 8.2e+53)
      		tmp = atan2((sin((lambda1 - lambda2)) * cos(phi2)), (t_1 - (sin(phi1) * t_0)));
      	else
      		tmp = t_2;
      	end
      	tmp_2 = tmp;
      end
      
      code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[ArcTan[N[(N[Sin[lambda1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(t$95$1 - N[(N[(N[Sin[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[lambda1, -0.0044], t$95$2, If[LessEqual[lambda1, 8.2e+53], N[ArcTan[N[(N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(t$95$1 - N[(N[Sin[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$2]]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
      t_1 := \cos \phi_1 \cdot \sin \phi_2\\
      t_2 := \tan^{-1}_* \frac{\sin \lambda_1 \cdot \cos \phi_2}{t\_1 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot t\_0}\\
      \mathbf{if}\;\lambda_1 \leq -0.0044:\\
      \;\;\;\;t\_2\\
      
      \mathbf{elif}\;\lambda_1 \leq 8.2 \cdot 10^{+53}:\\
      \;\;\;\;\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{t\_1 - \sin \phi_1 \cdot t\_0}\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_2\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if lambda1 < -0.00440000000000000027 or 8.20000000000000037e53 < lambda1

        1. Initial program 59.1%

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

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

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

          if -0.00440000000000000027 < lambda1 < 8.20000000000000037e53

          1. Initial program 95.9%

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

            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \color{blue}{\sin \phi_1} \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          3. Step-by-step derivation
            1. lift-sin.f6479.5

              \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \sin \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          4. Applied rewrites79.5%

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

        Alternative 17: 70.3% accurate, 0.8× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \phi_1 \cdot \sin \phi_2\\ t_1 := \tan^{-1}_* \frac{\sin \lambda_1 \cdot \cos \phi_2}{t\_0 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1}\\ \mathbf{if}\;\lambda_1 \leq -0.0044:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\lambda_1 \leq 8.2 \cdot 10^{+53}:\\ \;\;\;\;\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{t\_0 - \sin \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
        (FPCore (lambda1 lambda2 phi1 phi2)
         :precision binary64
         (let* ((t_0 (* (cos phi1) (sin phi2)))
                (t_1
                 (atan2
                  (* (sin lambda1) (cos phi2))
                  (- t_0 (* (* (cos lambda1) (cos phi2)) (sin phi1))))))
           (if (<= lambda1 -0.0044)
             t_1
             (if (<= lambda1 8.2e+53)
               (atan2
                (* (sin (- lambda1 lambda2)) (cos phi2))
                (- t_0 (* (sin phi1) (cos (- lambda1 lambda2)))))
               t_1))))
        double code(double lambda1, double lambda2, double phi1, double phi2) {
        	double t_0 = cos(phi1) * sin(phi2);
        	double t_1 = atan2((sin(lambda1) * cos(phi2)), (t_0 - ((cos(lambda1) * cos(phi2)) * sin(phi1))));
        	double tmp;
        	if (lambda1 <= -0.0044) {
        		tmp = t_1;
        	} else if (lambda1 <= 8.2e+53) {
        		tmp = atan2((sin((lambda1 - lambda2)) * cos(phi2)), (t_0 - (sin(phi1) * cos((lambda1 - lambda2)))));
        	} 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, lambda2, phi1, phi2)
        use fmin_fmax_functions
            real(8), intent (in) :: lambda1
            real(8), intent (in) :: lambda2
            real(8), intent (in) :: phi1
            real(8), intent (in) :: phi2
            real(8) :: t_0
            real(8) :: t_1
            real(8) :: tmp
            t_0 = cos(phi1) * sin(phi2)
            t_1 = atan2((sin(lambda1) * cos(phi2)), (t_0 - ((cos(lambda1) * cos(phi2)) * sin(phi1))))
            if (lambda1 <= (-0.0044d0)) then
                tmp = t_1
            else if (lambda1 <= 8.2d+53) then
                tmp = atan2((sin((lambda1 - lambda2)) * cos(phi2)), (t_0 - (sin(phi1) * cos((lambda1 - lambda2)))))
            else
                tmp = t_1
            end if
            code = tmp
        end function
        
        public static double code(double lambda1, double lambda2, double phi1, double phi2) {
        	double t_0 = Math.cos(phi1) * Math.sin(phi2);
        	double t_1 = Math.atan2((Math.sin(lambda1) * Math.cos(phi2)), (t_0 - ((Math.cos(lambda1) * Math.cos(phi2)) * Math.sin(phi1))));
        	double tmp;
        	if (lambda1 <= -0.0044) {
        		tmp = t_1;
        	} else if (lambda1 <= 8.2e+53) {
        		tmp = Math.atan2((Math.sin((lambda1 - lambda2)) * Math.cos(phi2)), (t_0 - (Math.sin(phi1) * Math.cos((lambda1 - lambda2)))));
        	} else {
        		tmp = t_1;
        	}
        	return tmp;
        }
        
        def code(lambda1, lambda2, phi1, phi2):
        	t_0 = math.cos(phi1) * math.sin(phi2)
        	t_1 = math.atan2((math.sin(lambda1) * math.cos(phi2)), (t_0 - ((math.cos(lambda1) * math.cos(phi2)) * math.sin(phi1))))
        	tmp = 0
        	if lambda1 <= -0.0044:
        		tmp = t_1
        	elif lambda1 <= 8.2e+53:
        		tmp = math.atan2((math.sin((lambda1 - lambda2)) * math.cos(phi2)), (t_0 - (math.sin(phi1) * math.cos((lambda1 - lambda2)))))
        	else:
        		tmp = t_1
        	return tmp
        
        function code(lambda1, lambda2, phi1, phi2)
        	t_0 = Float64(cos(phi1) * sin(phi2))
        	t_1 = atan(Float64(sin(lambda1) * cos(phi2)), Float64(t_0 - Float64(Float64(cos(lambda1) * cos(phi2)) * sin(phi1))))
        	tmp = 0.0
        	if (lambda1 <= -0.0044)
        		tmp = t_1;
        	elseif (lambda1 <= 8.2e+53)
        		tmp = atan(Float64(sin(Float64(lambda1 - lambda2)) * cos(phi2)), Float64(t_0 - Float64(sin(phi1) * cos(Float64(lambda1 - lambda2)))));
        	else
        		tmp = t_1;
        	end
        	return tmp
        end
        
        function tmp_2 = code(lambda1, lambda2, phi1, phi2)
        	t_0 = cos(phi1) * sin(phi2);
        	t_1 = atan2((sin(lambda1) * cos(phi2)), (t_0 - ((cos(lambda1) * cos(phi2)) * sin(phi1))));
        	tmp = 0.0;
        	if (lambda1 <= -0.0044)
        		tmp = t_1;
        	elseif (lambda1 <= 8.2e+53)
        		tmp = atan2((sin((lambda1 - lambda2)) * cos(phi2)), (t_0 - (sin(phi1) * cos((lambda1 - lambda2)))));
        	else
        		tmp = t_1;
        	end
        	tmp_2 = tmp;
        end
        
        code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[ArcTan[N[(N[Sin[lambda1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(t$95$0 - N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[lambda1, -0.0044], t$95$1, If[LessEqual[lambda1, 8.2e+53], N[ArcTan[N[(N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(t$95$0 - N[(N[Sin[phi1], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$1]]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_0 := \cos \phi_1 \cdot \sin \phi_2\\
        t_1 := \tan^{-1}_* \frac{\sin \lambda_1 \cdot \cos \phi_2}{t\_0 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1}\\
        \mathbf{if}\;\lambda_1 \leq -0.0044:\\
        \;\;\;\;t\_1\\
        
        \mathbf{elif}\;\lambda_1 \leq 8.2 \cdot 10^{+53}:\\
        \;\;\;\;\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{t\_0 - \sin \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_1\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if lambda1 < -0.00440000000000000027 or 8.20000000000000037e53 < lambda1

          1. Initial program 59.1%

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

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

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

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

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

              \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
            5. lift-cos.f64N/A

              \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
            6. lift-sin.f6459.1

              \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
          4. Applied rewrites59.1%

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

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

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

            if -0.00440000000000000027 < lambda1 < 8.20000000000000037e53

            1. Initial program 95.9%

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

              \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \color{blue}{\sin \phi_1} \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
            3. Step-by-step derivation
              1. lift-sin.f6479.5

                \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \sin \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
            4. Applied rewrites79.5%

              \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \color{blue}{\sin \phi_1} \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          7. Recombined 2 regimes into one program.
          8. Add Preprocessing

          Alternative 18: 70.1% accurate, 0.8× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan^{-1}_* \frac{\sin \lambda_1 \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1}\\ \mathbf{if}\;\lambda_1 \leq -0.008:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\lambda_1 \leq 7.5 \cdot 10^{+41}:\\ \;\;\;\;\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
          (FPCore (lambda1 lambda2 phi1 phi2)
           :precision binary64
           (let* ((t_0
                   (atan2
                    (* (sin lambda1) (cos phi2))
                    (-
                     (* (cos phi1) (sin phi2))
                     (* (* (cos lambda1) (cos phi2)) (sin phi1))))))
             (if (<= lambda1 -0.008)
               t_0
               (if (<= lambda1 7.5e+41)
                 (atan2
                  (* (sin (- lambda1 lambda2)) (cos phi2))
                  (- (sin phi2) (* (* (sin phi1) (cos phi2)) (cos (- lambda1 lambda2)))))
                 t_0))))
          double code(double lambda1, double lambda2, double phi1, double phi2) {
          	double t_0 = atan2((sin(lambda1) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((cos(lambda1) * cos(phi2)) * sin(phi1))));
          	double tmp;
          	if (lambda1 <= -0.008) {
          		tmp = t_0;
          	} else if (lambda1 <= 7.5e+41) {
          		tmp = atan2((sin((lambda1 - lambda2)) * cos(phi2)), (sin(phi2) - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))));
          	} else {
          		tmp = t_0;
          	}
          	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, lambda2, phi1, phi2)
          use fmin_fmax_functions
              real(8), intent (in) :: lambda1
              real(8), intent (in) :: lambda2
              real(8), intent (in) :: phi1
              real(8), intent (in) :: phi2
              real(8) :: t_0
              real(8) :: tmp
              t_0 = atan2((sin(lambda1) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((cos(lambda1) * cos(phi2)) * sin(phi1))))
              if (lambda1 <= (-0.008d0)) then
                  tmp = t_0
              else if (lambda1 <= 7.5d+41) then
                  tmp = atan2((sin((lambda1 - lambda2)) * cos(phi2)), (sin(phi2) - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))))
              else
                  tmp = t_0
              end if
              code = tmp
          end function
          
          public static double code(double lambda1, double lambda2, double phi1, double phi2) {
          	double t_0 = Math.atan2((Math.sin(lambda1) * Math.cos(phi2)), ((Math.cos(phi1) * Math.sin(phi2)) - ((Math.cos(lambda1) * Math.cos(phi2)) * Math.sin(phi1))));
          	double tmp;
          	if (lambda1 <= -0.008) {
          		tmp = t_0;
          	} else if (lambda1 <= 7.5e+41) {
          		tmp = Math.atan2((Math.sin((lambda1 - lambda2)) * Math.cos(phi2)), (Math.sin(phi2) - ((Math.sin(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2)))));
          	} else {
          		tmp = t_0;
          	}
          	return tmp;
          }
          
          def code(lambda1, lambda2, phi1, phi2):
          	t_0 = math.atan2((math.sin(lambda1) * math.cos(phi2)), ((math.cos(phi1) * math.sin(phi2)) - ((math.cos(lambda1) * math.cos(phi2)) * math.sin(phi1))))
          	tmp = 0
          	if lambda1 <= -0.008:
          		tmp = t_0
          	elif lambda1 <= 7.5e+41:
          		tmp = math.atan2((math.sin((lambda1 - lambda2)) * math.cos(phi2)), (math.sin(phi2) - ((math.sin(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2)))))
          	else:
          		tmp = t_0
          	return tmp
          
          function code(lambda1, lambda2, phi1, phi2)
          	t_0 = atan(Float64(sin(lambda1) * cos(phi2)), Float64(Float64(cos(phi1) * sin(phi2)) - Float64(Float64(cos(lambda1) * cos(phi2)) * sin(phi1))))
          	tmp = 0.0
          	if (lambda1 <= -0.008)
          		tmp = t_0;
          	elseif (lambda1 <= 7.5e+41)
          		tmp = atan(Float64(sin(Float64(lambda1 - lambda2)) * cos(phi2)), Float64(sin(phi2) - Float64(Float64(sin(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2)))));
          	else
          		tmp = t_0;
          	end
          	return tmp
          end
          
          function tmp_2 = code(lambda1, lambda2, phi1, phi2)
          	t_0 = atan2((sin(lambda1) * cos(phi2)), ((cos(phi1) * sin(phi2)) - ((cos(lambda1) * cos(phi2)) * sin(phi1))));
          	tmp = 0.0;
          	if (lambda1 <= -0.008)
          		tmp = t_0;
          	elseif (lambda1 <= 7.5e+41)
          		tmp = atan2((sin((lambda1 - lambda2)) * cos(phi2)), (sin(phi2) - ((sin(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))));
          	else
          		tmp = t_0;
          	end
          	tmp_2 = tmp;
          end
          
          code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[ArcTan[N[(N[Sin[lambda1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[lambda1, -0.008], t$95$0, If[LessEqual[lambda1, 7.5e+41], N[ArcTan[N[(N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(N[Sin[phi2], $MachinePrecision] - N[(N[(N[Sin[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$0]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          t_0 := \tan^{-1}_* \frac{\sin \lambda_1 \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1}\\
          \mathbf{if}\;\lambda_1 \leq -0.008:\\
          \;\;\;\;t\_0\\
          
          \mathbf{elif}\;\lambda_1 \leq 7.5 \cdot 10^{+41}:\\
          \;\;\;\;\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\
          
          \mathbf{else}:\\
          \;\;\;\;t\_0\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if lambda1 < -0.0080000000000000002 or 7.50000000000000072e41 < lambda1

            1. Initial program 59.0%

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

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

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

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

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

                \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
              5. lift-cos.f64N/A

                \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
              6. lift-sin.f6459.0

                \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
            4. Applied rewrites59.0%

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

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

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

              if -0.0080000000000000002 < lambda1 < 7.50000000000000072e41

              1. Initial program 96.7%

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

                \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2} - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
              3. Step-by-step derivation
                1. lift-sin.f6479.7

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2 - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
              4. Applied rewrites79.7%

                \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2} - \left(\sin \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
            7. Recombined 2 regimes into one program.
            8. Add Preprocessing

            Alternative 19: 69.3% accurate, 0.9× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \phi_1 \cdot \sin \phi_2\\ t_1 := \tan^{-1}_* \frac{\sin \lambda_1 \cdot \cos \phi_2}{t\_0 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1}\\ \mathbf{if}\;\lambda_1 \leq -0.00105:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\lambda_1 \leq 7.5 \cdot 10^{+41}:\\ \;\;\;\;\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{t\_0 - \cos \phi_2 \cdot \sin \phi_1}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
            (FPCore (lambda1 lambda2 phi1 phi2)
             :precision binary64
             (let* ((t_0 (* (cos phi1) (sin phi2)))
                    (t_1
                     (atan2
                      (* (sin lambda1) (cos phi2))
                      (- t_0 (* (* (cos lambda1) (cos phi2)) (sin phi1))))))
               (if (<= lambda1 -0.00105)
                 t_1
                 (if (<= lambda1 7.5e+41)
                   (atan2
                    (* (sin (- lambda1 lambda2)) (cos phi2))
                    (- t_0 (* (cos phi2) (sin phi1))))
                   t_1))))
            double code(double lambda1, double lambda2, double phi1, double phi2) {
            	double t_0 = cos(phi1) * sin(phi2);
            	double t_1 = atan2((sin(lambda1) * cos(phi2)), (t_0 - ((cos(lambda1) * cos(phi2)) * sin(phi1))));
            	double tmp;
            	if (lambda1 <= -0.00105) {
            		tmp = t_1;
            	} else if (lambda1 <= 7.5e+41) {
            		tmp = atan2((sin((lambda1 - lambda2)) * cos(phi2)), (t_0 - (cos(phi2) * sin(phi1))));
            	} 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, lambda2, phi1, phi2)
            use fmin_fmax_functions
                real(8), intent (in) :: lambda1
                real(8), intent (in) :: lambda2
                real(8), intent (in) :: phi1
                real(8), intent (in) :: phi2
                real(8) :: t_0
                real(8) :: t_1
                real(8) :: tmp
                t_0 = cos(phi1) * sin(phi2)
                t_1 = atan2((sin(lambda1) * cos(phi2)), (t_0 - ((cos(lambda1) * cos(phi2)) * sin(phi1))))
                if (lambda1 <= (-0.00105d0)) then
                    tmp = t_1
                else if (lambda1 <= 7.5d+41) then
                    tmp = atan2((sin((lambda1 - lambda2)) * cos(phi2)), (t_0 - (cos(phi2) * sin(phi1))))
                else
                    tmp = t_1
                end if
                code = tmp
            end function
            
            public static double code(double lambda1, double lambda2, double phi1, double phi2) {
            	double t_0 = Math.cos(phi1) * Math.sin(phi2);
            	double t_1 = Math.atan2((Math.sin(lambda1) * Math.cos(phi2)), (t_0 - ((Math.cos(lambda1) * Math.cos(phi2)) * Math.sin(phi1))));
            	double tmp;
            	if (lambda1 <= -0.00105) {
            		tmp = t_1;
            	} else if (lambda1 <= 7.5e+41) {
            		tmp = Math.atan2((Math.sin((lambda1 - lambda2)) * Math.cos(phi2)), (t_0 - (Math.cos(phi2) * Math.sin(phi1))));
            	} else {
            		tmp = t_1;
            	}
            	return tmp;
            }
            
            def code(lambda1, lambda2, phi1, phi2):
            	t_0 = math.cos(phi1) * math.sin(phi2)
            	t_1 = math.atan2((math.sin(lambda1) * math.cos(phi2)), (t_0 - ((math.cos(lambda1) * math.cos(phi2)) * math.sin(phi1))))
            	tmp = 0
            	if lambda1 <= -0.00105:
            		tmp = t_1
            	elif lambda1 <= 7.5e+41:
            		tmp = math.atan2((math.sin((lambda1 - lambda2)) * math.cos(phi2)), (t_0 - (math.cos(phi2) * math.sin(phi1))))
            	else:
            		tmp = t_1
            	return tmp
            
            function code(lambda1, lambda2, phi1, phi2)
            	t_0 = Float64(cos(phi1) * sin(phi2))
            	t_1 = atan(Float64(sin(lambda1) * cos(phi2)), Float64(t_0 - Float64(Float64(cos(lambda1) * cos(phi2)) * sin(phi1))))
            	tmp = 0.0
            	if (lambda1 <= -0.00105)
            		tmp = t_1;
            	elseif (lambda1 <= 7.5e+41)
            		tmp = atan(Float64(sin(Float64(lambda1 - lambda2)) * cos(phi2)), Float64(t_0 - Float64(cos(phi2) * sin(phi1))));
            	else
            		tmp = t_1;
            	end
            	return tmp
            end
            
            function tmp_2 = code(lambda1, lambda2, phi1, phi2)
            	t_0 = cos(phi1) * sin(phi2);
            	t_1 = atan2((sin(lambda1) * cos(phi2)), (t_0 - ((cos(lambda1) * cos(phi2)) * sin(phi1))));
            	tmp = 0.0;
            	if (lambda1 <= -0.00105)
            		tmp = t_1;
            	elseif (lambda1 <= 7.5e+41)
            		tmp = atan2((sin((lambda1 - lambda2)) * cos(phi2)), (t_0 - (cos(phi2) * sin(phi1))));
            	else
            		tmp = t_1;
            	end
            	tmp_2 = tmp;
            end
            
            code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[ArcTan[N[(N[Sin[lambda1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(t$95$0 - N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[lambda1, -0.00105], t$95$1, If[LessEqual[lambda1, 7.5e+41], N[ArcTan[N[(N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(t$95$0 - N[(N[Cos[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$1]]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            t_0 := \cos \phi_1 \cdot \sin \phi_2\\
            t_1 := \tan^{-1}_* \frac{\sin \lambda_1 \cdot \cos \phi_2}{t\_0 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1}\\
            \mathbf{if}\;\lambda_1 \leq -0.00105:\\
            \;\;\;\;t\_1\\
            
            \mathbf{elif}\;\lambda_1 \leq 7.5 \cdot 10^{+41}:\\
            \;\;\;\;\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{t\_0 - \cos \phi_2 \cdot \sin \phi_1}\\
            
            \mathbf{else}:\\
            \;\;\;\;t\_1\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if lambda1 < -0.00104999999999999994 or 7.50000000000000072e41 < lambda1

              1. Initial program 59.1%

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

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

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

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

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

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                5. lift-cos.f64N/A

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                6. lift-sin.f6459.0

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
              4. Applied rewrites59.0%

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

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

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

                if -0.00104999999999999994 < lambda1 < 7.50000000000000072e41

                1. Initial program 96.7%

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

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

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

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

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

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                  5. lift-cos.f64N/A

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                  6. lift-sin.f6478.5

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                4. Applied rewrites78.5%

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

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \cos \phi_2 \cdot \sin \color{blue}{\phi_1}} \]
                6. Step-by-step derivation
                  1. lift-cos.f6477.1

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \cos \phi_2 \cdot \sin \phi_1} \]
                7. Applied rewrites77.1%

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \cos \phi_2 \cdot \sin \color{blue}{\phi_1}} \]
              7. Recombined 2 regimes into one program.
              8. Add Preprocessing

              Alternative 20: 68.8% accurate, 0.9× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\ t_1 := \tan^{-1}_* \frac{t\_0 \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \cos \phi_2 \cdot \sin \phi_1}\\ \mathbf{if}\;\phi_2 \leq -0.000105:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\phi_2 \leq 3.2 \cdot 10^{-9}:\\ \;\;\;\;\tan^{-1}_* \frac{t\_0 \cdot 1}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
              (FPCore (lambda1 lambda2 phi1 phi2)
               :precision binary64
               (let* ((t_0 (sin (- lambda1 lambda2)))
                      (t_1
                       (atan2
                        (* t_0 (cos phi2))
                        (- (* (cos phi1) (sin phi2)) (* (cos phi2) (sin phi1))))))
                 (if (<= phi2 -0.000105)
                   t_1
                   (if (<= phi2 3.2e-9)
                     (atan2
                      (* t_0 1.0)
                      (- (* (cos phi1) phi2) (* (cos (- lambda1 lambda2)) (sin phi1))))
                     t_1))))
              double code(double lambda1, double lambda2, double phi1, double phi2) {
              	double t_0 = sin((lambda1 - lambda2));
              	double t_1 = atan2((t_0 * cos(phi2)), ((cos(phi1) * sin(phi2)) - (cos(phi2) * sin(phi1))));
              	double tmp;
              	if (phi2 <= -0.000105) {
              		tmp = t_1;
              	} else if (phi2 <= 3.2e-9) {
              		tmp = atan2((t_0 * 1.0), ((cos(phi1) * phi2) - (cos((lambda1 - lambda2)) * sin(phi1))));
              	} 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, lambda2, phi1, phi2)
              use fmin_fmax_functions
                  real(8), intent (in) :: lambda1
                  real(8), intent (in) :: lambda2
                  real(8), intent (in) :: phi1
                  real(8), intent (in) :: phi2
                  real(8) :: t_0
                  real(8) :: t_1
                  real(8) :: tmp
                  t_0 = sin((lambda1 - lambda2))
                  t_1 = atan2((t_0 * cos(phi2)), ((cos(phi1) * sin(phi2)) - (cos(phi2) * sin(phi1))))
                  if (phi2 <= (-0.000105d0)) then
                      tmp = t_1
                  else if (phi2 <= 3.2d-9) then
                      tmp = atan2((t_0 * 1.0d0), ((cos(phi1) * phi2) - (cos((lambda1 - lambda2)) * sin(phi1))))
                  else
                      tmp = t_1
                  end if
                  code = tmp
              end function
              
              public static double code(double lambda1, double lambda2, double phi1, double phi2) {
              	double t_0 = Math.sin((lambda1 - lambda2));
              	double t_1 = Math.atan2((t_0 * Math.cos(phi2)), ((Math.cos(phi1) * Math.sin(phi2)) - (Math.cos(phi2) * Math.sin(phi1))));
              	double tmp;
              	if (phi2 <= -0.000105) {
              		tmp = t_1;
              	} else if (phi2 <= 3.2e-9) {
              		tmp = Math.atan2((t_0 * 1.0), ((Math.cos(phi1) * phi2) - (Math.cos((lambda1 - lambda2)) * Math.sin(phi1))));
              	} else {
              		tmp = t_1;
              	}
              	return tmp;
              }
              
              def code(lambda1, lambda2, phi1, phi2):
              	t_0 = math.sin((lambda1 - lambda2))
              	t_1 = math.atan2((t_0 * math.cos(phi2)), ((math.cos(phi1) * math.sin(phi2)) - (math.cos(phi2) * math.sin(phi1))))
              	tmp = 0
              	if phi2 <= -0.000105:
              		tmp = t_1
              	elif phi2 <= 3.2e-9:
              		tmp = math.atan2((t_0 * 1.0), ((math.cos(phi1) * phi2) - (math.cos((lambda1 - lambda2)) * math.sin(phi1))))
              	else:
              		tmp = t_1
              	return tmp
              
              function code(lambda1, lambda2, phi1, phi2)
              	t_0 = sin(Float64(lambda1 - lambda2))
              	t_1 = atan(Float64(t_0 * cos(phi2)), Float64(Float64(cos(phi1) * sin(phi2)) - Float64(cos(phi2) * sin(phi1))))
              	tmp = 0.0
              	if (phi2 <= -0.000105)
              		tmp = t_1;
              	elseif (phi2 <= 3.2e-9)
              		tmp = atan(Float64(t_0 * 1.0), Float64(Float64(cos(phi1) * phi2) - Float64(cos(Float64(lambda1 - lambda2)) * sin(phi1))));
              	else
              		tmp = t_1;
              	end
              	return tmp
              end
              
              function tmp_2 = code(lambda1, lambda2, phi1, phi2)
              	t_0 = sin((lambda1 - lambda2));
              	t_1 = atan2((t_0 * cos(phi2)), ((cos(phi1) * sin(phi2)) - (cos(phi2) * sin(phi1))));
              	tmp = 0.0;
              	if (phi2 <= -0.000105)
              		tmp = t_1;
              	elseif (phi2 <= 3.2e-9)
              		tmp = atan2((t_0 * 1.0), ((cos(phi1) * phi2) - (cos((lambda1 - lambda2)) * sin(phi1))));
              	else
              		tmp = t_1;
              	end
              	tmp_2 = tmp;
              end
              
              code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[ArcTan[N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -0.000105], t$95$1, If[LessEqual[phi2, 3.2e-9], N[ArcTan[N[(t$95$0 * 1.0), $MachinePrecision] / N[(N[(N[Cos[phi1], $MachinePrecision] * phi2), $MachinePrecision] - N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$1]]]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\
              t_1 := \tan^{-1}_* \frac{t\_0 \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \cos \phi_2 \cdot \sin \phi_1}\\
              \mathbf{if}\;\phi_2 \leq -0.000105:\\
              \;\;\;\;t\_1\\
              
              \mathbf{elif}\;\phi_2 \leq 3.2 \cdot 10^{-9}:\\
              \;\;\;\;\tan^{-1}_* \frac{t\_0 \cdot 1}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1}\\
              
              \mathbf{else}:\\
              \;\;\;\;t\_1\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if phi2 < -1.05e-4 or 3.20000000000000012e-9 < phi2

                1. Initial program 76.8%

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

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

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

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

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

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                  5. lift-cos.f64N/A

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                  6. lift-sin.f6466.9

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                4. Applied rewrites66.9%

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

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \cos \phi_2 \cdot \sin \color{blue}{\phi_1}} \]
                6. Step-by-step derivation
                  1. lift-cos.f6457.7

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \cos \phi_2 \cdot \sin \phi_1} \]
                7. Applied rewrites57.7%

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

                if -1.05e-4 < phi2 < 3.20000000000000012e-9

                1. Initial program 81.5%

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

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\phi_2 \cdot \cos \phi_1 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1}} \]
                3. Step-by-step derivation
                  1. lower--.f64N/A

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

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

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)} \cdot \sin \phi_1} \]
                  4. lift-cos.f64N/A

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

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\sin \phi_1}} \]
                  6. lift-cos.f64N/A

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \color{blue}{\phi_1}} \]
                  7. lift--.f64N/A

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                  8. lift-sin.f6481.4

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                4. Applied rewrites81.4%

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

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{1}}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                6. Step-by-step derivation
                  1. cos-neg-rev81.5

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot 1}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                  2. sin-+PI/281.5

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot 1}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                7. Applied rewrites81.5%

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

              Alternative 21: 65.6% accurate, 0.9× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\ t_1 := t\_0 \cdot \cos \phi_2\\ \mathbf{if}\;\phi_2 \leq -0.000105:\\ \;\;\;\;\tan^{-1}_* \frac{t\_1}{\cos \phi_1 \cdot \sin \phi_2 - \cos \lambda_1 \cdot \sin \phi_1}\\ \mathbf{elif}\;\phi_2 \leq 3.2 \cdot 10^{-9}:\\ \;\;\;\;\tan^{-1}_* \frac{t\_0 \cdot 1}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1}\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1}_* \frac{t\_1}{\sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1}\\ \end{array} \end{array} \]
              (FPCore (lambda1 lambda2 phi1 phi2)
               :precision binary64
               (let* ((t_0 (sin (- lambda1 lambda2))) (t_1 (* t_0 (cos phi2))))
                 (if (<= phi2 -0.000105)
                   (atan2 t_1 (- (* (cos phi1) (sin phi2)) (* (cos lambda1) (sin phi1))))
                   (if (<= phi2 3.2e-9)
                     (atan2
                      (* t_0 1.0)
                      (- (* (cos phi1) phi2) (* (cos (- lambda1 lambda2)) (sin phi1))))
                     (atan2
                      t_1
                      (- (sin phi2) (* (* (cos lambda1) (cos phi2)) (sin phi1))))))))
              double code(double lambda1, double lambda2, double phi1, double phi2) {
              	double t_0 = sin((lambda1 - lambda2));
              	double t_1 = t_0 * cos(phi2);
              	double tmp;
              	if (phi2 <= -0.000105) {
              		tmp = atan2(t_1, ((cos(phi1) * sin(phi2)) - (cos(lambda1) * sin(phi1))));
              	} else if (phi2 <= 3.2e-9) {
              		tmp = atan2((t_0 * 1.0), ((cos(phi1) * phi2) - (cos((lambda1 - lambda2)) * sin(phi1))));
              	} else {
              		tmp = atan2(t_1, (sin(phi2) - ((cos(lambda1) * cos(phi2)) * sin(phi1))));
              	}
              	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, lambda2, phi1, phi2)
              use fmin_fmax_functions
                  real(8), intent (in) :: lambda1
                  real(8), intent (in) :: lambda2
                  real(8), intent (in) :: phi1
                  real(8), intent (in) :: phi2
                  real(8) :: t_0
                  real(8) :: t_1
                  real(8) :: tmp
                  t_0 = sin((lambda1 - lambda2))
                  t_1 = t_0 * cos(phi2)
                  if (phi2 <= (-0.000105d0)) then
                      tmp = atan2(t_1, ((cos(phi1) * sin(phi2)) - (cos(lambda1) * sin(phi1))))
                  else if (phi2 <= 3.2d-9) then
                      tmp = atan2((t_0 * 1.0d0), ((cos(phi1) * phi2) - (cos((lambda1 - lambda2)) * sin(phi1))))
                  else
                      tmp = atan2(t_1, (sin(phi2) - ((cos(lambda1) * cos(phi2)) * sin(phi1))))
                  end if
                  code = tmp
              end function
              
              public static double code(double lambda1, double lambda2, double phi1, double phi2) {
              	double t_0 = Math.sin((lambda1 - lambda2));
              	double t_1 = t_0 * Math.cos(phi2);
              	double tmp;
              	if (phi2 <= -0.000105) {
              		tmp = Math.atan2(t_1, ((Math.cos(phi1) * Math.sin(phi2)) - (Math.cos(lambda1) * Math.sin(phi1))));
              	} else if (phi2 <= 3.2e-9) {
              		tmp = Math.atan2((t_0 * 1.0), ((Math.cos(phi1) * phi2) - (Math.cos((lambda1 - lambda2)) * Math.sin(phi1))));
              	} else {
              		tmp = Math.atan2(t_1, (Math.sin(phi2) - ((Math.cos(lambda1) * Math.cos(phi2)) * Math.sin(phi1))));
              	}
              	return tmp;
              }
              
              def code(lambda1, lambda2, phi1, phi2):
              	t_0 = math.sin((lambda1 - lambda2))
              	t_1 = t_0 * math.cos(phi2)
              	tmp = 0
              	if phi2 <= -0.000105:
              		tmp = math.atan2(t_1, ((math.cos(phi1) * math.sin(phi2)) - (math.cos(lambda1) * math.sin(phi1))))
              	elif phi2 <= 3.2e-9:
              		tmp = math.atan2((t_0 * 1.0), ((math.cos(phi1) * phi2) - (math.cos((lambda1 - lambda2)) * math.sin(phi1))))
              	else:
              		tmp = math.atan2(t_1, (math.sin(phi2) - ((math.cos(lambda1) * math.cos(phi2)) * math.sin(phi1))))
              	return tmp
              
              function code(lambda1, lambda2, phi1, phi2)
              	t_0 = sin(Float64(lambda1 - lambda2))
              	t_1 = Float64(t_0 * cos(phi2))
              	tmp = 0.0
              	if (phi2 <= -0.000105)
              		tmp = atan(t_1, Float64(Float64(cos(phi1) * sin(phi2)) - Float64(cos(lambda1) * sin(phi1))));
              	elseif (phi2 <= 3.2e-9)
              		tmp = atan(Float64(t_0 * 1.0), Float64(Float64(cos(phi1) * phi2) - Float64(cos(Float64(lambda1 - lambda2)) * sin(phi1))));
              	else
              		tmp = atan(t_1, Float64(sin(phi2) - Float64(Float64(cos(lambda1) * cos(phi2)) * sin(phi1))));
              	end
              	return tmp
              end
              
              function tmp_2 = code(lambda1, lambda2, phi1, phi2)
              	t_0 = sin((lambda1 - lambda2));
              	t_1 = t_0 * cos(phi2);
              	tmp = 0.0;
              	if (phi2 <= -0.000105)
              		tmp = atan2(t_1, ((cos(phi1) * sin(phi2)) - (cos(lambda1) * sin(phi1))));
              	elseif (phi2 <= 3.2e-9)
              		tmp = atan2((t_0 * 1.0), ((cos(phi1) * phi2) - (cos((lambda1 - lambda2)) * sin(phi1))));
              	else
              		tmp = atan2(t_1, (sin(phi2) - ((cos(lambda1) * cos(phi2)) * sin(phi1))));
              	end
              	tmp_2 = tmp;
              end
              
              code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -0.000105], N[ArcTan[t$95$1 / N[(N[(N[Cos[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[lambda1], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[phi2, 3.2e-9], N[ArcTan[N[(t$95$0 * 1.0), $MachinePrecision] / N[(N[(N[Cos[phi1], $MachinePrecision] * phi2), $MachinePrecision] - N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[t$95$1 / N[(N[Sin[phi2], $MachinePrecision] - N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\
              t_1 := t\_0 \cdot \cos \phi_2\\
              \mathbf{if}\;\phi_2 \leq -0.000105:\\
              \;\;\;\;\tan^{-1}_* \frac{t\_1}{\cos \phi_1 \cdot \sin \phi_2 - \cos \lambda_1 \cdot \sin \phi_1}\\
              
              \mathbf{elif}\;\phi_2 \leq 3.2 \cdot 10^{-9}:\\
              \;\;\;\;\tan^{-1}_* \frac{t\_0 \cdot 1}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1}\\
              
              \mathbf{else}:\\
              \;\;\;\;\tan^{-1}_* \frac{t\_1}{\sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1}\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 3 regimes
              2. if phi2 < -1.05e-4

                1. Initial program 77.2%

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

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

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

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

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

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                  5. lift-cos.f64N/A

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                  6. lift-sin.f6467.7

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                4. Applied rewrites67.7%

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

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \cos \lambda_1 \cdot \sin \color{blue}{\phi_1}} \]
                6. Step-by-step derivation
                  1. lift-cos.f6451.8

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \cos \lambda_1 \cdot \sin \phi_1} \]
                7. Applied rewrites51.8%

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

                if -1.05e-4 < phi2 < 3.20000000000000012e-9

                1. Initial program 81.5%

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

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\phi_2 \cdot \cos \phi_1 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1}} \]
                3. Step-by-step derivation
                  1. lower--.f64N/A

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

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

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)} \cdot \sin \phi_1} \]
                  4. lift-cos.f64N/A

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

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\sin \phi_1}} \]
                  6. lift-cos.f64N/A

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \color{blue}{\phi_1}} \]
                  7. lift--.f64N/A

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                  8. lift-sin.f6481.4

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                4. Applied rewrites81.4%

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

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{1}}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                6. Step-by-step derivation
                  1. cos-neg-rev81.5

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot 1}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                  2. sin-+PI/281.5

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot 1}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                7. Applied rewrites81.5%

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

                if 3.20000000000000012e-9 < phi2

                1. Initial program 76.4%

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

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

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

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

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

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                  5. lift-cos.f64N/A

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                  6. lift-sin.f6466.0

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                4. Applied rewrites66.0%

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

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2} - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                6. Step-by-step derivation
                  1. lift-sin.f6449.3

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                7. Applied rewrites49.3%

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

              Alternative 22: 65.5% accurate, 0.9× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\ t_1 := \tan^{-1}_* \frac{t\_0 \cdot \cos \phi_2}{\sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1}\\ \mathbf{if}\;\phi_2 \leq -0.000105:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\phi_2 \leq 3.2 \cdot 10^{-9}:\\ \;\;\;\;\tan^{-1}_* \frac{t\_0 \cdot 1}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
              (FPCore (lambda1 lambda2 phi1 phi2)
               :precision binary64
               (let* ((t_0 (sin (- lambda1 lambda2)))
                      (t_1
                       (atan2
                        (* t_0 (cos phi2))
                        (- (sin phi2) (* (* (cos lambda1) (cos phi2)) (sin phi1))))))
                 (if (<= phi2 -0.000105)
                   t_1
                   (if (<= phi2 3.2e-9)
                     (atan2
                      (* t_0 1.0)
                      (- (* (cos phi1) phi2) (* (cos (- lambda1 lambda2)) (sin phi1))))
                     t_1))))
              double code(double lambda1, double lambda2, double phi1, double phi2) {
              	double t_0 = sin((lambda1 - lambda2));
              	double t_1 = atan2((t_0 * cos(phi2)), (sin(phi2) - ((cos(lambda1) * cos(phi2)) * sin(phi1))));
              	double tmp;
              	if (phi2 <= -0.000105) {
              		tmp = t_1;
              	} else if (phi2 <= 3.2e-9) {
              		tmp = atan2((t_0 * 1.0), ((cos(phi1) * phi2) - (cos((lambda1 - lambda2)) * sin(phi1))));
              	} 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, lambda2, phi1, phi2)
              use fmin_fmax_functions
                  real(8), intent (in) :: lambda1
                  real(8), intent (in) :: lambda2
                  real(8), intent (in) :: phi1
                  real(8), intent (in) :: phi2
                  real(8) :: t_0
                  real(8) :: t_1
                  real(8) :: tmp
                  t_0 = sin((lambda1 - lambda2))
                  t_1 = atan2((t_0 * cos(phi2)), (sin(phi2) - ((cos(lambda1) * cos(phi2)) * sin(phi1))))
                  if (phi2 <= (-0.000105d0)) then
                      tmp = t_1
                  else if (phi2 <= 3.2d-9) then
                      tmp = atan2((t_0 * 1.0d0), ((cos(phi1) * phi2) - (cos((lambda1 - lambda2)) * sin(phi1))))
                  else
                      tmp = t_1
                  end if
                  code = tmp
              end function
              
              public static double code(double lambda1, double lambda2, double phi1, double phi2) {
              	double t_0 = Math.sin((lambda1 - lambda2));
              	double t_1 = Math.atan2((t_0 * Math.cos(phi2)), (Math.sin(phi2) - ((Math.cos(lambda1) * Math.cos(phi2)) * Math.sin(phi1))));
              	double tmp;
              	if (phi2 <= -0.000105) {
              		tmp = t_1;
              	} else if (phi2 <= 3.2e-9) {
              		tmp = Math.atan2((t_0 * 1.0), ((Math.cos(phi1) * phi2) - (Math.cos((lambda1 - lambda2)) * Math.sin(phi1))));
              	} else {
              		tmp = t_1;
              	}
              	return tmp;
              }
              
              def code(lambda1, lambda2, phi1, phi2):
              	t_0 = math.sin((lambda1 - lambda2))
              	t_1 = math.atan2((t_0 * math.cos(phi2)), (math.sin(phi2) - ((math.cos(lambda1) * math.cos(phi2)) * math.sin(phi1))))
              	tmp = 0
              	if phi2 <= -0.000105:
              		tmp = t_1
              	elif phi2 <= 3.2e-9:
              		tmp = math.atan2((t_0 * 1.0), ((math.cos(phi1) * phi2) - (math.cos((lambda1 - lambda2)) * math.sin(phi1))))
              	else:
              		tmp = t_1
              	return tmp
              
              function code(lambda1, lambda2, phi1, phi2)
              	t_0 = sin(Float64(lambda1 - lambda2))
              	t_1 = atan(Float64(t_0 * cos(phi2)), Float64(sin(phi2) - Float64(Float64(cos(lambda1) * cos(phi2)) * sin(phi1))))
              	tmp = 0.0
              	if (phi2 <= -0.000105)
              		tmp = t_1;
              	elseif (phi2 <= 3.2e-9)
              		tmp = atan(Float64(t_0 * 1.0), Float64(Float64(cos(phi1) * phi2) - Float64(cos(Float64(lambda1 - lambda2)) * sin(phi1))));
              	else
              		tmp = t_1;
              	end
              	return tmp
              end
              
              function tmp_2 = code(lambda1, lambda2, phi1, phi2)
              	t_0 = sin((lambda1 - lambda2));
              	t_1 = atan2((t_0 * cos(phi2)), (sin(phi2) - ((cos(lambda1) * cos(phi2)) * sin(phi1))));
              	tmp = 0.0;
              	if (phi2 <= -0.000105)
              		tmp = t_1;
              	elseif (phi2 <= 3.2e-9)
              		tmp = atan2((t_0 * 1.0), ((cos(phi1) * phi2) - (cos((lambda1 - lambda2)) * sin(phi1))));
              	else
              		tmp = t_1;
              	end
              	tmp_2 = tmp;
              end
              
              code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[ArcTan[N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[(N[Sin[phi2], $MachinePrecision] - N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -0.000105], t$95$1, If[LessEqual[phi2, 3.2e-9], N[ArcTan[N[(t$95$0 * 1.0), $MachinePrecision] / N[(N[(N[Cos[phi1], $MachinePrecision] * phi2), $MachinePrecision] - N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$1]]]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\
              t_1 := \tan^{-1}_* \frac{t\_0 \cdot \cos \phi_2}{\sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1}\\
              \mathbf{if}\;\phi_2 \leq -0.000105:\\
              \;\;\;\;t\_1\\
              
              \mathbf{elif}\;\phi_2 \leq 3.2 \cdot 10^{-9}:\\
              \;\;\;\;\tan^{-1}_* \frac{t\_0 \cdot 1}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1}\\
              
              \mathbf{else}:\\
              \;\;\;\;t\_1\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if phi2 < -1.05e-4 or 3.20000000000000012e-9 < phi2

                1. Initial program 76.8%

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

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

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

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

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

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                  5. lift-cos.f64N/A

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                  6. lift-sin.f6466.9

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                4. Applied rewrites66.9%

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

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2} - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                6. Step-by-step derivation
                  1. lift-sin.f6450.3

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2 - \left(\cos \lambda_1 \cdot \cos \phi_2\right) \cdot \sin \phi_1} \]
                7. Applied rewrites50.3%

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

                if -1.05e-4 < phi2 < 3.20000000000000012e-9

                1. Initial program 81.5%

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

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\phi_2 \cdot \cos \phi_1 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1}} \]
                3. Step-by-step derivation
                  1. lower--.f64N/A

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

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

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)} \cdot \sin \phi_1} \]
                  4. lift-cos.f64N/A

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

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\sin \phi_1}} \]
                  6. lift-cos.f64N/A

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \color{blue}{\phi_1}} \]
                  7. lift--.f64N/A

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                  8. lift-sin.f6481.4

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                4. Applied rewrites81.4%

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

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{1}}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                6. Step-by-step derivation
                  1. cos-neg-rev81.5

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot 1}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                  2. sin-+PI/281.5

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot 1}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                7. Applied rewrites81.5%

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

              Alternative 23: 64.8% accurate, 0.9× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\ t_1 := \tan^{-1}_* \frac{t\_0 \cdot \cos \phi_2}{\sin \phi_2}\\ \mathbf{if}\;\phi_2 \leq -0.000105:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\phi_2 \leq 0.00086:\\ \;\;\;\;\tan^{-1}_* \frac{t\_0 \cdot 1}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
              (FPCore (lambda1 lambda2 phi1 phi2)
               :precision binary64
               (let* ((t_0 (sin (- lambda1 lambda2)))
                      (t_1 (atan2 (* t_0 (cos phi2)) (sin phi2))))
                 (if (<= phi2 -0.000105)
                   t_1
                   (if (<= phi2 0.00086)
                     (atan2
                      (* t_0 1.0)
                      (- (* (cos phi1) phi2) (* (cos (- lambda1 lambda2)) (sin phi1))))
                     t_1))))
              double code(double lambda1, double lambda2, double phi1, double phi2) {
              	double t_0 = sin((lambda1 - lambda2));
              	double t_1 = atan2((t_0 * cos(phi2)), sin(phi2));
              	double tmp;
              	if (phi2 <= -0.000105) {
              		tmp = t_1;
              	} else if (phi2 <= 0.00086) {
              		tmp = atan2((t_0 * 1.0), ((cos(phi1) * phi2) - (cos((lambda1 - lambda2)) * sin(phi1))));
              	} 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, lambda2, phi1, phi2)
              use fmin_fmax_functions
                  real(8), intent (in) :: lambda1
                  real(8), intent (in) :: lambda2
                  real(8), intent (in) :: phi1
                  real(8), intent (in) :: phi2
                  real(8) :: t_0
                  real(8) :: t_1
                  real(8) :: tmp
                  t_0 = sin((lambda1 - lambda2))
                  t_1 = atan2((t_0 * cos(phi2)), sin(phi2))
                  if (phi2 <= (-0.000105d0)) then
                      tmp = t_1
                  else if (phi2 <= 0.00086d0) then
                      tmp = atan2((t_0 * 1.0d0), ((cos(phi1) * phi2) - (cos((lambda1 - lambda2)) * sin(phi1))))
                  else
                      tmp = t_1
                  end if
                  code = tmp
              end function
              
              public static double code(double lambda1, double lambda2, double phi1, double phi2) {
              	double t_0 = Math.sin((lambda1 - lambda2));
              	double t_1 = Math.atan2((t_0 * Math.cos(phi2)), Math.sin(phi2));
              	double tmp;
              	if (phi2 <= -0.000105) {
              		tmp = t_1;
              	} else if (phi2 <= 0.00086) {
              		tmp = Math.atan2((t_0 * 1.0), ((Math.cos(phi1) * phi2) - (Math.cos((lambda1 - lambda2)) * Math.sin(phi1))));
              	} else {
              		tmp = t_1;
              	}
              	return tmp;
              }
              
              def code(lambda1, lambda2, phi1, phi2):
              	t_0 = math.sin((lambda1 - lambda2))
              	t_1 = math.atan2((t_0 * math.cos(phi2)), math.sin(phi2))
              	tmp = 0
              	if phi2 <= -0.000105:
              		tmp = t_1
              	elif phi2 <= 0.00086:
              		tmp = math.atan2((t_0 * 1.0), ((math.cos(phi1) * phi2) - (math.cos((lambda1 - lambda2)) * math.sin(phi1))))
              	else:
              		tmp = t_1
              	return tmp
              
              function code(lambda1, lambda2, phi1, phi2)
              	t_0 = sin(Float64(lambda1 - lambda2))
              	t_1 = atan(Float64(t_0 * cos(phi2)), sin(phi2))
              	tmp = 0.0
              	if (phi2 <= -0.000105)
              		tmp = t_1;
              	elseif (phi2 <= 0.00086)
              		tmp = atan(Float64(t_0 * 1.0), Float64(Float64(cos(phi1) * phi2) - Float64(cos(Float64(lambda1 - lambda2)) * sin(phi1))));
              	else
              		tmp = t_1;
              	end
              	return tmp
              end
              
              function tmp_2 = code(lambda1, lambda2, phi1, phi2)
              	t_0 = sin((lambda1 - lambda2));
              	t_1 = atan2((t_0 * cos(phi2)), sin(phi2));
              	tmp = 0.0;
              	if (phi2 <= -0.000105)
              		tmp = t_1;
              	elseif (phi2 <= 0.00086)
              		tmp = atan2((t_0 * 1.0), ((cos(phi1) * phi2) - (cos((lambda1 - lambda2)) * sin(phi1))));
              	else
              		tmp = t_1;
              	end
              	tmp_2 = tmp;
              end
              
              code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[ArcTan[N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[Sin[phi2], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -0.000105], t$95$1, If[LessEqual[phi2, 0.00086], N[ArcTan[N[(t$95$0 * 1.0), $MachinePrecision] / N[(N[(N[Cos[phi1], $MachinePrecision] * phi2), $MachinePrecision] - N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$1]]]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\
              t_1 := \tan^{-1}_* \frac{t\_0 \cdot \cos \phi_2}{\sin \phi_2}\\
              \mathbf{if}\;\phi_2 \leq -0.000105:\\
              \;\;\;\;t\_1\\
              
              \mathbf{elif}\;\phi_2 \leq 0.00086:\\
              \;\;\;\;\tan^{-1}_* \frac{t\_0 \cdot 1}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1}\\
              
              \mathbf{else}:\\
              \;\;\;\;t\_1\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if phi2 < -1.05e-4 or 8.59999999999999979e-4 < phi2

                1. Initial program 76.8%

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

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                3. Step-by-step derivation
                  1. lift-sin.f6448.6

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2} \]
                4. Applied rewrites48.6%

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

                if -1.05e-4 < phi2 < 8.59999999999999979e-4

                1. Initial program 81.4%

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

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\phi_2 \cdot \cos \phi_1 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1}} \]
                3. Step-by-step derivation
                  1. lower--.f64N/A

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

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

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)} \cdot \sin \phi_1} \]
                  4. lift-cos.f64N/A

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

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\sin \phi_1}} \]
                  6. lift-cos.f64N/A

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \color{blue}{\phi_1}} \]
                  7. lift--.f64N/A

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                  8. lift-sin.f6481.3

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                4. Applied rewrites81.3%

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

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{1}}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                6. Step-by-step derivation
                  1. cos-neg-rev81.4

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot 1}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                  2. sin-+PI/281.4

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot 1}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                7. Applied rewrites81.4%

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

              Alternative 24: 64.6% accurate, 1.0× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\ t_1 := \tan^{-1}_* \frac{t\_0 \cdot \cos \phi_2}{\sin \phi_2}\\ \mathbf{if}\;\phi_2 \leq -0.000102:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\phi_2 \leq 0.00052:\\ \;\;\;\;\tan^{-1}_* \frac{t\_0 \cdot 1}{\phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
              (FPCore (lambda1 lambda2 phi1 phi2)
               :precision binary64
               (let* ((t_0 (sin (- lambda1 lambda2)))
                      (t_1 (atan2 (* t_0 (cos phi2)) (sin phi2))))
                 (if (<= phi2 -0.000102)
                   t_1
                   (if (<= phi2 0.00052)
                     (atan2 (* t_0 1.0) (- phi2 (* (cos (- lambda1 lambda2)) (sin phi1))))
                     t_1))))
              double code(double lambda1, double lambda2, double phi1, double phi2) {
              	double t_0 = sin((lambda1 - lambda2));
              	double t_1 = atan2((t_0 * cos(phi2)), sin(phi2));
              	double tmp;
              	if (phi2 <= -0.000102) {
              		tmp = t_1;
              	} else if (phi2 <= 0.00052) {
              		tmp = atan2((t_0 * 1.0), (phi2 - (cos((lambda1 - lambda2)) * sin(phi1))));
              	} 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, lambda2, phi1, phi2)
              use fmin_fmax_functions
                  real(8), intent (in) :: lambda1
                  real(8), intent (in) :: lambda2
                  real(8), intent (in) :: phi1
                  real(8), intent (in) :: phi2
                  real(8) :: t_0
                  real(8) :: t_1
                  real(8) :: tmp
                  t_0 = sin((lambda1 - lambda2))
                  t_1 = atan2((t_0 * cos(phi2)), sin(phi2))
                  if (phi2 <= (-0.000102d0)) then
                      tmp = t_1
                  else if (phi2 <= 0.00052d0) then
                      tmp = atan2((t_0 * 1.0d0), (phi2 - (cos((lambda1 - lambda2)) * sin(phi1))))
                  else
                      tmp = t_1
                  end if
                  code = tmp
              end function
              
              public static double code(double lambda1, double lambda2, double phi1, double phi2) {
              	double t_0 = Math.sin((lambda1 - lambda2));
              	double t_1 = Math.atan2((t_0 * Math.cos(phi2)), Math.sin(phi2));
              	double tmp;
              	if (phi2 <= -0.000102) {
              		tmp = t_1;
              	} else if (phi2 <= 0.00052) {
              		tmp = Math.atan2((t_0 * 1.0), (phi2 - (Math.cos((lambda1 - lambda2)) * Math.sin(phi1))));
              	} else {
              		tmp = t_1;
              	}
              	return tmp;
              }
              
              def code(lambda1, lambda2, phi1, phi2):
              	t_0 = math.sin((lambda1 - lambda2))
              	t_1 = math.atan2((t_0 * math.cos(phi2)), math.sin(phi2))
              	tmp = 0
              	if phi2 <= -0.000102:
              		tmp = t_1
              	elif phi2 <= 0.00052:
              		tmp = math.atan2((t_0 * 1.0), (phi2 - (math.cos((lambda1 - lambda2)) * math.sin(phi1))))
              	else:
              		tmp = t_1
              	return tmp
              
              function code(lambda1, lambda2, phi1, phi2)
              	t_0 = sin(Float64(lambda1 - lambda2))
              	t_1 = atan(Float64(t_0 * cos(phi2)), sin(phi2))
              	tmp = 0.0
              	if (phi2 <= -0.000102)
              		tmp = t_1;
              	elseif (phi2 <= 0.00052)
              		tmp = atan(Float64(t_0 * 1.0), Float64(phi2 - Float64(cos(Float64(lambda1 - lambda2)) * sin(phi1))));
              	else
              		tmp = t_1;
              	end
              	return tmp
              end
              
              function tmp_2 = code(lambda1, lambda2, phi1, phi2)
              	t_0 = sin((lambda1 - lambda2));
              	t_1 = atan2((t_0 * cos(phi2)), sin(phi2));
              	tmp = 0.0;
              	if (phi2 <= -0.000102)
              		tmp = t_1;
              	elseif (phi2 <= 0.00052)
              		tmp = atan2((t_0 * 1.0), (phi2 - (cos((lambda1 - lambda2)) * sin(phi1))));
              	else
              		tmp = t_1;
              	end
              	tmp_2 = tmp;
              end
              
              code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[ArcTan[N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[Sin[phi2], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -0.000102], t$95$1, If[LessEqual[phi2, 0.00052], N[ArcTan[N[(t$95$0 * 1.0), $MachinePrecision] / N[(phi2 - N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$1]]]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\
              t_1 := \tan^{-1}_* \frac{t\_0 \cdot \cos \phi_2}{\sin \phi_2}\\
              \mathbf{if}\;\phi_2 \leq -0.000102:\\
              \;\;\;\;t\_1\\
              
              \mathbf{elif}\;\phi_2 \leq 0.00052:\\
              \;\;\;\;\tan^{-1}_* \frac{t\_0 \cdot 1}{\phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1}\\
              
              \mathbf{else}:\\
              \;\;\;\;t\_1\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if phi2 < -1.01999999999999999e-4 or 5.19999999999999954e-4 < phi2

                1. Initial program 76.8%

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

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                3. Step-by-step derivation
                  1. lift-sin.f6448.6

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2} \]
                4. Applied rewrites48.6%

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

                if -1.01999999999999999e-4 < phi2 < 5.19999999999999954e-4

                1. Initial program 81.5%

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

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\phi_2 \cdot \cos \phi_1 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1}} \]
                3. Step-by-step derivation
                  1. lower--.f64N/A

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

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

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)} \cdot \sin \phi_1} \]
                  4. lift-cos.f64N/A

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

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\sin \phi_1}} \]
                  6. lift-cos.f64N/A

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \color{blue}{\phi_1}} \]
                  7. lift--.f64N/A

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                  8. lift-sin.f6481.3

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                4. Applied rewrites81.3%

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

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{1}}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                6. Step-by-step derivation
                  1. cos-neg-rev81.4

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot 1}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                  2. sin-+PI/281.4

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot 1}{\cos \phi_1 \cdot \phi_2 - \cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1} \]
                7. Applied rewrites81.4%

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

                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot 1}{\phi_2 - \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)} \cdot \sin \phi_1} \]
                9. Step-by-step derivation
                  1. Applied rewrites81.0%

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot 1}{\phi_2 - \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)} \cdot \sin \phi_1} \]
                10. Recombined 2 regimes into one program.
                11. Add Preprocessing

                Alternative 25: 63.1% accurate, 1.1× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\ t_1 := \tan^{-1}_* \frac{t\_0 \cdot \cos \phi_2}{\sin \phi_2}\\ \mathbf{if}\;\phi_2 \leq -1.25 \cdot 10^{-7}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\phi_2 \leq 2.05 \cdot 10^{-6}:\\ \;\;\;\;\tan^{-1}_* \frac{t\_0}{-1 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
                (FPCore (lambda1 lambda2 phi1 phi2)
                 :precision binary64
                 (let* ((t_0 (sin (- lambda1 lambda2)))
                        (t_1 (atan2 (* t_0 (cos phi2)) (sin phi2))))
                   (if (<= phi2 -1.25e-7)
                     t_1
                     (if (<= phi2 2.05e-6)
                       (atan2 t_0 (* -1.0 (* (cos (- lambda1 lambda2)) (sin phi1))))
                       t_1))))
                double code(double lambda1, double lambda2, double phi1, double phi2) {
                	double t_0 = sin((lambda1 - lambda2));
                	double t_1 = atan2((t_0 * cos(phi2)), sin(phi2));
                	double tmp;
                	if (phi2 <= -1.25e-7) {
                		tmp = t_1;
                	} else if (phi2 <= 2.05e-6) {
                		tmp = atan2(t_0, (-1.0 * (cos((lambda1 - lambda2)) * sin(phi1))));
                	} 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, lambda2, phi1, phi2)
                use fmin_fmax_functions
                    real(8), intent (in) :: lambda1
                    real(8), intent (in) :: lambda2
                    real(8), intent (in) :: phi1
                    real(8), intent (in) :: phi2
                    real(8) :: t_0
                    real(8) :: t_1
                    real(8) :: tmp
                    t_0 = sin((lambda1 - lambda2))
                    t_1 = atan2((t_0 * cos(phi2)), sin(phi2))
                    if (phi2 <= (-1.25d-7)) then
                        tmp = t_1
                    else if (phi2 <= 2.05d-6) then
                        tmp = atan2(t_0, ((-1.0d0) * (cos((lambda1 - lambda2)) * sin(phi1))))
                    else
                        tmp = t_1
                    end if
                    code = tmp
                end function
                
                public static double code(double lambda1, double lambda2, double phi1, double phi2) {
                	double t_0 = Math.sin((lambda1 - lambda2));
                	double t_1 = Math.atan2((t_0 * Math.cos(phi2)), Math.sin(phi2));
                	double tmp;
                	if (phi2 <= -1.25e-7) {
                		tmp = t_1;
                	} else if (phi2 <= 2.05e-6) {
                		tmp = Math.atan2(t_0, (-1.0 * (Math.cos((lambda1 - lambda2)) * Math.sin(phi1))));
                	} else {
                		tmp = t_1;
                	}
                	return tmp;
                }
                
                def code(lambda1, lambda2, phi1, phi2):
                	t_0 = math.sin((lambda1 - lambda2))
                	t_1 = math.atan2((t_0 * math.cos(phi2)), math.sin(phi2))
                	tmp = 0
                	if phi2 <= -1.25e-7:
                		tmp = t_1
                	elif phi2 <= 2.05e-6:
                		tmp = math.atan2(t_0, (-1.0 * (math.cos((lambda1 - lambda2)) * math.sin(phi1))))
                	else:
                		tmp = t_1
                	return tmp
                
                function code(lambda1, lambda2, phi1, phi2)
                	t_0 = sin(Float64(lambda1 - lambda2))
                	t_1 = atan(Float64(t_0 * cos(phi2)), sin(phi2))
                	tmp = 0.0
                	if (phi2 <= -1.25e-7)
                		tmp = t_1;
                	elseif (phi2 <= 2.05e-6)
                		tmp = atan(t_0, Float64(-1.0 * Float64(cos(Float64(lambda1 - lambda2)) * sin(phi1))));
                	else
                		tmp = t_1;
                	end
                	return tmp
                end
                
                function tmp_2 = code(lambda1, lambda2, phi1, phi2)
                	t_0 = sin((lambda1 - lambda2));
                	t_1 = atan2((t_0 * cos(phi2)), sin(phi2));
                	tmp = 0.0;
                	if (phi2 <= -1.25e-7)
                		tmp = t_1;
                	elseif (phi2 <= 2.05e-6)
                		tmp = atan2(t_0, (-1.0 * (cos((lambda1 - lambda2)) * sin(phi1))));
                	else
                		tmp = t_1;
                	end
                	tmp_2 = tmp;
                end
                
                code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[ArcTan[N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[Sin[phi2], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -1.25e-7], t$95$1, If[LessEqual[phi2, 2.05e-6], N[ArcTan[t$95$0 / N[(-1.0 * N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$1]]]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\
                t_1 := \tan^{-1}_* \frac{t\_0 \cdot \cos \phi_2}{\sin \phi_2}\\
                \mathbf{if}\;\phi_2 \leq -1.25 \cdot 10^{-7}:\\
                \;\;\;\;t\_1\\
                
                \mathbf{elif}\;\phi_2 \leq 2.05 \cdot 10^{-6}:\\
                \;\;\;\;\tan^{-1}_* \frac{t\_0}{-1 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1\right)}\\
                
                \mathbf{else}:\\
                \;\;\;\;t\_1\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if phi2 < -1.24999999999999994e-7 or 2.0499999999999999e-6 < phi2

                  1. Initial program 76.8%

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

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                  3. Step-by-step derivation
                    1. lift-sin.f6448.6

                      \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2} \]
                  4. Applied rewrites48.6%

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

                  if -1.24999999999999994e-7 < phi2 < 2.0499999999999999e-6

                  1. Initial program 81.4%

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

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                  3. Step-by-step derivation
                    1. lift-sin.f6449.5

                      \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2} \]
                  4. Applied rewrites49.5%

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                  5. Taylor expanded in lambda1 around inf

                    \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]
                  6. Step-by-step derivation
                    1. Applied rewrites35.6%

                      \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]
                    2. Taylor expanded in phi2 around 0

                      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\sin \left(\lambda_1 - \lambda_2\right)}}{\sin \phi_2} \]
                    3. Step-by-step derivation
                      1. lift-sin.f64N/A

                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\sin \phi_2} \]
                      2. lift--.f6449.5

                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\sin \phi_2} \]
                    4. Applied rewrites49.5%

                      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\sin \left(\lambda_1 - \lambda_2\right)}}{\sin \phi_2} \]
                    5. Taylor expanded in phi2 around 0

                      \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{-1 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1\right)}} \]
                    6. Step-by-step derivation
                      1. cos-neg-revN/A

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

                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{-1 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1\right)} \]
                      3. sin-+PI/2N/A

                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{-1 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1\right)} \]
                      4. cos-neg-revN/A

                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{-1 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1\right)} \]
                      5. cos-diff-revN/A

                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{-1 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1\right)} \]
                      6. lower-*.f64N/A

                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{-1 \cdot \color{blue}{\left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1\right)}} \]
                      7. lift-cos.f64N/A

                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{-1 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \color{blue}{\phi_1}\right)} \]
                      8. lift--.f64N/A

                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{-1 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1\right)} \]
                      9. lift-sin.f64N/A

                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{-1 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \sin \phi_1\right)} \]
                      10. lift-*.f6478.3

                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{-1 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\sin \phi_1}\right)} \]
                    7. Applied rewrites78.3%

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

                  Alternative 26: 49.1% accurate, 2.4× speedup?

                  \[\begin{array}{l} \\ \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2} \end{array} \]
                  (FPCore (lambda1 lambda2 phi1 phi2)
                   :precision binary64
                   (atan2 (* (sin (- lambda1 lambda2)) (cos phi2)) (sin phi2)))
                  double code(double lambda1, double lambda2, double phi1, double phi2) {
                  	return atan2((sin((lambda1 - lambda2)) * cos(phi2)), sin(phi2));
                  }
                  
                  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, lambda2, phi1, phi2)
                  use fmin_fmax_functions
                      real(8), intent (in) :: lambda1
                      real(8), intent (in) :: lambda2
                      real(8), intent (in) :: phi1
                      real(8), intent (in) :: phi2
                      code = atan2((sin((lambda1 - lambda2)) * cos(phi2)), sin(phi2))
                  end function
                  
                  public static double code(double lambda1, double lambda2, double phi1, double phi2) {
                  	return Math.atan2((Math.sin((lambda1 - lambda2)) * Math.cos(phi2)), Math.sin(phi2));
                  }
                  
                  def code(lambda1, lambda2, phi1, phi2):
                  	return math.atan2((math.sin((lambda1 - lambda2)) * math.cos(phi2)), math.sin(phi2))
                  
                  function code(lambda1, lambda2, phi1, phi2)
                  	return atan(Float64(sin(Float64(lambda1 - lambda2)) * cos(phi2)), sin(phi2))
                  end
                  
                  function tmp = code(lambda1, lambda2, phi1, phi2)
                  	tmp = atan2((sin((lambda1 - lambda2)) * cos(phi2)), sin(phi2));
                  end
                  
                  code[lambda1_, lambda2_, phi1_, phi2_] := N[ArcTan[N[(N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[Sin[phi2], $MachinePrecision]], $MachinePrecision]
                  
                  \begin{array}{l}
                  
                  \\
                  \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2}
                  \end{array}
                  
                  Derivation
                  1. Initial program 79.1%

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

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                  3. Step-by-step derivation
                    1. lift-sin.f6449.1

                      \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2} \]
                  4. Applied rewrites49.1%

                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                  5. Add Preprocessing

                  Alternative 27: 43.3% accurate, 1.4× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan^{-1}_* \frac{\sin \lambda_1 \cdot \cos \phi_2}{\sin \phi_2}\\ \mathbf{if}\;\lambda_1 \leq -2.5 \cdot 10^{-80}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\lambda_1 \leq 7 \cdot 10^{+41}:\\ \;\;\;\;\tan^{-1}_* \frac{\sin \left(-\lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
                  (FPCore (lambda1 lambda2 phi1 phi2)
                   :precision binary64
                   (let* ((t_0 (atan2 (* (sin lambda1) (cos phi2)) (sin phi2))))
                     (if (<= lambda1 -2.5e-80)
                       t_0
                       (if (<= lambda1 7e+41)
                         (atan2 (* (sin (- lambda2)) (cos phi2)) (sin phi2))
                         t_0))))
                  double code(double lambda1, double lambda2, double phi1, double phi2) {
                  	double t_0 = atan2((sin(lambda1) * cos(phi2)), sin(phi2));
                  	double tmp;
                  	if (lambda1 <= -2.5e-80) {
                  		tmp = t_0;
                  	} else if (lambda1 <= 7e+41) {
                  		tmp = atan2((sin(-lambda2) * cos(phi2)), sin(phi2));
                  	} else {
                  		tmp = t_0;
                  	}
                  	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, lambda2, phi1, phi2)
                  use fmin_fmax_functions
                      real(8), intent (in) :: lambda1
                      real(8), intent (in) :: lambda2
                      real(8), intent (in) :: phi1
                      real(8), intent (in) :: phi2
                      real(8) :: t_0
                      real(8) :: tmp
                      t_0 = atan2((sin(lambda1) * cos(phi2)), sin(phi2))
                      if (lambda1 <= (-2.5d-80)) then
                          tmp = t_0
                      else if (lambda1 <= 7d+41) then
                          tmp = atan2((sin(-lambda2) * cos(phi2)), sin(phi2))
                      else
                          tmp = t_0
                      end if
                      code = tmp
                  end function
                  
                  public static double code(double lambda1, double lambda2, double phi1, double phi2) {
                  	double t_0 = Math.atan2((Math.sin(lambda1) * Math.cos(phi2)), Math.sin(phi2));
                  	double tmp;
                  	if (lambda1 <= -2.5e-80) {
                  		tmp = t_0;
                  	} else if (lambda1 <= 7e+41) {
                  		tmp = Math.atan2((Math.sin(-lambda2) * Math.cos(phi2)), Math.sin(phi2));
                  	} else {
                  		tmp = t_0;
                  	}
                  	return tmp;
                  }
                  
                  def code(lambda1, lambda2, phi1, phi2):
                  	t_0 = math.atan2((math.sin(lambda1) * math.cos(phi2)), math.sin(phi2))
                  	tmp = 0
                  	if lambda1 <= -2.5e-80:
                  		tmp = t_0
                  	elif lambda1 <= 7e+41:
                  		tmp = math.atan2((math.sin(-lambda2) * math.cos(phi2)), math.sin(phi2))
                  	else:
                  		tmp = t_0
                  	return tmp
                  
                  function code(lambda1, lambda2, phi1, phi2)
                  	t_0 = atan(Float64(sin(lambda1) * cos(phi2)), sin(phi2))
                  	tmp = 0.0
                  	if (lambda1 <= -2.5e-80)
                  		tmp = t_0;
                  	elseif (lambda1 <= 7e+41)
                  		tmp = atan(Float64(sin(Float64(-lambda2)) * cos(phi2)), sin(phi2));
                  	else
                  		tmp = t_0;
                  	end
                  	return tmp
                  end
                  
                  function tmp_2 = code(lambda1, lambda2, phi1, phi2)
                  	t_0 = atan2((sin(lambda1) * cos(phi2)), sin(phi2));
                  	tmp = 0.0;
                  	if (lambda1 <= -2.5e-80)
                  		tmp = t_0;
                  	elseif (lambda1 <= 7e+41)
                  		tmp = atan2((sin(-lambda2) * cos(phi2)), sin(phi2));
                  	else
                  		tmp = t_0;
                  	end
                  	tmp_2 = tmp;
                  end
                  
                  code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[ArcTan[N[(N[Sin[lambda1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[Sin[phi2], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[lambda1, -2.5e-80], t$95$0, If[LessEqual[lambda1, 7e+41], N[ArcTan[N[(N[Sin[(-lambda2)], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[Sin[phi2], $MachinePrecision]], $MachinePrecision], t$95$0]]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  t_0 := \tan^{-1}_* \frac{\sin \lambda_1 \cdot \cos \phi_2}{\sin \phi_2}\\
                  \mathbf{if}\;\lambda_1 \leq -2.5 \cdot 10^{-80}:\\
                  \;\;\;\;t\_0\\
                  
                  \mathbf{elif}\;\lambda_1 \leq 7 \cdot 10^{+41}:\\
                  \;\;\;\;\tan^{-1}_* \frac{\sin \left(-\lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2}\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;t\_0\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 2 regimes
                  2. if lambda1 < -2.5e-80 or 6.9999999999999998e41 < lambda1

                    1. Initial program 63.4%

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

                      \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                    3. Step-by-step derivation
                      1. lift-sin.f6442.1

                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2} \]
                    4. Applied rewrites42.1%

                      \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                    5. Taylor expanded in lambda1 around inf

                      \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]
                    6. Step-by-step derivation
                      1. Applied rewrites39.7%

                        \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]

                      if -2.5e-80 < lambda1 < 6.9999999999999998e41

                      1. Initial program 96.6%

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

                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                      3. Step-by-step derivation
                        1. lift-sin.f6456.9

                          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2} \]
                      4. Applied rewrites56.9%

                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                      5. Taylor expanded in lambda1 around 0

                        \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\left(-1 \cdot \lambda_2\right)} \cdot \cos \phi_2}{\sin \phi_2} \]
                      6. Step-by-step derivation
                        1. mul-1-negN/A

                          \[\leadsto \tan^{-1}_* \frac{\sin \left(\mathsf{neg}\left(\lambda_2\right)\right) \cdot \cos \phi_2}{\sin \phi_2} \]
                        2. lower-neg.f6447.3

                          \[\leadsto \tan^{-1}_* \frac{\sin \left(-\lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2} \]
                      7. Applied rewrites47.3%

                        \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\left(-\lambda_2\right)} \cdot \cos \phi_2}{\sin \phi_2} \]
                    7. Recombined 2 regimes into one program.
                    8. Add Preprocessing

                    Alternative 28: 39.1% accurate, 1.5× speedup?

                    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan^{-1}_* \frac{\sin \lambda_1 \cdot \cos \phi_2}{\sin \phi_2}\\ \mathbf{if}\;\phi_2 \leq -0.7:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_2 \leq 1.85 \cdot 10^{-22}:\\ \;\;\;\;\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\phi_2}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
                    (FPCore (lambda1 lambda2 phi1 phi2)
                     :precision binary64
                     (let* ((t_0 (atan2 (* (sin lambda1) (cos phi2)) (sin phi2))))
                       (if (<= phi2 -0.7)
                         t_0
                         (if (<= phi2 1.85e-22) (atan2 (sin (- lambda1 lambda2)) phi2) t_0))))
                    double code(double lambda1, double lambda2, double phi1, double phi2) {
                    	double t_0 = atan2((sin(lambda1) * cos(phi2)), sin(phi2));
                    	double tmp;
                    	if (phi2 <= -0.7) {
                    		tmp = t_0;
                    	} else if (phi2 <= 1.85e-22) {
                    		tmp = atan2(sin((lambda1 - lambda2)), phi2);
                    	} else {
                    		tmp = t_0;
                    	}
                    	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, lambda2, phi1, phi2)
                    use fmin_fmax_functions
                        real(8), intent (in) :: lambda1
                        real(8), intent (in) :: lambda2
                        real(8), intent (in) :: phi1
                        real(8), intent (in) :: phi2
                        real(8) :: t_0
                        real(8) :: tmp
                        t_0 = atan2((sin(lambda1) * cos(phi2)), sin(phi2))
                        if (phi2 <= (-0.7d0)) then
                            tmp = t_0
                        else if (phi2 <= 1.85d-22) then
                            tmp = atan2(sin((lambda1 - lambda2)), phi2)
                        else
                            tmp = t_0
                        end if
                        code = tmp
                    end function
                    
                    public static double code(double lambda1, double lambda2, double phi1, double phi2) {
                    	double t_0 = Math.atan2((Math.sin(lambda1) * Math.cos(phi2)), Math.sin(phi2));
                    	double tmp;
                    	if (phi2 <= -0.7) {
                    		tmp = t_0;
                    	} else if (phi2 <= 1.85e-22) {
                    		tmp = Math.atan2(Math.sin((lambda1 - lambda2)), phi2);
                    	} else {
                    		tmp = t_0;
                    	}
                    	return tmp;
                    }
                    
                    def code(lambda1, lambda2, phi1, phi2):
                    	t_0 = math.atan2((math.sin(lambda1) * math.cos(phi2)), math.sin(phi2))
                    	tmp = 0
                    	if phi2 <= -0.7:
                    		tmp = t_0
                    	elif phi2 <= 1.85e-22:
                    		tmp = math.atan2(math.sin((lambda1 - lambda2)), phi2)
                    	else:
                    		tmp = t_0
                    	return tmp
                    
                    function code(lambda1, lambda2, phi1, phi2)
                    	t_0 = atan(Float64(sin(lambda1) * cos(phi2)), sin(phi2))
                    	tmp = 0.0
                    	if (phi2 <= -0.7)
                    		tmp = t_0;
                    	elseif (phi2 <= 1.85e-22)
                    		tmp = atan(sin(Float64(lambda1 - lambda2)), phi2);
                    	else
                    		tmp = t_0;
                    	end
                    	return tmp
                    end
                    
                    function tmp_2 = code(lambda1, lambda2, phi1, phi2)
                    	t_0 = atan2((sin(lambda1) * cos(phi2)), sin(phi2));
                    	tmp = 0.0;
                    	if (phi2 <= -0.7)
                    		tmp = t_0;
                    	elseif (phi2 <= 1.85e-22)
                    		tmp = atan2(sin((lambda1 - lambda2)), phi2);
                    	else
                    		tmp = t_0;
                    	end
                    	tmp_2 = tmp;
                    end
                    
                    code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[ArcTan[N[(N[Sin[lambda1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] / N[Sin[phi2], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -0.7], t$95$0, If[LessEqual[phi2, 1.85e-22], N[ArcTan[N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] / phi2], $MachinePrecision], t$95$0]]]
                    
                    \begin{array}{l}
                    
                    \\
                    \begin{array}{l}
                    t_0 := \tan^{-1}_* \frac{\sin \lambda_1 \cdot \cos \phi_2}{\sin \phi_2}\\
                    \mathbf{if}\;\phi_2 \leq -0.7:\\
                    \;\;\;\;t\_0\\
                    
                    \mathbf{elif}\;\phi_2 \leq 1.85 \cdot 10^{-22}:\\
                    \;\;\;\;\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\phi_2}\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;t\_0\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 2 regimes
                    2. if phi2 < -0.69999999999999996 or 1.85e-22 < phi2

                      1. Initial program 76.6%

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

                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                      3. Step-by-step derivation
                        1. lift-sin.f6448.4

                          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2} \]
                      4. Applied rewrites48.4%

                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                      5. Taylor expanded in lambda1 around inf

                        \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]
                      6. Step-by-step derivation
                        1. Applied rewrites29.3%

                          \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]

                        if -0.69999999999999996 < phi2 < 1.85e-22

                        1. Initial program 81.7%

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

                          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                        3. Step-by-step derivation
                          1. lift-sin.f6449.8

                            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2} \]
                        4. Applied rewrites49.8%

                          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                        5. Taylor expanded in lambda1 around inf

                          \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]
                        6. Step-by-step derivation
                          1. Applied rewrites35.9%

                            \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]
                          2. Taylor expanded in phi2 around 0

                            \[\leadsto \tan^{-1}_* \frac{\color{blue}{\sin \left(\lambda_1 - \lambda_2\right)}}{\sin \phi_2} \]
                          3. Step-by-step derivation
                            1. lift-sin.f64N/A

                              \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\sin \phi_2} \]
                            2. lift--.f6449.7

                              \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\sin \phi_2} \]
                          4. Applied rewrites49.7%

                            \[\leadsto \tan^{-1}_* \frac{\color{blue}{\sin \left(\lambda_1 - \lambda_2\right)}}{\sin \phi_2} \]
                          5. Taylor expanded in phi2 around 0

                            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\phi_2} \]
                          6. Step-by-step derivation
                            1. Applied rewrites49.7%

                              \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\phi_2} \]
                          7. Recombined 2 regimes into one program.
                          8. Add Preprocessing

                          Alternative 29: 31.9% accurate, 2.4× speedup?

                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.85 \cdot 10^{-22}:\\ \;\;\;\;\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\phi_2}\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1}_* \frac{\sin \lambda_1}{\sin \phi_2}\\ \end{array} \end{array} \]
                          (FPCore (lambda1 lambda2 phi1 phi2)
                           :precision binary64
                           (if (<= phi2 1.85e-22)
                             (atan2 (sin (- lambda1 lambda2)) phi2)
                             (atan2 (sin lambda1) (sin phi2))))
                          double code(double lambda1, double lambda2, double phi1, double phi2) {
                          	double tmp;
                          	if (phi2 <= 1.85e-22) {
                          		tmp = atan2(sin((lambda1 - lambda2)), phi2);
                          	} else {
                          		tmp = atan2(sin(lambda1), sin(phi2));
                          	}
                          	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, lambda2, phi1, phi2)
                          use fmin_fmax_functions
                              real(8), intent (in) :: lambda1
                              real(8), intent (in) :: lambda2
                              real(8), intent (in) :: phi1
                              real(8), intent (in) :: phi2
                              real(8) :: tmp
                              if (phi2 <= 1.85d-22) then
                                  tmp = atan2(sin((lambda1 - lambda2)), phi2)
                              else
                                  tmp = atan2(sin(lambda1), sin(phi2))
                              end if
                              code = tmp
                          end function
                          
                          public static double code(double lambda1, double lambda2, double phi1, double phi2) {
                          	double tmp;
                          	if (phi2 <= 1.85e-22) {
                          		tmp = Math.atan2(Math.sin((lambda1 - lambda2)), phi2);
                          	} else {
                          		tmp = Math.atan2(Math.sin(lambda1), Math.sin(phi2));
                          	}
                          	return tmp;
                          }
                          
                          def code(lambda1, lambda2, phi1, phi2):
                          	tmp = 0
                          	if phi2 <= 1.85e-22:
                          		tmp = math.atan2(math.sin((lambda1 - lambda2)), phi2)
                          	else:
                          		tmp = math.atan2(math.sin(lambda1), math.sin(phi2))
                          	return tmp
                          
                          function code(lambda1, lambda2, phi1, phi2)
                          	tmp = 0.0
                          	if (phi2 <= 1.85e-22)
                          		tmp = atan(sin(Float64(lambda1 - lambda2)), phi2);
                          	else
                          		tmp = atan(sin(lambda1), sin(phi2));
                          	end
                          	return tmp
                          end
                          
                          function tmp_2 = code(lambda1, lambda2, phi1, phi2)
                          	tmp = 0.0;
                          	if (phi2 <= 1.85e-22)
                          		tmp = atan2(sin((lambda1 - lambda2)), phi2);
                          	else
                          		tmp = atan2(sin(lambda1), sin(phi2));
                          	end
                          	tmp_2 = tmp;
                          end
                          
                          code[lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 1.85e-22], N[ArcTan[N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] / phi2], $MachinePrecision], N[ArcTan[N[Sin[lambda1], $MachinePrecision] / N[Sin[phi2], $MachinePrecision]], $MachinePrecision]]
                          
                          \begin{array}{l}
                          
                          \\
                          \begin{array}{l}
                          \mathbf{if}\;\phi_2 \leq 1.85 \cdot 10^{-22}:\\
                          \;\;\;\;\tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\phi_2}\\
                          
                          \mathbf{else}:\\
                          \;\;\;\;\tan^{-1}_* \frac{\sin \lambda_1}{\sin \phi_2}\\
                          
                          
                          \end{array}
                          \end{array}
                          
                          Derivation
                          1. Split input into 2 regimes
                          2. if phi2 < 1.85e-22

                            1. Initial program 80.2%

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

                              \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                            3. Step-by-step derivation
                              1. lift-sin.f6449.7

                                \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2} \]
                            4. Applied rewrites49.7%

                              \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                            5. Taylor expanded in lambda1 around inf

                              \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]
                            6. Step-by-step derivation
                              1. Applied rewrites33.9%

                                \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]
                              2. Taylor expanded in phi2 around 0

                                \[\leadsto \tan^{-1}_* \frac{\color{blue}{\sin \left(\lambda_1 - \lambda_2\right)}}{\sin \phi_2} \]
                              3. Step-by-step derivation
                                1. lift-sin.f64N/A

                                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\sin \phi_2} \]
                                2. lift--.f6437.8

                                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\sin \phi_2} \]
                              4. Applied rewrites37.8%

                                \[\leadsto \tan^{-1}_* \frac{\color{blue}{\sin \left(\lambda_1 - \lambda_2\right)}}{\sin \phi_2} \]
                              5. Taylor expanded in phi2 around 0

                                \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\phi_2} \]
                              6. Step-by-step derivation
                                1. Applied rewrites37.8%

                                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\phi_2} \]

                                if 1.85e-22 < phi2

                                1. Initial program 76.2%

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

                                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                                3. Step-by-step derivation
                                  1. lift-sin.f6447.3

                                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2} \]
                                4. Applied rewrites47.3%

                                  \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                                5. Taylor expanded in lambda1 around inf

                                  \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]
                                6. Step-by-step derivation
                                  1. Applied rewrites28.5%

                                    \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]
                                  2. Taylor expanded in phi2 around 0

                                    \[\leadsto \tan^{-1}_* \frac{\color{blue}{\sin \left(\lambda_1 - \lambda_2\right)}}{\sin \phi_2} \]
                                  3. Step-by-step derivation
                                    1. lift-sin.f64N/A

                                      \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\sin \phi_2} \]
                                    2. lift--.f6415.9

                                      \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\sin \phi_2} \]
                                  4. Applied rewrites15.9%

                                    \[\leadsto \tan^{-1}_* \frac{\color{blue}{\sin \left(\lambda_1 - \lambda_2\right)}}{\sin \phi_2} \]
                                  5. Taylor expanded in lambda1 around inf

                                    \[\leadsto \tan^{-1}_* \frac{\sin \lambda_1}{\sin \phi_2} \]
                                  6. Step-by-step derivation
                                    1. Applied rewrites14.0%

                                      \[\leadsto \tan^{-1}_* \frac{\sin \lambda_1}{\sin \phi_2} \]
                                  7. Recombined 2 regimes into one program.
                                  8. Add Preprocessing

                                  Alternative 30: 31.3% accurate, 3.4× speedup?

                                  \[\begin{array}{l} \\ \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\sin \phi_2} \end{array} \]
                                  (FPCore (lambda1 lambda2 phi1 phi2)
                                   :precision binary64
                                   (atan2 (sin (- lambda1 lambda2)) (sin phi2)))
                                  double code(double lambda1, double lambda2, double phi1, double phi2) {
                                  	return atan2(sin((lambda1 - lambda2)), sin(phi2));
                                  }
                                  
                                  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, lambda2, phi1, phi2)
                                  use fmin_fmax_functions
                                      real(8), intent (in) :: lambda1
                                      real(8), intent (in) :: lambda2
                                      real(8), intent (in) :: phi1
                                      real(8), intent (in) :: phi2
                                      code = atan2(sin((lambda1 - lambda2)), sin(phi2))
                                  end function
                                  
                                  public static double code(double lambda1, double lambda2, double phi1, double phi2) {
                                  	return Math.atan2(Math.sin((lambda1 - lambda2)), Math.sin(phi2));
                                  }
                                  
                                  def code(lambda1, lambda2, phi1, phi2):
                                  	return math.atan2(math.sin((lambda1 - lambda2)), math.sin(phi2))
                                  
                                  function code(lambda1, lambda2, phi1, phi2)
                                  	return atan(sin(Float64(lambda1 - lambda2)), sin(phi2))
                                  end
                                  
                                  function tmp = code(lambda1, lambda2, phi1, phi2)
                                  	tmp = atan2(sin((lambda1 - lambda2)), sin(phi2));
                                  end
                                  
                                  code[lambda1_, lambda2_, phi1_, phi2_] := N[ArcTan[N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] / N[Sin[phi2], $MachinePrecision]], $MachinePrecision]
                                  
                                  \begin{array}{l}
                                  
                                  \\
                                  \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\sin \phi_2}
                                  \end{array}
                                  
                                  Derivation
                                  1. Initial program 79.1%

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

                                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                                  3. Step-by-step derivation
                                    1. lift-sin.f6449.1

                                      \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2} \]
                                  4. Applied rewrites49.1%

                                    \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                                  5. Taylor expanded in lambda1 around inf

                                    \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]
                                  6. Step-by-step derivation
                                    1. Applied rewrites32.5%

                                      \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]
                                    2. Taylor expanded in phi2 around 0

                                      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\sin \left(\lambda_1 - \lambda_2\right)}}{\sin \phi_2} \]
                                    3. Step-by-step derivation
                                      1. lift-sin.f64N/A

                                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\sin \phi_2} \]
                                      2. lift--.f6431.9

                                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\sin \phi_2} \]
                                    4. Applied rewrites31.9%

                                      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\sin \left(\lambda_1 - \lambda_2\right)}}{\sin \phi_2} \]
                                    5. Add Preprocessing

                                    Alternative 31: 26.6% accurate, 2.4× speedup?

                                    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 3.2 \cdot 10^{-132}:\\ \;\;\;\;\tan^{-1}_* \frac{\sin \lambda_1}{\sin \phi_2}\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1}_* \frac{-\sin \lambda_2}{\sin \phi_2}\\ \end{array} \end{array} \]
                                    (FPCore (lambda1 lambda2 phi1 phi2)
                                     :precision binary64
                                     (if (<= lambda2 3.2e-132)
                                       (atan2 (sin lambda1) (sin phi2))
                                       (atan2 (- (sin lambda2)) (sin phi2))))
                                    double code(double lambda1, double lambda2, double phi1, double phi2) {
                                    	double tmp;
                                    	if (lambda2 <= 3.2e-132) {
                                    		tmp = atan2(sin(lambda1), sin(phi2));
                                    	} else {
                                    		tmp = atan2(-sin(lambda2), sin(phi2));
                                    	}
                                    	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, lambda2, phi1, phi2)
                                    use fmin_fmax_functions
                                        real(8), intent (in) :: lambda1
                                        real(8), intent (in) :: lambda2
                                        real(8), intent (in) :: phi1
                                        real(8), intent (in) :: phi2
                                        real(8) :: tmp
                                        if (lambda2 <= 3.2d-132) then
                                            tmp = atan2(sin(lambda1), sin(phi2))
                                        else
                                            tmp = atan2(-sin(lambda2), sin(phi2))
                                        end if
                                        code = tmp
                                    end function
                                    
                                    public static double code(double lambda1, double lambda2, double phi1, double phi2) {
                                    	double tmp;
                                    	if (lambda2 <= 3.2e-132) {
                                    		tmp = Math.atan2(Math.sin(lambda1), Math.sin(phi2));
                                    	} else {
                                    		tmp = Math.atan2(-Math.sin(lambda2), Math.sin(phi2));
                                    	}
                                    	return tmp;
                                    }
                                    
                                    def code(lambda1, lambda2, phi1, phi2):
                                    	tmp = 0
                                    	if lambda2 <= 3.2e-132:
                                    		tmp = math.atan2(math.sin(lambda1), math.sin(phi2))
                                    	else:
                                    		tmp = math.atan2(-math.sin(lambda2), math.sin(phi2))
                                    	return tmp
                                    
                                    function code(lambda1, lambda2, phi1, phi2)
                                    	tmp = 0.0
                                    	if (lambda2 <= 3.2e-132)
                                    		tmp = atan(sin(lambda1), sin(phi2));
                                    	else
                                    		tmp = atan(Float64(-sin(lambda2)), sin(phi2));
                                    	end
                                    	return tmp
                                    end
                                    
                                    function tmp_2 = code(lambda1, lambda2, phi1, phi2)
                                    	tmp = 0.0;
                                    	if (lambda2 <= 3.2e-132)
                                    		tmp = atan2(sin(lambda1), sin(phi2));
                                    	else
                                    		tmp = atan2(-sin(lambda2), sin(phi2));
                                    	end
                                    	tmp_2 = tmp;
                                    end
                                    
                                    code[lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda2, 3.2e-132], N[ArcTan[N[Sin[lambda1], $MachinePrecision] / N[Sin[phi2], $MachinePrecision]], $MachinePrecision], N[ArcTan[(-N[Sin[lambda2], $MachinePrecision]) / N[Sin[phi2], $MachinePrecision]], $MachinePrecision]]
                                    
                                    \begin{array}{l}
                                    
                                    \\
                                    \begin{array}{l}
                                    \mathbf{if}\;\lambda_2 \leq 3.2 \cdot 10^{-132}:\\
                                    \;\;\;\;\tan^{-1}_* \frac{\sin \lambda_1}{\sin \phi_2}\\
                                    
                                    \mathbf{else}:\\
                                    \;\;\;\;\tan^{-1}_* \frac{-\sin \lambda_2}{\sin \phi_2}\\
                                    
                                    
                                    \end{array}
                                    \end{array}
                                    
                                    Derivation
                                    1. Split input into 2 regimes
                                    2. if lambda2 < 3.2000000000000002e-132

                                      1. Initial program 83.6%

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

                                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                                      3. Step-by-step derivation
                                        1. lift-sin.f6450.9

                                          \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2} \]
                                      4. Applied rewrites50.9%

                                        \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                                      5. Taylor expanded in lambda1 around inf

                                        \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]
                                      6. Step-by-step derivation
                                        1. Applied rewrites36.8%

                                          \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]
                                        2. Taylor expanded in phi2 around 0

                                          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\sin \left(\lambda_1 - \lambda_2\right)}}{\sin \phi_2} \]
                                        3. Step-by-step derivation
                                          1. lift-sin.f64N/A

                                            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\sin \phi_2} \]
                                          2. lift--.f6432.5

                                            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\sin \phi_2} \]
                                        4. Applied rewrites32.5%

                                          \[\leadsto \tan^{-1}_* \frac{\color{blue}{\sin \left(\lambda_1 - \lambda_2\right)}}{\sin \phi_2} \]
                                        5. Taylor expanded in lambda1 around inf

                                          \[\leadsto \tan^{-1}_* \frac{\sin \lambda_1}{\sin \phi_2} \]
                                        6. Step-by-step derivation
                                          1. Applied rewrites26.2%

                                            \[\leadsto \tan^{-1}_* \frac{\sin \lambda_1}{\sin \phi_2} \]

                                          if 3.2000000000000002e-132 < lambda2

                                          1. Initial program 70.8%

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

                                            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                                          3. Step-by-step derivation
                                            1. lift-sin.f6445.7

                                              \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2} \]
                                          4. Applied rewrites45.7%

                                            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                                          5. Taylor expanded in lambda1 around inf

                                            \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]
                                          6. Step-by-step derivation
                                            1. Applied rewrites24.5%

                                              \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]
                                            2. Taylor expanded in phi2 around 0

                                              \[\leadsto \tan^{-1}_* \frac{\color{blue}{\sin \left(\lambda_1 - \lambda_2\right)}}{\sin \phi_2} \]
                                            3. Step-by-step derivation
                                              1. lift-sin.f64N/A

                                                \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\sin \phi_2} \]
                                              2. lift--.f6430.7

                                                \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\sin \phi_2} \]
                                            4. Applied rewrites30.7%

                                              \[\leadsto \tan^{-1}_* \frac{\color{blue}{\sin \left(\lambda_1 - \lambda_2\right)}}{\sin \phi_2} \]
                                            5. Taylor expanded in lambda1 around 0

                                              \[\leadsto \tan^{-1}_* \frac{\sin \left(\mathsf{neg}\left(\lambda_2\right)\right)}{\sin \phi_2} \]
                                            6. Step-by-step derivation
                                              1. sin-negN/A

                                                \[\leadsto \tan^{-1}_* \frac{\mathsf{neg}\left(\sin \lambda_2\right)}{\sin \phi_2} \]
                                              2. lower-neg.f64N/A

                                                \[\leadsto \tan^{-1}_* \frac{-\sin \lambda_2}{\sin \phi_2} \]
                                              3. lift-sin.f6427.5

                                                \[\leadsto \tan^{-1}_* \frac{-\sin \lambda_2}{\sin \phi_2} \]
                                            7. Applied rewrites27.5%

                                              \[\leadsto \tan^{-1}_* \frac{-\sin \lambda_2}{\sin \phi_2} \]
                                          7. Recombined 2 regimes into one program.
                                          8. Add Preprocessing

                                          Alternative 32: 24.1% accurate, 4.8× speedup?

                                          \[\begin{array}{l} \\ \tan^{-1}_* \frac{\sin \lambda_1}{\sin \phi_2} \end{array} \]
                                          (FPCore (lambda1 lambda2 phi1 phi2)
                                           :precision binary64
                                           (atan2 (sin lambda1) (sin phi2)))
                                          double code(double lambda1, double lambda2, double phi1, double phi2) {
                                          	return atan2(sin(lambda1), sin(phi2));
                                          }
                                          
                                          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, lambda2, phi1, phi2)
                                          use fmin_fmax_functions
                                              real(8), intent (in) :: lambda1
                                              real(8), intent (in) :: lambda2
                                              real(8), intent (in) :: phi1
                                              real(8), intent (in) :: phi2
                                              code = atan2(sin(lambda1), sin(phi2))
                                          end function
                                          
                                          public static double code(double lambda1, double lambda2, double phi1, double phi2) {
                                          	return Math.atan2(Math.sin(lambda1), Math.sin(phi2));
                                          }
                                          
                                          def code(lambda1, lambda2, phi1, phi2):
                                          	return math.atan2(math.sin(lambda1), math.sin(phi2))
                                          
                                          function code(lambda1, lambda2, phi1, phi2)
                                          	return atan(sin(lambda1), sin(phi2))
                                          end
                                          
                                          function tmp = code(lambda1, lambda2, phi1, phi2)
                                          	tmp = atan2(sin(lambda1), sin(phi2));
                                          end
                                          
                                          code[lambda1_, lambda2_, phi1_, phi2_] := N[ArcTan[N[Sin[lambda1], $MachinePrecision] / N[Sin[phi2], $MachinePrecision]], $MachinePrecision]
                                          
                                          \begin{array}{l}
                                          
                                          \\
                                          \tan^{-1}_* \frac{\sin \lambda_1}{\sin \phi_2}
                                          \end{array}
                                          
                                          Derivation
                                          1. Initial program 79.1%

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

                                            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                                          3. Step-by-step derivation
                                            1. lift-sin.f6449.1

                                              \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\sin \phi_2} \]
                                          4. Applied rewrites49.1%

                                            \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2}{\color{blue}{\sin \phi_2}} \]
                                          5. Taylor expanded in lambda1 around inf

                                            \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]
                                          6. Step-by-step derivation
                                            1. Applied rewrites32.5%

                                              \[\leadsto \tan^{-1}_* \frac{\sin \color{blue}{\lambda_1} \cdot \cos \phi_2}{\sin \phi_2} \]
                                            2. Taylor expanded in phi2 around 0

                                              \[\leadsto \tan^{-1}_* \frac{\color{blue}{\sin \left(\lambda_1 - \lambda_2\right)}}{\sin \phi_2} \]
                                            3. Step-by-step derivation
                                              1. lift-sin.f64N/A

                                                \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\sin \phi_2} \]
                                              2. lift--.f6431.9

                                                \[\leadsto \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\sin \phi_2} \]
                                            4. Applied rewrites31.9%

                                              \[\leadsto \tan^{-1}_* \frac{\color{blue}{\sin \left(\lambda_1 - \lambda_2\right)}}{\sin \phi_2} \]
                                            5. Taylor expanded in lambda1 around inf

                                              \[\leadsto \tan^{-1}_* \frac{\sin \lambda_1}{\sin \phi_2} \]
                                            6. Step-by-step derivation
                                              1. Applied rewrites24.1%

                                                \[\leadsto \tan^{-1}_* \frac{\sin \lambda_1}{\sin \phi_2} \]
                                              2. Add Preprocessing

                                              Reproduce

                                              ?
                                              herbie shell --seed 2025101 
                                              (FPCore (lambda1 lambda2 phi1 phi2)
                                                :name "Bearing on a great circle"
                                                :precision binary64
                                                (atan2 (* (sin (- lambda1 lambda2)) (cos phi2)) (- (* (cos phi1) (sin phi2)) (* (* (sin phi1) (cos phi2)) (cos (- lambda1 lambda2))))))