Equirectangular approximation to distance on a great circle

Percentage Accurate: 59.0% → 99.8%
Time: 16.8s
Alternatives: 14
Speedup: 1.6×

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 14 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.0% accurate, 1.0× speedup?

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

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

Alternative 1: 99.8% accurate, 0.5× speedup?

\[\begin{array}{l} \\ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right) \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R
  (hypot
   (*
    (- lambda1 lambda2)
    (expm1
     (log1p
      (-
       (* (cos (* 0.5 phi1)) (cos (* phi2 0.5)))
       (* (sin (* 0.5 phi1)) (sin (* phi2 0.5)))))))
   (- phi1 phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * hypot(((lambda1 - lambda2) * expm1(log1p(((cos((0.5 * phi1)) * cos((phi2 * 0.5))) - (sin((0.5 * phi1)) * sin((phi2 * 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.expm1(Math.log1p(((Math.cos((0.5 * phi1)) * Math.cos((phi2 * 0.5))) - (Math.sin((0.5 * phi1)) * Math.sin((phi2 * 0.5))))))), (phi1 - phi2));
}
def code(R, lambda1, lambda2, phi1, phi2):
	return R * math.hypot(((lambda1 - lambda2) * math.expm1(math.log1p(((math.cos((0.5 * phi1)) * math.cos((phi2 * 0.5))) - (math.sin((0.5 * phi1)) * math.sin((phi2 * 0.5))))))), (phi1 - phi2))
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(R * hypot(Float64(Float64(lambda1 - lambda2) * expm1(log1p(Float64(Float64(cos(Float64(0.5 * phi1)) * cos(Float64(phi2 * 0.5))) - Float64(sin(Float64(0.5 * phi1)) * sin(Float64(phi2 * 0.5))))))), Float64(phi1 - phi2)))
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[Sqrt[N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(Exp[N[Log[1 + N[(N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.8% accurate, 0.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 96.1% accurate, 0.6× speedup?

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

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

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


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

    1. Initial program 62.7%

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

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified93.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. Step-by-step derivation
      1. expm1-log1p-u93.2%

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

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

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

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

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

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

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

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

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

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

    if -3.9999999999999998e196 < lambda1

    1. Initial program 66.2%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -4 \cdot 10^{+196}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\lambda_1 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot 0.5\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot 0.5\right)\right), \phi_1 - \phi_2\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_2 + \phi_1}{2}\right), \phi_1 - \phi_2\right)\\ \end{array} \]

Alternative 4: 83.1% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 57.7%

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

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified91.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. Taylor expanded in phi2 around 0 90.1%

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

    if -2.2500000000000001e-58 < phi1

    1. Initial program 69.5%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 95.8% accurate, 1.5× speedup?

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

\\
R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_2 + \phi_1}{2}\right), \phi_1 - \phi_2\right)
\end{array}
Derivation
  1. Initial program 65.9%

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

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

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

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

Alternative 6: 74.9% accurate, 1.6× speedup?

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

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

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


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

    1. Initial program 68.9%

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.30000000000000018e-9 < phi2

    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. hypot-def95.2%

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

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

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

        \[\leadsto \phi_2 \cdot R + \color{blue}{\left(-1 \cdot \phi_1\right) \cdot R} \]
      3. distribute-rgt-out63.8%

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

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

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

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

Alternative 7: 77.7% accurate, 1.6× speedup?

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

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

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


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

    1. Initial program 68.4%

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

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified96.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. Taylor expanded in phi2 around 0 62.1%

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

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

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

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

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

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

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

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

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

    if 8.50000000000000029e-79 < phi2

    1. Initial program 60.2%

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

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified95.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. Taylor expanded in phi1 around 0 55.3%

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

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

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

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

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

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

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

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

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

Alternative 8: 31.6% accurate, 15.6× speedup?

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

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

\mathbf{elif}\;\phi_1 \leq -1.1 \cdot 10^{-284}:\\
\;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right) + -0.25 \cdot \left(\phi_1 \cdot \left(R \cdot \left(\phi_2 \cdot \left(\lambda_2 - \lambda_1\right)\right)\right)\right)\\

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


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

    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. Step-by-step derivation
      1. hypot-def89.2%

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

      \[\leadsto \color{blue}{R \cdot \phi_2 + -1 \cdot \left(\phi_1 \cdot R\right)} \]
    5. Step-by-step derivation
      1. *-commutative61.2%

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

        \[\leadsto \phi_2 \cdot R + \color{blue}{\left(-1 \cdot \phi_1\right) \cdot R} \]
      3. distribute-rgt-out63.0%

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

        \[\leadsto R \cdot \left(\phi_2 + \color{blue}{\left(-\phi_1\right)}\right) \]
    6. Simplified63.0%

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

    if -2.3e7 < phi1 < -1.1e-284

    1. Initial program 72.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\lambda_2 \cdot R\right) \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) - \left(\lambda_1 \cdot R\right) \cdot \cos \color{blue}{\left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)} \]
      11. +-commutative39.8%

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

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

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

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

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

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

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

        \[\leadsto \left(\left(-0.5 \cdot \left(\lambda_2 \cdot \left(R \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right) - -0.5 \cdot \left(R \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \lambda_1\right)\right)\right) \cdot \phi_2 + \lambda_2 \cdot \color{blue}{\left(R \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}\right) - \cos \left(0.5 \cdot \phi_1\right) \cdot \left(R \cdot \lambda_1\right) \]
      6. associate--l+32.1%

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

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

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

    if -1.1e-284 < phi1

    1. Initial program 67.7%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -23000000:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -1.1 \cdot 10^{-284}:\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right) + -0.25 \cdot \left(\phi_1 \cdot \left(R \cdot \left(\phi_2 \cdot \left(\lambda_2 - \lambda_1\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]

Alternative 9: 27.9% accurate, 32.3× speedup?

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

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

\mathbf{elif}\;\phi_1 \leq -2.45 \cdot 10^{-185}:\\
\;\;\;\;R \cdot \lambda_2\\

\mathbf{elif}\;\phi_1 \leq -7.8 \cdot 10^{-272}:\\
\;\;\;\;R \cdot \left(-\lambda_1\right)\\

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


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

    1. Initial program 54.4%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot R\right)} \]
    5. Step-by-step derivation
      1. associate-*r*57.8%

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

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

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

    if -8.5e6 < phi1 < -2.4500000000000001e-185

    1. Initial program 72.5%

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

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified99.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. Taylor expanded in lambda1 around -inf 39.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{R} \cdot \left(\lambda_2 - \lambda_1\right) \]
    11. Taylor expanded in lambda2 around inf 17.5%

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

    if -2.4500000000000001e-185 < phi1 < -7.7999999999999994e-272

    1. Initial program 72.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.7999999999999994e-272 < phi1

    1. Initial program 67.7%

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

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

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

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

        \[\leadsto \color{blue}{\phi_2 \cdot R} \]
    6. Simplified19.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -8500000:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq -2.45 \cdot 10^{-185}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{elif}\;\phi_1 \leq -7.8 \cdot 10^{-272}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]

