Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.4% → 99.9%
Time: 7.8s
Alternatives: 15
Speedup: 1.7×

Specification

?
\[\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} \]
(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}
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}

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 15 alternatives:

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

Initial Program: 59.4% accurate, 1.0× speedup?

\[\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} \]
(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}
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}

Alternative 1: 99.9% accurate, 0.6× speedup?

\[\mathsf{hypot}\left(\phi_2 - \phi_1, \mathsf{fma}\left(\sin \left(0.5 \cdot \phi_2\right), \sin \left(-0.5 \cdot \phi_1\right), \cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  (hypot
   (- phi2 phi1)
   (*
    (fma
     (sin (* 0.5 phi2))
     (sin (* -0.5 phi1))
     (* (cos (* 0.5 phi1)) (cos (* 0.5 phi2))))
    (- lambda1 lambda2)))
  R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return hypot((phi2 - phi1), (fma(sin((0.5 * phi2)), sin((-0.5 * phi1)), (cos((0.5 * phi1)) * cos((0.5 * phi2)))) * (lambda1 - lambda2))) * R;
}
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(hypot(Float64(phi2 - phi1), Float64(fma(sin(Float64(0.5 * phi2)), sin(Float64(-0.5 * phi1)), Float64(cos(Float64(0.5 * phi1)) * cos(Float64(0.5 * phi2)))) * Float64(lambda1 - lambda2))) * R)
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[Sqrt[N[(phi2 - phi1), $MachinePrecision] ^ 2 + N[(N[(N[Sin[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision] + N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]
\mathsf{hypot}\left(\phi_2 - \phi_1, \mathsf{fma}\left(\sin \left(0.5 \cdot \phi_2\right), \sin \left(-0.5 \cdot \phi_1\right), \cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R
Derivation
  1. Initial program 59.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. 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. *-commutativeN/A

      \[\leadsto \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)} \cdot R} \]
    3. lower-*.f6459.4%

      \[\leadsto \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)} \cdot R} \]
  3. Applied rewrites96.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{hypot}\left(\phi_2 - \phi_1, \left(\cos \left(\phi_2 \cdot \frac{-1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{-1}{2}\right) - \color{blue}{\sin \left(\phi_2 \cdot \frac{-1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{-1}{2}\right)}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
    3. fp-cancel-sub-sign-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{hypot}\left(\phi_2 - \phi_1, \mathsf{fma}\left(\sin \color{blue}{\left(0.5 \cdot \phi_2\right)}, \sin \left(\phi_1 \cdot -0.5\right), \cos \left(\phi_2 \cdot -0.5\right) \cdot \cos \left(\phi_1 \cdot -0.5\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
    18. lift-*.f64N/A

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

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

      \[\leadsto \mathsf{hypot}\left(\phi_2 - \phi_1, \mathsf{fma}\left(\sin \left(0.5 \cdot \phi_2\right), \sin \color{blue}{\left(-0.5 \cdot \phi_1\right)}, \cos \left(\phi_2 \cdot -0.5\right) \cdot \cos \left(\phi_1 \cdot -0.5\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
    21. lift-*.f64N/A

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

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

Alternative 2: 99.9% accurate, 0.6× speedup?

\[\mathsf{hypot}\left(\phi_2 - \phi_1, \mathsf{fma}\left(\cos \left(0.5 \cdot \phi_1\right), \cos \left(-0.5 \cdot \phi_2\right), \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(-0.5 \cdot \phi_2\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  (hypot
   (- phi2 phi1)
   (*
    (fma
     (cos (* 0.5 phi1))
     (cos (* -0.5 phi2))
     (* (sin (* 0.5 phi1)) (sin (* -0.5 phi2))))
    (- lambda1 lambda2)))
  R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return hypot((phi2 - phi1), (fma(cos((0.5 * phi1)), cos((-0.5 * phi2)), (sin((0.5 * phi1)) * sin((-0.5 * phi2)))) * (lambda1 - lambda2))) * R;
}
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(hypot(Float64(phi2 - phi1), Float64(fma(cos(Float64(0.5 * phi1)), cos(Float64(-0.5 * phi2)), Float64(sin(Float64(0.5 * phi1)) * sin(Float64(-0.5 * phi2)))) * Float64(lambda1 - lambda2))) * R)
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[Sqrt[N[(phi2 - phi1), $MachinePrecision] ^ 2 + N[(N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision] + N[(N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]
\mathsf{hypot}\left(\phi_2 - \phi_1, \mathsf{fma}\left(\cos \left(0.5 \cdot \phi_1\right), \cos \left(-0.5 \cdot \phi_2\right), \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(-0.5 \cdot \phi_2\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R
Derivation
  1. Initial program 59.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. 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. *-commutativeN/A

      \[\leadsto \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)} \cdot R} \]
    3. lower-*.f6459.4%

      \[\leadsto \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)} \cdot R} \]
  3. Applied rewrites96.0%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{hypot}\left(\phi_2 - \phi_1, \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_1 + \frac{1}{2} \cdot \phi_2\right)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
    12. fp-cancel-sign-sub-invN/A

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

      \[\leadsto \mathsf{hypot}\left(\phi_2 - \phi_1, \cos \left(\color{blue}{\frac{1}{2}} \cdot \phi_1 - \left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
    14. associate-*l/N/A

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

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

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

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

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

Alternative 3: 97.4% accurate, 0.6× speedup?

\[\begin{array}{l} t_0 := \mathsf{min}\left(\lambda_1, \lambda_2\right) - \mathsf{max}\left(\lambda_1, \lambda_2\right)\\ \mathbf{if}\;t\_0 \leq -1 \cdot 10^{+246}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_2, \mathsf{fma}\left(\sin \left(0.5 \cdot \phi_2\right), \sin \left(-0.5 \cdot \phi_1\right), \cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot t\_0\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_2 - \phi_1, \cos \left(\left(\phi_2 + \phi_1\right) \cdot -0.5\right) \cdot t\_0\right) \cdot R\\ \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (- (fmin lambda1 lambda2) (fmax lambda1 lambda2))))
   (if (<= t_0 -1e+246)
     (*
      (hypot
       phi2
       (*
        (fma
         (sin (* 0.5 phi2))
         (sin (* -0.5 phi1))
         (* (cos (* 0.5 phi1)) (cos (* 0.5 phi2))))
        t_0))
      R)
     (* (hypot (- phi2 phi1) (* (cos (* (+ phi2 phi1) -0.5)) t_0)) R))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2);
	double tmp;
	if (t_0 <= -1e+246) {
		tmp = hypot(phi2, (fma(sin((0.5 * phi2)), sin((-0.5 * phi1)), (cos((0.5 * phi1)) * cos((0.5 * phi2)))) * t_0)) * R;
	} else {
		tmp = hypot((phi2 - phi1), (cos(((phi2 + phi1) * -0.5)) * t_0)) * R;
	}
	return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(fmin(lambda1, lambda2) - fmax(lambda1, lambda2))
	tmp = 0.0
	if (t_0 <= -1e+246)
		tmp = Float64(hypot(phi2, Float64(fma(sin(Float64(0.5 * phi2)), sin(Float64(-0.5 * phi1)), Float64(cos(Float64(0.5 * phi1)) * cos(Float64(0.5 * phi2)))) * t_0)) * R);
	else
		tmp = Float64(hypot(Float64(phi2 - phi1), Float64(cos(Float64(Float64(phi2 + phi1) * -0.5)) * t_0)) * R);
	end
	return tmp
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Min[lambda1, lambda2], $MachinePrecision] - N[Max[lambda1, lambda2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+246], N[(N[Sqrt[phi2 ^ 2 + N[(N[(N[Sin[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision] + N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(N[Sqrt[N[(phi2 - phi1), $MachinePrecision] ^ 2 + N[(N[Cos[N[(N[(phi2 + phi1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]]]
\begin{array}{l}
t_0 := \mathsf{min}\left(\lambda_1, \lambda_2\right) - \mathsf{max}\left(\lambda_1, \lambda_2\right)\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+246}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_2, \mathsf{fma}\left(\sin \left(0.5 \cdot \phi_2\right), \sin \left(-0.5 \cdot \phi_1\right), \cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot t\_0\right) \cdot R\\

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 lambda1 lambda2) < -1.00000000000000007e246

    1. Initial program 59.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. 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. *-commutativeN/A

        \[\leadsto \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)} \cdot R} \]
      3. lower-*.f6459.4%

        \[\leadsto \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)} \cdot R} \]
    3. Applied rewrites96.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{hypot}\left(\phi_2 - \phi_1, \left(\cos \left(\phi_2 \cdot \frac{-1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{-1}{2}\right) - \color{blue}{\sin \left(\phi_2 \cdot \frac{-1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{-1}{2}\right)}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      3. fp-cancel-sub-sign-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{hypot}\left(\phi_2 - \phi_1, \mathsf{fma}\left(\sin \color{blue}{\left(0.5 \cdot \phi_2\right)}, \sin \left(\phi_1 \cdot -0.5\right), \cos \left(\phi_2 \cdot -0.5\right) \cdot \cos \left(\phi_1 \cdot -0.5\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      18. lift-*.f64N/A

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

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

        \[\leadsto \mathsf{hypot}\left(\phi_2 - \phi_1, \mathsf{fma}\left(\sin \left(0.5 \cdot \phi_2\right), \sin \color{blue}{\left(-0.5 \cdot \phi_1\right)}, \cos \left(\phi_2 \cdot -0.5\right) \cdot \cos \left(\phi_1 \cdot -0.5\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      21. lift-*.f64N/A

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

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

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

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

      if -1.00000000000000007e246 < (-.f64 lambda1 lambda2)

      1. Initial program 59.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. 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. *-commutativeN/A

          \[\leadsto \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)} \cdot R} \]
        3. lower-*.f6459.4%

          \[\leadsto \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)} \cdot R} \]
      3. Applied rewrites96.0%

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

    Alternative 4: 96.1% accurate, 0.6× speedup?

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

      1. Initial program 59.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. 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. *-commutativeN/A

          \[\leadsto \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)} \cdot R} \]
        3. lower-*.f6459.4%

          \[\leadsto \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)} \cdot R} \]
      3. Applied rewrites96.0%

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

      if 5.6000000000000003e222 < lambda2

      1. Initial program 59.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. Taylor expanded in lambda2 around inf

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

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

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

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

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

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

          \[\leadsto R \cdot \left(\lambda_2 \cdot \sqrt{{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right) \]
      4. Applied rewrites17.2%

        \[\leadsto R \cdot \color{blue}{\left(\lambda_2 \cdot \sqrt{{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)} \]
      5. Step-by-step derivation
        1. lift-sqrt.f64N/A

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

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

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

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

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

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

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

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

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

          \[\leadsto R \cdot \left(\lambda_2 \cdot \left|\cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right|\right) \]
        11. div-addN/A

          \[\leadsto R \cdot \left(\lambda_2 \cdot \left|\cos \left(\frac{\phi_1}{2} + \frac{\phi_2}{2}\right)\right|\right) \]
        12. cos-sumN/A

          \[\leadsto R \cdot \left(\lambda_2 \cdot \left|\cos \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \sin \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right|\right) \]
        13. fabs-subN/A

          \[\leadsto R \cdot \left(\lambda_2 \cdot \left|\sin \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right)\right|\right) \]
        14. lower-fabs.f64N/A

          \[\leadsto R \cdot \left(\lambda_2 \cdot \left|\sin \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right)\right|\right) \]
        15. lower--.f64N/A

          \[\leadsto R \cdot \left(\lambda_2 \cdot \left|\sin \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right)\right|\right) \]
      6. Applied rewrites18.2%

        \[\leadsto R \cdot \left(\lambda_2 \cdot \left|\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right)\right|\right) \]
    3. Recombined 2 regimes into one program.
    4. Add Preprocessing

    Alternative 5: 96.0% accurate, 1.4× speedup?

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

      1. Initial program 59.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. 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. *-commutativeN/A

          \[\leadsto \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)} \cdot R} \]
        3. lower-*.f6459.4%

          \[\leadsto \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)} \cdot R} \]
      3. Applied rewrites96.0%

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

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

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

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

      if -49000 < phi1

      1. Initial program 59.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. 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. *-commutativeN/A

          \[\leadsto \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)} \cdot R} \]
        3. lower-*.f6459.4%

          \[\leadsto \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)} \cdot R} \]
      3. Applied rewrites96.0%

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

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

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

        \[\leadsto \mathsf{hypot}\left(\phi_2 - \phi_1, \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: 95.7% accurate, 1.7× speedup?

    \[\mathsf{hypot}\left(\phi_2 - \phi_1, \cos \left(\left(\phi_2 + \phi_1\right) \cdot -0.5\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
     :precision binary64
     (*
      (hypot (- phi2 phi1) (* (cos (* (+ phi2 phi1) -0.5)) (- lambda1 lambda2)))
      R))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	return hypot((phi2 - phi1), (cos(((phi2 + phi1) * -0.5)) * (lambda1 - lambda2))) * R;
    }
    
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	return Math.hypot((phi2 - phi1), (Math.cos(((phi2 + phi1) * -0.5)) * (lambda1 - lambda2))) * R;
    }
    
    def code(R, lambda1, lambda2, phi1, phi2):
    	return math.hypot((phi2 - phi1), (math.cos(((phi2 + phi1) * -0.5)) * (lambda1 - lambda2))) * R
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	return Float64(hypot(Float64(phi2 - phi1), Float64(cos(Float64(Float64(phi2 + phi1) * -0.5)) * Float64(lambda1 - lambda2))) * R)
    end
    
    function tmp = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = hypot((phi2 - phi1), (cos(((phi2 + phi1) * -0.5)) * (lambda1 - lambda2))) * R;
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[Sqrt[N[(phi2 - phi1), $MachinePrecision] ^ 2 + N[(N[Cos[N[(N[(phi2 + phi1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]
    
    \mathsf{hypot}\left(\phi_2 - \phi_1, \cos \left(\left(\phi_2 + \phi_1\right) \cdot -0.5\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R
    
    Derivation
    1. Initial program 59.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. 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. *-commutativeN/A

        \[\leadsto \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)} \cdot R} \]
      3. lower-*.f6459.4%

        \[\leadsto \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)} \cdot R} \]
    3. Applied rewrites96.0%

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

    Alternative 7: 94.8% accurate, 1.4× speedup?

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

      1. Initial program 59.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. 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. *-commutativeN/A

          \[\leadsto \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)} \cdot R} \]
        3. lower-*.f6459.4%

          \[\leadsto \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)} \cdot R} \]
      3. Applied rewrites96.0%

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

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

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

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

      if -2.3499999999999999e-29 < phi1

      1. Initial program 59.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. 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. *-commutativeN/A

          \[\leadsto \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)} \cdot R} \]
        3. lower-*.f6459.4%

          \[\leadsto \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)} \cdot R} \]
      3. Applied rewrites96.0%

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

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

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

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

        \[\leadsto \mathsf{hypot}\left(\color{blue}{\phi_2}, \cos \left(-0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      8. Step-by-step derivation
        1. Applied rewrites71.1%

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

      Alternative 8: 83.2% accurate, 1.5× speedup?

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

        1. Initial program 59.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. Taylor expanded in phi1 around -inf

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

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

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

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

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

            \[\leadsto -1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\color{blue}{\phi_1}}\right)\right) \]
          6. lower-*.f6428.5%

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

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

        if -2.7999999999999998e-4 < phi1

        1. Initial program 59.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. 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. *-commutativeN/A

            \[\leadsto \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)} \cdot R} \]
          3. lower-*.f6459.4%

            \[\leadsto \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)} \cdot R} \]
        3. Applied rewrites96.0%

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

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

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

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

          \[\leadsto \mathsf{hypot}\left(\color{blue}{\phi_2}, \cos \left(-0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
        8. Step-by-step derivation
          1. Applied rewrites71.1%

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

        Alternative 9: 61.4% accurate, 1.7× speedup?

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

          1. Initial program 59.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. Taylor expanded in phi2 around inf

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

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

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

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

              \[\leadsto \phi_2 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_1}{\color{blue}{\phi_2}}\right) \]
            5. lower-*.f6428.4%

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

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

          if 5.6000000000000003e222 < lambda2

          1. Initial program 59.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. Taylor expanded in lambda2 around inf

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

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

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

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

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

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

              \[\leadsto R \cdot \left(\lambda_2 \cdot \sqrt{{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right) \]
          4. Applied rewrites17.2%

            \[\leadsto R \cdot \color{blue}{\left(\lambda_2 \cdot \sqrt{{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)} \]
          5. Step-by-step derivation
            1. lift-*.f64N/A

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

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

              \[\leadsto \color{blue}{\left(\lambda_2 \cdot \sqrt{{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right) \cdot R} \]
          6. Applied rewrites17.2%

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

        Alternative 10: 58.1% accurate, 2.2× speedup?

        \[\begin{array}{l} \mathbf{if}\;\mathsf{max}\left(\lambda_1, \lambda_2\right) \leq 2 \cdot 10^{+235}:\\ \;\;\;\;\mathsf{max}\left(\phi_1, \phi_2\right) \cdot \left(R + -1 \cdot \frac{R \cdot \mathsf{min}\left(\phi_1, \phi_2\right)}{\mathsf{max}\left(\phi_1, \phi_2\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) \cdot \sqrt{{\left(1 + -0.25 \cdot \left(\mathsf{min}\left(\phi_1, \phi_2\right) \cdot \mathsf{max}\left(\phi_1, \phi_2\right)\right)\right)}^{2}}\right)\\ \end{array} \]
        (FPCore (R lambda1 lambda2 phi1 phi2)
         :precision binary64
         (if (<= (fmax lambda1 lambda2) 2e+235)
           (*
            (fmax phi1 phi2)
            (+ R (* -1.0 (/ (* R (fmin phi1 phi2)) (fmax phi1 phi2)))))
           (*
            R
            (*
             (fmax lambda1 lambda2)
             (sqrt
              (pow (+ 1.0 (* -0.25 (* (fmin phi1 phi2) (fmax phi1 phi2)))) 2.0))))))
        double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
        	double tmp;
        	if (fmax(lambda1, lambda2) <= 2e+235) {
        		tmp = fmax(phi1, phi2) * (R + (-1.0 * ((R * fmin(phi1, phi2)) / fmax(phi1, phi2))));
        	} else {
        		tmp = R * (fmax(lambda1, lambda2) * sqrt(pow((1.0 + (-0.25 * (fmin(phi1, phi2) * fmax(phi1, phi2)))), 2.0)));
        	}
        	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 (fmax(lambda1, lambda2) <= 2d+235) then
                tmp = fmax(phi1, phi2) * (r + ((-1.0d0) * ((r * fmin(phi1, phi2)) / fmax(phi1, phi2))))
            else
                tmp = r * (fmax(lambda1, lambda2) * sqrt(((1.0d0 + ((-0.25d0) * (fmin(phi1, phi2) * fmax(phi1, phi2)))) ** 2.0d0)))
            end if
            code = tmp
        end function
        
        public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
        	double tmp;
        	if (fmax(lambda1, lambda2) <= 2e+235) {
        		tmp = fmax(phi1, phi2) * (R + (-1.0 * ((R * fmin(phi1, phi2)) / fmax(phi1, phi2))));
        	} else {
        		tmp = R * (fmax(lambda1, lambda2) * Math.sqrt(Math.pow((1.0 + (-0.25 * (fmin(phi1, phi2) * fmax(phi1, phi2)))), 2.0)));
        	}
        	return tmp;
        }
        
        def code(R, lambda1, lambda2, phi1, phi2):
        	tmp = 0
        	if fmax(lambda1, lambda2) <= 2e+235:
        		tmp = fmax(phi1, phi2) * (R + (-1.0 * ((R * fmin(phi1, phi2)) / fmax(phi1, phi2))))
        	else:
        		tmp = R * (fmax(lambda1, lambda2) * math.sqrt(math.pow((1.0 + (-0.25 * (fmin(phi1, phi2) * fmax(phi1, phi2)))), 2.0)))
        	return tmp
        
        function code(R, lambda1, lambda2, phi1, phi2)
        	tmp = 0.0
        	if (fmax(lambda1, lambda2) <= 2e+235)
        		tmp = Float64(fmax(phi1, phi2) * Float64(R + Float64(-1.0 * Float64(Float64(R * fmin(phi1, phi2)) / fmax(phi1, phi2)))));
        	else
        		tmp = Float64(R * Float64(fmax(lambda1, lambda2) * sqrt((Float64(1.0 + Float64(-0.25 * Float64(fmin(phi1, phi2) * fmax(phi1, phi2)))) ^ 2.0))));
        	end
        	return tmp
        end
        
        function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
        	tmp = 0.0;
        	if (max(lambda1, lambda2) <= 2e+235)
        		tmp = max(phi1, phi2) * (R + (-1.0 * ((R * min(phi1, phi2)) / max(phi1, phi2))));
        	else
        		tmp = R * (max(lambda1, lambda2) * sqrt(((1.0 + (-0.25 * (min(phi1, phi2) * max(phi1, phi2)))) ^ 2.0)));
        	end
        	tmp_2 = tmp;
        end
        
        code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[Max[lambda1, lambda2], $MachinePrecision], 2e+235], N[(N[Max[phi1, phi2], $MachinePrecision] * N[(R + N[(-1.0 * N[(N[(R * N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision] / N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(N[Max[lambda1, lambda2], $MachinePrecision] * N[Sqrt[N[Power[N[(1.0 + N[(-0.25 * N[(N[Min[phi1, phi2], $MachinePrecision] * N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
        
        \begin{array}{l}
        \mathbf{if}\;\mathsf{max}\left(\lambda_1, \lambda_2\right) \leq 2 \cdot 10^{+235}:\\
        \;\;\;\;\mathsf{max}\left(\phi_1, \phi_2\right) \cdot \left(R + -1 \cdot \frac{R \cdot \mathsf{min}\left(\phi_1, \phi_2\right)}{\mathsf{max}\left(\phi_1, \phi_2\right)}\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;R \cdot \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) \cdot \sqrt{{\left(1 + -0.25 \cdot \left(\mathsf{min}\left(\phi_1, \phi_2\right) \cdot \mathsf{max}\left(\phi_1, \phi_2\right)\right)\right)}^{2}}\right)\\
        
        
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if lambda2 < 2.0000000000000001e235

          1. Initial program 59.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. Taylor expanded in phi2 around inf

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

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

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

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

              \[\leadsto \phi_2 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_1}{\color{blue}{\phi_2}}\right) \]
            5. lower-*.f6428.4%

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

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

          if 2.0000000000000001e235 < lambda2

          1. Initial program 59.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. Taylor expanded in lambda2 around inf

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

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

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

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

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

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

              \[\leadsto R \cdot \left(\lambda_2 \cdot \sqrt{{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right) \]
          4. Applied rewrites17.2%

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

            \[\leadsto R \cdot \left(\lambda_2 \cdot \sqrt{{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) + \frac{-1}{2} \cdot \left(\phi_2 \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)}^{2}}\right) \]
          6. Step-by-step derivation
            1. lower-+.f64N/A

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

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

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

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

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

              \[\leadsto R \cdot \left(\lambda_2 \cdot \sqrt{{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) + \frac{-1}{2} \cdot \left(\phi_2 \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)}^{2}}\right) \]
            7. lower-*.f6417.9%

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

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

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

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

              \[\leadsto R \cdot \left(\lambda_2 \cdot \sqrt{{\left(1 + \frac{-1}{4} \cdot \left(\phi_1 \cdot \phi_2\right)\right)}^{2}}\right) \]
            3. lower-*.f6418.0%

              \[\leadsto R \cdot \left(\lambda_2 \cdot \sqrt{{\left(1 + -0.25 \cdot \left(\phi_1 \cdot \phi_2\right)\right)}^{2}}\right) \]
          10. Applied rewrites18.0%

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

        Alternative 11: 55.1% accurate, 3.0× speedup?

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

          1. Initial program 59.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. Taylor expanded in phi2 around inf

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

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

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

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

              \[\leadsto \phi_2 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_1}{\color{blue}{\phi_2}}\right) \]
            5. lower-*.f6428.4%

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

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

          if 3.79999999999999981e-226 < phi1

          1. Initial program 59.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. Taylor expanded in phi1 around -inf

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

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

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

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

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

              \[\leadsto -1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\color{blue}{\phi_1}}\right)\right) \]
            6. lower-*.f6428.5%

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

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

        Alternative 12: 54.2% accurate, 4.3× speedup?

        \[\mathsf{max}\left(\phi_1, \phi_2\right) \cdot \left(R + -1 \cdot \frac{R \cdot \mathsf{min}\left(\phi_1, \phi_2\right)}{\mathsf{max}\left(\phi_1, \phi_2\right)}\right) \]
        (FPCore (R lambda1 lambda2 phi1 phi2)
         :precision binary64
         (*
          (fmax phi1 phi2)
          (+ R (* -1.0 (/ (* R (fmin phi1 phi2)) (fmax phi1 phi2))))))
        double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
        	return fmax(phi1, phi2) * (R + (-1.0 * ((R * fmin(phi1, phi2)) / fmax(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
            code = fmax(phi1, phi2) * (r + ((-1.0d0) * ((r * fmin(phi1, phi2)) / fmax(phi1, phi2))))
        end function
        
        public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
        	return fmax(phi1, phi2) * (R + (-1.0 * ((R * fmin(phi1, phi2)) / fmax(phi1, phi2))));
        }
        
        def code(R, lambda1, lambda2, phi1, phi2):
        	return fmax(phi1, phi2) * (R + (-1.0 * ((R * fmin(phi1, phi2)) / fmax(phi1, phi2))))
        
        function code(R, lambda1, lambda2, phi1, phi2)
        	return Float64(fmax(phi1, phi2) * Float64(R + Float64(-1.0 * Float64(Float64(R * fmin(phi1, phi2)) / fmax(phi1, phi2)))))
        end
        
        function tmp = code(R, lambda1, lambda2, phi1, phi2)
        	tmp = max(phi1, phi2) * (R + (-1.0 * ((R * min(phi1, phi2)) / max(phi1, phi2))));
        end
        
        code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[Max[phi1, phi2], $MachinePrecision] * N[(R + N[(-1.0 * N[(N[(R * N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision] / N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
        
        \mathsf{max}\left(\phi_1, \phi_2\right) \cdot \left(R + -1 \cdot \frac{R \cdot \mathsf{min}\left(\phi_1, \phi_2\right)}{\mathsf{max}\left(\phi_1, \phi_2\right)}\right)
        
        Derivation
        1. Initial program 59.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. Taylor expanded in phi2 around inf

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

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

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

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

            \[\leadsto \phi_2 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_1}{\color{blue}{\phi_2}}\right) \]
          5. lower-*.f6428.4%

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

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

        Alternative 13: 50.6% accurate, 6.3× speedup?

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

          1. Initial program 59.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. Taylor expanded in phi1 around -inf

            \[\leadsto R \cdot \color{blue}{\left(-1 \cdot \phi_1\right)} \]
          3. Step-by-step derivation
            1. lower-*.f6417.1%

              \[\leadsto R \cdot \left(-1 \cdot \color{blue}{\phi_1}\right) \]
          4. Applied rewrites17.1%

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

          if 1.55000000000000015e70 < phi2

          1. Initial program 59.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. Taylor expanded in phi2 around inf

            \[\leadsto \color{blue}{R \cdot \phi_2} \]
          3. Step-by-step derivation
            1. lower-*.f6417.0%

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

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

        Alternative 14: 30.7% accurate, 15.4× speedup?

        \[R \cdot \mathsf{max}\left(\phi_1, \phi_2\right) \]
        (FPCore (R lambda1 lambda2 phi1 phi2)
         :precision binary64
         (* R (fmax phi1 phi2)))
        double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
        	return R * fmax(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
            code = r * fmax(phi1, phi2)
        end function
        
        public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
        	return R * fmax(phi1, phi2);
        }
        
        def code(R, lambda1, lambda2, phi1, phi2):
        	return R * fmax(phi1, phi2)
        
        function code(R, lambda1, lambda2, phi1, phi2)
        	return Float64(R * fmax(phi1, phi2))
        end
        
        function tmp = code(R, lambda1, lambda2, phi1, phi2)
        	tmp = R * max(phi1, phi2);
        end
        
        code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision]
        
        R \cdot \mathsf{max}\left(\phi_1, \phi_2\right)
        
        Derivation
        1. Initial program 59.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. Taylor expanded in phi2 around inf

          \[\leadsto \color{blue}{R \cdot \phi_2} \]
        3. Step-by-step derivation
          1. lower-*.f6417.0%

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

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

        Alternative 15: 17.4% accurate, 27.0× speedup?

        \[R \cdot \phi_1 \]
        (FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R phi1))
        double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
        	return R * phi1;
        }
        
        module fmin_fmax_functions
            implicit none
            private
            public fmax
            public fmin
        
            interface fmax
                module procedure fmax88
                module procedure fmax44
                module procedure fmax84
                module procedure fmax48
            end interface
            interface fmin
                module procedure fmin88
                module procedure fmin44
                module procedure fmin84
                module procedure fmin48
            end interface
        contains
            real(8) function fmax88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(4) function fmax44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(8) function fmax84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmax48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
            end function
            real(8) function fmin88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(4) function fmin44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(8) function fmin84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmin48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
            end function
        end module
        
        real(8) function code(r, lambda1, lambda2, phi1, phi2)
        use fmin_fmax_functions
            real(8), intent (in) :: r
            real(8), intent (in) :: lambda1
            real(8), intent (in) :: lambda2
            real(8), intent (in) :: phi1
            real(8), intent (in) :: phi2
            code = r * phi1
        end function
        
        public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
        	return R * phi1;
        }
        
        def code(R, lambda1, lambda2, phi1, phi2):
        	return R * phi1
        
        function code(R, lambda1, lambda2, phi1, phi2)
        	return Float64(R * phi1)
        end
        
        function tmp = code(R, lambda1, lambda2, phi1, phi2)
        	tmp = R * phi1;
        end
        
        code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * phi1), $MachinePrecision]
        
        R \cdot \phi_1
        
        Derivation
        1. Initial program 59.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. Taylor expanded in phi1 around inf

          \[\leadsto \color{blue}{R \cdot \phi_1} \]
        3. Step-by-step derivation
          1. lower-*.f6417.4%

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

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

        Reproduce

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