Equirectangular approximation to distance on a great circle

Percentage Accurate: 60.7% → 99.8%
Time: 20.4s
Alternatives: 15
Speedup: 1.6×

Specification

?
\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\\ R \cdot \sqrt{t_0 \cdot t_0 + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0)))))
   (* R (sqrt (+ (* t_0 t_0) (* (- phi1 phi2) (- phi1 phi2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0));
	return R * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
}
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 15 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.7% accurate, 1.0× speedup?

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

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

Alternative 1: 99.8% accurate, 0.4× speedup?

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

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \sqrt[3]{{\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)}}^{3}}, \phi_1 - \phi_2\right) \]
  7. Applied egg-rr99.8%

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \sqrt[3]{{\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)}}^{3}}, \phi_1 - \phi_2\right) \]
  8. Step-by-step derivation
    1. expm1-log1p-u99.8%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt[3]{{\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)}^{3}}\right)\right)}, \phi_1 - \phi_2\right) \]
    2. rem-cbrt-cube99.9%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\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) \]
    3. *-commutative99.9%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(\phi_2 \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) \]
    4. *-commutative99.9%

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

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

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

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

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

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

Alternative 2: 99.8% accurate, 0.5× speedup?

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

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \sqrt[3]{{\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)}}^{3}}, \phi_1 - \phi_2\right) \]
  7. Applied egg-rr99.8%

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \sqrt[3]{{\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)}}^{3}}, \phi_1 - \phi_2\right) \]
  8. Step-by-step derivation
    1. expm1-log1p-u99.8%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt[3]{{\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)}^{3}}\right)\right)}, \phi_1 - \phi_2\right) \]
    2. rem-cbrt-cube99.9%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\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) \]
    3. *-commutative99.9%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(\phi_2 \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) \]
    4. *-commutative99.9%

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

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

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

Alternative 3: 99.8% accurate, 0.6× speedup?

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

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \sqrt[3]{{\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)}}^{3}}, \phi_1 - \phi_2\right) \]
  7. Applied egg-rr99.8%

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \sqrt[3]{{\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)}}^{3}}, \phi_1 - \phi_2\right) \]
  8. Step-by-step derivation
    1. expm1-log1p-u99.8%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt[3]{{\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)}^{3}}\right)\right)}, \phi_1 - \phi_2\right) \]
    2. rem-cbrt-cube99.9%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\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) \]
    3. *-commutative99.9%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\cos \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(\phi_2 \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) \]
    4. *-commutative99.9%

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)} - 1\right)}, \phi_1 - \phi_2\right) \]
    2. log1p-expm1-u99.8%

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(e^{\color{blue}{\log \left(1 + \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right)\right)}} - 1\right), \phi_1 - \phi_2\right) \]
    4. add-exp-log99.8%

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

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

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

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

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

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

Alternative 4: 82.4% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 52.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-def91.5%

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

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

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

    if -1.8000000000000001e-42 < phi1

    1. Initial program 65.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\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)} \]
    8. Simplified79.9%

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

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

Alternative 5: 93.1% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 48.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-def90.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. Simplified90.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. Taylor expanded in phi2 around 0 90.8%

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

    if -7.99999999999999964e-6 < phi1

    1. Initial program 66.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-def98.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. Simplified98.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. Taylor expanded in phi1 around 0 94.4%

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

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

Alternative 6: 95.9% accurate, 1.5× speedup?

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

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

    \[\leadsto 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) \]

Alternative 7: 74.2% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 1.35 \cdot 10^{-25}:\\
\;\;\;\;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 \left(\phi_2 - \phi_1\right)\\


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

    1. Initial program 62.8%

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

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

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

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

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

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

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

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

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

        \[\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}}} \]
      2. +-commutative51.1%

        \[\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}}} \]
      3. unpow251.1%

        \[\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}} \]
      4. unpow251.1%

        \[\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}} \]
      5. unpow251.1%

        \[\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)}} \]
      6. unswap-sqr51.1%

        \[\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)}} \]
      7. hypot-def77.1%

        \[\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)} \]
    8. Simplified77.1%

      \[\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.35000000000000008e-25 < phi2

    1. Initial program 56.3%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.35 \cdot 10^{-25}:\\ \;\;\;\;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 \left(\phi_2 - \phi_1\right)\\ \end{array} \]