Alternative 10: 31.3% accurate, 36.1× speedup?

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

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

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

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


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

    1. Initial program 51.5%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot R\right)} \]
    5. Step-by-step derivation
      1. associate-*r*72.5%

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

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

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

    if -2.7999999999999999e85 < phi1 < 6.6000000000000007e-201

    1. Initial program 66.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 6.6000000000000007e-201 < phi1

    1. Initial program 71.3%

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

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

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

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

        \[\leadsto \color{blue}{\phi_2 \cdot R} \]
    6. Simplified19.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -2.8 \cdot 10^{+85}:\\ \;\;\;\;R \cdot \left(-\phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq 6.6 \cdot 10^{-201}:\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]

Alternative 11: 33.3% accurate, 36.1× speedup?

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

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

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

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


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

    1. Initial program 54.5%

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

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

      \[\leadsto \color{blue}{R \cdot \phi_2 + -1 \cdot \left(\phi_1 \cdot R\right)} \]
    5. Step-by-step derivation
      1. *-commutative62.3%

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

        \[\leadsto \phi_2 \cdot R + \color{blue}{\left(-1 \cdot \phi_1\right) \cdot R} \]
      3. distribute-rgt-out64.1%

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

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

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

    if -4.9e7 < phi1 < 6.4999999999999996e-206

    1. Initial program 66.6%

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

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified98.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. Taylor expanded in lambda1 around -inf 38.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\lambda_2 \cdot R\right) \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) - \left(\lambda_1 \cdot R\right) \cdot \cos \color{blue}{\left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)} \]
      11. +-commutative38.0%

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

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

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

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

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

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

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

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

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

    if 6.4999999999999996e-206 < phi1

    1. Initial program 71.3%

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

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

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

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

        \[\leadsto \color{blue}{\phi_2 \cdot R} \]
    6. Simplified19.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_1 \leq -49000000:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{elif}\;\phi_1 \leq 6.5 \cdot 10^{-206}:\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]

