Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.5% → 95.8%
Time: 6.0s
Alternatives: 13
Speedup: 1.2×

Specification

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

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

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 13 alternatives:

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

Initial Program: 59.5% accurate, 1.0× speedup?

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

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

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

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

Alternative 1: 95.8% accurate, 1.2× 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 62.9%

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

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

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

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

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

Alternative 2: 76.1% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 0.94:\\ \;\;\;\;\mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \cdot R\\ \mathbf{elif}\;\phi_2 \leq 6.8 \cdot 10^{+38}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi2 0.94)
   (* (hypot (* (cos (* 0.5 phi1)) (- lambda1 lambda2)) phi1) R)
   (if (<= phi2 6.8e+38)
     (* (hypot phi1 (* (cos (* 0.5 phi2)) (- lambda1 lambda2))) R)
     (* R (- phi2 phi1)))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 0.94) {
		tmp = hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R;
	} else if (phi2 <= 6.8e+38) {
		tmp = hypot(phi1, (cos((0.5 * phi2)) * (lambda1 - lambda2))) * R;
	} else {
		tmp = R * (phi2 - phi1);
	}
	return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 0.94) {
		tmp = Math.hypot((Math.cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R;
	} else if (phi2 <= 6.8e+38) {
		tmp = Math.hypot(phi1, (Math.cos((0.5 * phi2)) * (lambda1 - lambda2))) * R;
	} else {
		tmp = R * (phi2 - phi1);
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 0.94:
		tmp = math.hypot((math.cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R
	elif phi2 <= 6.8e+38:
		tmp = math.hypot(phi1, (math.cos((0.5 * phi2)) * (lambda1 - lambda2))) * R
	else:
		tmp = R * (phi2 - phi1)
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 0.94)
		tmp = Float64(hypot(Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2)), phi1) * R);
	elseif (phi2 <= 6.8e+38)
		tmp = Float64(hypot(phi1, Float64(cos(Float64(0.5 * phi2)) * Float64(lambda1 - lambda2))) * R);
	else
		tmp = Float64(R * Float64(phi2 - phi1));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi2 <= 0.94)
		tmp = hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R;
	elseif (phi2 <= 6.8e+38)
		tmp = hypot(phi1, (cos((0.5 * phi2)) * (lambda1 - lambda2))) * R;
	else
		tmp = R * (phi2 - phi1);
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 0.94], N[(N[Sqrt[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi2, 6.8e+38], N[(N[Sqrt[phi1 ^ 2 + N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{hypot}\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \cdot R \]
      8. lift--.f6482.5

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

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

    if 0.93999999999999995 < phi2 < 6.79999999999999992e38

    1. Initial program 74.9%

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{hypot}\left(\color{blue}{\phi_1}, \cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
    9. Step-by-step derivation
      1. Applied rewrites64.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.79999999999999992e38 < 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. Add Preprocessing
      3. Taylor expanded in phi1 around -inf

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \phi_1\right) \]
        3. lower-*.f6470.3

          \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \phi_1\right) \]
      11. Applied rewrites70.3%

        \[\leadsto R \cdot \left(\phi_2 + \color{blue}{-1 \cdot \phi_1}\right) \]
    10. Recombined 3 regimes into one program.
    11. Final simplification79.0%

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

    Alternative 3: 82.2% accurate, 1.2× speedup?

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

      1. Initial program 63.7%

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \mathsf{hypot}\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \cdot R \]
        8. lift--.f6483.9

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

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

      if 7.19999999999999982e-47 < phi2

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

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

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

          \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
      4. Applied 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} \]
      5. Taylor expanded in phi1 around 0

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

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

        \[\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. Final simplification86.7%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 7.2 \cdot 10^{-47}:\\ \;\;\;\;\mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\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} \]
    5. Add Preprocessing

    Alternative 4: 78.0% accurate, 1.2× speedup?

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

      1. Initial program 63.9%

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \mathsf{hypot}\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \cdot R \]
        8. lift--.f6484.0

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

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

      if 1.1e-46 < phi2

      1. Initial program 60.6%

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

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

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

          \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
      4. Applied 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} \]
      5. Taylor expanded in phi1 around 0

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

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

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

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

          \[\leadsto \mathsf{hypot}\left(\mathsf{neg}\left(\phi_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
        2. lower-neg.f6480.3

          \[\leadsto \mathsf{hypot}\left(-\phi_2, \cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      10. Applied rewrites80.3%

        \[\leadsto \mathsf{hypot}\left(\color{blue}{-\phi_2}, \cos \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. Final simplification82.9%

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

    Alternative 5: 75.5% accurate, 1.2× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 8.6 \cdot 10^{+36}:\\ \;\;\;\;\mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \end{array} \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (<= phi2 8.6e+36)
       (* (hypot (* (cos (* 0.5 phi1)) (- lambda1 lambda2)) phi1) R)
       (* R (- phi2 phi1))))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi2 <= 8.6e+36) {
    		tmp = hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R;
    	} else {
    		tmp = R * (phi2 - phi1);
    	}
    	return tmp;
    }
    
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi2 <= 8.6e+36) {
    		tmp = Math.hypot((Math.cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R;
    	} else {
    		tmp = R * (phi2 - phi1);
    	}
    	return tmp;
    }
    
    def code(R, lambda1, lambda2, phi1, phi2):
    	tmp = 0
    	if phi2 <= 8.6e+36:
    		tmp = math.hypot((math.cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R
    	else:
    		tmp = R * (phi2 - phi1)
    	return tmp
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (phi2 <= 8.6e+36)
    		tmp = Float64(hypot(Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2)), phi1) * R);
    	else
    		tmp = Float64(R * Float64(phi2 - phi1));
    	end
    	return tmp
    end
    
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0;
    	if (phi2 <= 8.6e+36)
    		tmp = hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R;
    	else
    		tmp = R * (phi2 - phi1);
    	end
    	tmp_2 = tmp;
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 8.6e+36], N[(N[Sqrt[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\phi_2 \leq 8.6 \cdot 10^{+36}:\\
    \;\;\;\;\mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if phi2 < 8.6000000000000001e36

      1. Initial program 65.1%

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \mathsf{hypot}\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \cdot R \]
        8. lift--.f6480.7

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

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

      if 8.6000000000000001e36 < phi2

      1. Initial program 54.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{R \cdot \phi_2} \]
      7. 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.5

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

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

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

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

          \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \phi_1\right) \]
        3. lower-*.f6469.7

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

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

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

    Alternative 6: 41.1% accurate, 5.9× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;R \leq 5 \cdot 10^{+67}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right) + \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
     (if (<= R 5e+67)
       (* R (- phi2 phi1))
       (*
        R
        (sqrt
         (+
          (* (- lambda1 lambda2) (- lambda1 lambda2))
          (* (- phi1 phi2) (- phi1 phi2)))))))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (R <= 5e+67) {
    		tmp = R * (phi2 - phi1);
    	} else {
    		tmp = R * sqrt((((lambda1 - lambda2) * (lambda1 - lambda2)) + ((phi1 - phi2) * (phi1 - 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 (r <= 5d+67) then
            tmp = r * (phi2 - phi1)
        else
            tmp = r * sqrt((((lambda1 - lambda2) * (lambda1 - lambda2)) + ((phi1 - phi2) * (phi1 - phi2))))
        end if
        code = tmp
    end function
    
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (R <= 5e+67) {
    		tmp = R * (phi2 - phi1);
    	} else {
    		tmp = R * Math.sqrt((((lambda1 - lambda2) * (lambda1 - lambda2)) + ((phi1 - phi2) * (phi1 - phi2))));
    	}
    	return tmp;
    }
    
    def code(R, lambda1, lambda2, phi1, phi2):
    	tmp = 0
    	if R <= 5e+67:
    		tmp = R * (phi2 - phi1)
    	else:
    		tmp = R * math.sqrt((((lambda1 - lambda2) * (lambda1 - lambda2)) + ((phi1 - phi2) * (phi1 - phi2))))
    	return tmp
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (R <= 5e+67)
    		tmp = Float64(R * Float64(phi2 - phi1));
    	else
    		tmp = Float64(R * sqrt(Float64(Float64(Float64(lambda1 - lambda2) * Float64(lambda1 - lambda2)) + Float64(Float64(phi1 - phi2) * Float64(phi1 - phi2)))));
    	end
    	return tmp
    end
    
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0;
    	if (R <= 5e+67)
    		tmp = R * (phi2 - phi1);
    	else
    		tmp = R * sqrt((((lambda1 - lambda2) * (lambda1 - lambda2)) + ((phi1 - phi2) * (phi1 - phi2))));
    	end
    	tmp_2 = tmp;
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[R, 5e+67], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] + N[(N[(phi1 - phi2), $MachinePrecision] * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;R \leq 5 \cdot 10^{+67}:\\
    \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if R < 4.99999999999999976e67

      1. Initial program 55.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{R \cdot \phi_2} \]
      7. 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-*.f6430.6

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

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

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

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

          \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \phi_1\right) \]
        3. lower-*.f6430.6

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

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

      if 4.99999999999999976e67 < R

      1. Initial program 94.4%

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

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

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

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

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

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

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

          \[\leadsto R \cdot \sqrt{{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      5. Applied rewrites92.7%

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

        \[\leadsto R \cdot \sqrt{{\left(\lambda_1 - \lambda_2\right)}^{2} + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      7. Step-by-step derivation
        1. lift--.f6492.7

          \[\leadsto R \cdot \sqrt{{\left(\lambda_1 - \lambda_2\right)}^{2} + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      8. Applied rewrites92.7%

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

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

          \[\leadsto R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\lambda_1 - \lambda_2\right)} + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        3. lower-*.f6492.7

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;R \leq 5 \cdot 10^{+67}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\\ \end{array} \]
    5. Add Preprocessing

    Alternative 7: 30.0% accurate, 5.9× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -2.3 \cdot 10^{+107}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \mathsf{fma}\left(-1, \frac{R}{\phi_1}, \frac{R}{\phi_2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \end{array} \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (<= lambda1 -2.3e+107)
       (* (- phi1) (* phi2 (fma -1.0 (/ R phi1) (/ R phi2))))
       (* R (- phi2 phi1))))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (lambda1 <= -2.3e+107) {
    		tmp = -phi1 * (phi2 * fma(-1.0, (R / phi1), (R / phi2)));
    	} else {
    		tmp = R * (phi2 - phi1);
    	}
    	return tmp;
    }
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (lambda1 <= -2.3e+107)
    		tmp = Float64(Float64(-phi1) * Float64(phi2 * fma(-1.0, Float64(R / phi1), Float64(R / phi2))));
    	else
    		tmp = Float64(R * Float64(phi2 - phi1));
    	end
    	return tmp
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda1, -2.3e+107], N[((-phi1) * N[(phi2 * N[(-1.0 * N[(R / phi1), $MachinePrecision] + N[(R / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\lambda_1 \leq -2.3 \cdot 10^{+107}:\\
    \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \mathsf{fma}\left(-1, \frac{R}{\phi_1}, \frac{R}{\phi_2}\right)\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if lambda1 < -2.3e107

      1. Initial program 67.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -2.3e107 < lambda1

      1. Initial program 62.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{R \cdot \phi_2} \]
      7. 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-*.f6435.6

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

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

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

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

          \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \phi_1\right) \]
        3. lower-*.f6435.6

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

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

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

    Alternative 8: 31.8% accurate, 6.6× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.9 \cdot 10^{-152}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \frac{R}{\phi_2}\right)\\ \mathbf{elif}\;\phi_2 \leq 9.5 \cdot 10^{+36}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \end{array} \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (<= phi2 1.9e-152)
       (* (- phi1) (* phi2 (/ R phi2)))
       (if (<= phi2 9.5e+36)
         (* (- phi1) (fma (/ (* phi2 R) phi1) -1.0 R))
         (* R (- phi2 phi1)))))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi2 <= 1.9e-152) {
    		tmp = -phi1 * (phi2 * (R / phi2));
    	} else if (phi2 <= 9.5e+36) {
    		tmp = -phi1 * fma(((phi2 * R) / phi1), -1.0, R);
    	} else {
    		tmp = R * (phi2 - phi1);
    	}
    	return tmp;
    }
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (phi2 <= 1.9e-152)
    		tmp = Float64(Float64(-phi1) * Float64(phi2 * Float64(R / phi2)));
    	elseif (phi2 <= 9.5e+36)
    		tmp = Float64(Float64(-phi1) * fma(Float64(Float64(phi2 * R) / phi1), -1.0, R));
    	else
    		tmp = Float64(R * Float64(phi2 - phi1));
    	end
    	return tmp
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 1.9e-152], N[((-phi1) * N[(phi2 * N[(R / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 9.5e+36], N[((-phi1) * N[(N[(N[(phi2 * R), $MachinePrecision] / phi1), $MachinePrecision] * -1.0 + R), $MachinePrecision]), $MachinePrecision], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\phi_2 \leq 1.9 \cdot 10^{-152}:\\
    \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \frac{R}{\phi_2}\right)\\
    
    \mathbf{elif}\;\phi_2 \leq 9.5 \cdot 10^{+36}:\\
    \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if phi2 < 1.90000000000000006e-152

      1. Initial program 62.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 1.90000000000000006e-152 < phi2 < 9.49999999999999974e36

      1. Initial program 74.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 9.49999999999999974e36 < phi2

      1. Initial program 54.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{R \cdot \phi_2} \]
      7. 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.5

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

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

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

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

          \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \phi_1\right) \]
        3. lower-*.f6469.7

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

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

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

    Alternative 9: 31.7% accurate, 7.5× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.9 \cdot 10^{-152}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \frac{R}{\phi_2}\right)\\ \mathbf{elif}\;\phi_2 \leq 8.6 \cdot 10^{+36}:\\ \;\;\;\;\mathsf{fma}\left(R, \frac{\phi_2}{\phi_1}, -R\right) \cdot \phi_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \end{array} \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (<= phi2 1.9e-152)
       (* (- phi1) (* phi2 (/ R phi2)))
       (if (<= phi2 8.6e+36)
         (* (fma R (/ phi2 phi1) (- R)) phi1)
         (* R (- phi2 phi1)))))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi2 <= 1.9e-152) {
    		tmp = -phi1 * (phi2 * (R / phi2));
    	} else if (phi2 <= 8.6e+36) {
    		tmp = fma(R, (phi2 / phi1), -R) * phi1;
    	} else {
    		tmp = R * (phi2 - phi1);
    	}
    	return tmp;
    }
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (phi2 <= 1.9e-152)
    		tmp = Float64(Float64(-phi1) * Float64(phi2 * Float64(R / phi2)));
    	elseif (phi2 <= 8.6e+36)
    		tmp = Float64(fma(R, Float64(phi2 / phi1), Float64(-R)) * phi1);
    	else
    		tmp = Float64(R * Float64(phi2 - phi1));
    	end
    	return tmp
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 1.9e-152], N[((-phi1) * N[(phi2 * N[(R / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 8.6e+36], N[(N[(R * N[(phi2 / phi1), $MachinePrecision] + (-R)), $MachinePrecision] * phi1), $MachinePrecision], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\phi_2 \leq 1.9 \cdot 10^{-152}:\\
    \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \frac{R}{\phi_2}\right)\\
    
    \mathbf{elif}\;\phi_2 \leq 8.6 \cdot 10^{+36}:\\
    \;\;\;\;\mathsf{fma}\left(R, \frac{\phi_2}{\phi_1}, -R\right) \cdot \phi_1\\
    
    \mathbf{else}:\\
    \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if phi2 < 1.90000000000000006e-152

      1. Initial program 62.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 1.90000000000000006e-152 < phi2 < 8.6000000000000001e36

      1. Initial program 74.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 8.6000000000000001e36 < phi2

      1. Initial program 54.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{R \cdot \phi_2} \]
      7. 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.5

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

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

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

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

          \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \phi_1\right) \]
        3. lower-*.f6469.7

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

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

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

    Alternative 10: 31.3% accurate, 9.3× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 9 \cdot 10^{-80}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \frac{R}{\phi_2}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \end{array} \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (<= phi2 9e-80) (* (- phi1) (* phi2 (/ R phi2))) (* R (- phi2 phi1))))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi2 <= 9e-80) {
    		tmp = -phi1 * (phi2 * (R / phi2));
    	} else {
    		tmp = R * (phi2 - phi1);
    	}
    	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 (phi2 <= 9d-80) then
            tmp = -phi1 * (phi2 * (r / phi2))
        else
            tmp = r * (phi2 - phi1)
        end if
        code = tmp
    end function
    
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi2 <= 9e-80) {
    		tmp = -phi1 * (phi2 * (R / phi2));
    	} else {
    		tmp = R * (phi2 - phi1);
    	}
    	return tmp;
    }
    
    def code(R, lambda1, lambda2, phi1, phi2):
    	tmp = 0
    	if phi2 <= 9e-80:
    		tmp = -phi1 * (phi2 * (R / phi2))
    	else:
    		tmp = R * (phi2 - phi1)
    	return tmp
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (phi2 <= 9e-80)
    		tmp = Float64(Float64(-phi1) * Float64(phi2 * Float64(R / phi2)));
    	else
    		tmp = Float64(R * Float64(phi2 - phi1));
    	end
    	return tmp
    end
    
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0;
    	if (phi2 <= 9e-80)
    		tmp = -phi1 * (phi2 * (R / phi2));
    	else
    		tmp = R * (phi2 - phi1);
    	end
    	tmp_2 = tmp;
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 9e-80], N[((-phi1) * N[(phi2 * N[(R / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\phi_2 \leq 9 \cdot 10^{-80}:\\
    \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \frac{R}{\phi_2}\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if phi2 < 9.0000000000000006e-80

      1. Initial program 64.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 9.0000000000000006e-80 < phi2

      1. Initial program 60.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{R \cdot \phi_2} \]
      7. 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-*.f6458.1

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

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

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

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

          \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \phi_1\right) \]
        3. lower-*.f6457.0

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

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

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

    Alternative 11: 28.5% accurate, 19.9× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.1 \cdot 10^{-46}:\\ \;\;\;\;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 (<= phi2 1.1e-46) (* R (- phi1)) (* R phi2)))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi2 <= 1.1e-46) {
    		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 (phi2 <= 1.1d-46) 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 (phi2 <= 1.1e-46) {
    		tmp = R * -phi1;
    	} else {
    		tmp = R * phi2;
    	}
    	return tmp;
    }
    
    def code(R, lambda1, lambda2, phi1, phi2):
    	tmp = 0
    	if phi2 <= 1.1e-46:
    		tmp = R * -phi1
    	else:
    		tmp = R * phi2
    	return tmp
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (phi2 <= 1.1e-46)
    		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 (phi2 <= 1.1e-46)
    		tmp = R * -phi1;
    	else
    		tmp = R * phi2;
    	end
    	tmp_2 = tmp;
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 1.1e-46], N[(R * (-phi1)), $MachinePrecision], N[(R * phi2), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\phi_2 \leq 1.1 \cdot 10^{-46}:\\
    \;\;\;\;R \cdot \left(-\phi_1\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;R \cdot \phi_2\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if phi2 < 1.1e-46

      1. Initial program 63.9%

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

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

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

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

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

      if 1.1e-46 < phi2

      1. Initial program 60.6%

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

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

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

      Alternative 12: 29.8% accurate, 31.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -1 \cdot \left(R \cdot \phi_1\right) + \color{blue}{R \cdot \phi_2} \]
      7. 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-*.f6433.3

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

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

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

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

          \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \phi_1\right) \]
        3. lower-*.f6433.3

          \[\leadsto R \cdot \left(\phi_2 + -1 \cdot \phi_1\right) \]
      11. Applied rewrites33.3%

        \[\leadsto R \cdot \left(\phi_2 + \color{blue}{-1 \cdot \phi_1}\right) \]
      12. Final simplification33.3%

        \[\leadsto R \cdot \left(\phi_2 - \phi_1\right) \]
      13. Add Preprocessing

      Alternative 13: 17.3% accurate, 46.5× 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 62.9%

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

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

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

        Reproduce

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