Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.1% → 99.1%
Time: 6.0s
Alternatives: 16
Speedup: 1.8×

Specification

?
\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\\ R \cdot \sqrt{t\_0 \cdot t\_0 + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0)))))
   (* R (sqrt (+ (* t_0 t_0) (* (- phi1 phi2) (- phi1 phi2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0));
	return R * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0d0))
    code = r * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (lambda1 - lambda2) * Math.cos(((phi1 + phi2) / 2.0));
	return R * Math.sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = (lambda1 - lambda2) * math.cos(((phi1 + phi2) / 2.0))
	return R * math.sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))))
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi1 + phi2) / 2.0)))
	return Float64(R * sqrt(Float64(Float64(t_0 * t_0) + Float64(Float64(phi1 - phi2) * Float64(phi1 - phi2)))))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0));
	tmp = R * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(N[(phi1 + phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(R * N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] + N[(N[(phi1 - phi2), $MachinePrecision] * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\\
R \cdot \sqrt{t\_0 \cdot t\_0 + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}
\end{array}
\end{array}

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 16 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: 59.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\\ R \cdot \sqrt{t\_0 \cdot t\_0 + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0)))))
   (* R (sqrt (+ (* t_0 t_0) (* (- phi1 phi2) (- phi1 phi2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0));
	return R * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0d0))
    code = r * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (lambda1 - lambda2) * Math.cos(((phi1 + phi2) / 2.0));
	return R * Math.sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = (lambda1 - lambda2) * math.cos(((phi1 + phi2) / 2.0))
	return R * math.sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))))
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi1 + phi2) / 2.0)))
	return Float64(R * sqrt(Float64(Float64(t_0 * t_0) + Float64(Float64(phi1 - phi2) * Float64(phi1 - phi2)))))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0));
	tmp = R * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(N[(phi1 + phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(R * N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] + N[(N[(phi1 - phi2), $MachinePrecision] * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\\
R \cdot \sqrt{t\_0 \cdot t\_0 + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}
\end{array}
\end{array}

Alternative 1: 99.1% accurate, 0.6× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\\ \mathbf{if}\;\lambda_1 \leq -2.4 \cdot 10^{-100}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, t\_0 \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, t\_0 \cdot \left(-\lambda_2\right)\right) \cdot R\\ \end{array} \end{array} \]
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0
         (-
          (* (cos (/ phi2 2.0)) (cos (/ phi1 2.0)))
          (* (sin (/ phi2 2.0)) (sin (/ phi1 2.0))))))
   (if (<= lambda1 -2.4e-100)
     (*
      (hypot (- phi1 phi2) (* t_0 (- (* (- (/ lambda2 lambda1) 1.0) lambda1))))
      R)
     (* (hypot (- phi1 phi2) (* t_0 (- lambda2))) R))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (cos((phi2 / 2.0)) * cos((phi1 / 2.0))) - (sin((phi2 / 2.0)) * sin((phi1 / 2.0)));
	double tmp;
	if (lambda1 <= -2.4e-100) {
		tmp = hypot((phi1 - phi2), (t_0 * -(((lambda2 / lambda1) - 1.0) * lambda1))) * R;
	} else {
		tmp = hypot((phi1 - phi2), (t_0 * -lambda2)) * R;
	}
	return tmp;
}
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (Math.cos((phi2 / 2.0)) * Math.cos((phi1 / 2.0))) - (Math.sin((phi2 / 2.0)) * Math.sin((phi1 / 2.0)));
	double tmp;
	if (lambda1 <= -2.4e-100) {
		tmp = Math.hypot((phi1 - phi2), (t_0 * -(((lambda2 / lambda1) - 1.0) * lambda1))) * R;
	} else {
		tmp = Math.hypot((phi1 - phi2), (t_0 * -lambda2)) * R;
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = (math.cos((phi2 / 2.0)) * math.cos((phi1 / 2.0))) - (math.sin((phi2 / 2.0)) * math.sin((phi1 / 2.0)))
	tmp = 0
	if lambda1 <= -2.4e-100:
		tmp = math.hypot((phi1 - phi2), (t_0 * -(((lambda2 / lambda1) - 1.0) * lambda1))) * R
	else:
		tmp = math.hypot((phi1 - phi2), (t_0 * -lambda2)) * R
	return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(Float64(cos(Float64(phi2 / 2.0)) * cos(Float64(phi1 / 2.0))) - Float64(sin(Float64(phi2 / 2.0)) * sin(Float64(phi1 / 2.0))))
	tmp = 0.0
	if (lambda1 <= -2.4e-100)
		tmp = Float64(hypot(Float64(phi1 - phi2), Float64(t_0 * Float64(-Float64(Float64(Float64(lambda2 / lambda1) - 1.0) * lambda1)))) * R);
	else
		tmp = Float64(hypot(Float64(phi1 - phi2), Float64(t_0 * Float64(-lambda2))) * R);
	end
	return tmp
end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = (cos((phi2 / 2.0)) * cos((phi1 / 2.0))) - (sin((phi2 / 2.0)) * sin((phi1 / 2.0)));
	tmp = 0.0;
	if (lambda1 <= -2.4e-100)
		tmp = hypot((phi1 - phi2), (t_0 * -(((lambda2 / lambda1) - 1.0) * lambda1))) * R;
	else
		tmp = hypot((phi1 - phi2), (t_0 * -lambda2)) * R;
	end
	tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(N[Cos[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda1, -2.4e-100], N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(t$95$0 * (-N[(N[(N[(lambda2 / lambda1), $MachinePrecision] - 1.0), $MachinePrecision] * lambda1), $MachinePrecision])), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(t$95$0 * (-lambda2)), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\\
\mathbf{if}\;\lambda_1 \leq -2.4 \cdot 10^{-100}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, t\_0 \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R\\

\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, t\_0 \cdot \left(-\lambda_2\right)\right) \cdot R\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda1 < -2.4000000000000003e-100

    1. Initial program 56.7%

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

        \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
      2. lift-sqrt.f64N/A

        \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
      3. lift-+.f64N/A

        \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
    3. Applied rewrites95.2%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
    4. Taylor expanded in lambda1 around -inf

      \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \color{blue}{\left(-1 \cdot \left(\lambda_1 \cdot \left(\frac{\lambda_2}{\lambda_1} - 1\right)\right)\right)}\right) \cdot R \]
    5. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\mathsf{neg}\left(\lambda_1 \cdot \left(\frac{\lambda_2}{\lambda_1} - 1\right)\right)\right)\right) \cdot R \]
      2. lower-neg.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\lambda_1 \cdot \left(\frac{\lambda_2}{\lambda_1} - 1\right)\right)\right) \cdot R \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      4. lower-*.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      5. lower--.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      6. lower-/.f6494.7

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
    6. Applied rewrites94.7%

      \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \color{blue}{\left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)}\right) \cdot R \]
    7. Step-by-step derivation
      1. lift-cos.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \color{blue}{\cos \left(\frac{\phi_2 + \phi_1}{2}\right)} \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      2. lift-+.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\color{blue}{\phi_2 + \phi_1}}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      3. lift-/.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(\frac{\phi_2 + \phi_1}{2}\right)} \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      4. div-addN/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(\frac{\phi_2}{2} + \frac{\phi_1}{2}\right)} \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      5. cos-sumN/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \color{blue}{\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)} \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      6. lower--.f64N/A

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

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\color{blue}{\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      8. lower-cos.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\color{blue}{\cos \left(\frac{\phi_2}{2}\right)} \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      9. lower-/.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \color{blue}{\left(\frac{\phi_2}{2}\right)} \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      10. lower-cos.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \color{blue}{\cos \left(\frac{\phi_1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      11. lower-/.f64N/A

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

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \color{blue}{\sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      13. lower-sin.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \color{blue}{\sin \left(\frac{\phi_2}{2}\right)} \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      14. lower-/.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \color{blue}{\left(\frac{\phi_2}{2}\right)} \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      15. lower-sin.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \color{blue}{\sin \left(\frac{\phi_1}{2}\right)}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      16. lower-/.f6499.2

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \color{blue}{\left(\frac{\phi_1}{2}\right)}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
    8. Applied rewrites99.2%

      \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \color{blue}{\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)} \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]

    if -2.4000000000000003e-100 < lambda1

    1. Initial program 62.1%

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

        \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
      2. lift-sqrt.f64N/A

        \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
      3. lift-+.f64N/A

        \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
    3. Applied rewrites96.9%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
    4. Taylor expanded in lambda1 around -inf

      \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \color{blue}{\left(-1 \cdot \left(\lambda_1 \cdot \left(\frac{\lambda_2}{\lambda_1} - 1\right)\right)\right)}\right) \cdot R \]
    5. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\mathsf{neg}\left(\lambda_1 \cdot \left(\frac{\lambda_2}{\lambda_1} - 1\right)\right)\right)\right) \cdot R \]
      2. lower-neg.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\lambda_1 \cdot \left(\frac{\lambda_2}{\lambda_1} - 1\right)\right)\right) \cdot R \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      4. lower-*.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      5. lower--.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      6. lower-/.f6481.7

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
    6. Applied rewrites81.7%

      \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \color{blue}{\left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)}\right) \cdot R \]
    7. Step-by-step derivation
      1. lift-cos.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \color{blue}{\cos \left(\frac{\phi_2 + \phi_1}{2}\right)} \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      2. lift-+.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\color{blue}{\phi_2 + \phi_1}}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      3. lift-/.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(\frac{\phi_2 + \phi_1}{2}\right)} \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      4. div-addN/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(\frac{\phi_2}{2} + \frac{\phi_1}{2}\right)} \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      5. cos-sumN/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \color{blue}{\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)} \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      6. lower--.f64N/A

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

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\color{blue}{\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      8. lower-cos.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\color{blue}{\cos \left(\frac{\phi_2}{2}\right)} \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      9. lower-/.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \color{blue}{\left(\frac{\phi_2}{2}\right)} \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      10. lower-cos.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \color{blue}{\cos \left(\frac{\phi_1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      11. lower-/.f64N/A

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

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \color{blue}{\sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      13. lower-sin.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \color{blue}{\sin \left(\frac{\phi_2}{2}\right)} \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      14. lower-/.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \color{blue}{\left(\frac{\phi_2}{2}\right)} \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      15. lower-sin.f64N/A

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \color{blue}{\sin \left(\frac{\phi_1}{2}\right)}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      16. lower-/.f6482.7

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \color{blue}{\left(\frac{\phi_1}{2}\right)}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
    8. Applied rewrites82.7%

      \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \color{blue}{\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)} \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
    9. Taylor expanded in lambda1 around 0

      \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\lambda_2\right)\right) \cdot R \]
    10. Step-by-step derivation
      1. Applied rewrites99.0%

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\lambda_2\right)\right) \cdot R \]
    11. Recombined 2 regimes into one program.
    12. Add Preprocessing

    Alternative 2: 96.6% accurate, 0.6× speedup?

    \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 6.8 \cdot 10^{-60}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \lambda_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\left(\frac{\lambda_1}{\lambda_2} - 1\right) \cdot \lambda_2\right)\right) \cdot R\\ \end{array} \end{array} \]
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (<= lambda2 6.8e-60)
       (*
        (hypot
         (- phi1 phi2)
         (*
          (-
           (* (cos (/ phi2 2.0)) (cos (/ phi1 2.0)))
           (* (sin (/ phi2 2.0)) (sin (/ phi1 2.0))))
          lambda1))
        R)
       (*
        (hypot
         (- phi1 phi2)
         (* (cos (/ (+ phi2 phi1) 2.0)) (* (- (/ lambda1 lambda2) 1.0) lambda2)))
        R)))
    assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (lambda2 <= 6.8e-60) {
    		tmp = hypot((phi1 - phi2), (((cos((phi2 / 2.0)) * cos((phi1 / 2.0))) - (sin((phi2 / 2.0)) * sin((phi1 / 2.0)))) * lambda1)) * R;
    	} else {
    		tmp = hypot((phi1 - phi2), (cos(((phi2 + phi1) / 2.0)) * (((lambda1 / lambda2) - 1.0) * lambda2))) * R;
    	}
    	return tmp;
    }
    
    assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (lambda2 <= 6.8e-60) {
    		tmp = Math.hypot((phi1 - phi2), (((Math.cos((phi2 / 2.0)) * Math.cos((phi1 / 2.0))) - (Math.sin((phi2 / 2.0)) * Math.sin((phi1 / 2.0)))) * lambda1)) * R;
    	} else {
    		tmp = Math.hypot((phi1 - phi2), (Math.cos(((phi2 + phi1) / 2.0)) * (((lambda1 / lambda2) - 1.0) * lambda2))) * R;
    	}
    	return tmp;
    }
    
    [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
    def code(R, lambda1, lambda2, phi1, phi2):
    	tmp = 0
    	if lambda2 <= 6.8e-60:
    		tmp = math.hypot((phi1 - phi2), (((math.cos((phi2 / 2.0)) * math.cos((phi1 / 2.0))) - (math.sin((phi2 / 2.0)) * math.sin((phi1 / 2.0)))) * lambda1)) * R
    	else:
    		tmp = math.hypot((phi1 - phi2), (math.cos(((phi2 + phi1) / 2.0)) * (((lambda1 / lambda2) - 1.0) * lambda2))) * R
    	return tmp
    
    R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (lambda2 <= 6.8e-60)
    		tmp = Float64(hypot(Float64(phi1 - phi2), Float64(Float64(Float64(cos(Float64(phi2 / 2.0)) * cos(Float64(phi1 / 2.0))) - Float64(sin(Float64(phi2 / 2.0)) * sin(Float64(phi1 / 2.0)))) * lambda1)) * R);
    	else
    		tmp = Float64(hypot(Float64(phi1 - phi2), Float64(cos(Float64(Float64(phi2 + phi1) / 2.0)) * Float64(Float64(Float64(lambda1 / lambda2) - 1.0) * lambda2))) * R);
    	end
    	return tmp
    end
    
    R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0;
    	if (lambda2 <= 6.8e-60)
    		tmp = hypot((phi1 - phi2), (((cos((phi2 / 2.0)) * cos((phi1 / 2.0))) - (sin((phi2 / 2.0)) * sin((phi1 / 2.0)))) * lambda1)) * R;
    	else
    		tmp = hypot((phi1 - phi2), (cos(((phi2 + phi1) / 2.0)) * (((lambda1 / lambda2) - 1.0) * lambda2))) * R;
    	end
    	tmp_2 = tmp;
    end
    
    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda2, 6.8e-60], N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(N[(N[(N[Cos[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * lambda1), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(N[Cos[N[(N[(phi2 + phi1), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] * N[(N[(N[(lambda1 / lambda2), $MachinePrecision] - 1.0), $MachinePrecision] * lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]]
    
    \begin{array}{l}
    [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
    \\
    \begin{array}{l}
    \mathbf{if}\;\lambda_2 \leq 6.8 \cdot 10^{-60}:\\
    \;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \lambda_1\right) \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\left(\frac{\lambda_1}{\lambda_2} - 1\right) \cdot \lambda_2\right)\right) \cdot R\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if lambda2 < 6.80000000000000013e-60

      1. Initial program 62.5%

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

          \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
        2. lift-sqrt.f64N/A

          \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
        3. lift-+.f64N/A

          \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
      3. Applied rewrites96.9%

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
      4. Taylor expanded in lambda1 around -inf

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \color{blue}{\left(-1 \cdot \left(\lambda_1 \cdot \left(\frac{\lambda_2}{\lambda_1} - 1\right)\right)\right)}\right) \cdot R \]
      5. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\mathsf{neg}\left(\lambda_1 \cdot \left(\frac{\lambda_2}{\lambda_1} - 1\right)\right)\right)\right) \cdot R \]
        2. lower-neg.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\lambda_1 \cdot \left(\frac{\lambda_2}{\lambda_1} - 1\right)\right)\right) \cdot R \]
        3. *-commutativeN/A

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        4. lower-*.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        5. lower--.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        6. lower-/.f6496.9

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      6. Applied rewrites96.9%

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \color{blue}{\left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)}\right) \cdot R \]
      7. Step-by-step derivation
        1. lift-cos.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \color{blue}{\cos \left(\frac{\phi_2 + \phi_1}{2}\right)} \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        2. lift-+.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\color{blue}{\phi_2 + \phi_1}}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        3. lift-/.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(\frac{\phi_2 + \phi_1}{2}\right)} \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        4. div-addN/A

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(\frac{\phi_2}{2} + \frac{\phi_1}{2}\right)} \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        5. cos-sumN/A

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \color{blue}{\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)} \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        6. lower--.f64N/A

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

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\color{blue}{\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        8. lower-cos.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\color{blue}{\cos \left(\frac{\phi_2}{2}\right)} \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        9. lower-/.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \color{blue}{\left(\frac{\phi_2}{2}\right)} \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        10. lower-cos.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \color{blue}{\cos \left(\frac{\phi_1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        11. lower-/.f64N/A

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

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \color{blue}{\sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        13. lower-sin.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \color{blue}{\sin \left(\frac{\phi_2}{2}\right)} \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        14. lower-/.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \color{blue}{\left(\frac{\phi_2}{2}\right)} \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        15. lower-sin.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \color{blue}{\sin \left(\frac{\phi_1}{2}\right)}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        16. lower-/.f6499.9

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \color{blue}{\left(\frac{\phi_1}{2}\right)}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      8. Applied rewrites99.9%

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \color{blue}{\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)} \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      9. Taylor expanded in lambda1 around inf

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \lambda_1\right) \cdot R \]
      10. Step-by-step derivation
        1. Applied rewrites98.3%

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \lambda_1\right) \cdot R \]

        if 6.80000000000000013e-60 < lambda2

        1. Initial program 55.9%

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

            \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
          2. lift-sqrt.f64N/A

            \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
          3. lift-+.f64N/A

            \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
        3. Applied rewrites95.1%

          \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
        4. Taylor expanded in lambda2 around inf

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \color{blue}{\left(\lambda_2 \cdot \left(\frac{\lambda_1}{\lambda_2} - 1\right)\right)}\right) \cdot R \]
        5. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\left(\frac{\lambda_1}{\lambda_2} - 1\right) \cdot \color{blue}{\lambda_2}\right)\right) \cdot R \]
          2. lower-*.f64N/A

            \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\left(\frac{\lambda_1}{\lambda_2} - 1\right) \cdot \color{blue}{\lambda_2}\right)\right) \cdot R \]
          3. lower--.f64N/A

            \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\left(\frac{\lambda_1}{\lambda_2} - 1\right) \cdot \lambda_2\right)\right) \cdot R \]
          4. lower-/.f6494.9

            \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\left(\frac{\lambda_1}{\lambda_2} - 1\right) \cdot \lambda_2\right)\right) \cdot R \]
        6. Applied rewrites94.9%

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \color{blue}{\left(\left(\frac{\lambda_1}{\lambda_2} - 1\right) \cdot \lambda_2\right)}\right) \cdot R \]
      11. Recombined 2 regimes into one program.
      12. Add Preprocessing

      Alternative 3: 96.0% accurate, 1.7× speedup?

      \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \end{array} \]
      NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
      (FPCore (R lambda1 lambda2 phi1 phi2)
       :precision binary64
       (*
        (hypot (- phi1 phi2) (* (cos (/ (+ phi2 phi1) 2.0)) (- lambda1 lambda2)))
        R))
      assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
      double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	return hypot((phi1 - phi2), (cos(((phi2 + phi1) / 2.0)) * (lambda1 - lambda2))) * R;
      }
      
      assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
      public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	return Math.hypot((phi1 - phi2), (Math.cos(((phi2 + phi1) / 2.0)) * (lambda1 - lambda2))) * R;
      }
      
      [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
      def code(R, lambda1, lambda2, phi1, phi2):
      	return math.hypot((phi1 - phi2), (math.cos(((phi2 + phi1) / 2.0)) * (lambda1 - lambda2))) * R
      
      R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
      function code(R, lambda1, lambda2, phi1, phi2)
      	return Float64(hypot(Float64(phi1 - phi2), Float64(cos(Float64(Float64(phi2 + phi1) / 2.0)) * Float64(lambda1 - lambda2))) * R)
      end
      
      R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
      function tmp = code(R, lambda1, lambda2, phi1, phi2)
      	tmp = hypot((phi1 - phi2), (cos(((phi2 + phi1) / 2.0)) * (lambda1 - lambda2))) * R;
      end
      
      NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
      code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(N[Cos[N[(N[(phi2 + phi1), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]
      
      \begin{array}{l}
      [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
      \\
      \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R
      \end{array}
      
      Derivation
      1. Initial program 59.1%

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

          \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
        2. lift-sqrt.f64N/A

          \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
        3. lift-+.f64N/A

          \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
      3. Applied rewrites96.0%

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
      4. Add Preprocessing

      Alternative 4: 92.7% accurate, 1.7× speedup?

      \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 7 \cdot 10^{-68}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \end{array} \end{array} \]
      NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
      (FPCore (R lambda1 lambda2 phi1 phi2)
       :precision binary64
       (if (<= phi2 7e-68)
         (* (hypot (- phi1 phi2) (* (cos (* 0.5 phi1)) (- lambda1 lambda2))) R)
         (* (hypot (- phi1 phi2) (* (cos (* 0.5 phi2)) (- lambda1 lambda2))) R)))
      assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
      double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	double tmp;
      	if (phi2 <= 7e-68) {
      		tmp = hypot((phi1 - phi2), (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
      	} else {
      		tmp = hypot((phi1 - phi2), (cos((0.5 * phi2)) * (lambda1 - lambda2))) * R;
      	}
      	return tmp;
      }
      
      assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
      public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	double tmp;
      	if (phi2 <= 7e-68) {
      		tmp = Math.hypot((phi1 - phi2), (Math.cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
      	} else {
      		tmp = Math.hypot((phi1 - phi2), (Math.cos((0.5 * phi2)) * (lambda1 - lambda2))) * R;
      	}
      	return tmp;
      }
      
      [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
      def code(R, lambda1, lambda2, phi1, phi2):
      	tmp = 0
      	if phi2 <= 7e-68:
      		tmp = math.hypot((phi1 - phi2), (math.cos((0.5 * phi1)) * (lambda1 - lambda2))) * R
      	else:
      		tmp = math.hypot((phi1 - phi2), (math.cos((0.5 * phi2)) * (lambda1 - lambda2))) * R
      	return tmp
      
      R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
      function code(R, lambda1, lambda2, phi1, phi2)
      	tmp = 0.0
      	if (phi2 <= 7e-68)
      		tmp = Float64(hypot(Float64(phi1 - phi2), Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2))) * R);
      	else
      		tmp = Float64(hypot(Float64(phi1 - phi2), Float64(cos(Float64(0.5 * phi2)) * Float64(lambda1 - lambda2))) * R);
      	end
      	return tmp
      end
      
      R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
      function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
      	tmp = 0.0;
      	if (phi2 <= 7e-68)
      		tmp = hypot((phi1 - phi2), (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
      	else
      		tmp = hypot((phi1 - phi2), (cos((0.5 * phi2)) * (lambda1 - lambda2))) * R;
      	end
      	tmp_2 = tmp;
      end
      
      NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
      code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 7e-68], N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]]
      
      \begin{array}{l}
      [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
      \\
      \begin{array}{l}
      \mathbf{if}\;\phi_2 \leq 7 \cdot 10^{-68}:\\
      \;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
      
      \mathbf{else}:\\
      \;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if phi2 < 7.00000000000000026e-68

        1. Initial program 60.4%

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

            \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
          2. lift-sqrt.f64N/A

            \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
          3. lift-+.f64N/A

            \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
        3. Applied rewrites97.1%

          \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
        4. Taylor expanded in phi1 around inf

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
        5. Step-by-step derivation
          1. lower-*.f6493.0

            \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \color{blue}{\phi_1}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
        6. Applied rewrites93.0%

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(0.5 \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]

        if 7.00000000000000026e-68 < phi2

        1. Initial program 56.3%

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

            \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
          2. lift-sqrt.f64N/A

            \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
          3. lift-+.f64N/A

            \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
        3. Applied rewrites93.5%

          \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
        4. Taylor expanded in phi1 around 0

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_2\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
        5. Step-by-step derivation
          1. lower-*.f6491.9

            \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \color{blue}{\phi_2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
        6. Applied rewrites91.9%

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(0.5 \cdot \phi_2\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. Recombined 2 regimes into one program.
      4. Add Preprocessing

      Alternative 5: 90.6% accurate, 1.8× speedup?

      \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \end{array} \]
      NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
      (FPCore (R lambda1 lambda2 phi1 phi2)
       :precision binary64
       (* (hypot (- phi1 phi2) (* (cos (* 0.5 phi1)) (- lambda1 lambda2))) R))
      assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
      double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	return hypot((phi1 - phi2), (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
      }
      
      assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
      public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	return Math.hypot((phi1 - phi2), (Math.cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
      }
      
      [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
      def code(R, lambda1, lambda2, phi1, phi2):
      	return math.hypot((phi1 - phi2), (math.cos((0.5 * phi1)) * (lambda1 - lambda2))) * R
      
      R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
      function code(R, lambda1, lambda2, phi1, phi2)
      	return Float64(hypot(Float64(phi1 - phi2), Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2))) * R)
      end
      
      R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
      function tmp = code(R, lambda1, lambda2, phi1, phi2)
      	tmp = hypot((phi1 - phi2), (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
      end
      
      NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
      code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]
      
      \begin{array}{l}
      [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
      \\
      \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R
      \end{array}
      
      Derivation
      1. Initial program 59.1%

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

          \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
        2. lift-sqrt.f64N/A

          \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
        3. lift-+.f64N/A

          \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
      3. Applied rewrites96.0%

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
      4. Taylor expanded in phi1 around inf

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      5. Step-by-step derivation
        1. lower-*.f6490.6

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \color{blue}{\phi_1}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      6. Applied rewrites90.6%

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(0.5 \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      7. Add Preprocessing

      Alternative 6: 79.0% accurate, 1.7× speedup?

      \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \cos \left(0.5 \cdot \phi_1\right)\\ \mathbf{if}\;\phi_2 \leq 5.6 \cdot 10^{-12}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1, t\_0 \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, t\_0 \cdot \lambda_1\right) \cdot R\\ \end{array} \end{array} \]
      NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
      (FPCore (R lambda1 lambda2 phi1 phi2)
       :precision binary64
       (let* ((t_0 (cos (* 0.5 phi1))))
         (if (<= phi2 5.6e-12)
           (* (hypot phi1 (* t_0 (- lambda1 lambda2))) R)
           (* (hypot (- phi1 phi2) (* t_0 lambda1)) R))))
      assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
      double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	double t_0 = cos((0.5 * phi1));
      	double tmp;
      	if (phi2 <= 5.6e-12) {
      		tmp = hypot(phi1, (t_0 * (lambda1 - lambda2))) * R;
      	} else {
      		tmp = hypot((phi1 - phi2), (t_0 * lambda1)) * R;
      	}
      	return tmp;
      }
      
      assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
      public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	double t_0 = Math.cos((0.5 * phi1));
      	double tmp;
      	if (phi2 <= 5.6e-12) {
      		tmp = Math.hypot(phi1, (t_0 * (lambda1 - lambda2))) * R;
      	} else {
      		tmp = Math.hypot((phi1 - phi2), (t_0 * lambda1)) * R;
      	}
      	return tmp;
      }
      
      [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
      def code(R, lambda1, lambda2, phi1, phi2):
      	t_0 = math.cos((0.5 * phi1))
      	tmp = 0
      	if phi2 <= 5.6e-12:
      		tmp = math.hypot(phi1, (t_0 * (lambda1 - lambda2))) * R
      	else:
      		tmp = math.hypot((phi1 - phi2), (t_0 * lambda1)) * R
      	return tmp
      
      R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
      function code(R, lambda1, lambda2, phi1, phi2)
      	t_0 = cos(Float64(0.5 * phi1))
      	tmp = 0.0
      	if (phi2 <= 5.6e-12)
      		tmp = Float64(hypot(phi1, Float64(t_0 * Float64(lambda1 - lambda2))) * R);
      	else
      		tmp = Float64(hypot(Float64(phi1 - phi2), Float64(t_0 * lambda1)) * R);
      	end
      	return tmp
      end
      
      R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
      function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
      	t_0 = cos((0.5 * phi1));
      	tmp = 0.0;
      	if (phi2 <= 5.6e-12)
      		tmp = hypot(phi1, (t_0 * (lambda1 - lambda2))) * R;
      	else
      		tmp = hypot((phi1 - phi2), (t_0 * lambda1)) * R;
      	end
      	tmp_2 = tmp;
      end
      
      NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
      code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, 5.6e-12], N[(N[Sqrt[phi1 ^ 2 + N[(t$95$0 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(t$95$0 * lambda1), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]]]
      
      \begin{array}{l}
      [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
      \\
      \begin{array}{l}
      t_0 := \cos \left(0.5 \cdot \phi_1\right)\\
      \mathbf{if}\;\phi_2 \leq 5.6 \cdot 10^{-12}:\\
      \;\;\;\;\mathsf{hypot}\left(\phi_1, t\_0 \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
      
      \mathbf{else}:\\
      \;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, t\_0 \cdot \lambda_1\right) \cdot R\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if phi2 < 5.6000000000000004e-12

        1. Initial program 60.9%

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

            \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
          2. lift-sqrt.f64N/A

            \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
          3. lift-+.f64N/A

            \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
        3. Applied rewrites97.3%

          \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
        4. Taylor expanded in phi1 around inf

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
        5. Step-by-step derivation
          1. lower-*.f6493.4

            \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \color{blue}{\phi_1}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
        6. Applied rewrites93.4%

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(0.5 \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
        7. Taylor expanded in phi1 around inf

          \[\leadsto \mathsf{hypot}\left(\color{blue}{\phi_1}, \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
        8. Step-by-step derivation
          1. Applied rewrites79.2%

            \[\leadsto \mathsf{hypot}\left(\color{blue}{\phi_1}, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]

          if 5.6000000000000004e-12 < phi2

          1. Initial program 54.0%

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

              \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
            2. lift-sqrt.f64N/A

              \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
            3. lift-+.f64N/A

              \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
          3. Applied rewrites92.4%

            \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
          4. Taylor expanded in phi1 around inf

            \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
          5. Step-by-step derivation
            1. lower-*.f6482.4

              \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \color{blue}{\phi_1}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
          6. Applied rewrites82.4%

            \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(0.5 \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
          7. Taylor expanded in lambda1 around inf

            \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \color{blue}{\lambda_1}\right) \cdot R \]
          8. Step-by-step derivation
            1. Applied rewrites78.5%

              \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \phi_1\right) \cdot \color{blue}{\lambda_1}\right) \cdot R \]
          9. Recombined 2 regimes into one program.
          10. Add Preprocessing

          Alternative 7: 75.2% accurate, 1.7× speedup?

          \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.2 \cdot 10^{-8}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\left(\left(-\phi_2\right) \cdot \left(\frac{\phi_1}{\phi_2} - 1\right)\right) \cdot R\\ \end{array} \end{array} \]
          NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
          (FPCore (R lambda1 lambda2 phi1 phi2)
           :precision binary64
           (if (<= phi2 1.2e-8)
             (* (hypot phi1 (* (cos (* 0.5 phi1)) (- lambda1 lambda2))) R)
             (* (* (- phi2) (- (/ phi1 phi2) 1.0)) R)))
          assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
          double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
          	double tmp;
          	if (phi2 <= 1.2e-8) {
          		tmp = hypot(phi1, (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
          	} else {
          		tmp = (-phi2 * ((phi1 / phi2) - 1.0)) * R;
          	}
          	return tmp;
          }
          
          assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
          public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
          	double tmp;
          	if (phi2 <= 1.2e-8) {
          		tmp = Math.hypot(phi1, (Math.cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
          	} else {
          		tmp = (-phi2 * ((phi1 / phi2) - 1.0)) * R;
          	}
          	return tmp;
          }
          
          [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
          def code(R, lambda1, lambda2, phi1, phi2):
          	tmp = 0
          	if phi2 <= 1.2e-8:
          		tmp = math.hypot(phi1, (math.cos((0.5 * phi1)) * (lambda1 - lambda2))) * R
          	else:
          		tmp = (-phi2 * ((phi1 / phi2) - 1.0)) * R
          	return tmp
          
          R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
          function code(R, lambda1, lambda2, phi1, phi2)
          	tmp = 0.0
          	if (phi2 <= 1.2e-8)
          		tmp = Float64(hypot(phi1, Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2))) * R);
          	else
          		tmp = Float64(Float64(Float64(-phi2) * Float64(Float64(phi1 / phi2) - 1.0)) * R);
          	end
          	return tmp
          end
          
          R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
          function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
          	tmp = 0.0;
          	if (phi2 <= 1.2e-8)
          		tmp = hypot(phi1, (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
          	else
          		tmp = (-phi2 * ((phi1 / phi2) - 1.0)) * R;
          	end
          	tmp_2 = tmp;
          end
          
          NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
          code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 1.2e-8], N[(N[Sqrt[phi1 ^ 2 + N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(N[((-phi2) * N[(N[(phi1 / phi2), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision]]
          
          \begin{array}{l}
          [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
          \\
          \begin{array}{l}
          \mathbf{if}\;\phi_2 \leq 1.2 \cdot 10^{-8}:\\
          \;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
          
          \mathbf{else}:\\
          \;\;\;\;\left(\left(-\phi_2\right) \cdot \left(\frac{\phi_1}{\phi_2} - 1\right)\right) \cdot R\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if phi2 < 1.19999999999999999e-8

            1. Initial program 60.9%

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

                \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
              2. lift-sqrt.f64N/A

                \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
              3. lift-+.f64N/A

                \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
            3. Applied rewrites97.3%

              \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
            4. Taylor expanded in phi1 around inf

              \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
            5. Step-by-step derivation
              1. lower-*.f6493.4

                \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \color{blue}{\phi_1}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
            6. Applied rewrites93.4%

              \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(0.5 \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
            7. Taylor expanded in phi1 around inf

              \[\leadsto \mathsf{hypot}\left(\color{blue}{\phi_1}, \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
            8. Step-by-step derivation
              1. Applied rewrites79.2%

                \[\leadsto \mathsf{hypot}\left(\color{blue}{\phi_1}, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]

              if 1.19999999999999999e-8 < phi2

              1. Initial program 54.0%

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

                  \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                2. lift-sqrt.f64N/A

                  \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                3. lift-+.f64N/A

                  \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
              3. Applied rewrites92.3%

                \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
              4. Taylor expanded in phi2 around inf

                \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \cdot R \]
              5. Step-by-step derivation
                1. Applied rewrites63.3%

                  \[\leadsto \color{blue}{\left(\left(\frac{-\phi_1}{\phi_2} + 1\right) \cdot \phi_2\right)} \cdot R \]
                2. Taylor expanded in phi2 around -inf

                  \[\leadsto \left(-1 \cdot \color{blue}{\left(\phi_2 \cdot \left(\frac{\phi_1}{\phi_2} - 1\right)\right)}\right) \cdot R \]
                3. Step-by-step derivation
                  1. associate-*r*N/A

                    \[\leadsto \left(\left(-1 \cdot \phi_2\right) \cdot \left(\frac{\phi_1}{\phi_2} - \color{blue}{1}\right)\right) \cdot R \]
                  2. mul-1-negN/A

                    \[\leadsto \left(\left(\mathsf{neg}\left(\phi_2\right)\right) \cdot \left(\frac{\phi_1}{\phi_2} - 1\right)\right) \cdot R \]
                  3. lower-*.f64N/A

                    \[\leadsto \left(\left(\mathsf{neg}\left(\phi_2\right)\right) \cdot \left(\frac{\phi_1}{\phi_2} - \color{blue}{1}\right)\right) \cdot R \]
                  4. lower-neg.f64N/A

                    \[\leadsto \left(\left(-\phi_2\right) \cdot \left(\frac{\phi_1}{\phi_2} - 1\right)\right) \cdot R \]
                  5. lower--.f64N/A

                    \[\leadsto \left(\left(-\phi_2\right) \cdot \left(\frac{\phi_1}{\phi_2} - 1\right)\right) \cdot R \]
                  6. lower-/.f6463.3

                    \[\leadsto \left(\left(-\phi_2\right) \cdot \left(\frac{\phi_1}{\phi_2} - 1\right)\right) \cdot R \]
                4. Applied rewrites63.3%

                  \[\leadsto \left(\left(-\phi_2\right) \cdot \color{blue}{\left(\frac{\phi_1}{\phi_2} - 1\right)}\right) \cdot R \]
              6. Recombined 2 regimes into one program.
              7. Add Preprocessing

              Alternative 8: 34.4% accurate, 1.9× speedup?

              \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -5.3 \cdot 10^{+225}:\\ \;\;\;\;\left(-\cos \left(\phi_2 \cdot 0.5\right) \cdot \lambda_1\right) \cdot R\\ \mathbf{elif}\;\lambda_1 \leq -1.4 \cdot 10^{+129}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(\left(-\frac{\phi_2 \cdot R}{\phi_1}\right) + R\right)\\ \mathbf{elif}\;\lambda_1 \leq -4.8 \cdot 10^{+97}:\\ \;\;\;\;-\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \lambda_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\left(\left(-\phi_1\right) + \phi_2\right) \cdot R\\ \end{array} \end{array} \]
              NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
              (FPCore (R lambda1 lambda2 phi1 phi2)
               :precision binary64
               (if (<= lambda1 -5.3e+225)
                 (* (- (* (cos (* phi2 0.5)) lambda1)) R)
                 (if (<= lambda1 -1.4e+129)
                   (* (- phi1) (+ (- (/ (* phi2 R) phi1)) R))
                   (if (<= lambda1 -4.8e+97)
                     (- (* (* (cos (* 0.5 (+ phi2 phi1))) lambda1) R))
                     (* (+ (- phi1) phi2) R)))))
              assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
              double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
              	double tmp;
              	if (lambda1 <= -5.3e+225) {
              		tmp = -(cos((phi2 * 0.5)) * lambda1) * R;
              	} else if (lambda1 <= -1.4e+129) {
              		tmp = -phi1 * (-((phi2 * R) / phi1) + R);
              	} else if (lambda1 <= -4.8e+97) {
              		tmp = -((cos((0.5 * (phi2 + phi1))) * lambda1) * R);
              	} else {
              		tmp = (-phi1 + phi2) * R;
              	}
              	return tmp;
              }
              
              NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
              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(r, lambda1, lambda2, phi1, phi2)
              use fmin_fmax_functions
                  real(8), intent (in) :: r
                  real(8), intent (in) :: lambda1
                  real(8), intent (in) :: lambda2
                  real(8), intent (in) :: phi1
                  real(8), intent (in) :: phi2
                  real(8) :: tmp
                  if (lambda1 <= (-5.3d+225)) then
                      tmp = -(cos((phi2 * 0.5d0)) * lambda1) * r
                  else if (lambda1 <= (-1.4d+129)) then
                      tmp = -phi1 * (-((phi2 * r) / phi1) + r)
                  else if (lambda1 <= (-4.8d+97)) then
                      tmp = -((cos((0.5d0 * (phi2 + phi1))) * lambda1) * r)
                  else
                      tmp = (-phi1 + phi2) * r
                  end if
                  code = tmp
              end function
              
              assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
              public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
              	double tmp;
              	if (lambda1 <= -5.3e+225) {
              		tmp = -(Math.cos((phi2 * 0.5)) * lambda1) * R;
              	} else if (lambda1 <= -1.4e+129) {
              		tmp = -phi1 * (-((phi2 * R) / phi1) + R);
              	} else if (lambda1 <= -4.8e+97) {
              		tmp = -((Math.cos((0.5 * (phi2 + phi1))) * lambda1) * R);
              	} else {
              		tmp = (-phi1 + phi2) * R;
              	}
              	return tmp;
              }
              
              [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
              def code(R, lambda1, lambda2, phi1, phi2):
              	tmp = 0
              	if lambda1 <= -5.3e+225:
              		tmp = -(math.cos((phi2 * 0.5)) * lambda1) * R
              	elif lambda1 <= -1.4e+129:
              		tmp = -phi1 * (-((phi2 * R) / phi1) + R)
              	elif lambda1 <= -4.8e+97:
              		tmp = -((math.cos((0.5 * (phi2 + phi1))) * lambda1) * R)
              	else:
              		tmp = (-phi1 + phi2) * R
              	return tmp
              
              R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
              function code(R, lambda1, lambda2, phi1, phi2)
              	tmp = 0.0
              	if (lambda1 <= -5.3e+225)
              		tmp = Float64(Float64(-Float64(cos(Float64(phi2 * 0.5)) * lambda1)) * R);
              	elseif (lambda1 <= -1.4e+129)
              		tmp = Float64(Float64(-phi1) * Float64(Float64(-Float64(Float64(phi2 * R) / phi1)) + R));
              	elseif (lambda1 <= -4.8e+97)
              		tmp = Float64(-Float64(Float64(cos(Float64(0.5 * Float64(phi2 + phi1))) * lambda1) * R));
              	else
              		tmp = Float64(Float64(Float64(-phi1) + phi2) * R);
              	end
              	return tmp
              end
              
              R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
              function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
              	tmp = 0.0;
              	if (lambda1 <= -5.3e+225)
              		tmp = -(cos((phi2 * 0.5)) * lambda1) * R;
              	elseif (lambda1 <= -1.4e+129)
              		tmp = -phi1 * (-((phi2 * R) / phi1) + R);
              	elseif (lambda1 <= -4.8e+97)
              		tmp = -((cos((0.5 * (phi2 + phi1))) * lambda1) * R);
              	else
              		tmp = (-phi1 + phi2) * R;
              	end
              	tmp_2 = tmp;
              end
              
              NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
              code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda1, -5.3e+225], N[((-N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * lambda1), $MachinePrecision]) * R), $MachinePrecision], If[LessEqual[lambda1, -1.4e+129], N[((-phi1) * N[((-N[(N[(phi2 * R), $MachinePrecision] / phi1), $MachinePrecision]) + R), $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda1, -4.8e+97], (-N[(N[(N[Cos[N[(0.5 * N[(phi2 + phi1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * lambda1), $MachinePrecision] * R), $MachinePrecision]), N[(N[((-phi1) + phi2), $MachinePrecision] * R), $MachinePrecision]]]]
              
              \begin{array}{l}
              [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
              \\
              \begin{array}{l}
              \mathbf{if}\;\lambda_1 \leq -5.3 \cdot 10^{+225}:\\
              \;\;\;\;\left(-\cos \left(\phi_2 \cdot 0.5\right) \cdot \lambda_1\right) \cdot R\\
              
              \mathbf{elif}\;\lambda_1 \leq -1.4 \cdot 10^{+129}:\\
              \;\;\;\;\left(-\phi_1\right) \cdot \left(\left(-\frac{\phi_2 \cdot R}{\phi_1}\right) + R\right)\\
              
              \mathbf{elif}\;\lambda_1 \leq -4.8 \cdot 10^{+97}:\\
              \;\;\;\;-\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \lambda_1\right) \cdot R\\
              
              \mathbf{else}:\\
              \;\;\;\;\left(\left(-\phi_1\right) + \phi_2\right) \cdot R\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 4 regimes
              2. if lambda1 < -5.3000000000000002e225

                1. Initial program 45.5%

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

                    \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                  2. lift-sqrt.f64N/A

                    \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                  3. lift-+.f64N/A

                    \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                3. Applied rewrites89.3%

                  \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
                4. Taylor expanded in lambda1 around -inf

                  \[\leadsto \color{blue}{\left(-1 \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} \cdot R \]
                5. Step-by-step derivation
                  1. Applied rewrites49.8%

                    \[\leadsto \color{blue}{\left(-\cos \left(\left(\phi_2 + \phi_1\right) \cdot 0.5\right) \cdot \lambda_1\right)} \cdot R \]
                  2. Taylor expanded in phi1 around 0

                    \[\leadsto \left(-\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \lambda_1\right) \cdot R \]
                  3. Step-by-step derivation
                    1. Applied rewrites52.2%

                      \[\leadsto \left(-\cos \left(\phi_2 \cdot 0.5\right) \cdot \lambda_1\right) \cdot R \]

                    if -5.3000000000000002e225 < lambda1 < -1.39999999999999987e129

                    1. Initial program 45.8%

                      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
                    2. Taylor expanded in phi1 around -inf

                      \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
                    3. Step-by-step derivation
                      1. associate-*r*N/A

                        \[\leadsto \left(-1 \cdot \phi_1\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                      2. mul-1-negN/A

                        \[\leadsto \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \left(\color{blue}{R} + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right) \]
                      3. lower-*.f64N/A

                        \[\leadsto \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                      4. lower-neg.f64N/A

                        \[\leadsto \left(-\phi_1\right) \cdot \left(\color{blue}{R} + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right) \]
                      5. +-commutativeN/A

                        \[\leadsto \left(-\phi_1\right) \cdot \left(-1 \cdot \frac{R \cdot \phi_2}{\phi_1} + \color{blue}{R}\right) \]
                      6. lower-+.f64N/A

                        \[\leadsto \left(-\phi_1\right) \cdot \left(-1 \cdot \frac{R \cdot \phi_2}{\phi_1} + \color{blue}{R}\right) \]
                      7. mul-1-negN/A

                        \[\leadsto \left(-\phi_1\right) \cdot \left(\left(\mathsf{neg}\left(\frac{R \cdot \phi_2}{\phi_1}\right)\right) + R\right) \]
                      8. lower-neg.f64N/A

                        \[\leadsto \left(-\phi_1\right) \cdot \left(\left(-\frac{R \cdot \phi_2}{\phi_1}\right) + R\right) \]
                      9. lower-/.f64N/A

                        \[\leadsto \left(-\phi_1\right) \cdot \left(\left(-\frac{R \cdot \phi_2}{\phi_1}\right) + R\right) \]
                      10. *-commutativeN/A

                        \[\leadsto \left(-\phi_1\right) \cdot \left(\left(-\frac{\phi_2 \cdot R}{\phi_1}\right) + R\right) \]
                      11. lower-*.f6424.7

                        \[\leadsto \left(-\phi_1\right) \cdot \left(\left(-\frac{\phi_2 \cdot R}{\phi_1}\right) + R\right) \]
                    4. Applied rewrites24.7%

                      \[\leadsto \color{blue}{\left(-\phi_1\right) \cdot \left(\left(-\frac{\phi_2 \cdot R}{\phi_1}\right) + R\right)} \]

                    if -1.39999999999999987e129 < lambda1 < -4.8e97

                    1. Initial program 63.5%

                      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
                    2. Taylor expanded in lambda1 around -inf

                      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} \]
                    3. Step-by-step derivation
                      1. mul-1-negN/A

                        \[\leadsto \mathsf{neg}\left(R \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right) \]
                      2. lower-neg.f64N/A

                        \[\leadsto -R \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right) \]
                      3. *-commutativeN/A

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

                        \[\leadsto -\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right) \cdot R \]
                      5. *-commutativeN/A

                        \[\leadsto -\left(\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \lambda_1\right) \cdot R \]
                      6. lower-*.f64N/A

                        \[\leadsto -\left(\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \lambda_1\right) \cdot R \]
                      7. lower-cos.f64N/A

                        \[\leadsto -\left(\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \lambda_1\right) \cdot R \]
                      8. lower-*.f64N/A

                        \[\leadsto -\left(\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \lambda_1\right) \cdot R \]
                      9. +-commutativeN/A

                        \[\leadsto -\left(\cos \left(\frac{1}{2} \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \lambda_1\right) \cdot R \]
                      10. lower-+.f6433.3

                        \[\leadsto -\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \lambda_1\right) \cdot R \]
                    4. Applied rewrites33.3%

                      \[\leadsto \color{blue}{-\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \lambda_1\right) \cdot R} \]

                    if -4.8e97 < lambda1

                    1. Initial program 64.1%

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

                        \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                      2. lift-sqrt.f64N/A

                        \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                      3. lift-+.f64N/A

                        \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                    3. Applied rewrites97.3%

                      \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
                    4. Taylor expanded in phi2 around inf

                      \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \cdot R \]
                    5. Step-by-step derivation
                      1. Applied rewrites30.4%

                        \[\leadsto \color{blue}{\left(\left(\frac{-\phi_1}{\phi_2} + 1\right) \cdot \phi_2\right)} \cdot R \]
                      2. Taylor expanded in phi1 around 0

                        \[\leadsto \left(\phi_2 + \color{blue}{-1 \cdot \phi_1}\right) \cdot R \]
                      3. Step-by-step derivation
                        1. mul-1-negN/A

                          \[\leadsto \left(\phi_2 + \left(\mathsf{neg}\left(\phi_1\right)\right)\right) \cdot R \]
                        2. lift-neg.f64N/A

                          \[\leadsto \left(\phi_2 + \left(-\phi_1\right)\right) \cdot R \]
                        3. +-commutativeN/A

                          \[\leadsto \left(\left(-\phi_1\right) + \phi_2\right) \cdot R \]
                        4. lower-+.f6433.0

                          \[\leadsto \left(\left(-\phi_1\right) + \phi_2\right) \cdot R \]
                      4. Applied rewrites33.0%

                        \[\leadsto \left(\left(-\phi_1\right) + \color{blue}{\phi_2}\right) \cdot R \]
                    6. Recombined 4 regimes into one program.
                    7. Add Preprocessing

                    Alternative 9: 34.3% accurate, 2.0× speedup?

                    \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -5.3 \cdot 10^{+225}:\\ \;\;\;\;\left(-\cos \left(\phi_2 \cdot 0.5\right) \cdot \lambda_1\right) \cdot R\\ \mathbf{elif}\;\lambda_1 \leq -1.4 \cdot 10^{+129}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(\left(-\frac{\phi_2 \cdot R}{\phi_1}\right) + R\right)\\ \mathbf{elif}\;\lambda_1 \leq -4.8 \cdot 10^{+97}:\\ \;\;\;\;\left(-\cos \left(\phi_1 \cdot 0.5\right) \cdot \lambda_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\left(\left(-\phi_1\right) + \phi_2\right) \cdot R\\ \end{array} \end{array} \]
                    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                    (FPCore (R lambda1 lambda2 phi1 phi2)
                     :precision binary64
                     (if (<= lambda1 -5.3e+225)
                       (* (- (* (cos (* phi2 0.5)) lambda1)) R)
                       (if (<= lambda1 -1.4e+129)
                         (* (- phi1) (+ (- (/ (* phi2 R) phi1)) R))
                         (if (<= lambda1 -4.8e+97)
                           (* (- (* (cos (* phi1 0.5)) lambda1)) R)
                           (* (+ (- phi1) phi2) R)))))
                    assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                    	double tmp;
                    	if (lambda1 <= -5.3e+225) {
                    		tmp = -(cos((phi2 * 0.5)) * lambda1) * R;
                    	} else if (lambda1 <= -1.4e+129) {
                    		tmp = -phi1 * (-((phi2 * R) / phi1) + R);
                    	} else if (lambda1 <= -4.8e+97) {
                    		tmp = -(cos((phi1 * 0.5)) * lambda1) * R;
                    	} else {
                    		tmp = (-phi1 + phi2) * R;
                    	}
                    	return tmp;
                    }
                    
                    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                    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(r, lambda1, lambda2, phi1, phi2)
                    use fmin_fmax_functions
                        real(8), intent (in) :: r
                        real(8), intent (in) :: lambda1
                        real(8), intent (in) :: lambda2
                        real(8), intent (in) :: phi1
                        real(8), intent (in) :: phi2
                        real(8) :: tmp
                        if (lambda1 <= (-5.3d+225)) then
                            tmp = -(cos((phi2 * 0.5d0)) * lambda1) * r
                        else if (lambda1 <= (-1.4d+129)) then
                            tmp = -phi1 * (-((phi2 * r) / phi1) + r)
                        else if (lambda1 <= (-4.8d+97)) then
                            tmp = -(cos((phi1 * 0.5d0)) * lambda1) * r
                        else
                            tmp = (-phi1 + phi2) * r
                        end if
                        code = tmp
                    end function
                    
                    assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
                    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                    	double tmp;
                    	if (lambda1 <= -5.3e+225) {
                    		tmp = -(Math.cos((phi2 * 0.5)) * lambda1) * R;
                    	} else if (lambda1 <= -1.4e+129) {
                    		tmp = -phi1 * (-((phi2 * R) / phi1) + R);
                    	} else if (lambda1 <= -4.8e+97) {
                    		tmp = -(Math.cos((phi1 * 0.5)) * lambda1) * R;
                    	} else {
                    		tmp = (-phi1 + phi2) * R;
                    	}
                    	return tmp;
                    }
                    
                    [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
                    def code(R, lambda1, lambda2, phi1, phi2):
                    	tmp = 0
                    	if lambda1 <= -5.3e+225:
                    		tmp = -(math.cos((phi2 * 0.5)) * lambda1) * R
                    	elif lambda1 <= -1.4e+129:
                    		tmp = -phi1 * (-((phi2 * R) / phi1) + R)
                    	elif lambda1 <= -4.8e+97:
                    		tmp = -(math.cos((phi1 * 0.5)) * lambda1) * R
                    	else:
                    		tmp = (-phi1 + phi2) * R
                    	return tmp
                    
                    R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                    function code(R, lambda1, lambda2, phi1, phi2)
                    	tmp = 0.0
                    	if (lambda1 <= -5.3e+225)
                    		tmp = Float64(Float64(-Float64(cos(Float64(phi2 * 0.5)) * lambda1)) * R);
                    	elseif (lambda1 <= -1.4e+129)
                    		tmp = Float64(Float64(-phi1) * Float64(Float64(-Float64(Float64(phi2 * R) / phi1)) + R));
                    	elseif (lambda1 <= -4.8e+97)
                    		tmp = Float64(Float64(-Float64(cos(Float64(phi1 * 0.5)) * lambda1)) * R);
                    	else
                    		tmp = Float64(Float64(Float64(-phi1) + phi2) * R);
                    	end
                    	return tmp
                    end
                    
                    R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
                    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
                    	tmp = 0.0;
                    	if (lambda1 <= -5.3e+225)
                    		tmp = -(cos((phi2 * 0.5)) * lambda1) * R;
                    	elseif (lambda1 <= -1.4e+129)
                    		tmp = -phi1 * (-((phi2 * R) / phi1) + R);
                    	elseif (lambda1 <= -4.8e+97)
                    		tmp = -(cos((phi1 * 0.5)) * lambda1) * R;
                    	else
                    		tmp = (-phi1 + phi2) * R;
                    	end
                    	tmp_2 = tmp;
                    end
                    
                    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda1, -5.3e+225], N[((-N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * lambda1), $MachinePrecision]) * R), $MachinePrecision], If[LessEqual[lambda1, -1.4e+129], N[((-phi1) * N[((-N[(N[(phi2 * R), $MachinePrecision] / phi1), $MachinePrecision]) + R), $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda1, -4.8e+97], N[((-N[(N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision] * lambda1), $MachinePrecision]) * R), $MachinePrecision], N[(N[((-phi1) + phi2), $MachinePrecision] * R), $MachinePrecision]]]]
                    
                    \begin{array}{l}
                    [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                    \\
                    \begin{array}{l}
                    \mathbf{if}\;\lambda_1 \leq -5.3 \cdot 10^{+225}:\\
                    \;\;\;\;\left(-\cos \left(\phi_2 \cdot 0.5\right) \cdot \lambda_1\right) \cdot R\\
                    
                    \mathbf{elif}\;\lambda_1 \leq -1.4 \cdot 10^{+129}:\\
                    \;\;\;\;\left(-\phi_1\right) \cdot \left(\left(-\frac{\phi_2 \cdot R}{\phi_1}\right) + R\right)\\
                    
                    \mathbf{elif}\;\lambda_1 \leq -4.8 \cdot 10^{+97}:\\
                    \;\;\;\;\left(-\cos \left(\phi_1 \cdot 0.5\right) \cdot \lambda_1\right) \cdot R\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;\left(\left(-\phi_1\right) + \phi_2\right) \cdot R\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 4 regimes
                    2. if lambda1 < -5.3000000000000002e225

                      1. Initial program 45.5%

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

                          \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                        2. lift-sqrt.f64N/A

                          \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                        3. lift-+.f64N/A

                          \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                      3. Applied rewrites89.3%

                        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
                      4. Taylor expanded in lambda1 around -inf

                        \[\leadsto \color{blue}{\left(-1 \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} \cdot R \]
                      5. Step-by-step derivation
                        1. Applied rewrites49.8%

                          \[\leadsto \color{blue}{\left(-\cos \left(\left(\phi_2 + \phi_1\right) \cdot 0.5\right) \cdot \lambda_1\right)} \cdot R \]
                        2. Taylor expanded in phi1 around 0

                          \[\leadsto \left(-\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \lambda_1\right) \cdot R \]
                        3. Step-by-step derivation
                          1. Applied rewrites52.2%

                            \[\leadsto \left(-\cos \left(\phi_2 \cdot 0.5\right) \cdot \lambda_1\right) \cdot R \]

                          if -5.3000000000000002e225 < lambda1 < -1.39999999999999987e129

                          1. Initial program 45.8%

                            \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
                          2. Taylor expanded in phi1 around -inf

                            \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
                          3. Step-by-step derivation
                            1. associate-*r*N/A

                              \[\leadsto \left(-1 \cdot \phi_1\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                            2. mul-1-negN/A

                              \[\leadsto \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \left(\color{blue}{R} + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right) \]
                            3. lower-*.f64N/A

                              \[\leadsto \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                            4. lower-neg.f64N/A

                              \[\leadsto \left(-\phi_1\right) \cdot \left(\color{blue}{R} + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right) \]
                            5. +-commutativeN/A

                              \[\leadsto \left(-\phi_1\right) \cdot \left(-1 \cdot \frac{R \cdot \phi_2}{\phi_1} + \color{blue}{R}\right) \]
                            6. lower-+.f64N/A

                              \[\leadsto \left(-\phi_1\right) \cdot \left(-1 \cdot \frac{R \cdot \phi_2}{\phi_1} + \color{blue}{R}\right) \]
                            7. mul-1-negN/A

                              \[\leadsto \left(-\phi_1\right) \cdot \left(\left(\mathsf{neg}\left(\frac{R \cdot \phi_2}{\phi_1}\right)\right) + R\right) \]
                            8. lower-neg.f64N/A

                              \[\leadsto \left(-\phi_1\right) \cdot \left(\left(-\frac{R \cdot \phi_2}{\phi_1}\right) + R\right) \]
                            9. lower-/.f64N/A

                              \[\leadsto \left(-\phi_1\right) \cdot \left(\left(-\frac{R \cdot \phi_2}{\phi_1}\right) + R\right) \]
                            10. *-commutativeN/A

                              \[\leadsto \left(-\phi_1\right) \cdot \left(\left(-\frac{\phi_2 \cdot R}{\phi_1}\right) + R\right) \]
                            11. lower-*.f6424.7

                              \[\leadsto \left(-\phi_1\right) \cdot \left(\left(-\frac{\phi_2 \cdot R}{\phi_1}\right) + R\right) \]
                          4. Applied rewrites24.7%

                            \[\leadsto \color{blue}{\left(-\phi_1\right) \cdot \left(\left(-\frac{\phi_2 \cdot R}{\phi_1}\right) + R\right)} \]

                          if -1.39999999999999987e129 < lambda1 < -4.8e97

                          1. Initial program 63.5%

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

                              \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                            2. lift-sqrt.f64N/A

                              \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                            3. lift-+.f64N/A

                              \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                          3. Applied rewrites97.0%

                            \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
                          4. Taylor expanded in lambda1 around -inf

                            \[\leadsto \color{blue}{\left(-1 \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} \cdot R \]
                          5. Step-by-step derivation
                            1. Applied rewrites33.3%

                              \[\leadsto \color{blue}{\left(-\cos \left(\left(\phi_2 + \phi_1\right) \cdot 0.5\right) \cdot \lambda_1\right)} \cdot R \]
                            2. Taylor expanded in phi1 around inf

                              \[\leadsto \left(-\cos \left(\phi_1 \cdot \frac{1}{2}\right) \cdot \lambda_1\right) \cdot R \]
                            3. Step-by-step derivation
                              1. Applied rewrites33.5%

                                \[\leadsto \left(-\cos \left(\phi_1 \cdot 0.5\right) \cdot \lambda_1\right) \cdot R \]

                              if -4.8e97 < lambda1

                              1. Initial program 64.1%

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

                                  \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                2. lift-sqrt.f64N/A

                                  \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                3. lift-+.f64N/A

                                  \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                              3. Applied rewrites97.3%

                                \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
                              4. Taylor expanded in phi2 around inf

                                \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \cdot R \]
                              5. Step-by-step derivation
                                1. Applied rewrites30.4%

                                  \[\leadsto \color{blue}{\left(\left(\frac{-\phi_1}{\phi_2} + 1\right) \cdot \phi_2\right)} \cdot R \]
                                2. Taylor expanded in phi1 around 0

                                  \[\leadsto \left(\phi_2 + \color{blue}{-1 \cdot \phi_1}\right) \cdot R \]
                                3. Step-by-step derivation
                                  1. mul-1-negN/A

                                    \[\leadsto \left(\phi_2 + \left(\mathsf{neg}\left(\phi_1\right)\right)\right) \cdot R \]
                                  2. lift-neg.f64N/A

                                    \[\leadsto \left(\phi_2 + \left(-\phi_1\right)\right) \cdot R \]
                                  3. +-commutativeN/A

                                    \[\leadsto \left(\left(-\phi_1\right) + \phi_2\right) \cdot R \]
                                  4. lower-+.f6433.0

                                    \[\leadsto \left(\left(-\phi_1\right) + \phi_2\right) \cdot R \]
                                4. Applied rewrites33.0%

                                  \[\leadsto \left(\left(-\phi_1\right) + \color{blue}{\phi_2}\right) \cdot R \]
                              6. Recombined 4 regimes into one program.
                              7. Add Preprocessing

                              Alternative 10: 30.7% accurate, 4.5× speedup?

                              \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_1 - \lambda_2 \leq -2 \cdot 10^{+101}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \left(\frac{R}{\phi_2} - \frac{R}{\phi_1}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(-\phi_1\right) + \phi_2\right) \cdot R\\ \end{array} \end{array} \]
                              NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                              (FPCore (R lambda1 lambda2 phi1 phi2)
                               :precision binary64
                               (if (<= (- lambda1 lambda2) -2e+101)
                                 (* (- phi1) (* phi2 (- (/ R phi2) (/ R phi1))))
                                 (* (+ (- phi1) phi2) R)))
                              assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                              double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                              	double tmp;
                              	if ((lambda1 - lambda2) <= -2e+101) {
                              		tmp = -phi1 * (phi2 * ((R / phi2) - (R / phi1)));
                              	} else {
                              		tmp = (-phi1 + phi2) * R;
                              	}
                              	return tmp;
                              }
                              
                              NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                              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(r, lambda1, lambda2, phi1, phi2)
                              use fmin_fmax_functions
                                  real(8), intent (in) :: r
                                  real(8), intent (in) :: lambda1
                                  real(8), intent (in) :: lambda2
                                  real(8), intent (in) :: phi1
                                  real(8), intent (in) :: phi2
                                  real(8) :: tmp
                                  if ((lambda1 - lambda2) <= (-2d+101)) then
                                      tmp = -phi1 * (phi2 * ((r / phi2) - (r / phi1)))
                                  else
                                      tmp = (-phi1 + phi2) * r
                                  end if
                                  code = tmp
                              end function
                              
                              assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
                              public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                              	double tmp;
                              	if ((lambda1 - lambda2) <= -2e+101) {
                              		tmp = -phi1 * (phi2 * ((R / phi2) - (R / phi1)));
                              	} else {
                              		tmp = (-phi1 + phi2) * R;
                              	}
                              	return tmp;
                              }
                              
                              [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
                              def code(R, lambda1, lambda2, phi1, phi2):
                              	tmp = 0
                              	if (lambda1 - lambda2) <= -2e+101:
                              		tmp = -phi1 * (phi2 * ((R / phi2) - (R / phi1)))
                              	else:
                              		tmp = (-phi1 + phi2) * R
                              	return tmp
                              
                              R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                              function code(R, lambda1, lambda2, phi1, phi2)
                              	tmp = 0.0
                              	if (Float64(lambda1 - lambda2) <= -2e+101)
                              		tmp = Float64(Float64(-phi1) * Float64(phi2 * Float64(Float64(R / phi2) - Float64(R / phi1))));
                              	else
                              		tmp = Float64(Float64(Float64(-phi1) + phi2) * R);
                              	end
                              	return tmp
                              end
                              
                              R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
                              function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
                              	tmp = 0.0;
                              	if ((lambda1 - lambda2) <= -2e+101)
                              		tmp = -phi1 * (phi2 * ((R / phi2) - (R / phi1)));
                              	else
                              		tmp = (-phi1 + phi2) * R;
                              	end
                              	tmp_2 = tmp;
                              end
                              
                              NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                              code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -2e+101], N[((-phi1) * N[(phi2 * N[(N[(R / phi2), $MachinePrecision] - N[(R / phi1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-phi1) + phi2), $MachinePrecision] * R), $MachinePrecision]]
                              
                              \begin{array}{l}
                              [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                              \\
                              \begin{array}{l}
                              \mathbf{if}\;\lambda_1 - \lambda_2 \leq -2 \cdot 10^{+101}:\\
                              \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \left(\frac{R}{\phi_2} - \frac{R}{\phi_1}\right)\right)\\
                              
                              \mathbf{else}:\\
                              \;\;\;\;\left(\left(-\phi_1\right) + \phi_2\right) \cdot R\\
                              
                              
                              \end{array}
                              \end{array}
                              
                              Derivation
                              1. Split input into 2 regimes
                              2. if (-.f64 lambda1 lambda2) < -2e101

                                1. Initial program 48.6%

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

                                    \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                  2. lift-sqrt.f64N/A

                                    \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                  3. lift-+.f64N/A

                                    \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                3. Applied rewrites93.3%

                                  \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
                                4. Taylor expanded in phi1 around inf

                                  \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                5. Step-by-step derivation
                                  1. lower-*.f6485.1

                                    \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \color{blue}{\phi_1}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                6. Applied rewrites85.1%

                                  \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(0.5 \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                7. Taylor expanded in phi1 around -inf

                                  \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
                                8. Step-by-step derivation
                                  1. associate-*r*N/A

                                    \[\leadsto \left(-1 \cdot \phi_1\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                                  2. mul-1-negN/A

                                    \[\leadsto \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \left(\color{blue}{R} + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right) \]
                                  3. lift-neg.f64N/A

                                    \[\leadsto \left(-\phi_1\right) \cdot \left(\color{blue}{R} + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right) \]
                                  4. lower-*.f64N/A

                                    \[\leadsto \left(-\phi_1\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                                  5. +-commutativeN/A

                                    \[\leadsto \left(-\phi_1\right) \cdot \left(-1 \cdot \frac{R \cdot \phi_2}{\phi_1} + \color{blue}{R}\right) \]
                                  6. lower-+.f64N/A

                                    \[\leadsto \left(-\phi_1\right) \cdot \left(-1 \cdot \frac{R \cdot \phi_2}{\phi_1} + \color{blue}{R}\right) \]
                                  7. mul-1-negN/A

                                    \[\leadsto \left(-\phi_1\right) \cdot \left(\left(\mathsf{neg}\left(\frac{R \cdot \phi_2}{\phi_1}\right)\right) + R\right) \]
                                  8. lower-neg.f64N/A

                                    \[\leadsto \left(-\phi_1\right) \cdot \left(\left(-\frac{R \cdot \phi_2}{\phi_1}\right) + R\right) \]
                                  9. lower-/.f64N/A

                                    \[\leadsto \left(-\phi_1\right) \cdot \left(\left(-\frac{R \cdot \phi_2}{\phi_1}\right) + R\right) \]
                                  10. lower-*.f6421.9

                                    \[\leadsto \left(-\phi_1\right) \cdot \left(\left(-\frac{R \cdot \phi_2}{\phi_1}\right) + R\right) \]
                                9. Applied rewrites21.9%

                                  \[\leadsto \color{blue}{\left(-\phi_1\right) \cdot \left(\left(-\frac{R \cdot \phi_2}{\phi_1}\right) + R\right)} \]
                                10. Taylor expanded in phi2 around inf

                                  \[\leadsto \left(-\phi_1\right) \cdot \left(\phi_2 \cdot \color{blue}{\left(\frac{R}{\phi_2} - \frac{R}{\phi_1}\right)}\right) \]
                                11. Step-by-step derivation
                                  1. lower-*.f64N/A

                                    \[\leadsto \left(-\phi_1\right) \cdot \left(\phi_2 \cdot \left(\frac{R}{\phi_2} - \color{blue}{\frac{R}{\phi_1}}\right)\right) \]
                                  2. lower--.f64N/A

                                    \[\leadsto \left(-\phi_1\right) \cdot \left(\phi_2 \cdot \left(\frac{R}{\phi_2} - \frac{R}{\color{blue}{\phi_1}}\right)\right) \]
                                  3. lower-/.f64N/A

                                    \[\leadsto \left(-\phi_1\right) \cdot \left(\phi_2 \cdot \left(\frac{R}{\phi_2} - \frac{R}{\phi_1}\right)\right) \]
                                  4. lower-/.f6422.9

                                    \[\leadsto \left(-\phi_1\right) \cdot \left(\phi_2 \cdot \left(\frac{R}{\phi_2} - \frac{R}{\phi_1}\right)\right) \]
                                12. Applied rewrites22.9%

                                  \[\leadsto \left(-\phi_1\right) \cdot \left(\phi_2 \cdot \color{blue}{\left(\frac{R}{\phi_2} - \frac{R}{\phi_1}\right)}\right) \]

                                if -2e101 < (-.f64 lambda1 lambda2)

                                1. Initial program 72.6%

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

                                    \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                  2. lift-sqrt.f64N/A

                                    \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                  3. lift-+.f64N/A

                                    \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                3. Applied rewrites99.4%

                                  \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
                                4. Taylor expanded in phi2 around inf

                                  \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \cdot R \]
                                5. Step-by-step derivation
                                  1. Applied rewrites37.2%

                                    \[\leadsto \color{blue}{\left(\left(\frac{-\phi_1}{\phi_2} + 1\right) \cdot \phi_2\right)} \cdot R \]
                                  2. Taylor expanded in phi1 around 0

                                    \[\leadsto \left(\phi_2 + \color{blue}{-1 \cdot \phi_1}\right) \cdot R \]
                                  3. Step-by-step derivation
                                    1. mul-1-negN/A

                                      \[\leadsto \left(\phi_2 + \left(\mathsf{neg}\left(\phi_1\right)\right)\right) \cdot R \]
                                    2. lift-neg.f64N/A

                                      \[\leadsto \left(\phi_2 + \left(-\phi_1\right)\right) \cdot R \]
                                    3. +-commutativeN/A

                                      \[\leadsto \left(\left(-\phi_1\right) + \phi_2\right) \cdot R \]
                                    4. lower-+.f6440.7

                                      \[\leadsto \left(\left(-\phi_1\right) + \phi_2\right) \cdot R \]
                                  4. Applied rewrites40.7%

                                    \[\leadsto \left(\left(-\phi_1\right) + \color{blue}{\phi_2}\right) \cdot R \]
                                6. Recombined 2 regimes into one program.
                                7. Add Preprocessing

                                Alternative 11: 30.3% accurate, 5.0× speedup?

                                \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_1 - \lambda_2 \leq -5.4 \cdot 10^{+117}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(\left(-\frac{\phi_2 \cdot R}{\phi_1}\right) + R\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(-\phi_1\right) + \phi_2\right) \cdot R\\ \end{array} \end{array} \]
                                NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                (FPCore (R lambda1 lambda2 phi1 phi2)
                                 :precision binary64
                                 (if (<= (- lambda1 lambda2) -5.4e+117)
                                   (* (- phi1) (+ (- (/ (* phi2 R) phi1)) R))
                                   (* (+ (- phi1) phi2) R)))
                                assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                                double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                	double tmp;
                                	if ((lambda1 - lambda2) <= -5.4e+117) {
                                		tmp = -phi1 * (-((phi2 * R) / phi1) + R);
                                	} else {
                                		tmp = (-phi1 + phi2) * R;
                                	}
                                	return tmp;
                                }
                                
                                NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                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(r, lambda1, lambda2, phi1, phi2)
                                use fmin_fmax_functions
                                    real(8), intent (in) :: r
                                    real(8), intent (in) :: lambda1
                                    real(8), intent (in) :: lambda2
                                    real(8), intent (in) :: phi1
                                    real(8), intent (in) :: phi2
                                    real(8) :: tmp
                                    if ((lambda1 - lambda2) <= (-5.4d+117)) then
                                        tmp = -phi1 * (-((phi2 * r) / phi1) + r)
                                    else
                                        tmp = (-phi1 + phi2) * r
                                    end if
                                    code = tmp
                                end function
                                
                                assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
                                public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                	double tmp;
                                	if ((lambda1 - lambda2) <= -5.4e+117) {
                                		tmp = -phi1 * (-((phi2 * R) / phi1) + R);
                                	} else {
                                		tmp = (-phi1 + phi2) * R;
                                	}
                                	return tmp;
                                }
                                
                                [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
                                def code(R, lambda1, lambda2, phi1, phi2):
                                	tmp = 0
                                	if (lambda1 - lambda2) <= -5.4e+117:
                                		tmp = -phi1 * (-((phi2 * R) / phi1) + R)
                                	else:
                                		tmp = (-phi1 + phi2) * R
                                	return tmp
                                
                                R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                                function code(R, lambda1, lambda2, phi1, phi2)
                                	tmp = 0.0
                                	if (Float64(lambda1 - lambda2) <= -5.4e+117)
                                		tmp = Float64(Float64(-phi1) * Float64(Float64(-Float64(Float64(phi2 * R) / phi1)) + R));
                                	else
                                		tmp = Float64(Float64(Float64(-phi1) + phi2) * R);
                                	end
                                	return tmp
                                end
                                
                                R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
                                function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
                                	tmp = 0.0;
                                	if ((lambda1 - lambda2) <= -5.4e+117)
                                		tmp = -phi1 * (-((phi2 * R) / phi1) + R);
                                	else
                                		tmp = (-phi1 + phi2) * R;
                                	end
                                	tmp_2 = tmp;
                                end
                                
                                NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -5.4e+117], N[((-phi1) * N[((-N[(N[(phi2 * R), $MachinePrecision] / phi1), $MachinePrecision]) + R), $MachinePrecision]), $MachinePrecision], N[(N[((-phi1) + phi2), $MachinePrecision] * R), $MachinePrecision]]
                                
                                \begin{array}{l}
                                [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                                \\
                                \begin{array}{l}
                                \mathbf{if}\;\lambda_1 - \lambda_2 \leq -5.4 \cdot 10^{+117}:\\
                                \;\;\;\;\left(-\phi_1\right) \cdot \left(\left(-\frac{\phi_2 \cdot R}{\phi_1}\right) + R\right)\\
                                
                                \mathbf{else}:\\
                                \;\;\;\;\left(\left(-\phi_1\right) + \phi_2\right) \cdot R\\
                                
                                
                                \end{array}
                                \end{array}
                                
                                Derivation
                                1. Split input into 2 regimes
                                2. if (-.f64 lambda1 lambda2) < -5.4000000000000005e117

                                  1. Initial program 47.4%

                                    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
                                  2. Taylor expanded in phi1 around -inf

                                    \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
                                  3. Step-by-step derivation
                                    1. associate-*r*N/A

                                      \[\leadsto \left(-1 \cdot \phi_1\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                                    2. mul-1-negN/A

                                      \[\leadsto \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \left(\color{blue}{R} + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right) \]
                                    3. lower-*.f64N/A

                                      \[\leadsto \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                                    4. lower-neg.f64N/A

                                      \[\leadsto \left(-\phi_1\right) \cdot \left(\color{blue}{R} + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right) \]
                                    5. +-commutativeN/A

                                      \[\leadsto \left(-\phi_1\right) \cdot \left(-1 \cdot \frac{R \cdot \phi_2}{\phi_1} + \color{blue}{R}\right) \]
                                    6. lower-+.f64N/A

                                      \[\leadsto \left(-\phi_1\right) \cdot \left(-1 \cdot \frac{R \cdot \phi_2}{\phi_1} + \color{blue}{R}\right) \]
                                    7. mul-1-negN/A

                                      \[\leadsto \left(-\phi_1\right) \cdot \left(\left(\mathsf{neg}\left(\frac{R \cdot \phi_2}{\phi_1}\right)\right) + R\right) \]
                                    8. lower-neg.f64N/A

                                      \[\leadsto \left(-\phi_1\right) \cdot \left(\left(-\frac{R \cdot \phi_2}{\phi_1}\right) + R\right) \]
                                    9. lower-/.f64N/A

                                      \[\leadsto \left(-\phi_1\right) \cdot \left(\left(-\frac{R \cdot \phi_2}{\phi_1}\right) + R\right) \]
                                    10. *-commutativeN/A

                                      \[\leadsto \left(-\phi_1\right) \cdot \left(\left(-\frac{\phi_2 \cdot R}{\phi_1}\right) + R\right) \]
                                    11. lower-*.f6421.3

                                      \[\leadsto \left(-\phi_1\right) \cdot \left(\left(-\frac{\phi_2 \cdot R}{\phi_1}\right) + R\right) \]
                                  4. Applied rewrites21.3%

                                    \[\leadsto \color{blue}{\left(-\phi_1\right) \cdot \left(\left(-\frac{\phi_2 \cdot R}{\phi_1}\right) + R\right)} \]

                                  if -5.4000000000000005e117 < (-.f64 lambda1 lambda2)

                                  1. Initial program 72.2%

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

                                      \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                    2. lift-sqrt.f64N/A

                                      \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                    3. lift-+.f64N/A

                                      \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                  3. Applied rewrites99.3%

                                    \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
                                  4. Taylor expanded in phi2 around inf

                                    \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \cdot R \]
                                  5. Step-by-step derivation
                                    1. Applied rewrites36.8%

                                      \[\leadsto \color{blue}{\left(\left(\frac{-\phi_1}{\phi_2} + 1\right) \cdot \phi_2\right)} \cdot R \]
                                    2. Taylor expanded in phi1 around 0

                                      \[\leadsto \left(\phi_2 + \color{blue}{-1 \cdot \phi_1}\right) \cdot R \]
                                    3. Step-by-step derivation
                                      1. mul-1-negN/A

                                        \[\leadsto \left(\phi_2 + \left(\mathsf{neg}\left(\phi_1\right)\right)\right) \cdot R \]
                                      2. lift-neg.f64N/A

                                        \[\leadsto \left(\phi_2 + \left(-\phi_1\right)\right) \cdot R \]
                                      3. +-commutativeN/A

                                        \[\leadsto \left(\left(-\phi_1\right) + \phi_2\right) \cdot R \]
                                      4. lower-+.f6440.3

                                        \[\leadsto \left(\left(-\phi_1\right) + \phi_2\right) \cdot R \]
                                    4. Applied rewrites40.3%

                                      \[\leadsto \left(\left(-\phi_1\right) + \color{blue}{\phi_2}\right) \cdot R \]
                                  6. Recombined 2 regimes into one program.
                                  7. Add Preprocessing

                                  Alternative 12: 30.0% accurate, 6.0× speedup?

                                  \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;R \leq 6.6 \cdot 10^{+142}:\\ \;\;\;\;\left(\left(-\phi_1\right) + \phi_2\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(R \cdot \left(1 - \frac{\phi_2}{\phi_1}\right)\right)\\ \end{array} \end{array} \]
                                  NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                  (FPCore (R lambda1 lambda2 phi1 phi2)
                                   :precision binary64
                                   (if (<= R 6.6e+142)
                                     (* (+ (- phi1) phi2) R)
                                     (* (- phi1) (* R (- 1.0 (/ phi2 phi1))))))
                                  assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                                  double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                  	double tmp;
                                  	if (R <= 6.6e+142) {
                                  		tmp = (-phi1 + phi2) * R;
                                  	} else {
                                  		tmp = -phi1 * (R * (1.0 - (phi2 / phi1)));
                                  	}
                                  	return tmp;
                                  }
                                  
                                  NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                  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(r, lambda1, lambda2, phi1, phi2)
                                  use fmin_fmax_functions
                                      real(8), intent (in) :: r
                                      real(8), intent (in) :: lambda1
                                      real(8), intent (in) :: lambda2
                                      real(8), intent (in) :: phi1
                                      real(8), intent (in) :: phi2
                                      real(8) :: tmp
                                      if (r <= 6.6d+142) then
                                          tmp = (-phi1 + phi2) * r
                                      else
                                          tmp = -phi1 * (r * (1.0d0 - (phi2 / phi1)))
                                      end if
                                      code = tmp
                                  end function
                                  
                                  assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
                                  public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                  	double tmp;
                                  	if (R <= 6.6e+142) {
                                  		tmp = (-phi1 + phi2) * R;
                                  	} else {
                                  		tmp = -phi1 * (R * (1.0 - (phi2 / phi1)));
                                  	}
                                  	return tmp;
                                  }
                                  
                                  [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
                                  def code(R, lambda1, lambda2, phi1, phi2):
                                  	tmp = 0
                                  	if R <= 6.6e+142:
                                  		tmp = (-phi1 + phi2) * R
                                  	else:
                                  		tmp = -phi1 * (R * (1.0 - (phi2 / phi1)))
                                  	return tmp
                                  
                                  R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                                  function code(R, lambda1, lambda2, phi1, phi2)
                                  	tmp = 0.0
                                  	if (R <= 6.6e+142)
                                  		tmp = Float64(Float64(Float64(-phi1) + phi2) * R);
                                  	else
                                  		tmp = Float64(Float64(-phi1) * Float64(R * Float64(1.0 - Float64(phi2 / phi1))));
                                  	end
                                  	return tmp
                                  end
                                  
                                  R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
                                  function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
                                  	tmp = 0.0;
                                  	if (R <= 6.6e+142)
                                  		tmp = (-phi1 + phi2) * R;
                                  	else
                                  		tmp = -phi1 * (R * (1.0 - (phi2 / phi1)));
                                  	end
                                  	tmp_2 = tmp;
                                  end
                                  
                                  NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                  code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[R, 6.6e+142], N[(N[((-phi1) + phi2), $MachinePrecision] * R), $MachinePrecision], N[((-phi1) * N[(R * N[(1.0 - N[(phi2 / phi1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
                                  
                                  \begin{array}{l}
                                  [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                                  \\
                                  \begin{array}{l}
                                  \mathbf{if}\;R \leq 6.6 \cdot 10^{+142}:\\
                                  \;\;\;\;\left(\left(-\phi_1\right) + \phi_2\right) \cdot R\\
                                  
                                  \mathbf{else}:\\
                                  \;\;\;\;\left(-\phi_1\right) \cdot \left(R \cdot \left(1 - \frac{\phi_2}{\phi_1}\right)\right)\\
                                  
                                  
                                  \end{array}
                                  \end{array}
                                  
                                  Derivation
                                  1. Split input into 2 regimes
                                  2. if R < 6.6000000000000004e142

                                    1. Initial program 53.2%

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

                                        \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                      2. lift-sqrt.f64N/A

                                        \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                      3. lift-+.f64N/A

                                        \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                    3. Applied rewrites95.4%

                                      \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
                                    4. Taylor expanded in phi2 around inf

                                      \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \cdot R \]
                                    5. Step-by-step derivation
                                      1. Applied rewrites26.4%

                                        \[\leadsto \color{blue}{\left(\left(\frac{-\phi_1}{\phi_2} + 1\right) \cdot \phi_2\right)} \cdot R \]
                                      2. Taylor expanded in phi1 around 0

                                        \[\leadsto \left(\phi_2 + \color{blue}{-1 \cdot \phi_1}\right) \cdot R \]
                                      3. Step-by-step derivation
                                        1. mul-1-negN/A

                                          \[\leadsto \left(\phi_2 + \left(\mathsf{neg}\left(\phi_1\right)\right)\right) \cdot R \]
                                        2. lift-neg.f64N/A

                                          \[\leadsto \left(\phi_2 + \left(-\phi_1\right)\right) \cdot R \]
                                        3. +-commutativeN/A

                                          \[\leadsto \left(\left(-\phi_1\right) + \phi_2\right) \cdot R \]
                                        4. lower-+.f6428.9

                                          \[\leadsto \left(\left(-\phi_1\right) + \phi_2\right) \cdot R \]
                                      4. Applied rewrites28.9%

                                        \[\leadsto \left(\left(-\phi_1\right) + \color{blue}{\phi_2}\right) \cdot R \]

                                      if 6.6000000000000004e142 < R

                                      1. Initial program 98.8%

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

                                          \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                        2. lift-sqrt.f64N/A

                                          \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                        3. lift-+.f64N/A

                                          \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                      3. Applied rewrites99.7%

                                        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
                                      4. Taylor expanded in phi1 around inf

                                        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                      5. Step-by-step derivation
                                        1. lower-*.f6499.3

                                          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \color{blue}{\phi_1}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                      6. Applied rewrites99.3%

                                        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(0.5 \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                                      7. Taylor expanded in phi1 around -inf

                                        \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
                                      8. Step-by-step derivation
                                        1. associate-*r*N/A

                                          \[\leadsto \left(-1 \cdot \phi_1\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                                        2. mul-1-negN/A

                                          \[\leadsto \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \left(\color{blue}{R} + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right) \]
                                        3. lift-neg.f64N/A

                                          \[\leadsto \left(-\phi_1\right) \cdot \left(\color{blue}{R} + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right) \]
                                        4. lower-*.f64N/A

                                          \[\leadsto \left(-\phi_1\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                                        5. +-commutativeN/A

                                          \[\leadsto \left(-\phi_1\right) \cdot \left(-1 \cdot \frac{R \cdot \phi_2}{\phi_1} + \color{blue}{R}\right) \]
                                        6. lower-+.f64N/A

                                          \[\leadsto \left(-\phi_1\right) \cdot \left(-1 \cdot \frac{R \cdot \phi_2}{\phi_1} + \color{blue}{R}\right) \]
                                        7. mul-1-negN/A

                                          \[\leadsto \left(-\phi_1\right) \cdot \left(\left(\mathsf{neg}\left(\frac{R \cdot \phi_2}{\phi_1}\right)\right) + R\right) \]
                                        8. lower-neg.f64N/A

                                          \[\leadsto \left(-\phi_1\right) \cdot \left(\left(-\frac{R \cdot \phi_2}{\phi_1}\right) + R\right) \]
                                        9. lower-/.f64N/A

                                          \[\leadsto \left(-\phi_1\right) \cdot \left(\left(-\frac{R \cdot \phi_2}{\phi_1}\right) + R\right) \]
                                        10. lower-*.f6436.6

                                          \[\leadsto \left(-\phi_1\right) \cdot \left(\left(-\frac{R \cdot \phi_2}{\phi_1}\right) + R\right) \]
                                      9. Applied rewrites36.6%

                                        \[\leadsto \color{blue}{\left(-\phi_1\right) \cdot \left(\left(-\frac{R \cdot \phi_2}{\phi_1}\right) + R\right)} \]
                                      10. Taylor expanded in R around 0

                                        \[\leadsto \left(-\phi_1\right) \cdot \left(R \cdot \color{blue}{\left(1 - \frac{\phi_2}{\phi_1}\right)}\right) \]
                                      11. Step-by-step derivation
                                        1. lower-*.f64N/A

                                          \[\leadsto \left(-\phi_1\right) \cdot \left(R \cdot \left(1 - \color{blue}{\frac{\phi_2}{\phi_1}}\right)\right) \]
                                        2. lower--.f64N/A

                                          \[\leadsto \left(-\phi_1\right) \cdot \left(R \cdot \left(1 - \frac{\phi_2}{\color{blue}{\phi_1}}\right)\right) \]
                                        3. lower-/.f6437.1

                                          \[\leadsto \left(-\phi_1\right) \cdot \left(R \cdot \left(1 - \frac{\phi_2}{\phi_1}\right)\right) \]
                                      12. Applied rewrites37.1%

                                        \[\leadsto \left(-\phi_1\right) \cdot \left(R \cdot \color{blue}{\left(1 - \frac{\phi_2}{\phi_1}\right)}\right) \]
                                    6. Recombined 2 regimes into one program.
                                    7. Add Preprocessing

                                    Alternative 13: 29.7% accurate, 13.9× speedup?

                                    \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \left(\left(-\phi_1\right) + \phi_2\right) \cdot R \end{array} \]
                                    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                    (FPCore (R lambda1 lambda2 phi1 phi2)
                                     :precision binary64
                                     (* (+ (- phi1) phi2) R))
                                    assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                                    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                    	return (-phi1 + phi2) * R;
                                    }
                                    
                                    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                    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(r, lambda1, lambda2, phi1, phi2)
                                    use fmin_fmax_functions
                                        real(8), intent (in) :: r
                                        real(8), intent (in) :: lambda1
                                        real(8), intent (in) :: lambda2
                                        real(8), intent (in) :: phi1
                                        real(8), intent (in) :: phi2
                                        code = (-phi1 + phi2) * r
                                    end function
                                    
                                    assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
                                    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                    	return (-phi1 + phi2) * R;
                                    }
                                    
                                    [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
                                    def code(R, lambda1, lambda2, phi1, phi2):
                                    	return (-phi1 + phi2) * R
                                    
                                    R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                                    function code(R, lambda1, lambda2, phi1, phi2)
                                    	return Float64(Float64(Float64(-phi1) + phi2) * R)
                                    end
                                    
                                    R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
                                    function tmp = code(R, lambda1, lambda2, phi1, phi2)
                                    	tmp = (-phi1 + phi2) * R;
                                    end
                                    
                                    NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                    code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[((-phi1) + phi2), $MachinePrecision] * R), $MachinePrecision]
                                    
                                    \begin{array}{l}
                                    [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                                    \\
                                    \left(\left(-\phi_1\right) + \phi_2\right) \cdot R
                                    \end{array}
                                    
                                    Derivation
                                    1. Initial program 59.1%

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

                                        \[\leadsto \color{blue}{R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                      2. lift-sqrt.f64N/A

                                        \[\leadsto R \cdot \color{blue}{\sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                      3. lift-+.f64N/A

                                        \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
                                    3. Applied rewrites96.0%

                                      \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
                                    4. Taylor expanded in phi2 around inf

                                      \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \cdot R \]
                                    5. Step-by-step derivation
                                      1. Applied rewrites27.5%

                                        \[\leadsto \color{blue}{\left(\left(\frac{-\phi_1}{\phi_2} + 1\right) \cdot \phi_2\right)} \cdot R \]
                                      2. Taylor expanded in phi1 around 0

                                        \[\leadsto \left(\phi_2 + \color{blue}{-1 \cdot \phi_1}\right) \cdot R \]
                                      3. Step-by-step derivation
                                        1. mul-1-negN/A

                                          \[\leadsto \left(\phi_2 + \left(\mathsf{neg}\left(\phi_1\right)\right)\right) \cdot R \]
                                        2. lift-neg.f64N/A

                                          \[\leadsto \left(\phi_2 + \left(-\phi_1\right)\right) \cdot R \]
                                        3. +-commutativeN/A

                                          \[\leadsto \left(\left(-\phi_1\right) + \phi_2\right) \cdot R \]
                                        4. lower-+.f6429.7

                                          \[\leadsto \left(\left(-\phi_1\right) + \phi_2\right) \cdot R \]
                                      4. Applied rewrites29.7%

                                        \[\leadsto \left(\left(-\phi_1\right) + \color{blue}{\phi_2}\right) \cdot R \]
                                      5. Add Preprocessing

                                      Alternative 14: 28.3% accurate, 12.2× speedup?

                                      \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.72 \cdot 10^{+56}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \end{array} \]
                                      NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                      (FPCore (R lambda1 lambda2 phi1 phi2)
                                       :precision binary64
                                       (if (<= phi1 -1.72e+56) (* R (- phi1)) (* R phi2)))
                                      assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                                      double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                      	double tmp;
                                      	if (phi1 <= -1.72e+56) {
                                      		tmp = R * -phi1;
                                      	} else {
                                      		tmp = R * phi2;
                                      	}
                                      	return tmp;
                                      }
                                      
                                      NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                      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(r, lambda1, lambda2, phi1, phi2)
                                      use fmin_fmax_functions
                                          real(8), intent (in) :: r
                                          real(8), intent (in) :: lambda1
                                          real(8), intent (in) :: lambda2
                                          real(8), intent (in) :: phi1
                                          real(8), intent (in) :: phi2
                                          real(8) :: tmp
                                          if (phi1 <= (-1.72d+56)) then
                                              tmp = r * -phi1
                                          else
                                              tmp = r * phi2
                                          end if
                                          code = tmp
                                      end function
                                      
                                      assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
                                      public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                      	double tmp;
                                      	if (phi1 <= -1.72e+56) {
                                      		tmp = R * -phi1;
                                      	} else {
                                      		tmp = R * phi2;
                                      	}
                                      	return tmp;
                                      }
                                      
                                      [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
                                      def code(R, lambda1, lambda2, phi1, phi2):
                                      	tmp = 0
                                      	if phi1 <= -1.72e+56:
                                      		tmp = R * -phi1
                                      	else:
                                      		tmp = R * phi2
                                      	return tmp
                                      
                                      R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                                      function code(R, lambda1, lambda2, phi1, phi2)
                                      	tmp = 0.0
                                      	if (phi1 <= -1.72e+56)
                                      		tmp = Float64(R * Float64(-phi1));
                                      	else
                                      		tmp = Float64(R * phi2);
                                      	end
                                      	return tmp
                                      end
                                      
                                      R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
                                      function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
                                      	tmp = 0.0;
                                      	if (phi1 <= -1.72e+56)
                                      		tmp = R * -phi1;
                                      	else
                                      		tmp = R * phi2;
                                      	end
                                      	tmp_2 = tmp;
                                      end
                                      
                                      NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                      code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -1.72e+56], N[(R * (-phi1)), $MachinePrecision], N[(R * phi2), $MachinePrecision]]
                                      
                                      \begin{array}{l}
                                      [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                                      \\
                                      \begin{array}{l}
                                      \mathbf{if}\;\phi_1 \leq -1.72 \cdot 10^{+56}:\\
                                      \;\;\;\;R \cdot \left(-\phi_1\right)\\
                                      
                                      \mathbf{else}:\\
                                      \;\;\;\;R \cdot \phi_2\\
                                      
                                      
                                      \end{array}
                                      \end{array}
                                      
                                      Derivation
                                      1. Split input into 2 regimes
                                      2. if phi1 < -1.72e56

                                        1. Initial program 50.5%

                                          \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
                                        2. Taylor expanded in phi1 around -inf

                                          \[\leadsto R \cdot \color{blue}{\left(-1 \cdot \phi_1\right)} \]
                                        3. Step-by-step derivation
                                          1. mul-1-negN/A

                                            \[\leadsto R \cdot \left(\mathsf{neg}\left(\phi_1\right)\right) \]
                                          2. lower-neg.f6465.0

                                            \[\leadsto R \cdot \left(-\phi_1\right) \]
                                        4. Applied rewrites65.0%

                                          \[\leadsto R \cdot \color{blue}{\left(-\phi_1\right)} \]

                                        if -1.72e56 < phi1

                                        1. Initial program 61.4%

                                          \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
                                        2. Taylor expanded in phi2 around inf

                                          \[\leadsto R \cdot \color{blue}{\phi_2} \]
                                        3. Step-by-step derivation
                                          1. Applied rewrites18.8%

                                            \[\leadsto R \cdot \color{blue}{\phi_2} \]
                                        4. Recombined 2 regimes into one program.
                                        5. Add Preprocessing

                                        Alternative 15: 17.7% accurate, 27.0× speedup?

                                        \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ R \cdot \phi_2 \end{array} \]
                                        NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                        (FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R phi2))
                                        assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                                        double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                        	return R * phi2;
                                        }
                                        
                                        NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                        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(r, lambda1, lambda2, phi1, phi2)
                                        use fmin_fmax_functions
                                            real(8), intent (in) :: r
                                            real(8), intent (in) :: lambda1
                                            real(8), intent (in) :: lambda2
                                            real(8), intent (in) :: phi1
                                            real(8), intent (in) :: phi2
                                            code = r * phi2
                                        end function
                                        
                                        assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
                                        public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                        	return R * phi2;
                                        }
                                        
                                        [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
                                        def code(R, lambda1, lambda2, phi1, phi2):
                                        	return R * phi2
                                        
                                        R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                                        function code(R, lambda1, lambda2, phi1, phi2)
                                        	return Float64(R * phi2)
                                        end
                                        
                                        R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
                                        function tmp = code(R, lambda1, lambda2, phi1, phi2)
                                        	tmp = R * phi2;
                                        end
                                        
                                        NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                        code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * phi2), $MachinePrecision]
                                        
                                        \begin{array}{l}
                                        [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                                        \\
                                        R \cdot \phi_2
                                        \end{array}
                                        
                                        Derivation
                                        1. Initial program 59.1%

                                          \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
                                        2. Taylor expanded in phi2 around inf

                                          \[\leadsto R \cdot \color{blue}{\phi_2} \]
                                        3. Step-by-step derivation
                                          1. Applied rewrites17.5%

                                            \[\leadsto R \cdot \color{blue}{\phi_2} \]
                                          2. Add Preprocessing

                                          Alternative 16: 17.5% accurate, 27.0× speedup?

                                          \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ R \cdot \phi_1 \end{array} \]
                                          NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                          (FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R phi1))
                                          assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                                          double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                          	return R * phi1;
                                          }
                                          
                                          NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                          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(r, lambda1, lambda2, phi1, phi2)
                                          use fmin_fmax_functions
                                              real(8), intent (in) :: r
                                              real(8), intent (in) :: lambda1
                                              real(8), intent (in) :: lambda2
                                              real(8), intent (in) :: phi1
                                              real(8), intent (in) :: phi2
                                              code = r * phi1
                                          end function
                                          
                                          assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
                                          public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                          	return R * phi1;
                                          }
                                          
                                          [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
                                          def code(R, lambda1, lambda2, phi1, phi2):
                                          	return R * phi1
                                          
                                          R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                                          function code(R, lambda1, lambda2, phi1, phi2)
                                          	return Float64(R * phi1)
                                          end
                                          
                                          R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
                                          function tmp = code(R, lambda1, lambda2, phi1, phi2)
                                          	tmp = R * phi1;
                                          end
                                          
                                          NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                          code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * phi1), $MachinePrecision]
                                          
                                          \begin{array}{l}
                                          [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                                          \\
                                          R \cdot \phi_1
                                          \end{array}
                                          
                                          Derivation
                                          1. Initial program 59.1%

                                            \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
                                          2. Taylor expanded in phi1 around inf

                                            \[\leadsto R \cdot \color{blue}{\phi_1} \]
                                          3. Step-by-step derivation
                                            1. Applied rewrites17.7%

                                              \[\leadsto R \cdot \color{blue}{\phi_1} \]
                                            2. Add Preprocessing

                                            Reproduce

                                            ?
                                            herbie shell --seed 2025112 
                                            (FPCore (R lambda1 lambda2 phi1 phi2)
                                              :name "Equirectangular approximation to distance on a great circle"
                                              :precision binary64
                                              (* R (sqrt (+ (* (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0))) (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0)))) (* (- phi1 phi2) (- phi1 phi2))))))