Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.5% → 99.8%
Time: 20.4s
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: 59.5% 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.8% accurate, 0.5× speedup?

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

    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
  2. Step-by-step derivation
    1. hypot-define96.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. Simplified96.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. Step-by-step derivation
    1. log1p-expm1-u96.5%

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \color{blue}{\left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}\right)\right), \phi_1 - \phi_2\right) \]
    2. distribute-rgt-in96.5%

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

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

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

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

Alternative 2: 95.6% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq 2.2 \cdot 10^{+80}:\\
\;\;\;\;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)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda2 < 2.20000000000000003e80

    1. Initial program 62.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

    if 2.20000000000000003e80 < lambda2

    1. Initial program 55.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-define95.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. Simplified95.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. Step-by-step derivation
      1. log1p-expm1-u95.0%

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

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \color{blue}{\left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}\right)\right), \phi_1 - \phi_2\right) \]
      2. distribute-rgt-in95.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 2.2 \cdot 10^{+80}:\\ \;\;\;\;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)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_2 \cdot \left(\sin \left(\phi_1 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_2\right) - \cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_2\right)\right), \phi_1 - \phi_2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 93.0% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 65.1%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. 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. Taylor expanded in phi2 around 0 93.9%

      \[\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 7.20000000000000031e25 < phi2

    1. Initial program 49.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-define93.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. Simplified93.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 0 93.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) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification93.7%

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

