Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.2% → 99.4%
Time: 19.3s
Alternatives: 17
Speedup: 3.0×

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))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    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 17 alternatives:

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

Initial Program: 60.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\\ R \cdot \sqrt{t\_0 \cdot t\_0 + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0)))))
   (* R (sqrt (+ (* t_0 t_0) (* (- phi1 phi2) (- phi1 phi2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0));
	return R * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0d0))
    code = r * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (lambda1 - lambda2) * Math.cos(((phi1 + phi2) / 2.0));
	return R * Math.sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = (lambda1 - lambda2) * math.cos(((phi1 + phi2) / 2.0))
	return R * math.sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))))
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi1 + phi2) / 2.0)))
	return Float64(R * sqrt(Float64(Float64(t_0 * t_0) + Float64(Float64(phi1 - phi2) * Float64(phi1 - phi2)))))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0));
	tmp = R * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(N[(phi1 + phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(R * N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] + N[(N[(phi1 - phi2), $MachinePrecision] * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

Alternative 1: 99.4% accurate, 0.5× speedup?

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

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

    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
  2. Step-by-step derivation
    1. hypot-define97.6%

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

    \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. add-sqr-sqrt97.1%

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

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

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

      \[\leadsto R \cdot {\left(\sqrt{\mathsf{hypot}\left(\cos \color{blue}{\left(\left(\phi_1 + \phi_2\right) \cdot \frac{1}{2}\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)}\right)}^{2} \]
    5. metadata-eval97.1%

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

    \[\leadsto R \cdot \color{blue}{{\left(\sqrt{\mathsf{hypot}\left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)}\right)}^{2}} \]
  7. Step-by-step derivation
    1. *-commutative97.1%

      \[\leadsto R \cdot {\left(\sqrt{\mathsf{hypot}\left(\cos \color{blue}{\left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)}\right)}^{2} \]
    2. +-commutative97.1%

      \[\leadsto R \cdot {\left(\sqrt{\mathsf{hypot}\left(\cos \left(0.5 \cdot \color{blue}{\left(\phi_2 + \phi_1\right)}\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)}\right)}^{2} \]
    3. distribute-rgt-in97.1%

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

      \[\leadsto R \cdot {\left(\sqrt{\mathsf{hypot}\left(\color{blue}{\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)}\right)}^{2} \]
  8. Applied egg-rr99.4%

    \[\leadsto R \cdot {\left(\sqrt{\mathsf{hypot}\left(\color{blue}{\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)}\right)}^{2} \]
  9. Final simplification99.4%

    \[\leadsto R \cdot {\left(\sqrt{\mathsf{hypot}\left(\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)}\right)}^{2} \]
  10. Add Preprocessing

Alternative 2: 93.0% accurate, 1.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < 3.10000000000000011e-40

    1. Initial program 56.6%

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

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

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

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

    if 3.10000000000000011e-40 < phi2

    1. Initial program 57.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. Step-by-step derivation
      1. hypot-define96.4%

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

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

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

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

Alternative 3: 90.5% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 56.3%

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

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

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

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

    if 1.2500000000000001e-23 < phi2

    1. Initial program 58.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. Step-by-step derivation
      1. hypot-define96.1%

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

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{-\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)}, \phi_1 - \phi_2\right) \]
      2. distribute-rgt-neg-in86.8%

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

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

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

Alternative 4: 79.7% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 \leq -1.25 \cdot 10^{+38}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_1 - \phi_2\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda1 < -1.24999999999999992e38

    1. Initial program 53.7%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define99.7%

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

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

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

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

    if -1.24999999999999992e38 < lambda1

    1. Initial program 57.6%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define97.1%

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{-1 \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)}, \phi_1 - \phi_2\right) \]
    7. Step-by-step derivation
      1. mul-1-neg79.7%

        \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{-\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)}, \phi_1 - \phi_2\right) \]
      2. distribute-rgt-neg-in79.7%

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

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

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

Alternative 5: 96.1% accurate, 1.5× speedup?

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

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

    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
  2. Step-by-step derivation
    1. hypot-define97.6%

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

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

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

Alternative 6: 71.7% accurate, 3.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 2.35 \cdot 10^{+58}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_1\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(\phi_2 \cdot \left(1 - \frac{\phi_1}{\phi_2}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < 2.34999999999999986e58

    1. Initial program 57.4%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define97.8%

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

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

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

      \[\leadsto \color{blue}{R \cdot \sqrt{{\phi_1}^{2} + {\left(\lambda_1 - \lambda_2\right)}^{2}}} \]
    7. Step-by-step derivation
      1. +-commutative46.0%

        \[\leadsto R \cdot \sqrt{\color{blue}{{\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
      2. unpow246.0%

        \[\leadsto R \cdot \sqrt{\color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)} + {\phi_1}^{2}} \]
      3. unpow246.0%

        \[\leadsto R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right) + \color{blue}{\phi_1 \cdot \phi_1}} \]
      4. hypot-define69.1%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_1\right)} \]
    8. Simplified69.1%

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

    if 2.34999999999999986e58 < phi2

    1. Initial program 55.0%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define96.8%

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

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

      \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg74.3%

        \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + \color{blue}{\left(-\frac{\phi_1}{\phi_2}\right)}\right)\right) \]
      2. unsub-neg74.3%

        \[\leadsto R \cdot \left(\phi_2 \cdot \color{blue}{\left(1 - \frac{\phi_1}{\phi_2}\right)}\right) \]
    7. Simplified74.3%

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

Alternative 7: 85.2% accurate, 3.0× speedup?

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

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

    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
  2. Step-by-step derivation
    1. hypot-define97.6%

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

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

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

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

