Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.5% → 99.9%
Time: 17.9s
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.5% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 0.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 95.8% accurate, 0.6× speedup?

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

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

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


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

    1. Initial program 43.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.5000000000000006e125 < lambda1

    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-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
  3. Recombined 2 regimes into one program.
  4. Final simplification96.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -7.5 \cdot 10^{+125}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right), \phi_1 - \phi_2\right)\\ \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: 79.3% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 58.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.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. Simplified91.4%

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

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

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

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

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

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

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

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

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

    if -3.29999999999999977e-8 < phi1

    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.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 phi1 around 0 53.7%

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

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

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

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

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

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

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

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

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

Alternative 4: 73.9% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 58.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.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. Simplified91.4%

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

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

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

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

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

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

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

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

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

    if -2.6499999999999999e-8 < phi1

    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.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 phi1 around 0 53.7%

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

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

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

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

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

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

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

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

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

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

Alternative 5: 95.7% accurate, 1.5× speedup?

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

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

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

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

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

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

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

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


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

    1. Initial program 58.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.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. Simplified91.4%

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

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

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

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

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

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

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

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

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

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

    if -1.69999999999999987e-7 < phi1

    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.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 phi1 around 0 53.7%

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

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

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

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

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

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

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

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

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

Alternative 7: 70.5% accurate, 3.0× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

    if 1.75e44 < phi2

    1. Initial program 54.9%

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

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

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

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

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

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

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

Alternative 8: 28.8% accurate, 13.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq -2.9 \cdot 10^{-153}:\\
\;\;\;\;R \cdot \left(-\lambda_1\right)\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if lambda2 < -2.90000000000000002e-153

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -\color{blue}{\lambda_1 \cdot R} \]
      3. distribute-rgt-neg-in14.9%

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

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

    if -2.90000000000000002e-153 < lambda2 < 1.00000000000000008e-86

    1. Initial program 71.2%

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

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

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

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

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

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

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

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

    if 1.00000000000000008e-86 < lambda2 < 3.40000000000000018e90

    1. Initial program 59.5%

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

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

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

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

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

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

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

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

    if 3.40000000000000018e90 < lambda2

    1. Initial program 50.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-define88.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. Simplified88.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 lambda2 around inf 53.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\lambda_2 \cdot R\right)} \cdot \cos \left(0.5 \cdot \phi_2\right) \]
    10. Simplified54.6%

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

      \[\leadsto \color{blue}{R \cdot \lambda_2} \]
    12. Step-by-step derivation
      1. *-commutative57.1%

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    13. Simplified57.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq -2.9 \cdot 10^{-153}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_2 \leq 10^{-86}:\\ \;\;\;\;\phi_1 \cdot \left(R \cdot \frac{\phi_2}{\phi_1} - R\right)\\ \mathbf{elif}\;\lambda_2 \leq 3.4 \cdot 10^{+90}:\\ \;\;\;\;\phi_2 \cdot \left(R - \frac{R \cdot \phi_1}{\phi_2}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \lambda_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 28.7% accurate, 13.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq -2.9 \cdot 10^{-153}:\\
\;\;\;\;R \cdot \left(-\lambda_1\right)\\

\mathbf{elif}\;\lambda_2 \leq 2.2 \cdot 10^{-86}:\\
\;\;\;\;\phi_1 \cdot \left(R \cdot \frac{\phi_2}{\phi_1} - R\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if lambda2 < -2.90000000000000002e-153

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -\color{blue}{\lambda_1 \cdot R} \]
      3. distribute-rgt-neg-in14.9%

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

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

    if -2.90000000000000002e-153 < lambda2 < 2.2000000000000002e-86

    1. Initial program 71.2%

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

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

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

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

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

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

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

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

    if 2.2000000000000002e-86 < lambda2 < 3.6e90

    1. Initial program 59.5%

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

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

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

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

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

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

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

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

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

    if 3.6e90 < lambda2

    1. Initial program 50.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-define88.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. Simplified88.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 lambda2 around inf 53.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\lambda_2 \cdot R\right)} \cdot \cos \left(0.5 \cdot \phi_2\right) \]
    10. Simplified54.6%

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

      \[\leadsto \color{blue}{R \cdot \lambda_2} \]
    12. Step-by-step derivation
      1. *-commutative57.1%

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    13. Simplified57.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq -2.9 \cdot 10^{-153}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_2 \leq 2.2 \cdot 10^{-86}:\\ \;\;\;\;\phi_1 \cdot \left(R \cdot \frac{\phi_2}{\phi_1} - R\right)\\ \mathbf{elif}\;\lambda_2 \leq 3.6 \cdot 10^{+90}:\\ \;\;\;\;\phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \lambda_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 29.1% accurate, 17.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq -7.7 \cdot 10^{-156}:\\
\;\;\;\;R \cdot \left(-\lambda_1\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if lambda2 < -7.6999999999999997e-156

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -\color{blue}{\lambda_1 \cdot R} \]
      3. distribute-rgt-neg-in14.9%

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

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

    if -7.6999999999999997e-156 < lambda2 < 2.85000000000000009e90

    1. Initial program 67.2%

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

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

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

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

    if 2.85000000000000009e90 < lambda2

    1. Initial program 50.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-define88.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. Simplified88.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 lambda2 around inf 53.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\lambda_2 \cdot R\right)} \cdot \cos \left(0.5 \cdot \phi_2\right) \]
    10. Simplified54.6%

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

      \[\leadsto \color{blue}{R \cdot \lambda_2} \]
    12. Step-by-step derivation
      1. *-commutative57.1%

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    13. Simplified57.1%

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

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

