Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.4% → 99.9%
Time: 25.5s
Alternatives: 14
Speedup: 3.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 14 alternatives:

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

Initial Program: 59.4% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(0.5 \cdot \phi_1\right)\\ t_1 := \sin \left(0.5 \cdot \phi_2\right)\\ t_2 := t\_0 \cdot t\_1\\ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - t\_2\right) + \mathsf{fma}\left(-t\_1, t\_0, t\_2\right)\right), \phi_1 - \phi_2\right) \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (* 0.5 phi1))) (t_1 (sin (* 0.5 phi2))) (t_2 (* t_0 t_1)))
   (*
    R
    (hypot
     (*
      (- lambda1 lambda2)
      (+
       (- (* (cos (* 0.5 phi1)) (cos (* 0.5 phi2))) t_2)
       (fma (- t_1) t_0 t_2)))
     (- phi1 phi2)))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin((0.5 * phi1));
	double t_1 = sin((0.5 * phi2));
	double t_2 = t_0 * t_1;
	return R * hypot(((lambda1 - lambda2) * (((cos((0.5 * phi1)) * cos((0.5 * phi2))) - t_2) + fma(-t_1, t_0, t_2))), (phi1 - phi2));
}
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = sin(Float64(0.5 * phi1))
	t_1 = sin(Float64(0.5 * phi2))
	t_2 = Float64(t_0 * t_1)
	return Float64(R * hypot(Float64(Float64(lambda1 - lambda2) * Float64(Float64(Float64(cos(Float64(0.5 * phi1)) * cos(Float64(0.5 * phi2))) - t_2) + fma(Float64(-t_1), t_0, t_2))), Float64(phi1 - phi2)))
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * t$95$1), $MachinePrecision]}, N[(R * N[Sqrt[N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(N[(N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - t$95$2), $MachinePrecision] + N[((-t$95$1) * t$95$0 + t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \phi_1\right)\\
t_1 := \sin \left(0.5 \cdot \phi_2\right)\\
t_2 := t\_0 \cdot t\_1\\
R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - t\_2\right) + \mathsf{fma}\left(-t\_1, t\_0, t\_2\right)\right), \phi_1 - \phi_2\right)
\end{array}
\end{array}
Derivation
  1. Initial program 58.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-def94.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. Simplified94.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)}, \phi_1 - \phi_2\right) \]
    2. *-un-lft-identity99.8%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \color{blue}{1 \cdot \left(\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. prod-diff99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.9% accurate, 0.5× speedup?

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

\\
R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \sin \left(0.5 \cdot \phi_1\right) \cdot \left(-\sin \left(0.5 \cdot \phi_2\right)\right)\right), \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 58.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-def94.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. Simplified94.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)}, \phi_1 - \phi_2\right) \]
    2. cancel-sign-sub-inv99.8%

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

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

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

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

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

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

Alternative 3: 87.5% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\\
\mathbf{if}\;\lambda_1 \leq -6 \cdot 10^{-58}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) + t\_0 \cdot 2\right), \phi_1 - \phi_2\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda1 < -6.00000000000000015e-58

    1. Initial program 53.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-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. Add Preprocessing
    5. Step-by-step derivation
      1. log1p-expm1-u94.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \color{blue}{1 \cdot \left(\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. prod-diff99.8%

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

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

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

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

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

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\left(\color{blue}{\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \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) + \mathsf{fma}\left(-\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right), 1, \left(\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) \cdot 1\right)\right), \phi_1 - \phi_2\right) \]
      5. *-commutative99.7%

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right) + \mathsf{fma}\left(-\sin \left(0.5 \cdot \phi_2\right), \sin \left(0.5 \cdot \phi_1\right), \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)}, \phi_1 - \phi_2\right) \]
    13. Step-by-step derivation
      1. distribute-lft-in99.8%

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(0.5 \cdot \phi_2 + 0.5 \cdot \phi_1\right)} + \left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(-\sin \left(0.5 \cdot \phi_2\right), \sin \left(0.5 \cdot \phi_1\right), \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right), \phi_1 - \phi_2\right) \]
      5. distribute-lft-in94.6%

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) + \left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(\sin \left(0.5 \cdot \phi_2\right), \sin \left(0.5 \cdot \phi_1\right), \sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)}, \phi_1 - \phi_2\right) \]
    15. Step-by-step derivation
      1. distribute-lft-out94.6%

        \[\leadsto R \cdot \mathsf{hypot}\left(\color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) + \mathsf{fma}\left(\sin \left(0.5 \cdot \phi_2\right), \sin \left(0.5 \cdot \phi_1\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) \]
      2. fma-def94.6%

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) + \color{blue}{\left(\sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\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) \]
      3. count-294.6%

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

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

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

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

    if -6.00000000000000015e-58 < lambda1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 81.6% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -2.85 \cdot 10^{-98}:\\ \;\;\;\;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 -2.85e-98)
   (* 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 <= -2.85e-98) {
		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 <= -2.85e-98) {
		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 <= -2.85e-98:
		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 <= -2.85e-98)
		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 <= -2.85e-98)
		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, -2.85e-98], 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 -2.85 \cdot 10^{-98}:\\