Alternative 4: 91.1% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 64.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. Taylor expanded in phi2 around 0 93.9%

      \[\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 2.1000000000000001e40 < phi2

    1. Initial program 48.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-define93.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. Simplified93.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 phi1 around 0 92.9%

      \[\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 inf 89.4%

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

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

Alternative 5: 75.1% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 65.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-define98.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. Simplified98.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 89.9%

      \[\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 56.4%

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

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

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

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

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

    if 4.00000000000000027e-37 < phi2

    1. Initial program 49.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-define91.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. Simplified91.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 0 90.9%

      \[\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 inf 86.3%

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

Alternative 6: 96.3% accurate, 1.5× speedup?

\[\begin{array}{l} \\ 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) \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R
  (hypot (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0))) (- phi1 phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * hypot(((lambda1 - lambda2) * cos(((phi1 + phi2) / 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(((phi1 + phi2) / 2.0))), (phi1 - phi2));
}
def code(R, lambda1, lambda2, phi1, phi2):
	return R * math.hypot(((lambda1 - lambda2) * math.cos(((phi1 + phi2) / 2.0))), (phi1 - phi2))
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(R * hypot(Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi1 + phi2) / 2.0))), Float64(phi1 - phi2)))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = R * hypot(((lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0))), (phi1 - phi2));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[Sqrt[N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(N[(phi1 + phi2), $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_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 61.0%

    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
  2. Step-by-step derivation
    1. hypot-define96.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. Simplified96.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. Add Preprocessing

Alternative 7: 70.7% accurate, 3.0× speedup?

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

    1. Initial program 65.1%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. 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. Taylor expanded in phi1 around 0 89.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) \]
    6. Taylor expanded in phi2 around 0 56.0%

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

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

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

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

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

    if 3.20000000000000015e27 < phi2

    1. Initial program 49.0%

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

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

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

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

      \[\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 8: 45.8% accurate, 13.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -6 \cdot 10^{+152}:\\ \;\;\;\;\phi_1 \cdot \left(R \cdot \frac{\phi_2}{\phi_1} - R\right)\\ \mathbf{elif}\;\phi_1 \leq -1.55 \cdot 10^{-49}:\\ \;\;\;\;\phi_2 \cdot \left(R - \frac{R \cdot \phi_1}{\phi_2}\right)\\ \mathbf{elif}\;\phi_1 \leq 2.2 \cdot 10^{-266}:\\ \;\;\;\;\lambda_1 \cdot \left(\frac{R \cdot \lambda_2}{\lambda_1} - R\right)\\ \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
 (if (<= phi1 -6e+152)
   (* phi1 (- (* R (/ phi2 phi1)) R))
   (if (<= phi1 -1.55e-49)
     (* phi2 (- R (/ (* R phi1) phi2)))
     (if (<= phi1 2.2e-266)
       (* lambda1 (- (/ (* R lambda2) lambda1) R))
       (* phi2 (+ R (* phi1 (/ R phi2))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -6e+152) {
		tmp = phi1 * ((R * (phi2 / phi1)) - R);
	} else if (phi1 <= -1.55e-49) {
		tmp = phi2 * (R - ((R * phi1) / phi2));
	} else if (phi1 <= 2.2e-266) {
		tmp = lambda1 * (((R * lambda2) / lambda1) - R);
	} 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) :: tmp
    if (phi1 <= (-6d+152)) then
        tmp = phi1 * ((r * (phi2 / phi1)) - r)
    else if (phi1 <= (-1.55d-49)) then
        tmp = phi2 * (r - ((r * phi1) / phi2))
    else if (phi1 <= 2.2d-266) then
        tmp = lambda1 * (((r * lambda2) / lambda1) - r)
    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 tmp;
	if (phi1 <= -6e+152) {
		tmp = phi1 * ((R * (phi2 / phi1)) - R);
	} else if (phi1 <= -1.55e-49) {
		tmp = phi2 * (R - ((R * phi1) / phi2));
	} else if (phi1 <= 2.2e-266) {
		tmp = lambda1 * (((R * lambda2) / lambda1) - R);
	} else {
		tmp = phi2 * (R + (phi1 * (R / phi2)));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -6e+152:
		tmp = phi1 * ((R * (phi2 / phi1)) - R)
	elif phi1 <= -1.55e-49:
		tmp = phi2 * (R - ((R * phi1) / phi2))
	elif phi1 <= 2.2e-266:
		tmp = lambda1 * (((R * lambda2) / lambda1) - R)
	else:
		tmp = phi2 * (R + (phi1 * (R / phi2)))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -6e+152)
		tmp = Float64(phi1 * Float64(Float64(R * Float64(phi2 / phi1)) - R));
	elseif (phi1 <= -1.55e-49)
		tmp = Float64(phi2 * Float64(R - Float64(Float64(R * phi1) / phi2)));
	elseif (phi1 <= 2.2e-266)
		tmp = Float64(lambda1 * Float64(Float64(Float64(R * lambda2) / lambda1) - R));
	else
		tmp = Float64(phi2 * Float64(R + Float64(phi1 * Float64(R / phi2))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi1 <= -6e+152)
		tmp = phi1 * ((R * (phi2 / phi1)) - R);
	elseif (phi1 <= -1.55e-49)
		tmp = phi2 * (R - ((R * phi1) / phi2));
	elseif (phi1 <= 2.2e-266)
		tmp = lambda1 * (((R * lambda2) / lambda1) - R);
	else
		tmp = phi2 * (R + (phi1 * (R / phi2)));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -6e+152], N[(phi1 * N[(N[(R * N[(phi2 / phi1), $MachinePrecision]), $MachinePrecision] - R), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, -1.55e-49], N[(phi2 * N[(R - N[(N[(R * phi1), $MachinePrecision] / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 2.2e-266], N[(lambda1 * N[(N[(N[(R * lambda2), $MachinePrecision] / lambda1), $MachinePrecision] - R), $MachinePrecision]), $MachinePrecision], N[(phi2 * N[(R + N[(phi1 * N[(R / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -6 \cdot 10^{+152}:\\
\;\;\;\;\phi_1 \cdot \left(R \cdot \frac{\phi_2}{\phi_1} - R\right)\\

\mathbf{elif}\;\phi_1 \leq -1.55 \cdot 10^{-49}:\\
\;\;\;\;\phi_2 \cdot \left(R - \frac{R \cdot \phi_1}{\phi_2}\right)\\

\mathbf{elif}\;\phi_1 \leq 2.2 \cdot 10^{-266}:\\
\;\;\;\;\lambda_1 \cdot \left(\frac{R \cdot \lambda_2}{\lambda_1} - R\right)\\

\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 phi1 < -5.99999999999999981e152

    1. Initial program 41.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-define91.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. Simplified91.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 phi2 around inf 73.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. associate-*r/73.7%

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

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

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

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

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

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

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

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

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

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

    if -5.99999999999999981e152 < phi1 < -1.55e-49

    1. Initial program 67.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.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. Simplified98.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 phi2 around inf 60.6%

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

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

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

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

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

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

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

        \[\leadsto \phi_2 \cdot \mathsf{fma}\left(1, R, \color{blue}{-\frac{\phi_1 \cdot R}{\phi_2}}\right) \]
      4. add-sqr-sqrt38.2%

        \[\leadsto \phi_2 \cdot \mathsf{fma}\left(1, R, -\frac{\phi_1 \cdot R}{\color{blue}{\sqrt{\phi_2} \cdot \sqrt{\phi_2}}}\right) \]
      5. times-frac38.1%

        \[\leadsto \phi_2 \cdot \mathsf{fma}\left(1, R, -\color{blue}{\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{R}{\sqrt{\phi_2}}}\right) \]
      6. add-sqr-sqrt24.9%

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

        \[\leadsto \phi_2 \cdot \mathsf{fma}\left(1, R, -\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{\color{blue}{\sqrt{R \cdot R}}}{\sqrt{\phi_2}}\right) \]
      8. sqr-neg25.1%

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

        \[\leadsto \phi_2 \cdot \mathsf{fma}\left(1, R, -\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{\color{blue}{\sqrt{-R} \cdot \sqrt{-R}}}{\sqrt{\phi_2}}\right) \]
      10. add-sqr-sqrt20.3%

        \[\leadsto \phi_2 \cdot \mathsf{fma}\left(1, R, -\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{\color{blue}{-R}}{\sqrt{\phi_2}}\right) \]
      11. times-frac15.9%

        \[\leadsto \phi_2 \cdot \mathsf{fma}\left(1, R, -\color{blue}{\frac{\phi_1 \cdot \left(-R\right)}{\sqrt{\phi_2} \cdot \sqrt{\phi_2}}}\right) \]
      12. distribute-rgt-neg-in15.9%

        \[\leadsto \phi_2 \cdot \mathsf{fma}\left(1, R, -\frac{\color{blue}{-\phi_1 \cdot R}}{\sqrt{\phi_2} \cdot \sqrt{\phi_2}}\right) \]
      13. add-sqr-sqrt16.4%

        \[\leadsto \phi_2 \cdot \mathsf{fma}\left(1, R, -\frac{-\phi_1 \cdot R}{\color{blue}{\phi_2}}\right) \]
      14. fmm-def16.4%

        \[\leadsto \phi_2 \cdot \color{blue}{\left(1 \cdot R - \frac{-\phi_1 \cdot R}{\phi_2}\right)} \]
      15. *-un-lft-identity16.4%

        \[\leadsto \phi_2 \cdot \left(\color{blue}{R} - \frac{-\phi_1 \cdot R}{\phi_2}\right) \]
      16. distribute-rgt-neg-in16.4%

        \[\leadsto \phi_2 \cdot \left(R - \frac{\color{blue}{\phi_1 \cdot \left(-R\right)}}{\phi_2}\right) \]
      17. add-sqr-sqrt15.9%

        \[\leadsto \phi_2 \cdot \left(R - \frac{\phi_1 \cdot \left(-R\right)}{\color{blue}{\sqrt{\phi_2} \cdot \sqrt{\phi_2}}}\right) \]
      18. times-frac20.3%

        \[\leadsto \phi_2 \cdot \left(R - \color{blue}{\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{-R}{\sqrt{\phi_2}}}\right) \]
    9. Applied egg-rr60.6%

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

    if -1.55e-49 < phi1 < 2.2e-266

    1. Initial program 63.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-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 31.2%

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

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

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

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

        \[\leadsto \lambda_1 \cdot \left(-\left(R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) + \color{blue}{\left(-\frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1}\right)}\right)\right) \]
      5. unsub-neg31.2%

        \[\leadsto \lambda_1 \cdot \left(-\color{blue}{\left(R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) - \frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1}\right)}\right) \]
      6. *-commutative31.2%

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

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

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

      \[\leadsto \color{blue}{\lambda_1 \cdot \left(\frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)}{\lambda_1} - R \cdot \cos \left(0.5 \cdot \phi_2\right)\right)} \]
    9. Taylor expanded in phi2 around 0 34.6%

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

    if 2.2e-266 < phi1

    1. Initial program 62.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-define95.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. Simplified95.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 13.3%

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

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

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

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

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

        \[\leadsto \color{blue}{\phi_2 \cdot R + \phi_2 \cdot \frac{-\phi_1 \cdot R}{\phi_2}} \]
      2. distribute-rgt-neg-in13.3%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \frac{\color{blue}{\phi_1 \cdot \left(-R\right)}}{\phi_2} \]
      3. add-sqr-sqrt12.8%

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

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \color{blue}{\left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{-R}{\sqrt{\phi_2}}\right)} \]
      5. add-sqr-sqrt9.1%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{\color{blue}{\sqrt{-R} \cdot \sqrt{-R}}}{\sqrt{\phi_2}}\right) \]
      6. sqrt-unprod20.5%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{\color{blue}{\sqrt{\left(-R\right) \cdot \left(-R\right)}}}{\sqrt{\phi_2}}\right) \]
      7. sqr-neg20.5%

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

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{\color{blue}{\sqrt{R} \cdot \sqrt{R}}}{\sqrt{\phi_2}}\right) \]
      9. add-sqr-sqrt29.2%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{\color{blue}{R}}{\sqrt{\phi_2}}\right) \]
      10. times-frac31.6%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \color{blue}{\frac{\phi_1 \cdot R}{\sqrt{\phi_2} \cdot \sqrt{\phi_2}}} \]
      11. add-sqr-sqrt43.4%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \frac{\phi_1 \cdot R}{\color{blue}{\phi_2}} \]
    9. Applied egg-rr43.4%

      \[\leadsto \color{blue}{\phi_2 \cdot R + \phi_2 \cdot \frac{\phi_1 \cdot R}{\phi_2}} \]
    10. Step-by-step derivation
      1. distribute-lft-in45.9%

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

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\phi_1 \cdot \frac{R}{\phi_2}}\right) \]
    11. Simplified42.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 simplification49.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -6 \cdot 10^{+152}:\\ \;\;\;\;\phi_1 \cdot \left(R \cdot \frac{\phi_2}{\phi_1} - R\right)\\ \mathbf{elif}\;\phi_1 \leq -1.55 \cdot 10^{-49}:\\ \;\;\;\;\phi_2 \cdot \left(R - \frac{R \cdot \phi_1}{\phi_2}\right)\\ \mathbf{elif}\;\phi_1 \leq 2.2 \cdot 10^{-266}:\\ \;\;\;\;\lambda_1 \cdot \left(\frac{R \cdot \lambda_2}{\lambda_1} - R\right)\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot \left(R + \phi_1 \cdot \frac{R}{\phi_2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 45.4% accurate, 13.7× speedup?

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

\\
\begin{array}{l}
t_0 := \phi_1 \cdot \frac{R}{\phi_2}\\
\mathbf{if}\;\phi_1 \leq -4.1 \cdot 10^{+151}:\\
\;\;\;\;\phi_1 \cdot \left(R \cdot \frac{\phi_2}{\phi_1} - R\right)\\

\mathbf{elif}\;\phi_1 \leq -9.5 \cdot 10^{-14}:\\
\;\;\;\;\phi_2 \cdot \left(R - t\_0\right)\\

\mathbf{elif}\;\phi_1 \leq 2.2 \cdot 10^{-268}:\\
\;\;\;\;\lambda_1 \cdot \left(\frac{R \cdot \lambda_2}{\lambda_1} - R\right)\\

\mathbf{else}:\\
\;\;\;\;\phi_2 \cdot \left(R + t\_0\right)\\


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

    1. Initial program 41.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-define91.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. Simplified91.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 phi2 around inf 73.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. associate-*r/73.7%

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

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

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

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

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

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

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

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

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

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

    if -4.0999999999999998e151 < phi1 < -9.4999999999999999e-14

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.4999999999999999e-14 < phi1 < 2.20000000000000004e-268

    1. Initial program 61.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 31.2%

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

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

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

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

        \[\leadsto \lambda_1 \cdot \left(-\left(R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) + \color{blue}{\left(-\frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1}\right)}\right)\right) \]
      5. unsub-neg31.2%

        \[\leadsto \lambda_1 \cdot \left(-\color{blue}{\left(R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) - \frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1}\right)}\right) \]
      6. *-commutative31.2%

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

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

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

      \[\leadsto \color{blue}{\lambda_1 \cdot \left(\frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)}{\lambda_1} - R \cdot \cos \left(0.5 \cdot \phi_2\right)\right)} \]
    9. Taylor expanded in phi2 around 0 34.2%

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

    if 2.20000000000000004e-268 < phi1

    1. Initial program 63.1%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define95.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. Simplified95.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 13.2%

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

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

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

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

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

        \[\leadsto \color{blue}{\phi_2 \cdot R + \phi_2 \cdot \frac{-\phi_1 \cdot R}{\phi_2}} \]
      2. distribute-rgt-neg-in13.2%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \frac{\color{blue}{\phi_1 \cdot \left(-R\right)}}{\phi_2} \]
      3. add-sqr-sqrt12.7%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \frac{\phi_1 \cdot \left(-R\right)}{\color{blue}{\sqrt{\phi_2} \cdot \sqrt{\phi_2}}} \]
      4. times-frac12.7%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \color{blue}{\left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{-R}{\sqrt{\phi_2}}\right)} \]
      5. add-sqr-sqrt9.0%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{\color{blue}{\sqrt{-R} \cdot \sqrt{-R}}}{\sqrt{\phi_2}}\right) \]
      6. sqrt-unprod21.2%

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

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{\sqrt{\color{blue}{R \cdot R}}}{\sqrt{\phi_2}}\right) \]
      8. sqrt-unprod13.9%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{\color{blue}{\sqrt{R} \cdot \sqrt{R}}}{\sqrt{\phi_2}}\right) \]
      9. add-sqr-sqrt29.8%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{\color{blue}{R}}{\sqrt{\phi_2}}\right) \]
      10. times-frac31.4%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \color{blue}{\frac{\phi_1 \cdot R}{\sqrt{\phi_2} \cdot \sqrt{\phi_2}}} \]
      11. add-sqr-sqrt43.1%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \frac{\phi_1 \cdot R}{\color{blue}{\phi_2}} \]
    9. Applied egg-rr43.1%

      \[\leadsto \color{blue}{\phi_2 \cdot R + \phi_2 \cdot \frac{\phi_1 \cdot R}{\phi_2}} \]
    10. Step-by-step derivation
      1. distribute-lft-in45.6%

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

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

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

