Midpoint on a great circle

Percentage Accurate: 98.6% → 98.6%
Time: 11.0s
Alternatives: 17
Speedup: 0.3×

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 17 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 98.6% accurate, 1.0× speedup?

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

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

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

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

Alternative 1: 98.6% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\\
\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2\right)}{\frac{{\left(\mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2\right)}^{3} + {\cos \phi_1}^{3}}{{t\_0}^{2} + \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \phi_1\right)\right) - t\_0 \cdot \cos \phi_1\right)}}
\end{array}
\end{array}
Derivation
  1. Initial program 98.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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)}{\frac{{\left(\mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2\right)}^{3} + {\cos \phi_1}^{3}}{{\left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right)}^{2} + \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \phi_1\right)\right) - \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)}} \]
  7. Applied rewrites98.5%

    \[\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)}}{\frac{{\left(\mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2\right)}^{3} + {\cos \phi_1}^{3}}{{\left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right)}^{2} + \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \phi_1\right)\right) - \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)}} \]
  8. Taylor expanded in lambda1 around 0

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

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

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

Alternative 2: 98.4% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\\
\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\frac{{\left(\mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2\right)}^{3} + {\cos \phi_1}^{3}}{{t\_0}^{2} + \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \phi_1\right)\right) - t\_0 \cdot \cos \phi_1\right)}}
\end{array}
\end{array}
Derivation
  1. Initial program 98.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 98.4% 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.6%

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

Alternative 4: 98.2% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;\lambda_2 \leq 5 \cdot 10^{-63}:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\mathsf{fma}\left(\cos \lambda_1, \cos \phi_2, \cos \phi_1\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda2 < -9.9999999999999998e-17 or 5.0000000000000002e-63 < lambda2

    1. Initial program 97.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 0

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

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

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

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

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

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

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

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

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

    if -9.9999999999999998e-17 < lambda2 < 5.0000000000000002e-63

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

Alternative 5: 97.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\mathsf{fma}\left(\cos \lambda_2, \cos \phi_2, \cos \phi_1\right)} \end{array} \]
(FPCore (lambda1 lambda2 phi1 phi2)
 :precision binary64
 (+
  lambda1
  (atan2
   (* (cos phi2) (sin (- lambda1 lambda2)))
   (fma (cos lambda2) (cos phi2) (cos phi1)))))
double code(double lambda1, double lambda2, double phi1, double phi2) {
	return lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), fma(cos(lambda2), cos(phi2), cos(phi1)));
}
function code(lambda1, lambda2, phi1, phi2)
	return Float64(lambda1 + atan(Float64(cos(phi2) * sin(Float64(lambda1 - lambda2))), fma(cos(lambda2), cos(phi2), cos(phi1))))
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[lambda2], $MachinePrecision] * N[Cos[phi2], $MachinePrecision] + N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 97.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(-\sin \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \lambda_2}\\ \mathbf{if}\;\lambda_2 \leq -18.5:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\lambda_2 \leq 0.00064:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \left(1 - 0.5 \cdot \left(\lambda_2 \cdot \lambda_2\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0
         (+
          lambda1
          (atan2
           (* (cos phi2) (- (sin lambda2)))
           (+ (cos phi1) (* (cos phi2) (cos lambda2)))))))
   (if (<= lambda2 -18.5)
     t_0
     (if (<= lambda2 0.00064)
       (+
        lambda1
        (atan2
         (* (cos phi2) (sin (- lambda1 lambda2)))
         (+ (cos phi1) (* (cos phi2) (- 1.0 (* 0.5 (* lambda2 lambda2)))))))
       t_0))))
