Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.1% → 99.9%
Time: 33.5s
Alternatives: 16
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 16 alternatives:

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

Initial Program: 60.1% 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.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(\cos \left(\phi_2 \cdot 0.5\right), \cos \left(0.5 \cdot \phi_1\right), \sin \left(0.5 \cdot \phi_1\right) \cdot \left(-\sin \left(\phi_2 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right) \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R
  (hypot
   (*
    (- lambda1 lambda2)
    (fma
     (cos (* phi2 0.5))
     (cos (* 0.5 phi1))
     (* (sin (* 0.5 phi1)) (- (sin (* phi2 0.5))))))
   (- phi1 phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * hypot(((lambda1 - lambda2) * fma(cos((phi2 * 0.5)), cos((0.5 * phi1)), (sin((0.5 * phi1)) * -sin((phi2 * 0.5))))), (phi1 - phi2));
}
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(R * hypot(Float64(Float64(lambda1 - lambda2) * fma(cos(Float64(phi2 * 0.5)), cos(Float64(0.5 * phi1)), Float64(sin(Float64(0.5 * phi1)) * Float64(-sin(Float64(phi2 * 0.5)))))), Float64(phi1 - phi2)))
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[Sqrt[N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] + N[(N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * (-N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision])), $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{fma}\left(\cos \left(\phi_2 \cdot 0.5\right), \cos \left(0.5 \cdot \phi_1\right), \sin \left(0.5 \cdot \phi_1\right) \cdot \left(-\sin \left(\phi_2 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 62.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-define96.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. Simplified96.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. Step-by-step derivation
    1. log1p-expm1-u96.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(\cos \left(\phi_2 \cdot 0.5\right), \cos \color{blue}{\left(0.5 \cdot \phi_1\right)}, -\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right), \phi_1 - \phi_2\right) \]
    4. distribute-rgt-neg-in99.9%

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

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

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

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

Alternative 2: 96.3% accurate, 0.6× speedup?

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

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

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


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

    1. Initial program 49.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-define87.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. Simplified87.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. Step-by-step derivation
      1. log1p-expm1-u87.7%

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

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

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

      \[\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. *-commutative87.7%

        \[\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. +-commutative87.7%

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}\right)\right), \phi_1 - \phi_2\right) \]
      6. *-commutative99.7%

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\lambda_1 \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) \]
    10. Step-by-step derivation
      1. *-commutative99.9%

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

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

    if -2.10000000000000006e236 < lambda1

    1. Initial program 63.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-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. Step-by-step derivation
      1. log1p-expm1-u97.2%

        \[\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-inv97.2%

        \[\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-eval97.2%

        \[\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-rr97.2%

      \[\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) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.5%

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

Alternative 3: 79.7% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 62.4%

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

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

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

      \[\leadsto \color{blue}{R \cdot \sqrt{{\cos \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
    6. Step-by-step derivation
      1. +-commutative54.9%

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      5. unswap-sqr54.9%

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

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

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

    if 1.4e-11 < phi2

    1. Initial program 60.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.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. Simplified95.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 53.1%

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

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_2 \cdot \phi_2 + \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      5. unswap-sqr53.1%

        \[\leadsto R \cdot \sqrt{\phi_2 \cdot \phi_2 + \color{blue}{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      6. hypot-define80.3%

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

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

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

Alternative 4: 74.7% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 4.9 \cdot 10^{-11}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\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 2 regimes
  2. if phi2 < 4.8999999999999999e-11

    1. Initial program 62.4%

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

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

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

      \[\leadsto \color{blue}{R \cdot \sqrt{{\cos \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
    6. Step-by-step derivation
      1. +-commutative54.9%

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      5. unswap-sqr54.9%

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

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

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

    if 4.8999999999999999e-11 < phi2

    1. Initial program 60.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.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. Simplified95.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 64.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. mul-1-neg64.6%

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

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

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

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

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

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

Alternative 5: 96.0% accurate, 1.5× speedup?

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

\\
R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_2 + \phi_1}{2}\right), \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 62.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-define96.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. Simplified96.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. Final simplification96.3%

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

Alternative 6: 56.0% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
t_0 := R \cdot \mathsf{hypot}\left(\lambda_1, \phi_1\right)\\
\mathbf{if}\;\phi_2 \leq 7.5 \cdot 10^{-94}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\phi_2 \leq 1.02 \cdot 10^{-65}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, -\lambda_2\right)\\

\mathbf{elif}\;\phi_2 \leq 1.3 \cdot 10^{-16}:\\
\;\;\;\;t\_0\\

\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 phi2 < 7.5000000000000003e-94 or 1.02000000000000004e-65 < phi2 < 1.2999999999999999e-16

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

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

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

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

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      5. unswap-sqr56.0%

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      6. hypot-define82.7%

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

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \]
    8. Step-by-step derivation
      1. add-cube-cbrt81.8%

        \[\leadsto \color{blue}{\left(\sqrt[3]{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot \sqrt[3]{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}\right) \cdot \sqrt[3]{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      2. pow381.8%

        \[\leadsto \color{blue}{{\left(\sqrt[3]{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}\right)}^{3}} \]
    9. Applied egg-rr81.8%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}\right)}^{3}} \]
    10. Step-by-step derivation
      1. pow1/338.6%

        \[\leadsto {\color{blue}{\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)\right)}^{0.3333333333333333}\right)}}^{3} \]
      2. *-commutative38.6%

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}\right)\right)}^{0.3333333333333333}\right)}^{3} \]
      3. sub-neg38.6%

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 + \left(-\lambda_2\right)\right)} \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}^{0.3333333333333333}\right)}^{3} \]
      4. add-sqr-sqrt18.3%

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \left(\lambda_1 + \color{blue}{\sqrt{-\lambda_2} \cdot \sqrt{-\lambda_2}}\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}^{0.3333333333333333}\right)}^{3} \]
      5. sqrt-unprod35.5%

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \left(\lambda_1 + \color{blue}{\sqrt{\left(-\lambda_2\right) \cdot \left(-\lambda_2\right)}}\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}^{0.3333333333333333}\right)}^{3} \]
      6. sqr-neg35.5%

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \left(\lambda_1 + \sqrt{\color{blue}{\lambda_2 \cdot \lambda_2}}\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}^{0.3333333333333333}\right)}^{3} \]
      7. sqrt-unprod20.3%

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \left(\lambda_1 + \color{blue}{\sqrt{\lambda_2} \cdot \sqrt{\lambda_2}}\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}^{0.3333333333333333}\right)}^{3} \]
      8. add-sqr-sqrt38.6%

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

      \[\leadsto {\color{blue}{\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \left(\lambda_1 + \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}^{0.3333333333333333}\right)}}^{3} \]
    12. Taylor expanded in phi1 around 0 37.6%

      \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_1 + \lambda_2}\right)\right)}^{0.3333333333333333}\right)}^{3} \]
    13. Step-by-step derivation
      1. +-commutative37.6%

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_2 + \lambda_1}\right)\right)}^{0.3333333333333333}\right)}^{3} \]
    14. Simplified37.6%

      \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_2 + \lambda_1}\right)\right)}^{0.3333333333333333}\right)}^{3} \]
    15. Taylor expanded in lambda2 around 0 42.3%

      \[\leadsto \color{blue}{R \cdot \sqrt{{\lambda_1}^{2} + {\phi_1}^{2}}} \]
    16. Step-by-step derivation
      1. unpow242.3%

        \[\leadsto R \cdot \sqrt{\color{blue}{\lambda_1 \cdot \lambda_1} + {\phi_1}^{2}} \]
      2. unpow242.3%

        \[\leadsto R \cdot \sqrt{\lambda_1 \cdot \lambda_1 + \color{blue}{\phi_1 \cdot \phi_1}} \]
      3. hypot-define61.1%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\lambda_1, \phi_1\right)} \]
    17. Simplified61.1%

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

    if 7.5000000000000003e-94 < phi2 < 1.02000000000000004e-65

    1. Initial program 28.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-define100.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. Simplified100.0%

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

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

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      5. unswap-sqr28.6%

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

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{-\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)}\right) \]
      2. distribute-lft-neg-out76.4%

        \[\leadsto R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\left(-\lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}\right) \]
      3. *-commutative76.4%

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{-1 \cdot \lambda_2}\right) \]
    12. Simplified66.7%

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

    if 1.2999999999999999e-16 < phi2

    1. Initial program 60.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.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. Simplified95.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 64.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. mul-1-neg64.6%

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

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

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

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

      \[\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 7: 54.9% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
t_0 := R \cdot \mathsf{hypot}\left(\lambda_1, \phi_1\right)\\
\mathbf{if}\;\phi_2 \leq 1.4 \cdot 10^{-93}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\phi_2 \leq 5.5 \cdot 10^{-67}:\\
\;\;\;\;R \cdot \lambda_2\\

\mathbf{elif}\;\phi_2 \leq 4.8 \cdot 10^{-17}:\\
\;\;\;\;t\_0\\

\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 phi2 < 1.39999999999999999e-93 or 5.5000000000000003e-67 < phi2 < 4.79999999999999973e-17

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

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

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

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

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      5. unswap-sqr56.0%

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      6. hypot-define82.7%

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

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \]
    8. Step-by-step derivation
      1. add-cube-cbrt81.8%

        \[\leadsto \color{blue}{\left(\sqrt[3]{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot \sqrt[3]{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}\right) \cdot \sqrt[3]{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      2. pow381.8%

        \[\leadsto \color{blue}{{\left(\sqrt[3]{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}\right)}^{3}} \]
    9. Applied egg-rr81.8%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}\right)}^{3}} \]
    10. Step-by-step derivation
      1. pow1/338.6%

        \[\leadsto {\color{blue}{\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)\right)}^{0.3333333333333333}\right)}}^{3} \]
      2. *-commutative38.6%

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}\right)\right)}^{0.3333333333333333}\right)}^{3} \]
      3. sub-neg38.6%

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 + \left(-\lambda_2\right)\right)} \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}^{0.3333333333333333}\right)}^{3} \]
      4. add-sqr-sqrt18.3%

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \left(\lambda_1 + \color{blue}{\sqrt{-\lambda_2} \cdot \sqrt{-\lambda_2}}\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}^{0.3333333333333333}\right)}^{3} \]
      5. sqrt-unprod35.5%

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \left(\lambda_1 + \color{blue}{\sqrt{\left(-\lambda_2\right) \cdot \left(-\lambda_2\right)}}\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}^{0.3333333333333333}\right)}^{3} \]
      6. sqr-neg35.5%

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \left(\lambda_1 + \sqrt{\color{blue}{\lambda_2 \cdot \lambda_2}}\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}^{0.3333333333333333}\right)}^{3} \]
      7. sqrt-unprod20.3%

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \left(\lambda_1 + \color{blue}{\sqrt{\lambda_2} \cdot \sqrt{\lambda_2}}\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}^{0.3333333333333333}\right)}^{3} \]
      8. add-sqr-sqrt38.6%

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

      \[\leadsto {\color{blue}{\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \left(\lambda_1 + \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}^{0.3333333333333333}\right)}}^{3} \]
    12. Taylor expanded in phi1 around 0 37.6%

      \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_1 + \lambda_2}\right)\right)}^{0.3333333333333333}\right)}^{3} \]
    13. Step-by-step derivation
      1. +-commutative37.6%

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_2 + \lambda_1}\right)\right)}^{0.3333333333333333}\right)}^{3} \]
    14. Simplified37.6%

      \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\lambda_2 + \lambda_1}\right)\right)}^{0.3333333333333333}\right)}^{3} \]
    15. Taylor expanded in lambda2 around 0 42.3%

      \[\leadsto \color{blue}{R \cdot \sqrt{{\lambda_1}^{2} + {\phi_1}^{2}}} \]
    16. Step-by-step derivation
      1. unpow242.3%

        \[\leadsto R \cdot \sqrt{\color{blue}{\lambda_1 \cdot \lambda_1} + {\phi_1}^{2}} \]
      2. unpow242.3%

        \[\leadsto R \cdot \sqrt{\lambda_1 \cdot \lambda_1 + \color{blue}{\phi_1 \cdot \phi_1}} \]
      3. hypot-define61.1%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\lambda_1, \phi_1\right)} \]
    17. Simplified61.1%

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

    if 1.39999999999999999e-93 < phi2 < 5.5000000000000003e-67

    1. Initial program 28.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-define100.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. Simplified100.0%

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

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

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      5. unswap-sqr28.6%

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

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

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \]
    8. Taylor expanded in lambda2 around inf 39.0%

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

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

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

      \[\leadsto \color{blue}{R \cdot \lambda_2} \]
    12. Simplified41.9%

      \[\leadsto \color{blue}{\lambda_2 \cdot R} \]

    if 4.79999999999999973e-17 < phi2

    1. Initial program 60.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.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. Simplified95.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 64.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. mul-1-neg64.6%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.4 \cdot 10^{-93}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1, \phi_1\right)\\ \mathbf{elif}\;\phi_2 \leq 5.5 \cdot 10^{-67}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{elif}\;\phi_2 \leq 4.8 \cdot 10^{-17}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1, \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 69.7% accurate, 3.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 0.000175:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\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 2 regimes
  2. if phi2 < 1.74999999999999998e-4

    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-define96.6%

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

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

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

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

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

        \[\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-define77.4%

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

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

    if 1.74999999999999998e-4 < phi2

    1. Initial program 60.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.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 phi2 around inf 63.9%

      \[\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-neg63.9%

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

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

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

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

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

Alternative 9: 27.2% accurate, 7.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := R \cdot \left(-\lambda_1\right)\\ t_1 := R \cdot \left(-\phi_1\right)\\ \mathbf{if}\;\phi_2 \leq -3.25 \cdot 10^{-282}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\phi_2 \leq 6.1 \cdot 10^{-294}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_2 \leq 9.5 \cdot 10^{-236}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\phi_2 \leq 2.4 \cdot 10^{-157}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{elif}\;\phi_2 \leq 8.2 \cdot 10^{-98}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\phi_2 \leq 5.5 \cdot 10^{-30}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{elif}\;\phi_2 \leq 3.6 \cdot 10^{-16}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_2 \leq 1.68 \cdot 10^{+66}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* R (- lambda1))) (t_1 (* R (- phi1))))
   (if (<= phi2 -3.25e-282)
     t_1
     (if (<= phi2 6.1e-294)
       t_0
       (if (<= phi2 9.5e-236)
         t_1
         (if (<= phi2 2.4e-157)
           (* R lambda2)
           (if (<= phi2 8.2e-98)
             t_1
             (if (<= phi2 5.5e-30)
               (* R lambda2)
               (if (<= phi2 3.6e-16)
                 t_0
                 (if (<= phi2 1.68e+66) t_1 (* R phi2)))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * -lambda1;
	double t_1 = R * -phi1;
	double tmp;
	if (phi2 <= -3.25e-282) {
		tmp = t_1;
	} else if (phi2 <= 6.1e-294) {
		tmp = t_0;
	} else if (phi2 <= 9.5e-236) {
		tmp = t_1;
	} else if (phi2 <= 2.4e-157) {
		tmp = R * lambda2;
	} else if (phi2 <= 8.2e-98) {
		tmp = t_1;
	} else if (phi2 <= 5.5e-30) {
		tmp = R * lambda2;
	} else if (phi2 <= 3.6e-16) {
		tmp = t_0;
	} else if (phi2 <= 1.68e+66) {
		tmp = t_1;
	} 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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = r * -lambda1
    t_1 = r * -phi1
    if (phi2 <= (-3.25d-282)) then
        tmp = t_1
    else if (phi2 <= 6.1d-294) then
        tmp = t_0
    else if (phi2 <= 9.5d-236) then
        tmp = t_1
    else if (phi2 <= 2.4d-157) then
        tmp = r * lambda2
    else if (phi2 <= 8.2d-98) then
        tmp = t_1
    else if (phi2 <= 5.5d-30) then
        tmp = r * lambda2
    else if (phi2 <= 3.6d-16) then
        tmp = t_0
    else if (phi2 <= 1.68d+66) then
        tmp = t_1
    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 t_0 = R * -lambda1;
	double t_1 = R * -phi1;
	double tmp;
	if (phi2 <= -3.25e-282) {
		tmp = t_1;
	} else if (phi2 <= 6.1e-294) {
		tmp = t_0;
	} else if (phi2 <= 9.5e-236) {
		tmp = t_1;
	} else if (phi2 <= 2.4e-157) {
		tmp = R * lambda2;
	} else if (phi2 <= 8.2e-98) {
		tmp = t_1;
	} else if (phi2 <= 5.5e-30) {
		tmp = R * lambda2;
	} else if (phi2 <= 3.6e-16) {
		tmp = t_0;
	} else if (phi2 <= 1.68e+66) {
		tmp = t_1;
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = R * -lambda1
	t_1 = R * -phi1
	tmp = 0
	if phi2 <= -3.25e-282:
		tmp = t_1
	elif phi2 <= 6.1e-294:
		tmp = t_0
	elif phi2 <= 9.5e-236:
		tmp = t_1
	elif phi2 <= 2.4e-157:
		tmp = R * lambda2
	elif phi2 <= 8.2e-98:
		tmp = t_1
	elif phi2 <= 5.5e-30:
		tmp = R * lambda2
	elif phi2 <= 3.6e-16:
		tmp = t_0
	elif phi2 <= 1.68e+66:
		tmp = t_1
	else:
		tmp = R * phi2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(R * Float64(-lambda1))
	t_1 = Float64(R * Float64(-phi1))
	tmp = 0.0
	if (phi2 <= -3.25e-282)
		tmp = t_1;
	elseif (phi2 <= 6.1e-294)
		tmp = t_0;
	elseif (phi2 <= 9.5e-236)
		tmp = t_1;
	elseif (phi2 <= 2.4e-157)
		tmp = Float64(R * lambda2);
	elseif (phi2 <= 8.2e-98)
		tmp = t_1;
	elseif (phi2 <= 5.5e-30)
		tmp = Float64(R * lambda2);
	elseif (phi2 <= 3.6e-16)
		tmp = t_0;
	elseif (phi2 <= 1.68e+66)
		tmp = t_1;
	else
		tmp = Float64(R * phi2);
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = R * -lambda1;
	t_1 = R * -phi1;
	tmp = 0.0;
	if (phi2 <= -3.25e-282)
		tmp = t_1;
	elseif (phi2 <= 6.1e-294)
		tmp = t_0;
	elseif (phi2 <= 9.5e-236)
		tmp = t_1;
	elseif (phi2 <= 2.4e-157)
		tmp = R * lambda2;
	elseif (phi2 <= 8.2e-98)
		tmp = t_1;
	elseif (phi2 <= 5.5e-30)
		tmp = R * lambda2;
	elseif (phi2 <= 3.6e-16)
		tmp = t_0;
	elseif (phi2 <= 1.68e+66)
		tmp = t_1;
	else
		tmp = R * phi2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(R * (-lambda1)), $MachinePrecision]}, Block[{t$95$1 = N[(R * (-phi1)), $MachinePrecision]}, If[LessEqual[phi2, -3.25e-282], t$95$1, If[LessEqual[phi2, 6.1e-294], t$95$0, If[LessEqual[phi2, 9.5e-236], t$95$1, If[LessEqual[phi2, 2.4e-157], N[(R * lambda2), $MachinePrecision], If[LessEqual[phi2, 8.2e-98], t$95$1, If[LessEqual[phi2, 5.5e-30], N[(R * lambda2), $MachinePrecision], If[LessEqual[phi2, 3.6e-16], t$95$0, If[LessEqual[phi2, 1.68e+66], t$95$1, N[(R * phi2), $MachinePrecision]]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := R \cdot \left(-\lambda_1\right)\\
t_1 := R \cdot \left(-\phi_1\right)\\
\mathbf{if}\;\phi_2 \leq -3.25 \cdot 10^{-282}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\phi_2 \leq 6.1 \cdot 10^{-294}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\phi_2 \leq 9.5 \cdot 10^{-236}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\phi_2 \leq 2.4 \cdot 10^{-157}:\\
\;\;\;\;R \cdot \lambda_2\\

\mathbf{elif}\;\phi_2 \leq 8.2 \cdot 10^{-98}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\phi_2 \leq 5.5 \cdot 10^{-30}:\\
\;\;\;\;R \cdot \lambda_2\\

\mathbf{elif}\;\phi_2 \leq 3.6 \cdot 10^{-16}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\phi_2 \leq 1.68 \cdot 10^{+66}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if phi2 < -3.25000000000000006e-282 or 6.1000000000000003e-294 < phi2 < 9.50000000000000065e-236 or 2.4e-157 < phi2 < 8.1999999999999996e-98 or 3.59999999999999983e-16 < phi2 < 1.67999999999999993e66

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

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

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

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

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

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

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

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

    if -3.25000000000000006e-282 < phi2 < 6.1000000000000003e-294 or 5.49999999999999976e-30 < phi2 < 3.59999999999999983e-16

    1. Initial program 74.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 28.9%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)} \]
      2. distribute-rgt-neg-in28.6%

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

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

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

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

    if 9.50000000000000065e-236 < phi2 < 2.4e-157 or 8.1999999999999996e-98 < phi2 < 5.49999999999999976e-30

    1. Initial program 60.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-define100.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. Simplified100.0%

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

      \[\leadsto \color{blue}{R \cdot \sqrt{{\cos \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
    6. Step-by-step derivation
      1. +-commutative60.9%

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      5. unswap-sqr60.9%

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

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

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \]
    8. Taylor expanded in lambda2 around inf 22.8%

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

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

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

      \[\leadsto \color{blue}{R \cdot \lambda_2} \]
    12. Simplified18.5%

      \[\leadsto \color{blue}{\lambda_2 \cdot R} \]

    if 1.67999999999999993e66 < phi2

    1. Initial program 58.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-define94.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. Simplified94.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 63.7%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -3.25 \cdot 10^{-282}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_2 \leq 6.1 \cdot 10^{-294}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\phi_2 \leq 9.5 \cdot 10^{-236}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_2 \leq 2.4 \cdot 10^{-157}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{elif}\;\phi_2 \leq 8.2 \cdot 10^{-98}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_2 \leq 5.5 \cdot 10^{-30}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{elif}\;\phi_2 \leq 3.6 \cdot 10^{-16}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\phi_2 \leq 1.68 \cdot 10^{+66}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 37.8% accurate, 11.3× speedup?

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

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

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

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

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

\mathbf{else}:\\
\;\;\;\;R \cdot \left(\lambda_1 + \lambda_2\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if lambda1 < -1.49999999999999989e136 or -2.1e62 < lambda1 < -4.69999999999999972e58

    1. Initial program 45.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-define91.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)} \]
      2. distribute-rgt-neg-in46.6%

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

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

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

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

    if -1.49999999999999989e136 < lambda1 < -2.1e62

    1. Initial program 60.7%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define99.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 phi2 around inf 43.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. mul-1-neg43.2%

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

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

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

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

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

    if -4.69999999999999972e58 < lambda1 < 1.3e-215

    1. Initial program 74.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.4%

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

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

      \[\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/35.5%

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

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

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

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

    if 1.3e-215 < lambda1

    1. Initial program 58.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.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. Simplified97.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 phi2 around 0 47.2%

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

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      5. unswap-sqr47.2%

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      6. hypot-define77.2%

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

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \]
    8. Step-by-step derivation
      1. add-cube-cbrt76.3%

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

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

      \[\leadsto \color{blue}{{\left(\sqrt[3]{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}\right)}^{3}} \]
    10. Step-by-step derivation
      1. pow1/334.6%

        \[\leadsto {\color{blue}{\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)\right)}^{0.3333333333333333}\right)}}^{3} \]
      2. *-commutative34.6%

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}\right)\right)}^{0.3333333333333333}\right)}^{3} \]
      3. sub-neg34.6%

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 + \left(-\lambda_2\right)\right)} \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}^{0.3333333333333333}\right)}^{3} \]
      4. add-sqr-sqrt17.2%

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

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

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

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \left(\lambda_1 + \color{blue}{\sqrt{\lambda_2} \cdot \sqrt{\lambda_2}}\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}^{0.3333333333333333}\right)}^{3} \]
      8. add-sqr-sqrt34.6%

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

      \[\leadsto {\color{blue}{\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \left(\lambda_1 + \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}^{0.3333333333333333}\right)}}^{3} \]
    12. Taylor expanded in phi1 around 0 33.8%

      \[\leadsto \color{blue}{R \cdot \left(\lambda_1 + \lambda_2\right)} \]
    13. Step-by-step derivation
      1. +-commutative33.8%

        \[\leadsto R \cdot \color{blue}{\left(\lambda_2 + \lambda_1\right)} \]
    14. Simplified33.8%

      \[\leadsto \color{blue}{R \cdot \left(\lambda_2 + \lambda_1\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification39.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -1.5 \cdot 10^{+136}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq -2.1 \cdot 10^{+62}:\\ \;\;\;\;\phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right)\\ \mathbf{elif}\;\lambda_1 \leq -4.7 \cdot 10^{+58}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq 1.3 \cdot 10^{-215}:\\ \;\;\;\;\phi_2 \cdot \left(R - \frac{R \cdot \phi_1}{\phi_2}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\lambda_1 + \lambda_2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 37.0% accurate, 17.3× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;R \cdot \left(\lambda_1 + \lambda_2\right)\\


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

    1. Initial program 44.0%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)\right)} \]
    9. Step-by-step derivation
      1. mul-1-neg47.3%

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

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

        \[\leadsto R \cdot \left(-\color{blue}{\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1}\right) \]
    10. Simplified47.3%

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

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

    if -1.89999999999999988e141 < lambda1 < 6.99999999999999965e-216

    1. Initial program 72.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-define96.9%

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

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

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

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

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

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

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

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

    if 6.99999999999999965e-216 < lambda1

    1. Initial program 58.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.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. Simplified97.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 phi2 around 0 47.2%

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

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      5. unswap-sqr47.2%

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      6. hypot-define77.2%

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

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \]
    8. Step-by-step derivation
      1. add-cube-cbrt76.3%

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

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

      \[\leadsto \color{blue}{{\left(\sqrt[3]{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}\right)}^{3}} \]
    10. Step-by-step derivation
      1. pow1/334.6%

        \[\leadsto {\color{blue}{\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)\right)}^{0.3333333333333333}\right)}}^{3} \]
      2. *-commutative34.6%

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)}\right)\right)}^{0.3333333333333333}\right)}^{3} \]
      3. sub-neg34.6%

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \color{blue}{\left(\lambda_1 + \left(-\lambda_2\right)\right)} \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}^{0.3333333333333333}\right)}^{3} \]
      4. add-sqr-sqrt17.2%

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

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

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

        \[\leadsto {\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \left(\lambda_1 + \color{blue}{\sqrt{\lambda_2} \cdot \sqrt{\lambda_2}}\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}^{0.3333333333333333}\right)}^{3} \]
      8. add-sqr-sqrt34.6%

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

      \[\leadsto {\color{blue}{\left({\left(R \cdot \mathsf{hypot}\left(\phi_1, \left(\lambda_1 + \lambda_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)\right)}^{0.3333333333333333}\right)}}^{3} \]
    12. Taylor expanded in phi1 around 0 33.8%

      \[\leadsto \color{blue}{R \cdot \left(\lambda_1 + \lambda_2\right)} \]
    13. Step-by-step derivation
      1. +-commutative33.8%

        \[\leadsto R \cdot \color{blue}{\left(\lambda_2 + \lambda_1\right)} \]
    14. Simplified33.8%

      \[\leadsto \color{blue}{R \cdot \left(\lambda_2 + \lambda_1\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification37.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -1.9 \cdot 10^{+141}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq 7 \cdot 10^{-216}:\\ \;\;\;\;\phi_2 \cdot \left(R - R \cdot \frac{\phi_1}{\phi_2}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\lambda_1 + \lambda_2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 26.5% accurate, 25.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 3.4 \cdot 10^{-95}:\\
\;\;\;\;R \cdot \left(-\lambda_1\right)\\

\mathbf{elif}\;\phi_2 \leq 3 \cdot 10^{-11}:\\
\;\;\;\;R \cdot \lambda_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < 3.39999999999999993e-95

    1. Initial program 64.6%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)} \]
      2. distribute-rgt-neg-in19.8%

        \[\leadsto \color{blue}{R \cdot \left(-\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)} \]
      3. *-commutative19.8%

        \[\leadsto R \cdot \left(-\color{blue}{\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1}\right) \]
    10. Simplified19.8%

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

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

    if 3.39999999999999993e-95 < phi2 < 3e-11

    1. Initial program 43.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-define100.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. Simplified100.0%

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

      \[\leadsto \color{blue}{R \cdot \sqrt{{\cos \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}} \]
    6. Step-by-step derivation
      1. +-commutative43.8%

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      5. unswap-sqr43.8%

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

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

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \]
    8. Taylor expanded in lambda2 around inf 25.8%

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

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

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

      \[\leadsto \color{blue}{R \cdot \lambda_2} \]
    12. Simplified26.1%

      \[\leadsto \color{blue}{\lambda_2 \cdot R} \]

    if 3e-11 < phi2

    1. Initial program 60.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.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. Simplified95.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 53.8%

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

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

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

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

Alternative 13: 29.0% accurate, 36.6× speedup?

\[\begin{array}{l} \\ \phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right) \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (* phi2 (- R (* phi1 (/ R phi2)))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return phi2 * (R - (phi1 * (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 = phi2 * (r - (phi1 * (r / phi2)))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return phi2 * (R - (phi1 * (R / phi2)));
}
def code(R, lambda1, lambda2, phi1, phi2):
	return phi2 * (R - (phi1 * (R / phi2)))
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(phi2 * Float64(R - Float64(phi1 * Float64(R / phi2))))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = phi2 * (R - (phi1 * (R / phi2)));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(phi2 * N[(R - N[(phi1 * N[(R / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right)
\end{array}
Derivation
  1. Initial program 62.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-define96.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. Simplified96.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 phi2 around inf 28.5%

    \[\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-neg28.5%

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

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

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

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

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

Alternative 14: 26.8% accurate, 41.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 4.8 \cdot 10^{-29}:\\
\;\;\;\;R \cdot \lambda_2\\

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


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

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

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

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

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

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

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

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

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      5. unswap-sqr55.0%

        \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
      6. hypot-define82.9%

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

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \]
    8. Taylor expanded in lambda2 around inf 15.5%

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

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

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

      \[\leadsto \color{blue}{R \cdot \lambda_2} \]
    12. Simplified14.3%

      \[\leadsto \color{blue}{\lambda_2 \cdot R} \]

    if 4.79999999999999984e-29 < phi2

    1. Initial program 59.9%

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

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

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

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

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

Alternative 15: 14.6% accurate, 109.7× speedup?

\[\begin{array}{l} \\ R \cdot \lambda_2 \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R lambda2))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * lambda2;
}
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 * lambda2
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * lambda2;
}
def code(R, lambda1, lambda2, phi1, phi2):
	return R * lambda2
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(R * lambda2)
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = R * lambda2;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * lambda2), $MachinePrecision]
\begin{array}{l}

\\
R \cdot \lambda_2
\end{array}
Derivation
  1. Initial program 62.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-define96.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. Simplified96.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 phi2 around 0 50.4%

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

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

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

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

      \[\leadsto R \cdot \sqrt{\phi_1 \cdot \phi_1 + \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
    5. unswap-sqr50.4%

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

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

    \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \]
  8. Taylor expanded in lambda2 around inf 13.9%

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

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

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

    \[\leadsto \color{blue}{R \cdot \lambda_2} \]
  12. Simplified13.7%

    \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
  13. Final simplification13.7%

    \[\leadsto R \cdot \lambda_2 \]
  14. Add Preprocessing

Alternative 16: 14.1% 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 62.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-define96.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. Simplified96.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 lambda1 around inf 17.6%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\lambda_1 \cdot R} \]
  13. Simplified14.1%

    \[\leadsto \color{blue}{\lambda_1 \cdot R} \]
  14. Final simplification14.1%

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

Reproduce

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