\;\;\;\;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 < -2.8499999999999999e-98

    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-def91.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. Simplified91.8%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi2 around 0 88.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 -2.8499999999999999e-98 < phi1

    1. Initial program 61.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-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. Add Preprocessing
    5. Taylor expanded in phi1 around 0 51.5%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -2.85 \cdot 10^{-98}:\\ \;\;\;\;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} \]
  5. Add Preprocessing

Alternative 5: 78.8% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 5.5 \cdot 10^{-190}:\\
\;\;\;\;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(\lambda_1 - \lambda_2, \phi_1 - \phi_2\right)\\


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

    1. Initial program 59.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-def97.9%

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

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

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

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

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

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

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

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

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

      \[\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.50000000000000048e-190 < phi2

    1. Initial program 56.5%

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

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

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi2 around 0 82.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) \]
    6. Taylor expanded in phi1 around 0 79.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 5.5 \cdot 10^{-190}:\\ \;\;\;\;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(\lambda_1 - \lambda_2, \phi_1 - \phi_2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 78.1% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.9 \cdot 10^{-22}:\\ \;\;\;\;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 -1.9e-22)
   (* 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 <= -1.9e-22) {
		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 <= -1.9e-22) {
		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 <= -1.9e-22:
		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 <= -1.9e-22)
		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 <= -1.9e-22)
		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, -1.9e-22], 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 -1.9 \cdot 10^{-22}:\\
\;\;\;\;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 < -1.90000000000000012e-22

    1. Initial program 45.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-def88.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. Simplified88.8%

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi2 around 0 45.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}}} \]
    6. Step-by-step derivation
      1. +-commutative45.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}}} \]
      2. unpow245.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}} \]
      3. unpow245.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}} \]
      4. unpow245.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)}} \]
      5. unswap-sqr45.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)}} \]
      6. hypot-def79.9%

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \]
    7. Simplified79.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 -1.90000000000000012e-22 < phi1

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -1.9 \cdot 10^{-22}:\\ \;\;\;\;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} \]
  5. Add Preprocessing

Alternative 7: 83.0% accurate, 1.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\left|\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right) \cdot \left(R \cdot \lambda_2\right)\right|\\


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

    1. Initial program 60.8%

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

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

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

    if 6.4000000000000003e236 < lambda2

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{{\left(\left(\cos \color{blue}{\left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right)} \cdot \lambda_2\right) \cdot R\right)}^{2}} \]
      7. associate-*l*24.6%

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

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

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

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

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

        \[\leadsto \left|\cos \left(0.5 \cdot \color{blue}{\left(\phi_2 + \phi_1\right)}\right) \cdot \left(\lambda_2 \cdot R\right)\right| \]
      5. remove-double-neg41.2%

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

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

        \[\leadsto \left|\cos \left(0.5 \cdot \color{blue}{\left(\phi_2 - -1 \cdot \phi_1\right)}\right) \cdot \left(\lambda_2 \cdot R\right)\right| \]
      8. cancel-sign-sub-inv41.2%

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

        \[\leadsto \left|\cos \left(0.5 \cdot \left(\phi_2 + \color{blue}{1} \cdot \phi_1\right)\right) \cdot \left(\lambda_2 \cdot R\right)\right| \]
      10. *-lft-identity41.2%

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

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

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

Alternative 8: 95.5% 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 58.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-def94.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. Simplified94.9%

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

    \[\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) \]
  6. Add Preprocessing

Alternative 9: 69.9% accurate, 3.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -4 \cdot 10^{+77}:\\
\;\;\;\;R \cdot \phi_2 - R \cdot \phi_1\\

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


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

    1. Initial program 34.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-def87.8%

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

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

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

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

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

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

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

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

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

    if -3.99999999999999993e77 < phi1

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

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

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

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

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

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

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

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

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

Alternative 10: 84.7% accurate, 3.0× speedup?

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

\\
R \cdot \mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 58.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-def94.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. Simplified94.9%

    \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in phi2 around 0 88.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) \]
  6. Taylor expanded in phi1 around 0 82.6%

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

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

