Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.2% → 99.9%
Time: 6.7s
Alternatives: 17
Speedup: 1.3×

Specification

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

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

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

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

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 17 alternatives:

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

Initial Program: 60.2% 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: 99.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\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 2.0)) (cos (/ phi1 2.0)))
     (* (sin (/ phi2 2.0)) (sin (/ phi1 2.0))))
    (- lambda1 lambda2)))
  R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return hypot((phi1 - phi2), (((cos((phi2 / 2.0)) * cos((phi1 / 2.0))) - (sin((phi2 / 2.0)) * sin((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 / 2.0)) * Math.cos((phi1 / 2.0))) - (Math.sin((phi2 / 2.0)) * Math.sin((phi1 / 2.0)))) * (lambda1 - lambda2))) * R;
}
def code(R, lambda1, lambda2, phi1, phi2):
	return math.hypot((phi1 - phi2), (((math.cos((phi2 / 2.0)) * math.cos((phi1 / 2.0))) - (math.sin((phi2 / 2.0)) * math.sin((phi1 / 2.0)))) * (lambda1 - lambda2))) * R
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(hypot(Float64(phi1 - phi2), Float64(Float64(Float64(cos(Float64(phi2 / 2.0)) * cos(Float64(phi1 / 2.0))) - Float64(sin(Float64(phi2 / 2.0)) * sin(Float64(phi1 / 2.0)))) * Float64(lambda1 - lambda2))) * R)
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = hypot((phi1 - phi2), (((cos((phi2 / 2.0)) * cos((phi1 / 2.0))) - (sin((phi2 / 2.0)) * sin((phi1 / 2.0)))) * (lambda1 - lambda2))) * R;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(N[(N[(N[Cos[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
  7. Applied rewrites89.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \color{blue}{\sin \left(\frac{\phi_1}{2}\right)}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
    16. lower-/.f6492.2

      \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \color{blue}{\left(\frac{\phi_1}{2}\right)}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
  9. Applied rewrites92.2%

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

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

      \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(\lambda_1 - \color{blue}{\lambda_2}\right)\right) \cdot R \]
  12. Applied rewrites99.9%

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

Alternative 2: 85.1% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\\
\mathbf{if}\;\lambda_1 \leq -9 \cdot 10^{-23}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, t\_0 \cdot \lambda_1\right) \cdot R\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda1 < -8.9999999999999995e-23

    1. Initial program 55.2%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
    7. Applied rewrites94.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \color{blue}{\sin \left(\frac{\phi_1}{2}\right)}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      16. lower-/.f6499.8

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \color{blue}{\left(\frac{\phi_1}{2}\right)}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
    9. Applied rewrites99.8%

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

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

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \lambda_1\right) \cdot R \]

      if -8.9999999999999995e-23 < lambda1

      1. Initial program 62.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 rewrites96.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 lambda1 around -inf

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

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

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

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

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

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        6. lower-/.f6487.3

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
      7. Applied rewrites87.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \color{blue}{\sin \left(\frac{\phi_1}{2}\right)}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        16. lower-/.f6489.4

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

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

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \left(-\lambda_2\right)\right) \cdot R \]
      11. Step-by-step derivation
        1. Applied rewrites84.4%

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

      Alternative 3: 96.0% accurate, 0.5× speedup?

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

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

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

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

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

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

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

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

            \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
          6. lower-/.f6492.0

            \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        7. Applied rewrites92.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \color{blue}{\sin \left(\frac{\phi_1}{2}\right)}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
          16. lower-/.f6499.8

            \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \color{blue}{\left(\frac{\phi_1}{2}\right)}\right) \cdot \left(-\left(\frac{\lambda_2}{\lambda_1} - 1\right) \cdot \lambda_1\right)\right) \cdot R \]
        9. Applied rewrites99.8%

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

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

            \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right) \cdot \lambda_1\right) \cdot R \]

          if -1.00000000000000003e139 < lambda1

          1. Initial program 62.7%

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

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

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

              \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}} \]
          4. Applied rewrites96.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} \]
        12. Recombined 2 regimes into one program.
        13. Add Preprocessing

        Alternative 4: 96.1% 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 60.2%

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

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

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

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

        Alternative 5: 92.2% accurate, 1.2× speedup?

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

          1. Initial program 62.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 rewrites97.2%

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

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

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

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

          if 5e-108 < phi2

          1. Initial program 56.6%

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

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

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

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

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

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

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

        Alternative 6: 79.4% accurate, 1.2× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(0.5 \cdot \phi_2\right)\\ \mathbf{if}\;\lambda_1 \leq -9 \cdot 10^{-23}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, t\_0 \cdot \lambda_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, t\_0 \cdot \left(-\lambda_2\right)\right) \cdot R\\ \end{array} \end{array} \]
        (FPCore (R lambda1 lambda2 phi1 phi2)
         :precision binary64
         (let* ((t_0 (cos (* 0.5 phi2))))
           (if (<= lambda1 -9e-23)
             (* (hypot (- phi1 phi2) (* t_0 lambda1)) R)
             (* (hypot (- phi1 phi2) (* t_0 (- lambda2))) R))))
        double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
        	double t_0 = cos((0.5 * phi2));
        	double tmp;
        	if (lambda1 <= -9e-23) {
        		tmp = hypot((phi1 - phi2), (t_0 * lambda1)) * R;
        	} else {
        		tmp = hypot((phi1 - phi2), (t_0 * -lambda2)) * 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 (lambda1 <= -9e-23) {
        		tmp = Math.hypot((phi1 - phi2), (t_0 * lambda1)) * R;
        	} else {
        		tmp = Math.hypot((phi1 - phi2), (t_0 * -lambda2)) * R;
        	}
        	return tmp;
        }
        
        def code(R, lambda1, lambda2, phi1, phi2):
        	t_0 = math.cos((0.5 * phi2))
        	tmp = 0
        	if lambda1 <= -9e-23:
        		tmp = math.hypot((phi1 - phi2), (t_0 * lambda1)) * R
        	else:
        		tmp = math.hypot((phi1 - phi2), (t_0 * -lambda2)) * R
        	return tmp
        
        function code(R, lambda1, lambda2, phi1, phi2)
        	t_0 = cos(Float64(0.5 * phi2))
        	tmp = 0.0
        	if (lambda1 <= -9e-23)
        		tmp = Float64(hypot(Float64(phi1 - phi2), Float64(t_0 * lambda1)) * R);
        	else
        		tmp = Float64(hypot(Float64(phi1 - phi2), Float64(t_0 * Float64(-lambda2))) * R);
        	end
        	return tmp
        end
        
        function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
        	t_0 = cos((0.5 * phi2));
        	tmp = 0.0;
        	if (lambda1 <= -9e-23)
        		tmp = hypot((phi1 - phi2), (t_0 * lambda1)) * R;
        	else
        		tmp = hypot((phi1 - phi2), (t_0 * -lambda2)) * 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[lambda1, -9e-23], N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(t$95$0 * lambda1), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(t$95$0 * (-lambda2)), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_0 := \cos \left(0.5 \cdot \phi_2\right)\\
        \mathbf{if}\;\lambda_1 \leq -9 \cdot 10^{-23}:\\
        \;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, t\_0 \cdot \lambda_1\right) \cdot R\\
        
        \mathbf{else}:\\
        \;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, t\_0 \cdot \left(-\lambda_2\right)\right) \cdot R\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if lambda1 < -8.9999999999999995e-23

          1. Initial program 55.2%

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

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

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

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

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

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

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

            if -8.9999999999999995e-23 < lambda1

            1. Initial program 62.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 rewrites96.6%

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

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

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

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

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

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

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

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

          Alternative 7: 77.2% accurate, 1.2× speedup?

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

            1. Initial program 62.9%

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

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

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

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

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

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

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

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

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

              if 5.39999999999999954e55 < phi2

              1. Initial program 49.9%

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

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

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

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

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

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

                  \[\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 rewrites92.5%

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

                  \[\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 8: 74.5% accurate, 1.2× speedup?

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

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

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

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

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

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

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

                  if 2.50000000000000008e82 < phi2

                  1. Initial program 47.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 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-/.f6472.0

                      \[\leadsto R \cdot \left(\mathsf{fma}\left(\frac{\phi_1}{\phi_2}, -1, 1\right) \cdot \phi_2\right) \]
                  5. Applied rewrites72.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.f6472.0

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

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

                Alternative 9: 90.2% accurate, 1.3× speedup?

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

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

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

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

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

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

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

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

                Alternative 10: 30.9% accurate, 2.2× speedup?

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

                  1. Initial program 53.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 lambda1 around -inf

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

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

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

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

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

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

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

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

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

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

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

                  if -1.95999999999999992e37 < lambda2 < 1.06e163

                  1. Initial program 65.4%

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

                    \[\leadsto R \cdot \color{blue}{\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-/.f6431.0

                      \[\leadsto R \cdot \left(\mathsf{fma}\left(\frac{\phi_1}{\phi_2}, -1, 1\right) \cdot \phi_2\right) \]
                  5. Applied rewrites31.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.f6433.8

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

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

                  if 1.06e163 < lambda2

                  1. Initial program 43.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 lambda2 around inf

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

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

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

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

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

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

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

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

                    \[\leadsto R \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \lambda_2\right) \]
                  7. Step-by-step derivation
                    1. Applied rewrites50.2%

                      \[\leadsto R \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_2\right) \]
                  8. Recombined 3 regimes into one program.
                  9. Final simplification30.9%

                    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq -1.96 \cdot 10^{+37}:\\ \;\;\;\;\left(\left(-R\right) \cdot \lambda_1\right) \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\\ \mathbf{elif}\;\lambda_2 \leq 1.06 \cdot 10^{+163}:\\ \;\;\;\;R \cdot \mathsf{fma}\left(-1, \phi_1, \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_2\right)\\ \end{array} \]
                  10. Add Preprocessing

                  Alternative 11: 30.8% accurate, 2.2× speedup?

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

                    1. Initial program 53.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 rewrites93.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-*.f6486.2

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

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

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

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

                        \[\leadsto \left(\left(-\lambda_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right) \cdot R \]
                      3. Step-by-step derivation
                        1. Applied rewrites11.0%

                          \[\leadsto \left(\left(-\lambda_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot R \]

                        if -1.95999999999999992e37 < lambda2 < 1.06e163

                        1. Initial program 65.4%

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

                          \[\leadsto R \cdot \color{blue}{\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-/.f6431.0

                            \[\leadsto R \cdot \left(\mathsf{fma}\left(\frac{\phi_1}{\phi_2}, -1, 1\right) \cdot \phi_2\right) \]
                        5. Applied rewrites31.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.f6433.8

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

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

                        if 1.06e163 < lambda2

                        1. Initial program 43.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 lambda2 around inf

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

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

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

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

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

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

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

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

                          \[\leadsto R \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \lambda_2\right) \]
                        7. Step-by-step derivation
                          1. Applied rewrites50.2%

                            \[\leadsto R \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_2\right) \]
                        8. Recombined 3 regimes into one program.
                        9. Add Preprocessing

                        Alternative 12: 30.7% accurate, 5.1× speedup?

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

                          1. Initial program 43.6%

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

                            \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
                          5. Taylor expanded in 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)} \]
                          6. Step-by-step derivation
                            1. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                          if -1.9999999999999999e159 < (-.f64 lambda1 lambda2)

                          1. Initial program 64.8%

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

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

                            \[\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.f6432.8

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

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

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

                        Alternative 13: 30.4% accurate, 5.6× speedup?

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

                          1. Initial program 45.9%

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

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

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

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

                            \[\leadsto \color{blue}{\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R} \]
                          5. Taylor expanded in 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)} \]
                          6. Step-by-step derivation
                            1. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                          if -1.09999999999999999e188 < (-.f64 lambda1 lambda2)

                          1. Initial program 63.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-/.f6429.7

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

                            \[\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.f6432.3

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

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

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

                        Alternative 14: 29.8% accurate, 8.5× speedup?

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

                          1. Initial program 53.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                              \[\leadsto \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \]
                            5. lift-*.f6429.0

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

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

                          if 1.2e114 < R

                          1. Initial program 98.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 rewrites99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                              \[\leadsto \left(-\phi_2\right) \cdot \mathsf{fma}\left(R, \frac{\phi_1}{\phi_2}, \mathsf{neg}\left(R\right)\right) \]
                            10. lower-neg.f6434.4

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

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

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

                        Alternative 15: 28.0% accurate, 19.9× speedup?

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

                          1. Initial program 52.1%

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

                            \[\leadsto 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.f6463.3

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

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

                          if -2.1999999999999999e40 < phi1

                          1. Initial program 62.4%

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

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

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

                          Alternative 16: 29.8% 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 60.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 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-/.f6427.5

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

                            \[\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.f6429.8

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

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

                          Alternative 17: 17.4% 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 60.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 inf

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

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

                            Reproduce

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