Midpoint on a great circle

Percentage Accurate: 98.6% → 98.6%
Time: 10.4s
Alternatives: 14
Speedup: 0.7×

Specification

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

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

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

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

Alternative 1: 98.6% accurate, 0.7× speedup?

\[\begin{array}{l} phi2_m = \left|\phi_2\right| \\ \lambda_1 + \tan^{-1}_* \frac{\cos phi2\_m \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \mathsf{fma}\left(\sin phi2\_m, \cos \left(\frac{\pi}{2}\right), \cos phi2\_m \cdot 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \end{array} \]
phi2_m = (fabs.f64 phi2)
(FPCore (lambda1 lambda2 phi1 phi2_m)
 :precision binary64
 (+
  lambda1
  (atan2
   (* (cos phi2_m) (sin (- lambda1 lambda2)))
   (+
    (cos phi1)
    (*
     (fma (sin phi2_m) (cos (/ PI 2.0)) (* (cos phi2_m) 1.0))
     (cos (- lambda1 lambda2)))))))
phi2_m = fabs(phi2);
double code(double lambda1, double lambda2, double phi1, double phi2_m) {
	return lambda1 + atan2((cos(phi2_m) * sin((lambda1 - lambda2))), (cos(phi1) + (fma(sin(phi2_m), cos((((double) M_PI) / 2.0)), (cos(phi2_m) * 1.0)) * cos((lambda1 - lambda2)))));
}
phi2_m = abs(phi2)
function code(lambda1, lambda2, phi1, phi2_m)
	return Float64(lambda1 + atan(Float64(cos(phi2_m) * sin(Float64(lambda1 - lambda2))), Float64(cos(phi1) + Float64(fma(sin(phi2_m), cos(Float64(pi / 2.0)), Float64(cos(phi2_m) * 1.0)) * cos(Float64(lambda1 - lambda2))))))
end
phi2_m = N[Abs[phi2], $MachinePrecision]
code[lambda1_, lambda2_, phi1_, phi2$95$m_] := N[(lambda1 + N[ArcTan[N[(N[Cos[phi2$95$m], $MachinePrecision] * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] + N[(N[(N[Sin[phi2$95$m], $MachinePrecision] * N[Cos[N[(Pi / 2.0), $MachinePrecision]], $MachinePrecision] + N[(N[Cos[phi2$95$m], $MachinePrecision] * 1.0), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
phi2_m = \left|\phi_2\right|

\\
\lambda_1 + \tan^{-1}_* \frac{\cos phi2\_m \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \mathsf{fma}\left(\sin phi2\_m, \cos \left(\frac{\pi}{2}\right), \cos phi2\_m \cdot 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)}
\end{array}
Derivation
  1. Initial program 98.6%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \mathsf{fma}\left(\sin \phi_2, \cos \left(\frac{\pi}{2}\right), \cos \phi_2 \cdot \sin \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{2}\right)}\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    13. lower-PI.f6498.6

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

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

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

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

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \mathsf{fma}\left(\sin \phi_2, \cos \left(\frac{\pi}{2}\right), \cos \phi_2 \cdot \sin \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{2}\right)}\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    4. sin-PI/298.6

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

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

Alternative 2: 98.6% accurate, 1.0× speedup?

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

\\
\lambda_1 + \tan^{-1}_* \frac{\cos phi2\_m \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos phi2\_m \cdot \cos \left(\lambda_1 - \lambda_2\right)}
\end{array}
Derivation
  1. Initial program 98.6%

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

Alternative 3: 98.0% accurate, 0.2× speedup?

\[\begin{array}{l} phi2_m = \left|\phi_2\right| \\ \begin{array}{l} t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\ t_1 := \cos phi2\_m \cdot t\_0\\ t_2 := \lambda_1 + \tan^{-1}_* \frac{t\_1}{\mathsf{fma}\left(\cos \lambda_1, \cos phi2\_m, \cos \phi_1\right)}\\ t_3 := \lambda_1 + \tan^{-1}_* \frac{t\_1}{\cos \phi_1 + \cos phi2\_m \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\ t_4 := \tan^{-1}_* \frac{t\_0 \cdot \cos phi2\_m}{\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), \cos phi2\_m, \cos \phi_1\right)}\\ \mathbf{if}\;t\_3 \leq -50:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_3 \leq -0.08:\\ \;\;\;\;t\_4\\ \mathbf{elif}\;t\_3 \leq 5 \cdot 10^{-7}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_3 \leq 3:\\ \;\;\;\;t\_4\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
phi2_m = (fabs.f64 phi2)
(FPCore (lambda1 lambda2 phi1 phi2_m)
 :precision binary64
 (let* ((t_0 (sin (- lambda1 lambda2)))
        (t_1 (* (cos phi2_m) t_0))
        (t_2
         (+ lambda1 (atan2 t_1 (fma (cos lambda1) (cos phi2_m) (cos phi1)))))
        (t_3
         (+
          lambda1
          (atan2
           t_1
           (+ (cos phi1) (* (cos phi2_m) (cos (- lambda1 lambda2)))))))
        (t_4
         (atan2
          (* t_0 (cos phi2_m))
          (fma (cos (- lambda2 lambda1)) (cos phi2_m) (cos phi1)))))
   (if (<= t_3 -50.0)
     t_2
     (if (<= t_3 -0.08)
       t_4
       (if (<= t_3 5e-7) t_2 (if (<= t_3 3.0) t_4 t_2))))))
phi2_m = fabs(phi2);
double code(double lambda1, double lambda2, double phi1, double phi2_m) {
	double t_0 = sin((lambda1 - lambda2));
	double t_1 = cos(phi2_m) * t_0;
	double t_2 = lambda1 + atan2(t_1, fma(cos(lambda1), cos(phi2_m), cos(phi1)));
	double t_3 = lambda1 + atan2(t_1, (cos(phi1) + (cos(phi2_m) * cos((lambda1 - lambda2)))));
	double t_4 = atan2((t_0 * cos(phi2_m)), fma(cos((lambda2 - lambda1)), cos(phi2_m), cos(phi1)));
	double tmp;
	if (t_3 <= -50.0) {
		tmp = t_2;
	} else if (t_3 <= -0.08) {
		tmp = t_4;
	} else if (t_3 <= 5e-7) {
		tmp = t_2;
	} else if (t_3 <= 3.0) {
		tmp = t_4;
	} else {
		tmp = t_2;
	}
	return tmp;
}
phi2_m = abs(phi2)
function code(lambda1, lambda2, phi1, phi2_m)
	t_0 = sin(Float64(lambda1 - lambda2))
	t_1 = Float64(cos(phi2_m) * t_0)
	t_2 = Float64(lambda1 + atan(t_1, fma(cos(lambda1), cos(phi2_m), cos(phi1))))
	t_3 = Float64(lambda1 + atan(t_1, Float64(cos(phi1) + Float64(cos(phi2_m) * cos(Float64(lambda1 - lambda2))))))
	t_4 = atan(Float64(t_0 * cos(phi2_m)), fma(cos(Float64(lambda2 - lambda1)), cos(phi2_m), cos(phi1)))
	tmp = 0.0
	if (t_3 <= -50.0)
		tmp = t_2;
	elseif (t_3 <= -0.08)
		tmp = t_4;
	elseif (t_3 <= 5e-7)
		tmp = t_2;
	elseif (t_3 <= 3.0)
		tmp = t_4;
	else
		tmp = t_2;
	end
	return tmp
end
phi2_m = N[Abs[phi2], $MachinePrecision]
code[lambda1_, lambda2_, phi1_, phi2$95$m_] := Block[{t$95$0 = N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi2$95$m], $MachinePrecision] * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(lambda1 + N[ArcTan[t$95$1 / N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi2$95$m], $MachinePrecision] + N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(lambda1 + N[ArcTan[t$95$1 / N[(N[Cos[phi1], $MachinePrecision] + N[(N[Cos[phi2$95$m], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[ArcTan[N[(t$95$0 * N[Cos[phi2$95$m], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2$95$m], $MachinePrecision] + N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$3, -50.0], t$95$2, If[LessEqual[t$95$3, -0.08], t$95$4, If[LessEqual[t$95$3, 5e-7], t$95$2, If[LessEqual[t$95$3, 3.0], t$95$4, t$95$2]]]]]]]]]
\begin{array}{l}
phi2_m = \left|\phi_2\right|

\\
\begin{array}{l}
t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\
t_1 := \cos phi2\_m \cdot t\_0\\
t_2 := \lambda_1 + \tan^{-1}_* \frac{t\_1}{\mathsf{fma}\left(\cos \lambda_1, \cos phi2\_m, \cos \phi_1\right)}\\
t_3 := \lambda_1 + \tan^{-1}_* \frac{t\_1}{\cos \phi_1 + \cos phi2\_m \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\
t_4 := \tan^{-1}_* \frac{t\_0 \cdot \cos phi2\_m}{\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), \cos phi2\_m, \cos \phi_1\right)}\\
\mathbf{if}\;t\_3 \leq -50:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_3 \leq -0.08:\\
\;\;\;\;t\_4\\

\mathbf{elif}\;t\_3 \leq 5 \cdot 10^{-7}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_3 \leq 3:\\
\;\;\;\;t\_4\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 lambda1 (atan2.f64 (*.f64 (cos.f64 phi2) (sin.f64 (-.f64 lambda1 lambda2))) (+.f64 (cos.f64 phi1) (*.f64 (cos.f64 phi2) (cos.f64 (-.f64 lambda1 lambda2)))))) < -50 or -0.0800000000000000017 < (+.f64 lambda1 (atan2.f64 (*.f64 (cos.f64 phi2) (sin.f64 (-.f64 lambda1 lambda2))) (+.f64 (cos.f64 phi1) (*.f64 (cos.f64 phi2) (cos.f64 (-.f64 lambda1 lambda2)))))) < 4.99999999999999977e-7 or 3 < (+.f64 lambda1 (atan2.f64 (*.f64 (cos.f64 phi2) (sin.f64 (-.f64 lambda1 lambda2))) (+.f64 (cos.f64 phi1) (*.f64 (cos.f64 phi2) (cos.f64 (-.f64 lambda1 lambda2))))))

    1. Initial program 99.0%

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

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

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

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

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

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

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

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

    if -50 < (+.f64 lambda1 (atan2.f64 (*.f64 (cos.f64 phi2) (sin.f64 (-.f64 lambda1 lambda2))) (+.f64 (cos.f64 phi1) (*.f64 (cos.f64 phi2) (cos.f64 (-.f64 lambda1 lambda2)))))) < -0.0800000000000000017 or 4.99999999999999977e-7 < (+.f64 lambda1 (atan2.f64 (*.f64 (cos.f64 phi2) (sin.f64 (-.f64 lambda1 lambda2))) (+.f64 (cos.f64 phi1) (*.f64 (cos.f64 phi2) (cos.f64 (-.f64 lambda1 lambda2)))))) < 3

    1. Initial program 97.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 97.8% accurate, 0.2× speedup?

\[\begin{array}{l} phi2_m = \left|\phi_2\right| \\ \begin{array}{l} t_0 := \lambda_1 + \tan^{-1}_* \frac{\cos phi2\_m \cdot \sin \lambda_1}{\mathsf{fma}\left(\cos \lambda_1, \cos phi2\_m, \cos \phi_1\right)}\\ t_1 := \sin \left(\lambda_1 - \lambda_2\right)\\ t_2 := \cos phi2\_m \cdot t\_1\\ t_3 := \lambda_1 + \tan^{-1}_* \frac{t\_2}{\cos \phi_1 + \cos phi2\_m \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\ t_4 := \tan^{-1}_* \frac{t\_1 \cdot \cos phi2\_m}{\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), \cos phi2\_m, \cos \phi_1\right)}\\ \mathbf{if}\;t\_3 \leq -50:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_3 \leq -0.04:\\ \;\;\;\;t\_4\\ \mathbf{elif}\;t\_3 \leq 5 \cdot 10^{-7}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_2}{\cos \phi_1 + \cos phi2\_m}\\ \mathbf{elif}\;t\_3 \leq 5:\\ \;\;\;\;t\_4\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
phi2_m = (fabs.f64 phi2)
(FPCore (lambda1 lambda2 phi1 phi2_m)
 :precision binary64
 (let* ((t_0
         (+
          lambda1
          (atan2
           (* (cos phi2_m) (sin lambda1))
           (fma (cos lambda1) (cos phi2_m) (cos phi1)))))
        (t_1 (sin (- lambda1 lambda2)))
        (t_2 (* (cos phi2_m) t_1))
        (t_3
         (+
          lambda1
          (atan2
           t_2
           (+ (cos phi1) (* (cos phi2_m) (cos (- lambda1 lambda2)))))))
        (t_4
         (atan2
          (* t_1 (cos phi2_m))
          (fma (cos (- lambda2 lambda1)) (cos phi2_m) (cos phi1)))))
   (if (<= t_3 -50.0)
     t_0
     (if (<= t_3 -0.04)
       t_4
       (if (<= t_3 5e-7)
         (+ lambda1 (atan2 t_2 (+ (cos phi1) (cos phi2_m))))
         (if (<= t_3 5.0) t_4 t_0))))))
phi2_m = fabs(phi2);
double code(double lambda1, double lambda2, double phi1, double phi2_m) {
	double t_0 = lambda1 + atan2((cos(phi2_m) * sin(lambda1)), fma(cos(lambda1), cos(phi2_m), cos(phi1)));
	double t_1 = sin((lambda1 - lambda2));
	double t_2 = cos(phi2_m) * t_1;
	double t_3 = lambda1 + atan2(t_2, (cos(phi1) + (cos(phi2_m) * cos((lambda1 - lambda2)))));
	double t_4 = atan2((t_1 * cos(phi2_m)), fma(cos((lambda2 - lambda1)), cos(phi2_m), cos(phi1)));
	double tmp;
	if (t_3 <= -50.0) {
		tmp = t_0;
	} else if (t_3 <= -0.04) {
		tmp = t_4;
	} else if (t_3 <= 5e-7) {
		tmp = lambda1 + atan2(t_2, (cos(phi1) + cos(phi2_m)));
	} else if (t_3 <= 5.0) {
		tmp = t_4;
	} else {
		tmp = t_0;
	}
	return tmp;
}
phi2_m = abs(phi2)
function code(lambda1, lambda2, phi1, phi2_m)
	t_0 = Float64(lambda1 + atan(Float64(cos(phi2_m) * sin(lambda1)), fma(cos(lambda1), cos(phi2_m), cos(phi1))))
	t_1 = sin(Float64(lambda1 - lambda2))
	t_2 = Float64(cos(phi2_m) * t_1)
	t_3 = Float64(lambda1 + atan(t_2, Float64(cos(phi1) + Float64(cos(phi2_m) * cos(Float64(lambda1 - lambda2))))))
	t_4 = atan(Float64(t_1 * cos(phi2_m)), fma(cos(Float64(lambda2 - lambda1)), cos(phi2_m), cos(phi1)))
	tmp = 0.0
	if (t_3 <= -50.0)
		tmp = t_0;
	elseif (t_3 <= -0.04)
		tmp = t_4;
	elseif (t_3 <= 5e-7)
		tmp = Float64(lambda1 + atan(t_2, Float64(cos(phi1) + cos(phi2_m))));
	elseif (t_3 <= 5.0)
		tmp = t_4;
	else
		tmp = t_0;
	end
	return tmp
end
phi2_m = N[Abs[phi2], $MachinePrecision]
code[lambda1_, lambda2_, phi1_, phi2$95$m_] := Block[{t$95$0 = N[(lambda1 + N[ArcTan[N[(N[Cos[phi2$95$m], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi2$95$m], $MachinePrecision] + N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Cos[phi2$95$m], $MachinePrecision] * t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(lambda1 + N[ArcTan[t$95$2 / N[(N[Cos[phi1], $MachinePrecision] + N[(N[Cos[phi2$95$m], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[ArcTan[N[(t$95$1 * N[Cos[phi2$95$m], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2$95$m], $MachinePrecision] + N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$3, -50.0], t$95$0, If[LessEqual[t$95$3, -0.04], t$95$4, If[LessEqual[t$95$3, 5e-7], N[(lambda1 + N[ArcTan[t$95$2 / N[(N[Cos[phi1], $MachinePrecision] + N[Cos[phi2$95$m], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 5.0], t$95$4, t$95$0]]]]]]]]]
\begin{array}{l}
phi2_m = \left|\phi_2\right|

\\
\begin{array}{l}
t_0 := \lambda_1 + \tan^{-1}_* \frac{\cos phi2\_m \cdot \sin \lambda_1}{\mathsf{fma}\left(\cos \lambda_1, \cos phi2\_m, \cos \phi_1\right)}\\
t_1 := \sin \left(\lambda_1 - \lambda_2\right)\\
t_2 := \cos phi2\_m \cdot t\_1\\
t_3 := \lambda_1 + \tan^{-1}_* \frac{t\_2}{\cos \phi_1 + \cos phi2\_m \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\
t_4 := \tan^{-1}_* \frac{t\_1 \cdot \cos phi2\_m}{\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), \cos phi2\_m, \cos \phi_1\right)}\\
\mathbf{if}\;t\_3 \leq -50:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;t\_3 \leq -0.04:\\
\;\;\;\;t\_4\\

\mathbf{elif}\;t\_3 \leq 5 \cdot 10^{-7}:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_2}{\cos \phi_1 + \cos phi2\_m}\\

\mathbf{elif}\;t\_3 \leq 5:\\
\;\;\;\;t\_4\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 lambda1 (atan2.f64 (*.f64 (cos.f64 phi2) (sin.f64 (-.f64 lambda1 lambda2))) (+.f64 (cos.f64 phi1) (*.f64 (cos.f64 phi2) (cos.f64 (-.f64 lambda1 lambda2)))))) < -50 or 5 < (+.f64 lambda1 (atan2.f64 (*.f64 (cos.f64 phi2) (sin.f64 (-.f64 lambda1 lambda2))) (+.f64 (cos.f64 phi1) (*.f64 (cos.f64 phi2) (cos.f64 (-.f64 lambda1 lambda2))))))

    1. Initial program 99.0%

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

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

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

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

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

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

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

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

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

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

      if -50 < (+.f64 lambda1 (atan2.f64 (*.f64 (cos.f64 phi2) (sin.f64 (-.f64 lambda1 lambda2))) (+.f64 (cos.f64 phi1) (*.f64 (cos.f64 phi2) (cos.f64 (-.f64 lambda1 lambda2)))))) < -0.0400000000000000008 or 4.99999999999999977e-7 < (+.f64 lambda1 (atan2.f64 (*.f64 (cos.f64 phi2) (sin.f64 (-.f64 lambda1 lambda2))) (+.f64 (cos.f64 phi1) (*.f64 (cos.f64 phi2) (cos.f64 (-.f64 lambda1 lambda2)))))) < 5

      1. Initial program 97.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -0.0400000000000000008 < (+.f64 lambda1 (atan2.f64 (*.f64 (cos.f64 phi2) (sin.f64 (-.f64 lambda1 lambda2))) (+.f64 (cos.f64 phi1) (*.f64 (cos.f64 phi2) (cos.f64 (-.f64 lambda1 lambda2)))))) < 4.99999999999999977e-7

      1. Initial program 99.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    Alternative 5: 97.3% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

    Alternative 6: 89.0% accurate, 1.1× speedup?

    \[\begin{array}{l} phi2_m = \left|\phi_2\right| \\ \begin{array}{l} t_0 := \cos phi2\_m \cdot \sin \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\phi_1 \leq 9 \cdot 10^{-22}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), \cos phi2\_m, 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \mathsf{fma}\left(phi2\_m \cdot phi2\_m, -0.5, 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\ \end{array} \end{array} \]
    phi2_m = (fabs.f64 phi2)
    (FPCore (lambda1 lambda2 phi1 phi2_m)
     :precision binary64
     (let* ((t_0 (* (cos phi2_m) (sin (- lambda1 lambda2)))))
       (if (<= phi1 9e-22)
         (+ lambda1 (atan2 t_0 (fma (cos (- lambda2 lambda1)) (cos phi2_m) 1.0)))
         (+
          lambda1
          (atan2
           t_0
           (+
            (cos phi1)
            (* (fma (* phi2_m phi2_m) -0.5 1.0) (cos (- lambda1 lambda2)))))))))
    phi2_m = fabs(phi2);
    double code(double lambda1, double lambda2, double phi1, double phi2_m) {
    	double t_0 = cos(phi2_m) * sin((lambda1 - lambda2));
    	double tmp;
    	if (phi1 <= 9e-22) {
    		tmp = lambda1 + atan2(t_0, fma(cos((lambda2 - lambda1)), cos(phi2_m), 1.0));
    	} else {
    		tmp = lambda1 + atan2(t_0, (cos(phi1) + (fma((phi2_m * phi2_m), -0.5, 1.0) * cos((lambda1 - lambda2)))));
    	}
    	return tmp;
    }
    
    phi2_m = abs(phi2)
    function code(lambda1, lambda2, phi1, phi2_m)
    	t_0 = Float64(cos(phi2_m) * sin(Float64(lambda1 - lambda2)))
    	tmp = 0.0
    	if (phi1 <= 9e-22)
    		tmp = Float64(lambda1 + atan(t_0, fma(cos(Float64(lambda2 - lambda1)), cos(phi2_m), 1.0)));
    	else
    		tmp = Float64(lambda1 + atan(t_0, Float64(cos(phi1) + Float64(fma(Float64(phi2_m * phi2_m), -0.5, 1.0) * cos(Float64(lambda1 - lambda2))))));
    	end
    	return tmp
    end
    
    phi2_m = N[Abs[phi2], $MachinePrecision]
    code[lambda1_, lambda2_, phi1_, phi2$95$m_] := Block[{t$95$0 = N[(N[Cos[phi2$95$m], $MachinePrecision] * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, 9e-22], N[(lambda1 + N[ArcTan[t$95$0 / N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2$95$m], $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(lambda1 + N[ArcTan[t$95$0 / N[(N[Cos[phi1], $MachinePrecision] + N[(N[(N[(phi2$95$m * phi2$95$m), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
    
    \begin{array}{l}
    phi2_m = \left|\phi_2\right|
    
    \\
    \begin{array}{l}
    t_0 := \cos phi2\_m \cdot \sin \left(\lambda_1 - \lambda_2\right)\\
    \mathbf{if}\;\phi_1 \leq 9 \cdot 10^{-22}:\\
    \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), \cos phi2\_m, 1\right)}\\
    
    \mathbf{else}:\\
    \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \mathsf{fma}\left(phi2\_m \cdot phi2\_m, -0.5, 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if phi1 < 8.99999999999999973e-22

      1. Initial program 98.6%

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

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

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

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

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

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

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

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

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

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

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

      if 8.99999999999999973e-22 < phi1

      1. Initial program 98.6%

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

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

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

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

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

          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \mathsf{fma}\left(\phi_2 \cdot \phi_2, \frac{-1}{2}, 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        5. lower-*.f6482.7

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

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

    Alternative 7: 84.3% accurate, 1.0× speedup?

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

      1. Initial program 98.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 0.99999499999999997 < (cos.f64 phi2)

      1. Initial program 98.7%

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \mathsf{fma}\left(\mathsf{fma}\left(\phi_2 \cdot \phi_2, \frac{1}{24}, \frac{-1}{2}\right), \phi_2 \cdot \color{blue}{\phi_2}, 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        11. lower-*.f6498.6

          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \mathsf{fma}\left(\mathsf{fma}\left(\phi_2 \cdot \phi_2, 0.041666666666666664, -0.5\right), \phi_2 \cdot \color{blue}{\phi_2}, 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      4. Applied rewrites98.6%

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

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

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

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

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

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

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

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

          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_2 - \lambda_1\right)} \]
        4. lower--.f6498.4

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

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

    Alternative 8: 80.7% accurate, 1.1× speedup?

    \[\begin{array}{l} phi2_m = \left|\phi_2\right| \\ \begin{array}{l} \mathbf{if}\;\cos phi2\_m \leq 0.5:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos phi2\_m \cdot \sin \left(\left(1 - \frac{\lambda_2}{\lambda_1}\right) \cdot \lambda_1\right)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, -0.5, 1\right) + 1 \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_2 - \lambda_1\right)}\\ \end{array} \end{array} \]
    phi2_m = (fabs.f64 phi2)
    (FPCore (lambda1 lambda2 phi1 phi2_m)
     :precision binary64
     (if (<= (cos phi2_m) 0.5)
       (+
        lambda1
        (atan2
         (* (cos phi2_m) (sin (* (- 1.0 (/ lambda2 lambda1)) lambda1)))
         (+ (fma (* phi1 phi1) -0.5 1.0) (* 1.0 (cos (- lambda1 lambda2))))))
       (+
        lambda1
        (atan2
         (sin (- lambda1 lambda2))
         (+ (cos phi1) (cos (- lambda2 lambda1)))))))
    phi2_m = fabs(phi2);
    double code(double lambda1, double lambda2, double phi1, double phi2_m) {
    	double tmp;
    	if (cos(phi2_m) <= 0.5) {
    		tmp = lambda1 + atan2((cos(phi2_m) * sin(((1.0 - (lambda2 / lambda1)) * lambda1))), (fma((phi1 * phi1), -0.5, 1.0) + (1.0 * cos((lambda1 - lambda2)))));
    	} else {
    		tmp = lambda1 + atan2(sin((lambda1 - lambda2)), (cos(phi1) + cos((lambda2 - lambda1))));
    	}
    	return tmp;
    }
    
    phi2_m = abs(phi2)
    function code(lambda1, lambda2, phi1, phi2_m)
    	tmp = 0.0
    	if (cos(phi2_m) <= 0.5)
    		tmp = Float64(lambda1 + atan(Float64(cos(phi2_m) * sin(Float64(Float64(1.0 - Float64(lambda2 / lambda1)) * lambda1))), Float64(fma(Float64(phi1 * phi1), -0.5, 1.0) + Float64(1.0 * cos(Float64(lambda1 - lambda2))))));
    	else
    		tmp = Float64(lambda1 + atan(sin(Float64(lambda1 - lambda2)), Float64(cos(phi1) + cos(Float64(lambda2 - lambda1)))));
    	end
    	return tmp
    end
    
    phi2_m = N[Abs[phi2], $MachinePrecision]
    code[lambda1_, lambda2_, phi1_, phi2$95$m_] := If[LessEqual[N[Cos[phi2$95$m], $MachinePrecision], 0.5], N[(lambda1 + N[ArcTan[N[(N[Cos[phi2$95$m], $MachinePrecision] * N[Sin[N[(N[(1.0 - N[(lambda2 / lambda1), $MachinePrecision]), $MachinePrecision] * lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(N[(N[(phi1 * phi1), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] + N[(1.0 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(lambda1 + N[ArcTan[N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] + N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    phi2_m = \left|\phi_2\right|
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\cos phi2\_m \leq 0.5:\\
    \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos phi2\_m \cdot \sin \left(\left(1 - \frac{\lambda_2}{\lambda_1}\right) \cdot \lambda_1\right)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, -0.5, 1\right) + 1 \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\
    
    \mathbf{else}:\\
    \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_2 - \lambda_1\right)}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (cos.f64 phi2) < 0.5

      1. Initial program 98.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\left(1 - \frac{\lambda_2}{\lambda_1}\right) \cdot \lambda_1\right)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, \frac{-1}{2}, 1\right) + 1 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          5. lower-*.f6463.2

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

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

        if 0.5 < (cos.f64 phi2)

        1. Initial program 98.7%

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \mathsf{fma}\left(\mathsf{fma}\left(\phi_2 \cdot \phi_2, \frac{1}{24}, \frac{-1}{2}\right), \phi_2 \cdot \color{blue}{\phi_2}, 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          11. lower-*.f6487.9

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

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

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

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

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

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

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

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

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

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_2 - \lambda_1\right)} \]
          4. lower--.f6489.2

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

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

      Alternative 9: 80.6% accurate, 1.1× speedup?

      \[\begin{array}{l} phi2_m = \left|\phi_2\right| \\ \begin{array}{l} \mathbf{if}\;\cos phi2\_m \leq 0.5:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos phi2\_m \cdot \sin \left(\left(1 - \frac{\lambda_2}{\lambda_1}\right) \cdot \lambda_1\right)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, -0.5, 1\right) + 1 \cdot \cos \lambda_1}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_2 - \lambda_1\right)}\\ \end{array} \end{array} \]
      phi2_m = (fabs.f64 phi2)
      (FPCore (lambda1 lambda2 phi1 phi2_m)
       :precision binary64
       (if (<= (cos phi2_m) 0.5)
         (+
          lambda1
          (atan2
           (* (cos phi2_m) (sin (* (- 1.0 (/ lambda2 lambda1)) lambda1)))
           (+ (fma (* phi1 phi1) -0.5 1.0) (* 1.0 (cos lambda1)))))
         (+
          lambda1
          (atan2
           (sin (- lambda1 lambda2))
           (+ (cos phi1) (cos (- lambda2 lambda1)))))))
      phi2_m = fabs(phi2);
      double code(double lambda1, double lambda2, double phi1, double phi2_m) {
      	double tmp;
      	if (cos(phi2_m) <= 0.5) {
      		tmp = lambda1 + atan2((cos(phi2_m) * sin(((1.0 - (lambda2 / lambda1)) * lambda1))), (fma((phi1 * phi1), -0.5, 1.0) + (1.0 * cos(lambda1))));
      	} else {
      		tmp = lambda1 + atan2(sin((lambda1 - lambda2)), (cos(phi1) + cos((lambda2 - lambda1))));
      	}
      	return tmp;
      }
      
      phi2_m = abs(phi2)
      function code(lambda1, lambda2, phi1, phi2_m)
      	tmp = 0.0
      	if (cos(phi2_m) <= 0.5)
      		tmp = Float64(lambda1 + atan(Float64(cos(phi2_m) * sin(Float64(Float64(1.0 - Float64(lambda2 / lambda1)) * lambda1))), Float64(fma(Float64(phi1 * phi1), -0.5, 1.0) + Float64(1.0 * cos(lambda1)))));
      	else
      		tmp = Float64(lambda1 + atan(sin(Float64(lambda1 - lambda2)), Float64(cos(phi1) + cos(Float64(lambda2 - lambda1)))));
      	end
      	return tmp
      end
      
      phi2_m = N[Abs[phi2], $MachinePrecision]
      code[lambda1_, lambda2_, phi1_, phi2$95$m_] := If[LessEqual[N[Cos[phi2$95$m], $MachinePrecision], 0.5], N[(lambda1 + N[ArcTan[N[(N[Cos[phi2$95$m], $MachinePrecision] * N[Sin[N[(N[(1.0 - N[(lambda2 / lambda1), $MachinePrecision]), $MachinePrecision] * lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(N[(N[(phi1 * phi1), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] + N[(1.0 * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(lambda1 + N[ArcTan[N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] + N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
      
      \begin{array}{l}
      phi2_m = \left|\phi_2\right|
      
      \\
      \begin{array}{l}
      \mathbf{if}\;\cos phi2\_m \leq 0.5:\\
      \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos phi2\_m \cdot \sin \left(\left(1 - \frac{\lambda_2}{\lambda_1}\right) \cdot \lambda_1\right)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, -0.5, 1\right) + 1 \cdot \cos \lambda_1}\\
      
      \mathbf{else}:\\
      \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_2 - \lambda_1\right)}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (cos.f64 phi2) < 0.5

        1. Initial program 98.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\left(1 - \frac{\lambda_2}{\lambda_1}\right) \cdot \lambda_1\right)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, \frac{-1}{2}, 1\right) + 1 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
            5. lower-*.f6463.2

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

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

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

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

            if 0.5 < (cos.f64 phi2)

            1. Initial program 98.7%

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \mathsf{fma}\left(\mathsf{fma}\left(\phi_2 \cdot \phi_2, \frac{1}{24}, \frac{-1}{2}\right), \phi_2 \cdot \color{blue}{\phi_2}, 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
              11. lower-*.f6487.9

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

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

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

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

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

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

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

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

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

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_2 - \lambda_1\right)} \]
              4. lower--.f6489.2

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

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

          Alternative 10: 80.6% accurate, 1.1× speedup?

          \[\begin{array}{l} phi2_m = \left|\phi_2\right| \\ \begin{array}{l} \mathbf{if}\;\cos phi2\_m \leq -0.05:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos phi2\_m \cdot \sin \left(-\lambda_2\right)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, -0.5, 1\right) + 1 \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_2 - \lambda_1\right)}\\ \end{array} \end{array} \]
          phi2_m = (fabs.f64 phi2)
          (FPCore (lambda1 lambda2 phi1 phi2_m)
           :precision binary64
           (if (<= (cos phi2_m) -0.05)
             (+
              lambda1
              (atan2
               (* (cos phi2_m) (sin (- lambda2)))
               (+ (fma (* phi1 phi1) -0.5 1.0) (* 1.0 (cos (- lambda1 lambda2))))))
             (+
              lambda1
              (atan2
               (sin (- lambda1 lambda2))
               (+ (cos phi1) (cos (- lambda2 lambda1)))))))
          phi2_m = fabs(phi2);
          double code(double lambda1, double lambda2, double phi1, double phi2_m) {
          	double tmp;
          	if (cos(phi2_m) <= -0.05) {
          		tmp = lambda1 + atan2((cos(phi2_m) * sin(-lambda2)), (fma((phi1 * phi1), -0.5, 1.0) + (1.0 * cos((lambda1 - lambda2)))));
          	} else {
          		tmp = lambda1 + atan2(sin((lambda1 - lambda2)), (cos(phi1) + cos((lambda2 - lambda1))));
          	}
          	return tmp;
          }
          
          phi2_m = abs(phi2)
          function code(lambda1, lambda2, phi1, phi2_m)
          	tmp = 0.0
          	if (cos(phi2_m) <= -0.05)
          		tmp = Float64(lambda1 + atan(Float64(cos(phi2_m) * sin(Float64(-lambda2))), Float64(fma(Float64(phi1 * phi1), -0.5, 1.0) + Float64(1.0 * cos(Float64(lambda1 - lambda2))))));
          	else
          		tmp = Float64(lambda1 + atan(sin(Float64(lambda1 - lambda2)), Float64(cos(phi1) + cos(Float64(lambda2 - lambda1)))));
          	end
          	return tmp
          end
          
          phi2_m = N[Abs[phi2], $MachinePrecision]
          code[lambda1_, lambda2_, phi1_, phi2$95$m_] := If[LessEqual[N[Cos[phi2$95$m], $MachinePrecision], -0.05], N[(lambda1 + N[ArcTan[N[(N[Cos[phi2$95$m], $MachinePrecision] * N[Sin[(-lambda2)], $MachinePrecision]), $MachinePrecision] / N[(N[(N[(phi1 * phi1), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] + N[(1.0 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(lambda1 + N[ArcTan[N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] + N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
          
          \begin{array}{l}
          phi2_m = \left|\phi_2\right|
          
          \\
          \begin{array}{l}
          \mathbf{if}\;\cos phi2\_m \leq -0.05:\\
          \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos phi2\_m \cdot \sin \left(-\lambda_2\right)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, -0.5, 1\right) + 1 \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\
          
          \mathbf{else}:\\
          \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_2 - \lambda_1\right)}\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (cos.f64 phi2) < -0.050000000000000003

            1. Initial program 98.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              if -0.050000000000000003 < (cos.f64 phi2)

              1. Initial program 98.6%

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \mathsf{fma}\left(\mathsf{fma}\left(\phi_2 \cdot \phi_2, \frac{1}{24}, \frac{-1}{2}\right), \phi_2 \cdot \color{blue}{\phi_2}, 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
                11. lower-*.f6484.5

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

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

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

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

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

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

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

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

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

                  \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_2 - \lambda_1\right)} \]
                4. lower--.f6485.9

                  \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_2 - \lambda_1\right)} \]
              10. Applied rewrites85.9%

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

            Alternative 11: 79.6% accurate, 1.1× speedup?

            \[\begin{array}{l} phi2_m = \left|\phi_2\right| \\ \begin{array}{l} \mathbf{if}\;\cos phi2\_m \leq 0.5:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos phi2\_m \cdot \sin \lambda_1}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, -0.5, 1\right) + 1 \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_2 - \lambda_1\right)}\\ \end{array} \end{array} \]
            phi2_m = (fabs.f64 phi2)
            (FPCore (lambda1 lambda2 phi1 phi2_m)
             :precision binary64
             (if (<= (cos phi2_m) 0.5)
               (+
                lambda1
                (atan2
                 (* (cos phi2_m) (sin lambda1))
                 (+ (fma (* phi1 phi1) -0.5 1.0) (* 1.0 (cos (- lambda1 lambda2))))))
               (+
                lambda1
                (atan2
                 (sin (- lambda1 lambda2))
                 (+ (cos phi1) (cos (- lambda2 lambda1)))))))
            phi2_m = fabs(phi2);
            double code(double lambda1, double lambda2, double phi1, double phi2_m) {
            	double tmp;
            	if (cos(phi2_m) <= 0.5) {
            		tmp = lambda1 + atan2((cos(phi2_m) * sin(lambda1)), (fma((phi1 * phi1), -0.5, 1.0) + (1.0 * cos((lambda1 - lambda2)))));
            	} else {
            		tmp = lambda1 + atan2(sin((lambda1 - lambda2)), (cos(phi1) + cos((lambda2 - lambda1))));
            	}
            	return tmp;
            }
            
            phi2_m = abs(phi2)
            function code(lambda1, lambda2, phi1, phi2_m)
            	tmp = 0.0
            	if (cos(phi2_m) <= 0.5)
            		tmp = Float64(lambda1 + atan(Float64(cos(phi2_m) * sin(lambda1)), Float64(fma(Float64(phi1 * phi1), -0.5, 1.0) + Float64(1.0 * cos(Float64(lambda1 - lambda2))))));
            	else
            		tmp = Float64(lambda1 + atan(sin(Float64(lambda1 - lambda2)), Float64(cos(phi1) + cos(Float64(lambda2 - lambda1)))));
            	end
            	return tmp
            end
            
            phi2_m = N[Abs[phi2], $MachinePrecision]
            code[lambda1_, lambda2_, phi1_, phi2$95$m_] := If[LessEqual[N[Cos[phi2$95$m], $MachinePrecision], 0.5], N[(lambda1 + N[ArcTan[N[(N[Cos[phi2$95$m], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision]), $MachinePrecision] / N[(N[(N[(phi1 * phi1), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] + N[(1.0 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(lambda1 + N[ArcTan[N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] + N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
            
            \begin{array}{l}
            phi2_m = \left|\phi_2\right|
            
            \\
            \begin{array}{l}
            \mathbf{if}\;\cos phi2\_m \leq 0.5:\\
            \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos phi2\_m \cdot \sin \lambda_1}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, -0.5, 1\right) + 1 \cdot \cos \left(\lambda_1 - \lambda_2\right)}\\
            
            \mathbf{else}:\\
            \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_2 - \lambda_1\right)}\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if (cos.f64 phi2) < 0.5

              1. Initial program 98.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\left(1 - \frac{\lambda_2}{\lambda_1}\right) \cdot \lambda_1\right)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, \frac{-1}{2}, 1\right) + 1 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
                  5. lower-*.f6463.2

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

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

                  \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \lambda_1}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, \frac{-1}{2}, 1\right) + 1 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
                6. Step-by-step derivation
                  1. Applied rewrites60.0%

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

                  if 0.5 < (cos.f64 phi2)

                  1. Initial program 98.7%

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \mathsf{fma}\left(\mathsf{fma}\left(\phi_2 \cdot \phi_2, \frac{1}{24}, \frac{-1}{2}\right), \phi_2 \cdot \color{blue}{\phi_2}, 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
                    11. lower-*.f6487.9

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

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

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

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

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

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

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

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

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

                      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_2 - \lambda_1\right)} \]
                    4. lower--.f6489.2

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

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

                Alternative 12: 77.6% accurate, 1.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_2 - \lambda_1\right)} \]
                  4. lower--.f6477.6

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

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

                Alternative 13: 67.3% accurate, 2.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{1} + \mathsf{fma}\left(\mathsf{fma}\left(\phi_2 \cdot \phi_2, \frac{1}{24}, \frac{-1}{2}\right), \phi_2 \cdot \phi_2, 1\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
                9. Step-by-step derivation
                  1. Applied rewrites66.4%

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

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

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

                    Alternative 14: 53.0% accurate, 192.4× speedup?

                    \[\begin{array}{l} phi2_m = \left|\phi_2\right| \\ \lambda_1 \end{array} \]
                    phi2_m = (fabs.f64 phi2)
                    (FPCore (lambda1 lambda2 phi1 phi2_m) :precision binary64 lambda1)
                    phi2_m = fabs(phi2);
                    double code(double lambda1, double lambda2, double phi1, double phi2_m) {
                    	return lambda1;
                    }
                    
                    phi2_m =     private
                    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_m)
                    use fmin_fmax_functions
                        real(8), intent (in) :: lambda1
                        real(8), intent (in) :: lambda2
                        real(8), intent (in) :: phi1
                        real(8), intent (in) :: phi2_m
                        code = lambda1
                    end function
                    
                    phi2_m = Math.abs(phi2);
                    public static double code(double lambda1, double lambda2, double phi1, double phi2_m) {
                    	return lambda1;
                    }
                    
                    phi2_m = math.fabs(phi2)
                    def code(lambda1, lambda2, phi1, phi2_m):
                    	return lambda1
                    
                    phi2_m = abs(phi2)
                    function code(lambda1, lambda2, phi1, phi2_m)
                    	return lambda1
                    end
                    
                    phi2_m = abs(phi2);
                    function tmp = code(lambda1, lambda2, phi1, phi2_m)
                    	tmp = lambda1;
                    end
                    
                    phi2_m = N[Abs[phi2], $MachinePrecision]
                    code[lambda1_, lambda2_, phi1_, phi2$95$m_] := lambda1
                    
                    \begin{array}{l}
                    phi2_m = \left|\phi_2\right|
                    
                    \\
                    \lambda_1
                    \end{array}
                    
                    Derivation
                    1. Initial program 98.6%

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

                      \[\leadsto \color{blue}{\lambda_1} \]
                    3. Step-by-step derivation
                      1. Applied rewrites53.0%

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

                      Reproduce

                      ?
                      herbie shell --seed 2025118 
                      (FPCore (lambda1 lambda2 phi1 phi2)
                        :name "Midpoint on a great circle"
                        :precision binary64
                        (+ lambda1 (atan2 (* (cos phi2) (sin (- lambda1 lambda2))) (+ (cos phi1) (* (cos phi2) (cos (- lambda1 lambda2)))))))