Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.0% → 96.0%
Time: 6.7s
Alternatives: 14
Speedup: 1.8×

Specification

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

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

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

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

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 14 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: 60.0% accurate, 1.0× speedup?

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

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

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

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

Alternative 1: 96.0% accurate, 1.7× speedup?

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

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

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

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

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

      \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
  4. Applied rewrites96.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: 92.9% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 52.2%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. 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 rewrites91.4%

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

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

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

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

    if -4.3000000000000001e-8 < phi1

    1. Initial program 68.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 rewrites98.6%

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

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

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

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

Alternative 3: 90.4% accurate, 1.8× speedup?

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

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

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

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

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

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

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

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

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

Alternative 4: 76.5% accurate, 1.6× speedup?

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

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

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

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


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

    1. Initial program 64.4%

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

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

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

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

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

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

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

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

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

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

      if 4.99999999999999968e-50 < phi2 < 2.29999999999999994e54

      1. Initial program 83.4%

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
      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-*.f6498.4

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

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \color{blue}{\left(0.5 \cdot \phi_2\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      8. Taylor expanded in 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 rewrites83.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 2.29999999999999994e54 < phi2

        1. Initial program 58.0%

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

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

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

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

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

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

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

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

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

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

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

      Alternative 5: 76.1% accurate, 1.7× speedup?

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

        1. Initial program 66.2%

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

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

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

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

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

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

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

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

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

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

          if 2.29999999999999994e54 < phi2

          1. Initial program 58.0%

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

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

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

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

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

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

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

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

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

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

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

        Alternative 6: 54.6% accurate, 4.2× speedup?

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

          1. Initial program 66.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 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} + {\phi_1}^{2}}} \]
          4. Step-by-step derivation
            1. lower-fma.f64N/A

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

              \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right), {\color{blue}{\left(\lambda_1 - \lambda_2\right)}}^{2}, {\phi_1}^{2}\right)} \]
            3. sqr-cos-aN/A

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

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

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

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

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

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

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

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

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

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

              \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot \left(\frac{1}{2} \cdot \phi_1\right)\right), \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 \cdot \phi_1\right)} \]
            14. lower-*.f6454.0

              \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(0.5 \cdot \phi_1\right)\right), \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 \cdot \phi_1\right)} \]
          5. Applied rewrites54.0%

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

            \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(1, \color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 \cdot \phi_1\right)} \]
          7. Step-by-step derivation
            1. Applied rewrites52.9%

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

            if 7.8000000000000002e48 < phi2

            1. Initial program 58.0%

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

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

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

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

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

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

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

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

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

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

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

          Alternative 7: 34.0% accurate, 4.9× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 7.8 \cdot 10^{-213}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \frac{R}{\phi_2}\right)\\ \mathbf{elif}\;\phi_2 \leq 1.7 \cdot 10^{+39}:\\ \;\;\;\;R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)}\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\left(\frac{-\phi_1}{\phi_2} + 1\right) \cdot \phi_2\right)\\ \end{array} \end{array} \]
          (FPCore (R lambda1 lambda2 phi1 phi2)
           :precision binary64
           (if (<= phi2 7.8e-213)
             (* (- phi1) (* phi2 (/ R phi2)))
             (if (<= phi2 1.7e+39)
               (* R (sqrt (* (- lambda1 lambda2) (- lambda1 lambda2))))
               (* R (* (+ (/ (- phi1) phi2) 1.0) phi2)))))
          double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
          	double tmp;
          	if (phi2 <= 7.8e-213) {
          		tmp = -phi1 * (phi2 * (R / phi2));
          	} else if (phi2 <= 1.7e+39) {
          		tmp = R * sqrt(((lambda1 - lambda2) * (lambda1 - lambda2)));
          	} else {
          		tmp = R * (((-phi1 / phi2) + 1.0) * 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 <= 7.8d-213) then
                  tmp = -phi1 * (phi2 * (r / phi2))
              else if (phi2 <= 1.7d+39) then
                  tmp = r * sqrt(((lambda1 - lambda2) * (lambda1 - lambda2)))
              else
                  tmp = r * (((-phi1 / phi2) + 1.0d0) * 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 <= 7.8e-213) {
          		tmp = -phi1 * (phi2 * (R / phi2));
          	} else if (phi2 <= 1.7e+39) {
          		tmp = R * Math.sqrt(((lambda1 - lambda2) * (lambda1 - lambda2)));
          	} else {
          		tmp = R * (((-phi1 / phi2) + 1.0) * phi2);
          	}
          	return tmp;
          }
          
          def code(R, lambda1, lambda2, phi1, phi2):
          	tmp = 0
          	if phi2 <= 7.8e-213:
          		tmp = -phi1 * (phi2 * (R / phi2))
          	elif phi2 <= 1.7e+39:
          		tmp = R * math.sqrt(((lambda1 - lambda2) * (lambda1 - lambda2)))
          	else:
          		tmp = R * (((-phi1 / phi2) + 1.0) * phi2)
          	return tmp
          
          function code(R, lambda1, lambda2, phi1, phi2)
          	tmp = 0.0
          	if (phi2 <= 7.8e-213)
          		tmp = Float64(Float64(-phi1) * Float64(phi2 * Float64(R / phi2)));
          	elseif (phi2 <= 1.7e+39)
          		tmp = Float64(R * sqrt(Float64(Float64(lambda1 - lambda2) * Float64(lambda1 - lambda2))));
          	else
          		tmp = Float64(R * Float64(Float64(Float64(Float64(-phi1) / phi2) + 1.0) * phi2));
          	end
          	return tmp
          end
          
          function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
          	tmp = 0.0;
          	if (phi2 <= 7.8e-213)
          		tmp = -phi1 * (phi2 * (R / phi2));
          	elseif (phi2 <= 1.7e+39)
          		tmp = R * sqrt(((lambda1 - lambda2) * (lambda1 - lambda2)));
          	else
          		tmp = R * (((-phi1 / phi2) + 1.0) * phi2);
          	end
          	tmp_2 = tmp;
          end
          
          code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 7.8e-213], N[((-phi1) * N[(phi2 * N[(R / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 1.7e+39], N[(R * N[Sqrt[N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(N[(N[((-phi1) / phi2), $MachinePrecision] + 1.0), $MachinePrecision] * phi2), $MachinePrecision]), $MachinePrecision]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;\phi_2 \leq 7.8 \cdot 10^{-213}:\\
          \;\;\;\;\left(-\phi_1\right) \cdot \left(\phi_2 \cdot \frac{R}{\phi_2}\right)\\
          
          \mathbf{elif}\;\phi_2 \leq 1.7 \cdot 10^{+39}:\\
          \;\;\;\;R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)}\\
          
          \mathbf{else}:\\
          \;\;\;\;R \cdot \left(\left(\frac{-\phi_1}{\phi_2} + 1\right) \cdot \phi_2\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 3 regimes
          2. if phi2 < 7.79999999999999977e-213

            1. Initial program 65.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if 7.79999999999999977e-213 < phi2 < 1.6999999999999999e39

            1. Initial program 68.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} + {\phi_1}^{2}}} \]
            4. Step-by-step derivation
              1. lower-fma.f64N/A

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

                \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right), {\color{blue}{\left(\lambda_1 - \lambda_2\right)}}^{2}, {\phi_1}^{2}\right)} \]
              3. sqr-cos-aN/A

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

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

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

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

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

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

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

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

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

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

                \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot \left(\frac{1}{2} \cdot \phi_1\right)\right), \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 \cdot \phi_1\right)} \]
              14. lower-*.f6459.8

                \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(0.5 \cdot \phi_1\right)\right), \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 \cdot \phi_1\right)} \]
            5. Applied rewrites59.8%

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

              \[\leadsto R \cdot \sqrt{{\left(\lambda_1 - \lambda_2\right)}^{\color{blue}{2}}} \]
            7. Step-by-step derivation
              1. pow2N/A

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

                \[\leadsto R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)} \]
              3. lift--.f64N/A

                \[\leadsto R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)} \]
              4. lift-*.f6442.1

                \[\leadsto R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \color{blue}{\lambda_2}\right)} \]
            8. Applied rewrites42.1%

              \[\leadsto R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\lambda_1 - \lambda_2\right)}} \]

            if 1.6999999999999999e39 < phi2

            1. Initial program 59.5%

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

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

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

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

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

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

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

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

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

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

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

          Alternative 8: 33.5% accurate, 5.0× speedup?

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

            1. Initial program 65.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if 7.79999999999999977e-213 < phi2 < 1.6999999999999999e39

            1. Initial program 68.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} + {\phi_1}^{2}}} \]
            4. Step-by-step derivation
              1. lower-fma.f64N/A

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

                \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right), {\color{blue}{\left(\lambda_1 - \lambda_2\right)}}^{2}, {\phi_1}^{2}\right)} \]
              3. sqr-cos-aN/A

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

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

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

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

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

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

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

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

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

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

                \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot \left(\frac{1}{2} \cdot \phi_1\right)\right), \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 \cdot \phi_1\right)} \]
              14. lower-*.f6459.8

                \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(0.5 \cdot \phi_1\right)\right), \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 \cdot \phi_1\right)} \]
            5. Applied rewrites59.8%

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

              \[\leadsto R \cdot \sqrt{{\left(\lambda_1 - \lambda_2\right)}^{\color{blue}{2}}} \]
            7. Step-by-step derivation
              1. pow2N/A

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

                \[\leadsto R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)} \]
              3. lift--.f64N/A

                \[\leadsto R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)} \]
              4. lift-*.f6442.1

                \[\leadsto R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \color{blue}{\lambda_2}\right)} \]
            8. Applied rewrites42.1%

              \[\leadsto R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\lambda_1 - \lambda_2\right)}} \]

            if 1.6999999999999999e39 < phi2

            1. Initial program 59.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          Alternative 9: 30.9% accurate, 5.0× speedup?

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

            1. Initial program 64.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if 3.8e-200 < phi2 < 8.59999999999999957e48

            1. Initial program 72.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if 8.59999999999999957e48 < phi2

            1. Initial program 58.0%

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

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

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

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

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

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

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

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

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

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

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

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

          Alternative 10: 30.2% accurate, 6.8× speedup?

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

            1. Initial program 64.4%

              \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
            2. Add Preprocessing
            3. 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. lower-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \left(-\phi_1\right) \cdot \left(\phi_2 \cdot \color{blue}{\left(\frac{R}{\phi_2} - \frac{R}{\phi_1}\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-/.f6423.8

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

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

            if 1.99999999999999987e-49 < phi2

            1. Initial program 64.4%

              \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
            2. Add Preprocessing
            3. 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. lower-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

          Alternative 11: 29.5% accurate, 6.6× speedup?

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

            1. Initial program 55.7%

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

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

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

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

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

            if -4.1999999999999999e-24 < phi1 < -4.40000000000000008e-113

            1. Initial program 82.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 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} + {\phi_1}^{2}}} \]
            4. Step-by-step derivation
              1. lower-fma.f64N/A

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

                \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right), {\color{blue}{\left(\lambda_1 - \lambda_2\right)}}^{2}, {\phi_1}^{2}\right)} \]
              3. sqr-cos-aN/A

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

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

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

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

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

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

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

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

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

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

                \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot \left(\frac{1}{2} \cdot \phi_1\right)\right), \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 \cdot \phi_1\right)} \]
              14. lower-*.f6469.9

                \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(0.5 \cdot \phi_1\right)\right), \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 \cdot \phi_1\right)} \]
            5. Applied rewrites69.9%

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

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

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

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

                \[\leadsto R \cdot \sqrt{\left(\lambda_1 \cdot \lambda_1\right) \cdot \left(\frac{1}{2} + \color{blue}{\frac{1}{2}} \cdot \cos \phi_1\right)} \]
              4. fp-cancel-sign-sub-invN/A

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

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

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

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

                \[\leadsto R \cdot \sqrt{\left(\lambda_1 \cdot \lambda_1\right) \cdot \left(0.5 - -0.5 \cdot \cos \phi_1\right)} \]
            8. Applied rewrites33.6%

              \[\leadsto R \cdot \sqrt{\left(\lambda_1 \cdot \lambda_1\right) \cdot \color{blue}{\left(0.5 - -0.5 \cdot \cos \phi_1\right)}} \]
            9. Taylor expanded in phi1 around 0

              \[\leadsto R \cdot \sqrt{{\lambda_1}^{2}} \]
            10. Step-by-step derivation
              1. pow2N/A

                \[\leadsto R \cdot \sqrt{\lambda_1 \cdot \lambda_1} \]
              2. lift-*.f6433.6

                \[\leadsto R \cdot \sqrt{\lambda_1 \cdot \lambda_1} \]
            11. Applied rewrites33.6%

              \[\leadsto R \cdot \sqrt{\lambda_1 \cdot \lambda_1} \]

            if -4.40000000000000008e-113 < phi1

            1. Initial program 65.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.0%

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

            Alternative 12: 28.5% accurate, 7.1× speedup?

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

              1. Initial program 64.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \left(-\phi_1\right) \cdot \left(\phi_2 \cdot \color{blue}{\left(\frac{R}{\phi_2} - \frac{R}{\phi_1}\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-/.f6423.0

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

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

              if 5.60000000000000038e-7 < phi2

              1. Initial program 63.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.5%

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

              Alternative 13: 27.7% accurate, 12.2× speedup?

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

                1. Initial program 61.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.f6450.3

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

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

                if -2.29999999999999991e-112 < phi1

                1. Initial program 65.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.0%

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

                Alternative 14: 17.5% accurate, 27.0× speedup?

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

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

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

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

                  Reproduce

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