Alternative 8: 78.7% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -5.4 \cdot 10^{-17}:\\
\;\;\;\;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(0.5 \cdot \phi_2\right)\right)\\


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

    1. Initial program 51.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-def90.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. Simplified90.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. Step-by-step derivation
      1. expm1-log1p-u57.6%

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

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

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

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

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

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

        \[\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}}} \]
      2. +-commutative45.7%

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

        \[\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}} \]
      4. unpow245.7%

        \[\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}} \]
      5. unpow245.7%

        \[\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)}} \]
      6. unswap-sqr45.7%

        \[\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)}} \]
      7. hypot-def71.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)} \]
    8. Simplified71.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)} \]

    if -5.4000000000000002e-17 < phi1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\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)} \]
    8. Simplified80.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -5.4 \cdot 10^{-17}:\\ \;\;\;\;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(0.5 \cdot \phi_2\right)\right)\\ \end{array} \]

Alternative 9: 34.0% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -2.8 \cdot 10^{-26} \lor \neg \left(\phi_1 \leq 5.2 \cdot 10^{-197}\right):\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \left(\lambda_2 - \lambda_1\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (or (<= phi1 -2.8e-26) (not (<= phi1 5.2e-197)))
   (* R (- phi2 phi1))
   (* (* R (cos (* 0.5 phi2))) (- lambda2 lambda1))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if ((phi1 <= -2.8e-26) || !(phi1 <= 5.2e-197)) {
		tmp = R * (phi2 - phi1);
	} else {
		tmp = (R * cos((0.5 * phi2))) * (lambda2 - lambda1);
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: tmp
    if ((phi1 <= (-2.8d-26)) .or. (.not. (phi1 <= 5.2d-197))) then
        tmp = r * (phi2 - phi1)
    else
        tmp = (r * cos((0.5d0 * phi2))) * (lambda2 - lambda1)
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if ((phi1 <= -2.8e-26) || !(phi1 <= 5.2e-197)) {
		tmp = R * (phi2 - phi1);
	} else {
		tmp = (R * Math.cos((0.5 * phi2))) * (lambda2 - lambda1);
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if (phi1 <= -2.8e-26) or not (phi1 <= 5.2e-197):
		tmp = R * (phi2 - phi1)
	else:
		tmp = (R * math.cos((0.5 * phi2))) * (lambda2 - lambda1)
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if ((phi1 <= -2.8e-26) || !(phi1 <= 5.2e-197))
		tmp = Float64(R * Float64(phi2 - phi1));
	else
		tmp = Float64(Float64(R * cos(Float64(0.5 * phi2))) * Float64(lambda2 - lambda1));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if ((phi1 <= -2.8e-26) || ~((phi1 <= 5.2e-197)))
		tmp = R * (phi2 - phi1);
	else
		tmp = (R * cos((0.5 * phi2))) * (lambda2 - lambda1);
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[Or[LessEqual[phi1, -2.8e-26], N[Not[LessEqual[phi1, 5.2e-197]], $MachinePrecision]], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], N[(N[(R * N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -2.8 \cdot 10^{-26} \lor \neg \left(\phi_1 \leq 5.2 \cdot 10^{-197}\right):\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi1 < -2.8000000000000001e-26 or 5.2000000000000003e-197 < phi1

    1. Initial program 56.6%

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

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

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

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

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

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

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

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

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

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

    if -2.8000000000000001e-26 < phi1 < 5.2000000000000003e-197

    1. Initial program 71.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-def99.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. Taylor expanded in lambda1 around -inf 35.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\lambda_2 \cdot \left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) - R \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1\right)} \]
    8. Step-by-step derivation
      1. *-commutative35.7%

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

        \[\leadsto \left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \lambda_2 - \color{blue}{\left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \lambda_1} \]
      3. distribute-lft-out--35.7%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -2.8 \cdot 10^{-26} \lor \neg \left(\phi_1 \leq 5.2 \cdot 10^{-197}\right):\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \left(\lambda_2 - \lambda_1\right)\\ \end{array} \]

Alternative 10: 27.9% accurate, 18.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := R \cdot \left(-\lambda_1\right)\\ \mathbf{if}\;\phi_1 \leq -1.2 \cdot 10^{-20}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -1 \cdot 10^{-101}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\phi_1 \leq -6 \cdot 10^{-197}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{elif}\;\phi_1 \leq -4.1 \cdot 10^{-218}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\phi_1 \leq -1.75 \cdot 10^{-252}:\\ \;\;\;\;R \cdot \phi_2\\ \mathbf{elif}\;\phi_1 \leq -1.05 \cdot 10^{-296}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\phi_1 \leq 2.05 \cdot 10^{-291}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* R (- lambda1))))
   (if (<= phi1 -1.2e-20)
     (* R (- phi1))
     (if (<= phi1 -1e-101)
       t_0
       (if (<= phi1 -6e-197)
         (* R lambda2)
         (if (<= phi1 -4.1e-218)
           t_0
           (if (<= phi1 -1.75e-252)
             (* R phi2)
             (if (<= phi1 -1.05e-296)
               t_0
               (if (<= phi1 2.05e-291) (* R lambda2) (* R phi2))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * -lambda1;
	double tmp;
	if (phi1 <= -1.2e-20) {
		tmp = R * -phi1;
	} else if (phi1 <= -1e-101) {
		tmp = t_0;
	} else if (phi1 <= -6e-197) {
		tmp = R * lambda2;
	} else if (phi1 <= -4.1e-218) {
		tmp = t_0;
	} else if (phi1 <= -1.75e-252) {
		tmp = R * phi2;
	} else if (phi1 <= -1.05e-296) {
		tmp = t_0;
	} else if (phi1 <= 2.05e-291) {
		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) :: t_0
    real(8) :: tmp
    t_0 = r * -lambda1
    if (phi1 <= (-1.2d-20)) then
        tmp = r * -phi1
    else if (phi1 <= (-1d-101)) then
        tmp = t_0
    else if (phi1 <= (-6d-197)) then
        tmp = r * lambda2
    else if (phi1 <= (-4.1d-218)) then
        tmp = t_0
    else if (phi1 <= (-1.75d-252)) then
        tmp = r * phi2
    else if (phi1 <= (-1.05d-296)) then
        tmp = t_0
    else if (phi1 <= 2.05d-291) 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 t_0 = R * -lambda1;
	double tmp;
	if (phi1 <= -1.2e-20) {
		tmp = R * -phi1;
	} else if (phi1 <= -1e-101) {
		tmp = t_0;
	} else if (phi1 <= -6e-197) {
		tmp = R * lambda2;
	} else if (phi1 <= -4.1e-218) {
		tmp = t_0;
	} else if (phi1 <= -1.75e-252) {
		tmp = R * phi2;
	} else if (phi1 <= -1.05e-296) {
		tmp = t_0;
	} else if (phi1 <= 2.05e-291) {
		tmp = R * lambda2;
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = R * -lambda1
	tmp = 0
	if phi1 <= -1.2e-20:
		tmp = R * -phi1
	elif phi1 <= -1e-101:
		tmp = t_0
	elif phi1 <= -6e-197:
		tmp = R * lambda2
	elif phi1 <= -4.1e-218:
		tmp = t_0
	elif phi1 <= -1.75e-252:
		tmp = R * phi2
	elif phi1 <= -1.05e-296:
		tmp = t_0
	elif phi1 <= 2.05e-291:
		tmp = R * lambda2
	else:
		tmp = R * phi2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(R * Float64(-lambda1))
	tmp = 0.0
	if (phi1 <= -1.2e-20)
		tmp = Float64(R * Float64(-phi1));
	elseif (phi1 <= -1e-101)
		tmp = t_0;
	elseif (phi1 <= -6e-197)
		tmp = Float64(R * lambda2);
	elseif (phi1 <= -4.1e-218)
		tmp = t_0;
	elseif (phi1 <= -1.75e-252)
		tmp = Float64(R * phi2);
	elseif (phi1 <= -1.05e-296)
		tmp = t_0;
	elseif (phi1 <= 2.05e-291)
		tmp = Float64(R * lambda2);
	else
		tmp = Float64(R * phi2);
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = R * -lambda1;
	tmp = 0.0;
	if (phi1 <= -1.2e-20)
		tmp = R * -phi1;
	elseif (phi1 <= -1e-101)
		tmp = t_0;
	elseif (phi1 <= -6e-197)
		tmp = R * lambda2;
	elseif (phi1 <= -4.1e-218)
		tmp = t_0;
	elseif (phi1 <= -1.75e-252)
		tmp = R * phi2;
	elseif (phi1 <= -1.05e-296)
		tmp = t_0;
	elseif (phi1 <= 2.05e-291)
		tmp = R * lambda2;
	else
		tmp = R * phi2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(R * (-lambda1)), $MachinePrecision]}, If[LessEqual[phi1, -1.2e-20], N[(R * (-phi1)), $MachinePrecision], If[LessEqual[phi1, -1e-101], t$95$0, If[LessEqual[phi1, -6e-197], N[(R * lambda2), $MachinePrecision], If[LessEqual[phi1, -4.1e-218], t$95$0, If[LessEqual[phi1, -1.75e-252], N[(R * phi2), $MachinePrecision], If[LessEqual[phi1, -1.05e-296], t$95$0, If[LessEqual[phi1, 2.05e-291], N[(R * lambda2), $MachinePrecision], N[(R * phi2), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := R \cdot \left(-\lambda_1\right)\\
\mathbf{if}\;\phi_1 \leq -1.2 \cdot 10^{-20}:\\
\;\;\;\;R \cdot \left(-\phi_1\right)\\

\mathbf{elif}\;\phi_1 \leq -1 \cdot 10^{-101}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\phi_1 \leq -6 \cdot 10^{-197}:\\
\;\;\;\;R \cdot \lambda_2\\

\mathbf{elif}\;\phi_1 \leq -4.1 \cdot 10^{-218}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\phi_1 \leq -1.75 \cdot 10^{-252}:\\
\;\;\;\;R \cdot \phi_2\\

\mathbf{elif}\;\phi_1 \leq -1.05 \cdot 10^{-296}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\phi_1 \leq 2.05 \cdot 10^{-291}:\\
\;\;\;\;R \cdot \lambda_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if phi1 < -1.19999999999999996e-20

    1. Initial program 52.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-def90.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. Simplified90.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. Taylor expanded in phi1 around -inf 59.0%

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

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

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

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

    if -1.19999999999999996e-20 < phi1 < -1.00000000000000005e-101 or -6.00000000000000051e-197 < phi1 < -4.0999999999999998e-218 or -1.74999999999999993e-252 < phi1 < -1.05e-296

    1. Initial program 63.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-def99.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. Taylor expanded in lambda1 around -inf 23.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \lambda_2 - \color{blue}{\left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \lambda_1} \]
      3. distribute-lft-out--23.1%

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

        \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot R\right)} \cdot \left(\lambda_2 - \lambda_1\right) \]
    9. Simplified23.1%

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

      \[\leadsto \color{blue}{R} \cdot \left(\lambda_2 - \lambda_1\right) \]
    11. Taylor expanded in lambda2 around 0 10.7%

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \lambda_1\right)} \]
    12. Step-by-step derivation
      1. mul-1-neg10.7%

        \[\leadsto \color{blue}{-R \cdot \lambda_1} \]
      2. distribute-rgt-neg-in10.7%

        \[\leadsto \color{blue}{R \cdot \left(-\lambda_1\right)} \]
    13. Simplified10.7%

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

    if -1.00000000000000005e-101 < phi1 < -6.00000000000000051e-197 or -1.05e-296 < phi1 < 2.05e-291

    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-def99.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. Taylor expanded in lambda1 around -inf 47.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\lambda_2 \cdot \left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) - R \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1\right)} \]
    8. Step-by-step derivation
      1. *-commutative47.0%

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

        \[\leadsto \left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \lambda_2 - \color{blue}{\left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \lambda_1} \]
      3. distribute-lft-out--47.0%

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

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

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

      \[\leadsto \color{blue}{R} \cdot \left(\lambda_2 - \lambda_1\right) \]
    11. Taylor expanded in lambda2 around inf 28.2%

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

    if -4.0999999999999998e-218 < phi1 < -1.74999999999999993e-252 or 2.05e-291 < phi1

    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-def98.0%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.2 \cdot 10^{-20}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -1 \cdot 10^{-101}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\phi_1 \leq -6 \cdot 10^{-197}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{elif}\;\phi_1 \leq -4.1 \cdot 10^{-218}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\phi_1 \leq -1.75 \cdot 10^{-252}:\\ \;\;\;\;R \cdot \phi_2\\ \mathbf{elif}\;\phi_1 \leq -1.05 \cdot 10^{-296}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\phi_1 \leq 2.05 \cdot 10^{-291}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]

Alternative 11: 23.4% accurate, 21.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := R \cdot \left(-\lambda_1\right)\\ \mathbf{if}\;\lambda_2 \leq -3.7 \cdot 10^{-145}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\lambda_2 \leq -4 \cdot 10^{-259}:\\ \;\;\;\;R \cdot \phi_2\\ \mathbf{elif}\;\lambda_2 \leq 1.2 \cdot 10^{-287}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\lambda_2 \leq 2.8 \cdot 10^{-258}:\\ \;\;\;\;R \cdot \phi_2\\ \mathbf{elif}\;\lambda_2 \leq 2.3 \cdot 10^{-183}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\lambda_2 \leq 1.8 \cdot 10^{+39}:\\ \;\;\;\;R \cdot \phi_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \lambda_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* R (- lambda1))))
   (if (<= lambda2 -3.7e-145)
     t_0
     (if (<= lambda2 -4e-259)
       (* R phi2)
       (if (<= lambda2 1.2e-287)
         t_0
         (if (<= lambda2 2.8e-258)
           (* R phi2)
           (if (<= lambda2 2.3e-183)
             t_0
             (if (<= lambda2 1.8e+39) (* R phi2) (* R lambda2)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * -lambda1;
	double tmp;
	if (lambda2 <= -3.7e-145) {
		tmp = t_0;
	} else if (lambda2 <= -4e-259) {
		tmp = R * phi2;
	} else if (lambda2 <= 1.2e-287) {
		tmp = t_0;
	} else if (lambda2 <= 2.8e-258) {
		tmp = R * phi2;
	} else if (lambda2 <= 2.3e-183) {
		tmp = t_0;
	} else if (lambda2 <= 1.8e+39) {
		tmp = R * phi2;
	} else {
		tmp = R * lambda2;
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: tmp
    t_0 = r * -lambda1
    if (lambda2 <= (-3.7d-145)) then
        tmp = t_0
    else if (lambda2 <= (-4d-259)) then
        tmp = r * phi2
    else if (lambda2 <= 1.2d-287) then
        tmp = t_0
    else if (lambda2 <= 2.8d-258) then
        tmp = r * phi2
    else if (lambda2 <= 2.3d-183) then
        tmp = t_0
    else if (lambda2 <= 1.8d+39) then
        tmp = r * phi2
    else
        tmp = r * lambda2
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * -lambda1;
	double tmp;
	if (lambda2 <= -3.7e-145) {
		tmp = t_0;
	} else if (lambda2 <= -4e-259) {
		tmp = R * phi2;
	} else if (lambda2 <= 1.2e-287) {
		tmp = t_0;
	} else if (lambda2 <= 2.8e-258) {
		tmp = R * phi2;
	} else if (lambda2 <= 2.3e-183) {
		tmp = t_0;
	} else if (lambda2 <= 1.8e+39) {
		tmp = R * phi2;
	} else {
		tmp = R * lambda2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = R * -lambda1
	tmp = 0
	if lambda2 <= -3.7e-145:
		tmp = t_0
	elif lambda2 <= -4e-259:
		tmp = R * phi2
	elif lambda2 <= 1.2e-287:
		tmp = t_0
	elif lambda2 <= 2.8e-258:
		tmp = R * phi2
	elif lambda2 <= 2.3e-183:
		tmp = t_0
	elif lambda2 <= 1.8e+39:
		tmp = R * phi2
	else:
		tmp = R * lambda2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(R * Float64(-lambda1))
	tmp = 0.0
	if (lambda2 <= -3.7e-145)
		tmp = t_0;
	elseif (lambda2 <= -4e-259)
		tmp = Float64(R * phi2);
	elseif (lambda2 <= 1.2e-287)
		tmp = t_0;
	elseif (lambda2 <= 2.8e-258)
		tmp = Float64(R * phi2);
	elseif (lambda2 <= 2.3e-183)
		tmp = t_0;
	elseif (lambda2 <= 1.8e+39)
		tmp = Float64(R * phi2);
	else
		tmp = Float64(R * lambda2);
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = R * -lambda1;
	tmp = 0.0;
	if (lambda2 <= -3.7e-145)
		tmp = t_0;
	elseif (lambda2 <= -4e-259)
		tmp = R * phi2;
	elseif (lambda2 <= 1.2e-287)
		tmp = t_0;
	elseif (lambda2 <= 2.8e-258)
		tmp = R * phi2;
	elseif (lambda2 <= 2.3e-183)
		tmp = t_0;
	elseif (lambda2 <= 1.8e+39)
		tmp = R * phi2;
	else
		tmp = R * lambda2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(R * (-lambda1)), $MachinePrecision]}, If[LessEqual[lambda2, -3.7e-145], t$95$0, If[LessEqual[lambda2, -4e-259], N[(R * phi2), $MachinePrecision], If[LessEqual[lambda2, 1.2e-287], t$95$0, If[LessEqual[lambda2, 2.8e-258], N[(R * phi2), $MachinePrecision], If[LessEqual[lambda2, 2.3e-183], t$95$0, If[LessEqual[lambda2, 1.8e+39], N[(R * phi2), $MachinePrecision], N[(R * lambda2), $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := R \cdot \left(-\lambda_1\right)\\
\mathbf{if}\;\lambda_2 \leq -3.7 \cdot 10^{-145}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\lambda_2 \leq -4 \cdot 10^{-259}:\\
\;\;\;\;R \cdot \phi_2\\

\mathbf{elif}\;\lambda_2 \leq 1.2 \cdot 10^{-287}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\lambda_2 \leq 2.8 \cdot 10^{-258}:\\
\;\;\;\;R \cdot \phi_2\\

\mathbf{elif}\;\lambda_2 \leq 2.3 \cdot 10^{-183}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\lambda_2 \leq 1.8 \cdot 10^{+39}:\\
\;\;\;\;R \cdot \phi_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if lambda2 < -3.70000000000000013e-145 or -4.0000000000000003e-259 < lambda2 < 1.2e-287 or 2.8000000000000002e-258 < lambda2 < 2.30000000000000016e-183

    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-def95.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\lambda_2 \cdot \left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) - R \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1\right)} \]
    8. Step-by-step derivation
      1. *-commutative20.5%

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

        \[\leadsto \left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \lambda_2 - \color{blue}{\left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \lambda_1} \]
      3. distribute-lft-out--21.4%

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

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

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

      \[\leadsto \color{blue}{R} \cdot \left(\lambda_2 - \lambda_1\right) \]
    11. Taylor expanded in lambda2 around 0 12.0%

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \lambda_1\right)} \]
    12. Step-by-step derivation
      1. mul-1-neg12.0%

        \[\leadsto \color{blue}{-R \cdot \lambda_1} \]
      2. distribute-rgt-neg-in12.0%

        \[\leadsto \color{blue}{R \cdot \left(-\lambda_1\right)} \]
    13. Simplified12.0%

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

    if -3.70000000000000013e-145 < lambda2 < -4.0000000000000003e-259 or 1.2e-287 < lambda2 < 2.8000000000000002e-258 or 2.30000000000000016e-183 < lambda2 < 1.79999999999999992e39

    1. Initial program 69.2%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-def99.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. Simplified99.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. Taylor expanded in phi2 around inf 22.7%

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

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

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

    if 1.79999999999999992e39 < lambda2

    1. Initial program 44.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\lambda_2 \cdot \left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) - R \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1\right)} \]
    8. Step-by-step derivation
      1. *-commutative46.5%

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

        \[\leadsto \left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \lambda_2 - \color{blue}{\left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \lambda_1} \]
      3. distribute-lft-out--48.9%

        \[\leadsto \color{blue}{\left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \left(\lambda_2 - \lambda_1\right)} \]
      4. *-commutative48.9%

        \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot R\right)} \cdot \left(\lambda_2 - \lambda_1\right) \]
    9. Simplified48.9%

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

      \[\leadsto \color{blue}{R} \cdot \left(\lambda_2 - \lambda_1\right) \]
    11. Taylor expanded in lambda2 around inf 49.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq -3.7 \cdot 10^{-145}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_2 \leq -4 \cdot 10^{-259}:\\ \;\;\;\;R \cdot \phi_2\\ \mathbf{elif}\;\lambda_2 \leq 1.2 \cdot 10^{-287}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_2 \leq 2.8 \cdot 10^{-258}:\\ \;\;\;\;R \cdot \phi_2\\ \mathbf{elif}\;\lambda_2 \leq 2.3 \cdot 10^{-183}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_2 \leq 1.8 \cdot 10^{+39}:\\ \;\;\;\;R \cdot \phi_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \lambda_2\\ \end{array} \]