Alternative 11: 29.1% accurate, 17.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq -2.8 \cdot 10^{-147}:\\
\;\;\;\;R \cdot \left(-\lambda_1\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if lambda2 < -2.8e-147

    1. Initial program 56.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.8e-147 < lambda2 < 3.40000000000000018e90

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

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

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

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

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

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

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

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

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

    if 3.40000000000000018e90 < lambda2

    1. Initial program 50.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-define88.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. Simplified88.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 lambda2 around inf 53.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\lambda_2 \cdot R\right)} \cdot \cos \left(0.5 \cdot \phi_2\right) \]
    10. Simplified54.6%

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

      \[\leadsto \color{blue}{R \cdot \lambda_2} \]
    12. Step-by-step derivation
      1. *-commutative57.1%

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    13. Simplified57.1%

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

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

Alternative 12: 28.5% accurate, 25.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -0.0175:\\
\;\;\;\;-R \cdot \phi_1\\

\mathbf{elif}\;\phi_1 \leq -1.35 \cdot 10^{-240}:\\
\;\;\;\;R \cdot \lambda_2\\

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


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

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

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

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

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

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

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

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

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

    if -0.017500000000000002 < phi1 < -1.35000000000000009e-240

    1. Initial program 66.8%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\lambda_2 \cdot R\right)} \cdot \cos \left(0.5 \cdot \phi_2\right) \]
    10. Simplified28.3%

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

      \[\leadsto \color{blue}{R \cdot \lambda_2} \]
    12. Step-by-step derivation
      1. *-commutative24.5%

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    13. Simplified24.5%

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

    if -1.35000000000000009e-240 < phi1

    1. Initial program 60.2%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -0.0175:\\ \;\;\;\;-R \cdot \phi_1\\ \mathbf{elif}\;\phi_1 \leq -1.35 \cdot 10^{-240}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 23.3% accurate, 25.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq -6 \cdot 10^{-175}:\\
\;\;\;\;R \cdot \left(-\lambda_1\right)\\

\mathbf{elif}\;\lambda_2 \leq 5 \cdot 10^{+70}:\\
\;\;\;\;R \cdot \phi_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if lambda2 < -6e-175

    1. Initial program 59.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -6e-175 < lambda2 < 5.0000000000000002e70

    1. Initial program 67.9%

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

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

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

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

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

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

    if 5.0000000000000002e70 < lambda2

    1. Initial program 47.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-define86.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. Simplified86.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 lambda2 around inf 50.1%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\lambda_2 \cdot R\right)} \cdot \cos \left(0.5 \cdot \phi_2\right) \]
    10. Simplified51.1%

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

      \[\leadsto \color{blue}{R \cdot \lambda_2} \]
    12. Step-by-step derivation
      1. *-commutative53.5%

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    13. Simplified53.5%

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

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

Alternative 14: 25.5% accurate, 41.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 1.72 \cdot 10^{+44}:\\
\;\;\;\;R \cdot \lambda_2\\

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


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

    1. Initial program 63.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-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 lambda2 around inf 18.1%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\lambda_2 \cdot R\right)} \cdot \cos \left(0.5 \cdot \phi_2\right) \]
    10. Simplified16.6%

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

      \[\leadsto \color{blue}{R \cdot \lambda_2} \]
    12. Step-by-step derivation
      1. *-commutative15.9%

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    13. Simplified15.9%

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

    if 1.72e44 < phi2

    1. Initial program 54.9%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 1.72 \cdot 10^{+44}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 14.5% accurate, 109.7× speedup?

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

\\
R \cdot \lambda_2
\end{array}
Derivation
  1. Initial program 61.3%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\lambda_2 \cdot R\right)} \cdot \cos \left(0.5 \cdot \phi_2\right) \]
  10. Simplified15.2%

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

    \[\leadsto \color{blue}{R \cdot \lambda_2} \]
  12. Step-by-step derivation
    1. *-commutative13.7%

      \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
  13. Simplified13.7%

    \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
  14. Final simplification13.7%

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

Reproduce

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