Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.0% → 95.9%
Time: 6.1s
Alternatives: 16
Speedup: 2.0×

Specification

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

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

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

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

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 16 alternatives:

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

Initial Program: 59.0% 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: 95.9% accurate, 1.7× speedup?

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

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


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

    1. Initial program 54.5%

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

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

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

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

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

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

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

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

    if -4.79999999999999957e-7 < phi1

    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. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

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

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

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

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

Alternative 2: 95.8% accurate, 1.7× speedup?

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

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

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

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

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

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

Alternative 3: 90.2% accurate, 1.8× speedup?

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

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

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

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

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

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

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

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

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

Alternative 4: 87.2% accurate, 1.6× speedup?

\[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 2.5 \cdot 10^{-13}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{elif}\;\phi_2 \leq 1.55 \cdot 10^{+138}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\left(\frac{-\phi_1}{\phi_2} + 1\right) \cdot \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 2.5e-13)
   (* (hypot phi1 (* (cos (* 0.5 phi1)) (- lambda1 lambda2))) R)
   (if (<= phi2 1.55e+138)
     (* (hypot phi1 (* (cos (* 0.5 phi2)) (- lambda1 lambda2))) R)
     (* R (* (+ (/ (- phi1) phi2) 1.0) 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 <= 2.5e-13) {
		tmp = hypot(phi1, (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
	} else if (phi2 <= 1.55e+138) {
		tmp = hypot(phi1, (cos((0.5 * phi2)) * (lambda1 - lambda2))) * R;
	} else {
		tmp = R * (((-phi1 / phi2) + 1.0) * 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 <= 2.5e-13) {
		tmp = Math.hypot(phi1, (Math.cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
	} else if (phi2 <= 1.55e+138) {
		tmp = Math.hypot(phi1, (Math.cos((0.5 * phi2)) * (lambda1 - lambda2))) * R;
	} else {
		tmp = R * (((-phi1 / phi2) + 1.0) * 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 <= 2.5e-13:
		tmp = math.hypot(phi1, (math.cos((0.5 * phi1)) * (lambda1 - lambda2))) * R
	elif phi2 <= 1.55e+138:
		tmp = math.hypot(phi1, (math.cos((0.5 * phi2)) * (lambda1 - lambda2))) * R
	else:
		tmp = R * (((-phi1 / phi2) + 1.0) * 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 <= 2.5e-13)
		tmp = Float64(hypot(phi1, Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2))) * R);
	elseif (phi2 <= 1.55e+138)
		tmp = Float64(hypot(phi1, Float64(cos(Float64(0.5 * phi2)) * Float64(lambda1 - lambda2))) * R);
	else
		tmp = Float64(R * Float64(Float64(Float64(Float64(-phi1) / phi2) + 1.0) * 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 <= 2.5e-13)
		tmp = hypot(phi1, (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
	elseif (phi2 <= 1.55e+138)
		tmp = hypot(phi1, (cos((0.5 * phi2)) * (lambda1 - lambda2))) * R;
	else
		tmp = R * (((-phi1 / phi2) + 1.0) * 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, 2.5e-13], N[(N[Sqrt[phi1 ^ 2 + N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi2, 1.55e+138], N[(N[Sqrt[phi1 ^ 2 + N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(R * N[(N[(N[((-phi1) / phi2), $MachinePrecision] + 1.0), $MachinePrecision] * phi2), $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 2.5 \cdot 10^{-13}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\

\mathbf{elif}\;\phi_2 \leq 1.55 \cdot 10^{+138}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(\left(\frac{-\phi_1}{\phi_2} + 1\right) \cdot \phi_2\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < 2.49999999999999995e-13

    1. Initial program 62.9%

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

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

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

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

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

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

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

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

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

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

      if 2.49999999999999995e-13 < phi2 < 1.5499999999999999e138

      1. Initial program 67.2%

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

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

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

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

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

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

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

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

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

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

        if 1.5499999999999999e138 < phi2

        1. Initial program 44.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. 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)} \]
        3. Step-by-step derivation
          1. *-commutativeN/A

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

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

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

            \[\leadsto R \cdot \left(\left(-1 \cdot \frac{\phi_1}{\phi_2} + 1\right) \cdot \phi_2\right) \]
          5. associate-*r/N/A

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

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

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

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

          \[\leadsto R \cdot \color{blue}{\left(\left(\frac{-\phi_1}{\phi_2} + 1\right) \cdot \phi_2\right)} \]
      9. Recombined 3 regimes into one program.
      10. Add Preprocessing

      Alternative 5: 84.8% accurate, 1.7× speedup?

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

        1. Initial program 63.2%

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

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

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

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

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

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

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

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

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

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

          if 2.7e18 < phi2

          1. Initial program 53.2%

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

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

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

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

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

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

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

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

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

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

              \[\leadsto R \cdot \left(\left(-\phi_1\right) \cdot \left(\frac{\mathsf{neg}\left(\phi_2\right)}{\phi_1} + 1\right)\right) \]
            10. lower-neg.f6462.0

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

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

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

              \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \color{blue}{\phi_1}\right) \]
            2. lower-*.f6472.8

              \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \phi_1\right) \]
          7. Applied rewrites72.8%

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

        Alternative 6: 62.1% accurate, 1.9× speedup?

        \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \sqrt{0.5 + 0.5 \cdot \cos \left(\phi_1 + \phi_2\right)}\\ \mathbf{if}\;\lambda_1 \leq -1.5 \cdot 10^{+118}:\\ \;\;\;\;-1 \cdot \left(\left(R \cdot \lambda_1\right) \cdot t\_0\right)\\ \mathbf{elif}\;\lambda_1 \leq 2.6 \cdot 10^{-150}:\\ \;\;\;\;R \cdot \left(\phi_2 + -1 \cdot \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(R \cdot \lambda_2\right) \cdot t\_0\\ \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 (sqrt (+ 0.5 (* 0.5 (cos (+ phi1 phi2)))))))
           (if (<= lambda1 -1.5e+118)
             (* -1.0 (* (* R lambda1) t_0))
             (if (<= lambda1 2.6e-150)
               (* R (+ phi2 (* -1.0 phi1)))
               (* (* R lambda2) t_0)))))
        assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
        double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
        	double t_0 = sqrt((0.5 + (0.5 * cos((phi1 + phi2)))));
        	double tmp;
        	if (lambda1 <= -1.5e+118) {
        		tmp = -1.0 * ((R * lambda1) * t_0);
        	} else if (lambda1 <= 2.6e-150) {
        		tmp = R * (phi2 + (-1.0 * phi1));
        	} else {
        		tmp = (R * lambda2) * t_0;
        	}
        	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 = sqrt((0.5d0 + (0.5d0 * cos((phi1 + phi2)))))
            if (lambda1 <= (-1.5d+118)) then
                tmp = (-1.0d0) * ((r * lambda1) * t_0)
            else if (lambda1 <= 2.6d-150) then
                tmp = r * (phi2 + ((-1.0d0) * phi1))
            else
                tmp = (r * lambda2) * t_0
            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.sqrt((0.5 + (0.5 * Math.cos((phi1 + phi2)))));
        	double tmp;
        	if (lambda1 <= -1.5e+118) {
        		tmp = -1.0 * ((R * lambda1) * t_0);
        	} else if (lambda1 <= 2.6e-150) {
        		tmp = R * (phi2 + (-1.0 * phi1));
        	} else {
        		tmp = (R * lambda2) * t_0;
        	}
        	return tmp;
        }
        
        [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
        def code(R, lambda1, lambda2, phi1, phi2):
        	t_0 = math.sqrt((0.5 + (0.5 * math.cos((phi1 + phi2)))))
        	tmp = 0
        	if lambda1 <= -1.5e+118:
        		tmp = -1.0 * ((R * lambda1) * t_0)
        	elif lambda1 <= 2.6e-150:
        		tmp = R * (phi2 + (-1.0 * phi1))
        	else:
        		tmp = (R * lambda2) * t_0
        	return tmp
        
        R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
        function code(R, lambda1, lambda2, phi1, phi2)
        	t_0 = sqrt(Float64(0.5 + Float64(0.5 * cos(Float64(phi1 + phi2)))))
        	tmp = 0.0
        	if (lambda1 <= -1.5e+118)
        		tmp = Float64(-1.0 * Float64(Float64(R * lambda1) * t_0));
        	elseif (lambda1 <= 2.6e-150)
        		tmp = Float64(R * Float64(phi2 + Float64(-1.0 * phi1)));
        	else
        		tmp = Float64(Float64(R * lambda2) * t_0);
        	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 = sqrt((0.5 + (0.5 * cos((phi1 + phi2)))));
        	tmp = 0.0;
        	if (lambda1 <= -1.5e+118)
        		tmp = -1.0 * ((R * lambda1) * t_0);
        	elseif (lambda1 <= 2.6e-150)
        		tmp = R * (phi2 + (-1.0 * phi1));
        	else
        		tmp = (R * lambda2) * t_0;
        	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[Sqrt[N[(0.5 + N[(0.5 * N[Cos[N[(phi1 + phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[lambda1, -1.5e+118], N[(-1.0 * N[(N[(R * lambda1), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda1, 2.6e-150], N[(R * N[(phi2 + N[(-1.0 * phi1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(R * lambda2), $MachinePrecision] * t$95$0), $MachinePrecision]]]]
        
        \begin{array}{l}
        [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
        \\
        \begin{array}{l}
        t_0 := \sqrt{0.5 + 0.5 \cdot \cos \left(\phi_1 + \phi_2\right)}\\
        \mathbf{if}\;\lambda_1 \leq -1.5 \cdot 10^{+118}:\\
        \;\;\;\;-1 \cdot \left(\left(R \cdot \lambda_1\right) \cdot t\_0\right)\\
        
        \mathbf{elif}\;\lambda_1 \leq 2.6 \cdot 10^{-150}:\\
        \;\;\;\;R \cdot \left(\phi_2 + -1 \cdot \phi_1\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;\left(R \cdot \lambda_2\right) \cdot t\_0\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if lambda1 < -1.5e118

          1. Initial program 45.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. Applied rewrites44.5%

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

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

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

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

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

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

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

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

              \[\leadsto -1 \cdot \left(\left(R \cdot \lambda_1\right) \cdot \sqrt{\frac{1}{2} + \frac{1}{2} \cdot \cos \left(\phi_1 + \phi_2\right)}\right) \]
            8. lower-+.f6467.6

              \[\leadsto -1 \cdot \left(\left(R \cdot \lambda_1\right) \cdot \sqrt{0.5 + 0.5 \cdot \cos \left(\phi_1 + \phi_2\right)}\right) \]
          5. Applied rewrites67.6%

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

          if -1.5e118 < lambda1 < 2.5999999999999998e-150

          1. Initial program 65.4%

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

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

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

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

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

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

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

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

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

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

              \[\leadsto R \cdot \left(\left(-\phi_1\right) \cdot \left(\frac{\mathsf{neg}\left(\phi_2\right)}{\phi_1} + 1\right)\right) \]
            10. lower-neg.f6461.4

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

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

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

              \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \color{blue}{\phi_1}\right) \]
            2. lower-*.f6466.8

              \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \phi_1\right) \]
          7. Applied rewrites66.8%

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

          if 2.5999999999999998e-150 < lambda1

          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. Applied rewrites54.8%

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

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

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

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

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

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

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

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

              \[\leadsto \left(R \cdot \lambda_2\right) \cdot \sqrt{0.5 + 0.5 \cdot \cos \left(\phi_1 + \phi_2\right)} \]
          5. Applied rewrites14.9%

            \[\leadsto \color{blue}{\left(R \cdot \lambda_2\right) \cdot \sqrt{0.5 + 0.5 \cdot \cos \left(\phi_1 + \phi_2\right)}} \]
        3. Recombined 3 regimes into one program.
        4. Add Preprocessing

        Alternative 7: 61.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}\;\lambda_2 \leq 41000000000:\\ \;\;\;\;R \cdot \left(\phi_2 + -1 \cdot \phi_1\right)\\ \mathbf{elif}\;\lambda_2 \leq 6.4 \cdot 10^{+176}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(\left(-\frac{\phi_2 \cdot R}{\phi_1}\right) + R\right)\\ \mathbf{else}:\\ \;\;\;\;\left(R \cdot \lambda_2\right) \cdot \sqrt{0.5 + 0.5 \cdot \cos \phi_1}\\ \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 41000000000.0)
           (* R (+ phi2 (* -1.0 phi1)))
           (if (<= lambda2 6.4e+176)
             (* (- phi1) (+ (- (/ (* phi2 R) phi1)) R))
             (* (* R lambda2) (sqrt (+ 0.5 (* 0.5 (cos 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 (lambda2 <= 41000000000.0) {
        		tmp = R * (phi2 + (-1.0 * phi1));
        	} else if (lambda2 <= 6.4e+176) {
        		tmp = -phi1 * (-((phi2 * R) / phi1) + R);
        	} else {
        		tmp = (R * lambda2) * sqrt((0.5 + (0.5 * cos(phi1))));
        	}
        	return tmp;
        }
        
        NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
        module fmin_fmax_functions
            implicit none
            private
            public fmax
            public fmin
        
            interface fmax
                module procedure fmax88
                module procedure fmax44
                module procedure fmax84
                module procedure fmax48
            end interface
            interface fmin
                module procedure fmin88
                module procedure fmin44
                module procedure fmin84
                module procedure fmin48
            end interface
        contains
            real(8) function fmax88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(4) function fmax44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(8) function fmax84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmax48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
            end function
            real(8) function fmin88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(4) function fmin44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(8) function fmin84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmin48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
            end function
        end module
        
        real(8) function code(r, lambda1, lambda2, phi1, phi2)
        use fmin_fmax_functions
            real(8), intent (in) :: r
            real(8), intent (in) :: lambda1
            real(8), intent (in) :: lambda2
            real(8), intent (in) :: phi1
            real(8), intent (in) :: phi2
            real(8) :: tmp
            if (lambda2 <= 41000000000.0d0) then
                tmp = r * (phi2 + ((-1.0d0) * phi1))
            else if (lambda2 <= 6.4d+176) then
                tmp = -phi1 * (-((phi2 * r) / phi1) + r)
            else
                tmp = (r * lambda2) * sqrt((0.5d0 + (0.5d0 * cos(phi1))))
            end if
            code = tmp
        end function
        
        assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
        public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
        	double tmp;
        	if (lambda2 <= 41000000000.0) {
        		tmp = R * (phi2 + (-1.0 * phi1));
        	} else if (lambda2 <= 6.4e+176) {
        		tmp = -phi1 * (-((phi2 * R) / phi1) + R);
        	} else {
        		tmp = (R * lambda2) * Math.sqrt((0.5 + (0.5 * Math.cos(phi1))));
        	}
        	return tmp;
        }
        
        [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
        def code(R, lambda1, lambda2, phi1, phi2):
        	tmp = 0
        	if lambda2 <= 41000000000.0:
        		tmp = R * (phi2 + (-1.0 * phi1))
        	elif lambda2 <= 6.4e+176:
        		tmp = -phi1 * (-((phi2 * R) / phi1) + R)
        	else:
        		tmp = (R * lambda2) * math.sqrt((0.5 + (0.5 * math.cos(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 (lambda2 <= 41000000000.0)
        		tmp = Float64(R * Float64(phi2 + Float64(-1.0 * phi1)));
        	elseif (lambda2 <= 6.4e+176)
        		tmp = Float64(Float64(-phi1) * Float64(Float64(-Float64(Float64(phi2 * R) / phi1)) + R));
        	else
        		tmp = Float64(Float64(R * lambda2) * sqrt(Float64(0.5 + Float64(0.5 * cos(phi1)))));
        	end
        	return tmp
        end
        
        R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
        function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
        	tmp = 0.0;
        	if (lambda2 <= 41000000000.0)
        		tmp = R * (phi2 + (-1.0 * phi1));
        	elseif (lambda2 <= 6.4e+176)
        		tmp = -phi1 * (-((phi2 * R) / phi1) + R);
        	else
        		tmp = (R * lambda2) * sqrt((0.5 + (0.5 * cos(phi1))));
        	end
        	tmp_2 = tmp;
        end
        
        NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
        code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda2, 41000000000.0], N[(R * N[(phi2 + N[(-1.0 * phi1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda2, 6.4e+176], N[((-phi1) * N[((-N[(N[(phi2 * R), $MachinePrecision] / phi1), $MachinePrecision]) + R), $MachinePrecision]), $MachinePrecision], N[(N[(R * lambda2), $MachinePrecision] * N[Sqrt[N[(0.5 + N[(0.5 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $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 41000000000:\\
        \;\;\;\;R \cdot \left(\phi_2 + -1 \cdot \phi_1\right)\\
        
        \mathbf{elif}\;\lambda_2 \leq 6.4 \cdot 10^{+176}:\\
        \;\;\;\;\left(-\phi_1\right) \cdot \left(\left(-\frac{\phi_2 \cdot R}{\phi_1}\right) + R\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;\left(R \cdot \lambda_2\right) \cdot \sqrt{0.5 + 0.5 \cdot \cos \phi_1}\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if lambda2 < 4.1e10

          1. Initial program 60.9%

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

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

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

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

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

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

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

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

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

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

              \[\leadsto R \cdot \left(\left(-\phi_1\right) \cdot \left(\frac{\mathsf{neg}\left(\phi_2\right)}{\phi_1} + 1\right)\right) \]
            10. lower-neg.f6456.3

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

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

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

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

              \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \phi_1\right) \]
          7. Applied rewrites61.2%

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

          if 4.1e10 < lambda2 < 6.3999999999999996e176

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          if 6.3999999999999996e176 < lambda2

          1. Initial program 44.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. Applied rewrites44.2%

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

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

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

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

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

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

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

              \[\leadsto \left(R \cdot \lambda_2\right) \cdot \sqrt{\frac{1}{2} + \frac{1}{2} \cdot \cos \left(\phi_1 + \phi_2\right)} \]
            7. lower-+.f6476.8

              \[\leadsto \left(R \cdot \lambda_2\right) \cdot \sqrt{0.5 + 0.5 \cdot \cos \left(\phi_1 + \phi_2\right)} \]
          5. Applied rewrites76.8%

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

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

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

          Alternative 8: 58.5% accurate, 2.0× speedup?

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

            1. Initial program 61.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. Taylor expanded in phi1 around -inf

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

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

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

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

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

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

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

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

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

                \[\leadsto R \cdot \left(\left(-\phi_1\right) \cdot \left(\frac{\mathsf{neg}\left(\phi_2\right)}{\phi_1} + 1\right)\right) \]
              10. lower-neg.f6456.1

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

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

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

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

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

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

            if 7.6000000000000002e90 < lambda2

            1. Initial program 49.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. Applied rewrites48.2%

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

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

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

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

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

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

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

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

                \[\leadsto \left(R \cdot \lambda_2\right) \cdot \sqrt{0.5 + 0.5 \cdot \cos \left(\phi_1 + \phi_2\right)} \]
            5. Applied rewrites66.9%

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

          Alternative 9: 58.1% accurate, 4.3× speedup?

          \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_1 - \lambda_2 \leq -1 \cdot 10^{+203}:\\ \;\;\;\;\left(\phi_1 \cdot \mathsf{fma}\left(-1, \frac{R}{\phi_2}, \frac{R}{\phi_1}\right)\right) \cdot \phi_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 + -1 \cdot \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 (<= (- lambda1 lambda2) -1e+203)
             (* (* phi1 (fma -1.0 (/ R phi2) (/ R phi1))) phi2)
             (* R (+ phi2 (* -1.0 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 ((lambda1 - lambda2) <= -1e+203) {
          		tmp = (phi1 * fma(-1.0, (R / phi2), (R / phi1))) * phi2;
          	} else {
          		tmp = R * (phi2 + (-1.0 * 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 (Float64(lambda1 - lambda2) <= -1e+203)
          		tmp = Float64(Float64(phi1 * fma(-1.0, Float64(R / phi2), Float64(R / phi1))) * phi2);
          	else
          		tmp = Float64(R * Float64(phi2 + Float64(-1.0 * 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[N[(lambda1 - lambda2), $MachinePrecision], -1e+203], N[(N[(phi1 * N[(-1.0 * N[(R / phi2), $MachinePrecision] + N[(R / phi1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * phi2), $MachinePrecision], N[(R * N[(phi2 + N[(-1.0 * phi1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
          
          \begin{array}{l}
          [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
          \\
          \begin{array}{l}
          \mathbf{if}\;\lambda_1 - \lambda_2 \leq -1 \cdot 10^{+203}:\\
          \;\;\;\;\left(\phi_1 \cdot \mathsf{fma}\left(-1, \frac{R}{\phi_2}, \frac{R}{\phi_1}\right)\right) \cdot \phi_2\\
          
          \mathbf{else}:\\
          \;\;\;\;R \cdot \left(\phi_2 + -1 \cdot \phi_1\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (-.f64 lambda1 lambda2) < -9.9999999999999999e202

            1. Initial program 45.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. Taylor expanded in phi2 around inf

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

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

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

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

                \[\leadsto \left(-1 \cdot \frac{R \cdot \phi_1}{\phi_2} + R\right) \cdot \phi_2 \]
              5. associate-*r/N/A

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \left(\phi_1 \cdot \mathsf{fma}\left(-1, \frac{R}{\phi_2}, \frac{R}{\phi_1}\right)\right) \cdot \phi_2 \]
              4. lower-/.f6440.2

                \[\leadsto \left(\phi_1 \cdot \mathsf{fma}\left(-1, \frac{R}{\phi_2}, \frac{R}{\phi_1}\right)\right) \cdot \phi_2 \]
            7. Applied rewrites40.2%

              \[\leadsto \left(\phi_1 \cdot \mathsf{fma}\left(-1, \frac{R}{\phi_2}, \frac{R}{\phi_1}\right)\right) \cdot \phi_2 \]

            if -9.9999999999999999e202 < (-.f64 lambda1 lambda2)

            1. Initial program 61.6%

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

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

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

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

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

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

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

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

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

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

                \[\leadsto R \cdot \left(\left(-\phi_1\right) \cdot \left(\frac{\mathsf{neg}\left(\phi_2\right)}{\phi_1} + 1\right)\right) \]
              10. lower-neg.f6456.6

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

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

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

                \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \color{blue}{\phi_1}\right) \]
              2. lower-*.f6461.8

                \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \phi_1\right) \]
            7. Applied rewrites61.8%

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

          Alternative 10: 57.6% accurate, 5.4× speedup?

          \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.05 \cdot 10^{+61}:\\ \;\;\;\;R \cdot \left(\phi_2 + -1 \cdot \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-1 \cdot \left(R \cdot \left(\frac{\phi_1}{\phi_2} - 1\right)\right)\right) \cdot \phi_2\\ \end{array} \end{array} \]
          NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
          (FPCore (R lambda1 lambda2 phi1 phi2)
           :precision binary64
           (if (<= phi1 -1.05e+61)
             (* R (+ phi2 (* -1.0 phi1)))
             (* (* -1.0 (* R (- (/ phi1 phi2) 1.0))) phi2)))
          assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
          double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
          	double tmp;
          	if (phi1 <= -1.05e+61) {
          		tmp = R * (phi2 + (-1.0 * phi1));
          	} else {
          		tmp = (-1.0 * (R * ((phi1 / phi2) - 1.0))) * phi2;
          	}
          	return tmp;
          }
          
          NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
          module fmin_fmax_functions
              implicit none
              private
              public fmax
              public fmin
          
              interface fmax
                  module procedure fmax88
                  module procedure fmax44
                  module procedure fmax84
                  module procedure fmax48
              end interface
              interface fmin
                  module procedure fmin88
                  module procedure fmin44
                  module procedure fmin84
                  module procedure fmin48
              end interface
          contains
              real(8) function fmax88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(4) function fmax44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(8) function fmax84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmax48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
              end function
              real(8) function fmin88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(4) function fmin44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(8) function fmin84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmin48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
              end function
          end module
          
          real(8) function code(r, lambda1, lambda2, phi1, phi2)
          use fmin_fmax_functions
              real(8), intent (in) :: r
              real(8), intent (in) :: lambda1
              real(8), intent (in) :: lambda2
              real(8), intent (in) :: phi1
              real(8), intent (in) :: phi2
              real(8) :: tmp
              if (phi1 <= (-1.05d+61)) then
                  tmp = r * (phi2 + ((-1.0d0) * phi1))
              else
                  tmp = ((-1.0d0) * (r * ((phi1 / phi2) - 1.0d0))) * phi2
              end if
              code = tmp
          end function
          
          assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
          public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
          	double tmp;
          	if (phi1 <= -1.05e+61) {
          		tmp = R * (phi2 + (-1.0 * phi1));
          	} else {
          		tmp = (-1.0 * (R * ((phi1 / phi2) - 1.0))) * phi2;
          	}
          	return tmp;
          }
          
          [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
          def code(R, lambda1, lambda2, phi1, phi2):
          	tmp = 0
          	if phi1 <= -1.05e+61:
          		tmp = R * (phi2 + (-1.0 * phi1))
          	else:
          		tmp = (-1.0 * (R * ((phi1 / phi2) - 1.0))) * phi2
          	return tmp
          
          R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
          function code(R, lambda1, lambda2, phi1, phi2)
          	tmp = 0.0
          	if (phi1 <= -1.05e+61)
          		tmp = Float64(R * Float64(phi2 + Float64(-1.0 * phi1)));
          	else
          		tmp = Float64(Float64(-1.0 * Float64(R * Float64(Float64(phi1 / phi2) - 1.0))) * phi2);
          	end
          	return tmp
          end
          
          R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
          function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
          	tmp = 0.0;
          	if (phi1 <= -1.05e+61)
          		tmp = R * (phi2 + (-1.0 * phi1));
          	else
          		tmp = (-1.0 * (R * ((phi1 / phi2) - 1.0))) * phi2;
          	end
          	tmp_2 = tmp;
          end
          
          NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
          code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -1.05e+61], N[(R * N[(phi2 + N[(-1.0 * phi1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 * N[(R * N[(N[(phi1 / phi2), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * phi2), $MachinePrecision]]
          
          \begin{array}{l}
          [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
          \\
          \begin{array}{l}
          \mathbf{if}\;\phi_1 \leq -1.05 \cdot 10^{+61}:\\
          \;\;\;\;R \cdot \left(\phi_2 + -1 \cdot \phi_1\right)\\
          
          \mathbf{else}:\\
          \;\;\;\;\left(-1 \cdot \left(R \cdot \left(\frac{\phi_1}{\phi_2} - 1\right)\right)\right) \cdot \phi_2\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if phi1 < -1.0500000000000001e61

            1. Initial program 52.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. Taylor expanded in phi1 around -inf

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

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

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

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

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

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

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

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

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

                \[\leadsto R \cdot \left(\left(-\phi_1\right) \cdot \left(\frac{\mathsf{neg}\left(\phi_2\right)}{\phi_1} + 1\right)\right) \]
              10. lower-neg.f6477.6

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

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

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

                \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \color{blue}{\phi_1}\right) \]
              2. lower-*.f6477.6

                \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \phi_1\right) \]
            7. Applied rewrites77.6%

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

            if -1.0500000000000001e61 < phi1

            1. Initial program 63.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. Taylor expanded in phi2 around inf

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

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

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

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

                \[\leadsto \left(-1 \cdot \frac{R \cdot \phi_1}{\phi_2} + R\right) \cdot \phi_2 \]
              5. associate-*r/N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

          Alternative 11: 57.4% accurate, 5.0× speedup?

          \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_1 - \lambda_2 \leq -1.35 \cdot 10^{+44}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(\left(-\frac{\phi_2 \cdot R}{\phi_1}\right) + R\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 + -1 \cdot \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 (<= (- lambda1 lambda2) -1.35e+44)
             (* (- phi1) (+ (- (/ (* phi2 R) phi1)) R))
             (* R (+ phi2 (* -1.0 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 ((lambda1 - lambda2) <= -1.35e+44) {
          		tmp = -phi1 * (-((phi2 * R) / phi1) + R);
          	} else {
          		tmp = R * (phi2 + (-1.0 * phi1));
          	}
          	return tmp;
          }
          
          NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
          module fmin_fmax_functions
              implicit none
              private
              public fmax
              public fmin
          
              interface fmax
                  module procedure fmax88
                  module procedure fmax44
                  module procedure fmax84
                  module procedure fmax48
              end interface
              interface fmin
                  module procedure fmin88
                  module procedure fmin44
                  module procedure fmin84
                  module procedure fmin48
              end interface
          contains
              real(8) function fmax88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(4) function fmax44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(8) function fmax84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmax48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
              end function
              real(8) function fmin88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(4) function fmin44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(8) function fmin84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmin48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
              end function
          end module
          
          real(8) function code(r, lambda1, lambda2, phi1, phi2)
          use fmin_fmax_functions
              real(8), intent (in) :: r
              real(8), intent (in) :: lambda1
              real(8), intent (in) :: lambda2
              real(8), intent (in) :: phi1
              real(8), intent (in) :: phi2
              real(8) :: tmp
              if ((lambda1 - lambda2) <= (-1.35d+44)) then
                  tmp = -phi1 * (-((phi2 * r) / phi1) + r)
              else
                  tmp = r * (phi2 + ((-1.0d0) * phi1))
              end if
              code = tmp
          end function
          
          assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
          public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
          	double tmp;
          	if ((lambda1 - lambda2) <= -1.35e+44) {
          		tmp = -phi1 * (-((phi2 * R) / phi1) + R);
          	} else {
          		tmp = R * (phi2 + (-1.0 * phi1));
          	}
          	return tmp;
          }
          
          [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
          def code(R, lambda1, lambda2, phi1, phi2):
          	tmp = 0
          	if (lambda1 - lambda2) <= -1.35e+44:
          		tmp = -phi1 * (-((phi2 * R) / phi1) + R)
          	else:
          		tmp = R * (phi2 + (-1.0 * 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 (Float64(lambda1 - lambda2) <= -1.35e+44)
          		tmp = Float64(Float64(-phi1) * Float64(Float64(-Float64(Float64(phi2 * R) / phi1)) + R));
          	else
          		tmp = Float64(R * Float64(phi2 + Float64(-1.0 * phi1)));
          	end
          	return tmp
          end
          
          R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
          function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
          	tmp = 0.0;
          	if ((lambda1 - lambda2) <= -1.35e+44)
          		tmp = -phi1 * (-((phi2 * R) / phi1) + R);
          	else
          		tmp = R * (phi2 + (-1.0 * phi1));
          	end
          	tmp_2 = tmp;
          end
          
          NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
          code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -1.35e+44], N[((-phi1) * N[((-N[(N[(phi2 * R), $MachinePrecision] / phi1), $MachinePrecision]) + R), $MachinePrecision]), $MachinePrecision], N[(R * N[(phi2 + N[(-1.0 * phi1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
          
          \begin{array}{l}
          [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
          \\
          \begin{array}{l}
          \mathbf{if}\;\lambda_1 - \lambda_2 \leq -1.35 \cdot 10^{+44}:\\
          \;\;\;\;\left(-\phi_1\right) \cdot \left(\left(-\frac{\phi_2 \cdot R}{\phi_1}\right) + R\right)\\
          
          \mathbf{else}:\\
          \;\;\;\;R \cdot \left(\phi_2 + -1 \cdot \phi_1\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (-.f64 lambda1 lambda2) < -1.35e44

            1. Initial program 52.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. Taylor expanded in phi1 around -inf

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

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

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

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

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

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

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

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

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

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

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

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

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

            if -1.35e44 < (-.f64 lambda1 lambda2)

            1. Initial program 62.1%

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

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

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

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

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

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

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

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

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

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

                \[\leadsto R \cdot \left(\left(-\phi_1\right) \cdot \left(\frac{\mathsf{neg}\left(\phi_2\right)}{\phi_1} + 1\right)\right) \]
              10. lower-neg.f6458.3

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

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

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

                \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \color{blue}{\phi_1}\right) \]
              2. lower-*.f6463.4

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

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

          Alternative 12: 57.3% accurate, 6.0× speedup?

          \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.3 \cdot 10^{+62}:\\ \;\;\;\;R \cdot \left(\phi_2 + -1 \cdot \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{-\phi_1 \cdot R}{\phi_2} + R\right) \cdot \phi_2\\ \end{array} \end{array} \]
          NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
          (FPCore (R lambda1 lambda2 phi1 phi2)
           :precision binary64
           (if (<= phi1 -1.3e+62)
             (* R (+ phi2 (* -1.0 phi1)))
             (* (+ (/ (- (* phi1 R)) phi2) R) phi2)))
          assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
          double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
          	double tmp;
          	if (phi1 <= -1.3e+62) {
          		tmp = R * (phi2 + (-1.0 * phi1));
          	} else {
          		tmp = ((-(phi1 * R) / phi2) + R) * phi2;
          	}
          	return tmp;
          }
          
          NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
          module fmin_fmax_functions
              implicit none
              private
              public fmax
              public fmin
          
              interface fmax
                  module procedure fmax88
                  module procedure fmax44
                  module procedure fmax84
                  module procedure fmax48
              end interface
              interface fmin
                  module procedure fmin88
                  module procedure fmin44
                  module procedure fmin84
                  module procedure fmin48
              end interface
          contains
              real(8) function fmax88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(4) function fmax44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(8) function fmax84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmax48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
              end function
              real(8) function fmin88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(4) function fmin44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(8) function fmin84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmin48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
              end function
          end module
          
          real(8) function code(r, lambda1, lambda2, phi1, phi2)
          use fmin_fmax_functions
              real(8), intent (in) :: r
              real(8), intent (in) :: lambda1
              real(8), intent (in) :: lambda2
              real(8), intent (in) :: phi1
              real(8), intent (in) :: phi2
              real(8) :: tmp
              if (phi1 <= (-1.3d+62)) then
                  tmp = r * (phi2 + ((-1.0d0) * phi1))
              else
                  tmp = ((-(phi1 * r) / phi2) + r) * phi2
              end if
              code = tmp
          end function
          
          assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
          public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
          	double tmp;
          	if (phi1 <= -1.3e+62) {
          		tmp = R * (phi2 + (-1.0 * phi1));
          	} else {
          		tmp = ((-(phi1 * R) / phi2) + R) * phi2;
          	}
          	return tmp;
          }
          
          [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
          def code(R, lambda1, lambda2, phi1, phi2):
          	tmp = 0
          	if phi1 <= -1.3e+62:
          		tmp = R * (phi2 + (-1.0 * phi1))
          	else:
          		tmp = ((-(phi1 * R) / phi2) + R) * phi2
          	return tmp
          
          R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
          function code(R, lambda1, lambda2, phi1, phi2)
          	tmp = 0.0
          	if (phi1 <= -1.3e+62)
          		tmp = Float64(R * Float64(phi2 + Float64(-1.0 * phi1)));
          	else
          		tmp = Float64(Float64(Float64(Float64(-Float64(phi1 * R)) / phi2) + R) * phi2);
          	end
          	return tmp
          end
          
          R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
          function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
          	tmp = 0.0;
          	if (phi1 <= -1.3e+62)
          		tmp = R * (phi2 + (-1.0 * phi1));
          	else
          		tmp = ((-(phi1 * R) / phi2) + R) * phi2;
          	end
          	tmp_2 = tmp;
          end
          
          NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
          code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -1.3e+62], N[(R * N[(phi2 + N[(-1.0 * phi1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[((-N[(phi1 * R), $MachinePrecision]) / phi2), $MachinePrecision] + R), $MachinePrecision] * phi2), $MachinePrecision]]
          
          \begin{array}{l}
          [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
          \\
          \begin{array}{l}
          \mathbf{if}\;\phi_1 \leq -1.3 \cdot 10^{+62}:\\
          \;\;\;\;R \cdot \left(\phi_2 + -1 \cdot \phi_1\right)\\
          
          \mathbf{else}:\\
          \;\;\;\;\left(\frac{-\phi_1 \cdot R}{\phi_2} + R\right) \cdot \phi_2\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if phi1 < -1.29999999999999992e62

            1. Initial program 52.1%

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

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

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

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

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

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

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

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

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

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

                \[\leadsto R \cdot \left(\left(-\phi_1\right) \cdot \left(\frac{\mathsf{neg}\left(\phi_2\right)}{\phi_1} + 1\right)\right) \]
              10. lower-neg.f6477.6

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

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

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

                \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \color{blue}{\phi_1}\right) \]
              2. lower-*.f6477.6

                \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \phi_1\right) \]
            7. Applied rewrites77.6%

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

            if -1.29999999999999992e62 < phi1

            1. Initial program 63.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. Taylor expanded in phi2 around inf

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

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

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

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

                \[\leadsto \left(-1 \cdot \frac{R \cdot \phi_1}{\phi_2} + R\right) \cdot \phi_2 \]
              5. associate-*r/N/A

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

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

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

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

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

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

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

          Alternative 13: 51.9% accurate, 11.1× speedup?

          \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ R \cdot \left(\phi_2 + -1 \cdot \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 (* -1.0 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 + (-1.0 * 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 + ((-1.0d0) * 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 + (-1.0 * phi1));
          }
          
          [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
          def code(R, lambda1, lambda2, phi1, phi2):
          	return R * (phi2 + (-1.0 * phi1))
          
          R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
          function code(R, lambda1, lambda2, phi1, phi2)
          	return Float64(R * Float64(phi2 + Float64(-1.0 * 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 + (-1.0 * 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 + N[(-1.0 * phi1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
          
          \begin{array}{l}
          [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
          \\
          R \cdot \left(\phi_2 + -1 \cdot \phi_1\right)
          \end{array}
          
          Derivation
          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. Taylor expanded in phi1 around -inf

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

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

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

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

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

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

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

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

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

              \[\leadsto R \cdot \left(\left(-\phi_1\right) \cdot \left(\frac{\mathsf{neg}\left(\phi_2\right)}{\phi_1} + 1\right)\right) \]
            10. lower-neg.f6452.9

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

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

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

              \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \color{blue}{\phi_1}\right) \]
            2. lower-*.f6457.4

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

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

          Alternative 14: 47.8% accurate, 12.2× speedup?

          \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 10^{-32}:\\ \;\;\;\;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 1e-32) (* 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 <= 1e-32) {
          		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 <= 1d-32) 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 <= 1e-32) {
          		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 <= 1e-32:
          		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 <= 1e-32)
          		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 <= 1e-32)
          		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, 1e-32], 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 10^{-32}:\\
          \;\;\;\;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 < 1.00000000000000006e-32

            1. Initial program 62.5%

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

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

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

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

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

            if 1.00000000000000006e-32 < phi2

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

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

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

            Alternative 15: 30.9% accurate, 27.0× speedup?

            \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ R \cdot \phi_2 \end{array} \]
            NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
            (FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R phi2))
            assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
            double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
            	return R * phi2;
            }
            
            NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
            module fmin_fmax_functions
                implicit none
                private
                public fmax
                public fmin
            
                interface fmax
                    module procedure fmax88
                    module procedure fmax44
                    module procedure fmax84
                    module procedure fmax48
                end interface
                interface fmin
                    module procedure fmin88
                    module procedure fmin44
                    module procedure fmin84
                    module procedure fmin48
                end interface
            contains
                real(8) function fmax88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(4) function fmax44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(8) function fmax84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmax48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                end function
                real(8) function fmin88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(4) function fmin44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(8) function fmin84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmin48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                end function
            end module
            
            real(8) function code(r, lambda1, lambda2, phi1, phi2)
            use fmin_fmax_functions
                real(8), intent (in) :: r
                real(8), intent (in) :: lambda1
                real(8), intent (in) :: lambda2
                real(8), intent (in) :: phi1
                real(8), intent (in) :: phi2
                code = r * phi2
            end function
            
            assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
            public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
            	return R * phi2;
            }
            
            [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
            def code(R, lambda1, lambda2, phi1, phi2):
            	return R * phi2
            
            R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
            function code(R, lambda1, lambda2, phi1, phi2)
            	return Float64(R * phi2)
            end
            
            R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
            function tmp = code(R, lambda1, lambda2, phi1, phi2)
            	tmp = R * phi2;
            end
            
            NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
            code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * phi2), $MachinePrecision]
            
            \begin{array}{l}
            [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
            \\
            R \cdot \phi_2
            \end{array}
            
            Derivation
            1. Initial program 59.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. Taylor expanded in phi2 around inf

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

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

              Alternative 16: 3.3% accurate, 27.0× speedup?

              \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ R \cdot \phi_1 \end{array} \]
              NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
              (FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R phi1))
              assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
              double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
              	return R * phi1;
              }
              
              NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
              module fmin_fmax_functions
                  implicit none
                  private
                  public fmax
                  public fmin
              
                  interface fmax
                      module procedure fmax88
                      module procedure fmax44
                      module procedure fmax84
                      module procedure fmax48
                  end interface
                  interface fmin
                      module procedure fmin88
                      module procedure fmin44
                      module procedure fmin84
                      module procedure fmin48
                  end interface
              contains
                  real(8) function fmax88(x, y) result (res)
                      real(8), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                  end function
                  real(4) function fmax44(x, y) result (res)
                      real(4), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                  end function
                  real(8) function fmax84(x, y) result(res)
                      real(8), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                  end function
                  real(8) function fmax48(x, y) result(res)
                      real(4), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                  end function
                  real(8) function fmin88(x, y) result (res)
                      real(8), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                  end function
                  real(4) function fmin44(x, y) result (res)
                      real(4), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                  end function
                  real(8) function fmin84(x, y) result(res)
                      real(8), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                  end function
                  real(8) function fmin48(x, y) result(res)
                      real(4), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                  end function
              end module
              
              real(8) function code(r, lambda1, lambda2, phi1, phi2)
              use fmin_fmax_functions
                  real(8), intent (in) :: r
                  real(8), intent (in) :: lambda1
                  real(8), intent (in) :: lambda2
                  real(8), intent (in) :: phi1
                  real(8), intent (in) :: phi2
                  code = r * phi1
              end function
              
              assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
              public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
              	return R * phi1;
              }
              
              [R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2])
              def code(R, lambda1, lambda2, phi1, phi2):
              	return R * phi1
              
              R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
              function code(R, lambda1, lambda2, phi1, phi2)
              	return Float64(R * phi1)
              end
              
              R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
              function tmp = code(R, lambda1, lambda2, phi1, phi2)
              	tmp = R * phi1;
              end
              
              NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
              code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * phi1), $MachinePrecision]
              
              \begin{array}{l}
              [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
              \\
              R \cdot \phi_1
              \end{array}
              
              Derivation
              1. Initial program 59.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. Taylor expanded in phi1 around inf

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

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

                Reproduce

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