Equirectangular approximation to distance on a great circle

Percentage Accurate: 58.7% → 99.9%
Time: 20.3s
Alternatives: 16
Speedup: 3.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 16 alternatives:

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

Initial Program: 58.7% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 0.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\color{blue}{\frac{\phi_2}{2}} + \phi_1 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right) \]
    6. 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(\frac{\phi_2}{2}\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}\right)\right), \phi_1 - \phi_2\right) \]
    7. div-inv99.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 \frac{1}{2}\right)} \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right) \]
    8. metadata-eval99.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 \color{blue}{0.5}\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right) \]
    9. div-inv99.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 \frac{1}{2}\right)} \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right) \]
    10. metadata-eval99.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 \color{blue}{0.5}\right) \cdot \sin \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. fma-neg99.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), -\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)}, \phi_1 - \phi_2\right) \]
    3. *-commutative99.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(\phi_1 \cdot 0.5\right), -\color{blue}{\sin \left(\phi_1 \cdot 0.5\right) \cdot \sin \left(\phi_2 \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)}, -\sin \left(\phi_1 \cdot 0.5\right) \cdot \sin \left(\phi_2 \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), -\color{blue}{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}\right), \phi_1 - \phi_2\right) \]
    6. *-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), -\sin \left(\phi_2 \cdot 0.5\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), -\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)}, \phi_1 - \phi_2\right) \]
  11. Step-by-step derivation
    1. distribute-rgt-neg-in99.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), \color{blue}{\sin \left(\phi_2 \cdot 0.5\right) \cdot \left(-\sin \left(0.5 \cdot \phi_1\right)\right)}\right), \phi_1 - \phi_2\right) \]
  12. Simplified99.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), \sin \left(\phi_2 \cdot 0.5\right) \cdot \left(-\sin \left(0.5 \cdot \phi_1\right)\right)\right)}, \phi_1 - \phi_2\right) \]
  13. Final simplification99.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), \sin \left(0.5 \cdot \phi_1\right) \cdot \left(-\sin \left(\phi_2 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right) \]
  14. Add Preprocessing

Alternative 2: 87.7% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq 5 \cdot 10^{-149}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot \left(\cos \left(\phi_2 \cdot 0.5\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), \phi_1 - \phi_2\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if lambda2 < 4.99999999999999968e-149

    1. Initial program 59.4%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\color{blue}{\frac{\phi_2}{2}} + \phi_1 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right) \]
      6. 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(\frac{\phi_2}{2}\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}\right)\right), \phi_1 - \phi_2\right) \]
      7. div-inv99.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 \frac{1}{2}\right)} \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right) \]
      8. metadata-eval99.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 \color{blue}{0.5}\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right) \]
      9. div-inv99.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 \frac{1}{2}\right)} \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right) \]
      10. metadata-eval99.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 \color{blue}{0.5}\right) \cdot \sin \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 inf 80.4%

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

    if 4.99999999999999968e-149 < lambda2

    1. Initial program 69.8%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define95.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
  3. Recombined 2 regimes into one program.
  4. Final simplification86.7%

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

Alternative 3: 99.9% accurate, 0.6× speedup?

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

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

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

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

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\color{blue}{\frac{\phi_2}{2}} + \phi_1 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right) \]
    6. 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(\frac{\phi_2}{2}\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}\right)\right), \phi_1 - \phi_2\right) \]
    7. div-inv99.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 \frac{1}{2}\right)} \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right) \]
    8. metadata-eval99.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 \color{blue}{0.5}\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right) \]
    9. div-inv99.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 \frac{1}{2}\right)} \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right) \]
    10. metadata-eval99.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 \color{blue}{0.5}\right) \cdot \sin \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. sub-neg99.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) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right)}, \phi_1 - \phi_2\right) \]
    3. *-commutative99.8%

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

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

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

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

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

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)}, \phi_1 - \phi_2\right) \]
  13. Final simplification99.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(0.5 \cdot \phi_1\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right), \phi_1 - \phi_2\right) \]
  14. Add Preprocessing

Alternative 4: 92.3% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 64.7%

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

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

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

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

    if 3.7999999999999999e-85 < phi2

    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-define93.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. Simplified93.9%

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

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

Alternative 5: 90.6% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 67.1%

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

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

    if 3.7999999999999999e78 < phi2

    1. Initial program 49.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-define93.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. Simplified93.5%

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

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

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

Alternative 6: 79.9% accurate, 1.5× speedup?

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

    1. Initial program 59.0%

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

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

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

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

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

    if 2e-116 < lambda2

    1. Initial program 71.1%

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

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

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

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

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

Alternative 7: 95.7% accurate, 1.5× speedup?

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

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

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

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

Alternative 8: 70.2% accurate, 3.0× speedup?

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

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

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


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

    1. Initial program 66.7%

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

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

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

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

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

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

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

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

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

    if 4.9999999999999998e34 < phi2

    1. Initial program 54.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-define92.1%

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

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

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

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

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

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

Alternative 9: 84.8% 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 63.7%

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

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

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

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

