Midpoint on a great circle

Percentage Accurate: 98.8% → 99.7%
Time: 10.1s
Alternatives: 20
Speedup: 1.0×

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 20 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.8% 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: 99.7% accurate, 0.5× speedup?

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

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

    \[\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--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 98.8% accurate, 0.7× speedup?

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

    \[\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--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 98.8% 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}
Derivation
  1. Initial program 98.8%

    \[\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 4: 90.6% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
t_1 := \sin \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\cos \phi_2 \leq 0.997:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot t\_1}{\mathsf{fma}\left(t\_0, \cos \phi_2, 1\right) + \left(\mathsf{fma}\left(-0.001388888888888889, \phi_1 \cdot \phi_1, 0.041666666666666664\right) \cdot \left(\phi_1 \cdot \phi_1\right) - 0.5\right) \cdot \left(\phi_1 \cdot \phi_1\right)}\\

\mathbf{else}:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{1 \cdot t\_1}{\cos \phi_1 + 1 \cdot t\_0}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 phi2) < 0.996999999999999997

    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 + \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right) + {\phi_1}^{2} \cdot \left({\phi_1}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_1}^{2}\right) - \frac{1}{2}\right)\right)}} \]
    3. Step-by-step derivation
      1. associate-+r+N/A

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

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

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

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2 + 1\right) + {\color{blue}{\phi_1}}^{2} \cdot \left({\phi_1}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_1}^{2}\right) - \frac{1}{2}\right)} \]
      5. 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), \cos \phi_2, 1\right) + \color{blue}{{\phi_1}^{2}} \cdot \left({\phi_1}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_1}^{2}\right) - \frac{1}{2}\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 \left(\lambda_1 - \lambda_2\right), \cos \phi_2, 1\right) + {\color{blue}{\phi_1}}^{2} \cdot \left({\phi_1}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_1}^{2}\right) - \frac{1}{2}\right)} \]
      7. lift--.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), \cos \phi_2, 1\right) + {\phi_1}^{2} \cdot \left({\phi_1}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_1}^{2}\right) - \frac{1}{2}\right)} \]
      8. 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 \left(\lambda_1 - \lambda_2\right), \cos \phi_2, 1\right) + {\phi_1}^{\color{blue}{2}} \cdot \left({\phi_1}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_1}^{2}\right) - \frac{1}{2}\right)} \]
      9. *-commutativeN/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), \cos \phi_2, 1\right) + \left({\phi_1}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_1}^{2}\right) - \frac{1}{2}\right) \cdot \color{blue}{{\phi_1}^{2}}} \]
      10. 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_1 - \lambda_2\right), \cos \phi_2, 1\right) + \left({\phi_1}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {\phi_1}^{2}\right) - \frac{1}{2}\right) \cdot \color{blue}{{\phi_1}^{2}}} \]
    4. Applied rewrites83.3%

      \[\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_1 - \lambda_2\right), \cos \phi_2, 1\right) + \left(\mathsf{fma}\left(-0.001388888888888889, \phi_1 \cdot \phi_1, 0.041666666666666664\right) \cdot \left(\phi_1 \cdot \phi_1\right) - 0.5\right) \cdot \left(\phi_1 \cdot \phi_1\right)}} \]

    if 0.996999999999999997 < (cos.f64 phi2)

    1. Initial program 98.9%

      \[\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{\color{blue}{1} \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. Applied rewrites97.7%

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{1} \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{1 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \color{blue}{1} \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      3. Step-by-step derivation
        1. Applied rewrites97.7%

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

      Alternative 5: 90.5% accurate, 0.9× speedup?

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

        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}{\left(1 + \frac{-1}{2} \cdot {\phi_1}^{2}\right)} + \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)}{\left(\frac{-1}{2} \cdot {\phi_1}^{2} + \color{blue}{1}\right) + \cos \phi_2 \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)}{\left({\phi_1}^{2} \cdot \frac{-1}{2} + 1\right) + \cos \phi_2 \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)}{\mathsf{fma}\left({\phi_1}^{2}, \color{blue}{\frac{-1}{2}}, 1\right) + \cos \phi_2 \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)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, \frac{-1}{2}, 1\right) + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          5. lower-*.f6483.2

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

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

        if 0.996999999999999997 < (cos.f64 phi2)

        1. Initial program 98.9%

          \[\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{\color{blue}{1} \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. Applied rewrites97.7%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{1} \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{1 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \color{blue}{1} \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          3. Step-by-step derivation
            1. Applied rewrites97.7%

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

          Alternative 6: 88.5% accurate, 1.0× speedup?

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

            1. Initial program 98.8%

              \[\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{\color{blue}{\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. lift-sin.f64N/A

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

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

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

            if 0.999999851377671889 < (cos.f64 phi1)

            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 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. 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 \left(\lambda_1 - \lambda_2\right), \cos \color{blue}{\phi_2}, 1\right)} \]
              5. lift--.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), \cos \phi_2, 1\right)} \]
              6. lift-cos.f6498.6

                \[\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), \cos \phi_2, 1\right)} \]
            4. Applied rewrites98.6%

              \[\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_1 - \lambda_2\right), \cos \phi_2, 1\right)}} \]
          3. Recombined 2 regimes into one program.
          4. Add Preprocessing

          Alternative 7: 88.2% accurate, 1.0× speedup?

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

            1. Initial program 98.8%

              \[\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{\color{blue}{\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. lift-sin.f64N/A

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

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

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

            if 0.999999851377671889 < (cos.f64 phi1)

            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 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. 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 \left(\lambda_1 - \lambda_2\right), \cos \color{blue}{\phi_2}, 1\right)} \]
              5. lift--.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), \cos \phi_2, 1\right)} \]
              6. lift-cos.f6498.6

                \[\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), \cos \phi_2, 1\right)} \]
            4. Applied rewrites98.6%

              \[\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_1 - \lambda_2\right), \cos \phi_2, 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)}{1 + \color{blue}{\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)}} \]
            6. 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) + 1} \]
              2. cos-neg-revN/A

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

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \lambda_2 \cdot \cos \phi_2 + 1} \]
              4. 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_2, \cos \phi_2, 1\right)} \]
              5. 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, 1\right)} \]
              6. 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, 1\right)} \]
            7. Applied rewrites98.0%

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

          Alternative 8: 88.2% accurate, 1.0× speedup?

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

            1. Initial program 98.8%

              \[\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{\color{blue}{\left(1 + \frac{-1}{2} \cdot {\phi_2}^{2}\right)} \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. +-commutativeN/A

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

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

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

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

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\mathsf{fma}\left(\phi_2 \cdot \phi_2, -0.5, 1\right)} \cdot \sin \left(\lambda_1 - \lambda_2\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{\mathsf{fma}\left(\phi_2 \cdot \phi_2, \frac{-1}{2}, 1\right) \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)} \]
            6. Step-by-step derivation
              1. +-commutativeN/A

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\mathsf{fma}\left(\phi_2 \cdot \phi_2, \frac{-1}{2}, 1\right) \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{\mathsf{fma}\left(\phi_2 \cdot \phi_2, \frac{-1}{2}, 1\right) \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{\mathsf{fma}\left(\phi_2 \cdot \phi_2, \frac{-1}{2}, 1\right) \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{\mathsf{fma}\left(\phi_2 \cdot \phi_2, \frac{-1}{2}, 1\right) \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-*.f6478.2

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\mathsf{fma}\left(\phi_2 \cdot \phi_2, -0.5, 1\right) \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)} \]
            7. Applied rewrites78.2%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\mathsf{fma}\left(\phi_2 \cdot \phi_2, -0.5, 1\right) \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)} \]

            if 0.999999851377671889 < (cos.f64 phi1)

            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 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. 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 \left(\lambda_1 - \lambda_2\right), \cos \color{blue}{\phi_2}, 1\right)} \]
              5. lift--.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), \cos \phi_2, 1\right)} \]
              6. lift-cos.f6498.6

                \[\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), \cos \phi_2, 1\right)} \]
            4. Applied rewrites98.6%

              \[\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_1 - \lambda_2\right), \cos \phi_2, 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)}{1 + \color{blue}{\cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)}} \]
            6. 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) + 1} \]
              2. cos-neg-revN/A

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

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \lambda_2 \cdot \cos \phi_2 + 1} \]
              4. 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_2, \cos \phi_2, 1\right)} \]
              5. 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, 1\right)} \]
              6. 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, 1\right)} \]
            7. Applied rewrites98.0%

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

          Alternative 9: 81.0% accurate, 1.2× speedup?

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

            1. Initial program 98.8%

              \[\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{\color{blue}{\left(1 + \frac{-1}{2} \cdot {\phi_2}^{2}\right)} \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. +-commutativeN/A

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

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

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

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

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{\mathsf{fma}\left(\phi_2 \cdot \phi_2, -0.5, 1\right)} \cdot \sin \left(\lambda_1 - \lambda_2\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{\mathsf{fma}\left(\phi_2 \cdot \phi_2, \frac{-1}{2}, 1\right) \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)} \]
            6. Step-by-step derivation
              1. +-commutativeN/A

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\mathsf{fma}\left(\phi_2 \cdot \phi_2, \frac{-1}{2}, 1\right) \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{\mathsf{fma}\left(\phi_2 \cdot \phi_2, \frac{-1}{2}, 1\right) \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{\mathsf{fma}\left(\phi_2 \cdot \phi_2, \frac{-1}{2}, 1\right) \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{\mathsf{fma}\left(\phi_2 \cdot \phi_2, \frac{-1}{2}, 1\right) \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-*.f6483.4

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\mathsf{fma}\left(\phi_2 \cdot \phi_2, -0.5, 1\right) \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)} \]
            7. Applied rewrites83.4%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\mathsf{fma}\left(\phi_2 \cdot \phi_2, -0.5, 1\right) \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)} \]

            if 1.25000000000000006e25 < 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 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. 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 \left(\lambda_1 - \lambda_2\right), \cos \color{blue}{\phi_2}, 1\right)} \]
              5. lift--.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), \cos \phi_2, 1\right)} \]
              6. lift-cos.f6479.5

                \[\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), \cos \phi_2, 1\right)} \]
            4. Applied rewrites79.5%

              \[\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_1 - \lambda_2\right), \cos \phi_2, 1\right)}} \]
            5. Taylor expanded in lambda1 around 0

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \color{blue}{\left(-1 \cdot \lambda_2\right)}}{\mathsf{fma}\left(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_2, 1\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(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_2, 1\right)} \]
              2. lower-neg.f6473.5

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          Alternative 10: 80.8% accurate, 1.1× speedup?

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

            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}{\left(1 + \frac{-1}{2} \cdot {\phi_1}^{2}\right)} + \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)}{\left(\frac{-1}{2} \cdot {\phi_1}^{2} + \color{blue}{1}\right) + \cos \phi_2 \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)}{\left({\phi_1}^{2} \cdot \frac{-1}{2} + 1\right) + \cos \phi_2 \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)}{\mathsf{fma}\left({\phi_1}^{2}, \color{blue}{\frac{-1}{2}}, 1\right) + \cos \phi_2 \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)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, \frac{-1}{2}, 1\right) + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
              5. lower-*.f6483.8

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, -0.5, 1\right)} + \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(\lambda_1 - \lambda_2\right)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, \frac{-1}{2}, 1\right) + \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)}} \]
            6. 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)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, \frac{-1}{2}, 1\right) + \cos \left(\lambda_1 - \lambda_2\right)} \]
              2. lift--.f6463.9

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

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

            if 0.849999999999999978 < (cos.f64 phi2)

            1. Initial program 98.9%

              \[\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{\color{blue}{1} \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. Applied rewrites93.0%

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{1} \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{1 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \color{blue}{1} \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
              3. Step-by-step derivation
                1. Applied rewrites93.0%

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

              Alternative 11: 79.1% accurate, 1.2× speedup?

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

                1. Initial program 98.4%

                  \[\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. 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 \left(\lambda_1 - \lambda_2\right), \cos \color{blue}{\phi_2}, 1\right)} \]
                  5. lift--.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), \cos \phi_2, 1\right)} \]
                  6. lift-cos.f6478.1

                    \[\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), \cos \phi_2, 1\right)} \]
                4. Applied rewrites78.1%

                  \[\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_1 - \lambda_2\right), \cos \phi_2, 1\right)}} \]
                5. Taylor expanded in phi2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                if 0.050000000000000003 < (cos.f64 phi2)

                1. Initial program 98.9%

                  \[\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{\color{blue}{1} \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. Applied rewrites86.7%

                    \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\color{blue}{1} \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{1 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \color{blue}{1} \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
                  3. Step-by-step derivation
                    1. Applied rewrites85.9%

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

                  Alternative 12: 68.8% accurate, 1.3× speedup?

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

                    1. Initial program 98.4%

                      \[\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. 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 \left(\lambda_1 - \lambda_2\right), \cos \color{blue}{\phi_2}, 1\right)} \]
                      5. lift--.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), \cos \phi_2, 1\right)} \]
                      6. lift-cos.f6478.1

                        \[\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), \cos \phi_2, 1\right)} \]
                    4. Applied rewrites78.1%

                      \[\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_1 - \lambda_2\right), \cos \phi_2, 1\right)}} \]
                    5. Taylor expanded in phi2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    if 0.050000000000000003 < (cos.f64 phi2)

                    1. Initial program 98.9%

                      \[\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}{\left(1 + \frac{-1}{2} \cdot {\phi_1}^{2}\right)} + \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)}{\left(\frac{-1}{2} \cdot {\phi_1}^{2} + \color{blue}{1}\right) + \cos \phi_2 \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)}{\left({\phi_1}^{2} \cdot \frac{-1}{2} + 1\right) + \cos \phi_2 \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)}{\mathsf{fma}\left({\phi_1}^{2}, \color{blue}{\frac{-1}{2}}, 1\right) + \cos \phi_2 \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)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, \frac{-1}{2}, 1\right) + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
                      5. lower-*.f6478.4

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

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

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

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

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

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

                      Alternative 13: 68.5% accurate, 1.3× speedup?

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

                        1. Initial program 98.4%

                          \[\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. 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 \left(\lambda_1 - \lambda_2\right), \cos \color{blue}{\phi_2}, 1\right)} \]
                          5. lift--.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), \cos \phi_2, 1\right)} \]
                          6. lift-cos.f6478.1

                            \[\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), \cos \phi_2, 1\right)} \]
                        4. Applied rewrites78.1%

                          \[\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_1 - \lambda_2\right), \cos \phi_2, 1\right)}} \]
                        5. Taylor expanded in lambda1 around 0

                          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \color{blue}{\left(-1 \cdot \lambda_2\right)}}{\mathsf{fma}\left(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_2, 1\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(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_2, 1\right)} \]
                          2. lower-neg.f6471.5

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        if 0.050000000000000003 < (cos.f64 phi2)

                        1. Initial program 98.9%

                          \[\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}{\left(1 + \frac{-1}{2} \cdot {\phi_1}^{2}\right)} + \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)}{\left(\frac{-1}{2} \cdot {\phi_1}^{2} + \color{blue}{1}\right) + \cos \phi_2 \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)}{\left({\phi_1}^{2} \cdot \frac{-1}{2} + 1\right) + \cos \phi_2 \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)}{\mathsf{fma}\left({\phi_1}^{2}, \color{blue}{\frac{-1}{2}}, 1\right) + \cos \phi_2 \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)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, \frac{-1}{2}, 1\right) + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
                          5. lower-*.f6478.4

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

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

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

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

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

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

                          Alternative 14: 68.5% accurate, 1.5× speedup?

                          \[\begin{array}{l} \\ \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \left(\lambda_2 - \lambda_1\right) + 1} \end{array} \]
                          (FPCore (lambda1 lambda2 phi1 phi2)
                           :precision binary64
                           (+
                            lambda1
                            (atan2
                             (* (cos phi2) (sin (- lambda1 lambda2)))
                             (+ (cos (- lambda2 lambda1)) 1.0))))
                          double code(double lambda1, double lambda2, double phi1, double phi2) {
                          	return lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos((lambda2 - lambda1)) + 1.0));
                          }
                          
                          module fmin_fmax_functions
                              implicit none
                              private
                              public fmax
                              public fmin
                          
                              interface fmax
                                  module procedure fmax88
                                  module procedure fmax44
                                  module procedure fmax84
                                  module procedure fmax48
                              end interface
                              interface fmin
                                  module procedure fmin88
                                  module procedure fmin44
                                  module procedure fmin84
                                  module procedure fmin48
                              end interface
                          contains
                              real(8) function fmax88(x, y) result (res)
                                  real(8), intent (in) :: x
                                  real(8), intent (in) :: y
                                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                              end function
                              real(4) function fmax44(x, y) result (res)
                                  real(4), intent (in) :: x
                                  real(4), intent (in) :: y
                                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                              end function
                              real(8) function fmax84(x, y) result(res)
                                  real(8), intent (in) :: x
                                  real(4), intent (in) :: y
                                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                              end function
                              real(8) function fmax48(x, y) result(res)
                                  real(4), intent (in) :: x
                                  real(8), intent (in) :: y
                                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                              end function
                              real(8) function fmin88(x, y) result (res)
                                  real(8), intent (in) :: x
                                  real(8), intent (in) :: y
                                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                              end function
                              real(4) function fmin44(x, y) result (res)
                                  real(4), intent (in) :: x
                                  real(4), intent (in) :: y
                                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                              end function
                              real(8) function fmin84(x, y) result(res)
                                  real(8), intent (in) :: x
                                  real(4), intent (in) :: y
                                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                              end function
                              real(8) function fmin48(x, y) result(res)
                                  real(4), intent (in) :: x
                                  real(8), intent (in) :: y
                                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                              end function
                          end module
                          
                          real(8) function code(lambda1, 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((lambda2 - lambda1)) + 1.0d0))
                          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((lambda2 - lambda1)) + 1.0));
                          }
                          
                          def code(lambda1, lambda2, phi1, phi2):
                          	return lambda1 + math.atan2((math.cos(phi2) * math.sin((lambda1 - lambda2))), (math.cos((lambda2 - lambda1)) + 1.0))
                          
                          function code(lambda1, lambda2, phi1, phi2)
                          	return Float64(lambda1 + atan(Float64(cos(phi2) * sin(Float64(lambda1 - lambda2))), Float64(cos(Float64(lambda2 - lambda1)) + 1.0)))
                          end
                          
                          function tmp = code(lambda1, lambda2, phi1, phi2)
                          	tmp = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos((lambda2 - lambda1)) + 1.0));
                          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[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
                          
                          \begin{array}{l}
                          
                          \\
                          \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \left(\lambda_2 - \lambda_1\right) + 1}
                          \end{array}
                          
                          Derivation
                          1. Initial program 98.8%

                            \[\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. 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 \left(\lambda_1 - \lambda_2\right), \cos \color{blue}{\phi_2}, 1\right)} \]
                            5. lift--.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), \cos \phi_2, 1\right)} \]
                            6. lift-cos.f6478.9

                              \[\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), \cos \phi_2, 1\right)} \]
                          4. Applied rewrites78.9%

                            \[\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_1 - \lambda_2\right), \cos \phi_2, 1\right)}} \]
                          5. Taylor expanded in phi2 around 0

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

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

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

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

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

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

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

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

                          Alternative 15: 67.0% accurate, 1.8× speedup?

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

                            \[\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}{\left(1 + \frac{-1}{2} \cdot {\phi_1}^{2}\right)} + \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)}{\left(\frac{-1}{2} \cdot {\phi_1}^{2} + \color{blue}{1}\right) + \cos \phi_2 \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)}{\left({\phi_1}^{2} \cdot \frac{-1}{2} + 1\right) + \cos \phi_2 \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)}{\mathsf{fma}\left({\phi_1}^{2}, \color{blue}{\frac{-1}{2}}, 1\right) + \cos \phi_2 \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)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, \frac{-1}{2}, 1\right) + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
                            5. lower-*.f6480.4

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

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

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

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

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

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

                              Alternative 16: 66.9% accurate, 2.0× speedup?

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

                                \[\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}{\left(1 + \frac{-1}{2} \cdot {\phi_1}^{2}\right)} + \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)}{\left(\frac{-1}{2} \cdot {\phi_1}^{2} + \color{blue}{1}\right) + \cos \phi_2 \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)}{\left({\phi_1}^{2} \cdot \frac{-1}{2} + 1\right) + \cos \phi_2 \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)}{\mathsf{fma}\left({\phi_1}^{2}, \color{blue}{\frac{-1}{2}}, 1\right) + \cos \phi_2 \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)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, \frac{-1}{2}, 1\right) + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
                                5. lower-*.f6480.4

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

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

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

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

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

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

                                    \[\leadsto \lambda_1 + \tan^{-1}_* \frac{1 \cdot \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.0%

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

                                    Alternative 17: 66.5% accurate, 2.0× speedup?

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

                                      \[\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}{\left(1 + \frac{-1}{2} \cdot {\phi_1}^{2}\right)} + \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)}{\left(\frac{-1}{2} \cdot {\phi_1}^{2} + \color{blue}{1}\right) + \cos \phi_2 \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)}{\left({\phi_1}^{2} \cdot \frac{-1}{2} + 1\right) + \cos \phi_2 \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)}{\mathsf{fma}\left({\phi_1}^{2}, \color{blue}{\frac{-1}{2}}, 1\right) + \cos \phi_2 \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)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, \frac{-1}{2}, 1\right) + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
                                      5. lower-*.f6480.4

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

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

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

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

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

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

                                          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{1 \cdot \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.0%

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

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

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

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

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

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

                                          Alternative 18: 62.2% accurate, 2.0× speedup?

                                          \[\begin{array}{l} \\ \lambda_1 + \tan^{-1}_* \frac{1 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + 1 \cdot \cos \lambda_1} \end{array} \]
                                          (FPCore (lambda1 lambda2 phi1 phi2)
                                           :precision binary64
                                           (+
                                            lambda1
                                            (atan2 (* 1.0 (sin (- lambda1 lambda2))) (+ 1.0 (* 1.0 (cos lambda1))))))
                                          double code(double lambda1, double lambda2, double phi1, double phi2) {
                                          	return lambda1 + atan2((1.0 * sin((lambda1 - lambda2))), (1.0 + (1.0 * cos(lambda1))));
                                          }
                                          
                                          module fmin_fmax_functions
                                              implicit none
                                              private
                                              public fmax
                                              public fmin
                                          
                                              interface fmax
                                                  module procedure fmax88
                                                  module procedure fmax44
                                                  module procedure fmax84
                                                  module procedure fmax48
                                              end interface
                                              interface fmin
                                                  module procedure fmin88
                                                  module procedure fmin44
                                                  module procedure fmin84
                                                  module procedure fmin48
                                              end interface
                                          contains
                                              real(8) function fmax88(x, y) result (res)
                                                  real(8), intent (in) :: x
                                                  real(8), intent (in) :: y
                                                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                              end function
                                              real(4) function fmax44(x, y) result (res)
                                                  real(4), intent (in) :: x
                                                  real(4), intent (in) :: y
                                                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                              end function
                                              real(8) function fmax84(x, y) result(res)
                                                  real(8), intent (in) :: x
                                                  real(4), intent (in) :: y
                                                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                              end function
                                              real(8) function fmax48(x, y) result(res)
                                                  real(4), intent (in) :: x
                                                  real(8), intent (in) :: y
                                                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                              end function
                                              real(8) function fmin88(x, y) result (res)
                                                  real(8), intent (in) :: x
                                                  real(8), intent (in) :: y
                                                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                              end function
                                              real(4) function fmin44(x, y) result (res)
                                                  real(4), intent (in) :: x
                                                  real(4), intent (in) :: y
                                                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                              end function
                                              real(8) function fmin84(x, y) result(res)
                                                  real(8), intent (in) :: x
                                                  real(4), intent (in) :: y
                                                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                              end function
                                              real(8) function fmin48(x, y) result(res)
                                                  real(4), intent (in) :: x
                                                  real(8), intent (in) :: y
                                                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                              end function
                                          end module
                                          
                                          real(8) function code(lambda1, 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((1.0d0 * sin((lambda1 - lambda2))), (1.0d0 + (1.0d0 * cos(lambda1))))
                                          end function
                                          
                                          public static double code(double lambda1, double lambda2, double phi1, double phi2) {
                                          	return lambda1 + Math.atan2((1.0 * Math.sin((lambda1 - lambda2))), (1.0 + (1.0 * Math.cos(lambda1))));
                                          }
                                          
                                          def code(lambda1, lambda2, phi1, phi2):
                                          	return lambda1 + math.atan2((1.0 * math.sin((lambda1 - lambda2))), (1.0 + (1.0 * math.cos(lambda1))))
                                          
                                          function code(lambda1, lambda2, phi1, phi2)
                                          	return Float64(lambda1 + atan(Float64(1.0 * sin(Float64(lambda1 - lambda2))), Float64(1.0 + Float64(1.0 * cos(lambda1)))))
                                          end
                                          
                                          function tmp = code(lambda1, lambda2, phi1, phi2)
                                          	tmp = lambda1 + atan2((1.0 * sin((lambda1 - lambda2))), (1.0 + (1.0 * cos(lambda1))));
                                          end
                                          
                                          code[lambda1_, lambda2_, phi1_, phi2_] := N[(lambda1 + N[ArcTan[N[(1.0 * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(1.0 * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
                                          
                                          \begin{array}{l}
                                          
                                          \\
                                          \lambda_1 + \tan^{-1}_* \frac{1 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + 1 \cdot \cos \lambda_1}
                                          \end{array}
                                          
                                          Derivation
                                          1. Initial program 98.8%

                                            \[\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}{\left(1 + \frac{-1}{2} \cdot {\phi_1}^{2}\right)} + \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)}{\left(\frac{-1}{2} \cdot {\phi_1}^{2} + \color{blue}{1}\right) + \cos \phi_2 \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)}{\left({\phi_1}^{2} \cdot \frac{-1}{2} + 1\right) + \cos \phi_2 \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)}{\mathsf{fma}\left({\phi_1}^{2}, \color{blue}{\frac{-1}{2}}, 1\right) + \cos \phi_2 \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)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, \frac{-1}{2}, 1\right) + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
                                            5. lower-*.f6480.4

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

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

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

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

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

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

                                                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{1 \cdot \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.0%

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

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

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

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

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

                                                Alternative 19: 55.9% accurate, 2.1× speedup?

                                                \[\begin{array}{l} \\ \lambda_1 + \tan^{-1}_* \frac{1 \cdot \sin \lambda_1}{1 + 1 \cdot \cos \lambda_1} \end{array} \]
                                                (FPCore (lambda1 lambda2 phi1 phi2)
                                                 :precision binary64
                                                 (+ lambda1 (atan2 (* 1.0 (sin lambda1)) (+ 1.0 (* 1.0 (cos lambda1))))))
                                                double code(double lambda1, double lambda2, double phi1, double phi2) {
                                                	return lambda1 + atan2((1.0 * sin(lambda1)), (1.0 + (1.0 * cos(lambda1))));
                                                }
                                                
                                                module fmin_fmax_functions
                                                    implicit none
                                                    private
                                                    public fmax
                                                    public fmin
                                                
                                                    interface fmax
                                                        module procedure fmax88
                                                        module procedure fmax44
                                                        module procedure fmax84
                                                        module procedure fmax48
                                                    end interface
                                                    interface fmin
                                                        module procedure fmin88
                                                        module procedure fmin44
                                                        module procedure fmin84
                                                        module procedure fmin48
                                                    end interface
                                                contains
                                                    real(8) function fmax88(x, y) result (res)
                                                        real(8), intent (in) :: x
                                                        real(8), intent (in) :: y
                                                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                    end function
                                                    real(4) function fmax44(x, y) result (res)
                                                        real(4), intent (in) :: x
                                                        real(4), intent (in) :: y
                                                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                    end function
                                                    real(8) function fmax84(x, y) result(res)
                                                        real(8), intent (in) :: x
                                                        real(4), intent (in) :: y
                                                        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                                    end function
                                                    real(8) function fmax48(x, y) result(res)
                                                        real(4), intent (in) :: x
                                                        real(8), intent (in) :: y
                                                        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                                    end function
                                                    real(8) function fmin88(x, y) result (res)
                                                        real(8), intent (in) :: x
                                                        real(8), intent (in) :: y
                                                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                    end function
                                                    real(4) function fmin44(x, y) result (res)
                                                        real(4), intent (in) :: x
                                                        real(4), intent (in) :: y
                                                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                    end function
                                                    real(8) function fmin84(x, y) result(res)
                                                        real(8), intent (in) :: x
                                                        real(4), intent (in) :: y
                                                        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                                    end function
                                                    real(8) function fmin48(x, y) result(res)
                                                        real(4), intent (in) :: x
                                                        real(8), intent (in) :: y
                                                        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                                    end function
                                                end module
                                                
                                                real(8) function code(lambda1, 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((1.0d0 * sin(lambda1)), (1.0d0 + (1.0d0 * cos(lambda1))))
                                                end function
                                                
                                                public static double code(double lambda1, double lambda2, double phi1, double phi2) {
                                                	return lambda1 + Math.atan2((1.0 * Math.sin(lambda1)), (1.0 + (1.0 * Math.cos(lambda1))));
                                                }
                                                
                                                def code(lambda1, lambda2, phi1, phi2):
                                                	return lambda1 + math.atan2((1.0 * math.sin(lambda1)), (1.0 + (1.0 * math.cos(lambda1))))
                                                
                                                function code(lambda1, lambda2, phi1, phi2)
                                                	return Float64(lambda1 + atan(Float64(1.0 * sin(lambda1)), Float64(1.0 + Float64(1.0 * cos(lambda1)))))
                                                end
                                                
                                                function tmp = code(lambda1, lambda2, phi1, phi2)
                                                	tmp = lambda1 + atan2((1.0 * sin(lambda1)), (1.0 + (1.0 * cos(lambda1))));
                                                end
                                                
                                                code[lambda1_, lambda2_, phi1_, phi2_] := N[(lambda1 + N[ArcTan[N[(1.0 * N[Sin[lambda1], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(1.0 * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
                                                
                                                \begin{array}{l}
                                                
                                                \\
                                                \lambda_1 + \tan^{-1}_* \frac{1 \cdot \sin \lambda_1}{1 + 1 \cdot \cos \lambda_1}
                                                \end{array}
                                                
                                                Derivation
                                                1. Initial program 98.8%

                                                  \[\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}{\left(1 + \frac{-1}{2} \cdot {\phi_1}^{2}\right)} + \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)}{\left(\frac{-1}{2} \cdot {\phi_1}^{2} + \color{blue}{1}\right) + \cos \phi_2 \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)}{\left({\phi_1}^{2} \cdot \frac{-1}{2} + 1\right) + \cos \phi_2 \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)}{\mathsf{fma}\left({\phi_1}^{2}, \color{blue}{\frac{-1}{2}}, 1\right) + \cos \phi_2 \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)}{\mathsf{fma}\left(\phi_1 \cdot \phi_1, \frac{-1}{2}, 1\right) + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
                                                  5. lower-*.f6480.4

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

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

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

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

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

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

                                                      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{1 \cdot \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.0%

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

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

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

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

                                                            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{1 \cdot \sin \lambda_1}{1 + 1 \cdot \cos \color{blue}{\lambda_1}} \]
                                                          2. Add Preprocessing

                                                          Alternative 20: 53.3% accurate, 192.4× speedup?

                                                          \[\begin{array}{l} \\ \lambda_1 \end{array} \]
                                                          (FPCore (lambda1 lambda2 phi1 phi2) :precision binary64 lambda1)
                                                          double code(double lambda1, double lambda2, double phi1, double phi2) {
                                                          	return lambda1;
                                                          }
                                                          
                                                          module fmin_fmax_functions
                                                              implicit none
                                                              private
                                                              public fmax
                                                              public fmin
                                                          
                                                              interface fmax
                                                                  module procedure fmax88
                                                                  module procedure fmax44
                                                                  module procedure fmax84
                                                                  module procedure fmax48
                                                              end interface
                                                              interface fmin
                                                                  module procedure fmin88
                                                                  module procedure fmin44
                                                                  module procedure fmin84
                                                                  module procedure fmin48
                                                              end interface
                                                          contains
                                                              real(8) function fmax88(x, y) result (res)
                                                                  real(8), intent (in) :: x
                                                                  real(8), intent (in) :: y
                                                                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                              end function
                                                              real(4) function fmax44(x, y) result (res)
                                                                  real(4), intent (in) :: x
                                                                  real(4), intent (in) :: y
                                                                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                              end function
                                                              real(8) function fmax84(x, y) result(res)
                                                                  real(8), intent (in) :: x
                                                                  real(4), intent (in) :: y
                                                                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                                              end function
                                                              real(8) function fmax48(x, y) result(res)
                                                                  real(4), intent (in) :: x
                                                                  real(8), intent (in) :: y
                                                                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                                              end function
                                                              real(8) function fmin88(x, y) result (res)
                                                                  real(8), intent (in) :: x
                                                                  real(8), intent (in) :: y
                                                                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                              end function
                                                              real(4) function fmin44(x, y) result (res)
                                                                  real(4), intent (in) :: x
                                                                  real(4), intent (in) :: y
                                                                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                              end function
                                                              real(8) function fmin84(x, y) result(res)
                                                                  real(8), intent (in) :: x
                                                                  real(4), intent (in) :: y
                                                                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                                              end function
                                                              real(8) function fmin48(x, y) result(res)
                                                                  real(4), intent (in) :: x
                                                                  real(8), intent (in) :: y
                                                                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                                              end function
                                                          end module
                                                          
                                                          real(8) function code(lambda1, 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
                                                          end function
                                                          
                                                          public static double code(double lambda1, double lambda2, double phi1, double phi2) {
                                                          	return lambda1;
                                                          }
                                                          
                                                          def code(lambda1, lambda2, phi1, phi2):
                                                          	return lambda1
                                                          
                                                          function code(lambda1, lambda2, phi1, phi2)
                                                          	return lambda1
                                                          end
                                                          
                                                          function tmp = code(lambda1, lambda2, phi1, phi2)
                                                          	tmp = lambda1;
                                                          end
                                                          
                                                          code[lambda1_, lambda2_, phi1_, phi2_] := lambda1
                                                          
                                                          \begin{array}{l}
                                                          
                                                          \\
                                                          \lambda_1
                                                          \end{array}
                                                          
                                                          Derivation
                                                          1. Initial program 98.8%

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

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

                                                            Reproduce

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