Alternative 12: 31.8% accurate, 24.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -2.5 \cdot 10^{-24} \lor \neg \left(\phi_1 \leq -4.6 \cdot 10^{-224} \lor \neg \left(\phi_1 \leq -1.1 \cdot 10^{-250}\right) \land \phi_1 \leq 5.3 \cdot 10^{-197}\right):\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (or (<= phi1 -2.5e-24)
         (not
          (or (<= phi1 -4.6e-224)
              (and (not (<= phi1 -1.1e-250)) (<= phi1 5.3e-197)))))
   (* R (- phi2 phi1))
   (* R (- lambda2 lambda1))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if ((phi1 <= -2.5e-24) || !((phi1 <= -4.6e-224) || (!(phi1 <= -1.1e-250) && (phi1 <= 5.3e-197)))) {
		tmp = R * (phi2 - phi1);
	} else {
		tmp = R * (lambda2 - lambda1);
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: tmp
    if ((phi1 <= (-2.5d-24)) .or. (.not. (phi1 <= (-4.6d-224)) .or. (.not. (phi1 <= (-1.1d-250))) .and. (phi1 <= 5.3d-197))) then
        tmp = r * (phi2 - phi1)
    else
        tmp = r * (lambda2 - lambda1)
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if ((phi1 <= -2.5e-24) || !((phi1 <= -4.6e-224) || (!(phi1 <= -1.1e-250) && (phi1 <= 5.3e-197)))) {
		tmp = R * (phi2 - phi1);
	} else {
		tmp = R * (lambda2 - lambda1);
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if (phi1 <= -2.5e-24) or not ((phi1 <= -4.6e-224) or (not (phi1 <= -1.1e-250) and (phi1 <= 5.3e-197))):
		tmp = R * (phi2 - phi1)
	else:
		tmp = R * (lambda2 - lambda1)
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if ((phi1 <= -2.5e-24) || !((phi1 <= -4.6e-224) || (!(phi1 <= -1.1e-250) && (phi1 <= 5.3e-197))))
		tmp = Float64(R * Float64(phi2 - phi1));
	else
		tmp = Float64(R * Float64(lambda2 - lambda1));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if ((phi1 <= -2.5e-24) || ~(((phi1 <= -4.6e-224) || (~((phi1 <= -1.1e-250)) && (phi1 <= 5.3e-197)))))
		tmp = R * (phi2 - phi1);
	else
		tmp = R * (lambda2 - lambda1);
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[Or[LessEqual[phi1, -2.5e-24], N[Not[Or[LessEqual[phi1, -4.6e-224], And[N[Not[LessEqual[phi1, -1.1e-250]], $MachinePrecision], LessEqual[phi1, 5.3e-197]]]], $MachinePrecision]], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], N[(R * N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -2.5 \cdot 10^{-24} \lor \neg \left(\phi_1 \leq -4.6 \cdot 10^{-224} \lor \neg \left(\phi_1 \leq -1.1 \cdot 10^{-250}\right) \land \phi_1 \leq 5.3 \cdot 10^{-197}\right):\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi1 < -2.4999999999999999e-24 or -4.59999999999999975e-224 < phi1 < -1.1e-250 or 5.29999999999999972e-197 < phi1

    1. Initial program 57.0%

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

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

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

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

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

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

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

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

    if -2.4999999999999999e-24 < phi1 < -4.59999999999999975e-224 or -1.1e-250 < phi1 < 5.29999999999999972e-197

    1. Initial program 71.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-def99.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. Taylor expanded in lambda1 around -inf 34.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\lambda_2 \cdot \left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) - R \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1\right)} \]
    8. Step-by-step derivation
      1. *-commutative34.5%

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

        \[\leadsto \left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \lambda_2 - \color{blue}{\left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \lambda_1} \]
      3. distribute-lft-out--34.5%

        \[\leadsto \color{blue}{\left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \left(\lambda_2 - \lambda_1\right)} \]
      4. *-commutative34.5%

        \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot R\right)} \cdot \left(\lambda_2 - \lambda_1\right) \]
    9. Simplified34.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -2.5 \cdot 10^{-24} \lor \neg \left(\phi_1 \leq -4.6 \cdot 10^{-224} \lor \neg \left(\phi_1 \leq -1.1 \cdot 10^{-250}\right) \land \phi_1 \leq 5.3 \cdot 10^{-197}\right):\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\ \end{array} \]

