Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.7% → 96.2%
Time: 17.2s
Alternatives: 15
Speedup: 3.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 15 alternatives:

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

Initial Program: 59.7% accurate, 1.0× speedup?

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

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

Alternative 1: 96.2% accurate, 1.5× speedup?

\[\begin{array}{l} \\ 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) \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R
  (hypot (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0))) (- phi1 phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * hypot(((lambda1 - lambda2) * cos(((phi1 + phi2) / 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(((phi1 + phi2) / 2.0))), (phi1 - phi2));
}
def code(R, lambda1, lambda2, phi1, phi2):
	return R * math.hypot(((lambda1 - lambda2) * math.cos(((phi1 + phi2) / 2.0))), (phi1 - phi2))
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(R * hypot(Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi1 + phi2) / 2.0))), Float64(phi1 - phi2)))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = R * hypot(((lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0))), (phi1 - phi2));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[Sqrt[N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(N[(phi1 + phi2), $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_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 57.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. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
    2. hypot-defineN/A

      \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
    3. hypot-lowering-hypot.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
    5. --lowering--.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    6. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    7. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    8. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    9. --lowering--.f6497.4%

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\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. Add Preprocessing

Alternative 2: 80.1% accurate, 1.5× speedup?

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

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

\mathbf{elif}\;\lambda_2 \leq 7 \cdot 10^{+156}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_1 - \phi_2\right)\\

\mathbf{else}:\\
\;\;\;\;\left(R \cdot \lambda_2\right) \cdot \sqrt{0.5 + 0.5 \cdot \cos \left(\phi_1 + \phi_2\right)}\\


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

    1. Initial program 56.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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
      2. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
      3. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      9. --lowering--.f6497.3%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\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 phi2 around 0

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6490.4%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified90.4%

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    9. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \lambda_1\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\cos \left(\frac{1}{2} \cdot \phi_1\right), \lambda_1\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_1\right)\right), \lambda_1\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. *-lowering-*.f6475.2%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right), \lambda_1\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    10. Simplified75.2%

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

    if 5.0000000000000005e-196 < lambda2 < 7.0000000000000006e156

    1. Initial program 63.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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
      2. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
      3. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      9. --lowering--.f6499.9%

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

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6495.1%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified95.1%

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\lambda_1 - \lambda_2\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    9. Step-by-step derivation
      1. --lowering--.f6492.0%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
    10. Simplified92.0%

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

    if 7.0000000000000006e156 < lambda2

    1. Initial program 45.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. Add Preprocessing
    3. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{sqrt.f64}\left(\left(\left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right) + \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)\right)\right)\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\left(\left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\right), \left(\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)\right)\right)\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\left(\phi_1 - \phi_2\right), \left(\phi_1 - \phi_2\right)\right), \left(\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)\right)\right)\right)\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\phi_1, \phi_2\right), \left(\phi_1 - \phi_2\right)\right), \left(\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)\right)\right)\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\phi_1, \phi_2\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right), \left(\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)\right)\right)\right)\right) \]
      6. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\phi_1, \phi_2\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right), \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right)\right)\right)\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\phi_1, \phi_2\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right), \mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right)\right)\right)\right)\right) \]
      8. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\phi_1, \phi_2\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right)\right)\right)\right)\right) \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\phi_1, \phi_2\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right)\right)\right) \]
      10. associate-*r*N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\phi_1, \phi_2\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \left(\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\phi_1, \phi_2\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right), \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{*.f64}\left(\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\right)\right) \]
    4. Applied egg-rr45.8%

      \[\leadsto R \cdot \sqrt{\color{blue}{\left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right) + \left(\lambda_1 - \lambda_2\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(\left(\phi_1 + \phi_2\right) \cdot 1\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}} \]
    5. Taylor expanded in lambda2 around inf

      \[\leadsto \color{blue}{\left(R \cdot \lambda_2\right) \cdot \sqrt{\frac{1}{2} + \frac{1}{2} \cdot \cos \left(\phi_1 + \phi_2\right)}} \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(R \cdot \lambda_2\right), \color{blue}{\left(\sqrt{\frac{1}{2} + \frac{1}{2} \cdot \cos \left(\phi_1 + \phi_2\right)}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_2\right), \left(\sqrt{\color{blue}{\frac{1}{2} + \frac{1}{2} \cdot \cos \left(\phi_1 + \phi_2\right)}}\right)\right) \]
      3. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_2\right), \mathsf{sqrt.f64}\left(\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(\phi_1 + \phi_2\right)\right)\right)\right) \]
      4. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_2\right), \mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\frac{1}{2}, \left(\frac{1}{2} \cdot \cos \left(\phi_1 + \phi_2\right)\right)\right)\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_2\right), \mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\frac{1}{2}, \cos \left(\phi_1 + \phi_2\right)\right)\right)\right)\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_2\right), \mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{cos.f64}\left(\left(\phi_1 + \phi_2\right)\right)\right)\right)\right)\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_2\right), \mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{cos.f64}\left(\left(\phi_2 + \phi_1\right)\right)\right)\right)\right)\right) \]
      8. +-lowering-+.f6481.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_2\right), \mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(\phi_2, \phi_1\right)\right)\right)\right)\right)\right) \]
    7. Simplified81.8%

      \[\leadsto \color{blue}{\left(R \cdot \lambda_2\right) \cdot \sqrt{0.5 + 0.5 \cdot \cos \left(\phi_2 + \phi_1\right)}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification80.4%

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

Alternative 3: 93.2% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\phi_2 \leq 5 \cdot 10^{-29}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\phi_1 \cdot 0.5\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 5e-29)
   (* R (hypot (* (- lambda1 lambda2) (cos (* phi1 0.5))) (- 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 <= 5e-29) {
		tmp = R * hypot(((lambda1 - lambda2) * cos((phi1 * 0.5))), (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 <= 5e-29) {
		tmp = R * Math.hypot(((lambda1 - lambda2) * Math.cos((phi1 * 0.5))), (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 <= 5e-29:
		tmp = R * math.hypot(((lambda1 - lambda2) * math.cos((phi1 * 0.5))), (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 <= 5e-29)
		tmp = Float64(R * hypot(Float64(Float64(lambda1 - lambda2) * cos(Float64(phi1 * 0.5))), 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 <= 5e-29)
		tmp = R * hypot(((lambda1 - lambda2) * cos((phi1 * 0.5))), (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, 5e-29], N[(R * N[Sqrt[N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(phi1 * 0.5), $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 5 \cdot 10^{-29}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\phi_1 \cdot 0.5\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 < 4.99999999999999986e-29

    1. Initial program 58.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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
      2. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
      3. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      9. --lowering--.f6498.8%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
    3. Simplified98.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 0

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6493.5%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified93.5%

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

    if 4.99999999999999986e-29 < phi2

    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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
      2. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
      3. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      9. --lowering--.f6494.4%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
    3. Simplified94.4%

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6494.4%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified94.4%

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

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

Alternative 4: 80.1% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 57.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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
      2. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
      3. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      9. --lowering--.f6497.2%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
    3. Simplified97.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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6490.4%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified90.4%

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    9. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \lambda_1\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\cos \left(\frac{1}{2} \cdot \phi_1\right), \lambda_1\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_1\right)\right), \lambda_1\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. *-lowering-*.f6475.0%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right), \lambda_1\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    10. Simplified75.0%

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

    if 9.99999999999999982e-200 < lambda2

    1. Initial program 57.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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
      2. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
      3. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      9. --lowering--.f6497.6%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
    3. Simplified97.6%

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6490.7%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified90.7%

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\lambda_1 - \lambda_2\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    9. Step-by-step derivation
      1. --lowering--.f6485.7%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
    10. Simplified85.7%

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

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

Alternative 5: 90.8% accurate, 1.6× speedup?

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

      \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
    2. hypot-defineN/A

      \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
    3. hypot-lowering-hypot.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
    5. --lowering--.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    6. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    7. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    8. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    9. --lowering--.f6497.4%

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\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 phi2 around 0

    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
  6. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
    3. --lowering--.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    4. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    5. *-lowering-*.f6490.5%

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
  7. Simplified90.5%

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

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

Alternative 6: 71.3% accurate, 3.0× speedup?

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

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

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


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

    1. Initial program 45.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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
      2. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
      3. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      9. --lowering--.f6495.0%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
    3. Simplified95.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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6484.6%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified84.6%

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

      \[\leadsto \color{blue}{R \cdot \sqrt{{\phi_1}^{2} + {\left(\lambda_1 - \lambda_2\right)}^{2}}} \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\sqrt{{\phi_1}^{2} + {\left(\lambda_1 - \lambda_2\right)}^{2}}\right)}\right) \]
      2. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\sqrt{{\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right) + {\phi_1}^{2}}\right)\right) \]
      4. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right) + \phi_1 \cdot \phi_1}\right)\right) \]
      5. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\lambda_1 - \lambda_2, \color{blue}{\phi_1}\right)\right)\right) \]
      6. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\lambda_1 - \lambda_2\right), \color{blue}{\phi_1}\right)\right) \]
      7. --lowering--.f6477.4%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \phi_1\right)\right) \]
    10. Simplified77.4%

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

    if -4.50000000000000032e40 < phi1

    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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
      2. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
      3. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      9. --lowering--.f6498.1%

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

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6489.1%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified89.1%

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

      \[\leadsto \color{blue}{R \cdot \sqrt{{\phi_2}^{2} + {\left(\lambda_1 - \lambda_2\right)}^{2}}} \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\sqrt{{\phi_2}^{2} + {\left(\lambda_1 - \lambda_2\right)}^{2}}\right)}\right) \]
      2. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\sqrt{{\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_2}^{2}}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right) + {\phi_2}^{2}}\right)\right) \]
      4. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right) + \phi_2 \cdot \phi_2}\right)\right) \]
      5. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\lambda_1 - \lambda_2, \color{blue}{\phi_2}\right)\right)\right) \]
      6. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\lambda_1 - \lambda_2\right), \color{blue}{\phi_2}\right)\right) \]
      7. --lowering--.f6472.9%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \phi_2\right)\right) \]
    10. Simplified72.9%

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

