Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.6% → 99.9%
Time: 10.2s
Alternatives: 17
Speedup: 2.6×

Specification

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

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

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

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

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 17 alternatives:

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

Initial Program: 60.6% 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.6× speedup?

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

\\
\mathsf{hypot}\left(\phi_2 - \phi_1, \mathsf{fma}\left(\sin \left(\phi_1 \cdot 0.5\right), \sin \left(-0.5 \cdot \phi_2\right), \cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \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.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. Step-by-step derivation
    1. lift-*.f64N/A

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

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

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

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

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

Alternative 2: 99.9% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \mathsf{hypot}\left(\phi_2 - \phi_1, \mathsf{fma}\left(\cos \left(\phi_1 \cdot 0.5\right), \cos \left(-0.5 \cdot \phi_2\right), \sin \left(\phi_1 \cdot 0.5\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
   (- phi2 phi1)
   (*
    (fma
     (cos (* phi1 0.5))
     (cos (* -0.5 phi2))
     (* (sin (* phi1 0.5)) (sin (* -0.5 phi2))))
    (- lambda1 lambda2)))
  R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return hypot((phi2 - phi1), (fma(cos((phi1 * 0.5)), cos((-0.5 * phi2)), (sin((phi1 * 0.5)) * sin((-0.5 * phi2)))) * (lambda1 - lambda2))) * R;
}
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(hypot(Float64(phi2 - phi1), Float64(fma(cos(Float64(phi1 * 0.5)), cos(Float64(-0.5 * phi2)), Float64(sin(Float64(phi1 * 0.5)) * sin(Float64(-0.5 * phi2)))) * Float64(lambda1 - lambda2))) * R)
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[Sqrt[N[(phi2 - phi1), $MachinePrecision] ^ 2 + N[(N[(N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision] + N[(N[Sin[N[(phi1 * 0.5), $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_2 - \phi_1, \mathsf{fma}\left(\cos \left(\phi_1 \cdot 0.5\right), \cos \left(-0.5 \cdot \phi_2\right), \sin \left(\phi_1 \cdot 0.5\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.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. Step-by-step derivation
    1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 96.8% accurate, 0.6× speedup?

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

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

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


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

    1. Initial program 60.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. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

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

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

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

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

      if -9.99999999999999961e225 < (-.f64 lambda1 lambda2)

      1. Initial program 60.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. Step-by-step derivation
        1. lift-*.f64N/A

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

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

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

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

    Alternative 4: 96.0% accurate, 1.7× speedup?

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

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

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

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

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

    Alternative 5: 93.5% accurate, 1.7× speedup?

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

      1. Initial program 60.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. Step-by-step derivation
        1. lift-*.f64N/A

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

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

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

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

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

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

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

      if -6.79999999999999948e-7 < phi1

      1. Initial program 60.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. Step-by-step derivation
        1. lift-*.f64N/A

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

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

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

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

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

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

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

    Alternative 6: 90.5% accurate, 1.8× speedup?

    \[\begin{array}{l} \\ \mathsf{hypot}\left(\phi_2 - \phi_1, \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 (- phi2 phi1) (* (cos (* -0.5 phi1)) (- lambda1 lambda2))) R))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	return hypot((phi2 - phi1), (cos((-0.5 * phi1)) * (lambda1 - lambda2))) * R;
    }
    
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	return Math.hypot((phi2 - phi1), (Math.cos((-0.5 * phi1)) * (lambda1 - lambda2))) * R;
    }
    
    def code(R, lambda1, lambda2, phi1, phi2):
    	return math.hypot((phi2 - phi1), (math.cos((-0.5 * phi1)) * (lambda1 - lambda2))) * R
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	return Float64(hypot(Float64(phi2 - phi1), Float64(cos(Float64(-0.5 * phi1)) * Float64(lambda1 - lambda2))) * R)
    end
    
    function tmp = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = hypot((phi2 - phi1), (cos((-0.5 * phi1)) * (lambda1 - lambda2))) * R;
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[Sqrt[N[(phi2 - phi1), $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_2 - \phi_1, \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.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. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

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

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

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

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

    Alternative 7: 75.2% accurate, 1.7× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.02 \cdot 10^{+93}:\\ \;\;\;\;-\mathsf{fma}\left(-R, \phi_2, R \cdot \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(\phi_2, \cos \left(-0.5 \cdot \phi_1\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 -1.02e+93)
       (- (fma (- R) phi2 (* R phi1)))
       (* (hypot phi2 (* (cos (* -0.5 phi1)) (- lambda1 lambda2))) R)))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (phi1 <= -1.02e+93) {
    		tmp = -fma(-R, phi2, (R * phi1));
    	} else {
    		tmp = hypot(phi2, (cos((-0.5 * phi1)) * (lambda1 - lambda2))) * R;
    	}
    	return tmp;
    }
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (phi1 <= -1.02e+93)
    		tmp = Float64(-fma(Float64(-R), phi2, Float64(R * phi1)));
    	else
    		tmp = Float64(hypot(phi2, Float64(cos(Float64(-0.5 * phi1)) * Float64(lambda1 - lambda2))) * R);
    	end
    	return tmp
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -1.02e+93], (-N[((-R) * phi2 + N[(R * phi1), $MachinePrecision]), $MachinePrecision]), N[(N[Sqrt[phi2 ^ 2 + N[(N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\phi_1 \leq -1.02 \cdot 10^{+93}:\\
    \;\;\;\;-\mathsf{fma}\left(-R, \phi_2, R \cdot \phi_1\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\mathsf{hypot}\left(\phi_2, \cos \left(-0.5 \cdot \phi_1\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 < -1.0200000000000001e93

      1. Initial program 60.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 phi1 around -inf

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto -1 \cdot \left(\phi_1 \cdot \mathsf{fma}\left(\mathsf{neg}\left(R \cdot \phi_2\right), \frac{1}{\phi_1}, R\right)\right) \]
        10. distribute-lft-neg-inN/A

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

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

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

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

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

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

          \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \mathsf{fma}\left(\left(-R\right) \cdot \phi_2, \frac{1}{\phi_1}, R\right)\right) \]
        3. lower-neg.f6430.2

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

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

          \[\leadsto -\phi_1 \cdot \left(\left(\left(-R\right) \cdot \phi_2\right) \cdot \frac{1}{\phi_1} + R\right) \]
        6. distribute-rgt-inN/A

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

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

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

          \[\leadsto -\left(\left(\left(-R\right) \cdot \phi_2\right) \cdot \left({\phi_1}^{-1} \cdot \phi_1\right) + R \cdot \phi_1\right) \]
        10. pow-plusN/A

          \[\leadsto -\left(\left(\left(-R\right) \cdot \phi_2\right) \cdot {\phi_1}^{\left(-1 + 1\right)} + R \cdot \phi_1\right) \]
        11. metadata-evalN/A

          \[\leadsto -\left(\left(\left(-R\right) \cdot \phi_2\right) \cdot {\phi_1}^{0} + R \cdot \phi_1\right) \]
        12. metadata-evalN/A

          \[\leadsto -\left(\left(\left(-R\right) \cdot \phi_2\right) \cdot 1 + R \cdot \phi_1\right) \]
        13. *-rgt-identityN/A

          \[\leadsto -\left(\left(-R\right) \cdot \phi_2 + R \cdot \phi_1\right) \]
        14. lift-*.f64N/A

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

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

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

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

      if -1.0200000000000001e93 < phi1

      1. Initial program 60.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. Step-by-step derivation
        1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

      Alternative 8: 74.0% accurate, 2.1× speedup?

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

        1. Initial program 60.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. Step-by-step derivation
          1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \mathsf{hypot}\left(\phi_2 - \phi_1, \left(\cos \left(0.5 \cdot \phi_1\right) + \phi_2 \cdot \mathsf{fma}\left(-0.5, \sin \left(0.5 \cdot \phi_1\right), -0.125 \cdot \left(\phi_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
        7. Applied rewrites73.5%

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

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

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

            \[\leadsto \mathsf{hypot}\left(\phi_2 - \phi_1, \left(1 + \frac{-1}{8} \cdot {\phi_2}^{\color{blue}{2}}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
          3. lower-pow.f6468.2

            \[\leadsto \mathsf{hypot}\left(\phi_2 - \phi_1, \left(1 + -0.125 \cdot {\phi_2}^{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
        10. Applied rewrites68.2%

          \[\leadsto \mathsf{hypot}\left(\phi_2 - \phi_1, \left(1 + \color{blue}{-0.125 \cdot {\phi_2}^{2}}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]

        if 6.7999999999999996e36 < phi2

        1. Initial program 60.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 phi1 around -inf

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto -1 \cdot \left(\phi_1 \cdot \mathsf{fma}\left(\mathsf{neg}\left(R \cdot \phi_2\right), \frac{1}{\phi_1}, R\right)\right) \]
          10. distribute-lft-neg-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto -1 \cdot \mathsf{fma}\left(\phi_1, R, \left(\left(-R\right) \cdot \phi_2\right) \cdot \left({\phi_1}^{-1} \cdot \phi_1\right)\right) \]
          10. pow-plusN/A

            \[\leadsto -1 \cdot \mathsf{fma}\left(\phi_1, R, \left(\left(-R\right) \cdot \phi_2\right) \cdot {\phi_1}^{\left(-1 + 1\right)}\right) \]
          11. metadata-evalN/A

            \[\leadsto -1 \cdot \mathsf{fma}\left(\phi_1, R, \left(\left(-R\right) \cdot \phi_2\right) \cdot {\phi_1}^{0}\right) \]
          12. metadata-evalN/A

            \[\leadsto -1 \cdot \mathsf{fma}\left(\phi_1, R, \left(\left(-R\right) \cdot \phi_2\right) \cdot 1\right) \]
          13. *-rgt-identity30.7

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

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

      Alternative 9: 60.8% accurate, 2.6× speedup?

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

        1. Initial program 60.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 phi1 around -inf

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto -1 \cdot \left(\phi_1 \cdot \mathsf{fma}\left(\mathsf{neg}\left(R \cdot \phi_2\right), \frac{1}{\phi_1}, R\right)\right) \]
          10. distribute-lft-neg-inN/A

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

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

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

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

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

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

            \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \mathsf{fma}\left(\left(-R\right) \cdot \phi_2, \frac{1}{\phi_1}, R\right)\right) \]
          3. lower-neg.f6430.2

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

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

            \[\leadsto -\phi_1 \cdot \left(\left(\left(-R\right) \cdot \phi_2\right) \cdot \frac{1}{\phi_1} + R\right) \]
          6. distribute-rgt-inN/A

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

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

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

            \[\leadsto -\left(\left(\left(-R\right) \cdot \phi_2\right) \cdot \left({\phi_1}^{-1} \cdot \phi_1\right) + R \cdot \phi_1\right) \]
          10. pow-plusN/A

            \[\leadsto -\left(\left(\left(-R\right) \cdot \phi_2\right) \cdot {\phi_1}^{\left(-1 + 1\right)} + R \cdot \phi_1\right) \]
          11. metadata-evalN/A

            \[\leadsto -\left(\left(\left(-R\right) \cdot \phi_2\right) \cdot {\phi_1}^{0} + R \cdot \phi_1\right) \]
          12. metadata-evalN/A

            \[\leadsto -\left(\left(\left(-R\right) \cdot \phi_2\right) \cdot 1 + R \cdot \phi_1\right) \]
          13. *-rgt-identityN/A

            \[\leadsto -\left(\left(-R\right) \cdot \phi_2 + R \cdot \phi_1\right) \]
          14. lift-*.f64N/A

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

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

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

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

        if -2.4999999999999999e98 < phi1 < 3.1999999999999998e-48

        1. Initial program 60.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 phi1 around 0

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + \frac{-1}{2} \cdot \left(\phi_1 \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)}\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \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. Step-by-step derivation
          1. lower-+.f64N/A

            \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + \color{blue}{\frac{-1}{2} \cdot \left(\phi_1 \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \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. lower-cos.f64N/A

            \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + \color{blue}{\frac{-1}{2}} \cdot \left(\phi_1 \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \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. lower-*.f64N/A

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

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

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

            \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + \frac{-1}{2} \cdot \left(\phi_1 \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
          7. lower-*.f6452.0

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

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

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

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

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

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

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

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

            \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + \frac{-1}{2} \cdot \left(\phi_1 \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + \frac{-1}{2} \cdot \left(\phi_1 \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
          7. lower-*.f6458.4

            \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_2\right) + -0.5 \cdot \left(\phi_1 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_2\right) + -0.5 \cdot \left(\phi_1 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        7. Applied rewrites58.4%

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

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

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

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

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

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

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

            \[\leadsto \mathsf{hypot}\left(\left(1 + \frac{-1}{4} \cdot \left(\phi_1 \cdot \color{blue}{\phi_2}\right)\right) \cdot \left(\lambda_2 - \lambda_1\right), \phi_1 - \phi_2\right) \cdot R \]
          3. lower-*.f6472.0

            \[\leadsto \mathsf{hypot}\left(\left(1 + -0.25 \cdot \left(\phi_1 \cdot \phi_2\right)\right) \cdot \left(\lambda_2 - \lambda_1\right), \phi_1 - \phi_2\right) \cdot R \]
        12. Applied rewrites72.0%

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

        if 3.1999999999999998e-48 < phi1

        1. Initial program 60.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 phi1 around -inf

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \mathsf{neg}\left(\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right) \cdot \phi_1\right) \]
          5. distribute-rgt-neg-inN/A

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

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

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

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

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

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

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

            \[\leadsto \left(R - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{R \cdot \phi_2}{\phi_1}\right)\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\phi_1\right)\right) \]
          13. distribute-neg-fracN/A

            \[\leadsto \left(R - \left(\mathsf{neg}\left(\frac{\mathsf{neg}\left(R \cdot \phi_2\right)}{\phi_1}\right)\right)\right) \cdot \left(\mathsf{neg}\left(\phi_1\right)\right) \]
          14. distribute-frac-neg2N/A

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

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

            \[\leadsto \left(R - \frac{R \cdot \phi_2}{\phi_1}\right) \cdot \left(\mathsf{neg}\left(\phi_1\right)\right) \]
          17. lower-neg.f6430.2

            \[\leadsto \left(R - \frac{R \cdot \phi_2}{\phi_1}\right) \cdot \left(-\phi_1\right) \]
        6. Applied rewrites30.2%

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

      Alternative 10: 48.6% accurate, 0.8× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\\ t_1 := \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\\ t_2 := \left(\lambda_1 - \lambda_2\right) \cdot 1\\ \mathbf{if}\;\sqrt{t\_1 \cdot t\_1 + t\_0} \leq 2 \cdot 10^{+154}:\\ \;\;\;\;R \cdot \sqrt{t\_2 \cdot t\_2 + t\_0}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \left(\phi_1 \cdot \left(\phi_2 \cdot \mathsf{fma}\left(-1, \frac{R}{\phi_1}, \frac{R}{\phi_2}\right)\right)\right)\\ \end{array} \end{array} \]
      (FPCore (R lambda1 lambda2 phi1 phi2)
       :precision binary64
       (let* ((t_0 (* (- phi1 phi2) (- phi1 phi2)))
              (t_1 (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0))))
              (t_2 (* (- lambda1 lambda2) 1.0)))
         (if (<= (sqrt (+ (* t_1 t_1) t_0)) 2e+154)
           (* R (sqrt (+ (* t_2 t_2) t_0)))
           (* -1.0 (* phi1 (* phi2 (fma -1.0 (/ R phi1) (/ R phi2))))))))
      double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	double t_0 = (phi1 - phi2) * (phi1 - phi2);
      	double t_1 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0));
      	double t_2 = (lambda1 - lambda2) * 1.0;
      	double tmp;
      	if (sqrt(((t_1 * t_1) + t_0)) <= 2e+154) {
      		tmp = R * sqrt(((t_2 * t_2) + t_0));
      	} else {
      		tmp = -1.0 * (phi1 * (phi2 * fma(-1.0, (R / phi1), (R / phi2))));
      	}
      	return tmp;
      }
      
      function code(R, lambda1, lambda2, phi1, phi2)
      	t_0 = Float64(Float64(phi1 - phi2) * Float64(phi1 - phi2))
      	t_1 = Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi1 + phi2) / 2.0)))
      	t_2 = Float64(Float64(lambda1 - lambda2) * 1.0)
      	tmp = 0.0
      	if (sqrt(Float64(Float64(t_1 * t_1) + t_0)) <= 2e+154)
      		tmp = Float64(R * sqrt(Float64(Float64(t_2 * t_2) + t_0)));
      	else
      		tmp = Float64(-1.0 * Float64(phi1 * Float64(phi2 * fma(-1.0, Float64(R / phi1), Float64(R / phi2)))));
      	end
      	return tmp
      end
      
      code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(phi1 - phi2), $MachinePrecision] * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(N[(phi1 + phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(lambda1 - lambda2), $MachinePrecision] * 1.0), $MachinePrecision]}, If[LessEqual[N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision], 2e+154], N[(R * N[Sqrt[N[(N[(t$95$2 * t$95$2), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(phi1 * N[(phi2 * N[(-1.0 * N[(R / phi1), $MachinePrecision] + N[(R / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\\
      t_1 := \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\\
      t_2 := \left(\lambda_1 - \lambda_2\right) \cdot 1\\
      \mathbf{if}\;\sqrt{t\_1 \cdot t\_1 + t\_0} \leq 2 \cdot 10^{+154}:\\
      \;\;\;\;R \cdot \sqrt{t\_2 \cdot t\_2 + t\_0}\\
      
      \mathbf{else}:\\
      \;\;\;\;-1 \cdot \left(\phi_1 \cdot \left(\phi_2 \cdot \mathsf{fma}\left(-1, \frac{R}{\phi_1}, \frac{R}{\phi_2}\right)\right)\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (sqrt.f64 (+.f64 (*.f64 (*.f64 (-.f64 lambda1 lambda2) (cos.f64 (/.f64 (+.f64 phi1 phi2) #s(literal 2 binary64)))) (*.f64 (-.f64 lambda1 lambda2) (cos.f64 (/.f64 (+.f64 phi1 phi2) #s(literal 2 binary64))))) (*.f64 (-.f64 phi1 phi2) (-.f64 phi1 phi2)))) < 2.00000000000000007e154

        1. Initial program 60.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 phi1 around 0

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + \frac{-1}{2} \cdot \left(\phi_1 \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)}\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \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. Step-by-step derivation
          1. lower-+.f64N/A

            \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + \color{blue}{\frac{-1}{2} \cdot \left(\phi_1 \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \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. lower-cos.f64N/A

            \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + \color{blue}{\frac{-1}{2}} \cdot \left(\phi_1 \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \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. lower-*.f64N/A

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

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

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

            \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + \frac{-1}{2} \cdot \left(\phi_1 \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
          7. lower-*.f6452.0

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

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

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

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

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

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

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

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

            \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + \frac{-1}{2} \cdot \left(\phi_1 \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + \frac{-1}{2} \cdot \left(\phi_1 \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
          7. lower-*.f6458.4

            \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_2\right) + -0.5 \cdot \left(\phi_1 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_2\right) + -0.5 \cdot \left(\phi_1 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        7. Applied rewrites58.4%

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

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot 1\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + \frac{-1}{2} \cdot \left(\phi_1 \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        9. Step-by-step derivation
          1. Applied rewrites49.0%

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

            \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot 1\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot 1\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
          3. Step-by-step derivation
            1. Applied rewrites57.8%

              \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot 1\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot 1\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]

            if 2.00000000000000007e154 < (sqrt.f64 (+.f64 (*.f64 (*.f64 (-.f64 lambda1 lambda2) (cos.f64 (/.f64 (+.f64 phi1 phi2) #s(literal 2 binary64)))) (*.f64 (-.f64 lambda1 lambda2) (cos.f64 (/.f64 (+.f64 phi1 phi2) #s(literal 2 binary64))))) (*.f64 (-.f64 phi1 phi2) (-.f64 phi1 phi2))))

            1. Initial program 60.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 phi1 around -inf

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          Alternative 11: 31.3% accurate, 3.8× speedup?

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

            1. Initial program 60.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 phi1 around -inf

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if -3.80000000000000035e227 < (-.f64 lambda1 lambda2)

            1. Initial program 60.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 phi1 around -inf

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto -1 \cdot \left(\phi_1 \cdot \mathsf{fma}\left(\mathsf{neg}\left(R \cdot \phi_2\right), \frac{1}{\phi_1}, R\right)\right) \]
              10. distribute-lft-neg-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto -1 \cdot \mathsf{fma}\left(\phi_1, R, \left(\left(-R\right) \cdot \phi_2\right) \cdot \left({\phi_1}^{-1} \cdot \phi_1\right)\right) \]
              10. pow-plusN/A

                \[\leadsto -1 \cdot \mathsf{fma}\left(\phi_1, R, \left(\left(-R\right) \cdot \phi_2\right) \cdot {\phi_1}^{\left(-1 + 1\right)}\right) \]
              11. metadata-evalN/A

                \[\leadsto -1 \cdot \mathsf{fma}\left(\phi_1, R, \left(\left(-R\right) \cdot \phi_2\right) \cdot {\phi_1}^{0}\right) \]
              12. metadata-evalN/A

                \[\leadsto -1 \cdot \mathsf{fma}\left(\phi_1, R, \left(\left(-R\right) \cdot \phi_2\right) \cdot 1\right) \]
              13. *-rgt-identity30.7

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

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

          Alternative 12: 31.1% accurate, 4.8× speedup?

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

            1. Initial program 60.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. lower-*.f64N/A

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

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

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

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

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

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

            if -5e228 < (-.f64 lambda1 lambda2)

            1. Initial program 60.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 phi1 around -inf

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto -1 \cdot \left(\phi_1 \cdot \mathsf{fma}\left(\mathsf{neg}\left(R \cdot \phi_2\right), \frac{1}{\phi_1}, R\right)\right) \]
              10. distribute-lft-neg-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto -1 \cdot \mathsf{fma}\left(\phi_1, R, \left(\left(-R\right) \cdot \phi_2\right) \cdot \left({\phi_1}^{-1} \cdot \phi_1\right)\right) \]
              10. pow-plusN/A

                \[\leadsto -1 \cdot \mathsf{fma}\left(\phi_1, R, \left(\left(-R\right) \cdot \phi_2\right) \cdot {\phi_1}^{\left(-1 + 1\right)}\right) \]
              11. metadata-evalN/A

                \[\leadsto -1 \cdot \mathsf{fma}\left(\phi_1, R, \left(\left(-R\right) \cdot \phi_2\right) \cdot {\phi_1}^{0}\right) \]
              12. metadata-evalN/A

                \[\leadsto -1 \cdot \mathsf{fma}\left(\phi_1, R, \left(\left(-R\right) \cdot \phi_2\right) \cdot 1\right) \]
              13. *-rgt-identity30.7

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

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

          Alternative 13: 30.7% accurate, 8.3× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto -1 \cdot \left(\phi_1 \cdot \mathsf{fma}\left(\mathsf{neg}\left(R \cdot \phi_2\right), \frac{1}{\phi_1}, R\right)\right) \]
            10. distribute-lft-neg-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto -1 \cdot \mathsf{fma}\left(\phi_1, R, \left(\left(-R\right) \cdot \phi_2\right) \cdot \left({\phi_1}^{-1} \cdot \phi_1\right)\right) \]
            10. pow-plusN/A

              \[\leadsto -1 \cdot \mathsf{fma}\left(\phi_1, R, \left(\left(-R\right) \cdot \phi_2\right) \cdot {\phi_1}^{\left(-1 + 1\right)}\right) \]
            11. metadata-evalN/A

              \[\leadsto -1 \cdot \mathsf{fma}\left(\phi_1, R, \left(\left(-R\right) \cdot \phi_2\right) \cdot {\phi_1}^{0}\right) \]
            12. metadata-evalN/A

              \[\leadsto -1 \cdot \mathsf{fma}\left(\phi_1, R, \left(\left(-R\right) \cdot \phi_2\right) \cdot 1\right) \]
            13. *-rgt-identity30.7

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

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

          Alternative 14: 30.7% accurate, 9.8× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto -1 \cdot \left(\phi_1 \cdot \mathsf{fma}\left(\mathsf{neg}\left(R \cdot \phi_2\right), \frac{1}{\phi_1}, R\right)\right) \]
            10. distribute-lft-neg-inN/A

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

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

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

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

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

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

              \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \mathsf{fma}\left(\left(-R\right) \cdot \phi_2, \frac{1}{\phi_1}, R\right)\right) \]
            3. lower-neg.f6430.2

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

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

              \[\leadsto -\phi_1 \cdot \left(\left(\left(-R\right) \cdot \phi_2\right) \cdot \frac{1}{\phi_1} + R\right) \]
            6. distribute-rgt-inN/A

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

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

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

              \[\leadsto -\left(\left(\left(-R\right) \cdot \phi_2\right) \cdot \left({\phi_1}^{-1} \cdot \phi_1\right) + R \cdot \phi_1\right) \]
            10. pow-plusN/A

              \[\leadsto -\left(\left(\left(-R\right) \cdot \phi_2\right) \cdot {\phi_1}^{\left(-1 + 1\right)} + R \cdot \phi_1\right) \]
            11. metadata-evalN/A

              \[\leadsto -\left(\left(\left(-R\right) \cdot \phi_2\right) \cdot {\phi_1}^{0} + R \cdot \phi_1\right) \]
            12. metadata-evalN/A

              \[\leadsto -\left(\left(\left(-R\right) \cdot \phi_2\right) \cdot 1 + R \cdot \phi_1\right) \]
            13. *-rgt-identityN/A

              \[\leadsto -\left(\left(-R\right) \cdot \phi_2 + R \cdot \phi_1\right) \]
            14. lift-*.f64N/A

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

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

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

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

          Alternative 15: 29.5% accurate, 10.0× speedup?

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

            1. Initial program 60.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 phi1 around -inf

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

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

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

            if -3.8000000000000004e22 < phi1

            1. Initial program 60.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}{R \cdot \phi_2} \]
            3. Step-by-step derivation
              1. lower-*.f6418.1

                \[\leadsto R \cdot \color{blue}{\phi_2} \]
            4. Applied rewrites18.1%

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

          Alternative 16: 18.1% accurate, 27.0× 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.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}{R \cdot \phi_2} \]
          3. Step-by-step derivation
            1. lower-*.f6418.1

              \[\leadsto R \cdot \color{blue}{\phi_2} \]
          4. Applied rewrites18.1%

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

          Alternative 17: 17.6% accurate, 27.0× 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.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 phi1 around inf

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

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

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

          Reproduce

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