Midpoint on a great circle

Percentage Accurate: 98.6% → 98.6%
Time: 14.9s
Alternatives: 14
Speedup: 1.0×

Specification

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

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

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 14 alternatives:

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

Initial Program: 98.6% accurate, 1.0× speedup?

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

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

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

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

Alternative 1: 98.6% accurate, 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
  3. Add Preprocessing

Alternative 2: 98.1% accurate, 0.2× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
t_1 := \sin \left(\lambda_1 - \lambda_2\right)\\
t_2 := \tan^{-1}_* \frac{t\_1 \cdot \cos \phi_2}{\mathsf{fma}\left(t\_0, \cos \phi_2, \cos \phi_1\right)}\\
t_3 := \cos \phi_2 \cdot t\_1\\
t_4 := \lambda_1 + \tan^{-1}_* \frac{t\_3}{\cos \phi_1 + \cos \phi_2 \cdot t\_0}\\
t_5 := \mathsf{fma}\left(\cos \lambda_1, \cos \phi_2, \cos \phi_1\right)\\
t_6 := \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \lambda_1}{t\_5}\\
\mathbf{if}\;t\_4 \leq -20:\\
\;\;\;\;t\_6\\

\mathbf{elif}\;t\_4 \leq -0.01:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_4 \leq 0.0002:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_3}{t\_5}\\

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

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


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

    1. Initial program 99.1%

      \[\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
    3. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

    if -20 < (+.f64 lambda1 (atan2.f64 (*.f64 (cos.f64 phi2) (sin.f64 (-.f64 lambda1 lambda2))) (+.f64 (cos.f64 phi1) (*.f64 (cos.f64 phi2) (cos.f64 (-.f64 lambda1 lambda2)))))) < -0.0100000000000000002 or 2.0000000000000001e-4 < (+.f64 lambda1 (atan2.f64 (*.f64 (cos.f64 phi2) (sin.f64 (-.f64 lambda1 lambda2))) (+.f64 (cos.f64 phi1) (*.f64 (cos.f64 phi2) (cos.f64 (-.f64 lambda1 lambda2)))))) < 5

    1. Initial program 97.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
    3. Taylor expanded in lambda1 around 0

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

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

    if -0.0100000000000000002 < (+.f64 lambda1 (atan2.f64 (*.f64 (cos.f64 phi2) (sin.f64 (-.f64 lambda1 lambda2))) (+.f64 (cos.f64 phi1) (*.f64 (cos.f64 phi2) (cos.f64 (-.f64 lambda1 lambda2)))))) < 2.0000000000000001e-4

    1. Initial program 99.0%

      \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    2. Add Preprocessing
    3. 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}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

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

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

Alternative 3: 98.0% 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 \lambda_2} \end{array} \]
(FPCore (lambda1 lambda2 phi1 phi2)
 :precision binary64
 (+
  lambda1
  (atan2
   (* (cos phi2) (sin (- lambda1 lambda2)))
   (+ (cos phi1) (* (cos phi2) (cos lambda2))))))
double code(double lambda1, double lambda2, double phi1, double phi2) {
	return lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + (cos(phi2) * cos(lambda2))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + (cos(phi2) * cos(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(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(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(lambda2)))))
end
function tmp = code(lambda1, lambda2, phi1, phi2)
	tmp = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + (cos(phi2) * cos(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[lambda2], $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 \lambda_2}
\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
  3. 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)}} \]
  4. 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 \color{blue}{\cos \lambda_2}} \]
    2. lower-cos.f6497.8

      \[\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. Applied rewrites97.8%

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

Alternative 4: 98.0% 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. Add Preprocessing
  3. 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)}} \]
  4. 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)}{\color{blue}{\cos \phi_1 - \left(\mathsf{neg}\left(\cos \phi_2\right)\right) \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)}} \]
    2. fp-cancel-sub-sign-invN/A

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

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

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

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

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

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

      \[\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, \color{blue}{\cos \phi_1}\right)} \]
  5. Applied rewrites97.8%

    \[\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)}} \]
  6. Add Preprocessing

