Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.3% → 95.9%
Time: 6.5s
Alternatives: 10
Speedup: 1.2×

Specification

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

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

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 10 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.3% accurate, 1.0× speedup?

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

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

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

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

Alternative 1: 95.9% accurate, 1.2× speedup?

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

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

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

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

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

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

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

Alternative 2: 82.4% accurate, 1.2× speedup?

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

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

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


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

    1. Initial program 57.4%

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

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

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

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

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

      \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \cdot R \]
    6. Applied rewrites79.8%

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

    if 4.4999999999999999e-45 < phi2

    1. Initial program 56.0%

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

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

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

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

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

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

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

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

Alternative 3: 79.5% accurate, 1.2× speedup?

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

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

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


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

    1. Initial program 57.1%

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

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

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

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

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

      \[\leadsto \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \cdot R \]
    6. Applied rewrites79.9%

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

    if 1.3e-25 < phi2

    1. Initial program 56.7%

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

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

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

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

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

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

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

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

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

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

    Alternative 4: 75.4% accurate, 1.2× speedup?

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

      1. Initial program 56.8%

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

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

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

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

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

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

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

      if 5.60000000000000025e48 < phi2

      1. Initial program 57.9%

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto R \cdot \left(-1 \cdot \phi_1 + \phi_2\right) \]
        4. lower-fma.f6470.6

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

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

    Alternative 5: 31.4% accurate, 2.0× speedup?

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

      1. Initial program 54.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -2.25e-246 < phi2 < 3.80000000000000012e-223

      1. Initial program 65.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto R \cdot \sqrt{{\left(\lambda_1 - \lambda_2\right)}^{2}} \]
        2. lift--.f6454.0

          \[\leadsto R \cdot \sqrt{{\left(\lambda_1 - \lambda_2\right)}^{2}} \]
      8. Applied rewrites54.0%

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

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

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

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

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

          \[\leadsto R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)} \]
        6. lift--.f6454.0

          \[\leadsto R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)} \]
      10. Applied rewrites54.0%

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

      if 3.80000000000000012e-223 < phi2 < 5.5999999999999999e-27

      1. Initial program 63.8%

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

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

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

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

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

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

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

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

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

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

    Alternative 6: 35.5% accurate, 7.1× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq -2.25 \cdot 10^{-246} \lor \neg \left(\phi_2 \leq 2.75 \cdot 10^{-5}\right):\\ \;\;\;\;R \cdot \mathsf{fma}\left(-1, \phi_1, \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)}\\ \end{array} \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (if (or (<= phi2 -2.25e-246) (not (<= phi2 2.75e-5)))
       (* R (fma -1.0 phi1 phi2))
       (* R (sqrt (* (- lambda1 lambda2) (- lambda1 lambda2))))))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if ((phi2 <= -2.25e-246) || !(phi2 <= 2.75e-5)) {
    		tmp = R * fma(-1.0, phi1, phi2);
    	} else {
    		tmp = R * sqrt(((lambda1 - lambda2) * (lambda1 - lambda2)));
    	}
    	return tmp;
    }
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if ((phi2 <= -2.25e-246) || !(phi2 <= 2.75e-5))
    		tmp = Float64(R * fma(-1.0, phi1, phi2));
    	else
    		tmp = Float64(R * sqrt(Float64(Float64(lambda1 - lambda2) * Float64(lambda1 - lambda2))));
    	end
    	return tmp
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[Or[LessEqual[phi2, -2.25e-246], N[Not[LessEqual[phi2, 2.75e-5]], $MachinePrecision]], N[(R * N[(-1.0 * phi1 + phi2), $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\phi_2 \leq -2.25 \cdot 10^{-246} \lor \neg \left(\phi_2 \leq 2.75 \cdot 10^{-5}\right):\\
    \;\;\;\;R \cdot \mathsf{fma}\left(-1, \phi_1, \phi_2\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if phi2 < -2.25e-246 or 2.7500000000000001e-5 < phi2

      1. Initial program 54.3%

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto R \cdot \left(-1 \cdot \phi_1 + \phi_2\right) \]
        4. lower-fma.f6433.9

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

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

      if -2.25e-246 < phi2 < 2.7500000000000001e-5

      1. Initial program 63.4%

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

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

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

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

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

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

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

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

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

          \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\phi_1, \phi_1, {\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right)} \]
        9. lift--.f6463.4

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

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

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

          \[\leadsto R \cdot \sqrt{{\left(\lambda_1 - \lambda_2\right)}^{2}} \]
        2. lift--.f6448.7

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

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

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

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

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

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

          \[\leadsto R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)} \]
        6. lift--.f6448.7

          \[\leadsto R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)} \]
      10. Applied rewrites48.7%

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -2.25 \cdot 10^{-246} \lor \neg \left(\phi_2 \leq 2.75 \cdot 10^{-5}\right):\\ \;\;\;\;R \cdot \mathsf{fma}\left(-1, \phi_1, \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)}\\ \end{array} \]
    5. Add Preprocessing

    Alternative 7: 31.7% accurate, 10.3× speedup?

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

      1. Initial program 47.3%

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

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

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

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

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

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

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

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

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

          \[\leadsto R \cdot \sqrt{\mathsf{fma}\left(\phi_1, \phi_1, {\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right)} \]
        9. lift--.f6447.3

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

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

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

          \[\leadsto R \cdot \sqrt{{\left(\lambda_1 - \lambda_2\right)}^{2}} \]
        2. lift--.f6447.3

          \[\leadsto R \cdot \sqrt{{\left(\lambda_1 - \lambda_2\right)}^{2}} \]
      8. Applied rewrites47.3%

        \[\leadsto R \cdot \sqrt{{\left(\lambda_1 - \lambda_2\right)}^{\color{blue}{2}}} \]
      9. Taylor expanded in lambda1 around inf

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

          \[\leadsto R \cdot \sqrt{\lambda_1 \cdot \lambda_1} \]
        2. lower-*.f6447.3

          \[\leadsto R \cdot \sqrt{\lambda_1 \cdot \lambda_1} \]
      11. Applied rewrites47.3%

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

      if -3.7000000000000001e192 < lambda1

      1. Initial program 57.7%

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto R \cdot \left(-1 \cdot \phi_1 + \phi_2\right) \]
        4. lower-fma.f6428.8

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

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

    Alternative 8: 28.4% accurate, 19.9× speedup?

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

      1. Initial program 56.5%

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

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

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

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

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

      if 7.2e44 < phi2

      1. Initial program 58.7%

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

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

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

      Alternative 9: 29.5% accurate, 23.3× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto R \cdot \left(-1 \cdot \phi_1 + \phi_2\right) \]
        4. lower-fma.f6427.7

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

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

      Alternative 10: 16.6% accurate, 46.5× speedup?

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

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

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

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

        Reproduce

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