Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.6% → 99.4%
Time: 20.2s
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: 59.6% 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.4% accurate, 0.4× speedup?

\[\begin{array}{l} R\_m = \left|R\right| \\ R\_s = \mathsf{copysign}\left(1, R\right) \\ R\_s \cdot {\left(\sqrt{R\_m \cdot \mathsf{hypot}\left(\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right) + \left(1 - e^{\mathsf{log1p}\left(\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)}\right)\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)}\right)}^{2} \end{array} \]
R\_m = (fabs.f64 R)
R\_s = (copysign.f64 #s(literal 1 binary64) R)
(FPCore (R_s R_m lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R_s
  (pow
   (sqrt
    (*
     R_m
     (hypot
      (*
       (+
        (* (cos (* 0.5 phi1)) (cos (* phi2 0.5)))
        (- 1.0 (exp (log1p (* (sin (* phi2 0.5)) (sin (* 0.5 phi1)))))))
       (- lambda1 lambda2))
      (- phi1 phi2))))
   2.0)))
R\_m = fabs(R);
R\_s = copysign(1.0, R);
double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	return R_s * pow(sqrt((R_m * hypot((((cos((0.5 * phi1)) * cos((phi2 * 0.5))) + (1.0 - exp(log1p((sin((phi2 * 0.5)) * sin((0.5 * phi1))))))) * (lambda1 - lambda2)), (phi1 - phi2)))), 2.0);
}
R\_m = Math.abs(R);
R\_s = Math.copySign(1.0, R);
public static double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	return R_s * Math.pow(Math.sqrt((R_m * Math.hypot((((Math.cos((0.5 * phi1)) * Math.cos((phi2 * 0.5))) + (1.0 - Math.exp(Math.log1p((Math.sin((phi2 * 0.5)) * Math.sin((0.5 * phi1))))))) * (lambda1 - lambda2)), (phi1 - phi2)))), 2.0);
}
R\_m = math.fabs(R)
R\_s = math.copysign(1.0, R)
def code(R_s, R_m, lambda1, lambda2, phi1, phi2):
	return R_s * math.pow(math.sqrt((R_m * math.hypot((((math.cos((0.5 * phi1)) * math.cos((phi2 * 0.5))) + (1.0 - math.exp(math.log1p((math.sin((phi2 * 0.5)) * math.sin((0.5 * phi1))))))) * (lambda1 - lambda2)), (phi1 - phi2)))), 2.0)
