Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.9% → 96.0%
Time: 6.0s
Alternatives: 17
Speedup: 1.8×

Specification

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

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

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

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

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 17 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.9% 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: 96.0% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \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} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  (hypot (- phi1 phi2) (* (cos (/ (+ phi2 phi1) 2.0)) (- lambda1 lambda2)))
  R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return hypot((phi1 - phi2), (cos(((phi2 + phi1) / 2.0)) * (lambda1 - lambda2))) * R;
}
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;
}
def code(R, lambda1, lambda2, phi1, phi2):
	return math.hypot((phi1 - phi2), (math.cos(((phi2 + phi1) / 2.0)) * (lambda1 - lambda2))) * R
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
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = hypot((phi1 - phi2), (cos(((phi2 + phi1) / 2.0)) * (lambda1 - lambda2))) * R;
end
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}

\\
\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R
\end{array}
Derivation
  1. Initial program 59.9%

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

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

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

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

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

Alternative 2: 92.4% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 8.8 \cdot 10^{-97}:\\ \;\;\;\;\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} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi2 8.8e-97)
   (* (hypot (- phi1 phi2) (* (cos (* 0.5 phi1)) (- lambda1 lambda2))) R)
   (* (hypot (- phi1 phi2) (* (cos (* 0.5 phi2)) (- lambda1 lambda2))) R)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 8.8e-97) {
		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;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 8.8e-97) {
		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;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 8.8e-97:
		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
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 8.8e-97)
		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
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi2 <= 8.8e-97)
		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
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 8.8e-97], 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}

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 8.8 \cdot 10^{-97}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\

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


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

    1. Initial program 60.9%

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

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

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

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

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

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

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

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

    if 8.7999999999999996e-97 < phi2

    1. Initial program 57.8%

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

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

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

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

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

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

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

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