Alternative 5: 84.1% 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 1.05 \cdot 10^{-14}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_1}{\mathsf{fma}\left(t\_0, \cos \phi_2, 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_1}{\mathsf{fma}\left(\mathsf{fma}\left(\phi_2 \cdot \phi_2, -0.5, 1\right), t\_0, \cos \phi_1\right)}\\ \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 1.05e-14)
     (+ lambda1 (atan2 t_1 (fma t_0 (cos phi2) 1.0)))
     (+
      lambda1
      (atan2 t_1 (fma (fma (* phi2 phi2) -0.5 1.0) t_0 (cos phi1)))))))
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 <= 1.05e-14) {
		tmp = lambda1 + atan2(t_1, fma(t_0, cos(phi2), 1.0));
	} else {
		tmp = lambda1 + atan2(t_1, fma(fma((phi2 * phi2), -0.5, 1.0), t_0, cos(phi1)));
	}
	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 <= 1.05e-14)
		tmp = Float64(lambda1 + atan(t_1, fma(t_0, cos(phi2), 1.0)));
	else
		tmp = Float64(lambda1 + atan(t_1, fma(fma(Float64(phi2 * phi2), -0.5, 1.0), t_0, cos(phi1))));
	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, 1.05e-14], N[(lambda1 + N[ArcTan[t$95$1 / N[(t$95$0 * N[Cos[phi2], $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(lambda1 + N[ArcTan[t$95$1 / N[(N[(N[(phi2 * phi2), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] * t$95$0 + N[Cos[phi1], $MachinePrecision]), $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 1.05 \cdot 10^{-14}:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_1}{\mathsf{fma}\left(t\_0, \cos \phi_2, 1\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi1 < 1.0499999999999999e-14

    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. Add Preprocessing
    3. 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)}} \]
    4. Step-by-step derivation
      1. +-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) + 1}} \]
      2. *-commutativeN/A

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{\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)}{\color{blue}{\mathsf{fma}\left(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_2, 1\right)}} \]
      4. *-lft-identityN/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 - \color{blue}{1 \cdot \lambda_2}\right), \cos \phi_2, 1\right)} \]
      5. metadata-evalN/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 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right), \cos \phi_2, 1\right)} \]
      6. fp-cancel-sign-sub-invN/A

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

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

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\mathsf{fma}\left(\cos \color{blue}{\left(\lambda_1 - \left(\mathsf{neg}\left(-1\right)\right) \cdot \lambda_2\right)}, \cos \phi_2, 1\right)} \]
      9. metadata-evalN/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 - \color{blue}{1} \cdot \lambda_2\right), \cos \phi_2, 1\right)} \]
      10. *-lft-identityN/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 - \color{blue}{\lambda_2}\right), \cos \phi_2, 1\right)} \]
      11. lower--.f64N/A

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

        \[\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)} \]
    5. Applied rewrites84.7%

      \[\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 1.0499999999999999e-14 < phi1

    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. Add Preprocessing
    3. Taylor expanded in phi2 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 80.2% accurate, 1.2× speedup?

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

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

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


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

    1. Initial program 99.0%

      \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi2 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 \left(\lambda_1 - \lambda_2\right)}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 0.325000000000000011 < (cos.f64 phi2)

      1. Initial program 98.4%

        \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      2. Add Preprocessing
      3. Taylor expanded in phi2 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 \left(\lambda_1 - \lambda_2\right)}} \]
      4. Step-by-step derivation
        1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 7: 83.4% 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 1.05 \cdot 10^{-14}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\mathsf{fma}\left(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_2, 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \lambda_2 + \cos \phi_1}\\ \end{array} \end{array} \]
      (FPCore (lambda1 lambda2 phi1 phi2)
       :precision binary64
       (let* ((t_0 (* (cos phi2) (sin (- lambda1 lambda2)))))
         (if (<= phi1 1.05e-14)
           (+ lambda1 (atan2 t_0 (fma (cos (- lambda1 lambda2)) (cos phi2) 1.0)))
           (+ lambda1 (atan2 t_0 (+ (cos lambda2) (cos phi1)))))))
      double code(double lambda1, double lambda2, double phi1, double phi2) {
      	double t_0 = cos(phi2) * sin((lambda1 - lambda2));
      	double tmp;
      	if (phi1 <= 1.05e-14) {
      		tmp = lambda1 + atan2(t_0, fma(cos((lambda1 - lambda2)), cos(phi2), 1.0));
      	} else {
      		tmp = lambda1 + atan2(t_0, (cos(lambda2) + cos(phi1)));
      	}
      	return tmp;
      }
      
      function code(lambda1, lambda2, phi1, phi2)
      	t_0 = Float64(cos(phi2) * sin(Float64(lambda1 - lambda2)))
      	tmp = 0.0
      	if (phi1 <= 1.05e-14)
      		tmp = Float64(lambda1 + atan(t_0, fma(cos(Float64(lambda1 - lambda2)), cos(phi2), 1.0)));
      	else
      		tmp = Float64(lambda1 + atan(t_0, Float64(cos(lambda2) + cos(phi1))));
      	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[phi1, 1.05e-14], N[(lambda1 + N[ArcTan[t$95$0 / N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(lambda1 + N[ArcTan[t$95$0 / N[(N[Cos[lambda2], $MachinePrecision] + N[Cos[phi1], $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 1.05 \cdot 10^{-14}:\\
      \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\mathsf{fma}\left(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_2, 1\right)}\\
      
      \mathbf{else}:\\
      \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \lambda_2 + \cos \phi_1}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if phi1 < 1.0499999999999999e-14

        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. Add Preprocessing
        3. 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)}} \]
        4. Step-by-step derivation
          1. +-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) + 1}} \]
          2. *-commutativeN/A

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{\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)}{\color{blue}{\mathsf{fma}\left(\cos \left(\lambda_1 - \lambda_2\right), \cos \phi_2, 1\right)}} \]
          4. *-lft-identityN/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 - \color{blue}{1 \cdot \lambda_2}\right), \cos \phi_2, 1\right)} \]
          5. metadata-evalN/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 - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \lambda_2\right), \cos \phi_2, 1\right)} \]
          6. fp-cancel-sign-sub-invN/A

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

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

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\mathsf{fma}\left(\cos \color{blue}{\left(\lambda_1 - \left(\mathsf{neg}\left(-1\right)\right) \cdot \lambda_2\right)}, \cos \phi_2, 1\right)} \]
          9. metadata-evalN/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 - \color{blue}{1} \cdot \lambda_2\right), \cos \phi_2, 1\right)} \]
          10. *-lft-identityN/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 - \color{blue}{\lambda_2}\right), \cos \phi_2, 1\right)} \]
          11. lower--.f64N/A

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

            \[\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)} \]
        5. Applied rewrites84.7%

          \[\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 1.0499999999999999e-14 < phi1

        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. Add Preprocessing
        3. Taylor expanded in phi2 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 \left(\lambda_1 - \lambda_2\right)}} \]
        4. Step-by-step derivation
          1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

          \[\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) + \cos \color{blue}{\phi_1}} \]
        7. Step-by-step derivation
          1. Applied rewrites78.6%

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

        Alternative 8: 78.0% accurate, 1.2× speedup?

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

          1. Initial program 99.0%

            \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          2. Add Preprocessing
          3. Taylor expanded in phi2 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 \left(\lambda_1 - \lambda_2\right)}} \]
          4. Step-by-step derivation
            1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if 0.5 < (cos.f64 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. Add Preprocessing
            3. Taylor expanded in phi2 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 \left(\lambda_1 - \lambda_2\right)}} \]
            4. Step-by-step derivation
              1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            Alternative 9: 76.5% accurate, 1.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              Alternative 10: 76.3% accurate, 1.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  Alternative 11: 66.4% accurate, 1.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                      Alternative 12: 57.7% accurate, 1.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        Alternative 13: 57.4% accurate, 1.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            Alternative 14: 57.2% accurate, 1.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                Reproduce

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