Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.6% → 90.6%
Time: 9.9s
Alternatives: 13
Speedup: 2.3×

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}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 13 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.6% 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: 90.6% accurate, 1.2× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 4.4 \cdot 10^{-43}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(-0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(-0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_2\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 (<= phi2 4.4e-43)
   (* R (hypot (* (cos (* -0.5 phi1)) (- lambda1 lambda2)) phi1))
   (* R (hypot (* (cos (* -0.5 phi2)) (- lambda1 lambda2)) 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 (phi2 <= 4.4e-43) {
		tmp = R * hypot((cos((-0.5 * phi1)) * (lambda1 - lambda2)), phi1);
	} else {
		tmp = R * hypot((cos((-0.5 * phi2)) * (lambda1 - lambda2)), phi2);
	}
	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 <= 4.4e-43) {
		tmp = R * Math.hypot((Math.cos((-0.5 * phi1)) * (lambda1 - lambda2)), phi1);
	} else {
		tmp = R * Math.hypot((Math.cos((-0.5 * phi2)) * (lambda1 - lambda2)), phi2);
	}
	return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 4.4e-43:
		tmp = R * math.hypot((math.cos((-0.5 * phi1)) * (lambda1 - lambda2)), phi1)
	else:
		tmp = R * math.hypot((math.cos((-0.5 * phi2)) * (lambda1 - lambda2)), 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 (phi2 <= 4.4e-43)
		tmp = Float64(R * hypot(Float64(cos(Float64(-0.5 * phi1)) * Float64(lambda1 - lambda2)), phi1));
	else
		tmp = Float64(R * hypot(Float64(cos(Float64(-0.5 * phi2)) * Float64(lambda1 - lambda2)), 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 (phi2 <= 4.4e-43)
		tmp = R * hypot((cos((-0.5 * phi1)) * (lambda1 - lambda2)), phi1);
	else
		tmp = R * hypot((cos((-0.5 * phi2)) * (lambda1 - lambda2)), 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[phi2, 4.4e-43], N[(R * N[Sqrt[N[(N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(N[Cos[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 4.4 \cdot 10^{-43}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(-0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(-0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_2\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < 4.39999999999999994e-43

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

      \[\leadsto R \cdot \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
    4. Step-by-step derivation
      1. unpow2N/A

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

        \[\leadsto R \cdot \sqrt{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
      3. unswap-sqrN/A

        \[\leadsto R \cdot \sqrt{\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
      4. unpow2N/A

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

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\cos \left(\mathsf{neg}\left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \]
      9. distribute-lft-neg-inN/A

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

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

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

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

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

    if 4.39999999999999994e-43 < 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. Add Preprocessing
    3. Taylor expanded in phi1 around 0

      \[\leadsto R \cdot \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}}} \]
    4. Step-by-step derivation
      1. unpow2N/A

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

        \[\leadsto R \cdot \sqrt{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_2}^{2}} \]
      3. unswap-sqrN/A

        \[\leadsto R \cdot \sqrt{\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_2}^{2}} \]
      4. unpow2N/A

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

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\cos \left(\mathsf{neg}\left(\frac{1}{2} \cdot \phi_2\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_2\right) \]
      9. distribute-lft-neg-inN/A

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\cos \color{blue}{\left(\frac{-1}{2} \cdot \phi_2\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_2\right) \]
      12. lower--.f6478.5

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

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

Alternative 2: 75.1% accurate, 1.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 -3 \cdot 10^{+16}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1, \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -3.8 \cdot 10^{-268}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(-0.125 \cdot \left(\phi_1 \cdot \phi_1\right), \lambda_1 - \lambda_2, \lambda_1\right) - \lambda_2, \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1, \phi_2\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 (<= phi1 -3e+16)
   (* R (hypot (* (cos (* 0.5 phi1)) lambda1) phi1))
   (if (<= phi1 -3.8e-268)
     (*
      R
      (hypot
       (- (fma (* -0.125 (* phi1 phi1)) (- lambda1 lambda2) lambda1) lambda2)
       phi1))
     (* R (hypot (* (cos (* 0.5 phi2)) lambda1) 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 <= -3e+16) {
		tmp = R * hypot((cos((0.5 * phi1)) * lambda1), phi1);
	} else if (phi1 <= -3.8e-268) {
		tmp = R * hypot((fma((-0.125 * (phi1 * phi1)), (lambda1 - lambda2), lambda1) - lambda2), phi1);
	} else {
		tmp = R * hypot((cos((0.5 * phi2)) * lambda1), 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 <= -3e+16)
		tmp = Float64(R * hypot(Float64(cos(Float64(0.5 * phi1)) * lambda1), phi1));
	elseif (phi1 <= -3.8e-268)
		tmp = Float64(R * hypot(Float64(fma(Float64(-0.125 * Float64(phi1 * phi1)), Float64(lambda1 - lambda2), lambda1) - lambda2), phi1));
	else
		tmp = Float64(R * hypot(Float64(cos(Float64(0.5 * phi2)) * lambda1), phi2));
	end
	return 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, -3e+16], N[(R * N[Sqrt[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * lambda1), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, -3.8e-268], N[(R * N[Sqrt[N[(N[(N[(-0.125 * N[(phi1 * phi1), $MachinePrecision]), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision] + lambda1), $MachinePrecision] - lambda2), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * lambda1), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -3 \cdot 10^{+16}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1, \phi_1\right)\\

\mathbf{elif}\;\phi_1 \leq -3.8 \cdot 10^{-268}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(-0.125 \cdot \left(\phi_1 \cdot \phi_1\right), \lambda_1 - \lambda_2, \lambda_1\right) - \lambda_2, \phi_1\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1, \phi_2\right)\\


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

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

      \[\leadsto R \cdot \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
    4. Step-by-step derivation
      1. unpow2N/A

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

        \[\leadsto R \cdot \sqrt{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
      3. unswap-sqrN/A

        \[\leadsto R \cdot \sqrt{\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
      4. unpow2N/A

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

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\cos \left(\mathsf{neg}\left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \]
      9. distribute-lft-neg-inN/A

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

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

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

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

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

      \[\leadsto R \cdot \sqrt{{\lambda_1}^{2} \cdot {\cos \left(\frac{-1}{2} \cdot \phi_1\right)}^{2} + {\phi_1}^{2}} \]
    7. Step-by-step derivation
      1. Applied rewrites74.3%

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

      if -3e16 < phi1 < -3.8000000000000002e-268

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

        \[\leadsto R \cdot \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
      4. Step-by-step derivation
        1. unpow2N/A

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

          \[\leadsto R \cdot \sqrt{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
        3. unswap-sqrN/A

          \[\leadsto R \cdot \sqrt{\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
        4. unpow2N/A

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

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

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

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

          \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\cos \left(\mathsf{neg}\left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \]
        9. distribute-lft-neg-inN/A

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

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

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 + \frac{-1}{8} \cdot \left({\phi_1}^{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)\right) - \lambda_2, \phi_1\right) \]
      7. Step-by-step derivation
        1. Applied rewrites67.9%

          \[\leadsto R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(-0.125 \cdot \left(\phi_1 \cdot \phi_1\right), \lambda_1 - \lambda_2, \lambda_1\right) - \lambda_2, \phi_1\right) \]

        if -3.8000000000000002e-268 < phi1

        1. Initial program 59.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. Add Preprocessing
        3. Taylor expanded in phi1 around 0

          \[\leadsto R \cdot \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}}} \]
        4. Step-by-step derivation
          1. unpow2N/A

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

            \[\leadsto R \cdot \sqrt{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_2}^{2}} \]
          3. unswap-sqrN/A

            \[\leadsto R \cdot \sqrt{\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_2}^{2}} \]
          4. unpow2N/A

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

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

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

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

            \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\cos \left(\mathsf{neg}\left(\frac{1}{2} \cdot \phi_2\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_2\right) \]
          9. distribute-lft-neg-inN/A

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

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

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

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

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

          \[\leadsto R \cdot \sqrt{{\lambda_1}^{2} \cdot {\cos \left(\frac{-1}{2} \cdot \phi_2\right)}^{2} + {\phi_2}^{2}} \]
        7. Step-by-step derivation
          1. Applied rewrites65.5%

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

        Alternative 3: 86.2% accurate, 1.2× speedup?

        \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 6.8 \cdot 10^{+65}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(-0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1, \phi_2\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 (<= phi2 6.8e+65)
           (* R (hypot (* (cos (* -0.5 phi1)) (- lambda1 lambda2)) phi1))
           (* R (hypot (* (cos (* 0.5 phi2)) lambda1) 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 (phi2 <= 6.8e+65) {
        		tmp = R * hypot((cos((-0.5 * phi1)) * (lambda1 - lambda2)), phi1);
        	} else {
        		tmp = R * hypot((cos((0.5 * phi2)) * lambda1), phi2);
        	}
        	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 <= 6.8e+65) {
        		tmp = R * Math.hypot((Math.cos((-0.5 * phi1)) * (lambda1 - lambda2)), phi1);
        	} else {
        		tmp = R * Math.hypot((Math.cos((0.5 * phi2)) * lambda1), phi2);
        	}
        	return tmp;
        }
        
        [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
        def code(R, lambda1, lambda2, phi1, phi2):
        	tmp = 0
        	if phi2 <= 6.8e+65:
        		tmp = R * math.hypot((math.cos((-0.5 * phi1)) * (lambda1 - lambda2)), phi1)
        	else:
        		tmp = R * math.hypot((math.cos((0.5 * phi2)) * lambda1), 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 (phi2 <= 6.8e+65)
        		tmp = Float64(R * hypot(Float64(cos(Float64(-0.5 * phi1)) * Float64(lambda1 - lambda2)), phi1));
        	else
        		tmp = Float64(R * hypot(Float64(cos(Float64(0.5 * phi2)) * lambda1), 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 (phi2 <= 6.8e+65)
        		tmp = R * hypot((cos((-0.5 * phi1)) * (lambda1 - lambda2)), phi1);
        	else
        		tmp = R * hypot((cos((0.5 * phi2)) * lambda1), 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[phi2, 6.8e+65], N[(R * N[Sqrt[N[(N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * lambda1), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision]), $MachinePrecision]]
        
        \begin{array}{l}
        [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
        \\
        \begin{array}{l}
        \mathbf{if}\;\phi_2 \leq 6.8 \cdot 10^{+65}:\\
        \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(-0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1, \phi_2\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if phi2 < 6.7999999999999999e65

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

            \[\leadsto R \cdot \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
          4. Step-by-step derivation
            1. unpow2N/A

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

              \[\leadsto R \cdot \sqrt{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
            3. unswap-sqrN/A

              \[\leadsto R \cdot \sqrt{\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
            4. unpow2N/A

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

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

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

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

              \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\cos \left(\mathsf{neg}\left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \]
            9. distribute-lft-neg-inN/A

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

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

              \[\leadsto R \cdot \mathsf{hypot}\left(\cos \color{blue}{\left(\frac{-1}{2} \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \]
            12. lower--.f6478.5

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

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

          if 6.7999999999999999e65 < phi2

          1. Initial program 56.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. Add Preprocessing
          3. Taylor expanded in phi1 around 0

            \[\leadsto R \cdot \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}}} \]
          4. Step-by-step derivation
            1. unpow2N/A

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

              \[\leadsto R \cdot \sqrt{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_2}^{2}} \]
            3. unswap-sqrN/A

              \[\leadsto R \cdot \sqrt{\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_2}^{2}} \]
            4. unpow2N/A

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

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

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

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

              \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\cos \left(\mathsf{neg}\left(\frac{1}{2} \cdot \phi_2\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_2\right) \]
            9. distribute-lft-neg-inN/A

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

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

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

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

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

            \[\leadsto R \cdot \sqrt{{\lambda_1}^{2} \cdot {\cos \left(\frac{-1}{2} \cdot \phi_2\right)}^{2} + {\phi_2}^{2}} \]
          7. Step-by-step derivation
            1. Applied rewrites80.7%

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

          Alternative 4: 72.1% accurate, 1.3× speedup?

          \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 6.5 \cdot 10^{-232}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2, \phi_1\right)\\ \mathbf{elif}\;\phi_2 \leq 10^{+71}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(-0.125 \cdot \left(\phi_1 \cdot \phi_1\right), \lambda_1 - \lambda_2, \lambda_1\right) - \lambda_2, \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\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 (<= phi2 6.5e-232)
             (* R (hypot (* (cos (* 0.5 phi1)) lambda2) phi1))
             (if (<= phi2 1e+71)
               (*
                R
                (hypot
                 (- (fma (* -0.125 (* phi1 phi1)) (- lambda1 lambda2) lambda1) lambda2)
                 phi1))
               (* R (- 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 (phi2 <= 6.5e-232) {
          		tmp = R * hypot((cos((0.5 * phi1)) * lambda2), phi1);
          	} else if (phi2 <= 1e+71) {
          		tmp = R * hypot((fma((-0.125 * (phi1 * phi1)), (lambda1 - lambda2), lambda1) - lambda2), phi1);
          	} else {
          		tmp = R * (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 (phi2 <= 6.5e-232)
          		tmp = Float64(R * hypot(Float64(cos(Float64(0.5 * phi1)) * lambda2), phi1));
          	elseif (phi2 <= 1e+71)
          		tmp = Float64(R * hypot(Float64(fma(Float64(-0.125 * Float64(phi1 * phi1)), Float64(lambda1 - lambda2), lambda1) - lambda2), phi1));
          	else
          		tmp = Float64(R * Float64(phi2 - phi1));
          	end
          	return 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, 6.5e-232], N[(R * N[Sqrt[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * lambda2), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 1e+71], N[(R * N[Sqrt[N[(N[(N[(-0.125 * N[(phi1 * phi1), $MachinePrecision]), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision] + lambda1), $MachinePrecision] - lambda2), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]]]
          
          \begin{array}{l}
          [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
          \\
          \begin{array}{l}
          \mathbf{if}\;\phi_2 \leq 6.5 \cdot 10^{-232}:\\
          \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2, \phi_1\right)\\
          
          \mathbf{elif}\;\phi_2 \leq 10^{+71}:\\
          \;\;\;\;R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(-0.125 \cdot \left(\phi_1 \cdot \phi_1\right), \lambda_1 - \lambda_2, \lambda_1\right) - \lambda_2, \phi_1\right)\\
          
          \mathbf{else}:\\
          \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 3 regimes
          2. if phi2 < 6.50000000000000007e-232

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

              \[\leadsto R \cdot \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
            4. Step-by-step derivation
              1. unpow2N/A

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

                \[\leadsto R \cdot \sqrt{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
              3. unswap-sqrN/A

                \[\leadsto R \cdot \sqrt{\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
              4. unpow2N/A

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

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

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

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

                \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\cos \left(\mathsf{neg}\left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \]
              9. distribute-lft-neg-inN/A

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

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

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

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

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

              \[\leadsto R \cdot \sqrt{{\lambda_2}^{2} \cdot {\cos \left(\frac{-1}{2} \cdot \phi_1\right)}^{2} + {\phi_1}^{2}} \]
            7. Step-by-step derivation
              1. Applied rewrites55.5%

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

              if 6.50000000000000007e-232 < phi2 < 1e71

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

                \[\leadsto R \cdot \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
              4. Step-by-step derivation
                1. unpow2N/A

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

                  \[\leadsto R \cdot \sqrt{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
                3. unswap-sqrN/A

                  \[\leadsto R \cdot \sqrt{\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
                4. unpow2N/A

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

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

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

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

                  \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\cos \left(\mathsf{neg}\left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \]
                9. distribute-lft-neg-inN/A

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

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

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

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

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

                \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 + \frac{-1}{8} \cdot \left({\phi_1}^{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)\right) - \lambda_2, \phi_1\right) \]
              7. Step-by-step derivation
                1. Applied rewrites63.7%

                  \[\leadsto R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(-0.125 \cdot \left(\phi_1 \cdot \phi_1\right), \lambda_1 - \lambda_2, \lambda_1\right) - \lambda_2, \phi_1\right) \]

                if 1e71 < phi2

                1. Initial program 56.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. Add Preprocessing
                3. Taylor expanded in phi2 around inf

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

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

                    \[\leadsto R \cdot \color{blue}{\left(\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right) \cdot \phi_2\right)} \]
                  3. fp-cancel-sign-sub-invN/A

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

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

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

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

                    \[\leadsto R \cdot \left(\left(1 - \color{blue}{\frac{\phi_1}{\phi_2}}\right) \cdot \phi_2\right) \]
                5. Applied rewrites87.7%

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

                  \[\leadsto R \cdot \left(\left(\phi_1 \cdot \left(\frac{1}{\phi_1} - \frac{1}{\phi_2}\right)\right) \cdot \phi_2\right) \]
                7. Step-by-step derivation
                  1. Applied rewrites87.6%

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

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

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

                  Alternative 5: 71.8% accurate, 1.3× 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.75 \cdot 10^{-212}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1, \phi_1\right)\\ \mathbf{elif}\;\phi_2 \leq 10^{+71}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(-0.125 \cdot \left(\phi_1 \cdot \phi_1\right), \lambda_1 - \lambda_2, \lambda_1\right) - \lambda_2, \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\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 (<= phi2 -1.75e-212)
                     (* R (hypot (* (cos (* 0.5 phi1)) lambda1) phi1))
                     (if (<= phi2 1e+71)
                       (*
                        R
                        (hypot
                         (- (fma (* -0.125 (* phi1 phi1)) (- lambda1 lambda2) lambda1) lambda2)
                         phi1))
                       (* R (- 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 (phi2 <= -1.75e-212) {
                  		tmp = R * hypot((cos((0.5 * phi1)) * lambda1), phi1);
                  	} else if (phi2 <= 1e+71) {
                  		tmp = R * hypot((fma((-0.125 * (phi1 * phi1)), (lambda1 - lambda2), lambda1) - lambda2), phi1);
                  	} else {
                  		tmp = R * (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 (phi2 <= -1.75e-212)
                  		tmp = Float64(R * hypot(Float64(cos(Float64(0.5 * phi1)) * lambda1), phi1));
                  	elseif (phi2 <= 1e+71)
                  		tmp = Float64(R * hypot(Float64(fma(Float64(-0.125 * Float64(phi1 * phi1)), Float64(lambda1 - lambda2), lambda1) - lambda2), phi1));
                  	else
                  		tmp = Float64(R * Float64(phi2 - phi1));
                  	end
                  	return 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.75e-212], N[(R * N[Sqrt[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * lambda1), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 1e+71], N[(R * N[Sqrt[N[(N[(N[(-0.125 * N[(phi1 * phi1), $MachinePrecision]), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision] + lambda1), $MachinePrecision] - lambda2), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[(phi2 - phi1), $MachinePrecision]), $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.75 \cdot 10^{-212}:\\
                  \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1, \phi_1\right)\\
                  
                  \mathbf{elif}\;\phi_2 \leq 10^{+71}:\\
                  \;\;\;\;R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(-0.125 \cdot \left(\phi_1 \cdot \phi_1\right), \lambda_1 - \lambda_2, \lambda_1\right) - \lambda_2, \phi_1\right)\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 3 regimes
                  2. if phi2 < -1.7499999999999999e-212

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

                      \[\leadsto R \cdot \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
                    4. Step-by-step derivation
                      1. unpow2N/A

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

                        \[\leadsto R \cdot \sqrt{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
                      3. unswap-sqrN/A

                        \[\leadsto R \cdot \sqrt{\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
                      4. unpow2N/A

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

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

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

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

                        \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\cos \left(\mathsf{neg}\left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \]
                      9. distribute-lft-neg-inN/A

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

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

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

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

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

                      \[\leadsto R \cdot \sqrt{{\lambda_1}^{2} \cdot {\cos \left(\frac{-1}{2} \cdot \phi_1\right)}^{2} + {\phi_1}^{2}} \]
                    7. Step-by-step derivation
                      1. Applied rewrites45.8%

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

                      if -1.7499999999999999e-212 < phi2 < 1e71

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

                        \[\leadsto R \cdot \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
                      4. Step-by-step derivation
                        1. unpow2N/A

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

                          \[\leadsto R \cdot \sqrt{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
                        3. unswap-sqrN/A

                          \[\leadsto R \cdot \sqrt{\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
                        4. unpow2N/A

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

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

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

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

                          \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\cos \left(\mathsf{neg}\left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \]
                        9. distribute-lft-neg-inN/A

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

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

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

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

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

                        \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 + \frac{-1}{8} \cdot \left({\phi_1}^{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)\right) - \lambda_2, \phi_1\right) \]
                      7. Step-by-step derivation
                        1. Applied rewrites68.3%

                          \[\leadsto R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(-0.125 \cdot \left(\phi_1 \cdot \phi_1\right), \lambda_1 - \lambda_2, \lambda_1\right) - \lambda_2, \phi_1\right) \]

                        if 1e71 < phi2

                        1. Initial program 56.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. Add Preprocessing
                        3. Taylor expanded in phi2 around inf

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

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

                            \[\leadsto R \cdot \color{blue}{\left(\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right) \cdot \phi_2\right)} \]
                          3. fp-cancel-sign-sub-invN/A

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

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

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

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

                            \[\leadsto R \cdot \left(\left(1 - \color{blue}{\frac{\phi_1}{\phi_2}}\right) \cdot \phi_2\right) \]
                        5. Applied rewrites87.7%

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

                          \[\leadsto R \cdot \left(\left(\phi_1 \cdot \left(\frac{1}{\phi_1} - \frac{1}{\phi_2}\right)\right) \cdot \phi_2\right) \]
                        7. Step-by-step derivation
                          1. Applied rewrites87.6%

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

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

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

                          Alternative 6: 69.1% accurate, 2.0× speedup?

                          \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq -4.4 \cdot 10^{-212} \lor \neg \left(\phi_2 \leq 10^{+71}\right):\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(-0.125 \cdot \left(\phi_1 \cdot \phi_1\right), \lambda_1 - \lambda_2, \lambda_1\right) - \lambda_2, \phi_1\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 (or (<= phi2 -4.4e-212) (not (<= phi2 1e+71)))
                             (* R (- phi2 phi1))
                             (*
                              R
                              (hypot
                               (- (fma (* -0.125 (* phi1 phi1)) (- lambda1 lambda2) lambda1) lambda2)
                               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 ((phi2 <= -4.4e-212) || !(phi2 <= 1e+71)) {
                          		tmp = R * (phi2 - phi1);
                          	} else {
                          		tmp = R * hypot((fma((-0.125 * (phi1 * phi1)), (lambda1 - lambda2), lambda1) - lambda2), 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 ((phi2 <= -4.4e-212) || !(phi2 <= 1e+71))
                          		tmp = Float64(R * Float64(phi2 - phi1));
                          	else
                          		tmp = Float64(R * hypot(Float64(fma(Float64(-0.125 * Float64(phi1 * phi1)), Float64(lambda1 - lambda2), lambda1) - lambda2), phi1));
                          	end
                          	return 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[Or[LessEqual[phi2, -4.4e-212], N[Not[LessEqual[phi2, 1e+71]], $MachinePrecision]], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(N[(N[(-0.125 * N[(phi1 * phi1), $MachinePrecision]), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision] + lambda1), $MachinePrecision] - lambda2), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision]), $MachinePrecision]]
                          
                          \begin{array}{l}
                          [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                          \\
                          \begin{array}{l}
                          \mathbf{if}\;\phi_2 \leq -4.4 \cdot 10^{-212} \lor \neg \left(\phi_2 \leq 10^{+71}\right):\\
                          \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
                          
                          \mathbf{else}:\\
                          \;\;\;\;R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(-0.125 \cdot \left(\phi_1 \cdot \phi_1\right), \lambda_1 - \lambda_2, \lambda_1\right) - \lambda_2, \phi_1\right)\\
                          
                          
                          \end{array}
                          \end{array}
                          
                          Derivation
                          1. Split input into 2 regimes
                          2. if phi2 < -4.40000000000000006e-212 or 1e71 < phi2

                            1. Initial program 55.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. Add Preprocessing
                            3. Taylor expanded in phi2 around inf

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

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

                                \[\leadsto R \cdot \color{blue}{\left(\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right) \cdot \phi_2\right)} \]
                              3. fp-cancel-sign-sub-invN/A

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

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

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

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

                                \[\leadsto R \cdot \left(\left(1 - \color{blue}{\frac{\phi_1}{\phi_2}}\right) \cdot \phi_2\right) \]
                            5. Applied rewrites34.2%

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

                              \[\leadsto R \cdot \left(\left(\phi_1 \cdot \left(\frac{1}{\phi_1} - \frac{1}{\phi_2}\right)\right) \cdot \phi_2\right) \]
                            7. Step-by-step derivation
                              1. Applied rewrites34.2%

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

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

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

                                if -4.40000000000000006e-212 < phi2 < 1e71

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

                                  \[\leadsto R \cdot \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
                                4. Step-by-step derivation
                                  1. unpow2N/A

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

                                    \[\leadsto R \cdot \sqrt{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
                                  3. unswap-sqrN/A

                                    \[\leadsto R \cdot \sqrt{\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
                                  4. unpow2N/A

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

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

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

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

                                    \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\cos \left(\mathsf{neg}\left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \]
                                  9. distribute-lft-neg-inN/A

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

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

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

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

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

                                  \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 + \frac{-1}{8} \cdot \left({\phi_1}^{2} \cdot \left(\lambda_1 - \lambda_2\right)\right)\right) - \lambda_2, \phi_1\right) \]
                                7. Step-by-step derivation
                                  1. Applied rewrites68.3%

                                    \[\leadsto R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(-0.125 \cdot \left(\phi_1 \cdot \phi_1\right), \lambda_1 - \lambda_2, \lambda_1\right) - \lambda_2, \phi_1\right) \]
                                8. Recombined 2 regimes into one program.
                                9. Final simplification49.8%

                                  \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -4.4 \cdot 10^{-212} \lor \neg \left(\phi_2 \leq 10^{+71}\right):\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(-0.125 \cdot \left(\phi_1 \cdot \phi_1\right), \lambda_1 - \lambda_2, \lambda_1\right) - \lambda_2, \phi_1\right)\\ \end{array} \]
                                10. Add Preprocessing

                                Alternative 7: 54.7% accurate, 2.2× 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}\;\lambda_1 \leq -1.12 \cdot 10^{+197}:\\ \;\;\;\;R \cdot \left(\left(-\lambda_1\right) \cdot t\_0\right)\\ \mathbf{elif}\;\lambda_1 \leq 1.55 \cdot 10^{+77}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(t\_0 \cdot \lambda_2\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
                                 (let* ((t_0 (cos (* 0.5 phi1))))
                                   (if (<= lambda1 -1.12e+197)
                                     (* R (* (- lambda1) t_0))
                                     (if (<= lambda1 1.55e+77) (* R (- phi2 phi1)) (* R (* t_0 lambda2))))))
                                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 (lambda1 <= -1.12e+197) {
                                		tmp = R * (-lambda1 * t_0);
                                	} else if (lambda1 <= 1.55e+77) {
                                		tmp = R * (phi2 - phi1);
                                	} else {
                                		tmp = R * (t_0 * lambda2);
                                	}
                                	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) :: t_0
                                    real(8) :: tmp
                                    t_0 = cos((0.5d0 * phi1))
                                    if (lambda1 <= (-1.12d+197)) then
                                        tmp = r * (-lambda1 * t_0)
                                    else if (lambda1 <= 1.55d+77) then
                                        tmp = r * (phi2 - phi1)
                                    else
                                        tmp = r * (t_0 * lambda2)
                                    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 t_0 = Math.cos((0.5 * phi1));
                                	double tmp;
                                	if (lambda1 <= -1.12e+197) {
                                		tmp = R * (-lambda1 * t_0);
                                	} else if (lambda1 <= 1.55e+77) {
                                		tmp = R * (phi2 - phi1);
                                	} else {
                                		tmp = R * (t_0 * lambda2);
                                	}
                                	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 lambda1 <= -1.12e+197:
                                		tmp = R * (-lambda1 * t_0)
                                	elif lambda1 <= 1.55e+77:
                                		tmp = R * (phi2 - phi1)
                                	else:
                                		tmp = R * (t_0 * lambda2)
                                	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 (lambda1 <= -1.12e+197)
                                		tmp = Float64(R * Float64(Float64(-lambda1) * t_0));
                                	elseif (lambda1 <= 1.55e+77)
                                		tmp = Float64(R * Float64(phi2 - phi1));
                                	else
                                		tmp = Float64(R * Float64(t_0 * lambda2));
                                	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 (lambda1 <= -1.12e+197)
                                		tmp = R * (-lambda1 * t_0);
                                	elseif (lambda1 <= 1.55e+77)
                                		tmp = R * (phi2 - phi1);
                                	else
                                		tmp = R * (t_0 * lambda2);
                                	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[lambda1, -1.12e+197], N[(R * N[((-lambda1) * t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda1, 1.55e+77], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], N[(R * N[(t$95$0 * lambda2), $MachinePrecision]), $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}\;\lambda_1 \leq -1.12 \cdot 10^{+197}:\\
                                \;\;\;\;R \cdot \left(\left(-\lambda_1\right) \cdot t\_0\right)\\
                                
                                \mathbf{elif}\;\lambda_1 \leq 1.55 \cdot 10^{+77}:\\
                                \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
                                
                                \mathbf{else}:\\
                                \;\;\;\;R \cdot \left(t\_0 \cdot \lambda_2\right)\\
                                
                                
                                \end{array}
                                \end{array}
                                
                                Derivation
                                1. Split input into 3 regimes
                                2. if lambda1 < -1.1200000000000001e197

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

                                    \[\leadsto R \cdot \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
                                  4. Step-by-step derivation
                                    1. unpow2N/A

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

                                      \[\leadsto R \cdot \sqrt{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
                                    3. unswap-sqrN/A

                                      \[\leadsto R \cdot \sqrt{\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_1}^{2}} \]
                                    4. unpow2N/A

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

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

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

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

                                      \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\cos \left(\mathsf{neg}\left(\frac{1}{2} \cdot \phi_1\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \]
                                    9. distribute-lft-neg-inN/A

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

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

                                      \[\leadsto R \cdot \mathsf{hypot}\left(\cos \color{blue}{\left(\frac{-1}{2} \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \]
                                    12. lower--.f6490.4

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

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

                                    \[\leadsto R \cdot \left(-1 \cdot \color{blue}{\left(\lambda_1 \cdot \cos \left(\frac{-1}{2} \cdot \phi_1\right)\right)}\right) \]
                                  7. Step-by-step derivation
                                    1. Applied rewrites72.0%

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

                                    if -1.1200000000000001e197 < lambda1 < 1.54999999999999999e77

                                    1. Initial program 62.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. Add Preprocessing
                                    3. Taylor expanded in phi2 around inf

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

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

                                        \[\leadsto R \cdot \color{blue}{\left(\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right) \cdot \phi_2\right)} \]
                                      3. fp-cancel-sign-sub-invN/A

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

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

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

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

                                        \[\leadsto R \cdot \left(\left(1 - \color{blue}{\frac{\phi_1}{\phi_2}}\right) \cdot \phi_2\right) \]
                                    5. Applied rewrites35.3%

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

                                      \[\leadsto R \cdot \left(\left(\phi_1 \cdot \left(\frac{1}{\phi_1} - \frac{1}{\phi_2}\right)\right) \cdot \phi_2\right) \]
                                    7. Step-by-step derivation
                                      1. Applied rewrites35.3%

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

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

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

                                        if 1.54999999999999999e77 < lambda1

                                        1. Initial program 50.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. Add Preprocessing
                                        3. Taylor expanded in lambda2 around inf

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

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

                                            \[\leadsto R \cdot \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \lambda_2\right)} \]
                                          3. cos-neg-revN/A

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

                                            \[\leadsto R \cdot \left(\color{blue}{\cos \left(\mathsf{neg}\left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \cdot \lambda_2\right) \]
                                          5. distribute-lft-neg-inN/A

                                            \[\leadsto R \cdot \left(\cos \color{blue}{\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \left(\phi_1 + \phi_2\right)\right)} \cdot \lambda_2\right) \]
                                          6. metadata-evalN/A

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

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

                                            \[\leadsto R \cdot \left(\cos \left(\frac{-1}{2} \cdot \color{blue}{\left(\phi_2 + \phi_1\right)}\right) \cdot \lambda_2\right) \]
                                          9. lower-+.f6412.0

                                            \[\leadsto R \cdot \left(\cos \left(-0.5 \cdot \color{blue}{\left(\phi_2 + \phi_1\right)}\right) \cdot \lambda_2\right) \]
                                        5. Applied rewrites12.0%

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

                                          \[\leadsto R \cdot \left(\cos \left(\frac{-1}{2} \cdot \phi_1\right) \cdot \lambda_2\right) \]
                                        7. Step-by-step derivation
                                          1. Applied rewrites11.7%

                                            \[\leadsto R \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2\right) \]
                                        8. Recombined 3 regimes into one program.
                                        9. Add Preprocessing

                                        Alternative 8: 54.6% accurate, 2.2× speedup?

                                        \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -8 \cdot 10^{+196}:\\ \;\;\;\;\left(R \cdot \left(-\lambda_1\right)\right) \cdot \cos \left(-0.5 \cdot \phi_2\right)\\ \mathbf{elif}\;\lambda_1 \leq 1.55 \cdot 10^{+77}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2\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 (<= lambda1 -8e+196)
                                           (* (* R (- lambda1)) (cos (* -0.5 phi2)))
                                           (if (<= lambda1 1.55e+77)
                                             (* R (- phi2 phi1))
                                             (* R (* (cos (* 0.5 phi1)) lambda2)))))
                                        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 <= -8e+196) {
                                        		tmp = (R * -lambda1) * cos((-0.5 * phi2));
                                        	} else if (lambda1 <= 1.55e+77) {
                                        		tmp = R * (phi2 - phi1);
                                        	} else {
                                        		tmp = R * (cos((0.5 * phi1)) * lambda2);
                                        	}
                                        	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 <= (-8d+196)) then
                                                tmp = (r * -lambda1) * cos(((-0.5d0) * phi2))
                                            else if (lambda1 <= 1.55d+77) then
                                                tmp = r * (phi2 - phi1)
                                            else
                                                tmp = r * (cos((0.5d0 * phi1)) * lambda2)
                                            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 <= -8e+196) {
                                        		tmp = (R * -lambda1) * Math.cos((-0.5 * phi2));
                                        	} else if (lambda1 <= 1.55e+77) {
                                        		tmp = R * (phi2 - phi1);
                                        	} else {
                                        		tmp = R * (Math.cos((0.5 * phi1)) * lambda2);
                                        	}
                                        	return tmp;
                                        }
                                        
                                        [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
                                        def code(R, lambda1, lambda2, phi1, phi2):
                                        	tmp = 0
                                        	if lambda1 <= -8e+196:
                                        		tmp = (R * -lambda1) * math.cos((-0.5 * phi2))
                                        	elif lambda1 <= 1.55e+77:
                                        		tmp = R * (phi2 - phi1)
                                        	else:
                                        		tmp = R * (math.cos((0.5 * phi1)) * lambda2)
                                        	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 <= -8e+196)
                                        		tmp = Float64(Float64(R * Float64(-lambda1)) * cos(Float64(-0.5 * phi2)));
                                        	elseif (lambda1 <= 1.55e+77)
                                        		tmp = Float64(R * Float64(phi2 - phi1));
                                        	else
                                        		tmp = Float64(R * Float64(cos(Float64(0.5 * phi1)) * lambda2));
                                        	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 <= -8e+196)
                                        		tmp = (R * -lambda1) * cos((-0.5 * phi2));
                                        	elseif (lambda1 <= 1.55e+77)
                                        		tmp = R * (phi2 - phi1);
                                        	else
                                        		tmp = R * (cos((0.5 * phi1)) * lambda2);
                                        	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, -8e+196], N[(N[(R * (-lambda1)), $MachinePrecision] * N[Cos[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda1, 1.55e+77], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], N[(R * N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * lambda2), $MachinePrecision]), $MachinePrecision]]]
                                        
                                        \begin{array}{l}
                                        [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                                        \\
                                        \begin{array}{l}
                                        \mathbf{if}\;\lambda_1 \leq -8 \cdot 10^{+196}:\\
                                        \;\;\;\;\left(R \cdot \left(-\lambda_1\right)\right) \cdot \cos \left(-0.5 \cdot \phi_2\right)\\
                                        
                                        \mathbf{elif}\;\lambda_1 \leq 1.55 \cdot 10^{+77}:\\
                                        \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
                                        
                                        \mathbf{else}:\\
                                        \;\;\;\;R \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2\right)\\
                                        
                                        
                                        \end{array}
                                        \end{array}
                                        
                                        Derivation
                                        1. Split input into 3 regimes
                                        2. if lambda1 < -7.9999999999999996e196

                                          1. Initial program 47.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. Add Preprocessing
                                          3. Taylor expanded in phi1 around 0

                                            \[\leadsto R \cdot \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_2\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}}} \]
                                          4. Step-by-step derivation
                                            1. unpow2N/A

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

                                              \[\leadsto R \cdot \sqrt{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_2}^{2}} \]
                                            3. unswap-sqrN/A

                                              \[\leadsto R \cdot \sqrt{\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + {\phi_2}^{2}} \]
                                            4. unpow2N/A

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

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

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

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

                                              \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\cos \left(\mathsf{neg}\left(\frac{1}{2} \cdot \phi_2\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_2\right) \]
                                            9. distribute-lft-neg-inN/A

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

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

                                              \[\leadsto R \cdot \mathsf{hypot}\left(\cos \color{blue}{\left(\frac{-1}{2} \cdot \phi_2\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_2\right) \]
                                            12. lower--.f6486.4

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

                                            \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\cos \left(-0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_2\right)} \]
                                          6. 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)} \]
                                          7. Step-by-step derivation
                                            1. mul-1-negN/A

                                              \[\leadsto \color{blue}{\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. associate-*r*N/A

                                              \[\leadsto \mathsf{neg}\left(\color{blue}{\left(R \cdot \lambda_1\right) \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}\right) \]
                                            3. distribute-lft-neg-inN/A

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

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

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

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

                                              \[\leadsto \left(-R \cdot \lambda_1\right) \cdot \cos \left(\color{blue}{\left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)} \cdot \left(\phi_1 + \phi_2\right)\right) \]
                                            8. distribute-lft-neg-inN/A

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

                                              \[\leadsto \left(-R \cdot \lambda_1\right) \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\frac{-1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \]
                                            10. distribute-lft-neg-inN/A

                                              \[\leadsto \left(-R \cdot \lambda_1\right) \cdot \cos \color{blue}{\left(\left(\mathsf{neg}\left(\frac{-1}{2}\right)\right) \cdot \left(\phi_1 + \phi_2\right)\right)} \]
                                            11. metadata-evalN/A

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

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

                                              \[\leadsto \left(-R \cdot \lambda_1\right) \cdot \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\phi_2 + \phi_1\right)}\right) \]
                                            14. lower-+.f6463.1

                                              \[\leadsto \left(-R \cdot \lambda_1\right) \cdot \cos \left(0.5 \cdot \color{blue}{\left(\phi_2 + \phi_1\right)}\right) \]
                                          8. Applied rewrites63.1%

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

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

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

                                            if -7.9999999999999996e196 < lambda1 < 1.54999999999999999e77

                                            1. Initial program 62.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. Add Preprocessing
                                            3. Taylor expanded in phi2 around inf

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

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

                                                \[\leadsto R \cdot \color{blue}{\left(\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right) \cdot \phi_2\right)} \]
                                              3. fp-cancel-sign-sub-invN/A

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

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

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

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

                                                \[\leadsto R \cdot \left(\left(1 - \color{blue}{\frac{\phi_1}{\phi_2}}\right) \cdot \phi_2\right) \]
                                            5. Applied rewrites35.3%

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

                                              \[\leadsto R \cdot \left(\left(\phi_1 \cdot \left(\frac{1}{\phi_1} - \frac{1}{\phi_2}\right)\right) \cdot \phi_2\right) \]
                                            7. Step-by-step derivation
                                              1. Applied rewrites35.3%

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

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

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

                                                if 1.54999999999999999e77 < lambda1

                                                1. Initial program 50.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. Add Preprocessing
                                                3. Taylor expanded in lambda2 around inf

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

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

                                                    \[\leadsto R \cdot \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \lambda_2\right)} \]
                                                  3. cos-neg-revN/A

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

                                                    \[\leadsto R \cdot \left(\color{blue}{\cos \left(\mathsf{neg}\left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \cdot \lambda_2\right) \]
                                                  5. distribute-lft-neg-inN/A

                                                    \[\leadsto R \cdot \left(\cos \color{blue}{\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \left(\phi_1 + \phi_2\right)\right)} \cdot \lambda_2\right) \]
                                                  6. metadata-evalN/A

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

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

                                                    \[\leadsto R \cdot \left(\cos \left(\frac{-1}{2} \cdot \color{blue}{\left(\phi_2 + \phi_1\right)}\right) \cdot \lambda_2\right) \]
                                                  9. lower-+.f6412.0

                                                    \[\leadsto R \cdot \left(\cos \left(-0.5 \cdot \color{blue}{\left(\phi_2 + \phi_1\right)}\right) \cdot \lambda_2\right) \]
                                                5. Applied rewrites12.0%

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

                                                  \[\leadsto R \cdot \left(\cos \left(\frac{-1}{2} \cdot \phi_1\right) \cdot \lambda_2\right) \]
                                                7. Step-by-step derivation
                                                  1. Applied rewrites11.7%

                                                    \[\leadsto R \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2\right) \]
                                                8. Recombined 3 regimes into one program.
                                                9. Final simplification35.9%

                                                  \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -8 \cdot 10^{+196}:\\ \;\;\;\;\left(R \cdot \left(-\lambda_1\right)\right) \cdot \cos \left(-0.5 \cdot \phi_2\right)\\ \mathbf{elif}\;\lambda_1 \leq 1.55 \cdot 10^{+77}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2\right)\\ \end{array} \]
                                                10. Add Preprocessing

                                                Alternative 9: 59.9% accurate, 2.3× 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.5 \cdot 10^{+169}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2\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 (<= lambda2 6.5e+169)
                                                   (* R (- phi2 phi1))
                                                   (* R (* (cos (* 0.5 phi1)) lambda2))))
                                                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.5e+169) {
                                                		tmp = R * (phi2 - phi1);
                                                	} else {
                                                		tmp = R * (cos((0.5 * phi1)) * lambda2);
                                                	}
                                                	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 (lambda2 <= 6.5d+169) then
                                                        tmp = r * (phi2 - phi1)
                                                    else
                                                        tmp = r * (cos((0.5d0 * phi1)) * lambda2)
                                                    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 (lambda2 <= 6.5e+169) {
                                                		tmp = R * (phi2 - phi1);
                                                	} else {
                                                		tmp = R * (Math.cos((0.5 * phi1)) * lambda2);
                                                	}
                                                	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.5e+169:
                                                		tmp = R * (phi2 - phi1)
                                                	else:
                                                		tmp = R * (math.cos((0.5 * phi1)) * lambda2)
                                                	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.5e+169)
                                                		tmp = Float64(R * Float64(phi2 - phi1));
                                                	else
                                                		tmp = Float64(R * Float64(cos(Float64(0.5 * phi1)) * lambda2));
                                                	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.5e+169)
                                                		tmp = R * (phi2 - phi1);
                                                	else
                                                		tmp = R * (cos((0.5 * phi1)) * lambda2);
                                                	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.5e+169], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], N[(R * N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * lambda2), $MachinePrecision]), $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.5 \cdot 10^{+169}:\\
                                                \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
                                                
                                                \mathbf{else}:\\
                                                \;\;\;\;R \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2\right)\\
                                                
                                                
                                                \end{array}
                                                \end{array}
                                                
                                                Derivation
                                                1. Split input into 2 regimes
                                                2. if lambda2 < 6.4999999999999995e169

                                                  1. Initial program 61.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. Add Preprocessing
                                                  3. Taylor expanded in phi2 around inf

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

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

                                                      \[\leadsto R \cdot \color{blue}{\left(\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right) \cdot \phi_2\right)} \]
                                                    3. fp-cancel-sign-sub-invN/A

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

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

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

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

                                                      \[\leadsto R \cdot \left(\left(1 - \color{blue}{\frac{\phi_1}{\phi_2}}\right) \cdot \phi_2\right) \]
                                                  5. Applied rewrites29.3%

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

                                                    \[\leadsto R \cdot \left(\left(\phi_1 \cdot \left(\frac{1}{\phi_1} - \frac{1}{\phi_2}\right)\right) \cdot \phi_2\right) \]
                                                  7. Step-by-step derivation
                                                    1. Applied rewrites29.3%

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

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

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

                                                      if 6.4999999999999995e169 < lambda2

                                                      1. Initial program 37.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. Add Preprocessing
                                                      3. Taylor expanded in lambda2 around inf

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

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

                                                          \[\leadsto R \cdot \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \lambda_2\right)} \]
                                                        3. cos-neg-revN/A

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

                                                          \[\leadsto R \cdot \left(\color{blue}{\cos \left(\mathsf{neg}\left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \cdot \lambda_2\right) \]
                                                        5. distribute-lft-neg-inN/A

                                                          \[\leadsto R \cdot \left(\cos \color{blue}{\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \left(\phi_1 + \phi_2\right)\right)} \cdot \lambda_2\right) \]
                                                        6. metadata-evalN/A

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

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

                                                          \[\leadsto R \cdot \left(\cos \left(\frac{-1}{2} \cdot \color{blue}{\left(\phi_2 + \phi_1\right)}\right) \cdot \lambda_2\right) \]
                                                        9. lower-+.f6445.9

                                                          \[\leadsto R \cdot \left(\cos \left(-0.5 \cdot \color{blue}{\left(\phi_2 + \phi_1\right)}\right) \cdot \lambda_2\right) \]
                                                      5. Applied rewrites45.9%

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

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

                                                          \[\leadsto R \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2\right) \]
                                                      8. Recombined 2 regimes into one program.
                                                      9. Add Preprocessing

                                                      Alternative 10: 59.5% accurate, 2.3× speedup?

                                                      \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 1.16 \cdot 10^{+164}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\cos \left(-0.5 \cdot \phi_2\right) \cdot \lambda_2\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 (<= lambda2 1.16e+164)
                                                         (* R (- phi2 phi1))
                                                         (* R (* (cos (* -0.5 phi2)) lambda2))))
                                                      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 <= 1.16e+164) {
                                                      		tmp = R * (phi2 - phi1);
                                                      	} else {
                                                      		tmp = R * (cos((-0.5 * phi2)) * lambda2);
                                                      	}
                                                      	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 (lambda2 <= 1.16d+164) then
                                                              tmp = r * (phi2 - phi1)
                                                          else
                                                              tmp = r * (cos(((-0.5d0) * phi2)) * lambda2)
                                                          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 (lambda2 <= 1.16e+164) {
                                                      		tmp = R * (phi2 - phi1);
                                                      	} else {
                                                      		tmp = R * (Math.cos((-0.5 * phi2)) * lambda2);
                                                      	}
                                                      	return tmp;
                                                      }
                                                      
                                                      [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
                                                      def code(R, lambda1, lambda2, phi1, phi2):
                                                      	tmp = 0
                                                      	if lambda2 <= 1.16e+164:
                                                      		tmp = R * (phi2 - phi1)
                                                      	else:
                                                      		tmp = R * (math.cos((-0.5 * phi2)) * lambda2)
                                                      	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 <= 1.16e+164)
                                                      		tmp = Float64(R * Float64(phi2 - phi1));
                                                      	else
                                                      		tmp = Float64(R * Float64(cos(Float64(-0.5 * phi2)) * lambda2));
                                                      	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 <= 1.16e+164)
                                                      		tmp = R * (phi2 - phi1);
                                                      	else
                                                      		tmp = R * (cos((-0.5 * phi2)) * lambda2);
                                                      	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, 1.16e+164], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], N[(R * N[(N[Cos[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision] * lambda2), $MachinePrecision]), $MachinePrecision]]
                                                      
                                                      \begin{array}{l}
                                                      [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                                                      \\
                                                      \begin{array}{l}
                                                      \mathbf{if}\;\lambda_2 \leq 1.16 \cdot 10^{+164}:\\
                                                      \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
                                                      
                                                      \mathbf{else}:\\
                                                      \;\;\;\;R \cdot \left(\cos \left(-0.5 \cdot \phi_2\right) \cdot \lambda_2\right)\\
                                                      
                                                      
                                                      \end{array}
                                                      \end{array}
                                                      
                                                      Derivation
                                                      1. Split input into 2 regimes
                                                      2. if lambda2 < 1.15999999999999999e164

                                                        1. Initial program 61.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. Add Preprocessing
                                                        3. Taylor expanded in phi2 around inf

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

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

                                                            \[\leadsto R \cdot \color{blue}{\left(\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right) \cdot \phi_2\right)} \]
                                                          3. fp-cancel-sign-sub-invN/A

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

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

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

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

                                                            \[\leadsto R \cdot \left(\left(1 - \color{blue}{\frac{\phi_1}{\phi_2}}\right) \cdot \phi_2\right) \]
                                                        5. Applied rewrites29.0%

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

                                                          \[\leadsto R \cdot \left(\left(\phi_1 \cdot \left(\frac{1}{\phi_1} - \frac{1}{\phi_2}\right)\right) \cdot \phi_2\right) \]
                                                        7. Step-by-step derivation
                                                          1. Applied rewrites29.0%

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

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

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

                                                            if 1.15999999999999999e164 < lambda2

                                                            1. Initial program 39.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. Add Preprocessing
                                                            3. Taylor expanded in lambda2 around inf

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

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

                                                                \[\leadsto R \cdot \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \lambda_2\right)} \]
                                                              3. cos-neg-revN/A

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

                                                                \[\leadsto R \cdot \left(\color{blue}{\cos \left(\mathsf{neg}\left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \cdot \lambda_2\right) \]
                                                              5. distribute-lft-neg-inN/A

                                                                \[\leadsto R \cdot \left(\cos \color{blue}{\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \left(\phi_1 + \phi_2\right)\right)} \cdot \lambda_2\right) \]
                                                              6. metadata-evalN/A

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

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

                                                                \[\leadsto R \cdot \left(\cos \left(\frac{-1}{2} \cdot \color{blue}{\left(\phi_2 + \phi_1\right)}\right) \cdot \lambda_2\right) \]
                                                              9. lower-+.f6444.4

                                                                \[\leadsto R \cdot \left(\cos \left(-0.5 \cdot \color{blue}{\left(\phi_2 + \phi_1\right)}\right) \cdot \lambda_2\right) \]
                                                            5. Applied rewrites44.4%

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

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

                                                                \[\leadsto R \cdot \left(\cos \left(-0.5 \cdot \phi_2\right) \cdot \lambda_2\right) \]
                                                            8. Recombined 2 regimes into one program.
                                                            9. Add Preprocessing

                                                            Alternative 11: 52.9% accurate, 19.9× speedup?

                                                            \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 6.2 \cdot 10^{+37}:\\ \;\;\;\;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 (<= phi2 6.2e+37) (* 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 (phi2 <= 6.2e+37) {
                                                            		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 (phi2 <= 6.2d+37) 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 (phi2 <= 6.2e+37) {
                                                            		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 phi2 <= 6.2e+37:
                                                            		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 (phi2 <= 6.2e+37)
                                                            		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 (phi2 <= 6.2e+37)
                                                            		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[phi2, 6.2e+37], 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_2 \leq 6.2 \cdot 10^{+37}:\\
                                                            \;\;\;\;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 phi2 < 6.2000000000000004e37

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

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

                                                                  \[\leadsto R \cdot \color{blue}{\left(\mathsf{neg}\left(\phi_1\right)\right)} \]
                                                                2. lower-neg.f6421.4

                                                                  \[\leadsto R \cdot \color{blue}{\left(-\phi_1\right)} \]
                                                              5. Applied rewrites21.4%

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

                                                              if 6.2000000000000004e37 < phi2

                                                              1. Initial program 54.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. Add Preprocessing
                                                              3. Taylor expanded in phi2 around inf

                                                                \[\leadsto \color{blue}{R \cdot \phi_2} \]
                                                              4. Step-by-step derivation
                                                                1. lower-*.f6472.0

                                                                  \[\leadsto \color{blue}{R \cdot \phi_2} \]
                                                              5. Applied rewrites72.0%

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

                                                            Alternative 12: 58.2% accurate, 31.0× speedup?

                                                            \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ R \cdot \left(\phi_2 - \phi_1\right) \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 phi1)))
                                                            assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                                                            double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                                                            	return R * (phi2 - 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 * (phi2 - 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 * (phi2 - phi1);
                                                            }
                                                            
                                                            [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
                                                            def code(R, lambda1, lambda2, phi1, phi2):
                                                            	return R * (phi2 - phi1)
                                                            
                                                            R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                                                            function code(R, lambda1, lambda2, phi1, phi2)
                                                            	return Float64(R * Float64(phi2 - phi1))
                                                            end
                                                            
                                                            R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
                                                            function tmp = code(R, lambda1, lambda2, phi1, phi2)
                                                            	tmp = R * (phi2 - 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 * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]
                                                            
                                                            \begin{array}{l}
                                                            [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                                                            \\
                                                            R \cdot \left(\phi_2 - \phi_1\right)
                                                            \end{array}
                                                            
                                                            Derivation
                                                            1. Initial program 58.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. Add Preprocessing
                                                            3. Taylor expanded in phi2 around inf

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

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

                                                                \[\leadsto R \cdot \color{blue}{\left(\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right) \cdot \phi_2\right)} \]
                                                              3. fp-cancel-sign-sub-invN/A

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

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

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

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

                                                                \[\leadsto R \cdot \left(\left(1 - \color{blue}{\frac{\phi_1}{\phi_2}}\right) \cdot \phi_2\right) \]
                                                            5. Applied rewrites29.3%

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

                                                              \[\leadsto R \cdot \left(\left(\phi_1 \cdot \left(\frac{1}{\phi_1} - \frac{1}{\phi_2}\right)\right) \cdot \phi_2\right) \]
                                                            7. Step-by-step derivation
                                                              1. Applied rewrites29.2%

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

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

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

                                                                Alternative 13: 31.3% accurate, 46.5× 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 58.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. Add Preprocessing
                                                                3. Taylor expanded in phi2 around inf

                                                                  \[\leadsto \color{blue}{R \cdot \phi_2} \]
                                                                4. Step-by-step derivation
                                                                  1. lower-*.f6416.6

                                                                    \[\leadsto \color{blue}{R \cdot \phi_2} \]
                                                                5. Applied rewrites16.6%

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

                                                                Reproduce

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