Alternative 7: 71.0% accurate, 3.0× speedup?

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

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

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


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

    1. Initial program 56.7%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
      2. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
      3. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      9. --lowering--.f6499.0%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
    3. Simplified99.0%

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6491.8%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified91.8%

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

      \[\leadsto \color{blue}{R \cdot \sqrt{{\phi_1}^{2} + {\left(\lambda_1 - \lambda_2\right)}^{2}}} \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\sqrt{{\phi_1}^{2} + {\left(\lambda_1 - \lambda_2\right)}^{2}}\right)}\right) \]
      2. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\sqrt{{\left(\lambda_1 - \lambda_2\right)}^{2} + {\phi_1}^{2}}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right) + {\phi_1}^{2}}\right)\right) \]
      4. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right) + \phi_1 \cdot \phi_1}\right)\right) \]
      5. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\lambda_1 - \lambda_2, \color{blue}{\phi_1}\right)\right)\right) \]
      6. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\lambda_1 - \lambda_2\right), \color{blue}{\phi_1}\right)\right) \]
      7. --lowering--.f6470.7%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \phi_1\right)\right) \]
    10. Simplified70.7%

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

    if 3.4e52 < phi2

    1. Initial program 58.3%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi2 around inf

      \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)}\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\phi_2, \color{blue}{\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)}\right)\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\phi_2, \left(1 + \left(\mathsf{neg}\left(\frac{\phi_1}{\phi_2}\right)\right)\right)\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\phi_2, \left(1 - \color{blue}{\frac{\phi_1}{\phi_2}}\right)\right)\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\phi_2, \mathsf{\_.f64}\left(1, \color{blue}{\left(\frac{\phi_1}{\phi_2}\right)}\right)\right)\right) \]
      5. /-lowering-/.f6480.4%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\phi_2, \mathsf{\_.f64}\left(1, \mathsf{/.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right)\right) \]
    5. Simplified80.4%

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