Alternative 3: 90.4% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.2 \cdot 10^{-17}:\\ \;\;\;\;\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} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi2 1.2e-17)
   (* (hypot phi1 (* (cos (* 0.5 phi1)) (- lambda1 lambda2))) R)
   (* (hypot (- phi1 phi2) (* (cos (* 0.5 phi2)) lambda1)) R)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 1.2e-17) {
		tmp = hypot(phi1, (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
	} else {
		tmp = hypot((phi1 - phi2), (cos((0.5 * phi2)) * lambda1)) * R;
	}
	return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 1.2e-17) {
		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;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 1.2e-17:
		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
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 1.2e-17)
		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
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi2 <= 1.2e-17)
		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
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 1.2e-17], 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}

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 1.2 \cdot 10^{-17}:\\
\;\;\;\;\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 < 1.19999999999999993e-17

    1. Initial program 61.6%

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{hypot}\left(\color{blue}{\phi_1}, \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
    8. Step-by-step derivation
      1. Applied rewrites78.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.19999999999999993e-17 < phi2

      1. Initial program 54.9%

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

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

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

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

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

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_2\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      5. Step-by-step derivation
        1. lower-*.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 \]
      6. 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 \]
      7. 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 \]
      8. Step-by-step derivation
        1. Applied rewrites82.6%

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

      Alternative 4: 79.8% accurate, 1.8× speedup?

      \[\begin{array}{l} \\ \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \end{array} \]
      (FPCore (R lambda1 lambda2 phi1 phi2)
       :precision binary64
       (* (hypot (- phi1 phi2) (* (cos (* 0.5 phi1)) (- lambda1 lambda2))) R))
      double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	return hypot((phi1 - phi2), (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
      }
      
      public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	return Math.hypot((phi1 - phi2), (Math.cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
      }
      
      def code(R, lambda1, lambda2, phi1, phi2):
      	return math.hypot((phi1 - phi2), (math.cos((0.5 * phi1)) * (lambda1 - lambda2))) * R
      
      function code(R, lambda1, lambda2, phi1, phi2)
      	return Float64(hypot(Float64(phi1 - phi2), Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2))) * R)
      end
      
      function tmp = code(R, lambda1, lambda2, phi1, phi2)
      	tmp = hypot((phi1 - phi2), (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
      end
      
      code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R
      \end{array}
      
      Derivation
      1. Initial program 59.9%

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

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

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

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

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

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

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

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

      Alternative 5: 79.1% accurate, 1.6× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(0.5 \cdot \phi_1\right)\\ \mathbf{if}\;\phi_2 \leq 5.4 \cdot 10^{-46}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1, t\_0 \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{elif}\;\phi_2 \leq 6.5 \cdot 10^{+39}:\\ \;\;\;\;\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{hypot}\left(\phi_1 - \phi_2, t\_0 \cdot \lambda_1\right) \cdot R\\ \end{array} \end{array} \]
      (FPCore (R lambda1 lambda2 phi1 phi2)
       :precision binary64
       (let* ((t_0 (cos (* 0.5 phi1))))
         (if (<= phi2 5.4e-46)
           (* (hypot phi1 (* t_0 (- lambda1 lambda2))) R)
           (if (<= phi2 6.5e+39)
             (* (hypot phi1 (* (cos (* 0.5 phi2)) (- lambda1 lambda2))) R)
             (* (hypot (- phi1 phi2) (* t_0 lambda1)) R)))))
      double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	double t_0 = cos((0.5 * phi1));
      	double tmp;
      	if (phi2 <= 5.4e-46) {
      		tmp = hypot(phi1, (t_0 * (lambda1 - lambda2))) * R;
      	} else if (phi2 <= 6.5e+39) {
      		tmp = hypot(phi1, (cos((0.5 * phi2)) * (lambda1 - lambda2))) * R;
      	} else {
      		tmp = hypot((phi1 - phi2), (t_0 * lambda1)) * R;
      	}
      	return tmp;
      }
      
      public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	double t_0 = Math.cos((0.5 * phi1));
      	double tmp;
      	if (phi2 <= 5.4e-46) {
      		tmp = Math.hypot(phi1, (t_0 * (lambda1 - lambda2))) * R;
      	} else if (phi2 <= 6.5e+39) {
      		tmp = Math.hypot(phi1, (Math.cos((0.5 * phi2)) * (lambda1 - lambda2))) * R;
      	} else {
      		tmp = Math.hypot((phi1 - phi2), (t_0 * lambda1)) * R;
      	}
      	return tmp;
      }
      
      def code(R, lambda1, lambda2, phi1, phi2):
      	t_0 = math.cos((0.5 * phi1))
      	tmp = 0
      	if phi2 <= 5.4e-46:
      		tmp = math.hypot(phi1, (t_0 * (lambda1 - lambda2))) * R
      	elif phi2 <= 6.5e+39:
      		tmp = math.hypot(phi1, (math.cos((0.5 * phi2)) * (lambda1 - lambda2))) * R
      	else:
      		tmp = math.hypot((phi1 - phi2), (t_0 * lambda1)) * R
      	return tmp
      
      function code(R, lambda1, lambda2, phi1, phi2)
      	t_0 = cos(Float64(0.5 * phi1))
      	tmp = 0.0
      	if (phi2 <= 5.4e-46)
      		tmp = Float64(hypot(phi1, Float64(t_0 * Float64(lambda1 - lambda2))) * R);
      	elseif (phi2 <= 6.5e+39)
      		tmp = Float64(hypot(phi1, Float64(cos(Float64(0.5 * phi2)) * Float64(lambda1 - lambda2))) * R);
      	else
      		tmp = Float64(hypot(Float64(phi1 - phi2), Float64(t_0 * lambda1)) * R);
      	end
      	return tmp
      end
      
      function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
      	t_0 = cos((0.5 * phi1));
      	tmp = 0.0;
      	if (phi2 <= 5.4e-46)
      		tmp = hypot(phi1, (t_0 * (lambda1 - lambda2))) * R;
      	elseif (phi2 <= 6.5e+39)
      		tmp = hypot(phi1, (cos((0.5 * phi2)) * (lambda1 - lambda2))) * R;
      	else
      		tmp = hypot((phi1 - phi2), (t_0 * lambda1)) * R;
      	end
      	tmp_2 = tmp;
      end
      
      code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, 5.4e-46], N[(N[Sqrt[phi1 ^ 2 + N[(t$95$0 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi2, 6.5e+39], N[(N[Sqrt[phi1 ^ 2 + N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * 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}
      
      \\
      \begin{array}{l}
      t_0 := \cos \left(0.5 \cdot \phi_1\right)\\
      \mathbf{if}\;\phi_2 \leq 5.4 \cdot 10^{-46}:\\
      \;\;\;\;\mathsf{hypot}\left(\phi_1, t\_0 \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
      
      \mathbf{elif}\;\phi_2 \leq 6.5 \cdot 10^{+39}:\\
      \;\;\;\;\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{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 < 5.4e-46

        1. Initial program 61.1%

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

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

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

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

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

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

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

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

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

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

          if 5.4e-46 < phi2 < 6.5000000000000001e39

          1. Initial program 67.1%

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

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

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

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

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

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

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

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

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

              \[\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 6.5000000000000001e39 < phi2

            1. Initial program 53.1%

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

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

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

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

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

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

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

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

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

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

            Alternative 6: 76.9% accurate, 1.6× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 5.4 \cdot 10^{-46}:\\ \;\;\;\;\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.04 \cdot 10^{+40}:\\ \;\;\;\;\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} \]
            (FPCore (R lambda1 lambda2 phi1 phi2)
             :precision binary64
             (if (<= phi2 5.4e-46)
               (* (hypot phi1 (* (cos (* 0.5 phi1)) (- lambda1 lambda2))) R)
               (if (<= phi2 1.04e+40)
                 (* (hypot phi1 (* (cos (* 0.5 phi2)) (- lambda1 lambda2))) R)
                 (fma (- R) phi1 (* R phi2)))))
            double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
            	double tmp;
            	if (phi2 <= 5.4e-46) {
            		tmp = hypot(phi1, (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
            	} else if (phi2 <= 1.04e+40) {
            		tmp = hypot(phi1, (cos((0.5 * phi2)) * (lambda1 - lambda2))) * R;
            	} else {
            		tmp = fma(-R, phi1, (R * phi2));
            	}
            	return tmp;
            }
            
            function code(R, lambda1, lambda2, phi1, phi2)
            	tmp = 0.0
            	if (phi2 <= 5.4e-46)
            		tmp = Float64(hypot(phi1, Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2))) * R);
            	elseif (phi2 <= 1.04e+40)
            		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
            
            code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 5.4e-46], 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.04e+40], 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}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;\phi_2 \leq 5.4 \cdot 10^{-46}:\\
            \;\;\;\;\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.04 \cdot 10^{+40}:\\
            \;\;\;\;\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 < 5.4e-46

              1. Initial program 61.1%

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

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

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

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

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

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

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

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

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

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

                if 5.4e-46 < phi2 < 1.04e40

                1. Initial program 67.1%

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

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

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

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

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

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

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

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

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

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

                  if 1.04e40 < phi2

                  1. Initial program 53.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \mathsf{fma}\left(-1 \cdot R, \phi_1, R \cdot \phi_2\right) \]
                    3. mul-1-negN/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-*.f6471.3

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

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

                Alternative 7: 76.4% accurate, 1.7× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 2.05 \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{else}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \end{array} \end{array} \]
                (FPCore (R lambda1 lambda2 phi1 phi2)
                 :precision binary64
                 (if (<= phi2 2.05e+38)
                   (* (hypot phi1 (* (cos (* 0.5 phi1)) (- lambda1 lambda2))) R)
                   (fma (- R) phi1 (* R phi2))))
                double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                	double tmp;
                	if (phi2 <= 2.05e+38) {
                		tmp = hypot(phi1, (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
                	} else {
                		tmp = fma(-R, phi1, (R * phi2));
                	}
                	return tmp;
                }
                
                function code(R, lambda1, lambda2, phi1, phi2)
                	tmp = 0.0
                	if (phi2 <= 2.05e+38)
                		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
                
                code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 2.05e+38], 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}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;\phi_2 \leq 2.05 \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{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.0500000000000002e38

                  1. Initial program 61.7%

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

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

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

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

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

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

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

                    \[\leadsto \mathsf{hypot}\left(\color{blue}{\phi_1}, \cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
                  8. Step-by-step derivation
                    1. Applied rewrites77.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 2.0500000000000002e38 < phi2

                    1. Initial program 53.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \mathsf{fma}\left(-1 \cdot R, \phi_1, R \cdot \phi_2\right) \]
                      3. mul-1-negN/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-*.f6471.0

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

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

                  Alternative 8: 34.3% accurate, 1.9× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{0.5 + 0.5 \cdot \cos \left(\phi_1 + \phi_2\right)}\\ \mathbf{if}\;\lambda_1 \leq -4.4 \cdot 10^{+151}:\\ \;\;\;\;-1 \cdot \left(\left(R \cdot \lambda_1\right) \cdot t\_0\right)\\ \mathbf{elif}\;\lambda_1 \leq 5.2 \cdot 10^{-38}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;\left(R \cdot \lambda_2\right) \cdot t\_0\\ \end{array} \end{array} \]
                  (FPCore (R lambda1 lambda2 phi1 phi2)
                   :precision binary64
                   (let* ((t_0 (sqrt (+ 0.5 (* 0.5 (cos (+ phi1 phi2)))))))
                     (if (<= lambda1 -4.4e+151)
                       (* -1.0 (* (* R lambda1) t_0))
                       (if (<= lambda1 5.2e-38)
                         (fma (- R) phi1 (* R phi2))
                         (* (* R lambda2) t_0)))))
                  double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                  	double t_0 = sqrt((0.5 + (0.5 * cos((phi1 + phi2)))));
                  	double tmp;
                  	if (lambda1 <= -4.4e+151) {
                  		tmp = -1.0 * ((R * lambda1) * t_0);
                  	} else if (lambda1 <= 5.2e-38) {
                  		tmp = fma(-R, phi1, (R * phi2));
                  	} else {
                  		tmp = (R * lambda2) * t_0;
                  	}
                  	return tmp;
                  }
                  
                  function code(R, lambda1, lambda2, phi1, phi2)
                  	t_0 = sqrt(Float64(0.5 + Float64(0.5 * cos(Float64(phi1 + phi2)))))
                  	tmp = 0.0
                  	if (lambda1 <= -4.4e+151)
                  		tmp = Float64(-1.0 * Float64(Float64(R * lambda1) * t_0));
                  	elseif (lambda1 <= 5.2e-38)
                  		tmp = fma(Float64(-R), phi1, Float64(R * phi2));
                  	else
                  		tmp = Float64(Float64(R * lambda2) * t_0);
                  	end
                  	return tmp
                  end
                  
                  code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sqrt[N[(0.5 + N[(0.5 * N[Cos[N[(phi1 + phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[lambda1, -4.4e+151], N[(-1.0 * N[(N[(R * lambda1), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda1, 5.2e-38], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision], N[(N[(R * lambda2), $MachinePrecision] * t$95$0), $MachinePrecision]]]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  t_0 := \sqrt{0.5 + 0.5 \cdot \cos \left(\phi_1 + \phi_2\right)}\\
                  \mathbf{if}\;\lambda_1 \leq -4.4 \cdot 10^{+151}:\\
                  \;\;\;\;-1 \cdot \left(\left(R \cdot \lambda_1\right) \cdot t\_0\right)\\
                  
                  \mathbf{elif}\;\lambda_1 \leq 5.2 \cdot 10^{-38}:\\
                  \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\left(R \cdot \lambda_2\right) \cdot t\_0\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 3 regimes
                  2. if lambda1 < -4.40000000000000013e151

                    1. Initial program 43.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. Applied rewrites43.5%

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

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

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

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

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

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

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

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

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

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

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

                    if -4.40000000000000013e151 < lambda1 < 5.20000000000000022e-38

                    1. Initial program 64.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \mathsf{fma}\left(-1 \cdot R, \phi_1, R \cdot \phi_2\right) \]
                      3. mul-1-negN/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-*.f6434.1

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

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

                    if 5.20000000000000022e-38 < lambda1

                    1. Initial program 57.1%

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

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

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

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

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

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

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

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

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

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

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

                  Alternative 9: 33.6% accurate, 1.9× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\lambda_2 \leq -1.5 \cdot 10^{-25}:\\ \;\;\;\;-\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \lambda_1\right) \cdot R\\ \mathbf{elif}\;\lambda_2 \leq 1.7 \cdot 10^{+119}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;\left(R \cdot \lambda_2\right) \cdot \sqrt{0.5 + 0.5 \cdot \cos \left(\phi_1 + \phi_2\right)}\\ \end{array} \end{array} \]
                  (FPCore (R lambda1 lambda2 phi1 phi2)
                   :precision binary64
                   (if (<= lambda2 -1.5e-25)
                     (- (* (* (cos (* 0.5 (+ phi2 phi1))) lambda1) R))
                     (if (<= lambda2 1.7e+119)
                       (fma (- R) phi1 (* R phi2))
                       (* (* R lambda2) (sqrt (+ 0.5 (* 0.5 (cos (+ phi1 phi2)))))))))
                  double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                  	double tmp;
                  	if (lambda2 <= -1.5e-25) {
                  		tmp = -((cos((0.5 * (phi2 + phi1))) * lambda1) * R);
                  	} else if (lambda2 <= 1.7e+119) {
                  		tmp = fma(-R, phi1, (R * phi2));
                  	} else {
                  		tmp = (R * lambda2) * sqrt((0.5 + (0.5 * cos((phi1 + phi2)))));
                  	}
                  	return tmp;
                  }
                  
                  function code(R, lambda1, lambda2, phi1, phi2)
                  	tmp = 0.0
                  	if (lambda2 <= -1.5e-25)
                  		tmp = Float64(-Float64(Float64(cos(Float64(0.5 * Float64(phi2 + phi1))) * lambda1) * R));
                  	elseif (lambda2 <= 1.7e+119)
                  		tmp = fma(Float64(-R), phi1, Float64(R * phi2));
                  	else
                  		tmp = Float64(Float64(R * lambda2) * sqrt(Float64(0.5 + Float64(0.5 * cos(Float64(phi1 + phi2))))));
                  	end
                  	return tmp
                  end
                  
                  code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda2, -1.5e-25], (-N[(N[(N[Cos[N[(0.5 * N[(phi2 + phi1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * lambda1), $MachinePrecision] * R), $MachinePrecision]), If[LessEqual[lambda2, 1.7e+119], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision], N[(N[(R * lambda2), $MachinePrecision] * N[Sqrt[N[(0.5 + N[(0.5 * N[Cos[N[(phi1 + phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;\lambda_2 \leq -1.5 \cdot 10^{-25}:\\
                  \;\;\;\;-\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \lambda_1\right) \cdot R\\
                  
                  \mathbf{elif}\;\lambda_2 \leq 1.7 \cdot 10^{+119}:\\
                  \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\left(R \cdot \lambda_2\right) \cdot \sqrt{0.5 + 0.5 \cdot \cos \left(\phi_1 + \phi_2\right)}\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 3 regimes
                  2. if lambda2 < -1.4999999999999999e-25

                    1. Initial program 54.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

                    if -1.4999999999999999e-25 < lambda2 < 1.70000000000000007e119

                    1. Initial program 66.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \mathsf{fma}\left(-1 \cdot R, \phi_1, R \cdot \phi_2\right) \]
                      3. mul-1-negN/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-*.f6434.7

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

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

                    if 1.70000000000000007e119 < lambda2

                    1. Initial program 47.0%

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

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

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

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

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

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

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

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

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

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

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

                  Alternative 10: 30.6% accurate, 4.5× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\lambda_1 - \lambda_2 \leq -1 \cdot 10^{+154}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \left(\frac{R}{\phi_2} - \frac{R}{\phi_1}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \end{array} \end{array} \]
                  (FPCore (R lambda1 lambda2 phi1 phi2)
                   :precision binary64
                   (if (<= (- lambda1 lambda2) -1e+154)
                     (* (- phi1) (* phi2 (- (/ R phi2) (/ R phi1))))
                     (fma (- R) phi1 (* R phi2))))
                  double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                  	double tmp;
                  	if ((lambda1 - lambda2) <= -1e+154) {
                  		tmp = -phi1 * (phi2 * ((R / phi2) - (R / phi1)));
                  	} else {
                  		tmp = fma(-R, phi1, (R * phi2));
                  	}
                  	return tmp;
                  }
                  
                  function code(R, lambda1, lambda2, phi1, phi2)
                  	tmp = 0.0
                  	if (Float64(lambda1 - lambda2) <= -1e+154)
                  		tmp = Float64(Float64(-phi1) * Float64(phi2 * Float64(Float64(R / phi2) - Float64(R / phi1))));
                  	else
                  		tmp = fma(Float64(-R), phi1, Float64(R * phi2));
                  	end
                  	return tmp
                  end
                  
                  code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -1e+154], N[((-phi1) * N[(phi2 * N[(N[(R / phi2), $MachinePrecision] - N[(R / phi1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;\lambda_1 - \lambda_2 \leq -1 \cdot 10^{+154}:\\
                  \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \left(\frac{R}{\phi_2} - \frac{R}{\phi_1}\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 (-.f64 lambda1 lambda2) < -1.00000000000000004e154

                    1. Initial program 42.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    if -1.00000000000000004e154 < (-.f64 lambda1 lambda2)

                    1. Initial program 64.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \mathsf{fma}\left(-1 \cdot R, \phi_1, R \cdot \phi_2\right) \]
                      3. mul-1-negN/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.5

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

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

                  Alternative 11: 29.9% accurate, 5.0× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\lambda_1 - \lambda_2 \leq -2.3 \cdot 10^{+129}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(\left(-\phi_2 \cdot \frac{R}{\phi_1}\right) + R\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \end{array} \end{array} \]
                  (FPCore (R lambda1 lambda2 phi1 phi2)
                   :precision binary64
                   (if (<= (- lambda1 lambda2) -2.3e+129)
                     (* (- phi1) (+ (- (* phi2 (/ R phi1))) R))
                     (fma (- R) phi1 (* R phi2))))
                  double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                  	double tmp;
                  	if ((lambda1 - lambda2) <= -2.3e+129) {
                  		tmp = -phi1 * (-(phi2 * (R / phi1)) + R);
                  	} else {
                  		tmp = fma(-R, phi1, (R * phi2));
                  	}
                  	return tmp;
                  }
                  
                  function code(R, lambda1, lambda2, phi1, phi2)
                  	tmp = 0.0
                  	if (Float64(lambda1 - lambda2) <= -2.3e+129)
                  		tmp = Float64(Float64(-phi1) * Float64(Float64(-Float64(phi2 * Float64(R / phi1))) + R));
                  	else
                  		tmp = fma(Float64(-R), phi1, Float64(R * phi2));
                  	end
                  	return tmp
                  end
                  
                  code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -2.3e+129], N[((-phi1) * N[((-N[(phi2 * N[(R / phi1), $MachinePrecision]), $MachinePrecision]) + R), $MachinePrecision]), $MachinePrecision], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;\lambda_1 - \lambda_2 \leq -2.3 \cdot 10^{+129}:\\
                  \;\;\;\;\left(-\phi_1\right) \cdot \left(\left(-\phi_2 \cdot \frac{R}{\phi_1}\right) + R\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 (-.f64 lambda1 lambda2) < -2.2999999999999999e129

                    1. Initial program 45.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \left(-\phi_1\right) \cdot \left(\left(-\phi_2 \cdot \frac{R}{\phi_1}\right) + R\right) \]
                      5. lower-/.f6421.8

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

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

                    if -2.2999999999999999e129 < (-.f64 lambda1 lambda2)

                    1. Initial program 64.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \mathsf{fma}\left(-1 \cdot R, \phi_1, R \cdot \phi_2\right) \]
                      3. mul-1-negN/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.6

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

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

                  Alternative 12: 29.9% accurate, 6.3× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 2.45 \cdot 10^{+38}:\\ \;\;\;\;\mathsf{fma}\left(R, \frac{\phi_2}{\phi_1}, -R\right) \cdot \phi_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \end{array} \end{array} \]
                  (FPCore (R lambda1 lambda2 phi1 phi2)
                   :precision binary64
                   (if (<= phi2 2.45e+38)
                     (* (fma R (/ phi2 phi1) (- R)) phi1)
                     (fma (- R) phi1 (* R phi2))))
                  double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                  	double tmp;
                  	if (phi2 <= 2.45e+38) {
                  		tmp = fma(R, (phi2 / phi1), -R) * phi1;
                  	} else {
                  		tmp = fma(-R, phi1, (R * phi2));
                  	}
                  	return tmp;
                  }
                  
                  function code(R, lambda1, lambda2, phi1, phi2)
                  	tmp = 0.0
                  	if (phi2 <= 2.45e+38)
                  		tmp = Float64(fma(R, Float64(phi2 / phi1), Float64(-R)) * phi1);
                  	else
                  		tmp = fma(Float64(-R), phi1, Float64(R * phi2));
                  	end
                  	return tmp
                  end
                  
                  code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 2.45e+38], N[(N[(R * N[(phi2 / phi1), $MachinePrecision] + (-R)), $MachinePrecision] * phi1), $MachinePrecision], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;\phi_2 \leq 2.45 \cdot 10^{+38}:\\
                  \;\;\;\;\mathsf{fma}\left(R, \frac{\phi_2}{\phi_1}, -R\right) \cdot \phi_1\\
                  
                  \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.45000000000000001e38

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \left(-\phi_2\right) \cdot \left(\left(-R\right) + R \cdot \frac{\phi_1}{\color{blue}{\phi_2}}\right) \]
                      10. lift-/.f6415.9

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

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

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

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

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

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

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

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

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

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

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

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

                    if 2.45000000000000001e38 < phi2

                    1. Initial program 53.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \mathsf{fma}\left(-1 \cdot R, \phi_1, R \cdot \phi_2\right) \]
                      3. mul-1-negN/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-*.f6471.0

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

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

                  Alternative 13: 29.4% accurate, 5.7× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\lambda_1 - \lambda_2 \leq -5.6 \cdot 10^{+284}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \frac{\left(-R\right) \cdot \phi_2}{\phi_1}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \end{array} \end{array} \]
                  (FPCore (R lambda1 lambda2 phi1 phi2)
                   :precision binary64
                   (if (<= (- lambda1 lambda2) -5.6e+284)
                     (* (- phi1) (/ (* (- R) phi2) phi1))
                     (fma (- R) phi1 (* R phi2))))
                  double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                  	double tmp;
                  	if ((lambda1 - lambda2) <= -5.6e+284) {
                  		tmp = -phi1 * ((-R * phi2) / phi1);
                  	} else {
                  		tmp = fma(-R, phi1, (R * phi2));
                  	}
                  	return tmp;
                  }
                  
                  function code(R, lambda1, lambda2, phi1, phi2)
                  	tmp = 0.0
                  	if (Float64(lambda1 - lambda2) <= -5.6e+284)
                  		tmp = Float64(Float64(-phi1) * Float64(Float64(Float64(-R) * phi2) / phi1));
                  	else
                  		tmp = fma(Float64(-R), phi1, Float64(R * phi2));
                  	end
                  	return tmp
                  end
                  
                  code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -5.6e+284], N[((-phi1) * N[(N[((-R) * phi2), $MachinePrecision] / phi1), $MachinePrecision]), $MachinePrecision], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;\lambda_1 - \lambda_2 \leq -5.6 \cdot 10^{+284}:\\
                  \;\;\;\;\left(-\phi_1\right) \cdot \frac{\left(-R\right) \cdot \phi_2}{\phi_1}\\
                  
                  \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 (-.f64 lambda1 lambda2) < -5.59999999999999992e284

                    1. Initial program 52.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \left(-\phi_1\right) \cdot \frac{\left(\mathsf{neg}\left(R\right)\right) \cdot \phi_2}{\phi_1} \]
                      6. lower-neg.f6412.5

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

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

                    if -5.59999999999999992e284 < (-.f64 lambda1 lambda2)

                    1. Initial program 60.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \mathsf{fma}\left(-1 \cdot R, \phi_1, R \cdot \phi_2\right) \]
                      3. mul-1-negN/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-*.f6429.9

                        \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                    7. Applied rewrites29.9%

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

                  Alternative 14: 29.3% accurate, 10.8× speedup?

                  \[\begin{array}{l} \\ \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \end{array} \]
                  (FPCore (R lambda1 lambda2 phi1 phi2)
                   :precision binary64
                   (fma (- R) phi1 (* R phi2)))
                  double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                  	return fma(-R, phi1, (R * phi2));
                  }
                  
                  function code(R, lambda1, lambda2, phi1, phi2)
                  	return fma(Float64(-R), phi1, Float64(R * phi2))
                  end
                  
                  code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision]
                  
                  \begin{array}{l}
                  
                  \\
                  \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)
                  \end{array}
                  
                  Derivation
                  1. Initial program 59.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \mathsf{fma}\left(-1 \cdot R, \phi_1, R \cdot \phi_2\right) \]
                    3. mul-1-negN/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-*.f6429.4

                      \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                  7. Applied rewrites29.4%

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

                  Alternative 15: 28.4% accurate, 12.2× speedup?

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

                    1. Initial program 51.9%

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

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

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

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

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

                    if -1.35e26 < 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. Taylor expanded in phi2 around inf

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

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

                    Alternative 16: 17.7% accurate, 27.0× speedup?

                    \[\begin{array}{l} \\ R \cdot \phi_2 \end{array} \]
                    (FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R phi2))
                    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                    	return R * 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
                        code = r * phi2
                    end function
                    
                    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
                    	return R * phi2;
                    }
                    
                    def code(R, lambda1, lambda2, phi1, phi2):
                    	return R * phi2
                    
                    function code(R, lambda1, lambda2, phi1, phi2)
                    	return Float64(R * phi2)
                    end
                    
                    function tmp = code(R, lambda1, lambda2, phi1, phi2)
                    	tmp = R * phi2;
                    end
                    
                    code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * phi2), $MachinePrecision]
                    
                    \begin{array}{l}
                    
                    \\
                    R \cdot \phi_2
                    \end{array}
                    
                    Derivation
                    1. Initial program 59.9%

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

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

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

                      Alternative 17: 17.4% accurate, 27.0× speedup?

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

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

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

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

                        Reproduce

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