Alternative 10: 45.3% accurate, 13.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.25 \cdot 10^{+152}:\\ \;\;\;\;\phi_1 \cdot \left(R \cdot \frac{\phi_2}{\phi_1} - R\right)\\ \mathbf{elif}\;\phi_1 \leq -6.4 \cdot 10^{-52}:\\ \;\;\;\;\phi_2 \cdot \left(R - R \cdot \frac{\phi_1}{\phi_2}\right)\\ \mathbf{elif}\;\phi_1 \leq 4.5 \cdot 10^{-265}:\\ \;\;\;\;\lambda_1 \cdot \left(\frac{R \cdot \lambda_2}{\lambda_1} - R\right)\\ \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
 (if (<= phi1 -1.25e+152)
   (* phi1 (- (* R (/ phi2 phi1)) R))
   (if (<= phi1 -6.4e-52)
     (* phi2 (- R (* R (/ phi1 phi2))))
     (if (<= phi1 4.5e-265)
       (* lambda1 (- (/ (* R lambda2) lambda1) R))
       (* phi2 (+ R (* phi1 (/ R phi2))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -1.25e+152) {
		tmp = phi1 * ((R * (phi2 / phi1)) - R);
	} else if (phi1 <= -6.4e-52) {
		tmp = phi2 * (R - (R * (phi1 / phi2)));
	} else if (phi1 <= 4.5e-265) {
		tmp = lambda1 * (((R * lambda2) / lambda1) - R);
	} 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) :: tmp
    if (phi1 <= (-1.25d+152)) then
        tmp = phi1 * ((r * (phi2 / phi1)) - r)
    else if (phi1 <= (-6.4d-52)) then
        tmp = phi2 * (r - (r * (phi1 / phi2)))
    else if (phi1 <= 4.5d-265) then
        tmp = lambda1 * (((r * lambda2) / lambda1) - r)
    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 tmp;
	if (phi1 <= -1.25e+152) {
		tmp = phi1 * ((R * (phi2 / phi1)) - R);
	} else if (phi1 <= -6.4e-52) {
		tmp = phi2 * (R - (R * (phi1 / phi2)));
	} else if (phi1 <= 4.5e-265) {
		tmp = lambda1 * (((R * lambda2) / lambda1) - R);
	} else {
		tmp = phi2 * (R + (phi1 * (R / phi2)));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -1.25e+152:
		tmp = phi1 * ((R * (phi2 / phi1)) - R)
	elif phi1 <= -6.4e-52:
		tmp = phi2 * (R - (R * (phi1 / phi2)))
	elif phi1 <= 4.5e-265:
		tmp = lambda1 * (((R * lambda2) / lambda1) - R)
	else:
		tmp = phi2 * (R + (phi1 * (R / phi2)))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -1.25e+152)
		tmp = Float64(phi1 * Float64(Float64(R * Float64(phi2 / phi1)) - R));
	elseif (phi1 <= -6.4e-52)
		tmp = Float64(phi2 * Float64(R - Float64(R * Float64(phi1 / phi2))));
	elseif (phi1 <= 4.5e-265)
		tmp = Float64(lambda1 * Float64(Float64(Float64(R * lambda2) / lambda1) - R));
	else
		tmp = Float64(phi2 * Float64(R + Float64(phi1 * Float64(R / phi2))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi1 <= -1.25e+152)
		tmp = phi1 * ((R * (phi2 / phi1)) - R);
	elseif (phi1 <= -6.4e-52)
		tmp = phi2 * (R - (R * (phi1 / phi2)));
	elseif (phi1 <= 4.5e-265)
		tmp = lambda1 * (((R * lambda2) / lambda1) - R);
	else
		tmp = phi2 * (R + (phi1 * (R / phi2)));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -1.25e+152], N[(phi1 * N[(N[(R * N[(phi2 / phi1), $MachinePrecision]), $MachinePrecision] - R), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, -6.4e-52], N[(phi2 * N[(R - N[(R * N[(phi1 / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 4.5e-265], N[(lambda1 * N[(N[(N[(R * lambda2), $MachinePrecision] / lambda1), $MachinePrecision] - R), $MachinePrecision]), $MachinePrecision], N[(phi2 * N[(R + N[(phi1 * N[(R / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -1.25 \cdot 10^{+152}:\\
\;\;\;\;\phi_1 \cdot \left(R \cdot \frac{\phi_2}{\phi_1} - R\right)\\

\mathbf{elif}\;\phi_1 \leq -6.4 \cdot 10^{-52}:\\
\;\;\;\;\phi_2 \cdot \left(R - R \cdot \frac{\phi_1}{\phi_2}\right)\\

\mathbf{elif}\;\phi_1 \leq 4.5 \cdot 10^{-265}:\\
\;\;\;\;\lambda_1 \cdot \left(\frac{R \cdot \lambda_2}{\lambda_1} - R\right)\\

\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 phi1 < -1.25e152

    1. Initial program 41.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-define91.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. Simplified91.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 phi2 around inf 73.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. associate-*r/73.7%

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

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

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

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

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

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

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

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

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

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

    if -1.25e152 < phi1 < -6.4000000000000002e-52

    1. Initial program 67.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-define98.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. Simplified98.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 phi2 around inf 59.3%

      \[\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-neg59.3%

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

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

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

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

    if -6.4000000000000002e-52 < phi1 < 4.5000000000000003e-265

    1. Initial program 63.1%

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

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

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

        \[\leadsto \color{blue}{\lambda_1 \cdot \left(-\left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1} + R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} \]
      3. +-commutative31.8%

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

        \[\leadsto \lambda_1 \cdot \left(-\left(R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) + \color{blue}{\left(-\frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1}\right)}\right)\right) \]
      5. unsub-neg31.8%

        \[\leadsto \lambda_1 \cdot \left(-\color{blue}{\left(R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) - \frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1}\right)}\right) \]
      6. *-commutative31.8%

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

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

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

      \[\leadsto \color{blue}{\lambda_1 \cdot \left(\frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)}{\lambda_1} - R \cdot \cos \left(0.5 \cdot \phi_2\right)\right)} \]
    9. Taylor expanded in phi2 around 0 33.5%

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

    if 4.5000000000000003e-265 < phi1

    1. Initial program 62.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-define95.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. Simplified95.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 13.3%

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

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

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

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

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

        \[\leadsto \color{blue}{\phi_2 \cdot R + \phi_2 \cdot \frac{-\phi_1 \cdot R}{\phi_2}} \]
      2. distribute-rgt-neg-in13.3%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \frac{\color{blue}{\phi_1 \cdot \left(-R\right)}}{\phi_2} \]
      3. add-sqr-sqrt12.8%

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

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \color{blue}{\left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{-R}{\sqrt{\phi_2}}\right)} \]
      5. add-sqr-sqrt9.1%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{\color{blue}{\sqrt{-R} \cdot \sqrt{-R}}}{\sqrt{\phi_2}}\right) \]
      6. sqrt-unprod20.5%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{\color{blue}{\sqrt{\left(-R\right) \cdot \left(-R\right)}}}{\sqrt{\phi_2}}\right) \]
      7. sqr-neg20.5%

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

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{\color{blue}{\sqrt{R} \cdot \sqrt{R}}}{\sqrt{\phi_2}}\right) \]
      9. add-sqr-sqrt29.2%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{\color{blue}{R}}{\sqrt{\phi_2}}\right) \]
      10. times-frac31.6%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \color{blue}{\frac{\phi_1 \cdot R}{\sqrt{\phi_2} \cdot \sqrt{\phi_2}}} \]
      11. add-sqr-sqrt43.4%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \frac{\phi_1 \cdot R}{\color{blue}{\phi_2}} \]
    9. Applied egg-rr43.4%

      \[\leadsto \color{blue}{\phi_2 \cdot R + \phi_2 \cdot \frac{\phi_1 \cdot R}{\phi_2}} \]
    10. Step-by-step derivation
      1. distribute-lft-in45.9%

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

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\phi_1 \cdot \frac{R}{\phi_2}}\right) \]
    11. Simplified42.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. Add Preprocessing