Alternative 8: 85.2% accurate, 3.0× speedup?

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

\\
R \cdot \mathsf{hypot}\left(\lambda_1 - \lambda_2, \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 57.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. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
    2. hypot-defineN/A

      \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
    3. hypot-lowering-hypot.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
    5. --lowering--.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    6. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    7. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    8. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    9. --lowering--.f6497.4%

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\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 phi2 around 0

    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
  6. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
    3. --lowering--.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    4. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    5. *-lowering-*.f6490.5%

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
  7. Simplified90.5%

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

    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\lambda_1 - \lambda_2\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
  9. Step-by-step derivation
    1. --lowering--.f6485.2%

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
  10. Simplified85.2%

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

Alternative 9: 29.9% accurate, 17.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq -7 \cdot 10^{-117}:\\
\;\;\;\;0 - R \cdot \lambda_1\\

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

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


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

    1. Initial program 51.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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
      2. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
      3. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      9. --lowering--.f6495.7%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
    3. Simplified95.7%

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6489.0%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified89.0%

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)} \]
    9. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(R \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{R \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)} \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left(R \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)}\right) \]
      4. associate-*r*N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \left(\left(R \cdot \lambda_1\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_2\right)}\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\left(R \cdot \lambda_1\right), \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_2\right)}\right)\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_1\right), \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_2\right)}\right)\right) \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_1\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right)\right)\right) \]
      8. *-lowering-*.f6411.4%

        \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_1\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right)\right) \]
    10. Simplified11.4%

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

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

        \[\leadsto \mathsf{neg}\left(R \cdot \lambda_1\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{R \cdot \lambda_1} \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left(R \cdot \lambda_1\right)}\right) \]
      4. *-lowering-*.f649.5%

        \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(R, \color{blue}{\lambda_1}\right)\right) \]
    13. Simplified9.5%

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

    if -6.9999999999999997e-117 < lambda2 < 1.9000000000000001e130

    1. Initial program 64.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. Add Preprocessing
    3. Taylor expanded in phi1 around -inf

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

        \[\leadsto \mathsf{neg}\left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{neg}\left(\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right) \cdot \phi_1\right) \]
      3. distribute-rgt-neg-inN/A

        \[\leadsto \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right) \cdot \color{blue}{\left(\mathsf{neg}\left(\phi_1\right)\right)} \]
      4. mul-1-negN/A

        \[\leadsto \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right) \cdot \left(-1 \cdot \color{blue}{\phi_1}\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right), \color{blue}{\left(-1 \cdot \phi_1\right)}\right) \]
      6. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\left(R + \left(\mathsf{neg}\left(\frac{R \cdot \phi_2}{\phi_1}\right)\right)\right), \left(-1 \cdot \phi_1\right)\right) \]
      7. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\left(R - \frac{R \cdot \phi_2}{\phi_1}\right), \left(\color{blue}{-1} \cdot \phi_1\right)\right) \]
      8. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(R, \left(\frac{R \cdot \phi_2}{\phi_1}\right)\right), \left(\color{blue}{-1} \cdot \phi_1\right)\right) \]
      9. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(R, \mathsf{/.f64}\left(\left(R \cdot \phi_2\right), \phi_1\right)\right), \left(-1 \cdot \phi_1\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(R, \mathsf{/.f64}\left(\mathsf{*.f64}\left(R, \phi_2\right), \phi_1\right)\right), \left(-1 \cdot \phi_1\right)\right) \]
      11. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(R, \mathsf{/.f64}\left(\mathsf{*.f64}\left(R, \phi_2\right), \phi_1\right)\right), \left(\mathsf{neg}\left(\phi_1\right)\right)\right) \]
      12. neg-sub0N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(R, \mathsf{/.f64}\left(\mathsf{*.f64}\left(R, \phi_2\right), \phi_1\right)\right), \left(0 - \color{blue}{\phi_1}\right)\right) \]
      13. --lowering--.f6441.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(R, \mathsf{/.f64}\left(\mathsf{*.f64}\left(R, \phi_2\right), \phi_1\right)\right), \mathsf{\_.f64}\left(0, \color{blue}{\phi_1}\right)\right) \]
    5. Simplified41.3%

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

    if 1.9000000000000001e130 < lambda2

    1. Initial program 48.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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
      2. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
      3. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      9. --lowering--.f6493.8%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
    3. Simplified93.8%

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6485.4%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified85.4%

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

      \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\lambda_2 \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + -1 \cdot \frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)\right)}\right) \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + -1 \cdot \frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)}\right)\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + \left(\mathsf{neg}\left(\frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)\right)\right)\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) - \color{blue}{\frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}}\right)\right)\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\cos \left(\frac{1}{2} \cdot \phi_2\right), \color{blue}{\left(\frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)}\right)\right)\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right), \left(\frac{\color{blue}{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}}{\lambda_2}\right)\right)\right)\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \left(\frac{\color{blue}{\lambda_1} \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \color{blue}{\lambda_2}\right)\right)\right)\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \lambda_1\right), \lambda_2\right)\right)\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\mathsf{*.f64}\left(\cos \left(\frac{1}{2} \cdot \phi_2\right), \lambda_1\right), \lambda_2\right)\right)\right)\right) \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right), \lambda_1\right), \lambda_2\right)\right)\right)\right) \]
      11. *-lowering-*.f6451.7%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \lambda_1\right), \lambda_2\right)\right)\right)\right) \]
    10. Simplified51.7%

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

      \[\leadsto \color{blue}{R \cdot \left(\lambda_2 \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)} \]
    12. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\lambda_2 \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \color{blue}{\left(1 - \frac{\lambda_1}{\lambda_2}\right)}\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(1, \color{blue}{\left(\frac{\lambda_1}{\lambda_2}\right)}\right)\right)\right) \]
      4. /-lowering-/.f6460.8%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(1, \mathsf{/.f64}\left(\lambda_1, \color{blue}{\lambda_2}\right)\right)\right)\right) \]
    13. Simplified60.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_2 \leq -7 \cdot 10^{-117}:\\ \;\;\;\;0 - R \cdot \lambda_1\\ \mathbf{elif}\;\lambda_2 \leq 1.9 \cdot 10^{+130}:\\ \;\;\;\;\phi_1 \cdot \left(\frac{R \cdot \phi_2}{\phi_1} - R\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\lambda_2 \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 29.9% accurate, 17.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq -7 \cdot 10^{-117}:\\
\;\;\;\;0 - R \cdot \lambda_1\\

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

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


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

    1. Initial program 51.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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
      2. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
      3. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      9. --lowering--.f6495.7%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
    3. Simplified95.7%

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6489.0%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified89.0%

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

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)} \]
    9. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(R \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{R \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)} \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left(R \cdot \left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)}\right) \]
      4. associate-*r*N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \left(\left(R \cdot \lambda_1\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_2\right)}\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\left(R \cdot \lambda_1\right), \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_2\right)}\right)\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_1\right), \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_2\right)}\right)\right) \]
      7. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_1\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right)\right)\right) \]
      8. *-lowering-*.f6411.4%

        \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_1\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right)\right) \]
    10. Simplified11.4%

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

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

        \[\leadsto \mathsf{neg}\left(R \cdot \lambda_1\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{R \cdot \lambda_1} \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left(R \cdot \lambda_1\right)}\right) \]
      4. *-lowering-*.f649.5%

        \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(R, \color{blue}{\lambda_1}\right)\right) \]
    13. Simplified9.5%

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

    if -6.9999999999999997e-117 < lambda2 < 3.8999999999999997e128

    1. Initial program 64.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. Add Preprocessing
    3. Taylor expanded in phi2 around inf

      \[\leadsto \color{blue}{\phi_2 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_1}{\phi_2}\right)} \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\phi_2, \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_1}{\phi_2}\right)}\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\phi_2, \left(R + \left(\mathsf{neg}\left(\frac{R \cdot \phi_1}{\phi_2}\right)\right)\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\phi_2, \left(R - \color{blue}{\frac{R \cdot \phi_1}{\phi_2}}\right)\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\phi_2, \mathsf{\_.f64}\left(R, \color{blue}{\left(\frac{R \cdot \phi_1}{\phi_2}\right)}\right)\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\phi_2, \mathsf{\_.f64}\left(R, \mathsf{/.f64}\left(\left(R \cdot \phi_1\right), \color{blue}{\phi_2}\right)\right)\right) \]
      6. *-lowering-*.f6441.6%

        \[\leadsto \mathsf{*.f64}\left(\phi_2, \mathsf{\_.f64}\left(R, \mathsf{/.f64}\left(\mathsf{*.f64}\left(R, \phi_1\right), \phi_2\right)\right)\right) \]
    5. Simplified41.6%

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

    if 3.8999999999999997e128 < lambda2

    1. Initial program 48.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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
      2. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
      3. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      9. --lowering--.f6493.8%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
    3. Simplified93.8%

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6485.4%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified85.4%

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

      \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\lambda_2 \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + -1 \cdot \frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)\right)}\right) \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + -1 \cdot \frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)}\right)\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + \left(\mathsf{neg}\left(\frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)\right)\right)\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) - \color{blue}{\frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}}\right)\right)\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\cos \left(\frac{1}{2} \cdot \phi_2\right), \color{blue}{\left(\frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)}\right)\right)\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right), \left(\frac{\color{blue}{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}}{\lambda_2}\right)\right)\right)\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \left(\frac{\color{blue}{\lambda_1} \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \color{blue}{\lambda_2}\right)\right)\right)\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \lambda_1\right), \lambda_2\right)\right)\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\mathsf{*.f64}\left(\cos \left(\frac{1}{2} \cdot \phi_2\right), \lambda_1\right), \lambda_2\right)\right)\right)\right) \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right), \lambda_1\right), \lambda_2\right)\right)\right)\right) \]
      11. *-lowering-*.f6451.7%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \lambda_1\right), \lambda_2\right)\right)\right)\right) \]
    10. Simplified51.7%

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

      \[\leadsto \color{blue}{R \cdot \left(\lambda_2 \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)} \]
    12. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\lambda_2 \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \color{blue}{\left(1 - \frac{\lambda_1}{\lambda_2}\right)}\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(1, \color{blue}{\left(\frac{\lambda_1}{\lambda_2}\right)}\right)\right)\right) \]
      4. /-lowering-/.f6460.8%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(1, \mathsf{/.f64}\left(\lambda_1, \color{blue}{\lambda_2}\right)\right)\right)\right) \]
    13. Simplified60.8%

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