R\_m = abs(R)
R\_s = copysign(1.0, R)
function code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	return Float64(R_s * (sqrt(Float64(R_m * hypot(Float64(Float64(Float64(cos(Float64(0.5 * phi1)) * cos(Float64(phi2 * 0.5))) + Float64(1.0 - exp(log1p(Float64(sin(Float64(phi2 * 0.5)) * sin(Float64(0.5 * phi1))))))) * Float64(lambda1 - lambda2)), Float64(phi1 - phi2)))) ^ 2.0))
end
R\_m = N[Abs[R], $MachinePrecision]
R\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[R]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[R$95$s_, R$95$m_, lambda1_, lambda2_, phi1_, phi2_] := N[(R$95$s * N[Power[N[Sqrt[N[(R$95$m * N[Sqrt[N[(N[(N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(1.0 - N[Exp[N[Log[1 + N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
R\_m = \left|R\right|
\\
R\_s = \mathsf{copysign}\left(1, R\right)

\\
R\_s \cdot {\left(\sqrt{R\_m \cdot \mathsf{hypot}\left(\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right) + \left(1 - e^{\mathsf{log1p}\left(\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)}\right)\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)}\right)}^{2}
\end{array}
Derivation
  1. Initial program 63.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-define96.7%

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

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

      \[\leadsto \color{blue}{\sqrt{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)} \cdot \sqrt{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)}} \]
    2. pow245.7%

      \[\leadsto \color{blue}{{\left(\sqrt{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)}\right)}^{2}} \]
    3. *-commutative45.7%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto {\left(\sqrt{R \cdot \mathsf{hypot}\left(\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \color{blue}{\left(\phi_2 \cdot 0.5\right)} \cdot \sin \left(\phi_1 \cdot 0.5\right)\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)}\right)}^{2} \]
  8. Applied egg-rr47.0%

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

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

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

      \[\leadsto {\left(\sqrt{R \cdot \mathsf{hypot}\left(\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \left(e^{\mathsf{log1p}\left(\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \color{blue}{\left(0.5 \cdot \phi_1\right)}\right)} - 1\right)\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)}\right)}^{2} \]
  10. Applied egg-rr47.0%

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

    \[\leadsto {\left(\sqrt{R \cdot \mathsf{hypot}\left(\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right) + \left(1 - e^{\mathsf{log1p}\left(\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)}\right)\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)}\right)}^{2} \]
  12. Add Preprocessing

Alternative 2: 99.4% accurate, 0.5× speedup?

\[\begin{array}{l} R\_m = \left|R\right| \\ R\_s = \mathsf{copysign}\left(1, R\right) \\ R\_s \cdot {\left(\sqrt{R\_m \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) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right), \phi_1 - \phi_2\right)}\right)}^{2} \end{array} \]
R\_m = (fabs.f64 R)
R\_s = (copysign.f64 #s(literal 1 binary64) R)
(FPCore (R_s R_m lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R_s
  (pow
   (sqrt
    (*
     R_m
     (hypot
      (*
       (- lambda1 lambda2)
       (-
        (* (cos (* 0.5 phi1)) (cos (* phi2 0.5)))
        (* (sin (* phi2 0.5)) (sin (* 0.5 phi1)))))
      (- phi1 phi2))))
   2.0)))
R\_m = fabs(R);
R\_s = copysign(1.0, R);
double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	return R_s * pow(sqrt((R_m * hypot(((lambda1 - lambda2) * ((cos((0.5 * phi1)) * cos((phi2 * 0.5))) - (sin((phi2 * 0.5)) * sin((0.5 * phi1))))), (phi1 - phi2)))), 2.0);
}
R\_m = Math.abs(R);
R\_s = Math.copySign(1.0, R);
public static double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	return R_s * Math.pow(Math.sqrt((R_m * Math.hypot(((lambda1 - lambda2) * ((Math.cos((0.5 * phi1)) * Math.cos((phi2 * 0.5))) - (Math.sin((phi2 * 0.5)) * Math.sin((0.5 * phi1))))), (phi1 - phi2)))), 2.0);
}
R\_m = math.fabs(R)
R\_s = math.copysign(1.0, R)
def code(R_s, R_m, lambda1, lambda2, phi1, phi2):
	return R_s * math.pow(math.sqrt((R_m * math.hypot(((lambda1 - lambda2) * ((math.cos((0.5 * phi1)) * math.cos((phi2 * 0.5))) - (math.sin((phi2 * 0.5)) * math.sin((0.5 * phi1))))), (phi1 - phi2)))), 2.0)
R\_m = abs(R)
R\_s = copysign(1.0, R)
function code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	return Float64(R_s * (sqrt(Float64(R_m * hypot(Float64(Float64(lambda1 - lambda2) * Float64(Float64(cos(Float64(0.5 * phi1)) * cos(Float64(phi2 * 0.5))) - Float64(sin(Float64(phi2 * 0.5)) * sin(Float64(0.5 * phi1))))), Float64(phi1 - phi2)))) ^ 2.0))
end
R\_m = abs(R);
R\_s = sign(R) * abs(1.0);
function tmp = code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = R_s * (sqrt((R_m * hypot(((lambda1 - lambda2) * ((cos((0.5 * phi1)) * cos((phi2 * 0.5))) - (sin((phi2 * 0.5)) * sin((0.5 * phi1))))), (phi1 - phi2)))) ^ 2.0);
end
R\_m = N[Abs[R], $MachinePrecision]
R\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[R]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[R$95$s_, R$95$m_, lambda1_, lambda2_, phi1_, phi2_] := N[(R$95$s * N[Power[N[Sqrt[N[(R$95$m * N[Sqrt[N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 * 0.5), $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]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
R\_m = \left|R\right|
\\
R\_s = \mathsf{copysign}\left(1, R\right)

\\
R\_s \cdot {\left(\sqrt{R\_m \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) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right), \phi_1 - \phi_2\right)}\right)}^{2}
\end{array}
Derivation
  1. Initial program 63.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-define96.7%

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

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

      \[\leadsto \color{blue}{\sqrt{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)} \cdot \sqrt{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)}} \]
    2. pow245.7%

      \[\leadsto \color{blue}{{\left(\sqrt{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)}\right)}^{2}} \]
    3. *-commutative45.7%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto {\left(\sqrt{R \cdot \mathsf{hypot}\left(\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \color{blue}{\left(\phi_2 \cdot 0.5\right)} \cdot \sin \left(\phi_1 \cdot 0.5\right)\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)}\right)}^{2} \]
  8. Applied egg-rr47.0%

    \[\leadsto {\left(\sqrt{R \cdot \mathsf{hypot}\left(\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)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)}\right)}^{2} \]
  9. Final simplification47.0%

    \[\leadsto {\left(\sqrt{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) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right), \phi_1 - \phi_2\right)}\right)}^{2} \]
  10. Add Preprocessing

Alternative 3: 93.1% accurate, 1.5× speedup?

\[\begin{array}{l} R\_m = \left|R\right| \\ R\_s = \mathsf{copysign}\left(1, R\right) \\ R\_s \cdot \begin{array}{l} \mathbf{if}\;\phi_2 \leq 5.2 \cdot 10^{-33}:\\ \;\;\;\;R\_m \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R\_m \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\phi_2 \cdot 0.5\right), \phi_1 - \phi_2\right)\\ \end{array} \end{array} \]
R\_m = (fabs.f64 R)
R\_s = (copysign.f64 #s(literal 1 binary64) R)
(FPCore (R_s R_m lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R_s
  (if (<= phi2 5.2e-33)
    (* R_m (hypot (* (cos (* 0.5 phi1)) (- lambda1 lambda2)) (- phi1 phi2)))
    (* R_m (hypot (* (- lambda1 lambda2) (cos (* phi2 0.5))) (- phi1 phi2))))))
R\_m = fabs(R);
R\_s = copysign(1.0, R);
double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 5.2e-33) {
		tmp = R_m * hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), (phi1 - phi2));
	} else {
		tmp = R_m * hypot(((lambda1 - lambda2) * cos((phi2 * 0.5))), (phi1 - phi2));
	}
	return R_s * tmp;
}
R\_m = Math.abs(R);
R\_s = Math.copySign(1.0, R);
public static double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 5.2e-33) {
		tmp = R_m * Math.hypot((Math.cos((0.5 * phi1)) * (lambda1 - lambda2)), (phi1 - phi2));
	} else {
		tmp = R_m * Math.hypot(((lambda1 - lambda2) * Math.cos((phi2 * 0.5))), (phi1 - phi2));
	}
	return R_s * tmp;
}
R\_m = math.fabs(R)
R\_s = math.copysign(1.0, R)
def code(R_s, R_m, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 5.2e-33:
		tmp = R_m * math.hypot((math.cos((0.5 * phi1)) * (lambda1 - lambda2)), (phi1 - phi2))
	else:
		tmp = R_m * math.hypot(((lambda1 - lambda2) * math.cos((phi2 * 0.5))), (phi1 - phi2))
	return R_s * tmp
R\_m = abs(R)
R\_s = copysign(1.0, R)
function code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 5.2e-33)
		tmp = Float64(R_m * hypot(Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2)), Float64(phi1 - phi2)));
	else
		tmp = Float64(R_m * hypot(Float64(Float64(lambda1 - lambda2) * cos(Float64(phi2 * 0.5))), Float64(phi1 - phi2)));
	end
	return Float64(R_s * tmp)
end
R\_m = abs(R);
R\_s = sign(R) * abs(1.0);
function tmp_2 = code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi2 <= 5.2e-33)
		tmp = R_m * hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), (phi1 - phi2));
	else
		tmp = R_m * hypot(((lambda1 - lambda2) * cos((phi2 * 0.5))), (phi1 - phi2));
	end
	tmp_2 = R_s * tmp;
end
R\_m = N[Abs[R], $MachinePrecision]
R\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[R]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[R$95$s_, R$95$m_, lambda1_, lambda2_, phi1_, phi2_] := N[(R$95$s * If[LessEqual[phi2, 5.2e-33], N[(R$95$m * N[Sqrt[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[(R$95$m * N[Sqrt[N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
R\_m = \left|R\right|
\\
R\_s = \mathsf{copysign}\left(1, R\right)

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

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


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

    1. Initial program 65.2%

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

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

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

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

    if 5.19999999999999988e-33 < 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.0%

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

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

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

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

Alternative 4: 91.0% accurate, 1.5× speedup?

\[\begin{array}{l} R\_m = \left|R\right| \\ R\_s = \mathsf{copysign}\left(1, R\right) \\ R\_s \cdot \begin{array}{l} \mathbf{if}\;\phi_2 \leq 61000000:\\ \;\;\;\;R\_m \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R\_m \cdot \mathsf{hypot}\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \left(-\lambda_2\right), \phi_1 - \phi_2\right)\\ \end{array} \end{array} \]
R\_m = (fabs.f64 R)
R\_s = (copysign.f64 #s(literal 1 binary64) R)
(FPCore (R_s R_m lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R_s
  (if (<= phi2 61000000.0)
    (* R_m (hypot (* (cos (* 0.5 phi1)) (- lambda1 lambda2)) (- phi1 phi2)))
    (* R_m (hypot (* (cos (* phi2 0.5)) (- lambda2)) (- phi1 phi2))))))
R\_m = fabs(R);
R\_s = copysign(1.0, R);
double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 61000000.0) {
		tmp = R_m * hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), (phi1 - phi2));
	} else {
		tmp = R_m * hypot((cos((phi2 * 0.5)) * -lambda2), (phi1 - phi2));
	}
	return R_s * tmp;
}
R\_m = Math.abs(R);
R\_s = Math.copySign(1.0, R);
public static double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 61000000.0) {
		tmp = R_m * Math.hypot((Math.cos((0.5 * phi1)) * (lambda1 - lambda2)), (phi1 - phi2));
	} else {
		tmp = R_m * Math.hypot((Math.cos((phi2 * 0.5)) * -lambda2), (phi1 - phi2));
	}
	return R_s * tmp;
}
R\_m = math.fabs(R)
R\_s = math.copysign(1.0, R)
def code(R_s, R_m, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 61000000.0:
		tmp = R_m * math.hypot((math.cos((0.5 * phi1)) * (lambda1 - lambda2)), (phi1 - phi2))
	else:
		tmp = R_m * math.hypot((math.cos((phi2 * 0.5)) * -lambda2), (phi1 - phi2))
	return R_s * tmp
R\_m = abs(R)
R\_s = copysign(1.0, R)
function code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 61000000.0)
		tmp = Float64(R_m * hypot(Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2)), Float64(phi1 - phi2)));
	else
		tmp = Float64(R_m * hypot(Float64(cos(Float64(phi2 * 0.5)) * Float64(-lambda2)), Float64(phi1 - phi2)));
	end
	return Float64(R_s * tmp)
end
R\_m = abs(R);
R\_s = sign(R) * abs(1.0);
function tmp_2 = code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi2 <= 61000000.0)
		tmp = R_m * hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), (phi1 - phi2));
	else
		tmp = R_m * hypot((cos((phi2 * 0.5)) * -lambda2), (phi1 - phi2));
	end
	tmp_2 = R_s * tmp;
