Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.5% → 95.6%
Time: 7.2s
Alternatives: 16
Speedup: 1.2×

Specification

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

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

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

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

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 16 alternatives:

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

Initial Program: 59.5% accurate, 1.0× speedup?

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

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

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

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

Alternative 1: 95.6% accurate, 1.2× speedup?

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

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


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

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

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

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

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

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

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

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

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

    if -7.9999999999999996e-7 < phi1

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

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

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

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

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

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

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

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

Alternative 2: 91.2% accurate, 1.2× speedup?

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

\mathbf{elif}\;\phi_2 \leq 8.5 \cdot 10^{+22}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1, t\_0 \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < 620

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

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

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

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

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

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

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

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

    if 620 < phi2 < 8.49999999999999979e22

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

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

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

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

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

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

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

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

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

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

      if 8.49999999999999979e22 < phi2

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

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

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

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

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

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

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

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

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

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

      Alternative 3: 85.9% 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 2 \cdot 10^{-38}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{elif}\;\phi_2 \leq 1.32 \cdot 10^{+34}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \end{array} \end{array} \]
      NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
      (FPCore (R lambda1 lambda2 phi1 phi2)
       :precision binary64
       (if (<= phi2 2e-38)
         (* (hypot phi1 (* (cos (* 0.5 phi1)) (- lambda1 lambda2))) R)
         (if (<= phi2 1.32e+34)
           (* (hypot phi1 (* (cos (* 0.5 phi2)) (- lambda1 lambda2))) R)
           (fma (- R) phi1 (* R phi2)))))
      assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
      double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	double tmp;
      	if (phi2 <= 2e-38) {
      		tmp = hypot(phi1, (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
      	} else if (phi2 <= 1.32e+34) {
      		tmp = hypot(phi1, (cos((0.5 * phi2)) * (lambda1 - lambda2))) * R;
      	} else {
      		tmp = fma(-R, phi1, (R * phi2));
      	}
      	return tmp;
      }
      
      R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
      function code(R, lambda1, lambda2, phi1, phi2)
      	tmp = 0.0
      	if (phi2 <= 2e-38)
      		tmp = Float64(hypot(phi1, Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2))) * R);
      	elseif (phi2 <= 1.32e+34)
      		tmp = Float64(hypot(phi1, Float64(cos(Float64(0.5 * phi2)) * Float64(lambda1 - lambda2))) * R);
      	else
      		tmp = fma(Float64(-R), phi1, Float64(R * 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, 2e-38], N[(N[Sqrt[phi1 ^ 2 + N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi2, 1.32e+34], N[(N[Sqrt[phi1 ^ 2 + N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision]]]
      
      \begin{array}{l}
      [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
      \\
      \begin{array}{l}
      \mathbf{if}\;\phi_2 \leq 2 \cdot 10^{-38}:\\
      \;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
      
      \mathbf{elif}\;\phi_2 \leq 1.32 \cdot 10^{+34}:\\
      \;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
      
      \mathbf{else}:\\
      \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if phi2 < 1.9999999999999999e-38

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

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

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

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

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

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

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

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

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

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

          if 1.9999999999999999e-38 < phi2 < 1.31999999999999991e34

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

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

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

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

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

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

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

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

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

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

            if 1.31999999999999991e34 < phi2

            1. Initial program 36.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 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 \left(-1 \cdot \phi_1\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
              2. mul-1-negN/A

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

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

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

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

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

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

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

                \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right) \]
              10. lower-*.f6458.2

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
              5. lower-*.f6468.2

                \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
            11. Applied rewrites68.2%

              \[\leadsto \mathsf{fma}\left(-R, \color{blue}{\phi_1}, R \cdot \phi_2\right) \]
          10. Recombined 3 regimes into one program.
          11. Final simplification78.6%

            \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 2 \cdot 10^{-38}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{elif}\;\phi_2 \leq 1.32 \cdot 10^{+34}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \end{array} \]
          12. Add Preprocessing

          Alternative 4: 95.7% accurate, 1.2× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              if 0.00700000000000000015 < phi2

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

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

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

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

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

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

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

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

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

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

              Alternative 6: 84.9% 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 5.8 \cdot 10^{+33}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \end{array} \end{array} \]
              NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
              (FPCore (R lambda1 lambda2 phi1 phi2)
               :precision binary64
               (if (<= phi2 5.8e+33)
                 (* (hypot phi1 (* (cos (* 0.5 phi1)) (- lambda1 lambda2))) R)
                 (fma (- R) phi1 (* R phi2))))
              assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
              double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
              	double tmp;
              	if (phi2 <= 5.8e+33) {
              		tmp = hypot(phi1, (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
              	} else {
              		tmp = fma(-R, phi1, (R * phi2));
              	}
              	return tmp;
              }
              
              R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
              function code(R, lambda1, lambda2, phi1, phi2)
              	tmp = 0.0
              	if (phi2 <= 5.8e+33)
              		tmp = Float64(hypot(phi1, Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2))) * R);
              	else
              		tmp = fma(Float64(-R), phi1, Float64(R * 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, 5.8e+33], N[(N[Sqrt[phi1 ^ 2 + N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision]]
              
              \begin{array}{l}
              [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
              \\
              \begin{array}{l}
              \mathbf{if}\;\phi_2 \leq 5.8 \cdot 10^{+33}:\\
              \;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
              
              \mathbf{else}:\\
              \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if phi2 < 5.80000000000000049e33

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

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

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

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

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

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

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

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

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

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

                  if 5.80000000000000049e33 < phi2

                  1. Initial program 36.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 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 \left(-1 \cdot \phi_1\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                    2. mul-1-negN/A

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

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

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

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

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

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

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

                      \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right) \]
                    10. lower-*.f6458.2

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

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                    5. lower-*.f6468.2

                      \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                  11. Applied rewrites68.2%

                    \[\leadsto \mathsf{fma}\left(-R, \color{blue}{\phi_1}, R \cdot \phi_2\right) \]
                10. Recombined 2 regimes into one program.
                11. Final simplification76.9%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 5.8 \cdot 10^{+33}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \end{array} \]
                12. Add Preprocessing

                Alternative 7: 58.1% 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 7.8 \cdot 10^{+180}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \lambda_2\right)\\ \end{array} \end{array} \]
                NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                (FPCore (R lambda1 lambda2 phi1 phi2)
                 :precision binary64
                 (if (<= lambda2 7.8e+180)
                   (fma (- R) phi1 (* R phi2))
                   (* R (* (cos (* 0.5 (+ phi2 phi1))) lambda2))))
                assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                	double tmp;
                	if (lambda2 <= 7.8e+180) {
                		tmp = fma(-R, phi1, (R * phi2));
                	} else {
                		tmp = R * (cos((0.5 * (phi2 + phi1))) * lambda2);
                	}
                	return tmp;
                }
                
                R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                function code(R, lambda1, lambda2, phi1, phi2)
                	tmp = 0.0
                	if (lambda2 <= 7.8e+180)
                		tmp = fma(Float64(-R), phi1, Float64(R * phi2));
                	else
                		tmp = Float64(R * Float64(cos(Float64(0.5 * Float64(phi2 + phi1))) * lambda2));
                	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[lambda2, 7.8e+180], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision], N[(R * N[(N[Cos[N[(0.5 * N[(phi2 + phi1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * lambda2), $MachinePrecision]), $MachinePrecision]]
                
                \begin{array}{l}
                [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                \\
                \begin{array}{l}
                \mathbf{if}\;\lambda_2 \leq 7.8 \cdot 10^{+180}:\\
                \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
                
                \mathbf{else}:\\
                \;\;\;\;R \cdot \left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \lambda_2\right)\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if lambda2 < 7.8000000000000002e180

                  1. Initial program 61.3%

                    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
                  2. 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 \left(-1 \cdot \phi_1\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                    2. mul-1-negN/A

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

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

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

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

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

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

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

                      \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right) \]
                    10. lower-*.f6430.3

                      \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right) \]
                  5. Applied rewrites30.3%

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                    5. lower-*.f6432.0

                      \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                  11. Applied rewrites32.0%

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

                  if 7.8000000000000002e180 < lambda2

                  1. Initial program 39.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 lambda2 around inf

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

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

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

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

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

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

                      \[\leadsto R \cdot \left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \lambda_2\right) \]
                  5. Applied rewrites58.7%

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

                  \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 7.8 \cdot 10^{+180}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \lambda_2\right)\\ \end{array} \]
                5. Add Preprocessing

                Alternative 8: 58.1% 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 7.8 \cdot 10^{+180}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\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 7.8e+180)
                   (fma (- R) phi1 (* R phi2))
                   (* (* 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 <= 7.8e+180) {
                		tmp = fma(-R, phi1, (R * phi2));
                	} else {
                		tmp = (R * lambda2) * 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 <= 7.8e+180)
                		tmp = fma(Float64(-R), phi1, Float64(R * phi2));
                	else
                		tmp = Float64(Float64(R * lambda2) * cos(Float64(0.5 * 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[lambda2, 7.8e+180], N[((-R) * phi1 + N[(R * phi2), $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 7.8 \cdot 10^{+180}:\\
                \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\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 < 7.8000000000000002e180

                  1. Initial program 61.3%

                    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
                  2. 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 \left(-1 \cdot \phi_1\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                    2. mul-1-negN/A

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

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

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

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

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

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

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

                      \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right) \]
                    10. lower-*.f6430.3

                      \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right) \]
                  5. Applied rewrites30.3%

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                    5. lower-*.f6432.0

                      \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                  11. Applied rewrites32.0%

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

                  if 7.8000000000000002e180 < lambda2

                  1. Initial program 39.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 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 \left(R \cdot \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)} \]
                    2. lower-*.f64N/A

                      \[\leadsto \left(R \cdot \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)} \]
                    3. 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)} \]
                    4. lower-cos.f64N/A

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

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

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

                      \[\leadsto \left(R \cdot \lambda_2\right) \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \]
                  5. Applied rewrites58.7%

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

                  \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 7.8 \cdot 10^{+180}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;\left(R \cdot \lambda_2\right) \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\\ \end{array} \]
                5. Add Preprocessing

                Alternative 9: 58.4% accurate, 2.3× speedup?

                \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 5.4 \cdot 10^{+185}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\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 5.4e+185)
                   (fma (- R) phi1 (* R phi2))
                   (* R (* lambda2 (cos (* 0.5 phi2))))))
                assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                	double tmp;
                	if (lambda2 <= 5.4e+185) {
                		tmp = fma(-R, phi1, (R * phi2));
                	} else {
                		tmp = R * (lambda2 * cos((0.5 * phi2)));
                	}
                	return tmp;
                }
                
                R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                function code(R, lambda1, lambda2, phi1, phi2)
                	tmp = 0.0
                	if (lambda2 <= 5.4e+185)
                		tmp = fma(Float64(-R), phi1, Float64(R * phi2));
                	else
                		tmp = Float64(R * Float64(lambda2 * cos(Float64(0.5 * 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[lambda2, 5.4e+185], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision], N[(R * N[(lambda2 * N[Cos[N[(0.5 * phi2), $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 5.4 \cdot 10^{+185}:\\
                \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
                
                \mathbf{else}:\\
                \;\;\;\;R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if lambda2 < 5.40000000000000013e185

                  1. Initial program 61.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 \left(-1 \cdot \phi_1\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                    2. mul-1-negN/A

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

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

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

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

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

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

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

                      \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right) \]
                    10. lower-*.f6430.6

                      \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right) \]
                  5. Applied rewrites30.6%

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                    5. lower-*.f6432.3

                      \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                  11. Applied rewrites32.3%

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

                  if 5.40000000000000013e185 < lambda2

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

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

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

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

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

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

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

                    \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(0.5 \cdot \phi_2\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                  8. 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)} \]
                  9. Step-by-step derivation
                    1. associate-*r*N/A

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

                      \[\leadsto \left(R \cdot \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)} \]
                    3. 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)} \]
                    4. +-commutativeN/A

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

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

                      \[\leadsto \left(R \cdot \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_2 + \phi_1\right)\right) \]
                    7. lift-cos.f6457.4

                      \[\leadsto \left(R \cdot \lambda_2\right) \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \]
                  10. Applied rewrites57.4%

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

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

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

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

                      \[\leadsto R \cdot \left(\lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right) \]
                    4. lift-*.f6451.5

                      \[\leadsto R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \]
                  13. Applied rewrites51.5%

                    \[\leadsto R \cdot \color{blue}{\left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)} \]
                3. Recombined 2 regimes into one program.
                4. Final simplification34.7%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 5.4 \cdot 10^{+185}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)\\ \end{array} \]
                5. Add Preprocessing

                Alternative 10: 58.3% accurate, 2.3× speedup?

                \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 2.3 \cdot 10^{+180}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \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 2.3e+180)
                   (fma (- R) phi1 (* R phi2))
                   (* R (* lambda2 (cos (* 0.5 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 <= 2.3e+180) {
                		tmp = fma(-R, phi1, (R * phi2));
                	} else {
                		tmp = R * (lambda2 * cos((0.5 * 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 <= 2.3e+180)
                		tmp = fma(Float64(-R), phi1, Float64(R * phi2));
                	else
                		tmp = Float64(R * Float64(lambda2 * cos(Float64(0.5 * 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[lambda2, 2.3e+180], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision], N[(R * N[(lambda2 * N[Cos[N[(0.5 * 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 2.3 \cdot 10^{+180}:\\
                \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
                
                \mathbf{else}:\\
                \;\;\;\;R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if lambda2 < 2.2999999999999999e180

                  1. Initial program 61.3%

                    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
                  2. 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 \left(-1 \cdot \phi_1\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                    2. mul-1-negN/A

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

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

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

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

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

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

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

                      \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right) \]
                    10. lower-*.f6430.3

                      \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right) \]
                  5. Applied rewrites30.3%

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                    5. lower-*.f6432.0

                      \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                  11. Applied rewrites32.0%

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

                  if 2.2999999999999999e180 < lambda2

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

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

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

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

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

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

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

                    \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(0.5 \cdot \phi_2\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                  8. 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)} \]
                  9. Step-by-step derivation
                    1. associate-*r*N/A

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

                      \[\leadsto \left(R \cdot \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)} \]
                    3. 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)} \]
                    4. +-commutativeN/A

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

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

                      \[\leadsto \left(R \cdot \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_2 + \phi_1\right)\right) \]
                    7. lift-cos.f6458.7

                      \[\leadsto \left(R \cdot \lambda_2\right) \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \]
                  10. Applied rewrites58.7%

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

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

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

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

                      \[\leadsto R \cdot \left(\lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) \]
                    4. lift-*.f6456.6

                      \[\leadsto R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \]
                  13. Applied rewrites56.6%

                    \[\leadsto R \cdot \color{blue}{\left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
                3. Recombined 2 regimes into one program.
                4. Final simplification35.1%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 2.3 \cdot 10^{+180}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\\ \end{array} \]
                5. Add Preprocessing

                Alternative 11: 58.3% accurate, 5.4× speedup?

                \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;R \leq 1.3 \cdot 10^{+150}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \frac{\mathsf{fma}\left(-1, R, \frac{R \cdot \phi_1}{\phi_2}\right)}{\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 (<= R 1.3e+150)
                   (fma (- R) phi1 (* R phi2))
                   (* (- phi1) (* phi2 (/ (fma -1.0 R (/ (* R phi1) phi2)) phi1)))))
                assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                	double tmp;
                	if (R <= 1.3e+150) {
                		tmp = fma(-R, phi1, (R * phi2));
                	} else {
                		tmp = -phi1 * (phi2 * (fma(-1.0, R, ((R * phi1) / phi2)) / phi1));
                	}
                	return tmp;
                }
                
                R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                function code(R, lambda1, lambda2, phi1, phi2)
                	tmp = 0.0
                	if (R <= 1.3e+150)
                		tmp = fma(Float64(-R), phi1, Float64(R * phi2));
                	else
                		tmp = Float64(Float64(-phi1) * Float64(phi2 * Float64(fma(-1.0, R, Float64(Float64(R * phi1) / 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[R, 1.3e+150], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision], N[((-phi1) * N[(phi2 * N[(N[(-1.0 * R + N[(N[(R * phi1), $MachinePrecision] / phi2), $MachinePrecision]), $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}\;R \leq 1.3 \cdot 10^{+150}:\\
                \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
                
                \mathbf{else}:\\
                \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \frac{\mathsf{fma}\left(-1, R, \frac{R \cdot \phi_1}{\phi_2}\right)}{\phi_1}\right)\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if R < 1.30000000000000003e150

                  1. Initial program 53.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 \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 \left(-1 \cdot \phi_1\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                    2. mul-1-negN/A

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

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

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

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

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

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

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

                      \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right) \]
                    10. lower-*.f6428.2

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

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                    5. lower-*.f6430.3

                      \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                  11. Applied rewrites30.3%

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

                  if 1.30000000000000003e150 < R

                  1. Initial program 100.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 \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 \left(-1 \cdot \phi_1\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                    2. mul-1-negN/A

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

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

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

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

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

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

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

                      \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right) \]
                    10. lower-*.f6432.5

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

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

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

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

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

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

                      \[\leadsto \left(-\phi_1\right) \cdot \left(\phi_2 \cdot \mathsf{fma}\left(-1, \frac{R}{\phi_1}, \frac{R}{\phi_2}\right)\right) \]
                  8. Applied rewrites28.9%

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

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

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

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

                      \[\leadsto \left(-\phi_1\right) \cdot \left(\phi_2 \cdot \frac{\mathsf{fma}\left(-1, R, \frac{R \cdot \phi_1}{\phi_2}\right)}{\phi_1}\right) \]
                    4. lower-*.f6436.3

                      \[\leadsto \left(-\phi_1\right) \cdot \left(\phi_2 \cdot \frac{\mathsf{fma}\left(-1, R, \frac{R \cdot \phi_1}{\phi_2}\right)}{\phi_1}\right) \]
                  11. Applied rewrites36.3%

                    \[\leadsto \left(-\phi_1\right) \cdot \left(\phi_2 \cdot \frac{\mathsf{fma}\left(-1, R, \frac{R \cdot \phi_1}{\phi_2}\right)}{\phi_1}\right) \]
                3. Recombined 2 regimes into one program.
                4. Final simplification30.9%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;R \leq 1.3 \cdot 10^{+150}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \frac{\mathsf{fma}\left(-1, R, \frac{R \cdot \phi_1}{\phi_2}\right)}{\phi_1}\right)\\ \end{array} \]
                5. Add Preprocessing

                Alternative 12: 58.5% accurate, 5.9× speedup?

                \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 2.65 \cdot 10^{+34}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \mathsf{fma}\left(-1, \frac{R}{\phi_1}, \frac{R}{\phi_2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \end{array} \end{array} \]
                NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                (FPCore (R lambda1 lambda2 phi1 phi2)
                 :precision binary64
                 (if (<= phi2 2.65e+34)
                   (* (- phi1) (* phi2 (fma -1.0 (/ R phi1) (/ R phi2))))
                   (fma (- R) phi1 (* R phi2))))
                assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                	double tmp;
                	if (phi2 <= 2.65e+34) {
                		tmp = -phi1 * (phi2 * fma(-1.0, (R / phi1), (R / phi2)));
                	} else {
                		tmp = fma(-R, phi1, (R * phi2));
                	}
                	return tmp;
                }
                
                R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                function code(R, lambda1, lambda2, phi1, phi2)
                	tmp = 0.0
                	if (phi2 <= 2.65e+34)
                		tmp = Float64(Float64(-phi1) * Float64(phi2 * fma(-1.0, Float64(R / phi1), Float64(R / phi2))));
                	else
                		tmp = fma(Float64(-R), phi1, Float64(R * 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.65e+34], N[((-phi1) * N[(phi2 * N[(-1.0 * N[(R / phi1), $MachinePrecision] + N[(R / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision]]
                
                \begin{array}{l}
                [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                \\
                \begin{array}{l}
                \mathbf{if}\;\phi_2 \leq 2.65 \cdot 10^{+34}:\\
                \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \mathsf{fma}\left(-1, \frac{R}{\phi_1}, \frac{R}{\phi_2}\right)\right)\\
                
                \mathbf{else}:\\
                \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if phi2 < 2.6500000000000002e34

                  1. Initial program 64.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 \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 \left(-1 \cdot \phi_1\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                    2. mul-1-negN/A

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

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

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

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

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

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

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

                      \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right) \]
                    10. lower-*.f6420.2

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

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

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

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

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

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

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

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

                  if 2.6500000000000002e34 < phi2

                  1. Initial program 36.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 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 \left(-1 \cdot \phi_1\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                    2. mul-1-negN/A

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

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

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

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

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

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

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

                      \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right) \]
                    10. lower-*.f6458.2

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

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                    5. lower-*.f6468.2

                      \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                  11. Applied rewrites68.2%

                    \[\leadsto \mathsf{fma}\left(-R, \color{blue}{\phi_1}, R \cdot \phi_2\right) \]
                3. Recombined 2 regimes into one program.
                4. Final simplification30.8%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 2.65 \cdot 10^{+34}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \mathsf{fma}\left(-1, \frac{R}{\phi_1}, \frac{R}{\phi_2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \end{array} \]
                5. Add Preprocessing

                Alternative 13: 58.4% accurate, 9.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 3.4 \cdot 10^{-132}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \frac{R}{\phi_2}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \end{array} \end{array} \]
                NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                (FPCore (R lambda1 lambda2 phi1 phi2)
                 :precision binary64
                 (if (<= phi2 3.4e-132)
                   (* (- phi1) (* phi2 (/ R phi2)))
                   (fma (- R) phi1 (* R phi2))))
                assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                	double tmp;
                	if (phi2 <= 3.4e-132) {
                		tmp = -phi1 * (phi2 * (R / phi2));
                	} else {
                		tmp = fma(-R, phi1, (R * phi2));
                	}
                	return tmp;
                }
                
                R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                function code(R, lambda1, lambda2, phi1, phi2)
                	tmp = 0.0
                	if (phi2 <= 3.4e-132)
                		tmp = Float64(Float64(-phi1) * Float64(phi2 * Float64(R / phi2)));
                	else
                		tmp = fma(Float64(-R), phi1, Float64(R * 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, 3.4e-132], N[((-phi1) * N[(phi2 * N[(R / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision]]
                
                \begin{array}{l}
                [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                \\
                \begin{array}{l}
                \mathbf{if}\;\phi_2 \leq 3.4 \cdot 10^{-132}:\\
                \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \frac{R}{\phi_2}\right)\\
                
                \mathbf{else}:\\
                \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if phi2 < 3.39999999999999983e-132

                  1. Initial program 65.1%

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

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

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

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

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

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

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

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

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

                      \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right) \]
                    10. lower-*.f6419.6

                      \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right) \]
                  5. Applied rewrites19.6%

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

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

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

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

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

                      \[\leadsto \left(-\phi_1\right) \cdot \left(\phi_2 \cdot \mathsf{fma}\left(-1, \frac{R}{\phi_1}, \frac{R}{\phi_2}\right)\right) \]
                  8. Applied rewrites19.5%

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

                    \[\leadsto \left(-\phi_1\right) \cdot \left(\phi_2 \cdot \frac{R}{\phi_2}\right) \]
                  10. Step-by-step derivation
                    1. lift-/.f6424.6

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

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

                  if 3.39999999999999983e-132 < phi2

                  1. Initial program 47.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 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 \left(-1 \cdot \phi_1\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                    2. mul-1-negN/A

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

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

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

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

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

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

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

                      \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right) \]
                    10. lower-*.f6443.4

                      \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right) \]
                  5. Applied rewrites43.4%

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                    5. lower-*.f6448.1

                      \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                  11. Applied rewrites48.1%

                    \[\leadsto \mathsf{fma}\left(-R, \color{blue}{\phi_1}, R \cdot \phi_2\right) \]
                3. Recombined 2 regimes into one program.
                4. Final simplification33.6%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 3.4 \cdot 10^{-132}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \frac{R}{\phi_2}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \end{array} \]
                5. Add Preprocessing

                Alternative 14: 57.4% accurate, 13.9× speedup?

                \[\begin{array}{l} [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\ \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq -1.02 \cdot 10^{+15}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \end{array} \end{array} \]
                NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
                (FPCore (R lambda1 lambda2 phi1 phi2)
                 :precision binary64
                 (if (<= phi2 -1.02e+15) (* R (- phi1)) (fma (- R) phi1 (* R phi2))))
                assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
                double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                	double tmp;
                	if (phi2 <= -1.02e+15) {
                		tmp = R * -phi1;
                	} else {
                		tmp = fma(-R, phi1, (R * phi2));
                	}
                	return tmp;
                }
                
                R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2])
                function code(R, lambda1, lambda2, phi1, phi2)
                	tmp = 0.0
                	if (phi2 <= -1.02e+15)
                		tmp = Float64(R * Float64(-phi1));
                	else
                		tmp = fma(Float64(-R), phi1, Float64(R * 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, -1.02e+15], N[(R * (-phi1)), $MachinePrecision], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision]]
                
                \begin{array}{l}
                [R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
                \\
                \begin{array}{l}
                \mathbf{if}\;\phi_2 \leq -1.02 \cdot 10^{+15}:\\
                \;\;\;\;R \cdot \left(-\phi_1\right)\\
                
                \mathbf{else}:\\
                \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if phi2 < -1.02e15

                  1. Initial program 55.1%

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

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

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

                      \[\leadsto R \cdot \left(-\phi_1\right) \]
                  5. Applied rewrites21.8%

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

                  if -1.02e15 < phi2

                  1. Initial program 59.3%

                    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
                  2. Add Preprocessing
                  3. Taylor expanded in phi1 around -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 \left(-1 \cdot \phi_1\right) \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
                    2. mul-1-negN/A

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

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

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

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

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

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

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

                      \[\leadsto \left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right) \]
                    10. lower-*.f6433.2

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

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                    5. lower-*.f6435.0

                      \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                  11. Applied rewrites35.0%

                    \[\leadsto \mathsf{fma}\left(-R, \color{blue}{\phi_1}, R \cdot \phi_2\right) \]
                3. Recombined 2 regimes into one program.
                4. Final simplification32.4%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -1.02 \cdot 10^{+15}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \end{array} \]
                5. Add Preprocessing

                Alternative 15: 51.8% 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 -3.4 \cdot 10^{-47}:\\ \;\;\;\;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 -3.4e-47) (* 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 <= -3.4e-47) {
                		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 <= (-3.4d-47)) 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 <= -3.4e-47) {
                		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 <= -3.4e-47:
                		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 <= -3.4e-47)
                		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 <= -3.4e-47)
                		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, -3.4e-47], 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 -3.4 \cdot 10^{-47}:\\
                \;\;\;\;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 < -3.4000000000000002e-47

                  1. Initial program 50.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 \phi_1\right)} \]
                  4. Step-by-step derivation
                    1. mul-1-negN/A

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

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

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

                  if -3.4000000000000002e-47 < phi1

                  1. Initial program 62.1%

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

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

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

                  Alternative 16: 31.3% accurate, 46.5× speedup?

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

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

                    Reproduce

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