Alternative 11: 32.1% accurate, 17.3× speedup?

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

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

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

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


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

    1. Initial program 56.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. Add Preprocessing
    3. Taylor expanded in phi1 around -inf

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right)} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(R \cdot \phi_1\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{R \cdot \phi_1} \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left(R \cdot \phi_1\right)}\right) \]
      4. *-lowering-*.f6421.1%

        \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(R, \color{blue}{\phi_1}\right)\right) \]
    5. Simplified21.1%

      \[\leadsto \color{blue}{0 - R \cdot \phi_1} \]
    6. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \mathsf{neg}\left(R \cdot \phi_1\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{neg}\left(\phi_1 \cdot R\right) \]
      3. distribute-lft-neg-inN/A

        \[\leadsto \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \color{blue}{R} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\mathsf{neg}\left(\phi_1\right)\right), \color{blue}{R}\right) \]
      5. neg-lowering-neg.f6421.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{neg.f64}\left(\phi_1\right), R\right) \]
    7. Applied egg-rr21.1%

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

    if 2.29999999999999995e-279 < phi2 < 2.05e-7

    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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
      2. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
      3. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      9. --lowering--.f64100.0%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6488.4%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified88.4%

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

      \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\lambda_2 \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + -1 \cdot \frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)\right)}\right) \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + -1 \cdot \frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)}\right)\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + \left(\mathsf{neg}\left(\frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)\right)\right)\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) - \color{blue}{\frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}}\right)\right)\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\cos \left(\frac{1}{2} \cdot \phi_2\right), \color{blue}{\left(\frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)}\right)\right)\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right), \left(\frac{\color{blue}{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}}{\lambda_2}\right)\right)\right)\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \left(\frac{\color{blue}{\lambda_1} \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \color{blue}{\lambda_2}\right)\right)\right)\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \lambda_1\right), \lambda_2\right)\right)\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\mathsf{*.f64}\left(\cos \left(\frac{1}{2} \cdot \phi_2\right), \lambda_1\right), \lambda_2\right)\right)\right)\right) \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right), \lambda_1\right), \lambda_2\right)\right)\right)\right) \]
      11. *-lowering-*.f6428.5%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \lambda_1\right), \lambda_2\right)\right)\right)\right) \]
    10. Simplified28.5%

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

      \[\leadsto \color{blue}{R \cdot \left(\lambda_2 \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)} \]
    12. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\lambda_2 \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \color{blue}{\left(1 - \frac{\lambda_1}{\lambda_2}\right)}\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(1, \color{blue}{\left(\frac{\lambda_1}{\lambda_2}\right)}\right)\right)\right) \]
      4. /-lowering-/.f6428.5%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(1, \mathsf{/.f64}\left(\lambda_1, \color{blue}{\lambda_2}\right)\right)\right)\right) \]
    13. Simplified28.5%

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

    if 2.05e-7 < phi2

    1. Initial program 54.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. Add Preprocessing
    3. Taylor expanded in phi2 around inf

      \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)}\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\phi_2, \color{blue}{\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)}\right)\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\phi_2, \left(1 + \left(\mathsf{neg}\left(\frac{\phi_1}{\phi_2}\right)\right)\right)\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\phi_2, \left(1 - \color{blue}{\frac{\phi_1}{\phi_2}}\right)\right)\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\phi_2, \mathsf{\_.f64}\left(1, \color{blue}{\left(\frac{\phi_1}{\phi_2}\right)}\right)\right)\right) \]
      5. /-lowering-/.f6470.0%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\phi_2, \mathsf{\_.f64}\left(1, \mathsf{/.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right)\right) \]
    5. Simplified70.0%

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

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