double code(double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = lambda1 + atan2((cos(phi2) * -sin(lambda2)), (cos(phi1) + (cos(phi2) * cos(lambda2))));
	double tmp;
	if (lambda2 <= -18.5) {
		tmp = t_0;
	} else if (lambda2 <= 0.00064) {
		tmp = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + (cos(phi2) * (1.0 - (0.5 * (lambda2 * lambda2))))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: tmp
    t_0 = lambda1 + atan2((cos(phi2) * -sin(lambda2)), (cos(phi1) + (cos(phi2) * cos(lambda2))))
    if (lambda2 <= (-18.5d0)) then
        tmp = t_0
    else if (lambda2 <= 0.00064d0) then
        tmp = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + (cos(phi2) * (1.0d0 - (0.5d0 * (lambda2 * lambda2))))))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = lambda1 + Math.atan2((Math.cos(phi2) * -Math.sin(lambda2)), (Math.cos(phi1) + (Math.cos(phi2) * Math.cos(lambda2))));
	double tmp;
	if (lambda2 <= -18.5) {
		tmp = t_0;
	} else if (lambda2 <= 0.00064) {
		tmp = lambda1 + Math.atan2((Math.cos(phi2) * Math.sin((lambda1 - lambda2))), (Math.cos(phi1) + (Math.cos(phi2) * (1.0 - (0.5 * (lambda2 * lambda2))))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(lambda1, lambda2, phi1, phi2):
	t_0 = lambda1 + math.atan2((math.cos(phi2) * -math.sin(lambda2)), (math.cos(phi1) + (math.cos(phi2) * math.cos(lambda2))))
	tmp = 0
	if lambda2 <= -18.5:
		tmp = t_0
	elif lambda2 <= 0.00064:
		tmp = lambda1 + math.atan2((math.cos(phi2) * math.sin((lambda1 - lambda2))), (math.cos(phi1) + (math.cos(phi2) * (1.0 - (0.5 * (lambda2 * lambda2))))))
	else:
		tmp = t_0
	return tmp
function code(lambda1, lambda2, phi1, phi2)
	t_0 = Float64(lambda1 + atan(Float64(cos(phi2) * Float64(-sin(lambda2))), Float64(cos(phi1) + Float64(cos(phi2) * cos(lambda2)))))
	tmp = 0.0
	if (lambda2 <= -18.5)
		tmp = t_0;
	elseif (lambda2 <= 0.00064)
		tmp = Float64(lambda1 + atan(Float64(cos(phi2) * sin(Float64(lambda1 - lambda2))), Float64(cos(phi1) + Float64(cos(phi2) * Float64(1.0 - Float64(0.5 * Float64(lambda2 * lambda2)))))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(lambda1, lambda2, phi1, phi2)
	t_0 = lambda1 + atan2((cos(phi2) * -sin(lambda2)), (cos(phi1) + (cos(phi2) * cos(lambda2))));
	tmp = 0.0;
	if (lambda2 <= -18.5)
		tmp = t_0;
	elseif (lambda2 <= 0.00064)
		tmp = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + (cos(phi2) * (1.0 - (0.5 * (lambda2 * lambda2))))));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * (-N[Sin[lambda2], $MachinePrecision])), $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda2, -18.5], t$95$0, If[LessEqual[lambda2, 0.00064], 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[(1.0 - N[(0.5 * N[(lambda2 * lambda2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(-\sin \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \lambda_2}\\
\mathbf{if}\;\lambda_2 \leq -18.5:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\lambda_2 \leq 0.00064:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \left(1 - 0.5 \cdot \left(\lambda_2 \cdot \lambda_2\right)\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda2 < -18.5 or 6.40000000000000052e-4 < lambda2

    1. Initial program 97.5%

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

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

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

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

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

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

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

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

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

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

    if -18.5 < lambda2 < 6.40000000000000052e-4

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 89.7% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\cos \phi_1 \leq 0.72:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \left(1 - 0.5 \cdot \left(\phi_2 \cdot \phi_2\right)\right) \cdot \cos \lambda_2}\\

\mathbf{elif}\;\cos \phi_1 \leq 0.99992:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \cos \phi_2}\\

\mathbf{else}:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\mathsf{fma}\left(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_2, 1\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (cos.f64 phi1) < 0.71999999999999997

    1. Initial program 98.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.71999999999999997 < (cos.f64 phi1) < 0.999920000000000031

    1. Initial program 98.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.999920000000000031 < (cos.f64 phi1)

    1. Initial program 98.6%

      \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    2. Taylor expanded in 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.0

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

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

Alternative 8: 88.0% accurate, 1.2× speedup?

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

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

\mathbf{elif}\;\phi_1 \leq 3.8 \cdot 10^{+213}:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_1}{\cos \phi_1 + \cos \phi_2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi1 < 6.9999999999999998e-9

    1. Initial program 98.6%

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

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

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

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

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

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

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

    if 6.9999999999999998e-9 < phi1 < 3.7999999999999997e213

    1. Initial program 98.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.7999999999999997e213 < phi1

    1. Initial program 98.6%

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

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

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

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

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

Alternative 9: 85.1% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\phi_1 \leq 7 \cdot 10^{-9}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{1 + \cos \phi_2 \cdot \cos \lambda_2}\\ \mathbf{elif}\;\phi_1 \leq 3.8 \cdot 10^{+213}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \cos \phi_2}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}\\ \end{array} \end{array} \]
(FPCore (lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (cos phi2) (sin (- lambda1 lambda2)))))
   (if (<= phi1 7e-9)
     (+ lambda1 (atan2 t_0 (+ 1.0 (* (cos phi2) (cos lambda2)))))
     (if (<= phi1 3.8e+213)
       (+ lambda1 (atan2 t_0 (+ (cos phi1) (cos phi2))))
       (+ lambda1 (atan2 t_0 (+ (cos phi1) (cos (- lambda1 lambda2)))))))))
double code(double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos(phi2) * sin((lambda1 - lambda2));
	double tmp;
	if (phi1 <= 7e-9) {
		tmp = lambda1 + atan2(t_0, (1.0 + (cos(phi2) * cos(lambda2))));
	} else if (phi1 <= 3.8e+213) {
		tmp = lambda1 + atan2(t_0, (cos(phi1) + cos(phi2)));
	} else {
		tmp = lambda1 + atan2(t_0, (cos(phi1) + cos((lambda1 - lambda2))));
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: tmp
    t_0 = cos(phi2) * sin((lambda1 - lambda2))
    if (phi1 <= 7d-9) then
        tmp = lambda1 + atan2(t_0, (1.0d0 + (cos(phi2) * cos(lambda2))))
    else if (phi1 <= 3.8d+213) then
        tmp = lambda1 + atan2(t_0, (cos(phi1) + cos(phi2)))
    else
        tmp = lambda1 + atan2(t_0, (cos(phi1) + cos((lambda1 - lambda2))))
    end if
    code = tmp
end function
public static double code(double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.cos(phi2) * Math.sin((lambda1 - lambda2));
	double tmp;
	if (phi1 <= 7e-9) {
		tmp = lambda1 + Math.atan2(t_0, (1.0 + (Math.cos(phi2) * Math.cos(lambda2))));
	} else if (phi1 <= 3.8e+213) {
		tmp = lambda1 + Math.atan2(t_0, (Math.cos(phi1) + Math.cos(phi2)));
	} else {
		tmp = lambda1 + Math.atan2(t_0, (Math.cos(phi1) + Math.cos((lambda1 - lambda2))));
	}
	return tmp;
}
def code(lambda1, lambda2, phi1, phi2):
	t_0 = math.cos(phi2) * math.sin((lambda1 - lambda2))
	tmp = 0
	if phi1 <= 7e-9:
		tmp = lambda1 + math.atan2(t_0, (1.0 + (math.cos(phi2) * math.cos(lambda2))))
	elif phi1 <= 3.8e+213:
		tmp = lambda1 + math.atan2(t_0, (math.cos(phi1) + math.cos(phi2)))
	else:
		tmp = lambda1 + math.atan2(t_0, (math.cos(phi1) + math.cos((lambda1 - lambda2))))
	return tmp
function code(lambda1, lambda2, phi1, phi2)
	t_0 = Float64(cos(phi2) * sin(Float64(lambda1 - lambda2)))
	tmp = 0.0
	if (phi1 <= 7e-9)
		tmp = Float64(lambda1 + atan(t_0, Float64(1.0 + Float64(cos(phi2) * cos(lambda2)))));
	elseif (phi1 <= 3.8e+213)
		tmp = Float64(lambda1 + atan(t_0, Float64(cos(phi1) + cos(phi2))));
	else
		tmp = Float64(lambda1 + atan(t_0, Float64(cos(phi1) + cos(Float64(lambda1 - lambda2)))));
	end
	return tmp
end
function tmp_2 = code(lambda1, lambda2, phi1, phi2)
	t_0 = cos(phi2) * sin((lambda1 - lambda2));
	tmp = 0.0;
	if (phi1 <= 7e-9)
		tmp = lambda1 + atan2(t_0, (1.0 + (cos(phi2) * cos(lambda2))));
	elseif (phi1 <= 3.8e+213)
		tmp = lambda1 + atan2(t_0, (cos(phi1) + cos(phi2)));
	else
		tmp = lambda1 + atan2(t_0, (cos(phi1) + cos((lambda1 - lambda2))));
	end
	tmp_2 = tmp;
end
code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, 7e-9], N[(lambda1 + N[ArcTan[t$95$0 / N[(1.0 + N[(N[Cos[phi2], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 3.8e+213], N[(lambda1 + N[ArcTan[t$95$0 / N[(N[Cos[phi1], $MachinePrecision] + N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(lambda1 + N[ArcTan[t$95$0 / N[(N[Cos[phi1], $MachinePrecision] + N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;\phi_1 \leq 3.8 \cdot 10^{+213}:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \cos \phi_2}\\

\mathbf{else}:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi1 < 6.9999999999999998e-9

    1. Initial program 98.6%

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

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

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

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

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

        \[\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 \lambda_2} \]

      if 6.9999999999999998e-9 < phi1 < 3.7999999999999997e213

      1. Initial program 98.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 3.7999999999999997e213 < phi1

      1. Initial program 98.6%

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

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

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

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

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

    Alternative 10: 83.3% accurate, 1.2× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\phi_2 \leq 8200000:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \cos \phi_2}\\ \end{array} \end{array} \]
    (FPCore (lambda1 lambda2 phi1 phi2)
     :precision binary64
     (let* ((t_0 (* (cos phi2) (sin (- lambda1 lambda2)))))
       (if (<= phi2 8200000.0)
         (+ lambda1 (atan2 t_0 (+ (cos phi1) (cos (- lambda1 lambda2)))))
         (+ lambda1 (atan2 t_0 (+ (cos phi1) (cos phi2)))))))
    double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = cos(phi2) * sin((lambda1 - lambda2));
    	double tmp;
    	if (phi2 <= 8200000.0) {
    		tmp = lambda1 + atan2(t_0, (cos(phi1) + cos((lambda1 - lambda2))));
    	} else {
    		tmp = lambda1 + atan2(t_0, (cos(phi1) + cos(phi2)));
    	}
    	return tmp;
    }
    
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(8) function code(lambda1, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: t_0
        real(8) :: tmp
        t_0 = cos(phi2) * sin((lambda1 - lambda2))
        if (phi2 <= 8200000.0d0) then
            tmp = lambda1 + atan2(t_0, (cos(phi1) + cos((lambda1 - lambda2))))
        else
            tmp = lambda1 + atan2(t_0, (cos(phi1) + cos(phi2)))
        end if
        code = tmp
    end function
    
    public static double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = Math.cos(phi2) * Math.sin((lambda1 - lambda2));
    	double tmp;
    	if (phi2 <= 8200000.0) {
    		tmp = lambda1 + Math.atan2(t_0, (Math.cos(phi1) + Math.cos((lambda1 - lambda2))));
    	} else {
    		tmp = lambda1 + Math.atan2(t_0, (Math.cos(phi1) + Math.cos(phi2)));
    	}
    	return tmp;
    }
    
    def code(lambda1, lambda2, phi1, phi2):
    	t_0 = math.cos(phi2) * math.sin((lambda1 - lambda2))
    	tmp = 0
    	if phi2 <= 8200000.0:
    		tmp = lambda1 + math.atan2(t_0, (math.cos(phi1) + math.cos((lambda1 - lambda2))))
    	else:
    		tmp = lambda1 + math.atan2(t_0, (math.cos(phi1) + math.cos(phi2)))
    	return tmp
    
    function code(lambda1, lambda2, phi1, phi2)
    	t_0 = Float64(cos(phi2) * sin(Float64(lambda1 - lambda2)))
    	tmp = 0.0
    	if (phi2 <= 8200000.0)
    		tmp = Float64(lambda1 + atan(t_0, Float64(cos(phi1) + cos(Float64(lambda1 - lambda2)))));
    	else
    		tmp = Float64(lambda1 + atan(t_0, Float64(cos(phi1) + cos(phi2))));
    	end
    	return tmp
    end
    
    function tmp_2 = code(lambda1, lambda2, phi1, phi2)
    	t_0 = cos(phi2) * sin((lambda1 - lambda2));
    	tmp = 0.0;
    	if (phi2 <= 8200000.0)
    		tmp = lambda1 + atan2(t_0, (cos(phi1) + cos((lambda1 - lambda2))));
    	else
    		tmp = lambda1 + atan2(t_0, (cos(phi1) + cos(phi2)));
    	end
    	tmp_2 = tmp;
    end
    
    code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, 8200000.0], N[(lambda1 + N[ArcTan[t$95$0 / N[(N[Cos[phi1], $MachinePrecision] + N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(lambda1 + N[ArcTan[t$95$0 / N[(N[Cos[phi1], $MachinePrecision] + N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)\\
    \mathbf{if}\;\phi_2 \leq 8200000:\\
    \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}\\
    
    \mathbf{else}:\\
    \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \cos \phi_2}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if phi2 < 8.2e6

      1. Initial program 98.6%

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

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

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

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

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

      if 8.2e6 < phi2

      1. Initial program 98.3%

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

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

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

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

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

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

          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\mathsf{fma}\left(\cos \lambda_1, \cos \phi_2, \cos \phi_1\right)} \]
      4. Applied 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 \lambda_1, \cos \phi_2, \cos \phi_1\right)}} \]
      5. Taylor expanded in lambda1 around 0

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

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

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

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

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

    Alternative 11: 83.0% accurate, 1.0× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\cos \phi_2 \leq 0.99996:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot t\_0}{\cos \phi_1 + \cos \phi_2}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}\\ \end{array} \end{array} \]
    (FPCore (lambda1 lambda2 phi1 phi2)
     :precision binary64
     (let* ((t_0 (sin (- lambda1 lambda2))))
       (if (<= (cos phi2) 0.99996)
         (+ lambda1 (atan2 (* (cos phi2) t_0) (+ (cos phi1) (cos phi2))))
         (+ lambda1 (atan2 t_0 (+ (cos phi1) (cos (- lambda1 lambda2))))))))
    double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = sin((lambda1 - lambda2));
    	double tmp;
    	if (cos(phi2) <= 0.99996) {
    		tmp = lambda1 + atan2((cos(phi2) * t_0), (cos(phi1) + cos(phi2)));
    	} else {
    		tmp = lambda1 + atan2(t_0, (cos(phi1) + cos((lambda1 - lambda2))));
    	}
    	return tmp;
    }
    
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(8) function code(lambda1, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: t_0
        real(8) :: tmp
        t_0 = sin((lambda1 - lambda2))
        if (cos(phi2) <= 0.99996d0) then
            tmp = lambda1 + atan2((cos(phi2) * t_0), (cos(phi1) + cos(phi2)))
        else
            tmp = lambda1 + atan2(t_0, (cos(phi1) + cos((lambda1 - lambda2))))
        end if
        code = tmp
    end function
    
    public static double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = Math.sin((lambda1 - lambda2));
    	double tmp;
    	if (Math.cos(phi2) <= 0.99996) {
    		tmp = lambda1 + Math.atan2((Math.cos(phi2) * t_0), (Math.cos(phi1) + Math.cos(phi2)));
    	} else {
    		tmp = lambda1 + Math.atan2(t_0, (Math.cos(phi1) + Math.cos((lambda1 - lambda2))));
    	}
    	return tmp;
    }
    
    def code(lambda1, lambda2, phi1, phi2):
    	t_0 = math.sin((lambda1 - lambda2))
    	tmp = 0
    	if math.cos(phi2) <= 0.99996:
    		tmp = lambda1 + math.atan2((math.cos(phi2) * t_0), (math.cos(phi1) + math.cos(phi2)))
    	else:
    		tmp = lambda1 + math.atan2(t_0, (math.cos(phi1) + math.cos((lambda1 - lambda2))))
    	return tmp
    
    function code(lambda1, lambda2, phi1, phi2)
    	t_0 = sin(Float64(lambda1 - lambda2))
    	tmp = 0.0
    	if (cos(phi2) <= 0.99996)
    		tmp = Float64(lambda1 + atan(Float64(cos(phi2) * t_0), Float64(cos(phi1) + cos(phi2))));
    	else
    		tmp = Float64(lambda1 + atan(t_0, Float64(cos(phi1) + cos(Float64(lambda1 - lambda2)))));
    	end
    	return tmp
    end
    
    function tmp_2 = code(lambda1, lambda2, phi1, phi2)
    	t_0 = sin((lambda1 - lambda2));
    	tmp = 0.0;
    	if (cos(phi2) <= 0.99996)
    		tmp = lambda1 + atan2((cos(phi2) * t_0), (cos(phi1) + cos(phi2)));
    	else
    		tmp = lambda1 + atan2(t_0, (cos(phi1) + cos((lambda1 - lambda2))));
    	end
    	tmp_2 = tmp;
    end
    
    code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Cos[phi2], $MachinePrecision], 0.99996], N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] + N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(lambda1 + N[ArcTan[t$95$0 / N[(N[Cos[phi1], $MachinePrecision] + N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\
    \mathbf{if}\;\cos \phi_2 \leq 0.99996:\\
    \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot t\_0}{\cos \phi_1 + \cos \phi_2}\\
    
    \mathbf{else}:\\
    \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (cos.f64 phi2) < 0.99995999999999996

      1. Initial program 98.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 0.99995999999999996 < (cos.f64 phi2)

      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 + {\phi_1}^{2} \cdot \left(\frac{1}{24} \cdot {\phi_1}^{2} - \frac{1}{2}\right)\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({\phi_1}^{2} \cdot \left(\frac{1}{24} \cdot {\phi_1}^{2} - \frac{1}{2}\right) + \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(\left(\frac{1}{24} \cdot {\phi_1}^{2} - \frac{1}{2}\right) \cdot {\phi_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(\frac{1}{24} \cdot {\phi_1}^{2} - \frac{1}{2}, \color{blue}{{\phi_1}^{2}}, 1\right) + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        4. lower--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Alternative 12: 82.9% accurate, 1.0× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \phi_2 \leq 0.9999:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(-\sin \lambda_2\right)}{\cos \phi_1 + \cos \phi_2}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}\\ \end{array} \end{array} \]
    (FPCore (lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (<= (cos phi2) 0.9999)
       (+
        lambda1
        (atan2 (* (cos phi2) (- (sin lambda2))) (+ (cos phi1) (cos phi2))))
       (+
        lambda1
        (atan2
         (sin (- lambda1 lambda2))
         (+ (cos phi1) (cos (- lambda1 lambda2)))))))
    double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (cos(phi2) <= 0.9999) {
    		tmp = lambda1 + atan2((cos(phi2) * -sin(lambda2)), (cos(phi1) + cos(phi2)));
    	} else {
    		tmp = lambda1 + atan2(sin((lambda1 - lambda2)), (cos(phi1) + cos((lambda1 - lambda2))));
    	}
    	return tmp;
    }
    
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(8) function code(lambda1, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: tmp
        if (cos(phi2) <= 0.9999d0) then
            tmp = lambda1 + atan2((cos(phi2) * -sin(lambda2)), (cos(phi1) + cos(phi2)))
        else
            tmp = lambda1 + atan2(sin((lambda1 - lambda2)), (cos(phi1) + cos((lambda1 - lambda2))))
        end if
        code = tmp
    end function
    
    public static double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (Math.cos(phi2) <= 0.9999) {
    		tmp = lambda1 + Math.atan2((Math.cos(phi2) * -Math.sin(lambda2)), (Math.cos(phi1) + Math.cos(phi2)));
    	} else {
    		tmp = lambda1 + Math.atan2(Math.sin((lambda1 - lambda2)), (Math.cos(phi1) + Math.cos((lambda1 - lambda2))));
    	}
    	return tmp;
    }
    
    def code(lambda1, lambda2, phi1, phi2):
    	tmp = 0
    	if math.cos(phi2) <= 0.9999:
    		tmp = lambda1 + math.atan2((math.cos(phi2) * -math.sin(lambda2)), (math.cos(phi1) + math.cos(phi2)))
    	else:
    		tmp = lambda1 + math.atan2(math.sin((lambda1 - lambda2)), (math.cos(phi1) + math.cos((lambda1 - lambda2))))
    	return tmp
    
    function code(lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (cos(phi2) <= 0.9999)
    		tmp = Float64(lambda1 + atan(Float64(cos(phi2) * Float64(-sin(lambda2))), Float64(cos(phi1) + cos(phi2))));
    	else
    		tmp = Float64(lambda1 + atan(sin(Float64(lambda1 - lambda2)), Float64(cos(phi1) + cos(Float64(lambda1 - lambda2)))));
    	end
    	return tmp
    end
    
    function tmp_2 = code(lambda1, lambda2, phi1, phi2)
    	tmp = 0.0;
    	if (cos(phi2) <= 0.9999)
    		tmp = lambda1 + atan2((cos(phi2) * -sin(lambda2)), (cos(phi1) + cos(phi2)));
    	else
    		tmp = lambda1 + atan2(sin((lambda1 - lambda2)), (cos(phi1) + cos((lambda1 - lambda2))));
    	end
    	tmp_2 = tmp;
    end
    
    code[lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[Cos[phi2], $MachinePrecision], 0.9999], N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * (-N[Sin[lambda2], $MachinePrecision])), $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] + N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(lambda1 + N[ArcTan[N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] + N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\cos \phi_2 \leq 0.9999:\\
    \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(-\sin \lambda_2\right)}{\cos \phi_1 + \cos \phi_2}\\
    
    \mathbf{else}:\\
    \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (cos.f64 phi2) < 0.99990000000000001

      1. Initial program 98.3%

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

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

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

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

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

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

          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\mathsf{fma}\left(\cos \lambda_1, \cos \phi_2, \cos \phi_1\right)} \]
      4. Applied 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 \lambda_1, \cos \phi_2, \cos \phi_1\right)}} \]
      5. Taylor expanded in lambda1 around 0

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

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

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

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

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

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

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

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

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

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

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

      if 0.99990000000000001 < (cos.f64 phi2)

      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 + {\phi_1}^{2} \cdot \left(\frac{1}{24} \cdot {\phi_1}^{2} - \frac{1}{2}\right)\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({\phi_1}^{2} \cdot \left(\frac{1}{24} \cdot {\phi_1}^{2} - \frac{1}{2}\right) + \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(\left(\frac{1}{24} \cdot {\phi_1}^{2} - \frac{1}{2}\right) \cdot {\phi_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(\frac{1}{24} \cdot {\phi_1}^{2} - \frac{1}{2}, \color{blue}{{\phi_1}^{2}}, 1\right) + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        4. lower--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Alternative 13: 82.7% accurate, 1.1× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\cos \phi_2 \leq 0.9999:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot t\_0}{\left(1 + -0.5 \cdot \left(\phi_1 \cdot \phi_1\right)\right) + \cos \phi_2}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}\\ \end{array} \end{array} \]
    (FPCore (lambda1 lambda2 phi1 phi2)
     :precision binary64
     (let* ((t_0 (sin (- lambda1 lambda2))))
       (if (<= (cos phi2) 0.9999)
         (+
          lambda1
          (atan2 (* (cos phi2) t_0) (+ (+ 1.0 (* -0.5 (* phi1 phi1))) (cos phi2))))
         (+ lambda1 (atan2 t_0 (+ (cos phi1) (cos (- lambda1 lambda2))))))))
    double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = sin((lambda1 - lambda2));
    	double tmp;
    	if (cos(phi2) <= 0.9999) {
    		tmp = lambda1 + atan2((cos(phi2) * t_0), ((1.0 + (-0.5 * (phi1 * phi1))) + cos(phi2)));
    	} else {
    		tmp = lambda1 + atan2(t_0, (cos(phi1) + cos((lambda1 - lambda2))));
    	}
    	return tmp;
    }
    
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(8) function code(lambda1, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: t_0
        real(8) :: tmp
        t_0 = sin((lambda1 - lambda2))
        if (cos(phi2) <= 0.9999d0) then
            tmp = lambda1 + atan2((cos(phi2) * t_0), ((1.0d0 + ((-0.5d0) * (phi1 * phi1))) + cos(phi2)))
        else
            tmp = lambda1 + atan2(t_0, (cos(phi1) + cos((lambda1 - lambda2))))
        end if
        code = tmp
    end function
    
    public static double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = Math.sin((lambda1 - lambda2));
    	double tmp;
    	if (Math.cos(phi2) <= 0.9999) {
    		tmp = lambda1 + Math.atan2((Math.cos(phi2) * t_0), ((1.0 + (-0.5 * (phi1 * phi1))) + Math.cos(phi2)));
    	} else {
    		tmp = lambda1 + Math.atan2(t_0, (Math.cos(phi1) + Math.cos((lambda1 - lambda2))));
    	}
    	return tmp;
    }
    
    def code(lambda1, lambda2, phi1, phi2):
    	t_0 = math.sin((lambda1 - lambda2))
    	tmp = 0
    	if math.cos(phi2) <= 0.9999:
    		tmp = lambda1 + math.atan2((math.cos(phi2) * t_0), ((1.0 + (-0.5 * (phi1 * phi1))) + math.cos(phi2)))
    	else:
    		tmp = lambda1 + math.atan2(t_0, (math.cos(phi1) + math.cos((lambda1 - lambda2))))
    	return tmp
    
    function code(lambda1, lambda2, phi1, phi2)
    	t_0 = sin(Float64(lambda1 - lambda2))
    	tmp = 0.0
    	if (cos(phi2) <= 0.9999)
    		tmp = Float64(lambda1 + atan(Float64(cos(phi2) * t_0), Float64(Float64(1.0 + Float64(-0.5 * Float64(phi1 * phi1))) + cos(phi2))));
    	else
    		tmp = Float64(lambda1 + atan(t_0, Float64(cos(phi1) + cos(Float64(lambda1 - lambda2)))));
    	end
    	return tmp
    end
    
    function tmp_2 = code(lambda1, lambda2, phi1, phi2)
    	t_0 = sin((lambda1 - lambda2));
    	tmp = 0.0;
    	if (cos(phi2) <= 0.9999)
    		tmp = lambda1 + atan2((cos(phi2) * t_0), ((1.0 + (-0.5 * (phi1 * phi1))) + cos(phi2)));
    	else
    		tmp = lambda1 + atan2(t_0, (cos(phi1) + cos((lambda1 - lambda2))));
    	end
    	tmp_2 = tmp;
    end
    
    code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Cos[phi2], $MachinePrecision], 0.9999], N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision] / N[(N[(1.0 + N[(-0.5 * N[(phi1 * phi1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(lambda1 + N[ArcTan[t$95$0 / N[(N[Cos[phi1], $MachinePrecision] + N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\
    \mathbf{if}\;\cos \phi_2 \leq 0.9999:\\
    \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot t\_0}{\left(1 + -0.5 \cdot \left(\phi_1 \cdot \phi_1\right)\right) + \cos \phi_2}\\
    
    \mathbf{else}:\\
    \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (cos.f64 phi2) < 0.99990000000000001

      1. Initial program 98.3%

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

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

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

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

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

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

          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\mathsf{fma}\left(\cos \lambda_1, \cos \phi_2, \cos \phi_1\right)} \]
      4. Applied 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 \lambda_1, \cos \phi_2, \cos \phi_1\right)}} \]
      5. Taylor expanded in lambda1 around 0

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

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

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

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

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

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

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

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

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

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

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

      if 0.99990000000000001 < (cos.f64 phi2)

      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 + {\phi_1}^{2} \cdot \left(\frac{1}{24} \cdot {\phi_1}^{2} - \frac{1}{2}\right)\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({\phi_1}^{2} \cdot \left(\frac{1}{24} \cdot {\phi_1}^{2} - \frac{1}{2}\right) + \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(\left(\frac{1}{24} \cdot {\phi_1}^{2} - \frac{1}{2}\right) \cdot {\phi_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(\frac{1}{24} \cdot {\phi_1}^{2} - \frac{1}{2}, \color{blue}{{\phi_1}^{2}}, 1\right) + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        4. lower--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Alternative 14: 82.7% accurate, 1.2× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\cos \phi_2 \leq 0.9999:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot t\_0}{1 + \cos \phi_2}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}\\ \end{array} \end{array} \]
    (FPCore (lambda1 lambda2 phi1 phi2)
     :precision binary64
     (let* ((t_0 (sin (- lambda1 lambda2))))
       (if (<= (cos phi2) 0.9999)
         (+ lambda1 (atan2 (* (cos phi2) t_0) (+ 1.0 (cos phi2))))
         (+ lambda1 (atan2 t_0 (+ (cos phi1) (cos (- lambda1 lambda2))))))))
    double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = sin((lambda1 - lambda2));
    	double tmp;
    	if (cos(phi2) <= 0.9999) {
    		tmp = lambda1 + atan2((cos(phi2) * t_0), (1.0 + cos(phi2)));
    	} else {
    		tmp = lambda1 + atan2(t_0, (cos(phi1) + cos((lambda1 - lambda2))));
    	}
    	return tmp;
    }
    
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(8) function code(lambda1, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: t_0
        real(8) :: tmp
        t_0 = sin((lambda1 - lambda2))
        if (cos(phi2) <= 0.9999d0) then
            tmp = lambda1 + atan2((cos(phi2) * t_0), (1.0d0 + cos(phi2)))
        else
            tmp = lambda1 + atan2(t_0, (cos(phi1) + cos((lambda1 - lambda2))))
        end if
        code = tmp
    end function
    
    public static double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = Math.sin((lambda1 - lambda2));
    	double tmp;
    	if (Math.cos(phi2) <= 0.9999) {
    		tmp = lambda1 + Math.atan2((Math.cos(phi2) * t_0), (1.0 + Math.cos(phi2)));
    	} else {
    		tmp = lambda1 + Math.atan2(t_0, (Math.cos(phi1) + Math.cos((lambda1 - lambda2))));
    	}
    	return tmp;
    }
    
    def code(lambda1, lambda2, phi1, phi2):
    	t_0 = math.sin((lambda1 - lambda2))
    	tmp = 0
    	if math.cos(phi2) <= 0.9999:
    		tmp = lambda1 + math.atan2((math.cos(phi2) * t_0), (1.0 + math.cos(phi2)))
    	else:
    		tmp = lambda1 + math.atan2(t_0, (math.cos(phi1) + math.cos((lambda1 - lambda2))))
    	return tmp
    
    function code(lambda1, lambda2, phi1, phi2)
    	t_0 = sin(Float64(lambda1 - lambda2))
    	tmp = 0.0
    	if (cos(phi2) <= 0.9999)
    		tmp = Float64(lambda1 + atan(Float64(cos(phi2) * t_0), Float64(1.0 + cos(phi2))));
    	else
    		tmp = Float64(lambda1 + atan(t_0, Float64(cos(phi1) + cos(Float64(lambda1 - lambda2)))));
    	end
    	return tmp
    end
    
    function tmp_2 = code(lambda1, lambda2, phi1, phi2)
    	t_0 = sin((lambda1 - lambda2));
    	tmp = 0.0;
    	if (cos(phi2) <= 0.9999)
    		tmp = lambda1 + atan2((cos(phi2) * t_0), (1.0 + cos(phi2)));
    	else
    		tmp = lambda1 + atan2(t_0, (cos(phi1) + cos((lambda1 - lambda2))));
    	end
    	tmp_2 = tmp;
    end
    
    code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Cos[phi2], $MachinePrecision], 0.9999], N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision] / N[(1.0 + N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(lambda1 + N[ArcTan[t$95$0 / N[(N[Cos[phi1], $MachinePrecision] + N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \sin \left(\lambda_1 - \lambda_2\right)\\
    \mathbf{if}\;\cos \phi_2 \leq 0.9999:\\
    \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot t\_0}{1 + \cos \phi_2}\\
    
    \mathbf{else}:\\
    \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (cos.f64 phi2) < 0.99990000000000001

      1. Initial program 98.3%

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

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

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

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

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

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

          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\mathsf{fma}\left(\cos \lambda_1, \cos \phi_2, \cos \phi_1\right)} \]
      4. Applied 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 \lambda_1, \cos \phi_2, \cos \phi_1\right)}} \]
      5. Taylor expanded in lambda1 around 0

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

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

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

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

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

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

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

        if 0.99990000000000001 < (cos.f64 phi2)

        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 + {\phi_1}^{2} \cdot \left(\frac{1}{24} \cdot {\phi_1}^{2} - \frac{1}{2}\right)\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({\phi_1}^{2} \cdot \left(\frac{1}{24} \cdot {\phi_1}^{2} - \frac{1}{2}\right) + \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(\left(\frac{1}{24} \cdot {\phi_1}^{2} - \frac{1}{2}\right) \cdot {\phi_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(\frac{1}{24} \cdot {\phi_1}^{2} - \frac{1}{2}, \color{blue}{{\phi_1}^{2}}, 1\right) + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          4. lower--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 15: 76.5% accurate, 1.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 16: 66.1% accurate, 2.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        Alternative 17: 51.6% 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.6%

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

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

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

          Reproduce

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