Alternative 11: 45.6% accurate, 17.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -5.1 \cdot 10^{-12}:\\ \;\;\;\;\phi_1 \cdot \left(R \cdot \frac{\phi_2}{\phi_1} - R\right)\\ \mathbf{elif}\;\phi_1 \leq 1.3 \cdot 10^{-266}:\\ \;\;\;\;\lambda_1 \cdot \left(\frac{R \cdot \lambda_2}{\lambda_1} - R\right)\\ \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
 (if (<= phi1 -5.1e-12)
   (* phi1 (- (* R (/ phi2 phi1)) R))
   (if (<= phi1 1.3e-266)
     (* lambda1 (- (/ (* R lambda2) lambda1) R))
     (* phi2 (+ R (* phi1 (/ R phi2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -5.1e-12) {
		tmp = phi1 * ((R * (phi2 / phi1)) - R);
	} else if (phi1 <= 1.3e-266) {
		tmp = lambda1 * (((R * lambda2) / lambda1) - R);
	} 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) :: tmp
    if (phi1 <= (-5.1d-12)) then
        tmp = phi1 * ((r * (phi2 / phi1)) - r)
    else if (phi1 <= 1.3d-266) then
        tmp = lambda1 * (((r * lambda2) / lambda1) - r)
    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 tmp;
	if (phi1 <= -5.1e-12) {
		tmp = phi1 * ((R * (phi2 / phi1)) - R);
	} else if (phi1 <= 1.3e-266) {
		tmp = lambda1 * (((R * lambda2) / lambda1) - R);
	} else {
		tmp = phi2 * (R + (phi1 * (R / phi2)));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -5.1e-12:
		tmp = phi1 * ((R * (phi2 / phi1)) - R)
	elif phi1 <= 1.3e-266:
		tmp = lambda1 * (((R * lambda2) / lambda1) - R)
	else:
		tmp = phi2 * (R + (phi1 * (R / phi2)))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -5.1e-12)
		tmp = Float64(phi1 * Float64(Float64(R * Float64(phi2 / phi1)) - R));
	elseif (phi1 <= 1.3e-266)
		tmp = Float64(lambda1 * Float64(Float64(Float64(R * lambda2) / lambda1) - R));
	else
		tmp = Float64(phi2 * Float64(R + Float64(phi1 * Float64(R / phi2))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi1 <= -5.1e-12)
		tmp = phi1 * ((R * (phi2 / phi1)) - R);
	elseif (phi1 <= 1.3e-266)
		tmp = lambda1 * (((R * lambda2) / lambda1) - R);
	else
		tmp = phi2 * (R + (phi1 * (R / phi2)));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -5.1e-12], N[(phi1 * N[(N[(R * N[(phi2 / phi1), $MachinePrecision]), $MachinePrecision] - R), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 1.3e-266], N[(lambda1 * N[(N[(N[(R * lambda2), $MachinePrecision] / lambda1), $MachinePrecision] - R), $MachinePrecision]), $MachinePrecision], N[(phi2 * N[(R + N[(phi1 * N[(R / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -5.1 \cdot 10^{-12}:\\
\;\;\;\;\phi_1 \cdot \left(R \cdot \frac{\phi_2}{\phi_1} - R\right)\\

\mathbf{elif}\;\phi_1 \leq 1.3 \cdot 10^{-266}:\\
\;\;\;\;\lambda_1 \cdot \left(\frac{R \cdot \lambda_2}{\lambda_1} - R\right)\\

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


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

    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-define94.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. Simplified94.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 phi2 around inf 69.2%

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

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

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

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

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

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

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

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

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

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

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

    if -5.09999999999999968e-12 < phi1 < 1.3e-266

    1. Initial program 62.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.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 32.2%

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

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

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

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

        \[\leadsto \lambda_1 \cdot \left(-\left(R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) + \color{blue}{\left(-\frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1}\right)}\right)\right) \]
      5. unsub-neg32.2%

        \[\leadsto \lambda_1 \cdot \left(-\color{blue}{\left(R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) - \frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1}\right)}\right) \]
      6. *-commutative32.2%

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

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

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

      \[\leadsto \color{blue}{\lambda_1 \cdot \left(\frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)}{\lambda_1} - R \cdot \cos \left(0.5 \cdot \phi_2\right)\right)} \]
    9. Taylor expanded in phi2 around 0 35.2%

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

    if 1.3e-266 < phi1

    1. Initial program 62.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-define95.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. Simplified95.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 13.3%

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

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

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

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

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

        \[\leadsto \color{blue}{\phi_2 \cdot R + \phi_2 \cdot \frac{-\phi_1 \cdot R}{\phi_2}} \]
      2. distribute-rgt-neg-in13.3%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \frac{\color{blue}{\phi_1 \cdot \left(-R\right)}}{\phi_2} \]
      3. add-sqr-sqrt12.8%

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

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \color{blue}{\left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{-R}{\sqrt{\phi_2}}\right)} \]
      5. add-sqr-sqrt9.1%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{\color{blue}{\sqrt{-R} \cdot \sqrt{-R}}}{\sqrt{\phi_2}}\right) \]
      6. sqrt-unprod20.5%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{\color{blue}{\sqrt{\left(-R\right) \cdot \left(-R\right)}}}{\sqrt{\phi_2}}\right) \]
      7. sqr-neg20.5%

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

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{\color{blue}{\sqrt{R} \cdot \sqrt{R}}}{\sqrt{\phi_2}}\right) \]
      9. add-sqr-sqrt29.2%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \left(\frac{\phi_1}{\sqrt{\phi_2}} \cdot \frac{\color{blue}{R}}{\sqrt{\phi_2}}\right) \]
      10. times-frac31.6%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \color{blue}{\frac{\phi_1 \cdot R}{\sqrt{\phi_2} \cdot \sqrt{\phi_2}}} \]
      11. add-sqr-sqrt43.4%

        \[\leadsto \phi_2 \cdot R + \phi_2 \cdot \frac{\phi_1 \cdot R}{\color{blue}{\phi_2}} \]
    9. Applied egg-rr43.4%

      \[\leadsto \color{blue}{\phi_2 \cdot R + \phi_2 \cdot \frac{\phi_1 \cdot R}{\phi_2}} \]
    10. Step-by-step derivation
      1. distribute-lft-in45.9%

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

        \[\leadsto \phi_2 \cdot \left(R + \color{blue}{\phi_1 \cdot \frac{R}{\phi_2}}\right) \]
    11. Simplified42.6%

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