Alternative 10: 33.1% accurate, 13.7× speedup?

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

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

\mathbf{elif}\;\phi_2 \leq 2 \cdot 10^{-45}:\\
\;\;\;\;\lambda_2 \cdot \left(R - \frac{R \cdot \lambda_1}{\lambda_2}\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if phi2 < -3.9999999999999999e-171

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

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

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

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

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

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

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

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

    if -3.9999999999999999e-171 < phi2 < 1.99999999999999997e-45

    1. Initial program 68.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-define99.9%

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

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

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

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

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

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

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

        \[\leadsto \lambda_2 \cdot \left(R \cdot \cos \left(0.5 \cdot \phi_2\right) - \color{blue}{R \cdot \frac{\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)}{\lambda_2}}\right) \]
      5. associate-/l*30.6%

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

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

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

    if 1.99999999999999997e-45 < phi2 < 1.6499999999999999e40

    1. Initial program 79.6%

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

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

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

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

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

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

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

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

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

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

    if 1.6499999999999999e40 < phi2

    1. Initial program 53.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-define91.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 inf 72.8%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -4 \cdot 10^{-171}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_2 \leq 2 \cdot 10^{-45}:\\ \;\;\;\;\lambda_2 \cdot \left(R - \frac{R \cdot \lambda_1}{\lambda_2}\right)\\ \mathbf{elif}\;\phi_2 \leq 1.65 \cdot 10^{+40}:\\ \;\;\;\;\phi_1 \cdot \left(\frac{R \cdot \phi_2}{\phi_1} - R\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 \cdot \left(1 - \frac{\phi_1}{\phi_2}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 32.9% accurate, 17.3× speedup?

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

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

\mathbf{elif}\;\phi_2 \leq 2 \cdot 10^{-45}:\\
\;\;\;\;\lambda_2 \cdot \left(R - \frac{R \cdot \lambda_1}{\lambda_2}\right)\\

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


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

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

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

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

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

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

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

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

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

    if -2.39999999999999987e-171 < phi2 < 1.99999999999999997e-45

    1. Initial program 68.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-define99.9%

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

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

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

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

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

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

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

        \[\leadsto \lambda_2 \cdot \left(R \cdot \cos \left(0.5 \cdot \phi_2\right) - \color{blue}{R \cdot \frac{\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)}{\lambda_2}}\right) \]
      5. associate-/l*30.6%

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

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

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

    if 1.99999999999999997e-45 < phi2

    1. Initial program 58.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-define93.2%

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

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

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

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

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

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

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

Alternative 12: 32.4% accurate, 17.3× speedup?

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

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

\mathbf{elif}\;\phi_2 \leq 1.15 \cdot 10^{-46}:\\
\;\;\;\;\lambda_2 \cdot \left(R - R \cdot \frac{\lambda_1}{\lambda_2}\right)\\

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


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

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

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

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

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

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

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

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

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

    if -1.5e-171 < phi2 < 1.15e-46

    1. Initial program 68.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-define99.9%

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

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

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

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

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

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

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

        \[\leadsto \lambda_2 \cdot \left(R \cdot \cos \left(0.5 \cdot \phi_2\right) - \color{blue}{R \cdot \frac{\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)}{\lambda_2}}\right) \]
      5. associate-/l*30.6%

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

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

      \[\leadsto \color{blue}{\lambda_2 \cdot \left(R - \frac{R \cdot \lambda_1}{\lambda_2}\right)} \]
    10. Step-by-step derivation
      1. associate-/l*30.6%

        \[\leadsto \lambda_2 \cdot \left(R - \color{blue}{R \cdot \frac{\lambda_1}{\lambda_2}}\right) \]
    11. Simplified30.6%

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

    if 1.15e-46 < phi2

    1. Initial program 58.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-define93.2%

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

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

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

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

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

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

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

Alternative 13: 27.9% accurate, 23.4× speedup?

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

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

\mathbf{elif}\;\phi_2 \leq 3.25 \cdot 10^{-40}:\\
\;\;\;\;R \cdot \left(-\lambda_1\right)\\

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


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

    1. Initial program 64.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-define94.8%

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

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

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

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

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

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

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

    if 3.6999999999999998e-301 < phi2 < 3.25e-40

    1. Initial program 68.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.25e-40 < phi2

    1. Initial program 57.9%

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

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

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

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

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

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

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

Alternative 14: 32.2% accurate, 23.5× speedup?

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

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

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


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

    1. Initial program 51.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(-R\right)} \cdot \lambda_1 \]
    11. Simplified55.9%

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

    if -2.9499999999999999e138 < lambda1

    1. Initial program 65.4%

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

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

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

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

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

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

Alternative 15: 28.1% accurate, 36.5× speedup?

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

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

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


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

    1. Initial program 66.7%

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

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

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

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

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

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

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

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

    if 9.2e17 < phi2

    1. Initial program 54.9%

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

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

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

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

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

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

Alternative 16: 17.7% 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 63.7%

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

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

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

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

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

Reproduce

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