Alternative 12: 30.7% accurate, 17.3× speedup?

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

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

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

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


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

    1. Initial program 45.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. Add Preprocessing
    3. Taylor expanded in phi1 around -inf

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right)} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(R \cdot \phi_1\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{R \cdot \phi_1} \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left(R \cdot \phi_1\right)}\right) \]
      4. *-lowering-*.f6470.9%

        \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(R, \color{blue}{\phi_1}\right)\right) \]
    5. Simplified70.9%

      \[\leadsto \color{blue}{0 - R \cdot \phi_1} \]
    6. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \mathsf{neg}\left(R \cdot \phi_1\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{neg}\left(\phi_1 \cdot R\right) \]
      3. distribute-lft-neg-inN/A

        \[\leadsto \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \color{blue}{R} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\mathsf{neg}\left(\phi_1\right)\right), \color{blue}{R}\right) \]
      5. neg-lowering-neg.f6470.9%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{neg.f64}\left(\phi_1\right), R\right) \]
    7. Applied egg-rr70.9%

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

    if -2.16000000000000003e49 < phi1 < 2.4999999999999998e-246

    1. Initial program 68.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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
      2. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
      3. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      9. --lowering--.f6499.7%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
    3. Simplified99.7%

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6498.0%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified98.0%

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

      \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\lambda_2 \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + -1 \cdot \frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)\right)}\right) \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + -1 \cdot \frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)}\right)\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) + \left(\mathsf{neg}\left(\frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)\right)\right)\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) - \color{blue}{\frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}}\right)\right)\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\cos \left(\frac{1}{2} \cdot \phi_2\right), \color{blue}{\left(\frac{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)}\right)\right)\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right), \left(\frac{\color{blue}{\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}}{\lambda_2}\right)\right)\right)\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \left(\frac{\color{blue}{\lambda_1} \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)}{\lambda_2}\right)\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\left(\lambda_1 \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right), \color{blue}{\lambda_2}\right)\right)\right)\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \lambda_1\right), \lambda_2\right)\right)\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\mathsf{*.f64}\left(\cos \left(\frac{1}{2} \cdot \phi_2\right), \lambda_1\right), \lambda_2\right)\right)\right)\right) \]
      10. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_2\right)\right), \lambda_1\right), \lambda_2\right)\right)\right)\right) \]
      11. *-lowering-*.f6429.0%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_2\right)\right), \lambda_1\right), \lambda_2\right)\right)\right)\right) \]
    10. Simplified29.0%

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

      \[\leadsto \color{blue}{R \cdot \left(\lambda_2 \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)} \]
    12. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\lambda_2 \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \color{blue}{\left(1 - \frac{\lambda_1}{\lambda_2}\right)}\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(1, \color{blue}{\left(\frac{\lambda_1}{\lambda_2}\right)}\right)\right)\right) \]
      4. /-lowering-/.f6429.1%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{*.f64}\left(\lambda_2, \mathsf{\_.f64}\left(1, \mathsf{/.f64}\left(\lambda_1, \color{blue}{\lambda_2}\right)\right)\right)\right) \]
    13. Simplified29.1%

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

    if 2.4999999999999998e-246 < phi1

    1. Initial program 53.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. Add Preprocessing
    3. Taylor expanded in phi2 around inf

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

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\phi_2}\right) \]
    5. Simplified22.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -2.16 \cdot 10^{+49}:\\ \;\;\;\;R \cdot \left(0 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq 2.5 \cdot 10^{-246}:\\ \;\;\;\;R \cdot \left(\lambda_2 \cdot \left(1 - \frac{\lambda_1}{\lambda_2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 28.1% accurate, 32.8× speedup?

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

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

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


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

    1. Initial program 44.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. Add Preprocessing
    3. Taylor expanded in phi1 around -inf

      \[\leadsto \color{blue}{-1 \cdot \left(R \cdot \phi_1\right)} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(R \cdot \phi_1\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{R \cdot \phi_1} \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left(R \cdot \phi_1\right)}\right) \]
      4. *-lowering-*.f6465.0%

        \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(R, \color{blue}{\phi_1}\right)\right) \]
    5. Simplified65.0%

      \[\leadsto \color{blue}{0 - R \cdot \phi_1} \]
    6. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \mathsf{neg}\left(R \cdot \phi_1\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{neg}\left(\phi_1 \cdot R\right) \]
      3. distribute-lft-neg-inN/A

        \[\leadsto \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \color{blue}{R} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\mathsf{neg}\left(\phi_1\right)\right), \color{blue}{R}\right) \]
      5. neg-lowering-neg.f6465.0%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{neg.f64}\left(\phi_1\right), R\right) \]
    7. Applied egg-rr65.0%

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

    if -2e20 < phi1

    1. Initial program 61.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. Add Preprocessing
    3. Taylor expanded in phi2 around inf

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

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\phi_2}\right) \]
    5. Simplified25.2%

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

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