Alternative 11: 28.3% accurate, 13.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -2200000000:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -2.3 \cdot 10^{-22} \lor \neg \left(\phi_1 \leq -5.4 \cdot 10^{-55}\right) \land \phi_1 \leq -4.3 \cdot 10^{-99}:\\ \;\;\;\;\lambda_1 \cdot \left(-R\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi1 -2200000000.0)
   (* R (- phi1))
   (if (or (<= phi1 -2.3e-22)
           (and (not (<= phi1 -5.4e-55)) (<= phi1 -4.3e-99)))
     (* lambda1 (- R))
     (* R phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -2200000000.0) {
		tmp = R * -phi1;
	} else if ((phi1 <= -2.3e-22) || (!(phi1 <= -5.4e-55) && (phi1 <= -4.3e-99))) {
		tmp = lambda1 * -R;
	} 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 <= (-2200000000.0d0)) then
        tmp = r * -phi1
    else if ((phi1 <= (-2.3d-22)) .or. (.not. (phi1 <= (-5.4d-55))) .and. (phi1 <= (-4.3d-99))) then
        tmp = lambda1 * -r
    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 <= -2200000000.0) {
		tmp = R * -phi1;
	} else if ((phi1 <= -2.3e-22) || (!(phi1 <= -5.4e-55) && (phi1 <= -4.3e-99))) {
		tmp = lambda1 * -R;
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -2200000000.0:
		tmp = R * -phi1
	elif (phi1 <= -2.3e-22) or (not (phi1 <= -5.4e-55) and (phi1 <= -4.3e-99)):
		tmp = lambda1 * -R
	else:
		tmp = R * phi2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -2200000000.0)
		tmp = Float64(R * Float64(-phi1));
	elseif ((phi1 <= -2.3e-22) || (!(phi1 <= -5.4e-55) && (phi1 <= -4.3e-99)))
		tmp = Float64(lambda1 * Float64(-R));
	else
		tmp = Float64(R * phi2);
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi1 <= -2200000000.0)
		tmp = R * -phi1;
	elseif ((phi1 <= -2.3e-22) || (~((phi1 <= -5.4e-55)) && (phi1 <= -4.3e-99)))
		tmp = lambda1 * -R;
	else
		tmp = R * phi2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -2200000000.0], N[(R * (-phi1)), $MachinePrecision], If[Or[LessEqual[phi1, -2.3e-22], And[N[Not[LessEqual[phi1, -5.4e-55]], $MachinePrecision], LessEqual[phi1, -4.3e-99]]], N[(lambda1 * (-R)), $MachinePrecision], N[(R * phi2), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;\phi_1 \leq -2.3 \cdot 10^{-22} \lor \neg \left(\phi_1 \leq -5.4 \cdot 10^{-55}\right) \land \phi_1 \leq -4.3 \cdot 10^{-99}:\\
\;\;\;\;\lambda_1 \cdot \left(-R\right)\\

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


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

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

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

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

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

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

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

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

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

    if -2.2e9 < phi1 < -2.2999999999999998e-22 or -5.40000000000000008e-55 < phi1 < -4.2999999999999999e-99

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

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

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

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

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

        \[\leadsto \color{blue}{-R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
      2. *-commutative17.8%

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

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

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

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

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

    if -2.2999999999999998e-22 < phi1 < -5.40000000000000008e-55 or -4.2999999999999999e-99 < phi1

    1. Initial program 61.4%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -2200000000:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -2.3 \cdot 10^{-22} \lor \neg \left(\phi_1 \leq -5.4 \cdot 10^{-55}\right) \land \phi_1 \leq -4.3 \cdot 10^{-99}:\\ \;\;\;\;\lambda_1 \cdot \left(-R\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 33.6% accurate, 27.4× speedup?

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

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

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


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

    1. Initial program 49.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-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. Add Preprocessing
    5. Taylor expanded in phi2 around 0 88.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) \]
    6. Taylor expanded in lambda1 around -inf 57.2%

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

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

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

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

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

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

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

    if -3.50000000000000018e162 < lambda1

    1. Initial program 59.5%

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

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

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

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

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

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

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

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

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

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

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

Alternative 13: 24.3% accurate, 36.5× speedup?

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

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

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


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

    1. Initial program 51.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-def93.7%

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

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi2 around 0 87.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) \]
    6. Taylor expanded in lambda1 around -inf 46.0%

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

        \[\leadsto \color{blue}{-R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
      2. *-commutative46.0%

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

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

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

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

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

    if -1.74999999999999989e68 < lambda1

    1. Initial program 59.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-def95.2%

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

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

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

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

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

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

Alternative 14: 17.6% accurate, 109.7× speedup?

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

\\
R \cdot \phi_2
\end{array}
Derivation
  1. Initial program 58.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-def94.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. Simplified94.9%

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

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

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

    \[\leadsto \color{blue}{\phi_2 \cdot R} \]
  8. Final simplification14.5%

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

Reproduce

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