Alternative 12: 23.7% accurate, 46.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 \leq -2.1 \cdot 10^{+67}:\\
\;\;\;\;R \cdot \left(-\lambda_1\right)\\

\mathbf{elif}\;\lambda_1 \leq 3.7 \cdot 10^{-299}:\\
\;\;\;\;R \cdot \phi_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if lambda1 < -2.1000000000000001e67

    1. Initial program 66.6%

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

        \[\leadsto R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)} \]
    3. Simplified91.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. Taylor expanded in lambda1 around -inf 49.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.1000000000000001e67 < lambda1 < 3.70000000000000014e-299

    1. Initial program 70.1%

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

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

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

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

        \[\leadsto \color{blue}{\phi_2 \cdot R} \]
    6. Simplified31.3%

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

    if 3.70000000000000014e-299 < lambda1

    1. Initial program 63.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{R} \cdot \left(\lambda_2 - \lambda_1\right) \]
    11. Taylor expanded in lambda2 around inf 14.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\lambda_1 \leq -2.1 \cdot 10^{+67}:\\ \;\;\;\;R \cdot \left(-\lambda_1\right)\\ \mathbf{elif}\;\lambda_1 \leq 3.7 \cdot 10^{-299}:\\ \;\;\;\;R \cdot \phi_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \lambda_2\\ \end{array} \]

Alternative 13: 25.9% accurate, 65.0× speedup?

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

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

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


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

    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. hypot-def96.4%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\lambda_2 \cdot R\right) \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) - \left(\lambda_1 \cdot R\right) \cdot \cos \color{blue}{\left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)} \]
      11. +-commutative31.8%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{R} \cdot \left(\lambda_2 - \lambda_1\right) \]
    11. Taylor expanded in lambda2 around inf 14.5%

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

    if 4.2999999999999999e-45 < phi2

    1. Initial program 59.6%

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

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

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

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

        \[\leadsto \color{blue}{\phi_2 \cdot R} \]
    6. Simplified54.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \leq 4.3 \cdot 10^{-45}:\\ \;\;\;\;R \cdot \lambda_2\\ \mathbf{else}:\\ \;\;\;\;R \cdot \phi_2\\ \end{array} \]

Alternative 14: 13.8% 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 65.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{R} \cdot \left(\lambda_2 - \lambda_1\right) \]
  11. Taylor expanded in lambda2 around inf 14.8%

    \[\leadsto \color{blue}{\lambda_2 \cdot R} \]
  12. Final simplification14.8%

    \[\leadsto R \cdot \lambda_2 \]

Reproduce

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