Alternative 14: 25.6% accurate, 41.0× speedup?

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

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

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


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

    1. Initial program 56.7%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
      2. hypot-defineN/A

        \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
      3. hypot-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
      9. --lowering--.f6499.0%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\right) \]
    3. Simplified99.0%

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

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
      5. *-lowering-*.f6491.9%

        \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    7. Simplified91.9%

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

      \[\leadsto \color{blue}{R \cdot \left(\lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)} \]
    9. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \left(R \cdot \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(R \cdot \lambda_2\right), \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_2\right), \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_1\right)}\right) \]
      4. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_1\right)\right)\right) \]
      5. *-lowering-*.f6417.7%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right)\right) \]
    10. Simplified17.7%

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

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

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\lambda_2}\right) \]
    13. Simplified18.2%

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

    if 6.2e52 < phi2

    1. Initial program 58.3%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in phi2 around inf

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

        \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\phi_2}\right) \]
    5. Simplified73.6%

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

Alternative 15: 14.2% 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 57.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. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\left(\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)}\right)}\right) \]
    2. hypot-defineN/A

      \[\leadsto \mathsf{*.f64}\left(R, \left(\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \color{blue}{\phi_1 - \phi_2}\right)\right)\right) \]
    3. hypot-lowering-hypot.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \color{blue}{\left(\phi_1 - \phi_2\right)}\right)\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\color{blue}{\phi_1} - \phi_2\right)\right)\right) \]
    5. --lowering--.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    6. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    7. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\left(\phi_1 + \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    8. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \left(\phi_1 - \phi_2\right)\right)\right) \]
    9. --lowering--.f6497.4%

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\phi_1, \phi_2\right), 2\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \color{blue}{\phi_2}\right)\right)\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 phi2 around 0

    \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)}, \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
  6. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\left(\lambda_1 - \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\color{blue}{\phi_1}, \phi_2\right)\right)\right) \]
    3. --lowering--.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \cos \left(\frac{1}{2} \cdot \phi_1\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    4. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
    5. *-lowering-*.f6490.5%

      \[\leadsto \mathsf{*.f64}\left(R, \mathsf{hypot.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\lambda_1, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right)\right), \mathsf{\_.f64}\left(\phi_1, \phi_2\right)\right)\right) \]
  7. Simplified90.5%

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

    \[\leadsto \color{blue}{R \cdot \left(\lambda_2 \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right)} \]
  9. Step-by-step derivation
    1. associate-*r*N/A

      \[\leadsto \left(R \cdot \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)} \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(R \cdot \lambda_2\right), \color{blue}{\cos \left(\frac{1}{2} \cdot \phi_1\right)}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_2\right), \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_1\right)}\right) \]
    4. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_2\right), \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \phi_1\right)\right)\right) \]
    5. *-lowering-*.f6415.5%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(R, \lambda_2\right), \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \phi_1\right)\right)\right) \]
  10. Simplified15.5%

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

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

      \[\leadsto \mathsf{*.f64}\left(R, \color{blue}{\lambda_2}\right) \]
  13. Simplified15.1%

    \[\leadsto \color{blue}{R \cdot \lambda_2} \]
  14. Add Preprocessing

Reproduce

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