end
R\_m = N[Abs[R], $MachinePrecision]
R\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[R]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[R$95$s_, R$95$m_, lambda1_, lambda2_, phi1_, phi2_] := N[(R$95$s * If[LessEqual[phi2, 61000000.0], N[(R$95$m * N[Sqrt[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[(R$95$m * N[Sqrt[N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * (-lambda2)), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
R\_m = \left|R\right|
\\
R\_s = \mathsf{copysign}\left(1, R\right)

\\
R\_s \cdot \begin{array}{l}
\mathbf{if}\;\phi_2 \leq 61000000:\\
\;\;\;\;R\_m \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\\

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


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

    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-define98.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. Simplified98.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 0 92.6%

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

    if 6.1e7 < phi2

    1. Initial program 56.3%

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

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

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

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

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

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

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

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

Alternative 5: 85.8% accurate, 1.5× speedup?

\[\begin{array}{l} R\_m = \left|R\right| \\ R\_s = \mathsf{copysign}\left(1, R\right) \\ R\_s \cdot \begin{array}{l} \mathbf{if}\;\lambda_2 \leq 1.75 \cdot 10^{+133}:\\ \;\;\;\;R\_m \cdot \mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_1 - \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R\_m \cdot \mathsf{hypot}\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \left(-\lambda_2\right), \phi_1 - \phi_2\right)\\ \end{array} \end{array} \]
R\_m = (fabs.f64 R)
R\_s = (copysign.f64 #s(literal 1 binary64) R)
(FPCore (R_s R_m lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R_s
  (if (<= lambda2 1.75e+133)
    (* R_m (hypot (- lambda1 lambda2) (- phi1 phi2)))
    (* R_m (hypot (* (cos (* phi2 0.5)) (- lambda2)) (- phi1 phi2))))))
R\_m = fabs(R);
R\_s = copysign(1.0, R);
double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda2 <= 1.75e+133) {
		tmp = R_m * hypot((lambda1 - lambda2), (phi1 - phi2));
	} else {
		tmp = R_m * hypot((cos((phi2 * 0.5)) * -lambda2), (phi1 - phi2));
	}
	return R_s * tmp;
}
R\_m = Math.abs(R);
R\_s = Math.copySign(1.0, R);
public static double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (lambda2 <= 1.75e+133) {
		tmp = R_m * Math.hypot((lambda1 - lambda2), (phi1 - phi2));
	} else {
		tmp = R_m * Math.hypot((Math.cos((phi2 * 0.5)) * -lambda2), (phi1 - phi2));
	}
	return R_s * tmp;
}
R\_m = math.fabs(R)
R\_s = math.copysign(1.0, R)
def code(R_s, R_m, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if lambda2 <= 1.75e+133:
		tmp = R_m * math.hypot((lambda1 - lambda2), (phi1 - phi2))
	else:
		tmp = R_m * math.hypot((math.cos((phi2 * 0.5)) * -lambda2), (phi1 - phi2))
	return R_s * tmp
R\_m = abs(R)
R\_s = copysign(1.0, R)
function code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (lambda2 <= 1.75e+133)
		tmp = Float64(R_m * hypot(Float64(lambda1 - lambda2), Float64(phi1 - phi2)));
	else
		tmp = Float64(R_m * hypot(Float64(cos(Float64(phi2 * 0.5)) * Float64(-lambda2)), Float64(phi1 - phi2)));
	end
	return Float64(R_s * tmp)
end
R\_m = abs(R);
R\_s = sign(R) * abs(1.0);
function tmp_2 = code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (lambda2 <= 1.75e+133)
		tmp = R_m * hypot((lambda1 - lambda2), (phi1 - phi2));
	else
		tmp = R_m * hypot((cos((phi2 * 0.5)) * -lambda2), (phi1 - phi2));
	end
	tmp_2 = R_s * tmp;
end
R\_m = N[Abs[R], $MachinePrecision]
R\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[R]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[R$95$s_, R$95$m_, lambda1_, lambda2_, phi1_, phi2_] := N[(R$95$s * If[LessEqual[lambda2, 1.75e+133], N[(R$95$m * N[Sqrt[N[(lambda1 - lambda2), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[(R$95$m * N[Sqrt[N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * (-lambda2)), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
R\_m = \left|R\right|
\\
R\_s = \mathsf{copysign}\left(1, R\right)

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

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


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

    1. Initial program 66.1%

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

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

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

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

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

    if 1.7499999999999999e133 < lambda2

    1. Initial program 46.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.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. Simplified93.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 0 85.7%

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

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

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

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

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

Alternative 6: 96.0% accurate, 1.5× speedup?

\[\begin{array}{l} R\_m = \left|R\right| \\ R\_s = \mathsf{copysign}\left(1, R\right) \\ R\_s \cdot \left(R\_m \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)\right) \end{array} \]
R\_m = (fabs.f64 R)
R\_s = (copysign.f64 #s(literal 1 binary64) R)
(FPCore (R_s R_m lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R_s
  (*
   R_m
   (hypot (* (- lambda1 lambda2) (cos (/ (+ phi2 phi1) 2.0))) (- phi1 phi2)))))
R\_m = fabs(R);
R\_s = copysign(1.0, R);
double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	return R_s * (R_m * hypot(((lambda1 - lambda2) * cos(((phi2 + phi1) / 2.0))), (phi1 - phi2)));
}
R\_m = Math.abs(R);
R\_s = Math.copySign(1.0, R);
public static double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	return R_s * (R_m * Math.hypot(((lambda1 - lambda2) * Math.cos(((phi2 + phi1) / 2.0))), (phi1 - phi2)));
}
R\_m = math.fabs(R)
R\_s = math.copysign(1.0, R)
def code(R_s, R_m, lambda1, lambda2, phi1, phi2):
	return R_s * (R_m * math.hypot(((lambda1 - lambda2) * math.cos(((phi2 + phi1) / 2.0))), (phi1 - phi2)))
R\_m = abs(R)
R\_s = copysign(1.0, R)
function code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	return Float64(R_s * Float64(R_m * hypot(Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi2 + phi1) / 2.0))), Float64(phi1 - phi2))))
end
R\_m = abs(R);
R\_s = sign(R) * abs(1.0);
function tmp = code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = R_s * (R_m * hypot(((lambda1 - lambda2) * cos(((phi2 + phi1) / 2.0))), (phi1 - phi2)));
end
R\_m = N[Abs[R], $MachinePrecision]
R\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[R]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[R$95$s_, R$95$m_, lambda1_, lambda2_, phi1_, phi2_] := N[(R$95$s * N[(R$95$m * 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]), $MachinePrecision]
\begin{array}{l}
R\_m = \left|R\right|
\\
R\_s = \mathsf{copysign}\left(1, R\right)

\\
R\_s \cdot \left(R\_m \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)\right)
\end{array}
Derivation
  1. Initial program 63.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-define96.7%

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

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

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

\[\begin{array}{l} R\_m = \left|R\right| \\ R\_s = \mathsf{copysign}\left(1, R\right) \\ R\_s \cdot \begin{array}{l} \mathbf{if}\;\phi_2 \leq 7.2 \cdot 10^{+67}:\\ \;\;\;\;R\_m \cdot \mathsf{hypot}\left(\phi_1, \lambda_1 - \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;R\_m \cdot \left(\phi_2 \cdot \left(1 - \frac{\phi_1}{\phi_2}\right)\right)\\ \end{array} \end{array} \]
R\_m = (fabs.f64 R)
R\_s = (copysign.f64 #s(literal 1 binary64) R)
(FPCore (R_s R_m lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R_s
  (if (<= phi2 7.2e+67)
    (* R_m (hypot phi1 (- lambda1 lambda2)))
    (* R_m (* phi2 (- 1.0 (/ phi1 phi2)))))))
R\_m = fabs(R);
R\_s = copysign(1.0, R);
double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 7.2e+67) {
		tmp = R_m * hypot(phi1, (lambda1 - lambda2));
	} else {
		tmp = R_m * (phi2 * (1.0 - (phi1 / phi2)));
	}
	return R_s * tmp;
}
R\_m = Math.abs(R);
R\_s = Math.copySign(1.0, R);
public static double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 7.2e+67) {
		tmp = R_m * Math.hypot(phi1, (lambda1 - lambda2));
	} else {
		tmp = R_m * (phi2 * (1.0 - (phi1 / phi2)));
	}
	return R_s * tmp;
}
R\_m = math.fabs(R)
R\_s = math.copysign(1.0, R)
def code(R_s, R_m, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 7.2e+67:
		tmp = R_m * math.hypot(phi1, (lambda1 - lambda2))
	else:
		tmp = R_m * (phi2 * (1.0 - (phi1 / phi2)))
	return R_s * tmp
R\_m = abs(R)
R\_s = copysign(1.0, R)
function code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 7.2e+67)
		tmp = Float64(R_m * hypot(phi1, Float64(lambda1 - lambda2)));
	else
		tmp = Float64(R_m * Float64(phi2 * Float64(1.0 - Float64(phi1 / phi2))));
	end
	return Float64(R_s * tmp)
end
R\_m = abs(R);
R\_s = sign(R) * abs(1.0);
function tmp_2 = code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi2 <= 7.2e+67)
		tmp = R_m * hypot(phi1, (lambda1 - lambda2));
	else
		tmp = R_m * (phi2 * (1.0 - (phi1 / phi2)));
	end
	tmp_2 = R_s * tmp;
end
R\_m = N[Abs[R], $MachinePrecision]
R\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[R]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[R$95$s_, R$95$m_, lambda1_, lambda2_, phi1_, phi2_] := N[(R$95$s * If[LessEqual[phi2, 7.2e+67], N[(R$95$m * N[Sqrt[phi1 ^ 2 + N[(lambda1 - lambda2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[(R$95$m * N[(phi2 * N[(1.0 - N[(phi1 / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
R\_m = \left|R\right|
\\
R\_s = \mathsf{copysign}\left(1, R\right)

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

\mathbf{else}:\\
\;\;\;\;R\_m \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 < 7.1999999999999998e67

    1. Initial program 65.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-define97.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. Simplified97.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 0 92.0%

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

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

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

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

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

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

    if 7.1999999999999998e67 < phi2

    1. Initial program 52.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-define92.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. Simplified92.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 68.4%

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

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

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

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

Alternative 8: 85.2% accurate, 3.0× speedup?

\[\begin{array}{l} R\_m = \left|R\right| \\ R\_s = \mathsf{copysign}\left(1, R\right) \\ R\_s \cdot \left(R\_m \cdot \mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_1 - \phi_2\right)\right) \end{array} \]
R\_m = (fabs.f64 R)
R\_s = (copysign.f64 #s(literal 1 binary64) R)
(FPCore (R_s R_m lambda1 lambda2 phi1 phi2)
 :precision binary64
 (* R_s (* R_m (hypot (- lambda1 lambda2) (- phi1 phi2)))))
R\_m = fabs(R);
R\_s = copysign(1.0, R);
double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	return R_s * (R_m * hypot((lambda1 - lambda2), (phi1 - phi2)));
}
R\_m = Math.abs(R);
R\_s = Math.copySign(1.0, R);
public static double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	return R_s * (R_m * Math.hypot((lambda1 - lambda2), (phi1 - phi2)));
}
R\_m = math.fabs(R)
R\_s = math.copysign(1.0, R)
def code(R_s, R_m, lambda1, lambda2, phi1, phi2):
	return R_s * (R_m * math.hypot((lambda1 - lambda2), (phi1 - phi2)))
R\_m = abs(R)
R\_s = copysign(1.0, R)
function code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	return Float64(R_s * Float64(R_m * hypot(Float64(lambda1 - lambda2), Float64(phi1 - phi2))))
end
R\_m = abs(R);
R\_s = sign(R) * abs(1.0);
function tmp = code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = R_s * (R_m * hypot((lambda1 - lambda2), (phi1 - phi2)));
end
R\_m = N[Abs[R], $MachinePrecision]
R\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[R]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[R$95$s_, R$95$m_, lambda1_, lambda2_, phi1_, phi2_] := N[(R$95$s * N[(R$95$m * N[Sqrt[N[(lambda1 - lambda2), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
R\_m = \left|R\right|
\\
R\_s = \mathsf{copysign}\left(1, R\right)

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

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

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

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

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

Alternative 9: 30.9% accurate, 23.5× speedup?

\[\begin{array}{l} R\_m = \left|R\right| \\ R\_s = \mathsf{copysign}\left(1, R\right) \\ R\_s \cdot \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.1 \cdot 10^{+69}:\\ \;\;\;\;\phi_1 \cdot \left(\phi_2 \cdot \frac{R\_m}{\phi_1} - R\_m\right)\\ \mathbf{else}:\\ \;\;\;\;R\_m \cdot \left(\phi_2 \cdot \left(1 - \frac{\phi_1}{\phi_2}\right)\right)\\ \end{array} \end{array} \]
R\_m = (fabs.f64 R)
R\_s = (copysign.f64 #s(literal 1 binary64) R)
(FPCore (R_s R_m lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R_s
  (if (<= phi2 1.1e+69)
    (* phi1 (- (* phi2 (/ R_m phi1)) R_m))
    (* R_m (* phi2 (- 1.0 (/ phi1 phi2)))))))
R\_m = fabs(R);
R\_s = copysign(1.0, R);
double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 1.1e+69) {
		tmp = phi1 * ((phi2 * (R_m / phi1)) - R_m);
	} else {
		tmp = R_m * (phi2 * (1.0 - (phi1 / phi2)));
	}
	return R_s * tmp;
}
R\_m = abs(r)
R\_s = copysign(1.0d0, r)
real(8) function code(r_s, r_m, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r_s
    real(8), intent (in) :: r_m
    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.1d+69) then
        tmp = phi1 * ((phi2 * (r_m / phi1)) - r_m)
    else
        tmp = r_m * (phi2 * (1.0d0 - (phi1 / phi2)))
    end if
    code = r_s * tmp
end function
R\_m = Math.abs(R);
R\_s = Math.copySign(1.0, R);
public static double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 1.1e+69) {
		tmp = phi1 * ((phi2 * (R_m / phi1)) - R_m);
	} else {
		tmp = R_m * (phi2 * (1.0 - (phi1 / phi2)));
	}
	return R_s * tmp;
}
R\_m = math.fabs(R)
R\_s = math.copysign(1.0, R)
def code(R_s, R_m, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 1.1e+69:
		tmp = phi1 * ((phi2 * (R_m / phi1)) - R_m)
	else:
		tmp = R_m * (phi2 * (1.0 - (phi1 / phi2)))
	return R_s * tmp
R\_m = abs(R)
R\_s = copysign(1.0, R)
function code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 1.1e+69)
		tmp = Float64(phi1 * Float64(Float64(phi2 * Float64(R_m / phi1)) - R_m));
	else
		tmp = Float64(R_m * Float64(phi2 * Float64(1.0 - Float64(phi1 / phi2))));
	end
	return Float64(R_s * tmp)
end
R\_m = abs(R);
R\_s = sign(R) * abs(1.0);
function tmp_2 = code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi2 <= 1.1e+69)
		tmp = phi1 * ((phi2 * (R_m / phi1)) - R_m);
	else
		tmp = R_m * (phi2 * (1.0 - (phi1 / phi2)));
	end
	tmp_2 = R_s * tmp;
end
R\_m = N[Abs[R], $MachinePrecision]
R\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[R]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[R$95$s_, R$95$m_, lambda1_, lambda2_, phi1_, phi2_] := N[(R$95$s * If[LessEqual[phi2, 1.1e+69], N[(phi1 * N[(N[(phi2 * N[(R$95$m / phi1), $MachinePrecision]), $MachinePrecision] - R$95$m), $MachinePrecision]), $MachinePrecision], N[(R$95$m * N[(phi2 * N[(1.0 - N[(phi1 / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
R\_m = \left|R\right|
\\
R\_s = \mathsf{copysign}\left(1, R\right)

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

\mathbf{else}:\\
\;\;\;\;R\_m \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 < 1.1000000000000001e69

    1. Initial program 65.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-define97.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. Simplified97.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 21.2%

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

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

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

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

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

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

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

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

    if 1.1000000000000001e69 < phi2

    1. Initial program 52.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-define92.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. Simplified92.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 68.4%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.1 \cdot 10^{+69}:\\ \;\;\;\;\phi_1 \cdot \left(\phi_2 \cdot \frac{R}{\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 10: 29.8% accurate, 23.5× speedup?

\[\begin{array}{l} R\_m = \left|R\right| \\ R\_s = \mathsf{copysign}\left(1, R\right) \\ R\_s \cdot \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.32 \cdot 10^{+68}:\\ \;\;\;\;\phi_1 \cdot \left(R\_m \cdot \frac{\phi_2}{\phi_1} - R\_m\right)\\ \mathbf{else}:\\ \;\;\;\;R\_m \cdot \left(\phi_2 \cdot \left(1 - \frac{\phi_1}{\phi_2}\right)\right)\\ \end{array} \end{array} \]
R\_m = (fabs.f64 R)
R\_s = (copysign.f64 #s(literal 1 binary64) R)
(FPCore (R_s R_m lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R_s
  (if (<= phi2 1.32e+68)
    (* phi1 (- (* R_m (/ phi2 phi1)) R_m))
    (* R_m (* phi2 (- 1.0 (/ phi1 phi2)))))))
R\_m = fabs(R);
R\_s = copysign(1.0, R);
double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 1.32e+68) {
		tmp = phi1 * ((R_m * (phi2 / phi1)) - R_m);
	} else {
		tmp = R_m * (phi2 * (1.0 - (phi1 / phi2)));
	}
	return R_s * tmp;
}
R\_m = abs(r)
R\_s = copysign(1.0d0, r)
real(8) function code(r_s, r_m, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r_s
    real(8), intent (in) :: r_m
    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.32d+68) then
        tmp = phi1 * ((r_m * (phi2 / phi1)) - r_m)
    else
        tmp = r_m * (phi2 * (1.0d0 - (phi1 / phi2)))
    end if
    code = r_s * tmp
end function
R\_m = Math.abs(R);
R\_s = Math.copySign(1.0, R);
public static double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 1.32e+68) {
		tmp = phi1 * ((R_m * (phi2 / phi1)) - R_m);
	} else {
		tmp = R_m * (phi2 * (1.0 - (phi1 / phi2)));
	}
	return R_s * tmp;
}
R\_m = math.fabs(R)
R\_s = math.copysign(1.0, R)
def code(R_s, R_m, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 1.32e+68:
		tmp = phi1 * ((R_m * (phi2 / phi1)) - R_m)
	else:
		tmp = R_m * (phi2 * (1.0 - (phi1 / phi2)))
	return R_s * tmp
R\_m = abs(R)
R\_s = copysign(1.0, R)
function code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 1.32e+68)
		tmp = Float64(phi1 * Float64(Float64(R_m * Float64(phi2 / phi1)) - R_m));
	else
		tmp = Float64(R_m * Float64(phi2 * Float64(1.0 - Float64(phi1 / phi2))));
	end
	return Float64(R_s * tmp)
end
R\_m = abs(R);
R\_s = sign(R) * abs(1.0);
function tmp_2 = code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi2 <= 1.32e+68)
		tmp = phi1 * ((R_m * (phi2 / phi1)) - R_m);
	else
		tmp = R_m * (phi2 * (1.0 - (phi1 / phi2)));
	end
	tmp_2 = R_s * tmp;
end
R\_m = N[Abs[R], $MachinePrecision]
R\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[R]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[R$95$s_, R$95$m_, lambda1_, lambda2_, phi1_, phi2_] := N[(R$95$s * If[LessEqual[phi2, 1.32e+68], N[(phi1 * N[(N[(R$95$m * N[(phi2 / phi1), $MachinePrecision]), $MachinePrecision] - R$95$m), $MachinePrecision]), $MachinePrecision], N[(R$95$m * N[(phi2 * N[(1.0 - N[(phi1 / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
R\_m = \left|R\right|
\\
R\_s = \mathsf{copysign}\left(1, R\right)

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

\mathbf{else}:\\
\;\;\;\;R\_m \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 < 1.3200000000000001e68

    1. Initial program 65.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-define97.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. Simplified97.8%

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

        \[\leadsto \color{blue}{\sqrt{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)} \cdot \sqrt{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)}} \]
      2. pow248.1%

        \[\leadsto \color{blue}{{\left(\sqrt{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)}\right)}^{2}} \]
      3. *-commutative48.1%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto {\left(\sqrt{R \cdot \mathsf{hypot}\left(\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \color{blue}{\left(\phi_2 \cdot 0.5\right)} \cdot \sin \left(\phi_1 \cdot 0.5\right)\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)}\right)}^{2} \]
    8. Applied egg-rr49.0%

      \[\leadsto {\left(\sqrt{R \cdot \mathsf{hypot}\left(\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)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)}\right)}^{2} \]
    9. Taylor expanded in phi1 around -inf 21.2%

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

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

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

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

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

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

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

    if 1.3200000000000001e68 < phi2

    1. Initial program 52.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-define92.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. Simplified92.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 68.4%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.32 \cdot 10^{+68}:\\ \;\;\;\;\phi_1 \cdot \left(R \cdot \frac{\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: 31.0% accurate, 23.5× speedup?

\[\begin{array}{l} R\_m = \left|R\right| \\ R\_s = \mathsf{copysign}\left(1, R\right) \\ R\_s \cdot \begin{array}{l} \mathbf{if}\;\phi_1 \leq -8 \cdot 10^{-13}:\\ \;\;\;\;R\_m \cdot \left(\phi_1 \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot \left(R\_m - \phi_1 \cdot \frac{R\_m}{\phi_2}\right)\\ \end{array} \end{array} \]
R\_m = (fabs.f64 R)
R\_s = (copysign.f64 #s(literal 1 binary64) R)
(FPCore (R_s R_m lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R_s
  (if (<= phi1 -8e-13)
    (* R_m (* phi1 (+ (/ phi2 phi1) -1.0)))
    (* phi2 (- R_m (* phi1 (/ R_m phi2)))))))
R\_m = fabs(R);
R\_s = copysign(1.0, R);
double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -8e-13) {
		tmp = R_m * (phi1 * ((phi2 / phi1) + -1.0));
	} else {
		tmp = phi2 * (R_m - (phi1 * (R_m / phi2)));
	}
	return R_s * tmp;
}
R\_m = abs(r)
R\_s = copysign(1.0d0, r)
real(8) function code(r_s, r_m, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r_s
    real(8), intent (in) :: r_m
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: tmp
    if (phi1 <= (-8d-13)) then
        tmp = r_m * (phi1 * ((phi2 / phi1) + (-1.0d0)))
    else
        tmp = phi2 * (r_m - (phi1 * (r_m / phi2)))
    end if
    code = r_s * tmp
end function
R\_m = Math.abs(R);
R\_s = Math.copySign(1.0, R);
public static double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -8e-13) {
		tmp = R_m * (phi1 * ((phi2 / phi1) + -1.0));
	} else {
		tmp = phi2 * (R_m - (phi1 * (R_m / phi2)));
	}
	return R_s * tmp;
}
R\_m = math.fabs(R)
R\_s = math.copysign(1.0, R)
def code(R_s, R_m, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -8e-13:
		tmp = R_m * (phi1 * ((phi2 / phi1) + -1.0))
	else:
		tmp = phi2 * (R_m - (phi1 * (R_m / phi2)))
	return R_s * tmp
R\_m = abs(R)
R\_s = copysign(1.0, R)
function code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -8e-13)
		tmp = Float64(R_m * Float64(phi1 * Float64(Float64(phi2 / phi1) + -1.0)));
	else
		tmp = Float64(phi2 * Float64(R_m - Float64(phi1 * Float64(R_m / phi2))));
	end
	return Float64(R_s * tmp)
end
R\_m = abs(R);
R\_s = sign(R) * abs(1.0);
function tmp_2 = code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi1 <= -8e-13)
		tmp = R_m * (phi1 * ((phi2 / phi1) + -1.0));
	else
		tmp = phi2 * (R_m - (phi1 * (R_m / phi2)));
	end
	tmp_2 = R_s * tmp;
end
R\_m = N[Abs[R], $MachinePrecision]
R\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[R]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[R$95$s_, R$95$m_, lambda1_, lambda2_, phi1_, phi2_] := N[(R$95$s * If[LessEqual[phi1, -8e-13], N[(R$95$m * N[(phi1 * N[(N[(phi2 / phi1), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(phi2 * N[(R$95$m - N[(phi1 * N[(R$95$m / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
R\_m = \left|R\right|
\\
R\_s = \mathsf{copysign}\left(1, R\right)

\\
R\_s \cdot \begin{array}{l}
\mathbf{if}\;\phi_1 \leq -8 \cdot 10^{-13}:\\
\;\;\;\;R\_m \cdot \left(\phi_1 \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\

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


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

    1. Initial program 55.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-define92.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. Simplified92.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 -inf 59.8%

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

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

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

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

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

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

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

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

    if -8.0000000000000002e-13 < phi1

    1. Initial program 65.7%

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

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

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

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

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

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

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

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

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

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

Alternative 12: 29.4% accurate, 23.5× speedup?

\[\begin{array}{l} R\_m = \left|R\right| \\ R\_s = \mathsf{copysign}\left(1, R\right) \\ R\_s \cdot \begin{array}{l} \mathbf{if}\;\phi_2 \leq 100000000:\\ \;\;\;\;R\_m \cdot \left(\phi_1 \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R\_m \cdot \left(\phi_2 \cdot \left(1 - \frac{\phi_1}{\phi_2}\right)\right)\\ \end{array} \end{array} \]
R\_m = (fabs.f64 R)
R\_s = (copysign.f64 #s(literal 1 binary64) R)
(FPCore (R_s R_m lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R_s
  (if (<= phi2 100000000.0)
    (* R_m (* phi1 (+ (/ phi2 phi1) -1.0)))
    (* R_m (* phi2 (- 1.0 (/ phi1 phi2)))))))
R\_m = fabs(R);
R\_s = copysign(1.0, R);
double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 100000000.0) {
		tmp = R_m * (phi1 * ((phi2 / phi1) + -1.0));
	} else {
		tmp = R_m * (phi2 * (1.0 - (phi1 / phi2)));
	}
	return R_s * tmp;
}
R\_m = abs(r)
R\_s = copysign(1.0d0, r)
real(8) function code(r_s, r_m, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r_s
    real(8), intent (in) :: r_m
    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 <= 100000000.0d0) then
        tmp = r_m * (phi1 * ((phi2 / phi1) + (-1.0d0)))
    else
        tmp = r_m * (phi2 * (1.0d0 - (phi1 / phi2)))
    end if
    code = r_s * tmp
end function
R\_m = Math.abs(R);
R\_s = Math.copySign(1.0, R);
public static double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 100000000.0) {
		tmp = R_m * (phi1 * ((phi2 / phi1) + -1.0));
	} else {
		tmp = R_m * (phi2 * (1.0 - (phi1 / phi2)));
	}
	return R_s * tmp;
}
R\_m = math.fabs(R)
R\_s = math.copysign(1.0, R)
def code(R_s, R_m, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 100000000.0:
		tmp = R_m * (phi1 * ((phi2 / phi1) + -1.0))
	else:
		tmp = R_m * (phi2 * (1.0 - (phi1 / phi2)))
	return R_s * tmp
R\_m = abs(R)
R\_s = copysign(1.0, R)
function code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 100000000.0)
		tmp = Float64(R_m * Float64(phi1 * Float64(Float64(phi2 / phi1) + -1.0)));
	else
		tmp = Float64(R_m * Float64(phi2 * Float64(1.0 - Float64(phi1 / phi2))));
	end
	return Float64(R_s * tmp)
end
R\_m = abs(R);
R\_s = sign(R) * abs(1.0);
function tmp_2 = code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi2 <= 100000000.0)
		tmp = R_m * (phi1 * ((phi2 / phi1) + -1.0));
	else
		tmp = R_m * (phi2 * (1.0 - (phi1 / phi2)));
	end
	tmp_2 = R_s * tmp;
end
R\_m = N[Abs[R], $MachinePrecision]
R\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[R]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[R$95$s_, R$95$m_, lambda1_, lambda2_, phi1_, phi2_] := N[(R$95$s * If[LessEqual[phi2, 100000000.0], N[(R$95$m * N[(phi1 * N[(N[(phi2 / phi1), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R$95$m * N[(phi2 * N[(1.0 - N[(phi1 / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
R\_m = \left|R\right|
\\
R\_s = \mathsf{copysign}\left(1, R\right)

\\
R\_s \cdot \begin{array}{l}
\mathbf{if}\;\phi_2 \leq 100000000:\\
\;\;\;\;R\_m \cdot \left(\phi_1 \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\

\mathbf{else}:\\
\;\;\;\;R\_m \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 < 1e8

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

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

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

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

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

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

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

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

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

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

    if 1e8 < phi2

    1. Initial program 55.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 100000000:\\ \;\;\;\;R \cdot \left(\phi_1 \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\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: 28.4% accurate, 23.5× speedup?

\[\begin{array}{l} R\_m = \left|R\right| \\ R\_s = \mathsf{copysign}\left(1, R\right) \\ R\_s \cdot \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.6 \cdot 10^{+206}:\\ \;\;\;\;R\_m \cdot \left(\phi_1 \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R\_m \cdot \phi_2\\ \end{array} \end{array} \]
R\_m = (fabs.f64 R)
R\_s = (copysign.f64 #s(literal 1 binary64) R)
(FPCore (R_s R_m lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R_s
  (if (<= phi2 1.6e+206)
    (* R_m (* phi1 (+ (/ phi2 phi1) -1.0)))
    (* R_m phi2))))
R\_m = fabs(R);
R\_s = copysign(1.0, R);
double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 1.6e+206) {
		tmp = R_m * (phi1 * ((phi2 / phi1) + -1.0));
	} else {
		tmp = R_m * phi2;
	}
	return R_s * tmp;
}
R\_m = abs(r)
R\_s = copysign(1.0d0, r)
real(8) function code(r_s, r_m, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r_s
    real(8), intent (in) :: r_m
    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.6d+206) then
        tmp = r_m * (phi1 * ((phi2 / phi1) + (-1.0d0)))
    else
        tmp = r_m * phi2
    end if
    code = r_s * tmp
end function
R\_m = Math.abs(R);
R\_s = Math.copySign(1.0, R);
public static double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 1.6e+206) {
		tmp = R_m * (phi1 * ((phi2 / phi1) + -1.0));
	} else {
		tmp = R_m * phi2;
	}
	return R_s * tmp;
}
R\_m = math.fabs(R)
R\_s = math.copysign(1.0, R)
def code(R_s, R_m, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 1.6e+206:
		tmp = R_m * (phi1 * ((phi2 / phi1) + -1.0))
	else:
		tmp = R_m * phi2
	return R_s * tmp
R\_m = abs(R)
R\_s = copysign(1.0, R)
function code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 1.6e+206)
		tmp = Float64(R_m * Float64(phi1 * Float64(Float64(phi2 / phi1) + -1.0)));
	else
		tmp = Float64(R_m * phi2);
	end
	return Float64(R_s * tmp)
end
R\_m = abs(R);
R\_s = sign(R) * abs(1.0);
function tmp_2 = code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi2 <= 1.6e+206)
		tmp = R_m * (phi1 * ((phi2 / phi1) + -1.0));
	else
		tmp = R_m * phi2;
	end
	tmp_2 = R_s * tmp;
end
R\_m = N[Abs[R], $MachinePrecision]
R\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[R]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[R$95$s_, R$95$m_, lambda1_, lambda2_, phi1_, phi2_] := N[(R$95$s * If[LessEqual[phi2, 1.6e+206], N[(R$95$m * N[(phi1 * N[(N[(phi2 / phi1), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R$95$m * phi2), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
R\_m = \left|R\right|
\\
R\_s = \mathsf{copysign}\left(1, R\right)

\\
R\_s \cdot \begin{array}{l}
\mathbf{if}\;\phi_2 \leq 1.6 \cdot 10^{+206}:\\
\;\;\;\;R\_m \cdot \left(\phi_1 \cdot \left(\frac{\phi_2}{\phi_1} + -1\right)\right)\\

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


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

    1. Initial program 63.9%

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

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

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

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

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

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

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

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

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

    if 1.60000000000000003e206 < phi2

    1. Initial program 52.6%

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

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

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

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

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

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

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

Alternative 14: 28.6% accurate, 36.5× speedup?

\[\begin{array}{l} R\_m = \left|R\right| \\ R\_s = \mathsf{copysign}\left(1, R\right) \\ R\_s \cdot \begin{array}{l} \mathbf{if}\;\phi_1 \leq -31000:\\ \;\;\;\;R\_m \cdot \left(-\phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;R\_m \cdot \phi_2\\ \end{array} \end{array} \]
R\_m = (fabs.f64 R)
R\_s = (copysign.f64 #s(literal 1 binary64) R)
(FPCore (R_s R_m lambda1 lambda2 phi1 phi2)
 :precision binary64
 (* R_s (if (<= phi1 -31000.0) (* R_m (- phi1)) (* R_m phi2))))
R\_m = fabs(R);
R\_s = copysign(1.0, R);
double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -31000.0) {
		tmp = R_m * -phi1;
	} else {
		tmp = R_m * phi2;
	}
	return R_s * tmp;
}
R\_m = abs(r)
R\_s = copysign(1.0d0, r)
real(8) function code(r_s, r_m, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r_s
    real(8), intent (in) :: r_m
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: tmp
    if (phi1 <= (-31000.0d0)) then
        tmp = r_m * -phi1
    else
        tmp = r_m * phi2
    end if
    code = r_s * tmp
end function
R\_m = Math.abs(R);
R\_s = Math.copySign(1.0, R);
public static double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -31000.0) {
		tmp = R_m * -phi1;
	} else {
		tmp = R_m * phi2;
	}
	return R_s * tmp;
}
R\_m = math.fabs(R)
R\_s = math.copysign(1.0, R)
def code(R_s, R_m, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -31000.0:
		tmp = R_m * -phi1
	else:
		tmp = R_m * phi2
	return R_s * tmp
R\_m = abs(R)
R\_s = copysign(1.0, R)
function code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -31000.0)
		tmp = Float64(R_m * Float64(-phi1));
	else
		tmp = Float64(R_m * phi2);
	end
	return Float64(R_s * tmp)
end
R\_m = abs(R);
R\_s = sign(R) * abs(1.0);
function tmp_2 = code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi1 <= -31000.0)
		tmp = R_m * -phi1;
	else
		tmp = R_m * phi2;
	end
	tmp_2 = R_s * tmp;
end
R\_m = N[Abs[R], $MachinePrecision]
R\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[R]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[R$95$s_, R$95$m_, lambda1_, lambda2_, phi1_, phi2_] := N[(R$95$s * If[LessEqual[phi1, -31000.0], N[(R$95$m * (-phi1)), $MachinePrecision], N[(R$95$m * phi2), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
R\_m = \left|R\right|
\\
R\_s = \mathsf{copysign}\left(1, R\right)

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

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


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

    1. Initial program 56.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-define94.0%

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

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

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

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

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

    if -31000 < phi1

    1. Initial program 65.1%

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

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

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

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

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

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

Alternative 15: 17.3% accurate, 109.7× speedup?

\[\begin{array}{l} R\_m = \left|R\right| \\ R\_s = \mathsf{copysign}\left(1, R\right) \\ R\_s \cdot \left(R\_m \cdot \phi_2\right) \end{array} \]
R\_m = (fabs.f64 R)
R\_s = (copysign.f64 #s(literal 1 binary64) R)
(FPCore (R_s R_m lambda1 lambda2 phi1 phi2)
 :precision binary64
 (* R_s (* R_m phi2)))
R\_m = fabs(R);
R\_s = copysign(1.0, R);
double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	return R_s * (R_m * phi2);
}
R\_m = abs(r)
R\_s = copysign(1.0d0, r)
real(8) function code(r_s, r_m, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r_s
    real(8), intent (in) :: r_m
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = r_s * (r_m * phi2)
end function
R\_m = Math.abs(R);
R\_s = Math.copySign(1.0, R);
public static double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	return R_s * (R_m * phi2);
}
R\_m = math.fabs(R)
R\_s = math.copysign(1.0, R)
def code(R_s, R_m, lambda1, lambda2, phi1, phi2):
	return R_s * (R_m * phi2)
R\_m = abs(R)
R\_s = copysign(1.0, R)
function code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	return Float64(R_s * Float64(R_m * phi2))
end
R\_m = abs(R);
R\_s = sign(R) * abs(1.0);
function tmp = code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = R_s * (R_m * phi2);
end
R\_m = N[Abs[R], $MachinePrecision]
R\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[R]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[R$95$s_, R$95$m_, lambda1_, lambda2_, phi1_, phi2_] := N[(R$95$s * N[(R$95$m * phi2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
R\_m = \left|R\right|
\\
R\_s = \mathsf{copysign}\left(1, R\right)

\\
R\_s \cdot \left(R\_m \cdot \phi_2\right)
\end{array}
Derivation
  1. Initial program 63.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-define96.7%

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

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

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

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

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

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

Alternative 16: 14.3% accurate, 109.7× speedup?

\[\begin{array}{l} R\_m = \left|R\right| \\ R\_s = \mathsf{copysign}\left(1, R\right) \\ R\_s \cdot \left(R\_m \cdot \lambda_1\right) \end{array} \]
R\_m = (fabs.f64 R)
R\_s = (copysign.f64 #s(literal 1 binary64) R)
(FPCore (R_s R_m lambda1 lambda2 phi1 phi2)
 :precision binary64
 (* R_s (* R_m lambda1)))
R\_m = fabs(R);
R\_s = copysign(1.0, R);
double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	return R_s * (R_m * lambda1);
}
R\_m = abs(r)
R\_s = copysign(1.0d0, r)
real(8) function code(r_s, r_m, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r_s
    real(8), intent (in) :: r_m
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = r_s * (r_m * lambda1)
end function
R\_m = Math.abs(R);
R\_s = Math.copySign(1.0, R);
public static double code(double R_s, double R_m, double lambda1, double lambda2, double phi1, double phi2) {
	return R_s * (R_m * lambda1);
}
R\_m = math.fabs(R)
R\_s = math.copysign(1.0, R)
def code(R_s, R_m, lambda1, lambda2, phi1, phi2):
	return R_s * (R_m * lambda1)
R\_m = abs(R)
R\_s = copysign(1.0, R)
function code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	return Float64(R_s * Float64(R_m * lambda1))
end
R\_m = abs(R);
R\_s = sign(R) * abs(1.0);
function tmp = code(R_s, R_m, lambda1, lambda2, phi1, phi2)
	tmp = R_s * (R_m * lambda1);
end
R\_m = N[Abs[R], $MachinePrecision]
R\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[R]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[R$95$s_, R$95$m_, lambda1_, lambda2_, phi1_, phi2_] := N[(R$95$s * N[(R$95$m * lambda1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
R\_m = \left|R\right|
\\
R\_s = \mathsf{copysign}\left(1, R\right)

\\
R\_s \cdot \left(R\_m \cdot \lambda_1\right)
\end{array}
Derivation
  1. Initial program 63.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-define96.7%

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

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

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

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

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

      \[\leadsto \color{blue}{\lambda_1 \cdot R} \]
  9. Simplified12.0%

    \[\leadsto \color{blue}{\lambda_1 \cdot R} \]
  10. Final simplification12.0%

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

Reproduce

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