Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.5% → 99.9%
Time: 28.6s
Alternatives: 18
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 18 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 58.9%

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

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

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

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

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

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\cos \left(0.5 \cdot \color{blue}{\left(\phi_2 + \phi_1\right)}\right)}\right), \phi_1 - \phi_2\right) \]
    3. distribute-lft-in96.1%

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

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\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), \phi_1 - \phi_2\right) \]
    5. *-commutative99.8%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\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), \phi_1 - \phi_2\right) \]
    6. *-commutative99.8%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\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), \phi_1 - \phi_2\right) \]
    7. *-commutative99.8%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\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), \phi_1 - \phi_2\right) \]
    8. *-commutative99.8%

      \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\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), \phi_1 - \phi_2\right) \]
  8. Applied egg-rr99.8%

    \[\leadsto R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \log \left(e^{\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), \phi_1 - \phi_2\right) \]
  9. Step-by-step derivation
    1. rem-log-exp99.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: 70.1% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_1 \leq -4.8 \cdot 10^{+65}:\\ \;\;\;\;\phi_1 \cdot \left(R \cdot \frac{\phi_2}{\phi_1} - R\right)\\ \mathbf{elif}\;\phi_1 \leq 3.2 \cdot 10^{-115} \lor \neg \left(\phi_1 \leq 7.2 \cdot 10^{-62}\right):\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \lambda_1 - \lambda_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \lambda_1 \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi1 -4.8e+65)
   (* phi1 (- (* R (/ phi2 phi1)) R))
   (if (or (<= phi1 3.2e-115) (not (<= phi1 7.2e-62)))
     (* R (hypot phi2 (- lambda1 lambda2)))
     (* R (hypot phi2 (* lambda1 (cos (* phi2 0.5))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -4.8e+65) {
		tmp = phi1 * ((R * (phi2 / phi1)) - R);
	} else if ((phi1 <= 3.2e-115) || !(phi1 <= 7.2e-62)) {
		tmp = R * hypot(phi2, (lambda1 - lambda2));
	} else {
		tmp = R * hypot(phi2, (lambda1 * cos((phi2 * 0.5))));
	}
	return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi1 <= -4.8e+65) {
		tmp = phi1 * ((R * (phi2 / phi1)) - R);
	} else if ((phi1 <= 3.2e-115) || !(phi1 <= 7.2e-62)) {
		tmp = R * Math.hypot(phi2, (lambda1 - lambda2));
	} else {
		tmp = R * Math.hypot(phi2, (lambda1 * Math.cos((phi2 * 0.5))));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi1 <= -4.8e+65:
		tmp = phi1 * ((R * (phi2 / phi1)) - R)
	elif (phi1 <= 3.2e-115) or not (phi1 <= 7.2e-62):
		tmp = R * math.hypot(phi2, (lambda1 - lambda2))
	else:
		tmp = R * math.hypot(phi2, (lambda1 * math.cos((phi2 * 0.5))))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi1 <= -4.8e+65)
		tmp = Float64(phi1 * Float64(Float64(R * Float64(phi2 / phi1)) - R));
	elseif ((phi1 <= 3.2e-115) || !(phi1 <= 7.2e-62))
		tmp = Float64(R * hypot(phi2, Float64(lambda1 - lambda2)));
	else
		tmp = Float64(R * hypot(phi2, Float64(lambda1 * cos(Float64(phi2 * 0.5)))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if (phi1 <= -4.8e+65)
		tmp = phi1 * ((R * (phi2 / phi1)) - R);
	elseif ((phi1 <= 3.2e-115) || ~((phi1 <= 7.2e-62)))
		tmp = R * hypot(phi2, (lambda1 - lambda2));
	else
		tmp = R * hypot(phi2, (lambda1 * cos((phi2 * 0.5))));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -4.8e+65], N[(phi1 * N[(N[(R * N[(phi2 / phi1), $MachinePrecision]), $MachinePrecision] - R), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[phi1, 3.2e-115], N[Not[LessEqual[phi1, 7.2e-62]], $MachinePrecision]], N[(R * N[Sqrt[phi2 ^ 2 + N[(lambda1 - lambda2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[phi2 ^ 2 + N[(lambda1 * N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;\phi_1 \leq 3.2 \cdot 10^{-115} \lor \neg \left(\phi_1 \leq 7.2 \cdot 10^{-62}\right):\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\phi_2, \lambda_1 - \lambda_2\right)\\

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


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

    1. Initial program 60.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-define90.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. Simplified90.7%

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

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

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

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

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

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

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

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

    if -4.8000000000000003e65 < phi1 < 3.2e-115 or 7.1999999999999999e-62 < phi1

    1. Initial program 58.1%

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

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

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

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

      \[\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 74.4%

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

    if 3.2e-115 < phi1 < 7.1999999999999999e-62

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 82.4% accurate, 1.5× speedup?

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

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


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

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

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

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

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

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

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

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

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

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

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

      \[\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 1e-61 < phi2

    1. Initial program 55.5%

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

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

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

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

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

Alternative 4: 92.8% accurate, 1.5× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

      \[\leadsto e^{\log \left(R \cdot \mathsf{hypot}\left(\color{blue}{\cos \left(0.5 \cdot \phi_1\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\right)} \]
    8. Step-by-step derivation
      1. rem-exp-log94.6%

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

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

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

    if 2.6e22 < phi2

    1. Initial program 50.9%

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

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

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

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

Alternative 5: 76.9% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 7 \cdot 10^{+54}:\\
\;\;\;\;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 \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\\


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

    1. Initial program 63.2%

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

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

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

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

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

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

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

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

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

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

      \[\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 7.0000000000000002e54 < phi2

    1. Initial program 47.8%

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

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

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

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

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

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

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

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

        \[\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-define88.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. Simplified88.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 78.4%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 7 \cdot 10^{+54}:\\ \;\;\;\;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 \cdot \cos \left(\phi_2 \cdot 0.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 78.6% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 3.2 \cdot 10^{+50}:\\ \;\;\;\;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 (<= phi2 3.2e+50)
   (* 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 (phi2 <= 3.2e+50) {
		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 (phi2 <= 3.2e+50) {
		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 phi2 <= 3.2e+50:
		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 (phi2 <= 3.2e+50)
		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 (phi2 <= 3.2e+50)
		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[phi2, 3.2e+50], 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_2 \leq 3.2 \cdot 10^{+50}:\\
\;\;\;\;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 phi2 < 3.19999999999999983e50

    1. Initial program 63.2%

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

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

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

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

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

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

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

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

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

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

      \[\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.19999999999999983e50 < phi2

    1. Initial program 47.8%

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

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

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

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

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

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

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

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

        \[\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-define88.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. Simplified88.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)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification82.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 3.2 \cdot 10^{+50}:\\ \;\;\;\;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 7: 95.9% 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 58.9%

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

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

Alternative 8: 70.9% accurate, 3.0× speedup?

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

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


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

    1. Initial program 60.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-define90.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. Simplified90.7%

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

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

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

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

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

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

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

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

    if -1.50000000000000001e66 < phi1

    1. Initial program 58.5%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. hypot-define97.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. Simplified97.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 51.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. +-commutative51.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. unpow251.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. unpow251.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. unpow251.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-sqr51.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-define83.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. Simplified83.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 phi2 around 0 74.4%

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

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

Alternative 9: 32.0% accurate, 9.7× speedup?

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

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

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

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

\mathbf{elif}\;\phi_1 \leq 8 \cdot 10^{-206}:\\
\;\;\;\;R \cdot \phi_2\\

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

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


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

    1. Initial program 53.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-define89.3%

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

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

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

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

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

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

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

    if -5.59999999999999999e124 < phi1 < -0.52000000000000002

    1. Initial program 73.2%

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

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

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

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

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

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

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

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

    if -0.52000000000000002 < phi1 < 6.50000000000000045e-259

    1. Initial program 63.3%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -\color{blue}{\left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}{\lambda_1} + R \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \lambda_1} \]
      3. distribute-rgt-neg-in35.5%

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

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

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

        \[\leadsto \color{blue}{\left(R \cdot \cos \left(0.5 \cdot \phi_1\right) - \frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}{\lambda_1}\right)} \cdot \left(-\lambda_1\right) \]
      7. *-commutative35.5%

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

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

        \[\leadsto \left(\cos \left(0.5 \cdot \phi_1\right) \cdot R - R \cdot \color{blue}{\left(\lambda_2 \cdot \frac{\cos \left(0.5 \cdot \phi_1\right)}{\lambda_1}\right)}\right) \cdot \left(-\lambda_1\right) \]
    10. Simplified32.0%

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

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

        \[\leadsto \color{blue}{-\lambda_1 \cdot \left(R - \frac{R \cdot \lambda_2}{\lambda_1}\right)} \]
      2. distribute-rgt-neg-in35.5%

        \[\leadsto \color{blue}{\lambda_1 \cdot \left(-\left(R - \frac{R \cdot \lambda_2}{\lambda_1}\right)\right)} \]
      3. associate-/l*32.0%

        \[\leadsto \lambda_1 \cdot \left(-\left(R - \color{blue}{R \cdot \frac{\lambda_2}{\lambda_1}}\right)\right) \]
    13. Simplified32.0%

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

    if 6.50000000000000045e-259 < phi1 < 8.00000000000000023e-206

    1. Initial program 41.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-define99.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. Simplified99.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 55.0%

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

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

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

    if 8.00000000000000023e-206 < phi1 < 6.99999999999999947e-110

    1. Initial program 71.6%

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

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

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

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

      \[\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 lambda2 around inf 52.0%

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

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

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

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

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

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

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

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

        \[\leadsto \lambda_2 \cdot \left(R - \frac{\color{blue}{\lambda_1 \cdot R}}{\lambda_2}\right) \]
      2. associate-/l*44.8%

        \[\leadsto \lambda_2 \cdot \left(R - \color{blue}{\lambda_1 \cdot \frac{R}{\lambda_2}}\right) \]
    13. Simplified44.8%

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

    if 6.99999999999999947e-110 < phi1

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

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

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

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

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

        \[\leadsto e^{\log \left(R \cdot \mathsf{hypot}\left(\cos \color{blue}{\left(\left(\phi_1 + \phi_2\right) \cdot \frac{1}{2}\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\right)} \]
      4. metadata-eval53.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -5.6 \cdot 10^{+124}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -0.52:\\ \;\;\;\;\phi_2 \cdot \left(R - \phi_1 \cdot \frac{R}{\phi_2}\right)\\ \mathbf{elif}\;\phi_1 \leq 6.5 \cdot 10^{-259}:\\ \;\;\;\;\lambda_1 \cdot \left(R \cdot \frac{\lambda_2}{\lambda_1} - R\right)\\ \mathbf{elif}\;\phi_1 \leq 8 \cdot 10^{-206}:\\ \;\;\;\;R \cdot \phi_2\\ \mathbf{elif}\;\phi_1 \leq 7 \cdot 10^{-110}:\\ \;\;\;\;\lambda_2 \cdot \left(R - \lambda_1 \cdot \frac{R}{\lambda_2}\right)\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot \left(R - R \cdot \frac{\phi_1}{\phi_2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 32.3% accurate, 9.7× speedup?

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

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

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

\mathbf{elif}\;\phi_2 \leq 1.5 \cdot 10^{-273}:\\
\;\;\;\;R \cdot \left(-\phi_1\right)\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 6 regimes
  2. if phi2 < -1.2e-192

    1. Initial program 55.3%

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

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

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

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

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

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

    if -1.2e-192 < phi2 < 4.50000000000000005e-286

    1. Initial program 64.7%

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

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

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

        \[\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-define52.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. Simplified52.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 lambda2 around inf 35.4%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\lambda_2 \cdot \left(R - \frac{R \cdot \lambda_1}{\lambda_2}\right)} \]
    12. Step-by-step derivation
      1. *-commutative35.4%

        \[\leadsto \lambda_2 \cdot \left(R - \frac{\color{blue}{\lambda_1 \cdot R}}{\lambda_2}\right) \]
      2. associate-/l*40.7%

        \[\leadsto \lambda_2 \cdot \left(R - \color{blue}{\lambda_1 \cdot \frac{R}{\lambda_2}}\right) \]
    13. Simplified40.7%

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

    if 4.50000000000000005e-286 < phi2 < 1.49999999999999994e-273

    1. Initial program 100.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-define100.0%

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

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

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

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

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

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

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

    if 1.49999999999999994e-273 < phi2 < 1.85000000000000002e-178

    1. Initial program 78.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-define100.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}{\lambda_1} + R \cdot \cos \left(0.5 \cdot \phi_1\right)\right)} \]
      2. *-commutative25.2%

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

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

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

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

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

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

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

        \[\leadsto \left(\cos \left(0.5 \cdot \phi_1\right) \cdot R - R \cdot \color{blue}{\left(\lambda_2 \cdot \frac{\cos \left(0.5 \cdot \phi_1\right)}{\lambda_1}\right)}\right) \cdot \left(-\lambda_1\right) \]
    10. Simplified25.2%

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

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

        \[\leadsto \color{blue}{-\lambda_1 \cdot \left(R - \frac{R \cdot \lambda_2}{\lambda_1}\right)} \]
      2. distribute-rgt-neg-in26.4%

        \[\leadsto \color{blue}{\lambda_1 \cdot \left(-\left(R - \frac{R \cdot \lambda_2}{\lambda_1}\right)\right)} \]
      3. associate-/l*26.4%

        \[\leadsto \lambda_1 \cdot \left(-\left(R - \color{blue}{R \cdot \frac{\lambda_2}{\lambda_1}}\right)\right) \]
    13. Simplified26.4%

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

    if 1.85000000000000002e-178 < phi2 < 2.4e-9

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.4e-9 < phi2

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

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

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

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

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

        \[\leadsto e^{\log \left(R \cdot \mathsf{hypot}\left(\cos \color{blue}{\left(\left(\phi_1 + \phi_2\right) \cdot \frac{1}{2}\right)} \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\right)} \]
      4. metadata-eval46.8%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -1.2 \cdot 10^{-192}:\\ \;\;\;\;\phi_2 \cdot \left(R - \frac{R \cdot \phi_1}{\phi_2}\right)\\ \mathbf{elif}\;\phi_2 \leq 4.5 \cdot 10^{-286}:\\ \;\;\;\;\lambda_2 \cdot \left(R - \lambda_1 \cdot \frac{R}{\lambda_2}\right)\\ \mathbf{elif}\;\phi_2 \leq 1.5 \cdot 10^{-273}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_2 \leq 1.85 \cdot 10^{-178}:\\ \;\;\;\;\lambda_1 \cdot \left(R \cdot \frac{\lambda_2}{\lambda_1} - R\right)\\ \mathbf{elif}\;\phi_2 \leq 2.4 \cdot 10^{-9}:\\ \;\;\;\;\lambda_2 \cdot \left(R - \frac{R \cdot \lambda_1}{\lambda_2}\right)\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot \left(R - R \cdot \frac{\phi_1}{\phi_2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 32.2% accurate, 11.3× speedup?

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

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

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

\mathbf{elif}\;\phi_1 \leq 1.15 \cdot 10^{-207}:\\
\;\;\;\;R \cdot \phi_2\\

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

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


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

    1. Initial program 61.8%

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

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

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

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

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

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

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

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

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

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

    if -0.225000000000000006 < phi1 < 4.5999999999999999e-259

    1. Initial program 63.3%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -\color{blue}{\left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}{\lambda_1} + R \cdot \cos \left(0.5 \cdot \phi_1\right)\right) \cdot \lambda_1} \]
      3. distribute-rgt-neg-in35.5%

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

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

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

        \[\leadsto \color{blue}{\left(R \cdot \cos \left(0.5 \cdot \phi_1\right) - \frac{R \cdot \left(\lambda_2 \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}{\lambda_1}\right)} \cdot \left(-\lambda_1\right) \]
      7. *-commutative35.5%

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

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

        \[\leadsto \left(\cos \left(0.5 \cdot \phi_1\right) \cdot R - R \cdot \color{blue}{\left(\lambda_2 \cdot \frac{\cos \left(0.5 \cdot \phi_1\right)}{\lambda_1}\right)}\right) \cdot \left(-\lambda_1\right) \]
    10. Simplified32.0%

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

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

        \[\leadsto \color{blue}{-\lambda_1 \cdot \left(R - \frac{R \cdot \lambda_2}{\lambda_1}\right)} \]
      2. distribute-rgt-neg-in35.5%

        \[\leadsto \color{blue}{\lambda_1 \cdot \left(-\left(R - \frac{R \cdot \lambda_2}{\lambda_1}\right)\right)} \]
      3. associate-/l*32.0%

        \[\leadsto \lambda_1 \cdot \left(-\left(R - \color{blue}{R \cdot \frac{\lambda_2}{\lambda_1}}\right)\right) \]
    13. Simplified32.0%

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

    if 4.5999999999999999e-259 < phi1 < 1.15e-207

    1. Initial program 41.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-define99.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. Simplified99.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 55.0%

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

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

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

    if 1.15e-207 < phi1 < 6e-103

    1. Initial program 73.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-define99.6%

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

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

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

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

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

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

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

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

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

      \[\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 lambda2 around inf 54.3%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\lambda_2 \cdot \left(R - \frac{R \cdot \lambda_1}{\lambda_2}\right)} \]
    12. Step-by-step derivation
      1. *-commutative47.5%

        \[\leadsto \lambda_2 \cdot \left(R - \frac{\color{blue}{\lambda_1 \cdot R}}{\lambda_2}\right) \]
      2. associate-/l*47.5%

        \[\leadsto \lambda_2 \cdot \left(R - \color{blue}{\lambda_1 \cdot \frac{R}{\lambda_2}}\right) \]
    13. Simplified47.5%

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

    if 6e-103 < phi1

    1. Initial program 50.5%

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

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

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

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

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

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

        \[\leadsto e^{\log \left(R \cdot \mathsf{hypot}\left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot \color{blue}{0.5}\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\right)} \]
    6. Applied egg-rr52.4%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -0.225:\\ \;\;\;\;\phi_1 \cdot \left(R \cdot \frac{\phi_2}{\phi_1} - R\right)\\ \mathbf{elif}\;\phi_1 \leq 4.6 \cdot 10^{-259}:\\ \;\;\;\;\lambda_1 \cdot \left(R \cdot \frac{\lambda_2}{\lambda_1} - R\right)\\ \mathbf{elif}\;\phi_1 \leq 1.15 \cdot 10^{-207}:\\ \;\;\;\;R \cdot \phi_2\\ \mathbf{elif}\;\phi_1 \leq 6 \cdot 10^{-103}:\\ \;\;\;\;\lambda_2 \cdot \left(R - \lambda_1 \cdot \frac{R}{\lambda_2}\right)\\ \mathbf{else}:\\ \;\;\;\;\phi_2 \cdot \left(R - R \cdot \frac{\phi_1}{\phi_2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 26.2% accurate, 13.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := R \cdot \left(-\lambda_1\right)\\ \mathbf{if}\;\phi_2 \leq 3.8 \cdot 10^{-268}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{elif}\;\phi_2 \leq 1.35 \cdot 10^{-178}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_2 \leq 8 \cdot 10^{-58}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{elif}\;\phi_2 \leq 1.55 \cdot 10^{-9}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* R (- lambda1))))
   (if (<= phi2 3.8e-268)
     (* R lambda2)
     (if (<= phi2 1.35e-178)
       t_0
       (if (<= phi2 8e-58)
         (* R lambda2)
         (if (<= phi2 1.55e-9) t_0 (* R phi2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * -lambda1;
	double tmp;
	if (phi2 <= 3.8e-268) {
		tmp = R * lambda2;
	} else if (phi2 <= 1.35e-178) {
		tmp = t_0;
	} else if (phi2 <= 8e-58) {
		tmp = R * lambda2;
	} else if (phi2 <= 1.55e-9) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = r * -lambda1
    if (phi2 <= 3.8d-268) then
        tmp = r * lambda2
    else if (phi2 <= 1.35d-178) then
        tmp = t_0
    else if (phi2 <= 8d-58) then
        tmp = r * lambda2
    else if (phi2 <= 1.55d-9) then
        tmp = t_0
    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 t_0 = R * -lambda1;
	double tmp;
	if (phi2 <= 3.8e-268) {
		tmp = R * lambda2;
	} else if (phi2 <= 1.35e-178) {
		tmp = t_0;
	} else if (phi2 <= 8e-58) {
		tmp = R * lambda2;
	} else if (phi2 <= 1.55e-9) {
		tmp = t_0;
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = R * -lambda1
	tmp = 0
	if phi2 <= 3.8e-268:
		tmp = R * lambda2
	elif phi2 <= 1.35e-178:
		tmp = t_0
	elif phi2 <= 8e-58:
		tmp = R * lambda2
	elif phi2 <= 1.55e-9:
		tmp = t_0
	else:
		tmp = R * phi2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(R * Float64(-lambda1))
	tmp = 0.0
	if (phi2 <= 3.8e-268)
		tmp = Float64(R * lambda2);
	elseif (phi2 <= 1.35e-178)
		tmp = t_0;
	elseif (phi2 <= 8e-58)
		tmp = Float64(R * lambda2);
	elseif (phi2 <= 1.55e-9)
		tmp = t_0;
	else
		tmp = Float64(R * phi2);
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = R * -lambda1;
	tmp = 0.0;
	if (phi2 <= 3.8e-268)
		tmp = R * lambda2;
	elseif (phi2 <= 1.35e-178)
		tmp = t_0;
	elseif (phi2 <= 8e-58)
		tmp = R * lambda2;
	elseif (phi2 <= 1.55e-9)
		tmp = t_0;
	else
		tmp = R * phi2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(R * (-lambda1)), $MachinePrecision]}, If[LessEqual[phi2, 3.8e-268], N[(R * lambda2), $MachinePrecision], If[LessEqual[phi2, 1.35e-178], t$95$0, If[LessEqual[phi2, 8e-58], N[(R * lambda2), $MachinePrecision], If[LessEqual[phi2, 1.55e-9], t$95$0, N[(R * phi2), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := R \cdot \left(-\lambda_1\right)\\
\mathbf{if}\;\phi_2 \leq 3.8 \cdot 10^{-268}:\\
\;\;\;\;R \cdot \lambda_2\\

\mathbf{elif}\;\phi_2 \leq 1.35 \cdot 10^{-178}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\phi_2 \leq 8 \cdot 10^{-58}:\\
\;\;\;\;R \cdot \lambda_2\\

\mathbf{elif}\;\phi_2 \leq 1.55 \cdot 10^{-9}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if phi2 < 3.8000000000000002e-268 or 1.35000000000000004e-178 < phi2 < 8.0000000000000002e-58

    1. Initial program 58.5%

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

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

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

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

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

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

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

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

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

      \[\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 21.9%

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

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

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

      \[\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 20.2%

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

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    13. Simplified20.2%

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

    if 3.8000000000000002e-268 < phi2 < 1.35000000000000004e-178 or 8.0000000000000002e-58 < phi2 < 1.55000000000000002e-9

    1. Initial program 77.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.55000000000000002e-9 < phi2

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 3.8 \cdot 10^{-268}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{elif}\;\phi_2 \leq 1.35 \cdot 10^{-178}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\phi_2 \leq 8 \cdot 10^{-58}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{elif}\;\phi_2 \leq 1.55 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 28.2% accurate, 13.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := R \cdot \left(-\lambda_1\right)\\ \mathbf{if}\;\phi_2 \leq 2.1 \cdot 10^{-219}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_2 \leq 8.5 \cdot 10^{-177}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\phi_2 \leq 3.5 \cdot 10^{-58}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{elif}\;\phi_2 \leq 2.45 \cdot 10^{-9}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (* R (- lambda1))))
   (if (<= phi2 2.1e-219)
     (* R (- phi1))
     (if (<= phi2 8.5e-177)
       t_0
       (if (<= phi2 3.5e-58)
         (* R lambda2)
         (if (<= phi2 2.45e-9) t_0 (* R phi2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = R * -lambda1;
	double tmp;
	if (phi2 <= 2.1e-219) {
		tmp = R * -phi1;
	} else if (phi2 <= 8.5e-177) {
		tmp = t_0;
	} else if (phi2 <= 3.5e-58) {
		tmp = R * lambda2;
	} else if (phi2 <= 2.45e-9) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = r * -lambda1
    if (phi2 <= 2.1d-219) then
        tmp = r * -phi1
    else if (phi2 <= 8.5d-177) then
        tmp = t_0
    else if (phi2 <= 3.5d-58) then
        tmp = r * lambda2
    else if (phi2 <= 2.45d-9) then
        tmp = t_0
    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 t_0 = R * -lambda1;
	double tmp;
	if (phi2 <= 2.1e-219) {
		tmp = R * -phi1;
	} else if (phi2 <= 8.5e-177) {
		tmp = t_0;
	} else if (phi2 <= 3.5e-58) {
		tmp = R * lambda2;
	} else if (phi2 <= 2.45e-9) {
		tmp = t_0;
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = R * -lambda1
	tmp = 0
	if phi2 <= 2.1e-219:
		tmp = R * -phi1
	elif phi2 <= 8.5e-177:
		tmp = t_0
	elif phi2 <= 3.5e-58:
		tmp = R * lambda2
	elif phi2 <= 2.45e-9:
		tmp = t_0
	else:
		tmp = R * phi2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(R * Float64(-lambda1))
	tmp = 0.0
	if (phi2 <= 2.1e-219)
		tmp = Float64(R * Float64(-phi1));
	elseif (phi2 <= 8.5e-177)
		tmp = t_0;
	elseif (phi2 <= 3.5e-58)
		tmp = Float64(R * lambda2);
	elseif (phi2 <= 2.45e-9)
		tmp = t_0;
	else
		tmp = Float64(R * phi2);
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = R * -lambda1;
	tmp = 0.0;
	if (phi2 <= 2.1e-219)
		tmp = R * -phi1;
	elseif (phi2 <= 8.5e-177)
		tmp = t_0;
	elseif (phi2 <= 3.5e-58)
		tmp = R * lambda2;
	elseif (phi2 <= 2.45e-9)
		tmp = t_0;
	else
		tmp = R * phi2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(R * (-lambda1)), $MachinePrecision]}, If[LessEqual[phi2, 2.1e-219], N[(R * (-phi1)), $MachinePrecision], If[LessEqual[phi2, 8.5e-177], t$95$0, If[LessEqual[phi2, 3.5e-58], N[(R * lambda2), $MachinePrecision], If[LessEqual[phi2, 2.45e-9], t$95$0, N[(R * phi2), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := R \cdot \left(-\lambda_1\right)\\
\mathbf{if}\;\phi_2 \leq 2.1 \cdot 10^{-219}:\\
\;\;\;\;R \cdot \left(-\phi_1\right)\\

\mathbf{elif}\;\phi_2 \leq 8.5 \cdot 10^{-177}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\phi_2 \leq 3.5 \cdot 10^{-58}:\\
\;\;\;\;R \cdot \lambda_2\\

\mathbf{elif}\;\phi_2 \leq 2.45 \cdot 10^{-9}:\\
\;\;\;\;t\_0\\

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


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

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

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

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

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

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

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

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

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

    if 2.1e-219 < phi2 < 8.4999999999999993e-177 or 3.4999999999999999e-58 < phi2 < 2.45000000000000002e-9

    1. Initial program 79.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-define100.0%

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

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

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

      \[\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 lambda2 around inf 23.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\lambda_1 \cdot \left(-R\right)} \]
    16. Simplified28.8%

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

    if 8.4999999999999993e-177 < phi2 < 3.4999999999999999e-58

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

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

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

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

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

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

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

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

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

      \[\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 33.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*33.3%

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

        \[\leadsto \color{blue}{\left(\lambda_2 \cdot R\right)} \cdot \cos \left(0.5 \cdot \phi_2\right) \]
    10. Simplified33.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 33.3%

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

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    13. Simplified33.3%

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

    if 2.45000000000000002e-9 < phi2

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 2.1 \cdot 10^{-219}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_2 \leq 8.5 \cdot 10^{-177}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\phi_2 \leq 3.5 \cdot 10^{-58}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{elif}\;\phi_2 \leq 2.45 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 32.9% accurate, 13.7× speedup?

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

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

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

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

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


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

    1. Initial program 53.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-define89.3%

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

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

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

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

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

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

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

    if -5.80000000000000043e124 < phi1 < -0.19

    1. Initial program 73.2%

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

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

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

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

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

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

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

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

    if -0.19 < phi1 < 7.6000000000000001e-103

    1. Initial program 62.6%

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

      \[\leadsto \color{blue}{R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in phi1 around 0 60.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. +-commutative60.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. unpow260.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. unpow260.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. unpow260.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-sqr60.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-define98.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. Simplified98.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 lambda2 around inf 39.7%

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

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

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

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

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

        \[\leadsto \lambda_2 \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot R - \frac{\color{blue}{\left(R \cdot \lambda_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right)}}{\lambda_2}\right) \]
    10. Simplified39.7%

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

      \[\leadsto \color{blue}{\lambda_2 \cdot \left(R - \frac{R \cdot \lambda_1}{\lambda_2}\right)} \]
    12. Step-by-step derivation
      1. *-commutative33.2%

        \[\leadsto \lambda_2 \cdot \left(R - \frac{\color{blue}{\lambda_1 \cdot R}}{\lambda_2}\right) \]
      2. associate-/l*31.6%

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

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

    if 7.6000000000000001e-103 < phi1

    1. Initial program 50.5%

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

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

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

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

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

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

        \[\leadsto e^{\log \left(R \cdot \mathsf{hypot}\left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot \color{blue}{0.5}\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1 - \phi_2\right)\right)} \]
    6. Applied egg-rr52.4%

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

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

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

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

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

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

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

Alternative 15: 31.2% accurate, 17.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq -1.2 \cdot 10^{-192} \lor \neg \left(\phi_2 \leq 2.45 \cdot 10^{-9}\right):\\ \;\;\;\;\phi_2 \cdot \left(R - R \cdot \frac{\phi_1}{\phi_2}\right)\\ \mathbf{else}:\\ \;\;\;\;\lambda_2 \cdot \left(R - \lambda_1 \cdot \frac{R}{\lambda_2}\right)\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (or (<= phi2 -1.2e-192) (not (<= phi2 2.45e-9)))
   (* phi2 (- R (* R (/ phi1 phi2))))
   (* lambda2 (- R (* lambda1 (/ R lambda2))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if ((phi2 <= -1.2e-192) || !(phi2 <= 2.45e-9)) {
		tmp = phi2 * (R - (R * (phi1 / phi2)));
	} else {
		tmp = lambda2 * (R - (lambda1 * (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 ((phi2 <= (-1.2d-192)) .or. (.not. (phi2 <= 2.45d-9))) then
        tmp = phi2 * (r - (r * (phi1 / phi2)))
    else
        tmp = lambda2 * (r - (lambda1 * (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 ((phi2 <= -1.2e-192) || !(phi2 <= 2.45e-9)) {
		tmp = phi2 * (R - (R * (phi1 / phi2)));
	} else {
		tmp = lambda2 * (R - (lambda1 * (R / lambda2)));
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if (phi2 <= -1.2e-192) or not (phi2 <= 2.45e-9):
		tmp = phi2 * (R - (R * (phi1 / phi2)))
	else:
		tmp = lambda2 * (R - (lambda1 * (R / lambda2)))
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if ((phi2 <= -1.2e-192) || !(phi2 <= 2.45e-9))
		tmp = Float64(phi2 * Float64(R - Float64(R * Float64(phi1 / phi2))));
	else
		tmp = Float64(lambda2 * Float64(R - Float64(lambda1 * Float64(R / lambda2))));
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0;
	if ((phi2 <= -1.2e-192) || ~((phi2 <= 2.45e-9)))
		tmp = phi2 * (R - (R * (phi1 / phi2)));
	else
		tmp = lambda2 * (R - (lambda1 * (R / lambda2)));
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[Or[LessEqual[phi2, -1.2e-192], N[Not[LessEqual[phi2, 2.45e-9]], $MachinePrecision]], N[(phi2 * N[(R - N[(R * N[(phi1 / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(lambda2 * N[(R - N[(lambda1 * N[(R / lambda2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq -1.2 \cdot 10^{-192} \lor \neg \left(\phi_2 \leq 2.45 \cdot 10^{-9}\right):\\
\;\;\;\;\phi_2 \cdot \left(R - R \cdot \frac{\phi_1}{\phi_2}\right)\\

\mathbf{else}:\\
\;\;\;\;\lambda_2 \cdot \left(R - \lambda_1 \cdot \frac{R}{\lambda_2}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if phi2 < -1.2e-192 or 2.45000000000000002e-9 < phi2

    1. Initial program 54.2%

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

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

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

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

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

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

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

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

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

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

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

    if -1.2e-192 < phi2 < 2.45000000000000002e-9

    1. Initial program 70.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-define100.0%

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

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

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

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

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

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

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

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

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

      \[\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 lambda2 around inf 33.0%

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

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

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

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

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

        \[\leadsto \lambda_2 \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot R - \frac{\color{blue}{\left(R \cdot \lambda_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right)}}{\lambda_2}\right) \]
    10. Simplified33.0%

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

      \[\leadsto \color{blue}{\lambda_2 \cdot \left(R - \frac{R \cdot \lambda_1}{\lambda_2}\right)} \]
    12. Step-by-step derivation
      1. *-commutative33.0%

        \[\leadsto \lambda_2 \cdot \left(R - \frac{\color{blue}{\lambda_1 \cdot R}}{\lambda_2}\right) \]
      2. associate-/l*34.3%

        \[\leadsto \lambda_2 \cdot \left(R - \color{blue}{\lambda_1 \cdot \frac{R}{\lambda_2}}\right) \]
    13. Simplified34.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq -1.2 \cdot 10^{-192} \lor \neg \left(\phi_2 \leq 2.45 \cdot 10^{-9}\right):\\ \;\;\;\;\phi_2 \cdot \left(R - R \cdot \frac{\phi_1}{\phi_2}\right)\\ \mathbf{else}:\\ \;\;\;\;\lambda_2 \cdot \left(R - \lambda_1 \cdot \frac{R}{\lambda_2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 16: 31.4% accurate, 17.3× speedup?

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

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

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

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


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

    1. Initial program 52.9%

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

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

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

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

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

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

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

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

    if -8.0000000000000002e-127 < phi2 < 3.7000000000000001e95

    1. Initial program 71.3%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\lambda_2 \cdot \left(R - \frac{R \cdot \lambda_1}{\lambda_2}\right)} \]
    12. Step-by-step derivation
      1. *-commutative29.2%

        \[\leadsto \lambda_2 \cdot \left(R - \frac{\color{blue}{\lambda_1 \cdot R}}{\lambda_2}\right) \]
      2. associate-/l*29.2%

        \[\leadsto \lambda_2 \cdot \left(R - \color{blue}{\lambda_1 \cdot \frac{R}{\lambda_2}}\right) \]
    13. Simplified29.2%

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

    if 3.7000000000000001e95 < phi2

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

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

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

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

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

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

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

Alternative 17: 26.4% accurate, 41.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 2.45 \cdot 10^{-9}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (if (<= phi2 2.45e-9) (* R lambda2) (* R phi2)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double tmp;
	if (phi2 <= 2.45e-9) {
		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 <= 2.45d-9) 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 <= 2.45e-9) {
		tmp = R * lambda2;
	} else {
		tmp = R * phi2;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	tmp = 0
	if phi2 <= 2.45e-9:
		tmp = R * lambda2
	else:
		tmp = R * phi2
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	tmp = 0.0
	if (phi2 <= 2.45e-9)
		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 <= 2.45e-9)
		tmp = R * lambda2;
	else
		tmp = R * phi2;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 2.45e-9], N[(R * lambda2), $MachinePrecision], N[(R * phi2), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 2.45 \cdot 10^{-9}:\\
\;\;\;\;R \cdot \lambda_2\\

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


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

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

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

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

        \[\leadsto \color{blue}{\left(R \cdot \cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right) \cdot \lambda_2} \]
      3. *-commutative19.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*19.3%

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

        \[\leadsto \cos \left(0.5 \cdot \color{blue}{\left(\phi_2 + \phi_1\right)}\right) \cdot \left(R \cdot \lambda_2\right) \]
    7. Simplified19.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 19.8%

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

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

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

      \[\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 18.4%

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

        \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
    13. Simplified18.4%

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

    if 2.45000000000000002e-9 < phi2

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

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

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

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

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

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

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

Alternative 18: 14.7% 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 58.9%

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

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

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

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

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

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

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

    \[\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 17.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*17.6%

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

      \[\leadsto \color{blue}{\left(\lambda_2 \cdot R\right)} \cdot \cos \left(0.5 \cdot \phi_2\right) \]
  10. Simplified17.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.6%

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

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

    \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
  14. Final simplification15.6%

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

Reproduce

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