Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.8% → 96.2%
Time: 5.8s
Alternatives: 14
Speedup: 1.9×

Specification

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

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

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

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

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 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: 59.8% accurate, 1.0× speedup?

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

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

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

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

Alternative 1: 96.2% accurate, 1.7× speedup?

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

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

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

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

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

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

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

Alternative 2: 93.3% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 59.8%

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

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

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

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

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

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

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

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

    if 14.199999999999999 < phi2

    1. Initial program 59.8%

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

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

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

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

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

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

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

    Alternative 3: 82.1% accurate, 1.7× speedup?

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

      1. Initial program 59.8%

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

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

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

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

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

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

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

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

      if -4.6e-175 < phi1

      1. Initial program 59.8%

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

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

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

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

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

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

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

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

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

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

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

      Alternative 4: 80.5% accurate, 1.7× speedup?

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

        1. Initial program 59.8%

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

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

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

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

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

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

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

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

            \[\leadsto \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right), \phi_1 - \phi_2\right) \cdot R \]
          4. lift-cos.f6477.9

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

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

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

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

            \[\leadsto \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right), \phi_1 - \phi_2\right) \cdot R \]
          3. lower-*.f6474.9

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

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

        if -3.2e52 < phi1

        1. Initial program 59.8%

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

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

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

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

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

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

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

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

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

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

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

        Alternative 5: 79.6% accurate, 1.7× speedup?

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

          1. Initial program 59.8%

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

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

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

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

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

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

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

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

              \[\leadsto \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right), \phi_1 - \phi_2\right) \cdot R \]
            4. lift-cos.f6477.9

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

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

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

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

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

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

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

          if 1.8499999999999999e-24 < lambda2

          1. Initial program 59.8%

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

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

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

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

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

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

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

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

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

                \[\leadsto \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \left(-\lambda_2\right), \phi_1 - \phi_2\right) \cdot R \]
            4. Applied rewrites75.1%

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

          Alternative 6: 76.0% accurate, 1.7× speedup?

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

            1. Initial program 59.8%

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

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

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

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

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

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

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

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

                \[\leadsto \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right), \phi_1 - \phi_2\right) \cdot R \]
              4. lift-cos.f6477.9

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

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

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

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

                \[\leadsto \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right), \phi_1 - \phi_2\right) \cdot R \]
              3. lower-*.f6474.9

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

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

            if 9.99999999999999934e-89 < phi2

            1. Initial program 59.8%

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

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

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

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

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

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

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

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

                \[\leadsto \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right), \phi_1 - \phi_2\right) \cdot R \]
              4. lift-cos.f6477.9

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

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

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

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

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

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

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

          Alternative 7: 74.9% accurate, 1.9× speedup?

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

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

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

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

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

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

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

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

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

              \[\leadsto \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right), \phi_1 - \phi_2\right) \cdot R \]
            4. lift-cos.f6477.9

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

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

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

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

              \[\leadsto \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right), \phi_1 - \phi_2\right) \cdot R \]
            3. lower-*.f6474.9

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

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

          Alternative 8: 60.8% accurate, 1.8× speedup?

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

            1. Initial program 59.8%

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

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

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

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

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

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

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

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

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

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

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

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

            if -3.4e52 < phi1

            1. Initial program 59.8%

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

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

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

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

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

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

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

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

                \[\leadsto \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right), \phi_1 - \phi_2\right) \cdot R \]
              4. lift-cos.f6477.9

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

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

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

                \[\leadsto \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right), \mathsf{neg}\left(\phi_2\right)\right) \cdot R \]
              2. lower-neg.f6456.4

                \[\leadsto \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right), -\phi_2\right) \cdot R \]
            9. Applied rewrites56.4%

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

              \[\leadsto \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right), -\phi_2\right) \cdot R \]
            11. Step-by-step derivation
              1. Applied rewrites53.7%

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

            Alternative 9: 59.5% accurate, 1.8× speedup?

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

              1. Initial program 59.8%

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

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

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

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

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

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

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

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

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

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

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

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

              if -6.5e54 < phi1

              1. Initial program 59.8%

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

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

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

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

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

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

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

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

                  \[\leadsto \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right), \phi_1 - \phi_2\right) \cdot R \]
                4. lift-cos.f6477.9

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

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

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

                  \[\leadsto \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right), \mathsf{neg}\left(\phi_2\right)\right) \cdot R \]
                2. lower-neg.f6456.4

                  \[\leadsto \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right), -\phi_2\right) \cdot R \]
              9. Applied rewrites56.4%

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

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

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

                  \[\leadsto \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right), -\phi_2\right) \cdot R \]
                3. lift-*.f6453.4

                  \[\leadsto \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right), -\phi_2\right) \cdot R \]
              12. Applied rewrites53.4%

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

            Alternative 10: 29.9% accurate, 4.5× speedup?

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

              1. Initial program 59.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              if -6.9999999999999994e191 < (-.f64 lambda1 lambda2)

              1. Initial program 59.8%

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

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

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

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

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

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

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

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

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

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

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

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

            Alternative 11: 29.2% accurate, 11.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

            Alternative 12: 28.3% accurate, 12.2× speedup?

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

              1. Initial program 59.8%

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

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

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

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

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

              if -7.1999999999999994e32 < phi1

              1. Initial program 59.8%

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

                \[\leadsto \color{blue}{R \cdot \phi_2} \]
              3. Step-by-step derivation
                1. *-commutativeN/A

                  \[\leadsto \phi_2 \cdot \color{blue}{R} \]
                2. lower-*.f6417.2

                  \[\leadsto \phi_2 \cdot \color{blue}{R} \]
              4. Applied rewrites17.2%

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

            Alternative 13: 17.3% accurate, 27.0× speedup?

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

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

              \[\leadsto \color{blue}{R \cdot \phi_2} \]
            3. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto \phi_2 \cdot \color{blue}{R} \]
              2. lower-*.f6417.2

                \[\leadsto \phi_2 \cdot \color{blue}{R} \]
            4. Applied rewrites17.2%

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

            Alternative 14: 17.2% accurate, 27.0× speedup?

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

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

              \[\leadsto \color{blue}{R \cdot \phi_1} \]
            3. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto \phi_1 \cdot \color{blue}{R} \]
              2. lower-*.f6417.3

                \[\leadsto \phi_1 \cdot \color{blue}{R} \]
            4. Applied rewrites17.3%

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

            Reproduce

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