Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.4% → 99.9%
Time: 7.4s
Alternatives: 14
Speedup: 1.3×

Specification

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

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

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

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

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 14 alternatives:

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

Initial Program: 60.4% accurate, 1.0× speedup?

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

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

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

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

Alternative 1: 99.9% accurate, 0.5× speedup?

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

\\
\mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \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
\end{array}
Derivation
  1. Initial program 60.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. lift-sqrt.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(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 \]
  8. Applied rewrites99.9%

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

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

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

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

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

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

      \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \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 \]
  11. Applied rewrites99.9%

    \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \left(\color{blue}{\cos \left(0.5 \cdot \phi_1\right) \cdot \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 \]
  12. Add Preprocessing

Alternative 2: 96.2% accurate, 1.2× speedup?

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

\\
\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R
\end{array}
Derivation
  1. Initial program 60.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. lift-sqrt.f64N/A

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

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

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

Alternative 3: 92.9% accurate, 1.2× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi1 < -4.7e13

    1. Initial program 54.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. lift-sqrt.f64N/A

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

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

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

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

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

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

    if -4.7e13 < phi1

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

Alternative 4: 90.6% accurate, 1.3× speedup?

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

\\
\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R
\end{array}
Derivation
  1. Initial program 60.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. lift-sqrt.f64N/A

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

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

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

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

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

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

Alternative 5: 30.2% accurate, 2.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -4.1 \cdot 10^{+173}:\\ \;\;\;\;R \cdot \left(-\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq 3.6 \cdot 10^{+24}:\\ \;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot R\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= lambda1 -4.1e+173)
   (* R (- (* (cos (* 0.5 phi2)) lambda1)))
   (if (<= lambda1 3.6e+24)
     (fma (- R) phi1 (* R phi2))
     (* (* lambda2 (cos (* 0.5 phi1))) R))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda1 <= -4.1e+173) {
		tmp = R * -(cos((0.5 * phi2)) * lambda1);
	} else if (lambda1 <= 3.6e+24) {
		tmp = fma(-R, phi1, (R * phi2));
	} else {
		tmp = (lambda2 * cos((0.5 * phi1))) * R;
	}
	return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (lambda1 <= -4.1e+173)
		tmp = Float64(R * Float64(-Float64(cos(Float64(0.5 * phi2)) * lambda1)));
	elseif (lambda1 <= 3.6e+24)
		tmp = fma(Float64(-R), phi1, Float64(R * phi2));
	else
		tmp = Float64(Float64(lambda2 * cos(Float64(0.5 * phi1))) * R);
	end
	return tmp
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda1, -4.1e+173], N[(R * (-N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * lambda1), $MachinePrecision])), $MachinePrecision], If[LessEqual[lambda1, 3.6e+24], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision], N[(N[(lambda2 * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 \leq -4.1 \cdot 10^{+173}:\\
\;\;\;\;R \cdot \left(-\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1\right)\\

\mathbf{elif}\;\lambda_1 \leq 3.6 \cdot 10^{+24}:\\
\;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\

\mathbf{else}:\\
\;\;\;\;\left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot R\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if lambda1 < -4.09999999999999976e173

    1. Initial program 47.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -4.09999999999999976e173 < lambda1 < 3.59999999999999983e24

      1. Initial program 65.5%

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(\frac{R \cdot \phi_1}{\phi_2}, -1, R\right) \cdot \phi_2 \]
        7. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

      if 3.59999999999999983e24 < lambda1

      1. Initial program 52.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\lambda_2 \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right) - \sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)} \cdot R \]
      7. Applied rewrites12.6%

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

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

          \[\leadsto \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot R \]
      10. Recombined 3 regimes into one program.
      11. Add Preprocessing

      Alternative 6: 30.2% accurate, 2.2× speedup?

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

        1. Initial program 47.2%

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto R \cdot \left(-\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \lambda_1\right) \]
        6. Step-by-step derivation
          1. Applied rewrites51.6%

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

          if -3.1e170 < lambda1 < 3.59999999999999983e24

          1. Initial program 65.6%

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

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

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

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

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

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

              \[\leadsto \mathsf{fma}\left(\frac{R \cdot \phi_1}{\phi_2}, -1, R\right) \cdot \phi_2 \]
            7. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

          if 3.59999999999999983e24 < lambda1

          1. Initial program 52.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \color{blue}{\left(\lambda_2 \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right) - \sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)} \cdot R \]
          7. Applied rewrites12.6%

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

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

              \[\leadsto \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot R \]
          10. Recombined 3 regimes into one program.
          11. Add Preprocessing

          Alternative 7: 34.5% accurate, 2.3× speedup?

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

            1. Initial program 63.0%

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

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

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

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

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

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

                \[\leadsto \mathsf{fma}\left(\frac{R \cdot \phi_1}{\phi_2}, -1, R\right) \cdot \phi_2 \]
              7. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

            if 1.2600000000000001e135 < lambda2

            1. Initial program 45.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot R \]
            10. Recombined 2 regimes into one program.
            11. Add Preprocessing

            Alternative 8: 30.3% accurate, 8.2× speedup?

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

              1. Initial program 52.2%

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

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

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

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

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

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

                  \[\leadsto \mathsf{fma}\left(\frac{R \cdot \phi_1}{\phi_2}, -1, R\right) \cdot \phi_2 \]
                7. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

              if 2.7999999999999999e72 < R

              1. Initial program 95.3%

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

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

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

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

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

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

                  \[\leadsto \mathsf{fma}\left(\frac{R \cdot \phi_1}{\phi_2}, -1, R\right) \cdot \phi_2 \]
                7. *-commutativeN/A

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

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

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

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

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

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

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

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

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

            Alternative 9: 29.5% accurate, 8.2× speedup?

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

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

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

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

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

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

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

                  \[\leadsto \mathsf{fma}\left(\frac{R \cdot \phi_1}{\phi_2}, -1, R\right) \cdot \phi_2 \]
                7. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \mathsf{fma}\left(R, \frac{\phi_2}{\phi_1}, \mathsf{neg}\left(R\right)\right) \cdot \phi_1 \]
                8. lower-neg.f6420.5

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

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

              if -2.00000000000000015e70 < (-.f64 lambda1 lambda2)

              1. Initial program 64.0%

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

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

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

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

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

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

                  \[\leadsto \mathsf{fma}\left(\frac{R \cdot \phi_1}{\phi_2}, -1, R\right) \cdot \phi_2 \]
                7. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

            Alternative 10: 29.8% accurate, 8.5× speedup?

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

              1. Initial program 52.8%

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

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

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

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

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

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

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

                  \[\leadsto \mathsf{fma}\left(\frac{R \cdot \phi_1}{\phi_2}, -1, R\right) \cdot \phi_2 \]
                7. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

              if 1.35e95 < R

              1. Initial program 98.0%

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

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

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

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

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

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

                  \[\leadsto \mathsf{fma}\left(\frac{R \cdot \phi_1}{\phi_2}, -1, R\right) \cdot \phi_2 \]
                7. *-commutativeN/A

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

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

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

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

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

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

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

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

                  \[\leadsto \left(\left(-R\right) \cdot \left(\frac{\phi_1}{\phi_2} - 1\right)\right) \cdot \phi_2 \]
                6. lift-/.f6436.1

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

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

            Alternative 11: 28.4% accurate, 19.9× speedup?

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

              1. Initial program 54.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. mul-1-negN/A

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

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

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

              if -4.5e13 < phi1

              1. Initial program 62.4%

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

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

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

              Alternative 12: 29.5% accurate, 19.9× speedup?

              \[\begin{array}{l} \\ \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right) \end{array} \]
              (FPCore (R lambda1 lambda2 phi1 phi2)
               :precision binary64
               (fma (- R) phi1 (* R phi2)))
              double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
              	return fma(-R, phi1, (R * phi2));
              }
              
              function code(R, lambda1, lambda2, phi1, phi2)
              	return fma(Float64(-R), phi1, Float64(R * phi2))
              end
              
              code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision]
              
              \begin{array}{l}
              
              \\
              \mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)
              \end{array}
              
              Derivation
              1. Initial program 60.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. *-commutativeN/A

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

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

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

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

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

                  \[\leadsto \mathsf{fma}\left(\frac{R \cdot \phi_1}{\phi_2}, -1, R\right) \cdot \phi_2 \]
                7. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

              Alternative 13: 17.1% accurate, 46.5× speedup?

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

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

                Alternative 14: 17.1% accurate, 46.5× speedup?

                \[\begin{array}{l} \\ R \cdot \phi_1 \end{array} \]
                (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]
                
                \begin{array}{l}
                
                \\
                R \cdot \phi_1
                \end{array}
                
                Derivation
                1. Initial program 60.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}{\phi_1} \]
                3. Step-by-step derivation
                  1. Applied rewrites17.1%

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

                  Reproduce

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