Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.8% → 91.5%
Time: 10.6s
Alternatives: 16
Speedup: 1.3×

Specification

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

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

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 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.8% 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: 91.5% accurate, 0.5× 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.25 \cdot 10^{-17}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(-0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right)\\ \mathbf{elif}\;\phi_2 \leq 2.7 \cdot 10^{+93}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(-0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right), \cos \left(\phi_2 \cdot -0.5\right), \left(\lambda_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right) \cdot \sin \left(\phi_2 \cdot -0.5\right)\right), \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 (<= phi2 2.25e-17)
   (* R (hypot (* (cos (* -0.5 phi1)) (- lambda1 lambda2)) phi1))
   (if (<= phi2 2.7e+93)
     (* R (hypot (* (cos (* -0.5 phi2)) (- lambda1 lambda2)) phi2))
     (*
      R
      (hypot
       (fma
        (* lambda2 (cos (* 0.5 phi1)))
        (cos (* phi2 -0.5))
        (* (* lambda2 (sin (* 0.5 phi1))) (sin (* phi2 -0.5))))
       (- 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 (phi2 <= 2.25e-17) {
		tmp = R * hypot((cos((-0.5 * phi1)) * (lambda1 - lambda2)), phi1);
	} else if (phi2 <= 2.7e+93) {
		tmp = R * hypot((cos((-0.5 * phi2)) * (lambda1 - lambda2)), phi2);
	} else {
		tmp = R * hypot(fma((lambda2 * cos((0.5 * phi1))), cos((phi2 * -0.5)), ((lambda2 * sin((0.5 * phi1))) * sin((phi2 * -0.5)))), (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 (phi2 <= 2.25e-17)
		tmp = Float64(R * hypot(Float64(cos(Float64(-0.5 * phi1)) * Float64(lambda1 - lambda2)), phi1));
	elseif (phi2 <= 2.7e+93)
		tmp = Float64(R * hypot(Float64(cos(Float64(-0.5 * phi2)) * Float64(lambda1 - lambda2)), phi2));
	else
		tmp = Float64(R * hypot(fma(Float64(lambda2 * cos(Float64(0.5 * phi1))), cos(Float64(phi2 * -0.5)), Float64(Float64(lambda2 * sin(Float64(0.5 * phi1))) * sin(Float64(phi2 * -0.5)))), Float64(phi1 - phi2)));
	end
	return tmp
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 2.25e-17], N[(R * N[Sqrt[N[(N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 2.7e+93], N[(R * N[Sqrt[N[(N[Cos[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(N[(lambda2 * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision] + N[(N[(lambda2 * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 2.25 \cdot 10^{-17}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(-0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right)\\

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

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


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

    1. Initial program 55.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.24999999999999989e-17 < phi2 < 2.6999999999999999e93

    1. Initial program 72.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.6999999999999999e93 < phi2

    1. Initial program 39.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\cos \left(-0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \lambda_2, \phi_1 - \phi_2\right)} \]
    6. Step-by-step derivation
      1. Applied rewrites92.8%

        \[\leadsto R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(\cos \left(-0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \sin \left(-0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) \cdot \lambda_2, \phi_1 - \phi_2\right) \]
      2. Step-by-step derivation
        1. Applied rewrites92.8%

          \[\leadsto R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(\cos \left(-0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right), \lambda_2, \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(-0.5 \cdot \phi_2\right)\right) \cdot \lambda_2\right), \color{blue}{\phi_1} - \phi_2\right) \]
        2. Step-by-step derivation
          1. Applied rewrites92.9%

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

        Alternative 2: 91.5% accurate, 0.5× speedup?

        \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \cos \left(-0.5 \cdot \phi_2\right)\\ \mathbf{if}\;\phi_2 \leq 2.25 \cdot 10^{-17}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(-0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right)\\ \mathbf{elif}\;\phi_2 \leq 2.7 \cdot 10^{+93}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(t\_0 \cdot \left(\lambda_1 - \lambda_2\right), \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(t\_0, \cos \left(0.5 \cdot \phi_1\right), \sin \left(-0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) \cdot \lambda_2, \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
         (let* ((t_0 (cos (* -0.5 phi2))))
           (if (<= phi2 2.25e-17)
             (* R (hypot (* (cos (* -0.5 phi1)) (- lambda1 lambda2)) phi1))
             (if (<= phi2 2.7e+93)
               (* R (hypot (* t_0 (- lambda1 lambda2)) phi2))
               (*
                R
                (hypot
                 (*
                  (fma
                   t_0
                   (cos (* 0.5 phi1))
                   (* (sin (* -0.5 phi2)) (sin (* 0.5 phi1))))
                  lambda2)
                 (- phi1 phi2)))))))
        assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
        double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
        	double t_0 = cos((-0.5 * phi2));
        	double tmp;
        	if (phi2 <= 2.25e-17) {
        		tmp = R * hypot((cos((-0.5 * phi1)) * (lambda1 - lambda2)), phi1);
        	} else if (phi2 <= 2.7e+93) {
        		tmp = R * hypot((t_0 * (lambda1 - lambda2)), phi2);
        	} else {
        		tmp = R * hypot((fma(t_0, cos((0.5 * phi1)), (sin((-0.5 * phi2)) * sin((0.5 * phi1)))) * lambda2), (phi1 - phi2));
        	}
        	return tmp;
        }
        
        R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
        function code(R, lambda1, lambda2, phi1, phi2)
        	t_0 = cos(Float64(-0.5 * phi2))
        	tmp = 0.0
        	if (phi2 <= 2.25e-17)
        		tmp = Float64(R * hypot(Float64(cos(Float64(-0.5 * phi1)) * Float64(lambda1 - lambda2)), phi1));
        	elseif (phi2 <= 2.7e+93)
        		tmp = Float64(R * hypot(Float64(t_0 * Float64(lambda1 - lambda2)), phi2));
        	else
        		tmp = Float64(R * hypot(Float64(fma(t_0, cos(Float64(0.5 * phi1)), Float64(sin(Float64(-0.5 * phi2)) * sin(Float64(0.5 * phi1)))) * lambda2), Float64(phi1 - phi2)));
        	end
        	return tmp
        end
        
        NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
        code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, 2.25e-17], N[(R * N[Sqrt[N[(N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 2.7e+93], N[(R * N[Sqrt[N[(t$95$0 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(N[(t$95$0 * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] + N[(N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * lambda2), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]]]
        
        \begin{array}{l}
        [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
        \\
        \begin{array}{l}
        t_0 := \cos \left(-0.5 \cdot \phi_2\right)\\
        \mathbf{if}\;\phi_2 \leq 2.25 \cdot 10^{-17}:\\
        \;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(-0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right)\\
        
        \mathbf{elif}\;\phi_2 \leq 2.7 \cdot 10^{+93}:\\
        \;\;\;\;R \cdot \mathsf{hypot}\left(t\_0 \cdot \left(\lambda_1 - \lambda_2\right), \phi_2\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(t\_0, \cos \left(0.5 \cdot \phi_1\right), \sin \left(-0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) \cdot \lambda_2, \phi_1 - \phi_2\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if phi2 < 2.24999999999999989e-17

          1. Initial program 55.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          if 2.24999999999999989e-17 < phi2 < 2.6999999999999999e93

          1. Initial program 72.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          if 2.6999999999999999e93 < phi2

          1. Initial program 39.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\cos \left(-0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \lambda_2, \phi_1 - \phi_2\right)} \]
          6. Step-by-step derivation
            1. Applied rewrites92.8%

              \[\leadsto R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(\cos \left(-0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \sin \left(-0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) \cdot \lambda_2, \phi_1 - \phi_2\right) \]
          7. Recombined 3 regimes into one program.
          8. Add Preprocessing

          Alternative 3: 63.2% accurate, 1.2× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              if -1.79999999999999991e-16 < phi1 < -5.80000000000000029e-54

              1. Initial program 59.4%

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

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

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

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

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

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

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

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

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

                  \[\leadsto \left(R - \color{blue}{R \cdot \frac{\phi_1}{\phi_2}}\right) \cdot \phi_2 \]
                9. lower-/.f6472.5

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

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

              if -5.80000000000000029e-54 < phi1 < 1.11999999999999993e-241

              1. Initial program 57.8%

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

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

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

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

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

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

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

                if 1.11999999999999993e-241 < phi1

                1. Initial program 52.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                Alternative 4: 90.5% accurate, 1.2× speedup?

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

                  1. Initial program 54.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  if -1.30000000000000009e-27 < phi1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                Alternative 5: 84.4% accurate, 1.2× speedup?

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

                  1. Initial program 57.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  if 4.5999999999999996e105 < phi2

                  1. Initial program 38.7%

                    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
                  2. Add Preprocessing
                  3. Taylor expanded in 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)} \]
                  4. Step-by-step derivation
                    1. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

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

                  Alternative 6: 64.0% accurate, 1.3× speedup?

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

                    1. Initial program 56.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                      if 1.81999999999999993e-153 < phi2 < 3.8e92

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

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

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

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

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

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

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

                        if 3.8e92 < phi2

                        1. Initial program 39.7%

                          \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
                        2. Add Preprocessing
                        3. Taylor expanded in 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)} \]
                        4. Step-by-step derivation
                          1. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

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

                        Alternative 7: 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}\;\phi_1 \leq -5.8 \cdot 10^{-54}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq 1.2 \cdot 10^{-235}:\\ \;\;\;\;R \cdot \left(\cos \left(-0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \mathsf{fma}\left(-1, \lambda_1, \lambda_2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(R - \frac{\phi_2 \cdot R}{\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 (<= phi1 -5.8e-54)
                           (* R (- phi2 phi1))
                           (if (<= phi1 1.2e-235)
                             (* R (* (cos (* -0.5 (+ phi2 phi1))) (fma -1.0 lambda1 lambda2)))
                             (* (- phi1) (- R (/ (* phi2 R) 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 (phi1 <= -5.8e-54) {
                        		tmp = R * (phi2 - phi1);
                        	} else if (phi1 <= 1.2e-235) {
                        		tmp = R * (cos((-0.5 * (phi2 + phi1))) * fma(-1.0, lambda1, lambda2));
                        	} else {
                        		tmp = -phi1 * (R - ((phi2 * R) / 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 (phi1 <= -5.8e-54)
                        		tmp = Float64(R * Float64(phi2 - phi1));
                        	elseif (phi1 <= 1.2e-235)
                        		tmp = Float64(R * Float64(cos(Float64(-0.5 * Float64(phi2 + phi1))) * fma(-1.0, lambda1, lambda2)));
                        	else
                        		tmp = Float64(Float64(-phi1) * Float64(R - Float64(Float64(phi2 * R) / 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[phi1, -5.8e-54], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 1.2e-235], N[(R * N[(N[Cos[N[(-0.5 * N[(phi2 + phi1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(-1.0 * lambda1 + lambda2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-phi1) * N[(R - N[(N[(phi2 * R), $MachinePrecision] / 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_1 \leq -5.8 \cdot 10^{-54}:\\
                        \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
                        
                        \mathbf{elif}\;\phi_1 \leq 1.2 \cdot 10^{-235}:\\
                        \;\;\;\;R \cdot \left(\cos \left(-0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \mathsf{fma}\left(-1, \lambda_1, \lambda_2\right)\right)\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;\left(-\phi_1\right) \cdot \left(R - \frac{\phi_2 \cdot R}{\phi_1}\right)\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 3 regimes
                        2. if phi1 < -5.80000000000000029e-54

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

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

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

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

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

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

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

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

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

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

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

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

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

                            if -5.80000000000000029e-54 < phi1 < 1.20000000000000005e-235

                            1. Initial program 57.1%

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

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

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

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

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

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

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

                              if 1.20000000000000005e-235 < phi1

                              1. Initial program 53.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                  \[\leadsto R \cdot \mathsf{hypot}\left(\cos \left(\frac{-1}{2} \cdot \color{blue}{\left(\phi_2 + \phi_1\right)}\right) \cdot \lambda_2, \phi_1 - \phi_2\right) \]
                                15. lower--.f6476.7

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

                                \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\cos \left(-0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \lambda_2, \phi_1 - \phi_2\right)} \]
                              6. Step-by-step derivation
                                1. Applied rewrites80.5%

                                  \[\leadsto R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(\cos \left(-0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \sin \left(-0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) \cdot \lambda_2, \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 \color{blue}{\left(-1 \cdot \phi_1\right) \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                                  2. mul-1-negN/A

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

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

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

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

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

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

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

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

                                    \[\leadsto \left(-\phi_1\right) \cdot \left(R - \frac{\color{blue}{\phi_2 \cdot R}}{\phi_1}\right) \]
                                  11. lower-*.f6411.5

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

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

                              Alternative 8: 51.0% accurate, 2.1× speedup?

                              \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} t_0 := \cos \left(-0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\\ \mathbf{if}\;\lambda_1 \leq -4.2 \cdot 10^{+103}:\\ \;\;\;\;\left(-\lambda_1\right) \cdot \left(t\_0 \cdot R\right)\\ \mathbf{elif}\;\lambda_1 \leq 9 \cdot 10^{+102}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(R - \frac{\phi_2 \cdot R}{\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 (cos (* -0.5 (+ phi2 phi1)))))
                                 (if (<= lambda1 -4.2e+103)
                                   (* (- lambda1) (* t_0 R))
                                   (if (<= lambda1 9e+102)
                                     (* (- phi1) (- R (/ (* phi2 R) 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 = cos((-0.5 * (phi2 + phi1)));
                              	double tmp;
                              	if (lambda1 <= -4.2e+103) {
                              		tmp = -lambda1 * (t_0 * R);
                              	} else if (lambda1 <= 9e+102) {
                              		tmp = -phi1 * (R - ((phi2 * R) / 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 = cos(((-0.5d0) * (phi2 + phi1)))
                                  if (lambda1 <= (-4.2d+103)) then
                                      tmp = -lambda1 * (t_0 * r)
                                  else if (lambda1 <= 9d+102) then
                                      tmp = -phi1 * (r - ((phi2 * r) / 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.cos((-0.5 * (phi2 + phi1)));
                              	double tmp;
                              	if (lambda1 <= -4.2e+103) {
                              		tmp = -lambda1 * (t_0 * R);
                              	} else if (lambda1 <= 9e+102) {
                              		tmp = -phi1 * (R - ((phi2 * R) / 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.cos((-0.5 * (phi2 + phi1)))
                              	tmp = 0
                              	if lambda1 <= -4.2e+103:
                              		tmp = -lambda1 * (t_0 * R)
                              	elif lambda1 <= 9e+102:
                              		tmp = -phi1 * (R - ((phi2 * R) / 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 = cos(Float64(-0.5 * Float64(phi2 + phi1)))
                              	tmp = 0.0
                              	if (lambda1 <= -4.2e+103)
                              		tmp = Float64(Float64(-lambda1) * Float64(t_0 * R));
                              	elseif (lambda1 <= 9e+102)
                              		tmp = Float64(Float64(-phi1) * Float64(R - Float64(Float64(phi2 * R) / 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 = cos((-0.5 * (phi2 + phi1)));
                              	tmp = 0.0;
                              	if (lambda1 <= -4.2e+103)
                              		tmp = -lambda1 * (t_0 * R);
                              	elseif (lambda1 <= 9e+102)
                              		tmp = -phi1 * (R - ((phi2 * R) / 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[Cos[N[(-0.5 * N[(phi2 + phi1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[lambda1, -4.2e+103], N[((-lambda1) * N[(t$95$0 * R), $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda1, 9e+102], N[((-phi1) * N[(R - N[(N[(phi2 * R), $MachinePrecision] / 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 := \cos \left(-0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\\
                              \mathbf{if}\;\lambda_1 \leq -4.2 \cdot 10^{+103}:\\
                              \;\;\;\;\left(-\lambda_1\right) \cdot \left(t\_0 \cdot R\right)\\
                              
                              \mathbf{elif}\;\lambda_1 \leq 9 \cdot 10^{+102}:\\
                              \;\;\;\;\left(-\phi_1\right) \cdot \left(R - \frac{\phi_2 \cdot R}{\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 < -4.2000000000000003e103

                                1. Initial program 48.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                  if -4.2000000000000003e103 < lambda1 < 9.00000000000000042e102

                                  1. Initial program 58.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                    \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\cos \left(-0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \lambda_2, \phi_1 - \phi_2\right)} \]
                                  6. Step-by-step derivation
                                    1. Applied rewrites96.5%

                                      \[\leadsto R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(\cos \left(-0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \sin \left(-0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) \cdot \lambda_2, \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 \color{blue}{\left(-1 \cdot \phi_1\right) \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                                      2. mul-1-negN/A

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

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

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

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

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

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

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

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

                                        \[\leadsto \left(-\phi_1\right) \cdot \left(R - \frac{\color{blue}{\phi_2 \cdot R}}{\phi_1}\right) \]
                                      11. lower-*.f6432.8

                                        \[\leadsto \left(-\phi_1\right) \cdot \left(R - \frac{\color{blue}{\phi_2 \cdot R}}{\phi_1}\right) \]
                                    4. Applied rewrites32.8%

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

                                    if 9.00000000000000042e102 < lambda1

                                    1. Initial program 48.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

                                  Alternative 9: 54.5% accurate, 2.1× speedup?

                                  \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -3.3 \cdot 10^{+174}:\\ \;\;\;\;\left(R \cdot \lambda_1\right) \cdot \cos \left(\mathsf{fma}\left(-0.5, \phi_2 + \phi_1, \mathsf{PI}\left(\right)\right)\right)\\ \mathbf{elif}\;\lambda_1 \leq 7.5 \cdot 10^{+101}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(R \cdot \lambda_2\right) \cdot \cos \left(-0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\\ \end{array} \end{array} \]
                                  NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                                  (FPCore (R lambda1 lambda2 phi1 phi2)
                                   :precision binary64
                                   (if (<= lambda1 -3.3e+174)
                                     (* (* R lambda1) (cos (fma -0.5 (+ phi2 phi1) (PI))))
                                     (if (<= lambda1 7.5e+101)
                                       (* R (- phi2 phi1))
                                       (* (* R lambda2) (cos (* -0.5 (+ phi2 phi1)))))))
                                  \begin{array}{l}
                                  [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                                  \\
                                  \begin{array}{l}
                                  \mathbf{if}\;\lambda_1 \leq -3.3 \cdot 10^{+174}:\\
                                  \;\;\;\;\left(R \cdot \lambda_1\right) \cdot \cos \left(\mathsf{fma}\left(-0.5, \phi_2 + \phi_1, \mathsf{PI}\left(\right)\right)\right)\\
                                  
                                  \mathbf{elif}\;\lambda_1 \leq 7.5 \cdot 10^{+101}:\\
                                  \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
                                  
                                  \mathbf{else}:\\
                                  \;\;\;\;\left(R \cdot \lambda_2\right) \cdot \cos \left(-0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\\
                                  
                                  
                                  \end{array}
                                  \end{array}
                                  
                                  Derivation
                                  1. Split input into 3 regimes
                                  2. if lambda1 < -3.3000000000000001e174

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                        \[\leadsto \left(R \cdot \lambda_1\right) \cdot \cos \left(\mathsf{fma}\left(\frac{-1}{2}, \color{blue}{\phi_2 + \phi_1}, \mathsf{PI}\left(\right)\right)\right) \]
                                      16. lower-PI.f6447.5

                                        \[\leadsto \left(R \cdot \lambda_1\right) \cdot \cos \left(\mathsf{fma}\left(-0.5, \phi_2 + \phi_1, \color{blue}{\mathsf{PI}\left(\right)}\right)\right) \]
                                    5. Applied rewrites47.5%

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

                                    if -3.3000000000000001e174 < lambda1 < 7.4999999999999995e101

                                    1. Initial program 55.8%

                                      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
                                    2. Add Preprocessing
                                    3. 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)} \]
                                    4. Step-by-step derivation
                                      1. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

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

                                      if 7.4999999999999995e101 < lambda1

                                      1. Initial program 48.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

                                    Alternative 10: 56.8% accurate, 2.2× speedup?

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

                                      1. Initial program 56.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                          \[\leadsto R \cdot \mathsf{hypot}\left(\cos \left(\frac{-1}{2} \cdot \color{blue}{\left(\phi_2 + \phi_1\right)}\right) \cdot \lambda_2, \phi_1 - \phi_2\right) \]
                                        15. lower--.f6477.6

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

                                        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\cos \left(-0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \lambda_2, \phi_1 - \phi_2\right)} \]
                                      6. Step-by-step derivation
                                        1. Applied rewrites79.7%

                                          \[\leadsto R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(\cos \left(-0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \sin \left(-0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) \cdot \lambda_2, \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 \color{blue}{\left(-1 \cdot \phi_1\right) \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                                          2. mul-1-negN/A

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

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

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

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

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

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

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

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

                                            \[\leadsto \left(-\phi_1\right) \cdot \left(R - \frac{\color{blue}{\phi_2 \cdot R}}{\phi_1}\right) \]
                                          11. lower-*.f6428.8

                                            \[\leadsto \left(-\phi_1\right) \cdot \left(R - \frac{\color{blue}{\phi_2 \cdot R}}{\phi_1}\right) \]
                                        4. Applied rewrites28.8%

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

                                        if 3.5000000000000002e228 < lambda2

                                        1. Initial program 26.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

                                      Alternative 11: 58.3% accurate, 7.7× speedup?

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

                                        1. Initial program 41.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                            \[\leadsto R \cdot \mathsf{hypot}\left(\cos \left(\frac{-1}{2} \cdot \color{blue}{\left(\phi_2 + \phi_1\right)}\right) \cdot \lambda_2, \phi_1 - \phi_2\right) \]
                                          15. lower--.f6458.7

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

                                          \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\cos \left(-0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \lambda_2, \phi_1 - \phi_2\right)} \]
                                        6. Step-by-step derivation
                                          1. Applied rewrites61.9%

                                            \[\leadsto R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(\cos \left(-0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \sin \left(-0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) \cdot \lambda_2, \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 \color{blue}{\left(-1 \cdot \phi_1\right) \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                                            2. mul-1-negN/A

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

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

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

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

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

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

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

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

                                              \[\leadsto \left(-\phi_1\right) \cdot \left(R - \frac{\color{blue}{\phi_2 \cdot R}}{\phi_1}\right) \]
                                            11. lower-*.f6418.0

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

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

                                          if -5.00000000000000049e198 < (-.f64 lambda1 lambda2)

                                          1. Initial program 57.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. Add Preprocessing
                                          3. 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)} \]
                                          4. Step-by-step derivation
                                            1. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

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

                                          Alternative 12: 58.9% accurate, 8.5× speedup?

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

                                            1. Initial program 56.5%

                                              \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
                                            2. Add Preprocessing
                                            3. Taylor expanded in 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)} \]
                                            4. Step-by-step derivation
                                              1. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

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

                                            if -6.5e54 < phi1

                                            1. Initial program 53.9%

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

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

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

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

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

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

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

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

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

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

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

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

                                          Alternative 13: 58.9% accurate, 9.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 -6.5 \cdot 10^{+54}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(R - R \cdot \frac{\phi_1}{\phi_2}\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 -6.5e+54)
                                             (* R (- phi2 phi1))
                                             (* (- R (* R (/ phi1 phi2))) 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 <= -6.5e+54) {
                                          		tmp = R * (phi2 - phi1);
                                          	} else {
                                          		tmp = (R - (R * (phi1 / phi2))) * 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 <= (-6.5d+54)) then
                                                  tmp = r * (phi2 - phi1)
                                              else
                                                  tmp = (r - (r * (phi1 / phi2))) * 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 <= -6.5e+54) {
                                          		tmp = R * (phi2 - phi1);
                                          	} else {
                                          		tmp = (R - (R * (phi1 / phi2))) * 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 <= -6.5e+54:
                                          		tmp = R * (phi2 - phi1)
                                          	else:
                                          		tmp = (R - (R * (phi1 / phi2))) * 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 <= -6.5e+54)
                                          		tmp = Float64(R * Float64(phi2 - phi1));
                                          	else
                                          		tmp = Float64(Float64(R - Float64(R * Float64(phi1 / phi2))) * 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 <= -6.5e+54)
                                          		tmp = R * (phi2 - phi1);
                                          	else
                                          		tmp = (R - (R * (phi1 / phi2))) * 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, -6.5e+54], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], N[(N[(R - N[(R * N[(phi1 / phi2), $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 -6.5 \cdot 10^{+54}:\\
                                          \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
                                          
                                          \mathbf{else}:\\
                                          \;\;\;\;\left(R - R \cdot \frac{\phi_1}{\phi_2}\right) \cdot \phi_2\\
                                          
                                          
                                          \end{array}
                                          \end{array}
                                          
                                          Derivation
                                          1. Split input into 2 regimes
                                          2. if phi1 < -6.5e54

                                            1. Initial program 56.5%

                                              \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
                                            2. Add Preprocessing
                                            3. Taylor expanded in 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)} \]
                                            4. Step-by-step derivation
                                              1. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

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

                                              if -6.5e54 < phi1

                                              1. Initial program 53.9%

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

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

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

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

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

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

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

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

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

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

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

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

                                            Alternative 14: 52.0% accurate, 19.9× speedup?

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

                                              1. Initial program 54.0%

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

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

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

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

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

                                              if -9.6000000000000008e-28 < phi1

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

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

                                                  \[\leadsto \color{blue}{R \cdot \phi_2} \]
                                              5. Applied rewrites12.3%

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

                                            Alternative 15: 57.7% accurate, 31.0× speedup?

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

                                              \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
                                            2. Add Preprocessing
                                            3. Taylor expanded in phi1 around -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)} \]
                                            4. Step-by-step derivation
                                              1. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

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

                                              Alternative 16: 30.5% accurate, 46.5× speedup?

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

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

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

                                                  \[\leadsto \color{blue}{R \cdot \phi_2} \]
                                              5. Applied rewrites11.7%

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

                                              Reproduce

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