Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.2% → 95.8%
Time: 14.7s
Alternatives: 13
Speedup: N/A×

Specification

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

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

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 13 alternatives:

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

Initial Program: 60.2% accurate, 1.0× speedup?

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

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

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

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

Alternative 1: 95.8% accurate, N/A× speedup?

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

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

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

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

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

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

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

Alternative 2: 92.2% accurate, N/A× speedup?

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

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

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


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

    1. Initial program 46.4%

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

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

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

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

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

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

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

      if -1e3 < phi1

      1. Initial program 61.4%

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

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

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

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

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

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

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

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

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

    Alternative 3: 90.4% accurate, N/A× speedup?

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

      1. Initial program 43.9%

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

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

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

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

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

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \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)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      6. Step-by-step derivation
        1. fp-cancel-sign-sub-invN/A

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

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

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

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

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

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \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) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
        7. lower-*.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \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) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
        8. lower-sin.f64N/A

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \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) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
        9. lift-*.f6460.4

          \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \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) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      7. Applied rewrites60.4%

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, \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)} \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      8. Taylor expanded in phi2 around 0

        \[\leadsto \mathsf{hypot}\left(\phi_1 - \phi_2, 1 \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
      9. Step-by-step derivation
        1. Applied rewrites86.6%

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

        if -9.1999999999999996e177 < phi1

        1. Initial program 59.4%

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

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

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

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

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

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

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

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

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

      Alternative 4: 89.1% accurate, N/A× speedup?

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

        1. Initial program 44.0%

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

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

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

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

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

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

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

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

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

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

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

        if -1.5499999999999999e228 < phi1

        1. Initial program 58.3%

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

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

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

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

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

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

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

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

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

      Alternative 5: 40.9% accurate, N/A× 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)\\ t_1 := \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\\ t_2 := \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\\ \mathbf{if}\;\phi_2 \leq -4.2 \cdot 10^{-87}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\phi_1 \cdot R}{\phi_2}, -1, R\right) \cdot \phi_2\\ \mathbf{elif}\;\phi_2 \leq -5 \cdot 10^{-213}:\\ \;\;\;\;R \cdot \sqrt{{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + t\_2}\\ \mathbf{elif}\;\phi_2 \leq 8.2 \cdot 10^{-28}:\\ \;\;\;\;\mathsf{fma}\left(t\_1, R, \frac{\left(R \cdot \lambda_2\right) \cdot t\_1}{-\lambda_1}\right) \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\phi_2 \leq 1.8 \cdot 10^{+135}:\\ \;\;\;\;R \cdot \sqrt{t\_0 \cdot t\_0 + t\_2}\\ \mathbf{else}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right)\\ \end{array} \end{array} \]
      (FPCore (R lambda1 lambda2 phi1 phi2)
       :precision binary64
       (let* ((t_0 (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0))))
              (t_1 (cos (* 0.5 (+ phi2 phi1))))
              (t_2 (* (- phi1 phi2) (- phi1 phi2))))
         (if (<= phi2 -4.2e-87)
           (* (fma (/ (* phi1 R) phi2) -1.0 R) phi2)
           (if (<= phi2 -5e-213)
             (*
              R
              (sqrt (+ (pow (* (cos (* 0.5 phi1)) (- lambda1 lambda2)) 2.0) t_2)))
             (if (<= phi2 8.2e-28)
               (* (fma t_1 R (/ (* (* R lambda2) t_1) (- lambda1))) (- lambda1))
               (if (<= phi2 1.8e+135)
                 (* R (sqrt (+ (* t_0 t_0) t_2)))
                 (* (- phi1) (fma (/ (* phi2 R) phi1) -1.0 R))))))))
      double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	double t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0));
      	double t_1 = cos((0.5 * (phi2 + phi1)));
      	double t_2 = (phi1 - phi2) * (phi1 - phi2);
      	double tmp;
      	if (phi2 <= -4.2e-87) {
      		tmp = fma(((phi1 * R) / phi2), -1.0, R) * phi2;
      	} else if (phi2 <= -5e-213) {
      		tmp = R * sqrt((pow((cos((0.5 * phi1)) * (lambda1 - lambda2)), 2.0) + t_2));
      	} else if (phi2 <= 8.2e-28) {
      		tmp = fma(t_1, R, (((R * lambda2) * t_1) / -lambda1)) * -lambda1;
      	} else if (phi2 <= 1.8e+135) {
      		tmp = R * sqrt(((t_0 * t_0) + t_2));
      	} else {
      		tmp = -phi1 * fma(((phi2 * R) / phi1), -1.0, R);
      	}
      	return tmp;
      }
      
      function code(R, lambda1, lambda2, phi1, phi2)
      	t_0 = Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi1 + phi2) / 2.0)))
      	t_1 = cos(Float64(0.5 * Float64(phi2 + phi1)))
      	t_2 = Float64(Float64(phi1 - phi2) * Float64(phi1 - phi2))
      	tmp = 0.0
      	if (phi2 <= -4.2e-87)
      		tmp = Float64(fma(Float64(Float64(phi1 * R) / phi2), -1.0, R) * phi2);
      	elseif (phi2 <= -5e-213)
      		tmp = Float64(R * sqrt(Float64((Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2)) ^ 2.0) + t_2)));
      	elseif (phi2 <= 8.2e-28)
      		tmp = Float64(fma(t_1, R, Float64(Float64(Float64(R * lambda2) * t_1) / Float64(-lambda1))) * Float64(-lambda1));
      	elseif (phi2 <= 1.8e+135)
      		tmp = Float64(R * sqrt(Float64(Float64(t_0 * t_0) + t_2)));
      	else
      		tmp = Float64(Float64(-phi1) * fma(Float64(Float64(phi2 * R) / phi1), -1.0, R));
      	end
      	return tmp
      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]}, Block[{t$95$1 = N[Cos[N[(0.5 * N[(phi2 + phi1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[(phi1 - phi2), $MachinePrecision] * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -4.2e-87], N[(N[(N[(N[(phi1 * R), $MachinePrecision] / phi2), $MachinePrecision] * -1.0 + R), $MachinePrecision] * phi2), $MachinePrecision], If[LessEqual[phi2, -5e-213], N[(R * N[Sqrt[N[(N[Power[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 8.2e-28], N[(N[(t$95$1 * R + N[(N[(N[(R * lambda2), $MachinePrecision] * t$95$1), $MachinePrecision] / (-lambda1)), $MachinePrecision]), $MachinePrecision] * (-lambda1)), $MachinePrecision], If[LessEqual[phi2, 1.8e+135], N[(R * N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[((-phi1) * N[(N[(N[(phi2 * R), $MachinePrecision] / phi1), $MachinePrecision] * -1.0 + R), $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)\\
      t_1 := \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\\
      t_2 := \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\\
      \mathbf{if}\;\phi_2 \leq -4.2 \cdot 10^{-87}:\\
      \;\;\;\;\mathsf{fma}\left(\frac{\phi_1 \cdot R}{\phi_2}, -1, R\right) \cdot \phi_2\\
      
      \mathbf{elif}\;\phi_2 \leq -5 \cdot 10^{-213}:\\
      \;\;\;\;R \cdot \sqrt{{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + t\_2}\\
      
      \mathbf{elif}\;\phi_2 \leq 8.2 \cdot 10^{-28}:\\
      \;\;\;\;\mathsf{fma}\left(t\_1, R, \frac{\left(R \cdot \lambda_2\right) \cdot t\_1}{-\lambda_1}\right) \cdot \left(-\lambda_1\right)\\
      
      \mathbf{elif}\;\phi_2 \leq 1.8 \cdot 10^{+135}:\\
      \;\;\;\;R \cdot \sqrt{t\_0 \cdot t\_0 + t\_2}\\
      
      \mathbf{else}:\\
      \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 5 regimes
      2. if phi2 < -4.20000000000000014e-87

        1. Initial program 49.5%

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

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

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

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

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

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

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

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

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

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

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

        if -4.20000000000000014e-87 < phi2 < -4.99999999999999977e-213

        1. Initial program 71.0%

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

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

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

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

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

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

            \[\leadsto R \cdot \sqrt{{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
          6. lift--.f6471.0

            \[\leadsto R \cdot \sqrt{{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        5. Applied rewrites71.0%

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

        if -4.99999999999999977e-213 < phi2 < 8.2000000000000005e-28

        1. Initial program 59.1%

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

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

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

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

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

            \[\leadsto -\left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1} + R \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right) \cdot \lambda_1 \]
        5. Applied rewrites38.5%

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

        if 8.2000000000000005e-28 < phi2 < 1.7999999999999999e135

        1. Initial program 59.9%

          \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        2. Add Preprocessing

        if 1.7999999999999999e135 < phi2

        1. Initial program 54.0%

          \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        2. Add Preprocessing
        3. Taylor expanded in 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)} \]
        4. Step-by-step derivation
          1. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -4.2 \cdot 10^{-87}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\phi_1 \cdot R}{\phi_2}, -1, R\right) \cdot \phi_2\\ \mathbf{elif}\;\phi_2 \leq -5 \cdot 10^{-213}:\\ \;\;\;\;R \cdot \sqrt{{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\\ \mathbf{elif}\;\phi_2 \leq 8.2 \cdot 10^{-28}:\\ \;\;\;\;\mathsf{fma}\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right), R, \frac{\left(R \cdot \lambda_2\right) \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)}{-\lambda_1}\right) \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\phi_2 \leq 1.8 \cdot 10^{+135}:\\ \;\;\;\;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)}\\ \mathbf{else}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right)\\ \end{array} \]
      5. Add Preprocessing

      Alternative 6: 40.1% accurate, N/A× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := R \cdot \sqrt{{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\\ t_1 := \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\\ \mathbf{if}\;\phi_2 \leq -4.2 \cdot 10^{-87}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\phi_1 \cdot R}{\phi_2}, -1, R\right) \cdot \phi_2\\ \mathbf{elif}\;\phi_2 \leq -5 \cdot 10^{-213}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_2 \leq 8.2 \cdot 10^{-28}:\\ \;\;\;\;\mathsf{fma}\left(t\_1, R, \frac{\left(R \cdot \lambda_2\right) \cdot t\_1}{-\lambda_1}\right) \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\phi_2 \leq 1.8 \cdot 10^{+135}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right)\\ \end{array} \end{array} \]
      (FPCore (R lambda1 lambda2 phi1 phi2)
       :precision binary64
       (let* ((t_0
               (*
                R
                (sqrt
                 (+
                  (pow (* (cos (* 0.5 phi1)) (- lambda1 lambda2)) 2.0)
                  (* (- phi1 phi2) (- phi1 phi2))))))
              (t_1 (cos (* 0.5 (+ phi2 phi1)))))
         (if (<= phi2 -4.2e-87)
           (* (fma (/ (* phi1 R) phi2) -1.0 R) phi2)
           (if (<= phi2 -5e-213)
             t_0
             (if (<= phi2 8.2e-28)
               (* (fma t_1 R (/ (* (* R lambda2) t_1) (- lambda1))) (- lambda1))
               (if (<= phi2 1.8e+135)
                 t_0
                 (* (- phi1) (fma (/ (* phi2 R) phi1) -1.0 R))))))))
      double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	double t_0 = R * sqrt((pow((cos((0.5 * phi1)) * (lambda1 - lambda2)), 2.0) + ((phi1 - phi2) * (phi1 - phi2))));
      	double t_1 = cos((0.5 * (phi2 + phi1)));
      	double tmp;
      	if (phi2 <= -4.2e-87) {
      		tmp = fma(((phi1 * R) / phi2), -1.0, R) * phi2;
      	} else if (phi2 <= -5e-213) {
      		tmp = t_0;
      	} else if (phi2 <= 8.2e-28) {
      		tmp = fma(t_1, R, (((R * lambda2) * t_1) / -lambda1)) * -lambda1;
      	} else if (phi2 <= 1.8e+135) {
      		tmp = t_0;
      	} else {
      		tmp = -phi1 * fma(((phi2 * R) / phi1), -1.0, R);
      	}
      	return tmp;
      }
      
      function code(R, lambda1, lambda2, phi1, phi2)
      	t_0 = Float64(R * sqrt(Float64((Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2)) ^ 2.0) + Float64(Float64(phi1 - phi2) * Float64(phi1 - phi2)))))
      	t_1 = cos(Float64(0.5 * Float64(phi2 + phi1)))
      	tmp = 0.0
      	if (phi2 <= -4.2e-87)
      		tmp = Float64(fma(Float64(Float64(phi1 * R) / phi2), -1.0, R) * phi2);
      	elseif (phi2 <= -5e-213)
      		tmp = t_0;
      	elseif (phi2 <= 8.2e-28)
      		tmp = Float64(fma(t_1, R, Float64(Float64(Float64(R * lambda2) * t_1) / Float64(-lambda1))) * Float64(-lambda1));
      	elseif (phi2 <= 1.8e+135)
      		tmp = t_0;
      	else
      		tmp = Float64(Float64(-phi1) * fma(Float64(Float64(phi2 * R) / phi1), -1.0, R));
      	end
      	return tmp
      end
      
      code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(R * N[Sqrt[N[(N[Power[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(phi1 - phi2), $MachinePrecision] * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(0.5 * N[(phi2 + phi1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -4.2e-87], N[(N[(N[(N[(phi1 * R), $MachinePrecision] / phi2), $MachinePrecision] * -1.0 + R), $MachinePrecision] * phi2), $MachinePrecision], If[LessEqual[phi2, -5e-213], t$95$0, If[LessEqual[phi2, 8.2e-28], N[(N[(t$95$1 * R + N[(N[(N[(R * lambda2), $MachinePrecision] * t$95$1), $MachinePrecision] / (-lambda1)), $MachinePrecision]), $MachinePrecision] * (-lambda1)), $MachinePrecision], If[LessEqual[phi2, 1.8e+135], t$95$0, N[((-phi1) * N[(N[(N[(phi2 * R), $MachinePrecision] / phi1), $MachinePrecision] * -1.0 + R), $MachinePrecision]), $MachinePrecision]]]]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := R \cdot \sqrt{{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\\
      t_1 := \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\\
      \mathbf{if}\;\phi_2 \leq -4.2 \cdot 10^{-87}:\\
      \;\;\;\;\mathsf{fma}\left(\frac{\phi_1 \cdot R}{\phi_2}, -1, R\right) \cdot \phi_2\\
      
      \mathbf{elif}\;\phi_2 \leq -5 \cdot 10^{-213}:\\
      \;\;\;\;t\_0\\
      
      \mathbf{elif}\;\phi_2 \leq 8.2 \cdot 10^{-28}:\\
      \;\;\;\;\mathsf{fma}\left(t\_1, R, \frac{\left(R \cdot \lambda_2\right) \cdot t\_1}{-\lambda_1}\right) \cdot \left(-\lambda_1\right)\\
      
      \mathbf{elif}\;\phi_2 \leq 1.8 \cdot 10^{+135}:\\
      \;\;\;\;t\_0\\
      
      \mathbf{else}:\\
      \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 4 regimes
      2. if phi2 < -4.20000000000000014e-87

        1. Initial program 49.5%

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

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

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

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

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

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

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

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

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

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

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

        if -4.20000000000000014e-87 < phi2 < -4.99999999999999977e-213 or 8.2000000000000005e-28 < phi2 < 1.7999999999999999e135

        1. Initial program 64.6%

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

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

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

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

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

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

            \[\leadsto R \cdot \sqrt{{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
          6. lift--.f6463.5

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

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

        if -4.99999999999999977e-213 < phi2 < 8.2000000000000005e-28

        1. Initial program 59.1%

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

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

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

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

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

            \[\leadsto -\left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1} + R \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right) \cdot \lambda_1 \]
        5. Applied rewrites38.5%

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

        if 1.7999999999999999e135 < phi2

        1. Initial program 54.0%

          \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        2. Add Preprocessing
        3. Taylor expanded in 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)} \]
        4. Step-by-step derivation
          1. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -4.2 \cdot 10^{-87}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\phi_1 \cdot R}{\phi_2}, -1, R\right) \cdot \phi_2\\ \mathbf{elif}\;\phi_2 \leq -5 \cdot 10^{-213}:\\ \;\;\;\;R \cdot \sqrt{{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\\ \mathbf{elif}\;\phi_2 \leq 8.2 \cdot 10^{-28}:\\ \;\;\;\;\mathsf{fma}\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right), R, \frac{\left(R \cdot \lambda_2\right) \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)}{-\lambda_1}\right) \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\phi_2 \leq 1.8 \cdot 10^{+135}:\\ \;\;\;\;R \cdot \sqrt{{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\\ \mathbf{else}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right)\\ \end{array} \]
      5. Add Preprocessing

      Alternative 7: 34.9% accurate, N/A× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\\ \mathbf{if}\;\phi_2 \leq -2.2 \cdot 10^{-211}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\phi_1 \cdot R}{\phi_2}, -1, R\right) \cdot \phi_2\\ \mathbf{elif}\;\phi_2 \leq 2.1 \cdot 10^{-20}:\\ \;\;\;\;\mathsf{fma}\left(t\_0, R, \frac{\left(R \cdot \lambda_2\right) \cdot t\_0}{-\lambda_1}\right) \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\phi_2 \leq 1.8 \cdot 10^{+135}:\\ \;\;\;\;R \cdot \sqrt{\mathsf{fma}\left(\phi_2, \phi_2, {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right)}\\ \mathbf{else}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right)\\ \end{array} \end{array} \]
      (FPCore (R lambda1 lambda2 phi1 phi2)
       :precision binary64
       (let* ((t_0 (cos (* 0.5 (+ phi2 phi1)))))
         (if (<= phi2 -2.2e-211)
           (* (fma (/ (* phi1 R) phi2) -1.0 R) phi2)
           (if (<= phi2 2.1e-20)
             (* (fma t_0 R (/ (* (* R lambda2) t_0) (- lambda1))) (- lambda1))
             (if (<= phi2 1.8e+135)
               (*
                R
                (sqrt
                 (fma
                  phi2
                  phi2
                  (pow (* (cos (* 0.5 phi2)) (- lambda1 lambda2)) 2.0))))
               (* (- phi1) (fma (/ (* phi2 R) phi1) -1.0 R)))))))
      double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	double t_0 = cos((0.5 * (phi2 + phi1)));
      	double tmp;
      	if (phi2 <= -2.2e-211) {
      		tmp = fma(((phi1 * R) / phi2), -1.0, R) * phi2;
      	} else if (phi2 <= 2.1e-20) {
      		tmp = fma(t_0, R, (((R * lambda2) * t_0) / -lambda1)) * -lambda1;
      	} else if (phi2 <= 1.8e+135) {
      		tmp = R * sqrt(fma(phi2, phi2, pow((cos((0.5 * phi2)) * (lambda1 - lambda2)), 2.0)));
      	} else {
      		tmp = -phi1 * fma(((phi2 * R) / phi1), -1.0, R);
      	}
      	return tmp;
      }
      
      function code(R, lambda1, lambda2, phi1, phi2)
      	t_0 = cos(Float64(0.5 * Float64(phi2 + phi1)))
      	tmp = 0.0
      	if (phi2 <= -2.2e-211)
      		tmp = Float64(fma(Float64(Float64(phi1 * R) / phi2), -1.0, R) * phi2);
      	elseif (phi2 <= 2.1e-20)
      		tmp = Float64(fma(t_0, R, Float64(Float64(Float64(R * lambda2) * t_0) / Float64(-lambda1))) * Float64(-lambda1));
      	elseif (phi2 <= 1.8e+135)
      		tmp = Float64(R * sqrt(fma(phi2, phi2, (Float64(cos(Float64(0.5 * phi2)) * Float64(lambda1 - lambda2)) ^ 2.0))));
      	else
      		tmp = Float64(Float64(-phi1) * fma(Float64(Float64(phi2 * R) / phi1), -1.0, R));
      	end
      	return tmp
      end
      
      code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(0.5 * N[(phi2 + phi1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -2.2e-211], N[(N[(N[(N[(phi1 * R), $MachinePrecision] / phi2), $MachinePrecision] * -1.0 + R), $MachinePrecision] * phi2), $MachinePrecision], If[LessEqual[phi2, 2.1e-20], N[(N[(t$95$0 * R + N[(N[(N[(R * lambda2), $MachinePrecision] * t$95$0), $MachinePrecision] / (-lambda1)), $MachinePrecision]), $MachinePrecision] * (-lambda1)), $MachinePrecision], If[LessEqual[phi2, 1.8e+135], N[(R * N[Sqrt[N[(phi2 * phi2 + N[Power[N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[((-phi1) * N[(N[(N[(phi2 * R), $MachinePrecision] / phi1), $MachinePrecision] * -1.0 + R), $MachinePrecision]), $MachinePrecision]]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\\
      \mathbf{if}\;\phi_2 \leq -2.2 \cdot 10^{-211}:\\
      \;\;\;\;\mathsf{fma}\left(\frac{\phi_1 \cdot R}{\phi_2}, -1, R\right) \cdot \phi_2\\
      
      \mathbf{elif}\;\phi_2 \leq 2.1 \cdot 10^{-20}:\\
      \;\;\;\;\mathsf{fma}\left(t\_0, R, \frac{\left(R \cdot \lambda_2\right) \cdot t\_0}{-\lambda_1}\right) \cdot \left(-\lambda_1\right)\\
      
      \mathbf{elif}\;\phi_2 \leq 1.8 \cdot 10^{+135}:\\
      \;\;\;\;R \cdot \sqrt{\mathsf{fma}\left(\phi_2, \phi_2, {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right)}\\
      
      \mathbf{else}:\\
      \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 4 regimes
      2. if phi2 < -2.19999999999999998e-211

        1. Initial program 54.8%

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

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

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

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

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

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

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

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

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

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

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

        if -2.19999999999999998e-211 < phi2 < 2.0999999999999999e-20

        1. Initial program 59.5%

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

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

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

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

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

            \[\leadsto -\left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1} + R \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right) \cdot \lambda_1 \]
        5. Applied rewrites37.2%

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

        if 2.0999999999999999e-20 < phi2 < 1.7999999999999999e135

        1. Initial program 60.3%

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto R \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\phi_2, \phi_2, {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right)}} \]

        if 1.7999999999999999e135 < phi2

        1. Initial program 54.0%

          \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        2. Add Preprocessing
        3. Taylor expanded in 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)} \]
        4. Step-by-step derivation
          1. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -2.2 \cdot 10^{-211}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\phi_1 \cdot R}{\phi_2}, -1, R\right) \cdot \phi_2\\ \mathbf{elif}\;\phi_2 \leq 2.1 \cdot 10^{-20}:\\ \;\;\;\;\mathsf{fma}\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right), R, \frac{\left(R \cdot \lambda_2\right) \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)}{-\lambda_1}\right) \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\phi_2 \leq 1.8 \cdot 10^{+135}:\\ \;\;\;\;R \cdot \sqrt{\mathsf{fma}\left(\phi_2, \phi_2, {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\right)}\\ \mathbf{else}:\\ \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right)\\ \end{array} \]
      5. Add Preprocessing

      Alternative 8: 33.1% accurate, N/A× speedup?

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

        1. Initial program 54.8%

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

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

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

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

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

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

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

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

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

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

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

        if -2.19999999999999998e-211 < phi2 < 2.45e7

        1. Initial program 61.0%

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

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

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

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

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

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

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

          \[\leadsto -\mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot \left(\phi_2 + \phi_1\right)\right), R, \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) + \frac{-1}{2} \cdot \left(\phi_2 \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
        7. Step-by-step derivation
          1. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

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

            \[\leadsto -\mathsf{fma}\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right), R, \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) - 0.5 \cdot \left(\phi_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
        8. Applied rewrites36.3%

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

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

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

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

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

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

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

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

            \[\leadsto -\left(\cos \left(\frac{1}{2} \cdot \left(\phi_2 + \phi_1\right)\right) \cdot R + \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) - \frac{1}{2} \cdot \left(\phi_2 \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
          9. lift-cos.f6436.3

            \[\leadsto -\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot R + \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) - 0.5 \cdot \left(\phi_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
        10. Applied rewrites36.3%

          \[\leadsto -\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot R + \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) - 0.5 \cdot \left(\phi_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]

        if 2.45e7 < phi2

        1. Initial program 54.4%

          \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        2. Add Preprocessing
        3. 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)} \]
        4. Step-by-step derivation
          1. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 9: 32.2% accurate, N/A× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq -2.2 \cdot 10^{-211} \lor \neg \left(\phi_2 \leq 24500000\right):\\ \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \left(-R\right) + \frac{\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) - 0.5 \cdot \left(\phi_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1\\ \end{array} \end{array} \]
      (FPCore (R lambda1 lambda2 phi1 phi2)
       :precision binary64
       (if (or (<= phi2 -2.2e-211) (not (<= phi2 24500000.0)))
         (* (- phi1) (fma (/ (* phi2 R) phi1) -1.0 R))
         (*
          (+
           (* (cos (* 0.5 (+ phi2 phi1))) (- R))
           (/
            (*
             (* R lambda2)
             (- (cos (* 0.5 phi1)) (* 0.5 (* phi2 (sin (* 0.5 phi1))))))
            lambda1))
          lambda1)))
      double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	double tmp;
      	if ((phi2 <= -2.2e-211) || !(phi2 <= 24500000.0)) {
      		tmp = -phi1 * fma(((phi2 * R) / phi1), -1.0, R);
      	} else {
      		tmp = ((cos((0.5 * (phi2 + phi1))) * -R) + (((R * lambda2) * (cos((0.5 * phi1)) - (0.5 * (phi2 * sin((0.5 * phi1)))))) / lambda1)) * lambda1;
      	}
      	return tmp;
      }
      
      function code(R, lambda1, lambda2, phi1, phi2)
      	tmp = 0.0
      	if ((phi2 <= -2.2e-211) || !(phi2 <= 24500000.0))
      		tmp = Float64(Float64(-phi1) * fma(Float64(Float64(phi2 * R) / phi1), -1.0, R));
      	else
      		tmp = Float64(Float64(Float64(cos(Float64(0.5 * Float64(phi2 + phi1))) * Float64(-R)) + Float64(Float64(Float64(R * lambda2) * Float64(cos(Float64(0.5 * phi1)) - Float64(0.5 * Float64(phi2 * sin(Float64(0.5 * phi1)))))) / lambda1)) * lambda1);
      	end
      	return tmp
      end
      
      code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[Or[LessEqual[phi2, -2.2e-211], N[Not[LessEqual[phi2, 24500000.0]], $MachinePrecision]], N[((-phi1) * N[(N[(N[(phi2 * R), $MachinePrecision] / phi1), $MachinePrecision] * -1.0 + R), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Cos[N[(0.5 * N[(phi2 + phi1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-R)), $MachinePrecision] + N[(N[(N[(R * lambda2), $MachinePrecision] * N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] - N[(0.5 * N[(phi2 * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / lambda1), $MachinePrecision]), $MachinePrecision] * lambda1), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;\phi_2 \leq -2.2 \cdot 10^{-211} \lor \neg \left(\phi_2 \leq 24500000\right):\\
      \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \left(-R\right) + \frac{\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) - 0.5 \cdot \left(\phi_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if phi2 < -2.19999999999999998e-211 or 2.45e7 < phi2

        1. Initial program 54.6%

          \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        2. Add Preprocessing
        3. 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)} \]
        4. Step-by-step derivation
          1. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

        if -2.19999999999999998e-211 < phi2 < 2.45e7

        1. Initial program 61.0%

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

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

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

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

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

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

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

          \[\leadsto -\mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot \left(\phi_2 + \phi_1\right)\right), R, \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) + \frac{-1}{2} \cdot \left(\phi_2 \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
        7. Step-by-step derivation
          1. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

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

            \[\leadsto -\mathsf{fma}\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right), R, \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) - 0.5 \cdot \left(\phi_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
        8. Applied rewrites36.3%

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

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

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

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

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

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

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

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

            \[\leadsto -\left(\cos \left(\frac{1}{2} \cdot \left(\phi_2 + \phi_1\right)\right) \cdot R + \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) - \frac{1}{2} \cdot \left(\phi_2 \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
          9. lift-cos.f6436.3

            \[\leadsto -\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot R + \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) - 0.5 \cdot \left(\phi_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
        10. Applied rewrites36.3%

          \[\leadsto -\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot R + \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) - 0.5 \cdot \left(\phi_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
      3. Recombined 2 regimes into one program.
      4. Final simplification39.6%

        \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -2.2 \cdot 10^{-211} \lor \neg \left(\phi_2 \leq 24500000\right):\\ \;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(\frac{\phi_2 \cdot R}{\phi_1}, -1, R\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \left(-R\right) + \frac{\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) - 0.5 \cdot \left(\phi_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1\\ \end{array} \]
      5. Add Preprocessing

      Alternative 10: 27.1% accurate, N/A× speedup?

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

        1. Initial program 59.4%

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

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

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

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

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

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

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

          \[\leadsto -\mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot \left(\phi_2 + \phi_1\right)\right), R, \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) + \frac{-1}{2} \cdot \left(\phi_2 \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
        7. Step-by-step derivation
          1. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto -\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot R + \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) - 0.5 \cdot \left(\phi_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
        10. Applied rewrites26.5%

          \[\leadsto -\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot R + \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) - 0.5 \cdot \left(\phi_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]

        if 5.8000000000000001e31 < lambda2

        1. Initial program 47.8%

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

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

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

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

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

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

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

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

      Alternative 11: 27.3% accurate, N/A× speedup?

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

        1. Initial program 56.5%

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

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

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

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

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

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

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

          \[\leadsto -\mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot \left(\phi_2 + \phi_1\right)\right), R, \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) + \frac{-1}{2} \cdot \left(\phi_2 \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
        7. Step-by-step derivation
          1. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

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

            \[\leadsto -\mathsf{fma}\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right), R, \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) - 0.5 \cdot \left(\phi_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
        8. Applied rewrites30.9%

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

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

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

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

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

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

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

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

            \[\leadsto -\left(\cos \left(\frac{1}{2} \cdot \left(\phi_2 + \phi_1\right)\right) \cdot R + \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) - \frac{1}{2} \cdot \left(\phi_2 \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
          9. lift-cos.f6430.9

            \[\leadsto -\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot R + \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) - 0.5 \cdot \left(\phi_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
        10. Applied rewrites30.9%

          \[\leadsto -\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot R + \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) - 0.5 \cdot \left(\phi_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]

        if 2.10000000000000002e-199 < phi1

        1. Initial program 57.5%

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

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

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

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

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

            \[\leadsto -\left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1} + R \cdot \cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)\right) \cdot \lambda_1 \]
        5. Applied rewrites22.1%

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

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

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

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

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

            \[\leadsto -\mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot \left(\phi_2 + \phi_1\right)\right), R, \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + \phi_1 \cdot \left(\phi_1 \cdot \left(\frac{-1}{8} \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right) + \frac{1}{48} \cdot \left(\phi_1 \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right) - \frac{1}{2} \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
          5. fp-cancel-sub-sign-invN/A

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

            \[\leadsto -\mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot \left(\phi_2 + \phi_1\right)\right), R, \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + \phi_1 \cdot \mathsf{fma}\left(\phi_1, \frac{-1}{8} \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right) + \frac{1}{48} \cdot \left(\phi_1 \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right), \left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
        8. Applied rewrites30.2%

          \[\leadsto -\mathsf{fma}\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right), R, \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_2\right) + \phi_1 \cdot \mathsf{fma}\left(\phi_1, \mathsf{fma}\left(-0.125, \cos \left(0.5 \cdot \phi_2\right), 0.020833333333333332 \cdot \left(\phi_1 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right), -0.5 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
      3. Recombined 2 regimes into one program.
      4. Final simplification30.6%

        \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq 2.1 \cdot 10^{-199}:\\ \;\;\;\;\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \left(-R\right) + \frac{\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) - 0.5 \cdot \left(\phi_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right), R, \frac{\left(\left(-R\right) \cdot \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_2\right) + \phi_1 \cdot \mathsf{fma}\left(\phi_1, \mathsf{fma}\left(-0.125, \cos \left(0.5 \cdot \phi_2\right), 0.020833333333333332 \cdot \left(\phi_1 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right), -0.5 \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)}{\lambda_1}\right) \cdot \left(-\lambda_1\right)\\ \end{array} \]
      5. Add Preprocessing

      Alternative 12: 26.2% accurate, N/A× speedup?

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

        1. Initial program 59.4%

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

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

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

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

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

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

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

          \[\leadsto -\mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot \left(\phi_2 + \phi_1\right)\right), R, \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) + \frac{-1}{2} \cdot \left(\phi_2 \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
        7. Step-by-step derivation
          1. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto -\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot R + \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) - 0.5 \cdot \left(\phi_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]
        10. Applied rewrites26.5%

          \[\leadsto -\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot R + \frac{-\left(R \cdot \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) - 0.5 \cdot \left(\phi_2 \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right)}{\lambda_1}\right) \cdot \lambda_1 \]

        if 5.8000000000000001e31 < lambda2

        1. Initial program 47.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto -\left(\lambda_2 \cdot \mathsf{fma}\left(-1, \frac{R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}{\lambda_1}, \frac{R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}{\lambda_2}\right)\right) \cdot \lambda_1 \]
      3. Recombined 2 regimes into one program.
      4. Final simplification29.1%

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

      Alternative 13: 26.4% accurate, N/A× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\\ \left(\lambda_2 \cdot \mathsf{fma}\left(-1, \frac{t\_0}{\lambda_1}, \frac{t\_0}{\lambda_2}\right)\right) \cdot \left(-\lambda_1\right) \end{array} \end{array} \]
      (FPCore (R lambda1 lambda2 phi1 phi2)
       :precision binary64
       (let* ((t_0 (* R (cos (* 0.5 (+ phi1 phi2))))))
         (* (* lambda2 (fma -1.0 (/ t_0 lambda1) (/ t_0 lambda2))) (- lambda1))))
      double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
      	double t_0 = R * cos((0.5 * (phi1 + phi2)));
      	return (lambda2 * fma(-1.0, (t_0 / lambda1), (t_0 / lambda2))) * -lambda1;
      }
      
      function code(R, lambda1, lambda2, phi1, phi2)
      	t_0 = Float64(R * cos(Float64(0.5 * Float64(phi1 + phi2))))
      	return Float64(Float64(lambda2 * fma(-1.0, Float64(t_0 / lambda1), Float64(t_0 / lambda2))) * Float64(-lambda1))
      end
      
      code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(R * N[Cos[N[(0.5 * N[(phi1 + phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(N[(lambda2 * N[(-1.0 * N[(t$95$0 / lambda1), $MachinePrecision] + N[(t$95$0 / lambda2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * (-lambda1)), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\\
      \left(\lambda_2 \cdot \mathsf{fma}\left(-1, \frac{t\_0}{\lambda_1}, \frac{t\_0}{\lambda_2}\right)\right) \cdot \left(-\lambda_1\right)
      \end{array}
      \end{array}
      
      Derivation
      1. Initial program 56.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -\left(\lambda_2 \cdot \mathsf{fma}\left(-1, \frac{R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}{\lambda_1}, \frac{R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}{\lambda_2}\right)\right) \cdot \lambda_1 \]
      9. Final simplification25.0%

        \[\leadsto \left(\lambda_2 \cdot \mathsf{fma}\left(-1, \frac{R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}{\lambda_1}, \frac{R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}{\lambda_2}\right)\right) \cdot \left(-\lambda_1\right) \]
      10. Add Preprocessing

      Reproduce

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