Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.8% → 99.4%
Time: 18.3s
Alternatives: 15
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 15 alternatives:

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

Initial Program: 59.8% 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.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(\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) \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)))
        (* (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))) - (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))) - (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))) - (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(sin(Float64(phi2 * 0.5)) * sin(Float64(0.5 * phi1)))) * Float64(lambda1 - lambda2)), 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((((cos((0.5 * phi1)) * cos((phi2 * 0.5))) - (sin((phi2 * 0.5)) * sin((0.5 * phi1)))) * (lambda1 - lambda2)), (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[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $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) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)}\right)}^{2}
\end{array}
Derivation
  1. Initial program 60.3%

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

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

    \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. add-sqr-sqrt51.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. pow251.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. *-commutative51.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-inv51.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-eval51.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-rr51.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. *-commutative51.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. +-commutative51.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-in51.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. *-commutative51.1%

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

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

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

      \[\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 \left(\phi_2 \cdot 0.5\right) \cdot \sin \color{blue}{\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-rr52.4%

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

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

Alternative 2: 96.0% accurate, 0.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_1 \leq -3.5 \cdot 10^{+212}:\\ \;\;\;\;{\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) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) \cdot \lambda_1, \phi_1 - \phi_2\right)}\right)}^{2}\\ \mathbf{else}:\\ \;\;\;\;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)\\ \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 (<= lambda1 -3.5e+212)
    (pow
     (sqrt
      (*
       R_m
       (hypot
        (*
         (-
          (* (cos (* 0.5 phi1)) (cos (* phi2 0.5)))
          (* (sin (* phi2 0.5)) (sin (* 0.5 phi1))))
         lambda1)
        (- phi1 phi2))))
     2.0)
    (*
     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) {
	double tmp;
	if (lambda1 <= -3.5e+212) {
		tmp = pow(sqrt((R_m * hypot((((cos((0.5 * phi1)) * cos((phi2 * 0.5))) - (sin((phi2 * 0.5)) * sin((0.5 * phi1)))) * lambda1), (phi1 - phi2)))), 2.0);
	} else {
		tmp = R_m * hypot(((lambda1 - lambda2) * cos(((phi2 + phi1) / 2.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 (lambda1 <= -3.5e+212) {
		tmp = Math.pow(Math.sqrt((R_m * Math.hypot((((Math.cos((0.5 * phi1)) * Math.cos((phi2 * 0.5))) - (Math.sin((phi2 * 0.5)) * Math.sin((0.5 * phi1)))) * lambda1), (phi1 - phi2)))), 2.0);
	} else {
		tmp = R_m * Math.hypot(((lambda1 - lambda2) * Math.cos(((phi2 + phi1) / 2.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 lambda1 <= -3.5e+212:
		tmp = math.pow(math.sqrt((R_m * math.hypot((((math.cos((0.5 * phi1)) * math.cos((phi2 * 0.5))) - (math.sin((phi2 * 0.5)) * math.sin((0.5 * phi1)))) * lambda1), (phi1 - phi2)))), 2.0)
	else:
		tmp = R_m * math.hypot(((lambda1 - lambda2) * math.cos(((phi2 + phi1) / 2.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 (lambda1 <= -3.5e+212)
		tmp = sqrt(Float64(R_m * hypot(Float64(Float64(Float64(cos(Float64(0.5 * phi1)) * cos(Float64(phi2 * 0.5))) - Float64(sin(Float64(phi2 * 0.5)) * sin(Float64(0.5 * phi1)))) * lambda1), Float64(phi1 - phi2)))) ^ 2.0;
	else
		tmp = Float64(R_m * hypot(Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi2 + phi1) / 2.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 (lambda1 <= -3.5e+212)
		tmp = sqrt((R_m * hypot((((cos((0.5 * phi1)) * cos((phi2 * 0.5))) - (sin((phi2 * 0.5)) * sin((0.5 * phi1)))) * lambda1), (phi1 - phi2)))) ^ 2.0;
	else
		tmp = R_m * hypot(((lambda1 - lambda2) * cos(((phi2 + phi1) / 2.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[lambda1, -3.5e+212], 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[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * lambda1), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision], 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 \begin{array}{l}
\mathbf{if}\;\lambda_1 \leq -3.5 \cdot 10^{+212}:\\
\;\;\;\;{\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) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right) \cdot \lambda_1, \phi_1 - \phi_2\right)}\right)}^{2}\\

\mathbf{else}:\\
\;\;\;\;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)\\


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

    1. Initial program 32.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-define80.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. Simplified80.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\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 \left(\phi_2 \cdot 0.5\right) \cdot \sin \color{blue}{\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-rr56.8%

      \[\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 lambda1 around inf 56.8%

      \[\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 \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right) \cdot \color{blue}{\lambda_1}, \phi_1 - \phi_2\right)}\right)}^{2} \]

    if -3.49999999999999987e212 < lambda1

    1. Initial program 62.8%

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

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

Alternative 3: 93.2% 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_1 \leq -3.5 \cdot 10^{-7}:\\ \;\;\;\;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 (<= phi1 -3.5e-7)
    (* 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 (phi1 <= -3.5e-7) {
		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 (phi1 <= -3.5e-7) {
		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 phi1 <= -3.5e-7:
		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 (phi1 <= -3.5e-7)
		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 (phi1 <= -3.5e-7)
		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[phi1, -3.5e-7], 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_1 \leq -3.5 \cdot 10^{-7}:\\
\;\;\;\;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 phi1 < -3.49999999999999984e-7

    1. Initial program 57.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-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 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 -3.49999999999999984e-7 < phi1

    1. Initial program 61.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -3.5 \cdot 10^{-7}:\\ \;\;\;\;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: 82.5% 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 10^{-211}:\\ \;\;\;\;R\_m \cdot \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\phi_2 \cdot 0.5\right), \phi_1 - \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;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)\\ \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 1e-211)
    (* R_m (hypot (* lambda1 (cos (* phi2 0.5))) (- phi1 phi2)))
    (* R_m (hypot (* (cos (* 0.5 phi1)) (- 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) {
	double tmp;
	if (lambda2 <= 1e-211) {
		tmp = R_m * hypot((lambda1 * cos((phi2 * 0.5))), (phi1 - phi2));
	} else {
		tmp = R_m * hypot((cos((0.5 * phi1)) * (lambda1 - 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 <= 1e-211) {
		tmp = R_m * Math.hypot((lambda1 * Math.cos((phi2 * 0.5))), (phi1 - phi2));
	} else {
		tmp = R_m * Math.hypot((Math.cos((0.5 * phi1)) * (lambda1 - 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 <= 1e-211:
		tmp = R_m * math.hypot((lambda1 * math.cos((phi2 * 0.5))), (phi1 - phi2))
	else:
		tmp = R_m * math.hypot((math.cos((0.5 * phi1)) * (lambda1 - 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 <= 1e-211)
		tmp = Float64(R_m * hypot(Float64(lambda1 * cos(Float64(phi2 * 0.5))), Float64(phi1 - phi2)));
	else
		tmp = Float64(R_m * hypot(Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - 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 <= 1e-211)
		tmp = R_m * hypot((lambda1 * cos((phi2 * 0.5))), (phi1 - phi2));
	else
		tmp = R_m * hypot((cos((0.5 * phi1)) * (lambda1 - 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, 1e-211], N[(R$95$m * N[Sqrt[N[(lambda1 * N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], 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]]), $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 10^{-211}:\\
\;\;\;\;R\_m \cdot \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\phi_2 \cdot 0.5\right), \phi_1 - \phi_2\right)\\

\mathbf{else}:\\
\;\;\;\;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)\\


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

    1. Initial program 61.3%

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

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

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

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

    if 1.00000000000000009e-211 < lambda2

    1. Initial program 59.3%

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

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

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

Alternative 5: 77.7% 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 7.2 \cdot 10^{+49}:\\ \;\;\;\;R\_m \cdot \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\phi_2 \cdot 0.5\right), \phi_1 - \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R\_m \cdot \mathsf{hypot}\left(\phi_2, \lambda_1 - \lambda_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 7.2e+49)
    (* R_m (hypot (* lambda1 (cos (* phi2 0.5))) (- phi1 phi2)))
    (* R_m (hypot phi2 (- lambda1 lambda2))))))
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 <= 7.2e+49) {
		tmp = R_m * hypot((lambda1 * cos((phi2 * 0.5))), (phi1 - phi2));
	} else {
		tmp = R_m * hypot(phi2, (lambda1 - lambda2));
	}
	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 <= 7.2e+49) {
		tmp = R_m * Math.hypot((lambda1 * Math.cos((phi2 * 0.5))), (phi1 - phi2));
	} else {
		tmp = R_m * Math.hypot(phi2, (lambda1 - lambda2));
	}
	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 <= 7.2e+49:
		tmp = R_m * math.hypot((lambda1 * math.cos((phi2 * 0.5))), (phi1 - phi2))
	else:
		tmp = R_m * math.hypot(phi2, (lambda1 - lambda2))
	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 <= 7.2e+49)
		tmp = Float64(R_m * hypot(Float64(lambda1 * cos(Float64(phi2 * 0.5))), Float64(phi1 - phi2)));
	else
		tmp = Float64(R_m * hypot(phi2, Float64(lambda1 - lambda2)));
	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 <= 7.2e+49)
		tmp = R_m * hypot((lambda1 * cos((phi2 * 0.5))), (phi1 - phi2));
	else
		tmp = R_m * hypot(phi2, (lambda1 - lambda2));
	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, 7.2e+49], N[(R$95$m * N[Sqrt[N[(lambda1 * N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[(R$95$m * N[Sqrt[phi2 ^ 2 + N[(lambda1 - lambda2), $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 7.2 \cdot 10^{+49}:\\
\;\;\;\;R\_m \cdot \mathsf{hypot}\left(\lambda_1 \cdot \cos \left(\phi_2 \cdot 0.5\right), \phi_1 - \phi_2\right)\\

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


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

    1. Initial program 61.5%

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

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

    if 7.19999999999999993e49 < lambda2

    1. Initial program 56.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-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 phi2 around 0 74.4%

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

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

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

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

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

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

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

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

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

Alternative 6: 95.8% 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 60.3%

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

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

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

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

Alternative 7: 70.1% 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_1 \leq -2.5 \cdot 10^{+14}:\\ \;\;\;\;\phi_1 \cdot \left(R\_m \cdot \frac{\phi_2}{\phi_1} - R\_m\right)\\ \mathbf{else}:\\ \;\;\;\;R\_m \cdot \mathsf{hypot}\left(\phi_2, \lambda_1 - \lambda_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 -2.5e+14)
    (* phi1 (- (* R_m (/ phi2 phi1)) R_m))
    (* R_m (hypot phi2 (- lambda1 lambda2))))))
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 <= -2.5e+14) {
		tmp = phi1 * ((R_m * (phi2 / phi1)) - R_m);
	} else {
		tmp = R_m * hypot(phi2, (lambda1 - lambda2));
	}
	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 (phi1 <= -2.5e+14) {
		tmp = phi1 * ((R_m * (phi2 / phi1)) - R_m);
	} else {
		tmp = R_m * Math.hypot(phi2, (lambda1 - lambda2));
	}
	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 <= -2.5e+14:
		tmp = phi1 * ((R_m * (phi2 / phi1)) - R_m)
	else:
		tmp = R_m * math.hypot(phi2, (lambda1 - lambda2))
	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 <= -2.5e+14)
		tmp = Float64(phi1 * Float64(Float64(R_m * Float64(phi2 / phi1)) - R_m));
	else
		tmp = Float64(R_m * hypot(phi2, Float64(lambda1 - lambda2)));
	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 <= -2.5e+14)
		tmp = phi1 * ((R_m * (phi2 / phi1)) - R_m);
	else
		tmp = R_m * hypot(phi2, (lambda1 - lambda2));
	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, -2.5e+14], N[(phi1 * N[(N[(R$95$m * N[(phi2 / phi1), $MachinePrecision]), $MachinePrecision] - R$95$m), $MachinePrecision]), $MachinePrecision], N[(R$95$m * N[Sqrt[phi2 ^ 2 + N[(lambda1 - lambda2), $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_1 \leq -2.5 \cdot 10^{+14}:\\
\;\;\;\;\phi_1 \cdot \left(R\_m \cdot \frac{\phi_2}{\phi_1} - R\_m\right)\\

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


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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(-\phi_1\right) \cdot \left(R - \color{blue}{\frac{R \cdot \phi_2}{\phi_1}}\right) \]
    9. Step-by-step derivation
      1. associate-/l*72.1%

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

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

    if -2.5e14 < phi1

    1. Initial program 60.6%

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

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

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

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

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

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

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

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

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\phi_2, \lambda_1 - \lambda_2\right)} \]
    10. Simplified67.9%

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

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

Alternative 8: 30.9% accurate, 17.3× 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_1 \leq -1.7 \cdot 10^{+242}:\\ \;\;\;\;R\_m \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq -1.45 \cdot 10^{-306}:\\ \;\;\;\;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 (<= lambda1 -1.7e+242)
    (* R_m (- lambda1))
    (if (<= lambda1 -1.45e-306)
      (* 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 (lambda1 <= -1.7e+242) {
		tmp = R_m * -lambda1;
	} else if (lambda1 <= -1.45e-306) {
		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 (lambda1 <= (-1.7d+242)) then
        tmp = r_m * -lambda1
    else if (lambda1 <= (-1.45d-306)) 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 (lambda1 <= -1.7e+242) {
		tmp = R_m * -lambda1;
	} else if (lambda1 <= -1.45e-306) {
		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 lambda1 <= -1.7e+242:
		tmp = R_m * -lambda1
	elif lambda1 <= -1.45e-306:
		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 (lambda1 <= -1.7e+242)
		tmp = Float64(R_m * Float64(-lambda1));
	elseif (lambda1 <= -1.45e-306)
		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 (lambda1 <= -1.7e+242)
		tmp = R_m * -lambda1;
	elseif (lambda1 <= -1.45e-306)
		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[lambda1, -1.7e+242], N[(R$95$m * (-lambda1)), $MachinePrecision], If[LessEqual[lambda1, -1.45e-306], 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}\;\lambda_1 \leq -1.7 \cdot 10^{+242}:\\
\;\;\;\;R\_m \cdot \left(-\lambda_1\right)\\

\mathbf{elif}\;\lambda_1 \leq -1.45 \cdot 10^{-306}:\\
\;\;\;\;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 3 regimes
  2. if lambda1 < -1.69999999999999991e242

    1. Initial program 33.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-define80.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. Simplified80.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 lambda1 around -inf 44.4%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-R \cdot \lambda_1} \]
    11. Simplified56.6%

      \[\leadsto \color{blue}{-R \cdot \lambda_1} \]

    if -1.69999999999999991e242 < lambda1 < -1.4499999999999999e-306

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

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

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

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

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

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

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

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

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

    if -1.4499999999999999e-306 < lambda1

    1. Initial program 60.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-define97.5%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -1.7 \cdot 10^{+242}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq -1.45 \cdot 10^{-306}:\\ \;\;\;\;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 9: 29.2% 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 -1.9 \cdot 10^{-246}:\\ \;\;\;\;\phi_1 \cdot \left(R\_m \cdot \frac{\phi_2}{\phi_1} - R\_m\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 -1.9e-246)
    (* phi1 (- (* R_m (/ phi2 phi1)) R_m))
    (* 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 <= -1.9e-246) {
		tmp = phi1 * ((R_m * (phi2 / phi1)) - R_m);
	} 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 <= (-1.9d-246)) then
        tmp = phi1 * ((r_m * (phi2 / phi1)) - r_m)
    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 <= -1.9e-246) {
		tmp = phi1 * ((R_m * (phi2 / phi1)) - R_m);
	} 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 <= -1.9e-246:
		tmp = phi1 * ((R_m * (phi2 / phi1)) - R_m)
	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 <= -1.9e-246)
		tmp = Float64(phi1 * Float64(Float64(R_m * Float64(phi2 / phi1)) - R_m));
	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 <= -1.9e-246)
		tmp = phi1 * ((R_m * (phi2 / phi1)) - R_m);
	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, -1.9e-246], N[(phi1 * N[(N[(R$95$m * N[(phi2 / phi1), $MachinePrecision]), $MachinePrecision] - R$95$m), $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 -1.9 \cdot 10^{-246}:\\
\;\;\;\;\phi_1 \cdot \left(R\_m \cdot \frac{\phi_2}{\phi_1} - R\_m\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 < -1.89999999999999988e-246

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(-\phi_1\right) \cdot \left(R - \color{blue}{\frac{R \cdot \phi_2}{\phi_1}}\right) \]
    9. Step-by-step derivation
      1. associate-/l*54.8%

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

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

    if -1.89999999999999988e-246 < phi1

    1. Initial program 62.8%

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

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

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

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

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

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

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

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

Alternative 10: 32.1% 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}\;\lambda_1 \leq -1.15 \cdot 10^{+223}:\\ \;\;\;\;R\_m \cdot \left(-\lambda_1\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 (<= lambda1 -1.15e+223)
    (* R_m (- lambda1))
    (* 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 (lambda1 <= -1.15e+223) {
		tmp = R_m * -lambda1;
	} 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 (lambda1 <= (-1.15d+223)) then
        tmp = r_m * -lambda1
    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 (lambda1 <= -1.15e+223) {
		tmp = R_m * -lambda1;
	} 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 lambda1 <= -1.15e+223:
		tmp = R_m * -lambda1
	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 (lambda1 <= -1.15e+223)
		tmp = Float64(R_m * Float64(-lambda1));
	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 (lambda1 <= -1.15e+223)
		tmp = R_m * -lambda1;
	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[lambda1, -1.15e+223], N[(R$95$m * (-lambda1)), $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}\;\lambda_1 \leq -1.15 \cdot 10^{+223}:\\
\;\;\;\;R\_m \cdot \left(-\lambda_1\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 lambda1 < -1.15000000000000002e223

    1. Initial program 35.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-define82.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. Simplified82.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 lambda1 around -inf 40.1%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-R \cdot \lambda_1} \]
    11. Simplified56.3%

      \[\leadsto \color{blue}{-R \cdot \lambda_1} \]

    if -1.15000000000000002e223 < lambda1

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

Alternative 11: 30.2% 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 2.9 \cdot 10^{-54}:\\ \;\;\;\;R\_m \cdot \left(-\phi_1\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 2.9e-54)
    (* R_m (- phi1))
    (* 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 <= 2.9e-54) {
		tmp = R_m * -phi1;
	} 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 <= 2.9d-54) then
        tmp = r_m * -phi1
    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 <= 2.9e-54) {
		tmp = R_m * -phi1;
	} 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 <= 2.9e-54:
		tmp = R_m * -phi1
	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 <= 2.9e-54)
		tmp = Float64(R_m * Float64(-phi1));
	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 <= 2.9e-54)
		tmp = R_m * -phi1;
	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, 2.9e-54], N[(R$95$m * (-phi1)), $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 2.9 \cdot 10^{-54}:\\
\;\;\;\;R\_m \cdot \left(-\phi_1\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 < 2.90000000000000015e-54

    1. Initial program 63.3%

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

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

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

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

    if 2.90000000000000015e-54 < phi2

    1. Initial program 53.0%

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

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

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

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

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

      \[\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 12: 28.5% 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 -17000000000:\\ \;\;\;\;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 -17000000000.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 <= -17000000000.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 <= (-17000000000.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 <= -17000000000.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 <= -17000000000.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 <= -17000000000.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 <= -17000000000.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, -17000000000.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 -17000000000:\\
\;\;\;\;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 < -1.7e10

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

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

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

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

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

    if -1.7e10 < phi1

    1. Initial program 60.6%

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

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

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

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

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

Alternative 13: 25.9% 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_2 \leq 3.2 \cdot 10^{-36}:\\ \;\;\;\;R\_m \cdot \left(-\lambda_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 (<= phi2 3.2e-36) (* R_m (- lambda1)) (* 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 <= 3.2e-36) {
		tmp = R_m * -lambda1;
	} 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 <= 3.2d-36) then
        tmp = r_m * -lambda1
    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 <= 3.2e-36) {
		tmp = R_m * -lambda1;
	} 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 <= 3.2e-36:
		tmp = R_m * -lambda1
	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 <= 3.2e-36)
		tmp = Float64(R_m * Float64(-lambda1));
	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 <= 3.2e-36)
		tmp = R_m * -lambda1;
	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, 3.2e-36], N[(R$95$m * (-lambda1)), $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 3.2 \cdot 10^{-36}:\\
\;\;\;\;R\_m \cdot \left(-\lambda_1\right)\\

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


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

    1. Initial program 64.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-R \cdot \lambda_1} \]
    11. Simplified13.5%

      \[\leadsto \color{blue}{-R \cdot \lambda_1} \]

    if 3.20000000000000021e-36 < phi2

    1. Initial program 50.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-define91.8%

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

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

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

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

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

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

Alternative 14: 17.4% 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 60.3%

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

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

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

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

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

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

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

Alternative 15: 14.1% 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 60.3%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{-R \cdot \lambda_1} \]
  12. Step-by-step derivation
    1. add-sqr-sqrt7.6%

      \[\leadsto \color{blue}{\sqrt{-R \cdot \lambda_1} \cdot \sqrt{-R \cdot \lambda_1}} \]
    2. sqrt-unprod14.1%

      \[\leadsto \color{blue}{\sqrt{\left(-R \cdot \lambda_1\right) \cdot \left(-R \cdot \lambda_1\right)}} \]
    3. sqr-neg14.1%

      \[\leadsto \sqrt{\color{blue}{\left(R \cdot \lambda_1\right) \cdot \left(R \cdot \lambda_1\right)}} \]
    4. sqrt-unprod8.8%

      \[\leadsto \color{blue}{\sqrt{R \cdot \lambda_1} \cdot \sqrt{R \cdot \lambda_1}} \]
    5. add-sqr-sqrt14.5%

      \[\leadsto \color{blue}{R \cdot \lambda_1} \]
    6. *-commutative14.5%

      \[\leadsto \color{blue}{\lambda_1 \cdot R} \]
  13. Applied egg-rr14.5%

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

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

Reproduce

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