Alternative 13: 31.2% accurate, 24.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.55 \cdot 10^{-17}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -4.4 \cdot 10^{-226} \lor \neg \left(\phi_1 \leq -3 \cdot 10^{-252}\right) \land \phi_1 \leq 1.06 \cdot 10^{-196}:\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi1 -1.55e-17)
   (* R (- phi1))
   (if (or (<= phi1 -4.4e-226)
           (and (not (<= phi1 -3e-252)) (<= phi1 1.06e-196)))
     (* R (- lambda2 lambda1))
     (* R phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -1.55e-17) {
		tmp = R * -phi1;
	} else if ((phi1 <= -4.4e-226) || (!(phi1 <= -3e-252) && (phi1 <= 1.06e-196))) {
		tmp = R * (lambda2 - lambda1);
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: tmp
    if (phi1 <= (-1.55d-17)) then
        tmp = r * -phi1
    else if ((phi1 <= (-4.4d-226)) .or. (.not. (phi1 <= (-3d-252))) .and. (phi1 <= 1.06d-196)) then
        tmp = r * (lambda2 - lambda1)
    else
        tmp = r * phi2
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -1.55e-17) {
		tmp = R * -phi1;
	} else if ((phi1 <= -4.4e-226) || (!(phi1 <= -3e-252) && (phi1 <= 1.06e-196))) {
		tmp = R * (lambda2 - lambda1);
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -1.55e-17:
		tmp = R * -phi1
	elif (phi1 <= -4.4e-226) or (not (phi1 <= -3e-252) and (phi1 <= 1.06e-196)):
		tmp = R * (lambda2 - lambda1)
	else:
		tmp = R * phi2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -1.55e-17)
		tmp = Float64(R * Float64(-phi1));
	elseif ((phi1 <= -4.4e-226) || (!(phi1 <= -3e-252) && (phi1 <= 1.06e-196)))
		tmp = Float64(R * Float64(lambda2 - lambda1));
	else
		tmp = Float64(R * phi2);
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi1 <= -1.55e-17)
		tmp = R * -phi1;
	elseif ((phi1 <= -4.4e-226) || (~((phi1 <= -3e-252)) && (phi1 <= 1.06e-196)))
		tmp = R * (lambda2 - lambda1);
	else
		tmp = R * phi2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -1.55e-17], N[(R * (-phi1)), $MachinePrecision], If[Or[LessEqual[phi1, -4.4e-226], And[N[Not[LessEqual[phi1, -3e-252]], $MachinePrecision], LessEqual[phi1, 1.06e-196]]], N[(R * N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision], N[(R * phi2), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -1.55 \cdot 10^{-17}:\\
\;\;\;\;R \cdot \left(-\phi_1\right)\\

\mathbf{elif}\;\phi_1 \leq -4.4 \cdot 10^{-226} \lor \neg \left(\phi_1 \leq -3 \cdot 10^{-252}\right) \land \phi_1 \leq 1.06 \cdot 10^{-196}:\\
\;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\

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


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

    1. Initial program 52.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-def90.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. Simplified90.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. Taylor expanded in phi1 around -inf 59.0%

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

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

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

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

    if -1.5499999999999999e-17 < phi1 < -4.4e-226 or -2.99999999999999995e-252 < phi1 < 1.05999999999999994e-196

    1. Initial program 70.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-def99.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. Taylor expanded in lambda1 around -inf 34.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \lambda_2 - \color{blue}{\left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \lambda_1} \]
      3. distribute-lft-out--34.9%

        \[\leadsto \color{blue}{\left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \left(\lambda_2 - \lambda_1\right)} \]
      4. *-commutative34.9%

        \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot R\right)} \cdot \left(\lambda_2 - \lambda_1\right) \]
    9. Simplified34.9%

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

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

    if -4.4e-226 < phi1 < -2.99999999999999995e-252 or 1.05999999999999994e-196 < phi1

    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-def97.5%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.55 \cdot 10^{-17}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -4.4 \cdot 10^{-226} \lor \neg \left(\phi_1 \leq -3 \cdot 10^{-252}\right) \land \phi_1 \leq 1.06 \cdot 10^{-196}:\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]