Alternative 12: 33.4% accurate, 17.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq -1.45 \cdot 10^{-116}:\\ \;\;\;\;\phi_1 \cdot \left(R \cdot \frac{\phi_2}{\phi_1} - R\right)\\ \mathbf{elif}\;\phi_2 \leq 1.35 \cdot 10^{-31}:\\ \;\;\;\;\lambda_1 \cdot \left(\frac{R \cdot \lambda_2}{\lambda_1} - R\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 -1.45e-116)
   (* phi1 (- (* R (/ phi2 phi1)) R))
   (if (<= phi2 1.35e-31)
     (* lambda1 (- (/ (* R lambda2) lambda1) R))
     (* R (* phi2 (- 1.0 (/ phi1 phi2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= -1.45e-116) {
		tmp = phi1 * ((R * (phi2 / phi1)) - R);
	} else if (phi2 <= 1.35e-31) {
		tmp = lambda1 * (((R * lambda2) / lambda1) - R);
	} else {
		tmp = R * (phi2 * (1.0 - (phi1 / 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 (phi2 <= (-1.45d-116)) then
        tmp = phi1 * ((r * (phi2 / phi1)) - r)
    else if (phi2 <= 1.35d-31) then
        tmp = lambda1 * (((r * lambda2) / lambda1) - r)
    else
        tmp = r * (phi2 * (1.0d0 - (phi1 / phi2)))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= -1.45e-116) {
		tmp = phi1 * ((R * (phi2 / phi1)) - R);
	} else if (phi2 <= 1.35e-31) {
		tmp = lambda1 * (((R * lambda2) / lambda1) - R);
	} else {
		tmp = R * (phi2 * (1.0 - (phi1 / phi2)));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= -1.45e-116:
		tmp = phi1 * ((R * (phi2 / phi1)) - R)
	elif phi2 <= 1.35e-31:
		tmp = lambda1 * (((R * lambda2) / lambda1) - R)
	else:
		tmp = R * (phi2 * (1.0 - (phi1 / phi2)))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= -1.45e-116)
		tmp = Float64(phi1 * Float64(Float64(R * Float64(phi2 / phi1)) - R));
	elseif (phi2 <= 1.35e-31)
		tmp = Float64(lambda1 * Float64(Float64(Float64(R * lambda2) / lambda1) - R));
	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 <= -1.45e-116)
		tmp = phi1 * ((R * (phi2 / phi1)) - R);
	elseif (phi2 <= 1.35e-31)
		tmp = lambda1 * (((R * lambda2) / lambda1) - R);
	else
		tmp = R * (phi2 * (1.0 - (phi1 / phi2)));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, -1.45e-116], N[(phi1 * N[(N[(R * N[(phi2 / phi1), $MachinePrecision]), $MachinePrecision] - R), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 1.35e-31], N[(lambda1 * N[(N[(N[(R * lambda2), $MachinePrecision] / lambda1), $MachinePrecision] - R), $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 -1.45 \cdot 10^{-116}:\\
\;\;\;\;\phi_1 \cdot \left(R \cdot \frac{\phi_2}{\phi_1} - R\right)\\

\mathbf{elif}\;\phi_2 \leq 1.35 \cdot 10^{-31}:\\
\;\;\;\;\lambda_1 \cdot \left(\frac{R \cdot \lambda_2}{\lambda_1} - R\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 3 regimes
  2. if phi2 < -1.4499999999999999e-116

    1. Initial program 66.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-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 17.3%

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

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

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

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

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

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

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

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

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

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

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

    if -1.4499999999999999e-116 < phi2 < 1.35000000000000007e-31

    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.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 36.4%

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

        \[\leadsto \color{blue}{-\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1} + R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \]
      2. distribute-rgt-neg-in36.4%

        \[\leadsto \color{blue}{\lambda_1 \cdot \left(-\left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1} + R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} \]
      3. +-commutative36.4%

        \[\leadsto \lambda_1 \cdot \left(-\color{blue}{\left(R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) + -1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1}\right)}\right) \]
      4. mul-1-neg36.4%

        \[\leadsto \lambda_1 \cdot \left(-\left(R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) + \color{blue}{\left(-\frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1}\right)}\right)\right) \]
      5. unsub-neg36.4%

        \[\leadsto \lambda_1 \cdot \left(-\color{blue}{\left(R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) - \frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1}\right)}\right) \]
      6. *-commutative36.4%

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

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

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

      \[\leadsto \color{blue}{\lambda_1 \cdot \left(\frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)}{\lambda_1} - R \cdot \cos \left(0.5 \cdot \phi_2\right)\right)} \]
    9. Taylor expanded in phi2 around 0 34.8%

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

    if 1.35000000000000007e-31 < phi2

    1. Initial program 48.8%

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

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

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

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

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

Alternative 13: 34.4% accurate, 17.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq -8.5 \cdot 10^{-115}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_2 \leq 7.5 \cdot 10^{-32}:\\ \;\;\;\;\lambda_1 \cdot \left(\frac{R \cdot \lambda_2}{\lambda_1} - R\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 -8.5e-115)
   (* R (- phi1))
   (if (<= phi2 7.5e-32)
     (* lambda1 (- (/ (* R lambda2) lambda1) R))
     (* R (* phi2 (- 1.0 (/ phi1 phi2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= -8.5e-115) {
		tmp = R * -phi1;
	} else if (phi2 <= 7.5e-32) {
		tmp = lambda1 * (((R * lambda2) / lambda1) - R);
	} else {
		tmp = R * (phi2 * (1.0 - (phi1 / 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 (phi2 <= (-8.5d-115)) then
        tmp = r * -phi1
    else if (phi2 <= 7.5d-32) then
        tmp = lambda1 * (((r * lambda2) / lambda1) - r)
    else
        tmp = r * (phi2 * (1.0d0 - (phi1 / phi2)))
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= -8.5e-115) {
		tmp = R * -phi1;
	} else if (phi2 <= 7.5e-32) {
		tmp = lambda1 * (((R * lambda2) / lambda1) - R);
	} else {
		tmp = R * (phi2 * (1.0 - (phi1 / phi2)));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= -8.5e-115:
		tmp = R * -phi1
	elif phi2 <= 7.5e-32:
		tmp = lambda1 * (((R * lambda2) / lambda1) - R)
	else:
		tmp = R * (phi2 * (1.0 - (phi1 / phi2)))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= -8.5e-115)
		tmp = Float64(R * Float64(-phi1));
	elseif (phi2 <= 7.5e-32)
		tmp = Float64(lambda1 * Float64(Float64(Float64(R * lambda2) / lambda1) - R));
	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 <= -8.5e-115)
		tmp = R * -phi1;
	elseif (phi2 <= 7.5e-32)
		tmp = lambda1 * (((R * lambda2) / lambda1) - R);
	else
		tmp = R * (phi2 * (1.0 - (phi1 / phi2)));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, -8.5e-115], N[(R * (-phi1)), $MachinePrecision], If[LessEqual[phi2, 7.5e-32], N[(lambda1 * N[(N[(N[(R * lambda2), $MachinePrecision] / lambda1), $MachinePrecision] - R), $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 -8.5 \cdot 10^{-115}:\\
\;\;\;\;R \cdot \left(-\phi_1\right)\\

\mathbf{elif}\;\phi_2 \leq 7.5 \cdot 10^{-32}:\\
\;\;\;\;\lambda_1 \cdot \left(\frac{R \cdot \lambda_2}{\lambda_1} - R\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 3 regimes
  2. if phi2 < -8.49999999999999953e-115

    1. Initial program 66.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-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 phi1 around -inf 18.3%

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

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

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

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

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

    if -8.49999999999999953e-115 < phi2 < 7.49999999999999953e-32

    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.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 36.4%

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

        \[\leadsto \color{blue}{-\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1} + R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \]
      2. distribute-rgt-neg-in36.4%

        \[\leadsto \color{blue}{\lambda_1 \cdot \left(-\left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1} + R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)} \]
      3. +-commutative36.4%

        \[\leadsto \lambda_1 \cdot \left(-\color{blue}{\left(R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) + -1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1}\right)}\right) \]
      4. mul-1-neg36.4%

        \[\leadsto \lambda_1 \cdot \left(-\left(R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) + \color{blue}{\left(-\frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1}\right)}\right)\right) \]
      5. unsub-neg36.4%

        \[\leadsto \lambda_1 \cdot \left(-\color{blue}{\left(R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) - \frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\lambda_1}\right)}\right) \]
      6. *-commutative36.4%

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

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

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

      \[\leadsto \color{blue}{\lambda_1 \cdot \left(\frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)}{\lambda_1} - R \cdot \cos \left(0.5 \cdot \phi_2\right)\right)} \]
    9. Taylor expanded in phi2 around 0 34.8%

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

    if 7.49999999999999953e-32 < phi2

    1. Initial program 48.8%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -8.5 \cdot 10^{-115}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_2 \leq 7.5 \cdot 10^{-32}:\\ \;\;\;\;\lambda_1 \cdot \left(\frac{R \cdot \lambda_2}{\lambda_1} - R\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 \cdot \left(1 - \frac{\phi_1}{\phi_2}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 34.4% accurate, 27.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 3 \cdot 10^{+120}:\\ \;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \lambda_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= lambda2 3e+120) (- (* R phi2) (* R phi1)) (* R lambda2)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda2 <= 3e+120) {
		tmp = (R * phi2) - (R * phi1);
	} else {
		tmp = R * lambda2;
	}
	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 (lambda2 <= 3d+120) then
        tmp = (r * phi2) - (r * phi1)
    else
        tmp = r * lambda2
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda2 <= 3e+120) {
		tmp = (R * phi2) - (R * phi1);
	} else {
		tmp = R * lambda2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if lambda2 <= 3e+120:
		tmp = (R * phi2) - (R * phi1)
	else:
		tmp = R * lambda2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (lambda2 <= 3e+120)
		tmp = Float64(Float64(R * phi2) - Float64(R * phi1));
	else
		tmp = Float64(R * lambda2);
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (lambda2 <= 3e+120)
		tmp = (R * phi2) - (R * phi1);
	else
		tmp = R * lambda2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda2, 3e+120], N[(N[(R * phi2), $MachinePrecision] - N[(R * phi1), $MachinePrecision]), $MachinePrecision], N[(R * lambda2), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq 3 \cdot 10^{+120}:\\
\;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda2 < 3e120

    1. Initial program 61.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.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. Simplified97.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 inf 33.4%

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

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

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

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

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

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

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

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

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

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

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

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

    if 3e120 < lambda2

    1. Initial program 58.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-define94.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. Simplified94.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 lambda2 around -inf 40.3%

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

        \[\leadsto \color{blue}{-R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)} \]
      2. *-commutative40.3%

        \[\leadsto -\color{blue}{\left(\lambda_2 \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right) \cdot R} \]
      3. distribute-rgt-neg-in40.3%

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

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

      \[\leadsto \color{blue}{\left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \cdot \left(-R\right) \]
    9. Step-by-step derivation
      1. *-commutative25.8%

        \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_2\right)} \cdot \left(-R\right) \]
    10. Simplified25.8%

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \lambda_2\right)} \]
    12. Step-by-step derivation
      1. associate-*r*0.5%

        \[\leadsto \color{blue}{\left(-1 \cdot R\right) \cdot \lambda_2} \]
      2. neg-mul-10.5%

        \[\leadsto \color{blue}{\left(-R\right)} \cdot \lambda_2 \]
    13. Simplified0.5%

      \[\leadsto \color{blue}{\left(-R\right) \cdot \lambda_2} \]
    14. Step-by-step derivation
      1. add-sqr-sqrt0.3%

        \[\leadsto \color{blue}{\left(\sqrt{-R} \cdot \sqrt{-R}\right)} \cdot \lambda_2 \]
      2. sqrt-unprod34.4%

        \[\leadsto \color{blue}{\sqrt{\left(-R\right) \cdot \left(-R\right)}} \cdot \lambda_2 \]
      3. sqr-neg34.4%

        \[\leadsto \sqrt{\color{blue}{R \cdot R}} \cdot \lambda_2 \]
      4. sqrt-unprod35.2%

        \[\leadsto \color{blue}{\left(\sqrt{R} \cdot \sqrt{R}\right)} \cdot \lambda_2 \]
      5. add-sqr-sqrt62.6%

        \[\leadsto \color{blue}{R} \cdot \lambda_2 \]
      6. *-un-lft-identity62.6%

        \[\leadsto \color{blue}{\left(1 \cdot R\right)} \cdot \lambda_2 \]
    15. Applied egg-rr62.6%

      \[\leadsto \color{blue}{\left(1 \cdot R\right)} \cdot \lambda_2 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification38.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 3 \cdot 10^{+120}:\\ \;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \lambda_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 28.7% accurate, 36.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -3.7 \cdot 10^{-46}:\\ \;\;\;\;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 -3.7e-46) (* R (- phi1)) (* R phi2)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -3.7e-46) {
		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 <= (-3.7d-46)) 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 <= -3.7e-46) {
		tmp = R * -phi1;
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -3.7e-46:
		tmp = R * -phi1
	else:
		tmp = R * phi2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -3.7e-46)
		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 <= -3.7e-46)
		tmp = R * -phi1;
	else
		tmp = R * phi2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -3.7e-46], N[(R * (-phi1)), $MachinePrecision], N[(R * phi2), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -3.7 \cdot 10^{-46}:\\
\;\;\;\;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 < -3.69999999999999983e-46

    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-define95.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. Simplified95.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 -inf 58.2%

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

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

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

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

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

    if -3.69999999999999983e-46 < phi1

    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-define97.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. Simplified97.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 phi2 around inf 18.6%

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

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

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

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

Alternative 16: 17.9% 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 61.0%

    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
  2. Step-by-step derivation
    1. hypot-define96.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. Simplified96.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 17.2%

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

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

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

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

Alternative 17: 13.3% 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 61.0%

    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
  2. Step-by-step derivation
    1. hypot-define96.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. Simplified96.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 phi1 around 0 90.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) \]
  6. Taylor expanded in lambda1 around inf 13.8%

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

    \[\leadsto \color{blue}{R \cdot \lambda_1} \]
  8. Step-by-step derivation
    1. *-commutative11.7%

      \[\leadsto \color{blue}{\lambda_1 \cdot R} \]
  9. Simplified11.7%

    \[\leadsto \color{blue}{\lambda_1 \cdot R} \]
  10. Final simplification11.7%

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

Reproduce

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