Alternative 8: 33.4% accurate, 9.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := R \cdot \left(-\lambda_1\right)\\ \mathbf{if}\;\lambda_1 \leq -3.2 \cdot 10^{+198}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\lambda_1 \leq -1.35 \cdot 10^{+158}:\\ \;\;\;\;R \cdot \left(\phi_1 \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\ \mathbf{elif}\;\lambda_1 \leq -9.2 \cdot 10^{+148}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\lambda_1 \leq 1.5 \cdot 10^{-299} \lor \neg \left(\lambda_1 \leq 1.9 \cdot 10^{-16}\right):\\ \;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* R (- lambda1))))
   (if (<= lambda1 -3.2e+198)
     t_0
     (if (<= lambda1 -1.35e+158)
       (* R (* phi1 (+ (/ phi2 phi1) -1.0)))
       (if (<= lambda1 -9.2e+148)
         t_0
         (if (or (<= lambda1 1.5e-299) (not (<= lambda1 1.9e-16)))
           (- (* R phi2) (* R phi1))
           (* phi2 (- R (* phi1 (/ R phi2))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * -lambda1;
	double tmp;
	if (lambda1 <= -3.2e+198) {
		tmp = t_0;
	} else if (lambda1 <= -1.35e+158) {
		tmp = R * (phi1 * ((phi2 / phi1) + -1.0));
	} else if (lambda1 <= -9.2e+148) {
		tmp = t_0;
	} else if ((lambda1 <= 1.5e-299) || !(lambda1 <= 1.9e-16)) {
		tmp = (R * phi2) - (R * phi1);
	} else {
		tmp = phi2 * (R - (phi1 * (R / phi2)));
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    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
    real(8) :: tmp
    t_0 = r * -lambda1
    if (lambda1 <= (-3.2d+198)) then
        tmp = t_0
    else if (lambda1 <= (-1.35d+158)) then
        tmp = r * (phi1 * ((phi2 / phi1) + (-1.0d0)))
    else if (lambda1 <= (-9.2d+148)) then
        tmp = t_0
    else if ((lambda1 <= 1.5d-299) .or. (.not. (lambda1 <= 1.9d-16))) then
        tmp = (r * phi2) - (r * phi1)
    else
        tmp = phi2 * (r - (phi1 * (r / phi2)))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * -lambda1;
	double tmp;
	if (lambda1 <= -3.2e+198) {
		tmp = t_0;
	} else if (lambda1 <= -1.35e+158) {
		tmp = R * (phi1 * ((phi2 / phi1) + -1.0));
	} else if (lambda1 <= -9.2e+148) {
		tmp = t_0;
	} else if ((lambda1 <= 1.5e-299) || !(lambda1 <= 1.9e-16)) {
		tmp = (R * phi2) - (R * phi1);
	} else {
		tmp = phi2 * (R - (phi1 * (R / phi2)));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = R * -lambda1
	tmp = 0
	if lambda1 <= -3.2e+198:
		tmp = t_0
	elif lambda1 <= -1.35e+158:
		tmp = R * (phi1 * ((phi2 / phi1) + -1.0))
	elif lambda1 <= -9.2e+148:
		tmp = t_0
	elif (lambda1 <= 1.5e-299) or not (lambda1 <= 1.9e-16):
		tmp = (R * phi2) - (R * phi1)
	else:
		tmp = phi2 * (R - (phi1 * (R / phi2)))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(R * Float64(-lambda1))
	tmp = 0.0
	if (lambda1 <= -3.2e+198)
		tmp = t_0;
	elseif (lambda1 <= -1.35e+158)
		tmp = Float64(R * Float64(phi1 * Float64(Float64(phi2 / phi1) + -1.0)));
	elseif (lambda1 <= -9.2e+148)
		tmp = t_0;
	elseif ((lambda1 <= 1.5e-299) || !(lambda1 <= 1.9e-16))
		tmp = Float64(Float64(R * phi2) - Float64(R * phi1));
	else
		tmp = Float64(phi2 * Float64(R - Float64(phi1 * Float64(R / phi2))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = R * -lambda1;
	tmp = 0.0;
	if (lambda1 <= -3.2e+198)
		tmp = t_0;
	elseif (lambda1 <= -1.35e+158)
		tmp = R * (phi1 * ((phi2 / phi1) + -1.0));
	elseif (lambda1 <= -9.2e+148)
		tmp = t_0;
	elseif ((lambda1 <= 1.5e-299) || ~((lambda1 <= 1.9e-16)))
		tmp = (R * phi2) - (R * phi1);
	else
		tmp = phi2 * (R - (phi1 * (R / phi2)));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(R * (-lambda1)), $MachinePrecision]}, If[LessEqual[lambda1, -3.2e+198], t$95$0, If[LessEqual[lambda1, -1.35e+158], N[(R * N[(phi1 * N[(N[(phi2 / phi1), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda1, -9.2e+148], t$95$0, If[Or[LessEqual[lambda1, 1.5e-299], N[Not[LessEqual[lambda1, 1.9e-16]], $MachinePrecision]], N[(N[(R * phi2), $MachinePrecision] - N[(R * phi1), $MachinePrecision]), $MachinePrecision], N[(phi2 * N[(R - N[(phi1 * N[(R / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := R \cdot \left(-\lambda_1\right)\\
\mathbf{if}\;\lambda_1 \leq -3.2 \cdot 10^{+198}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\lambda_1 \leq -1.35 \cdot 10^{+158}:\\
\;\;\;\;R \cdot \left(\phi_1 \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\

\mathbf{elif}\;\lambda_1 \leq -9.2 \cdot 10^{+148}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\lambda_1 \leq 1.5 \cdot 10^{-299} \lor \neg \left(\lambda_1 \leq 1.9 \cdot 10^{-16}\right):\\
\;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\

\mathbf{else}:\\
\;\;\;\;\phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if lambda1 < -3.1999999999999998e198 or -1.34999999999999989e158 < lambda1 < -9.2000000000000002e148

    1. Initial program 68.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. Step-by-step derivation
      1. hypot-define99.5%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg53.0%

        \[\leadsto \color{blue}{-R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \]
      2. associate-*r*53.0%

        \[\leadsto -\color{blue}{\left(R \cdot \lambda_1\right) \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)} \]
      3. distribute-lft-neg-in53.0%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)} \]
    9. Step-by-step derivation
      1. associate-*r*59.6%

        \[\leadsto \color{blue}{\left(-1 \cdot R\right) \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
      2. mul-1-neg59.6%

        \[\leadsto \color{blue}{\left(-R\right)} \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \]
      3. *-commutative59.6%

        \[\leadsto \left(-R\right) \cdot \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1\right)} \]
    10. Simplified59.6%

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

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

    if -3.1999999999999998e198 < lambda1 < -1.34999999999999989e158

    1. Initial program 31.2%

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

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

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

      \[\leadsto R \cdot \color{blue}{\left(-1 \cdot \left(\phi_1 \cdot \left(1 + -1 \cdot \frac{\phi_2}{\phi_1}\right)\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg10.3%

        \[\leadsto R \cdot \color{blue}{\left(-\phi_1 \cdot \left(1 + -1 \cdot \frac{\phi_2}{\phi_1}\right)\right)} \]
      2. distribute-rgt-neg-in10.3%

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

        \[\leadsto R \cdot \left(\phi_1 \cdot \left(-\left(1 + \color{blue}{\left(-\frac{\phi_2}{\phi_1}\right)}\right)\right)\right) \]
      4. unsub-neg10.3%

        \[\leadsto R \cdot \left(\phi_1 \cdot \left(-\color{blue}{\left(1 - \frac{\phi_2}{\phi_1}\right)}\right)\right) \]
    7. Simplified10.3%

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

    if -9.2000000000000002e148 < lambda1 < 1.49999999999999992e-299 or 1.90000000000000006e-16 < lambda1

    1. Initial program 55.3%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg27.9%

        \[\leadsto \color{blue}{-\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
      2. distribute-rgt-neg-in27.9%

        \[\leadsto \color{blue}{\phi_1 \cdot \left(-\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
      3. mul-1-neg27.9%

        \[\leadsto \phi_1 \cdot \left(-\left(R + \color{blue}{\left(-\frac{R \cdot \phi_2}{\phi_1}\right)}\right)\right) \]
      4. unsub-neg27.9%

        \[\leadsto \phi_1 \cdot \left(-\color{blue}{\left(R - \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
      5. *-commutative27.9%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right) + R \cdot \phi_2} \]
    9. Step-by-step derivation
      1. +-commutative29.6%

        \[\leadsto \color{blue}{R \cdot \phi_2 + -1 \cdot \left(R \cdot \phi_1\right)} \]
      2. mul-1-neg29.6%

        \[\leadsto R \cdot \phi_2 + \color{blue}{\left(-R \cdot \phi_1\right)} \]
      3. unsub-neg29.6%

        \[\leadsto \color{blue}{R \cdot \phi_2 - R \cdot \phi_1} \]
      4. *-commutative29.6%

        \[\leadsto \color{blue}{\phi_2 \cdot R} - R \cdot \phi_1 \]
      5. *-commutative29.6%

        \[\leadsto \phi_2 \cdot R - \color{blue}{\phi_1 \cdot R} \]
    10. Simplified29.6%

      \[\leadsto \color{blue}{\phi_2 \cdot R - \phi_1 \cdot R} \]

    if 1.49999999999999992e-299 < lambda1 < 1.90000000000000006e-16

    1. Initial program 63.0%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define98.5%

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

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

      \[\leadsto \color{blue}{\phi_2 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_1}{\phi_2}\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg43.7%

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\left(-\frac{R \cdot \phi_1}{\phi_2}\right)}\right) \]
      2. unsub-neg43.7%

        \[\leadsto \phi_2 \cdot \color{blue}{\left(R - \frac{R \cdot \phi_1}{\phi_2}\right)} \]
      3. *-commutative43.7%

        \[\leadsto \phi_2 \cdot \left(R - \frac{\color{blue}{\phi_1 \cdot R}}{\phi_2}\right) \]
      4. associate-/l*43.6%

        \[\leadsto \phi_2 \cdot \left(R - \color{blue}{\phi_1 \cdot \frac{R}{\phi_2}}\right) \]
    7. Simplified43.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -3.2 \cdot 10^{+198}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq -1.35 \cdot 10^{+158}:\\ \;\;\;\;R \cdot \left(\phi_1 \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\ \mathbf{elif}\;\lambda_1 \leq -9.2 \cdot 10^{+148}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq 1.5 \cdot 10^{-299} \lor \neg \left(\lambda_1 \leq 1.9 \cdot 10^{-16}\right):\\ \;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 33.4% accurate, 9.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := R \cdot \left(-\lambda_1\right)\\ \mathbf{if}\;\lambda_1 \leq -3.2 \cdot 10^{+198}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\lambda_1 \leq -1.45 \cdot 10^{+159}:\\ \;\;\;\;\left(R \cdot \phi_1\right) \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\\ \mathbf{elif}\;\lambda_1 \leq -4.5 \cdot 10^{+149}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\lambda_1 \leq 2.9 \cdot 10^{-297} \lor \neg \left(\lambda_1 \leq 4.8 \cdot 10^{-18}\right):\\ \;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* R (- lambda1))))
   (if (<= lambda1 -3.2e+198)
     t_0
     (if (<= lambda1 -1.45e+159)
       (* (* R phi1) (+ (/ phi2 phi1) -1.0))
       (if (<= lambda1 -4.5e+149)
         t_0
         (if (or (<= lambda1 2.9e-297) (not (<= lambda1 4.8e-18)))
           (- (* R phi2) (* R phi1))
           (* phi2 (- R (* phi1 (/ R phi2))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * -lambda1;
	double tmp;
	if (lambda1 <= -3.2e+198) {
		tmp = t_0;
	} else if (lambda1 <= -1.45e+159) {
		tmp = (R * phi1) * ((phi2 / phi1) + -1.0);
	} else if (lambda1 <= -4.5e+149) {
		tmp = t_0;
	} else if ((lambda1 <= 2.9e-297) || !(lambda1 <= 4.8e-18)) {
		tmp = (R * phi2) - (R * phi1);
	} else {
		tmp = phi2 * (R - (phi1 * (R / phi2)));
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    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
    real(8) :: tmp
    t_0 = r * -lambda1
    if (lambda1 <= (-3.2d+198)) then
        tmp = t_0
    else if (lambda1 <= (-1.45d+159)) then
        tmp = (r * phi1) * ((phi2 / phi1) + (-1.0d0))
    else if (lambda1 <= (-4.5d+149)) then
        tmp = t_0
    else if ((lambda1 <= 2.9d-297) .or. (.not. (lambda1 <= 4.8d-18))) then
        tmp = (r * phi2) - (r * phi1)
    else
        tmp = phi2 * (r - (phi1 * (r / phi2)))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * -lambda1;
	double tmp;
	if (lambda1 <= -3.2e+198) {
		tmp = t_0;
	} else if (lambda1 <= -1.45e+159) {
		tmp = (R * phi1) * ((phi2 / phi1) + -1.0);
	} else if (lambda1 <= -4.5e+149) {
		tmp = t_0;
	} else if ((lambda1 <= 2.9e-297) || !(lambda1 <= 4.8e-18)) {
		tmp = (R * phi2) - (R * phi1);
	} else {
		tmp = phi2 * (R - (phi1 * (R / phi2)));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = R * -lambda1
	tmp = 0
	if lambda1 <= -3.2e+198:
		tmp = t_0
	elif lambda1 <= -1.45e+159:
		tmp = (R * phi1) * ((phi2 / phi1) + -1.0)
	elif lambda1 <= -4.5e+149:
		tmp = t_0
	elif (lambda1 <= 2.9e-297) or not (lambda1 <= 4.8e-18):
		tmp = (R * phi2) - (R * phi1)
	else:
		tmp = phi2 * (R - (phi1 * (R / phi2)))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(R * Float64(-lambda1))
	tmp = 0.0
	if (lambda1 <= -3.2e+198)
		tmp = t_0;
	elseif (lambda1 <= -1.45e+159)
		tmp = Float64(Float64(R * phi1) * Float64(Float64(phi2 / phi1) + -1.0));
	elseif (lambda1 <= -4.5e+149)
		tmp = t_0;
	elseif ((lambda1 <= 2.9e-297) || !(lambda1 <= 4.8e-18))
		tmp = Float64(Float64(R * phi2) - Float64(R * phi1));
	else
		tmp = Float64(phi2 * Float64(R - Float64(phi1 * Float64(R / phi2))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = R * -lambda1;
	tmp = 0.0;
	if (lambda1 <= -3.2e+198)
		tmp = t_0;
	elseif (lambda1 <= -1.45e+159)
		tmp = (R * phi1) * ((phi2 / phi1) + -1.0);
	elseif (lambda1 <= -4.5e+149)
		tmp = t_0;
	elseif ((lambda1 <= 2.9e-297) || ~((lambda1 <= 4.8e-18)))
		tmp = (R * phi2) - (R * phi1);
	else
		tmp = phi2 * (R - (phi1 * (R / phi2)));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(R * (-lambda1)), $MachinePrecision]}, If[LessEqual[lambda1, -3.2e+198], t$95$0, If[LessEqual[lambda1, -1.45e+159], N[(N[(R * phi1), $MachinePrecision] * N[(N[(phi2 / phi1), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda1, -4.5e+149], t$95$0, If[Or[LessEqual[lambda1, 2.9e-297], N[Not[LessEqual[lambda1, 4.8e-18]], $MachinePrecision]], N[(N[(R * phi2), $MachinePrecision] - N[(R * phi1), $MachinePrecision]), $MachinePrecision], N[(phi2 * N[(R - N[(phi1 * N[(R / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := R \cdot \left(-\lambda_1\right)\\
\mathbf{if}\;\lambda_1 \leq -3.2 \cdot 10^{+198}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\lambda_1 \leq -1.45 \cdot 10^{+159}:\\
\;\;\;\;\left(R \cdot \phi_1\right) \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\\

\mathbf{elif}\;\lambda_1 \leq -4.5 \cdot 10^{+149}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\lambda_1 \leq 2.9 \cdot 10^{-297} \lor \neg \left(\lambda_1 \leq 4.8 \cdot 10^{-18}\right):\\
\;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\

\mathbf{else}:\\
\;\;\;\;\phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if lambda1 < -3.1999999999999998e198 or -1.45000000000000007e159 < lambda1 < -4.49999999999999982e149

    1. Initial program 68.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. Step-by-step derivation
      1. hypot-define99.5%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg53.0%

        \[\leadsto \color{blue}{-R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \]
      2. associate-*r*53.0%

        \[\leadsto -\color{blue}{\left(R \cdot \lambda_1\right) \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)} \]
      3. distribute-lft-neg-in53.0%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)} \]
    9. Step-by-step derivation
      1. associate-*r*59.6%

        \[\leadsto \color{blue}{\left(-1 \cdot R\right) \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
      2. mul-1-neg59.6%

        \[\leadsto \color{blue}{\left(-R\right)} \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \]
      3. *-commutative59.6%

        \[\leadsto \left(-R\right) \cdot \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1\right)} \]
    10. Simplified59.6%

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

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

    if -3.1999999999999998e198 < lambda1 < -1.45000000000000007e159

    1. Initial program 31.2%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg19.3%

        \[\leadsto \color{blue}{-\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
      2. distribute-rgt-neg-in19.3%

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

        \[\leadsto \phi_1 \cdot \left(-\left(R + \color{blue}{\left(-\frac{R \cdot \phi_2}{\phi_1}\right)}\right)\right) \]
      4. unsub-neg19.3%

        \[\leadsto \phi_1 \cdot \left(-\color{blue}{\left(R - \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
      5. *-commutative19.3%

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

        \[\leadsto \phi_1 \cdot \left(-\left(R - \color{blue}{\phi_2 \cdot \frac{R}{\phi_1}}\right)\right) \]
    7. Simplified10.2%

      \[\leadsto \color{blue}{\phi_1 \cdot \left(-\left(R - \phi_2 \cdot \frac{R}{\phi_1}\right)\right)} \]
    8. Taylor expanded in R around 0 10.3%

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

        \[\leadsto \color{blue}{\left(R \cdot \phi_1\right) \cdot \left(\frac{\phi_2}{\phi_1} - 1\right)} \]
      2. *-commutative10.3%

        \[\leadsto \color{blue}{\left(\phi_1 \cdot R\right)} \cdot \left(\frac{\phi_2}{\phi_1} - 1\right) \]
      3. sub-neg10.3%

        \[\leadsto \left(\phi_1 \cdot R\right) \cdot \color{blue}{\left(\frac{\phi_2}{\phi_1} + \left(-1\right)\right)} \]
      4. metadata-eval10.3%

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

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

    if -4.49999999999999982e149 < lambda1 < 2.89999999999999989e-297 or 4.79999999999999988e-18 < lambda1

    1. Initial program 55.3%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg27.9%

        \[\leadsto \color{blue}{-\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
      2. distribute-rgt-neg-in27.9%

        \[\leadsto \color{blue}{\phi_1 \cdot \left(-\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
      3. mul-1-neg27.9%

        \[\leadsto \phi_1 \cdot \left(-\left(R + \color{blue}{\left(-\frac{R \cdot \phi_2}{\phi_1}\right)}\right)\right) \]
      4. unsub-neg27.9%

        \[\leadsto \phi_1 \cdot \left(-\color{blue}{\left(R - \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
      5. *-commutative27.9%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right) + R \cdot \phi_2} \]
    9. Step-by-step derivation
      1. +-commutative29.6%

        \[\leadsto \color{blue}{R \cdot \phi_2 + -1 \cdot \left(R \cdot \phi_1\right)} \]
      2. mul-1-neg29.6%

        \[\leadsto R \cdot \phi_2 + \color{blue}{\left(-R \cdot \phi_1\right)} \]
      3. unsub-neg29.6%

        \[\leadsto \color{blue}{R \cdot \phi_2 - R \cdot \phi_1} \]
      4. *-commutative29.6%

        \[\leadsto \color{blue}{\phi_2 \cdot R} - R \cdot \phi_1 \]
      5. *-commutative29.6%

        \[\leadsto \phi_2 \cdot R - \color{blue}{\phi_1 \cdot R} \]
    10. Simplified29.6%

      \[\leadsto \color{blue}{\phi_2 \cdot R - \phi_1 \cdot R} \]

    if 2.89999999999999989e-297 < lambda1 < 4.79999999999999988e-18

    1. Initial program 63.0%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define98.5%

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

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

      \[\leadsto \color{blue}{\phi_2 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_1}{\phi_2}\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg43.7%

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\left(-\frac{R \cdot \phi_1}{\phi_2}\right)}\right) \]
      2. unsub-neg43.7%

        \[\leadsto \phi_2 \cdot \color{blue}{\left(R - \frac{R \cdot \phi_1}{\phi_2}\right)} \]
      3. *-commutative43.7%

        \[\leadsto \phi_2 \cdot \left(R - \frac{\color{blue}{\phi_1 \cdot R}}{\phi_2}\right) \]
      4. associate-/l*43.6%

        \[\leadsto \phi_2 \cdot \left(R - \color{blue}{\phi_1 \cdot \frac{R}{\phi_2}}\right) \]
    7. Simplified43.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -3.2 \cdot 10^{+198}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq -1.45 \cdot 10^{+159}:\\ \;\;\;\;\left(R \cdot \phi_1\right) \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\\ \mathbf{elif}\;\lambda_1 \leq -4.5 \cdot 10^{+149}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq 2.9 \cdot 10^{-297} \lor \neg \left(\lambda_1 \leq 4.8 \cdot 10^{-18}\right):\\ \;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 33.4% accurate, 9.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := R \cdot \left(-\lambda_1\right)\\ \mathbf{if}\;\lambda_1 \leq -7.5 \cdot 10^{+198}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\lambda_1 \leq -9.5 \cdot 10^{+156}:\\ \;\;\;\;\phi_1 \cdot \left(R \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\ \mathbf{elif}\;\lambda_1 \leq -5.4 \cdot 10^{+146}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\lambda_1 \leq 3.8 \cdot 10^{-297} \lor \neg \left(\lambda_1 \leq 8 \cdot 10^{-18}\right):\\ \;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* R (- lambda1))))
   (if (<= lambda1 -7.5e+198)
     t_0
     (if (<= lambda1 -9.5e+156)
       (* phi1 (* R (+ (/ phi2 phi1) -1.0)))
       (if (<= lambda1 -5.4e+146)
         t_0
         (if (or (<= lambda1 3.8e-297) (not (<= lambda1 8e-18)))
           (- (* R phi2) (* R phi1))
           (* phi2 (- R (* phi1 (/ R phi2))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * -lambda1;
	double tmp;
	if (lambda1 <= -7.5e+198) {
		tmp = t_0;
	} else if (lambda1 <= -9.5e+156) {
		tmp = phi1 * (R * ((phi2 / phi1) + -1.0));
	} else if (lambda1 <= -5.4e+146) {
		tmp = t_0;
	} else if ((lambda1 <= 3.8e-297) || !(lambda1 <= 8e-18)) {
		tmp = (R * phi2) - (R * phi1);
	} else {
		tmp = phi2 * (R - (phi1 * (R / phi2)));
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    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
    real(8) :: tmp
    t_0 = r * -lambda1
    if (lambda1 <= (-7.5d+198)) then
        tmp = t_0
    else if (lambda1 <= (-9.5d+156)) then
        tmp = phi1 * (r * ((phi2 / phi1) + (-1.0d0)))
    else if (lambda1 <= (-5.4d+146)) then
        tmp = t_0
    else if ((lambda1 <= 3.8d-297) .or. (.not. (lambda1 <= 8d-18))) then
        tmp = (r * phi2) - (r * phi1)
    else
        tmp = phi2 * (r - (phi1 * (r / phi2)))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * -lambda1;
	double tmp;
	if (lambda1 <= -7.5e+198) {
		tmp = t_0;
	} else if (lambda1 <= -9.5e+156) {
		tmp = phi1 * (R * ((phi2 / phi1) + -1.0));
	} else if (lambda1 <= -5.4e+146) {
		tmp = t_0;
	} else if ((lambda1 <= 3.8e-297) || !(lambda1 <= 8e-18)) {
		tmp = (R * phi2) - (R * phi1);
	} else {
		tmp = phi2 * (R - (phi1 * (R / phi2)));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = R * -lambda1
	tmp = 0
	if lambda1 <= -7.5e+198:
		tmp = t_0
	elif lambda1 <= -9.5e+156:
		tmp = phi1 * (R * ((phi2 / phi1) + -1.0))
	elif lambda1 <= -5.4e+146:
		tmp = t_0
	elif (lambda1 <= 3.8e-297) or not (lambda1 <= 8e-18):
		tmp = (R * phi2) - (R * phi1)
	else:
		tmp = phi2 * (R - (phi1 * (R / phi2)))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(R * Float64(-lambda1))
	tmp = 0.0
	if (lambda1 <= -7.5e+198)
		tmp = t_0;
	elseif (lambda1 <= -9.5e+156)
		tmp = Float64(phi1 * Float64(R * Float64(Float64(phi2 / phi1) + -1.0)));
	elseif (lambda1 <= -5.4e+146)
		tmp = t_0;
	elseif ((lambda1 <= 3.8e-297) || !(lambda1 <= 8e-18))
		tmp = Float64(Float64(R * phi2) - Float64(R * phi1));
	else
		tmp = Float64(phi2 * Float64(R - Float64(phi1 * Float64(R / phi2))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = R * -lambda1;
	tmp = 0.0;
	if (lambda1 <= -7.5e+198)
		tmp = t_0;
	elseif (lambda1 <= -9.5e+156)
		tmp = phi1 * (R * ((phi2 / phi1) + -1.0));
	elseif (lambda1 <= -5.4e+146)
		tmp = t_0;
	elseif ((lambda1 <= 3.8e-297) || ~((lambda1 <= 8e-18)))
		tmp = (R * phi2) - (R * phi1);
	else
		tmp = phi2 * (R - (phi1 * (R / phi2)));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(R * (-lambda1)), $MachinePrecision]}, If[LessEqual[lambda1, -7.5e+198], t$95$0, If[LessEqual[lambda1, -9.5e+156], N[(phi1 * N[(R * N[(N[(phi2 / phi1), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda1, -5.4e+146], t$95$0, If[Or[LessEqual[lambda1, 3.8e-297], N[Not[LessEqual[lambda1, 8e-18]], $MachinePrecision]], N[(N[(R * phi2), $MachinePrecision] - N[(R * phi1), $MachinePrecision]), $MachinePrecision], N[(phi2 * N[(R - N[(phi1 * N[(R / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := R \cdot \left(-\lambda_1\right)\\
\mathbf{if}\;\lambda_1 \leq -7.5 \cdot 10^{+198}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\lambda_1 \leq -9.5 \cdot 10^{+156}:\\
\;\;\;\;\phi_1 \cdot \left(R \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\

\mathbf{elif}\;\lambda_1 \leq -5.4 \cdot 10^{+146}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\lambda_1 \leq 3.8 \cdot 10^{-297} \lor \neg \left(\lambda_1 \leq 8 \cdot 10^{-18}\right):\\
\;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\

\mathbf{else}:\\
\;\;\;\;\phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if lambda1 < -7.5000000000000002e198 or -9.5000000000000002e156 < lambda1 < -5.39999999999999977e146

    1. Initial program 68.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. Step-by-step derivation
      1. hypot-define99.5%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg53.0%

        \[\leadsto \color{blue}{-R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \]
      2. associate-*r*53.0%

        \[\leadsto -\color{blue}{\left(R \cdot \lambda_1\right) \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)} \]
      3. distribute-lft-neg-in53.0%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)} \]
    9. Step-by-step derivation
      1. associate-*r*59.6%

        \[\leadsto \color{blue}{\left(-1 \cdot R\right) \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
      2. mul-1-neg59.6%

        \[\leadsto \color{blue}{\left(-R\right)} \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \]
      3. *-commutative59.6%

        \[\leadsto \left(-R\right) \cdot \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1\right)} \]
    10. Simplified59.6%

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

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

    if -7.5000000000000002e198 < lambda1 < -9.5000000000000002e156

    1. Initial program 31.2%

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

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

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. add-sqr-sqrt99.6%

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

        \[\leadsto R \cdot \color{blue}{{\left(\sqrt{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)}\right)}^{2}} \]
      3. *-commutative99.6%

        \[\leadsto R \cdot {\left(\sqrt{\mathsf{hypot}\left(\color{blue}{\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)}, \phi_1 - \phi_2\right)}\right)}^{2} \]
      4. div-inv99.6%

        \[\leadsto R \cdot {\left(\sqrt{\mathsf{hypot}\left(\cos \color{blue}{\left(\left(\phi_1 + \phi_2\right) \cdot \frac{1}{2}\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)}\right)}^{2} \]
      5. metadata-eval99.6%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
    8. Step-by-step derivation
      1. mul-1-neg19.3%

        \[\leadsto \color{blue}{-\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
      2. mul-1-neg19.3%

        \[\leadsto -\phi_1 \cdot \left(R + \color{blue}{\left(-\frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
      3. *-commutative19.3%

        \[\leadsto -\phi_1 \cdot \left(R + \left(-\frac{\color{blue}{\phi_2 \cdot R}}{\phi_1}\right)\right) \]
      4. associate-*r/10.2%

        \[\leadsto -\phi_1 \cdot \left(R + \left(-\color{blue}{\phi_2 \cdot \frac{R}{\phi_1}}\right)\right) \]
      5. sub-neg10.2%

        \[\leadsto -\phi_1 \cdot \color{blue}{\left(R - \phi_2 \cdot \frac{R}{\phi_1}\right)} \]
      6. distribute-rgt-neg-in10.2%

        \[\leadsto \color{blue}{\phi_1 \cdot \left(-\left(R - \phi_2 \cdot \frac{R}{\phi_1}\right)\right)} \]
      7. sub-neg10.2%

        \[\leadsto \phi_1 \cdot \left(-\color{blue}{\left(R + \left(-\phi_2 \cdot \frac{R}{\phi_1}\right)\right)}\right) \]
      8. associate-*r/19.3%

        \[\leadsto \phi_1 \cdot \left(-\left(R + \left(-\color{blue}{\frac{\phi_2 \cdot R}{\phi_1}}\right)\right)\right) \]
      9. *-commutative19.3%

        \[\leadsto \phi_1 \cdot \left(-\left(R + \left(-\frac{\color{blue}{R \cdot \phi_2}}{\phi_1}\right)\right)\right) \]
      10. mul-1-neg19.3%

        \[\leadsto \phi_1 \cdot \left(-\left(R + \color{blue}{-1 \cdot \frac{R \cdot \phi_2}{\phi_1}}\right)\right) \]
      11. distribute-neg-in19.3%

        \[\leadsto \phi_1 \cdot \color{blue}{\left(\left(-R\right) + \left(--1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
      12. mul-1-neg19.3%

        \[\leadsto \phi_1 \cdot \left(\color{blue}{-1 \cdot R} + \left(--1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right) \]
      13. mul-1-neg19.3%

        \[\leadsto \phi_1 \cdot \left(-1 \cdot R + \left(-\color{blue}{\left(-\frac{R \cdot \phi_2}{\phi_1}\right)}\right)\right) \]
      14. *-commutative19.3%

        \[\leadsto \phi_1 \cdot \left(-1 \cdot R + \left(-\left(-\frac{\color{blue}{\phi_2 \cdot R}}{\phi_1}\right)\right)\right) \]
      15. associate-*r/10.2%

        \[\leadsto \phi_1 \cdot \left(-1 \cdot R + \left(-\left(-\color{blue}{\phi_2 \cdot \frac{R}{\phi_1}}\right)\right)\right) \]
      16. remove-double-neg10.2%

        \[\leadsto \phi_1 \cdot \left(-1 \cdot R + \color{blue}{\phi_2 \cdot \frac{R}{\phi_1}}\right) \]
      17. associate-*r/19.3%

        \[\leadsto \phi_1 \cdot \left(-1 \cdot R + \color{blue}{\frac{\phi_2 \cdot R}{\phi_1}}\right) \]
      18. *-commutative19.3%

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

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

    if -5.39999999999999977e146 < lambda1 < 3.80000000000000005e-297 or 8.0000000000000006e-18 < lambda1

    1. Initial program 55.3%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg27.9%

        \[\leadsto \color{blue}{-\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
      2. distribute-rgt-neg-in27.9%

        \[\leadsto \color{blue}{\phi_1 \cdot \left(-\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
      3. mul-1-neg27.9%

        \[\leadsto \phi_1 \cdot \left(-\left(R + \color{blue}{\left(-\frac{R \cdot \phi_2}{\phi_1}\right)}\right)\right) \]
      4. unsub-neg27.9%

        \[\leadsto \phi_1 \cdot \left(-\color{blue}{\left(R - \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
      5. *-commutative27.9%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right) + R \cdot \phi_2} \]
    9. Step-by-step derivation
      1. +-commutative29.6%

        \[\leadsto \color{blue}{R \cdot \phi_2 + -1 \cdot \left(R \cdot \phi_1\right)} \]
      2. mul-1-neg29.6%

        \[\leadsto R \cdot \phi_2 + \color{blue}{\left(-R \cdot \phi_1\right)} \]
      3. unsub-neg29.6%

        \[\leadsto \color{blue}{R \cdot \phi_2 - R \cdot \phi_1} \]
      4. *-commutative29.6%

        \[\leadsto \color{blue}{\phi_2 \cdot R} - R \cdot \phi_1 \]
      5. *-commutative29.6%

        \[\leadsto \phi_2 \cdot R - \color{blue}{\phi_1 \cdot R} \]
    10. Simplified29.6%

      \[\leadsto \color{blue}{\phi_2 \cdot R - \phi_1 \cdot R} \]

    if 3.80000000000000005e-297 < lambda1 < 8.0000000000000006e-18

    1. Initial program 63.0%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define98.5%

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

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

      \[\leadsto \color{blue}{\phi_2 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_1}{\phi_2}\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg43.7%

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\left(-\frac{R \cdot \phi_1}{\phi_2}\right)}\right) \]
      2. unsub-neg43.7%

        \[\leadsto \phi_2 \cdot \color{blue}{\left(R - \frac{R \cdot \phi_1}{\phi_2}\right)} \]
      3. *-commutative43.7%

        \[\leadsto \phi_2 \cdot \left(R - \frac{\color{blue}{\phi_1 \cdot R}}{\phi_2}\right) \]
      4. associate-/l*43.6%

        \[\leadsto \phi_2 \cdot \left(R - \color{blue}{\phi_1 \cdot \frac{R}{\phi_2}}\right) \]
    7. Simplified43.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -7.5 \cdot 10^{+198}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq -9.5 \cdot 10^{+156}:\\ \;\;\;\;\phi_1 \cdot \left(R \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\ \mathbf{elif}\;\lambda_1 \leq -5.4 \cdot 10^{+146}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq 3.8 \cdot 10^{-297} \lor \neg \left(\lambda_1 \leq 8 \cdot 10^{-18}\right):\\ \;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 33.3% accurate, 9.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := R \cdot \left(-\lambda_1\right)\\ t_1 := \phi_1 \cdot \left(R \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\ \mathbf{if}\;\lambda_1 \leq -3.5 \cdot 10^{+200}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\lambda_1 \leq -1.12 \cdot 10^{+160}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\lambda_1 \leq -1.86 \cdot 10^{+149}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\lambda_1 \leq -2.15 \cdot 10^{-306} \lor \neg \left(\lambda_1 \leq 2 \cdot 10^{-181}\right):\\ \;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* R (- lambda1))) (t_1 (* phi1 (* R (+ (/ phi2 phi1) -1.0)))))
   (if (<= lambda1 -3.5e+200)
     t_0
     (if (<= lambda1 -1.12e+160)
       t_1
       (if (<= lambda1 -1.86e+149)
         t_0
         (if (or (<= lambda1 -2.15e-306) (not (<= lambda1 2e-181)))
           (- (* R phi2) (* R phi1))
           t_1))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * -lambda1;
	double t_1 = phi1 * (R * ((phi2 / phi1) + -1.0));
	double tmp;
	if (lambda1 <= -3.5e+200) {
		tmp = t_0;
	} else if (lambda1 <= -1.12e+160) {
		tmp = t_1;
	} else if (lambda1 <= -1.86e+149) {
		tmp = t_0;
	} else if ((lambda1 <= -2.15e-306) || !(lambda1 <= 2e-181)) {
		tmp = (R * phi2) - (R * phi1);
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    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
    real(8) :: t_1
    real(8) :: tmp
    t_0 = r * -lambda1
    t_1 = phi1 * (r * ((phi2 / phi1) + (-1.0d0)))
    if (lambda1 <= (-3.5d+200)) then
        tmp = t_0
    else if (lambda1 <= (-1.12d+160)) then
        tmp = t_1
    else if (lambda1 <= (-1.86d+149)) then
        tmp = t_0
    else if ((lambda1 <= (-2.15d-306)) .or. (.not. (lambda1 <= 2d-181))) then
        tmp = (r * phi2) - (r * phi1)
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * -lambda1;
	double t_1 = phi1 * (R * ((phi2 / phi1) + -1.0));
	double tmp;
	if (lambda1 <= -3.5e+200) {
		tmp = t_0;
	} else if (lambda1 <= -1.12e+160) {
		tmp = t_1;
	} else if (lambda1 <= -1.86e+149) {
		tmp = t_0;
	} else if ((lambda1 <= -2.15e-306) || !(lambda1 <= 2e-181)) {
		tmp = (R * phi2) - (R * phi1);
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = R * -lambda1
	t_1 = phi1 * (R * ((phi2 / phi1) + -1.0))
	tmp = 0
	if lambda1 <= -3.5e+200:
		tmp = t_0
	elif lambda1 <= -1.12e+160:
		tmp = t_1
	elif lambda1 <= -1.86e+149:
		tmp = t_0
	elif (lambda1 <= -2.15e-306) or not (lambda1 <= 2e-181):
		tmp = (R * phi2) - (R * phi1)
	else:
		tmp = t_1
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(R * Float64(-lambda1))
	t_1 = Float64(phi1 * Float64(R * Float64(Float64(phi2 / phi1) + -1.0)))
	tmp = 0.0
	if (lambda1 <= -3.5e+200)
		tmp = t_0;
	elseif (lambda1 <= -1.12e+160)
		tmp = t_1;
	elseif (lambda1 <= -1.86e+149)
		tmp = t_0;
	elseif ((lambda1 <= -2.15e-306) || !(lambda1 <= 2e-181))
		tmp = Float64(Float64(R * phi2) - Float64(R * phi1));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = R * -lambda1;
	t_1 = phi1 * (R * ((phi2 / phi1) + -1.0));
	tmp = 0.0;
	if (lambda1 <= -3.5e+200)
		tmp = t_0;
	elseif (lambda1 <= -1.12e+160)
		tmp = t_1;
	elseif (lambda1 <= -1.86e+149)
		tmp = t_0;
	elseif ((lambda1 <= -2.15e-306) || ~((lambda1 <= 2e-181)))
		tmp = (R * phi2) - (R * phi1);
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(R * (-lambda1)), $MachinePrecision]}, Block[{t$95$1 = N[(phi1 * N[(R * N[(N[(phi2 / phi1), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda1, -3.5e+200], t$95$0, If[LessEqual[lambda1, -1.12e+160], t$95$1, If[LessEqual[lambda1, -1.86e+149], t$95$0, If[Or[LessEqual[lambda1, -2.15e-306], N[Not[LessEqual[lambda1, 2e-181]], $MachinePrecision]], N[(N[(R * phi2), $MachinePrecision] - N[(R * phi1), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := R \cdot \left(-\lambda_1\right)\\
t_1 := \phi_1 \cdot \left(R \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\
\mathbf{if}\;\lambda_1 \leq -3.5 \cdot 10^{+200}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\lambda_1 \leq -1.12 \cdot 10^{+160}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\lambda_1 \leq -1.86 \cdot 10^{+149}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\lambda_1 \leq -2.15 \cdot 10^{-306} \lor \neg \left(\lambda_1 \leq 2 \cdot 10^{-181}\right):\\
\;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if lambda1 < -3.50000000000000006e200 or -1.12e160 < lambda1 < -1.85999999999999997e149

    1. Initial program 68.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. Step-by-step derivation
      1. hypot-define99.5%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg53.0%

        \[\leadsto \color{blue}{-R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \]
      2. associate-*r*53.0%

        \[\leadsto -\color{blue}{\left(R \cdot \lambda_1\right) \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)} \]
      3. distribute-lft-neg-in53.0%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)} \]
    9. Step-by-step derivation
      1. associate-*r*59.6%

        \[\leadsto \color{blue}{\left(-1 \cdot R\right) \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
      2. mul-1-neg59.6%

        \[\leadsto \color{blue}{\left(-R\right)} \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \]
      3. *-commutative59.6%

        \[\leadsto \left(-R\right) \cdot \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1\right)} \]
    10. Simplified59.6%

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

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

    if -3.50000000000000006e200 < lambda1 < -1.12e160 or -2.15e-306 < lambda1 < 2.00000000000000009e-181

    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. Step-by-step derivation
      1. hypot-define97.7%

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

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. add-sqr-sqrt97.3%

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

        \[\leadsto R \cdot \color{blue}{{\left(\sqrt{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)}\right)}^{2}} \]
      3. *-commutative97.3%

        \[\leadsto R \cdot {\left(\sqrt{\mathsf{hypot}\left(\color{blue}{\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)}, \phi_1 - \phi_2\right)}\right)}^{2} \]
      4. div-inv97.3%

        \[\leadsto R \cdot {\left(\sqrt{\mathsf{hypot}\left(\cos \color{blue}{\left(\left(\phi_1 + \phi_2\right) \cdot \frac{1}{2}\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)}\right)}^{2} \]
      5. metadata-eval97.3%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
    8. Step-by-step derivation
      1. mul-1-neg30.1%

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

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

        \[\leadsto -\phi_1 \cdot \left(R + \left(-\frac{\color{blue}{\phi_2 \cdot R}}{\phi_1}\right)\right) \]
      4. associate-*r/24.3%

        \[\leadsto -\phi_1 \cdot \left(R + \left(-\color{blue}{\phi_2 \cdot \frac{R}{\phi_1}}\right)\right) \]
      5. sub-neg24.3%

        \[\leadsto -\phi_1 \cdot \color{blue}{\left(R - \phi_2 \cdot \frac{R}{\phi_1}\right)} \]
      6. distribute-rgt-neg-in24.3%

        \[\leadsto \color{blue}{\phi_1 \cdot \left(-\left(R - \phi_2 \cdot \frac{R}{\phi_1}\right)\right)} \]
      7. sub-neg24.3%

        \[\leadsto \phi_1 \cdot \left(-\color{blue}{\left(R + \left(-\phi_2 \cdot \frac{R}{\phi_1}\right)\right)}\right) \]
      8. associate-*r/30.1%

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

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

        \[\leadsto \phi_1 \cdot \left(-\left(R + \color{blue}{-1 \cdot \frac{R \cdot \phi_2}{\phi_1}}\right)\right) \]
      11. distribute-neg-in30.1%

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

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

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

        \[\leadsto \phi_1 \cdot \left(-1 \cdot R + \left(-\left(-\frac{\color{blue}{\phi_2 \cdot R}}{\phi_1}\right)\right)\right) \]
      15. associate-*r/24.3%

        \[\leadsto \phi_1 \cdot \left(-1 \cdot R + \left(-\left(-\color{blue}{\phi_2 \cdot \frac{R}{\phi_1}}\right)\right)\right) \]
      16. remove-double-neg24.3%

        \[\leadsto \phi_1 \cdot \left(-1 \cdot R + \color{blue}{\phi_2 \cdot \frac{R}{\phi_1}}\right) \]
      17. associate-*r/30.1%

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

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

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

    if -1.85999999999999997e149 < lambda1 < -2.15e-306 or 2.00000000000000009e-181 < lambda1

    1. Initial program 55.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. Step-by-step derivation
      1. hypot-define97.3%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg30.8%

        \[\leadsto \color{blue}{-\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
      2. distribute-rgt-neg-in30.8%

        \[\leadsto \color{blue}{\phi_1 \cdot \left(-\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
      3. mul-1-neg30.8%

        \[\leadsto \phi_1 \cdot \left(-\left(R + \color{blue}{\left(-\frac{R \cdot \phi_2}{\phi_1}\right)}\right)\right) \]
      4. unsub-neg30.8%

        \[\leadsto \phi_1 \cdot \left(-\color{blue}{\left(R - \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
      5. *-commutative30.8%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right) + R \cdot \phi_2} \]
    9. Step-by-step derivation
      1. +-commutative32.3%

        \[\leadsto \color{blue}{R \cdot \phi_2 + -1 \cdot \left(R \cdot \phi_1\right)} \]
      2. mul-1-neg32.3%

        \[\leadsto R \cdot \phi_2 + \color{blue}{\left(-R \cdot \phi_1\right)} \]
      3. unsub-neg32.3%

        \[\leadsto \color{blue}{R \cdot \phi_2 - R \cdot \phi_1} \]
      4. *-commutative32.3%

        \[\leadsto \color{blue}{\phi_2 \cdot R} - R \cdot \phi_1 \]
      5. *-commutative32.3%

        \[\leadsto \phi_2 \cdot R - \color{blue}{\phi_1 \cdot R} \]
    10. Simplified32.3%

      \[\leadsto \color{blue}{\phi_2 \cdot R - \phi_1 \cdot R} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification34.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -3.5 \cdot 10^{+200}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq -1.12 \cdot 10^{+160}:\\ \;\;\;\;\phi_1 \cdot \left(R \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\ \mathbf{elif}\;\lambda_1 \leq -1.86 \cdot 10^{+149}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq -2.15 \cdot 10^{-306} \lor \neg \left(\lambda_1 \leq 2 \cdot 10^{-181}\right):\\ \;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\ \mathbf{else}:\\ \;\;\;\;\phi_1 \cdot \left(R \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 33.8% accurate, 11.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := R \cdot \left(-\lambda_1\right)\\ \mathbf{if}\;\lambda_1 \leq -3.2 \cdot 10^{+198}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\lambda_1 \leq -5.8 \cdot 10^{+156}:\\ \;\;\;\;R \cdot \left(\phi_1 \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\ \mathbf{elif}\;\lambda_1 \leq -9 \cdot 10^{+144}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\lambda_1 \leq 1.95 \cdot 10^{-307}:\\ \;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\ \mathbf{else}:\\ \;\;\;\;\phi_1 \cdot \left(\phi_2 \cdot \frac{R}{\phi_1} - R\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* R (- lambda1))))
   (if (<= lambda1 -3.2e+198)
     t_0
     (if (<= lambda1 -5.8e+156)
       (* R (* phi1 (+ (/ phi2 phi1) -1.0)))
       (if (<= lambda1 -9e+144)
         t_0
         (if (<= lambda1 1.95e-307)
           (- (* R phi2) (* R phi1))
           (* phi1 (- (* phi2 (/ R phi1)) R))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * -lambda1;
	double tmp;
	if (lambda1 <= -3.2e+198) {
		tmp = t_0;
	} else if (lambda1 <= -5.8e+156) {
		tmp = R * (phi1 * ((phi2 / phi1) + -1.0));
	} else if (lambda1 <= -9e+144) {
		tmp = t_0;
	} else if (lambda1 <= 1.95e-307) {
		tmp = (R * phi2) - (R * phi1);
	} else {
		tmp = phi1 * ((phi2 * (R / phi1)) - R);
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    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
    real(8) :: tmp
    t_0 = r * -lambda1
    if (lambda1 <= (-3.2d+198)) then
        tmp = t_0
    else if (lambda1 <= (-5.8d+156)) then
        tmp = r * (phi1 * ((phi2 / phi1) + (-1.0d0)))
    else if (lambda1 <= (-9d+144)) then
        tmp = t_0
    else if (lambda1 <= 1.95d-307) then
        tmp = (r * phi2) - (r * phi1)
    else
        tmp = phi1 * ((phi2 * (r / phi1)) - r)
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * -lambda1;
	double tmp;
	if (lambda1 <= -3.2e+198) {
		tmp = t_0;
	} else if (lambda1 <= -5.8e+156) {
		tmp = R * (phi1 * ((phi2 / phi1) + -1.0));
	} else if (lambda1 <= -9e+144) {
		tmp = t_0;
	} else if (lambda1 <= 1.95e-307) {
		tmp = (R * phi2) - (R * phi1);
	} else {
		tmp = phi1 * ((phi2 * (R / phi1)) - R);
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = R * -lambda1
	tmp = 0
	if lambda1 <= -3.2e+198:
		tmp = t_0
	elif lambda1 <= -5.8e+156:
		tmp = R * (phi1 * ((phi2 / phi1) + -1.0))
	elif lambda1 <= -9e+144:
		tmp = t_0
	elif lambda1 <= 1.95e-307:
		tmp = (R * phi2) - (R * phi1)
	else:
		tmp = phi1 * ((phi2 * (R / phi1)) - R)
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(R * Float64(-lambda1))
	tmp = 0.0
	if (lambda1 <= -3.2e+198)
		tmp = t_0;
	elseif (lambda1 <= -5.8e+156)
		tmp = Float64(R * Float64(phi1 * Float64(Float64(phi2 / phi1) + -1.0)));
	elseif (lambda1 <= -9e+144)
		tmp = t_0;
	elseif (lambda1 <= 1.95e-307)
		tmp = Float64(Float64(R * phi2) - Float64(R * phi1));
	else
		tmp = Float64(phi1 * Float64(Float64(phi2 * Float64(R / phi1)) - R));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = R * -lambda1;
	tmp = 0.0;
	if (lambda1 <= -3.2e+198)
		tmp = t_0;
	elseif (lambda1 <= -5.8e+156)
		tmp = R * (phi1 * ((phi2 / phi1) + -1.0));
	elseif (lambda1 <= -9e+144)
		tmp = t_0;
	elseif (lambda1 <= 1.95e-307)
		tmp = (R * phi2) - (R * phi1);
	else
		tmp = phi1 * ((phi2 * (R / phi1)) - R);
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(R * (-lambda1)), $MachinePrecision]}, If[LessEqual[lambda1, -3.2e+198], t$95$0, If[LessEqual[lambda1, -5.8e+156], N[(R * N[(phi1 * N[(N[(phi2 / phi1), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[lambda1, -9e+144], t$95$0, If[LessEqual[lambda1, 1.95e-307], N[(N[(R * phi2), $MachinePrecision] - N[(R * phi1), $MachinePrecision]), $MachinePrecision], N[(phi1 * N[(N[(phi2 * N[(R / phi1), $MachinePrecision]), $MachinePrecision] - R), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := R \cdot \left(-\lambda_1\right)\\
\mathbf{if}\;\lambda_1 \leq -3.2 \cdot 10^{+198}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\lambda_1 \leq -5.8 \cdot 10^{+156}:\\
\;\;\;\;R \cdot \left(\phi_1 \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\

\mathbf{elif}\;\lambda_1 \leq -9 \cdot 10^{+144}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\lambda_1 \leq 1.95 \cdot 10^{-307}:\\
\;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\

\mathbf{else}:\\
\;\;\;\;\phi_1 \cdot \left(\phi_2 \cdot \frac{R}{\phi_1} - R\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if lambda1 < -3.1999999999999998e198 or -5.80000000000000021e156 < lambda1 < -8.99999999999999935e144

    1. Initial program 68.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. Step-by-step derivation
      1. hypot-define99.5%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg53.0%

        \[\leadsto \color{blue}{-R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \]
      2. associate-*r*53.0%

        \[\leadsto -\color{blue}{\left(R \cdot \lambda_1\right) \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)} \]
      3. distribute-lft-neg-in53.0%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)} \]
    9. Step-by-step derivation
      1. associate-*r*59.6%

        \[\leadsto \color{blue}{\left(-1 \cdot R\right) \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
      2. mul-1-neg59.6%

        \[\leadsto \color{blue}{\left(-R\right)} \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \]
      3. *-commutative59.6%

        \[\leadsto \left(-R\right) \cdot \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1\right)} \]
    10. Simplified59.6%

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

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

    if -3.1999999999999998e198 < lambda1 < -5.80000000000000021e156

    1. Initial program 31.2%

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

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

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

      \[\leadsto R \cdot \color{blue}{\left(-1 \cdot \left(\phi_1 \cdot \left(1 + -1 \cdot \frac{\phi_2}{\phi_1}\right)\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg10.3%

        \[\leadsto R \cdot \color{blue}{\left(-\phi_1 \cdot \left(1 + -1 \cdot \frac{\phi_2}{\phi_1}\right)\right)} \]
      2. distribute-rgt-neg-in10.3%

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

        \[\leadsto R \cdot \left(\phi_1 \cdot \left(-\left(1 + \color{blue}{\left(-\frac{\phi_2}{\phi_1}\right)}\right)\right)\right) \]
      4. unsub-neg10.3%

        \[\leadsto R \cdot \left(\phi_1 \cdot \left(-\color{blue}{\left(1 - \frac{\phi_2}{\phi_1}\right)}\right)\right) \]
    7. Simplified10.3%

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

    if -8.99999999999999935e144 < lambda1 < 1.95e-307

    1. Initial program 58.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. Step-by-step derivation
      1. hypot-define98.2%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg33.0%

        \[\leadsto \color{blue}{-\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
      2. distribute-rgt-neg-in33.0%

        \[\leadsto \color{blue}{\phi_1 \cdot \left(-\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
      3. mul-1-neg33.0%

        \[\leadsto \phi_1 \cdot \left(-\left(R + \color{blue}{\left(-\frac{R \cdot \phi_2}{\phi_1}\right)}\right)\right) \]
      4. unsub-neg33.0%

        \[\leadsto \phi_1 \cdot \left(-\color{blue}{\left(R - \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
      5. *-commutative33.0%

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

        \[\leadsto \phi_1 \cdot \left(-\left(R - \color{blue}{\phi_2 \cdot \frac{R}{\phi_1}}\right)\right) \]
    7. Simplified34.9%

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right) + R \cdot \phi_2} \]
    9. Step-by-step derivation
      1. +-commutative36.2%

        \[\leadsto \color{blue}{R \cdot \phi_2 + -1 \cdot \left(R \cdot \phi_1\right)} \]
      2. mul-1-neg36.2%

        \[\leadsto R \cdot \phi_2 + \color{blue}{\left(-R \cdot \phi_1\right)} \]
      3. unsub-neg36.2%

        \[\leadsto \color{blue}{R \cdot \phi_2 - R \cdot \phi_1} \]
      4. *-commutative36.2%

        \[\leadsto \color{blue}{\phi_2 \cdot R} - R \cdot \phi_1 \]
      5. *-commutative36.2%

        \[\leadsto \phi_2 \cdot R - \color{blue}{\phi_1 \cdot R} \]
    10. Simplified36.2%

      \[\leadsto \color{blue}{\phi_2 \cdot R - \phi_1 \cdot R} \]

    if 1.95e-307 < lambda1

    1. Initial program 56.0%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define96.7%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg30.1%

        \[\leadsto \color{blue}{-\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
      2. distribute-rgt-neg-in30.1%

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

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

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

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

        \[\leadsto \phi_1 \cdot \left(-\left(R - \color{blue}{\phi_2 \cdot \frac{R}{\phi_1}}\right)\right) \]
    7. Simplified30.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -3.2 \cdot 10^{+198}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq -5.8 \cdot 10^{+156}:\\ \;\;\;\;R \cdot \left(\phi_1 \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\ \mathbf{elif}\;\lambda_1 \leq -9 \cdot 10^{+144}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq 1.95 \cdot 10^{-307}:\\ \;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\ \mathbf{else}:\\ \;\;\;\;\phi_1 \cdot \left(\phi_2 \cdot \frac{R}{\phi_1} - R\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 29.2% accurate, 23.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -215:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -5 \cdot 10^{-61}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi1 -215.0)
   (* R (- phi1))
   (if (<= phi1 -5e-61) (* R (- lambda1)) (* R phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -215.0) {
		tmp = R * -phi1;
	} else if (phi1 <= -5e-61) {
		tmp = R * -lambda1;
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: tmp
    if (phi1 <= (-215.0d0)) then
        tmp = r * -phi1
    else if (phi1 <= (-5d-61)) then
        tmp = r * -lambda1
    else
        tmp = r * phi2
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -215.0) {
		tmp = R * -phi1;
	} else if (phi1 <= -5e-61) {
		tmp = R * -lambda1;
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -215.0:
		tmp = R * -phi1
	elif phi1 <= -5e-61:
		tmp = R * -lambda1
	else:
		tmp = R * phi2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -215.0)
		tmp = Float64(R * Float64(-phi1));
	elseif (phi1 <= -5e-61)
		tmp = Float64(R * Float64(-lambda1));
	else
		tmp = Float64(R * phi2);
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi1 <= -215.0)
		tmp = R * -phi1;
	elseif (phi1 <= -5e-61)
		tmp = R * -lambda1;
	else
		tmp = R * phi2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -215.0], N[(R * (-phi1)), $MachinePrecision], If[LessEqual[phi1, -5e-61], N[(R * (-lambda1)), $MachinePrecision], N[(R * phi2), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -215:\\
\;\;\;\;R \cdot \left(-\phi_1\right)\\

\mathbf{elif}\;\phi_1 \leq -5 \cdot 10^{-61}:\\
\;\;\;\;R \cdot \left(-\lambda_1\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \phi_2\\


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

    1. Initial program 47.4%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define94.6%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg65.5%

        \[\leadsto \color{blue}{-R \cdot \phi_1} \]
      2. *-commutative65.5%

        \[\leadsto -\color{blue}{\phi_1 \cdot R} \]
      3. distribute-rgt-neg-in65.5%

        \[\leadsto \color{blue}{\phi_1 \cdot \left(-R\right)} \]
    7. Simplified65.5%

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

    if -215 < phi1 < -4.9999999999999999e-61

    1. Initial program 66.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. Step-by-step derivation
      1. hypot-define99.9%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg23.7%

        \[\leadsto \color{blue}{-R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \]
      2. associate-*r*23.7%

        \[\leadsto -\color{blue}{\left(R \cdot \lambda_1\right) \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)} \]
      3. distribute-lft-neg-in23.7%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)} \]
    9. Step-by-step derivation
      1. associate-*r*24.6%

        \[\leadsto \color{blue}{\left(-1 \cdot R\right) \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
      2. mul-1-neg24.6%

        \[\leadsto \color{blue}{\left(-R\right)} \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \]
      3. *-commutative24.6%

        \[\leadsto \left(-R\right) \cdot \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1\right)} \]
    10. Simplified24.6%

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

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

    if -4.9999999999999999e-61 < phi1

    1. Initial program 59.4%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define98.5%

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

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

      \[\leadsto \color{blue}{R \cdot \phi_2} \]
    6. Step-by-step derivation
      1. *-commutative19.7%

        \[\leadsto \color{blue}{\phi_2 \cdot R} \]
    7. Simplified19.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -215:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -5 \cdot 10^{-61}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 33.5% accurate, 27.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -2.25 \cdot 10^{+195}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= lambda1 -2.25e+195) (* R (- lambda1)) (- (* R phi2) (* R phi1))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda1 <= -2.25e+195) {
		tmp = R * -lambda1;
	} else {
		tmp = (R * phi2) - (R * phi1);
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: tmp
    if (lambda1 <= (-2.25d+195)) then
        tmp = r * -lambda1
    else
        tmp = (r * phi2) - (r * phi1)
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda1 <= -2.25e+195) {
		tmp = R * -lambda1;
	} else {
		tmp = (R * phi2) - (R * phi1);
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if lambda1 <= -2.25e+195:
		tmp = R * -lambda1
	else:
		tmp = (R * phi2) - (R * phi1)
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (lambda1 <= -2.25e+195)
		tmp = Float64(R * Float64(-lambda1));
	else
		tmp = Float64(Float64(R * phi2) - Float64(R * phi1));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (lambda1 <= -2.25e+195)
		tmp = R * -lambda1;
	else
		tmp = (R * phi2) - (R * phi1);
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda1, -2.25e+195], N[(R * (-lambda1)), $MachinePrecision], N[(N[(R * phi2), $MachinePrecision] - N[(R * phi1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 \leq -2.25 \cdot 10^{+195}:\\
\;\;\;\;R \cdot \left(-\lambda_1\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda1 < -2.25000000000000005e195

    1. Initial program 65.2%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define99.5%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg42.8%

        \[\leadsto \color{blue}{-R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \]
      2. associate-*r*42.8%

        \[\leadsto -\color{blue}{\left(R \cdot \lambda_1\right) \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)} \]
      3. distribute-lft-neg-in42.8%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)} \]
    9. Step-by-step derivation
      1. associate-*r*54.4%

        \[\leadsto \color{blue}{\left(-1 \cdot R\right) \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
      2. mul-1-neg54.4%

        \[\leadsto \color{blue}{\left(-R\right)} \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \]
      3. *-commutative54.4%

        \[\leadsto \left(-R\right) \cdot \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1\right)} \]
    10. Simplified54.4%

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

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

    if -2.25000000000000005e195 < lambda1

    1. Initial program 56.3%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define97.4%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg30.1%

        \[\leadsto \color{blue}{-\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)} \]
      2. distribute-rgt-neg-in30.1%

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

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

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

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

        \[\leadsto \phi_1 \cdot \left(-\left(R - \color{blue}{\phi_2 \cdot \frac{R}{\phi_1}}\right)\right) \]
    7. Simplified31.2%

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right) + R \cdot \phi_2} \]
    9. Step-by-step derivation
      1. +-commutative30.5%

        \[\leadsto \color{blue}{R \cdot \phi_2 + -1 \cdot \left(R \cdot \phi_1\right)} \]
      2. mul-1-neg30.5%

        \[\leadsto R \cdot \phi_2 + \color{blue}{\left(-R \cdot \phi_1\right)} \]
      3. unsub-neg30.5%

        \[\leadsto \color{blue}{R \cdot \phi_2 - R \cdot \phi_1} \]
      4. *-commutative30.5%

        \[\leadsto \color{blue}{\phi_2 \cdot R} - R \cdot \phi_1 \]
      5. *-commutative30.5%

        \[\leadsto \phi_2 \cdot R - \color{blue}{\phi_1 \cdot R} \]
    10. Simplified30.5%

      \[\leadsto \color{blue}{\phi_2 \cdot R - \phi_1 \cdot R} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification34.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -2.25 \cdot 10^{+195}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 29.4% accurate, 36.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1820:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi1 -1820.0) (* R (- phi1)) (* R phi2)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -1820.0) {
		tmp = R * -phi1;
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: tmp
    if (phi1 <= (-1820.0d0)) then
        tmp = r * -phi1
    else
        tmp = r * phi2
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -1820.0) {
		tmp = R * -phi1;
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -1820.0:
		tmp = R * -phi1
	else:
		tmp = R * phi2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -1820.0)
		tmp = Float64(R * Float64(-phi1));
	else
		tmp = Float64(R * phi2);
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi1 <= -1820.0)
		tmp = R * -phi1;
	else
		tmp = R * phi2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -1820.0], N[(R * (-phi1)), $MachinePrecision], N[(R * phi2), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -1820:\\
\;\;\;\;R \cdot \left(-\phi_1\right)\\

\mathbf{else}:\\
\;\;\;\;R \cdot \phi_2\\


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

    1. Initial program 47.4%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define94.6%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg65.5%

        \[\leadsto \color{blue}{-R \cdot \phi_1} \]
      2. *-commutative65.5%

        \[\leadsto -\color{blue}{\phi_1 \cdot R} \]
      3. distribute-rgt-neg-in65.5%

        \[\leadsto \color{blue}{\phi_1 \cdot \left(-R\right)} \]
    7. Simplified65.5%

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

    if -1820 < phi1

    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. Step-by-step derivation
      1. hypot-define98.6%

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

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

      \[\leadsto \color{blue}{R \cdot \phi_2} \]
    6. Step-by-step derivation
      1. *-commutative19.2%

        \[\leadsto \color{blue}{\phi_2 \cdot R} \]
    7. Simplified19.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1820:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 16: 18.2% accurate, 109.7× speedup?

\[\begin{array}{l} \\ R \cdot \phi_2 \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R phi2))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * phi2;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = r * phi2
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * phi2;
}
def code(R, lambda1, lambda2, phi1, phi2):
	return R * phi2
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(R * phi2)
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = R * phi2;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * phi2), $MachinePrecision]
\begin{array}{l}

\\
R \cdot \phi_2
\end{array}
Derivation
  1. Initial program 57.0%

    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
  2. Step-by-step derivation
    1. hypot-define97.6%

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

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

    \[\leadsto \color{blue}{R \cdot \phi_2} \]
  6. Step-by-step derivation
    1. *-commutative17.9%

      \[\leadsto \color{blue}{\phi_2 \cdot R} \]
  7. Simplified17.9%

    \[\leadsto \color{blue}{\phi_2 \cdot R} \]
  8. Final simplification17.9%

    \[\leadsto R \cdot \phi_2 \]
  9. Add Preprocessing

Alternative 17: 14.0% accurate, 109.7× speedup?

\[\begin{array}{l} \\ R \cdot \lambda_1 \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R lambda1))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * lambda1;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = r * lambda1
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * lambda1;
}
def code(R, lambda1, lambda2, phi1, phi2):
	return R * lambda1
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(R * lambda1)
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = R * lambda1;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * lambda1), $MachinePrecision]
\begin{array}{l}

\\
R \cdot \lambda_1
\end{array}
Derivation
  1. Initial program 57.0%

    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
  2. Step-by-step derivation
    1. hypot-define97.6%

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

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

    \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} \]
  6. Step-by-step derivation
    1. mul-1-neg12.2%

      \[\leadsto \color{blue}{-R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \]
    2. associate-*r*12.2%

      \[\leadsto -\color{blue}{\left(R \cdot \lambda_1\right) \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)} \]
    3. distribute-lft-neg-in12.2%

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

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

    \[\leadsto \color{blue}{\left(-R \cdot \lambda_1\right) \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)} \]
  8. Step-by-step derivation
    1. add-sqr-sqrt7.0%

      \[\leadsto \color{blue}{\sqrt{\left(-R \cdot \lambda_1\right) \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)} \cdot \sqrt{\left(-R \cdot \lambda_1\right) \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)}} \]
    2. pow27.0%

      \[\leadsto \color{blue}{{\left(\sqrt{\left(-R \cdot \lambda_1\right) \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)}\right)}^{2}} \]
    3. *-commutative7.0%

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

      \[\leadsto {\left(\sqrt{\cos \left(0.5 \cdot \color{blue}{\left(\phi_1 + \phi_2\right)}\right) \cdot \left(-R \cdot \lambda_1\right)}\right)}^{2} \]
    5. *-commutative7.0%

      \[\leadsto {\left(\sqrt{\cos \color{blue}{\left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right)} \cdot \left(-R \cdot \lambda_1\right)}\right)}^{2} \]
    6. add-sqr-sqrt4.7%

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

      \[\leadsto {\left(\sqrt{\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right) \cdot \color{blue}{\sqrt{\left(-R \cdot \lambda_1\right) \cdot \left(-R \cdot \lambda_1\right)}}}\right)}^{2} \]
    8. sqr-neg12.3%

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

      \[\leadsto {\left(\sqrt{\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right) \cdot \color{blue}{\left(\sqrt{R \cdot \lambda_1} \cdot \sqrt{R \cdot \lambda_1}\right)}}\right)}^{2} \]
    10. add-sqr-sqrt11.5%

      \[\leadsto {\left(\sqrt{\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right) \cdot \color{blue}{\left(R \cdot \lambda_1\right)}}\right)}^{2} \]
    11. *-commutative11.5%

      \[\leadsto {\left(\sqrt{\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right) \cdot \color{blue}{\left(\lambda_1 \cdot R\right)}}\right)}^{2} \]
  9. Applied egg-rr11.5%

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

    \[\leadsto \color{blue}{R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)} \]
  11. Step-by-step derivation
    1. associate-*r*16.7%

      \[\leadsto \color{blue}{\left(R \cdot \lambda_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right)} \]
    2. *-commutative16.7%

      \[\leadsto \color{blue}{\left(\lambda_1 \cdot R\right)} \cdot \cos \left(0.5 \cdot \phi_2\right) \]
  12. Simplified16.7%

    \[\leadsto \color{blue}{\left(\lambda_1 \cdot R\right) \cdot \cos \left(0.5 \cdot \phi_2\right)} \]
  13. Taylor expanded in phi2 around 0 14.0%

    \[\leadsto \color{blue}{R \cdot \lambda_1} \]
  14. Step-by-step derivation
    1. *-commutative14.0%

      \[\leadsto \color{blue}{\lambda_1 \cdot R} \]
  15. Simplified14.0%

    \[\leadsto \color{blue}{\lambda_1 \cdot R} \]
  16. Final simplification14.0%

    \[\leadsto R \cdot \lambda_1 \]
  17. Add Preprocessing

Reproduce

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