Alternative 14: 26.6% accurate, 65.0× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \lambda_2 - \color{blue}{\left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \lambda_1} \]
      3. distribute-lft-out--23.7%

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

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

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

      \[\leadsto \color{blue}{R} \cdot \left(\lambda_2 - \lambda_1\right) \]
    11. Taylor expanded in lambda2 around inf 13.9%

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

    if 3.4000000000000001e-28 < phi2

    1. Initial program 57.0%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-def93.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. Simplified93.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. Taylor expanded in phi2 around inf 58.7%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 3.4 \cdot 10^{-28}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]

Alternative 15: 14.4% 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 61.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-def96.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. Taylor expanded in lambda1 around -inf 23.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\lambda_2 \cdot \left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) - R \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1\right)} \]
  8. Step-by-step derivation
    1. *-commutative22.0%

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

      \[\leadsto \left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \lambda_2 - \color{blue}{\left(R \cdot \cos \left(0.5 \cdot \phi_2\right)\right) \cdot \lambda_1} \]
    3. distribute-lft-out--22.8%

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

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

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

    \[\leadsto \color{blue}{R} \cdot \left(\lambda_2 - \lambda_1\right) \]
  11. Taylor expanded in lambda2 around inf 11.7%

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

    \[\leadsto R \cdot \lambda_2 \]

Reproduce

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