Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.9% → 63.0%
Time: 34.4s
Alternatives: 9
Speedup: 151.0×

Specification

?
\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ \frac{c0}{2 \cdot w} \cdot \left(t_0 + \sqrt{t_0 \cdot t_0 - M \cdot M}\right) \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ (* c0 (* d d)) (* (* w h) (* D D)))))
   (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	return (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
}
real(8) function code(c0, w, h, d, d_1, m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d
    real(8), intent (in) :: d_1
    real(8), intent (in) :: m
    real(8) :: t_0
    t_0 = (c0 * (d_1 * d_1)) / ((w * h) * (d * d))
    code = (c0 / (2.0d0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (m * m))))
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	return (c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))));
}
def code(c0, w, h, D, d, M):
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D))
	return (c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))
function code(c0, w, h, D, d, M)
	t_0 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	return Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M)))))
end
function tmp = code(c0, w, h, D, d, M)
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	tmp = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 + N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\
\frac{c0}{2 \cdot w} \cdot \left(t_0 + \sqrt{t_0 \cdot t_0 - M \cdot M}\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 9 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: 24.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ \frac{c0}{2 \cdot w} \cdot \left(t_0 + \sqrt{t_0 \cdot t_0 - M \cdot M}\right) \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ (* c0 (* d d)) (* (* w h) (* D D)))))
   (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	return (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
}
real(8) function code(c0, w, h, d, d_1, m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d
    real(8), intent (in) :: d_1
    real(8), intent (in) :: m
    real(8) :: t_0
    t_0 = (c0 * (d_1 * d_1)) / ((w * h) * (d * d))
    code = (c0 / (2.0d0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (m * m))))
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	return (c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))));
}
def code(c0, w, h, D, d, M):
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D))
	return (c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))
function code(c0, w, h, D, d, M)
	t_0 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	return Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M)))))
end
function tmp = code(c0, w, h, D, d, M)
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	tmp = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 + N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\
\frac{c0}{2 \cdot w} \cdot \left(t_0 + \sqrt{t_0 \cdot t_0 - M \cdot M}\right)
\end{array}
\end{array}

Alternative 1: 63.0% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ t_1 := \frac{c0}{2 \cdot w}\\ t_2 := t_1 \cdot \left(t_0 + \sqrt{t_0 \cdot t_0 - M \cdot M}\right)\\ \mathbf{if}\;t_2 \leq -4 \cdot 10^{-48} \lor \neg \left(t_2 \leq 0\right) \land t_2 \leq \infty:\\ \;\;\;\;t_1 \cdot \left(2 \cdot \frac{c0 \cdot {d}^{2}}{\left(w \cdot h\right) \cdot {D}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\left(D \cdot M\right)}^{-2}}\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ (* c0 (* d d)) (* (* w h) (* D D))))
        (t_1 (/ c0 (* 2.0 w)))
        (t_2 (* t_1 (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))))
   (if (or (<= t_2 -4e-48) (and (not (<= t_2 0.0)) (<= t_2 INFINITY)))
     (* t_1 (* 2.0 (/ (* c0 (pow d 2.0)) (* (* w h) (pow D 2.0)))))
     (* h (/ (/ 0.25 (pow d 2.0)) (pow (* D M) -2.0))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	double t_1 = c0 / (2.0 * w);
	double t_2 = t_1 * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
	double tmp;
	if ((t_2 <= -4e-48) || (!(t_2 <= 0.0) && (t_2 <= ((double) INFINITY)))) {
		tmp = t_1 * (2.0 * ((c0 * pow(d, 2.0)) / ((w * h) * pow(D, 2.0))));
	} else {
		tmp = h * ((0.25 / pow(d, 2.0)) / pow((D * M), -2.0));
	}
	return tmp;
}
public static double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	double t_1 = c0 / (2.0 * w);
	double t_2 = t_1 * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))));
	double tmp;
	if ((t_2 <= -4e-48) || (!(t_2 <= 0.0) && (t_2 <= Double.POSITIVE_INFINITY))) {
		tmp = t_1 * (2.0 * ((c0 * Math.pow(d, 2.0)) / ((w * h) * Math.pow(D, 2.0))));
	} else {
		tmp = h * ((0.25 / Math.pow(d, 2.0)) / Math.pow((D * M), -2.0));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D))
	t_1 = c0 / (2.0 * w)
	t_2 = t_1 * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))
	tmp = 0
	if (t_2 <= -4e-48) or (not (t_2 <= 0.0) and (t_2 <= math.inf)):
		tmp = t_1 * (2.0 * ((c0 * math.pow(d, 2.0)) / ((w * h) * math.pow(D, 2.0))))
	else:
		tmp = h * ((0.25 / math.pow(d, 2.0)) / math.pow((D * M), -2.0))
	return tmp
function code(c0, w, h, D, d, M)
	t_0 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	t_1 = Float64(c0 / Float64(2.0 * w))
	t_2 = Float64(t_1 * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M)))))
	tmp = 0.0
	if ((t_2 <= -4e-48) || (!(t_2 <= 0.0) && (t_2 <= Inf)))
		tmp = Float64(t_1 * Float64(2.0 * Float64(Float64(c0 * (d ^ 2.0)) / Float64(Float64(w * h) * (D ^ 2.0)))));
	else
		tmp = Float64(h * Float64(Float64(0.25 / (d ^ 2.0)) / (Float64(D * M) ^ -2.0)));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	t_1 = c0 / (2.0 * w);
	t_2 = t_1 * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
	tmp = 0.0;
	if ((t_2 <= -4e-48) || (~((t_2 <= 0.0)) && (t_2 <= Inf)))
		tmp = t_1 * (2.0 * ((c0 * (d ^ 2.0)) / ((w * h) * (D ^ 2.0))));
	else
		tmp = h * ((0.25 / (d ^ 2.0)) / ((D * M) ^ -2.0));
	end
	tmp_2 = tmp;
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * N[(t$95$0 + N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$2, -4e-48], And[N[Not[LessEqual[t$95$2, 0.0]], $MachinePrecision], LessEqual[t$95$2, Infinity]]], N[(t$95$1 * N[(2.0 * N[(N[(c0 * N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[Power[D, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(h * N[(N[(0.25 / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[N[(D * M), $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\
t_1 := \frac{c0}{2 \cdot w}\\
t_2 := t_1 \cdot \left(t_0 + \sqrt{t_0 \cdot t_0 - M \cdot M}\right)\\
\mathbf{if}\;t_2 \leq -4 \cdot 10^{-48} \lor \neg \left(t_2 \leq 0\right) \land t_2 \leq \infty:\\
\;\;\;\;t_1 \cdot \left(2 \cdot \frac{c0 \cdot {d}^{2}}{\left(w \cdot h\right) \cdot {D}^{2}}\right)\\

\mathbf{else}:\\
\;\;\;\;h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\left(D \cdot M\right)}^{-2}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < -3.9999999999999999e-48 or 0.0 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < +inf.0

    1. Initial program 76.5%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified74.8%

      \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
    3. Taylor expanded in c0 around inf 79.4%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(2 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)} \]

    if -3.9999999999999999e-48 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < 0.0 or +inf.0 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M)))))

    1. Initial program 2.4%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified3.6%

      \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
    3. Applied egg-rr3.0%

      \[\leadsto \color{blue}{\frac{c0 \cdot \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right)}{\left(w \cdot 2\right) \cdot \left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right)}} \]
    4. Step-by-step derivation
      1. *-commutative3.0%

        \[\leadsto \frac{\color{blue}{\left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right) \cdot c0}}{\left(w \cdot 2\right) \cdot \left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right)} \]
      2. *-commutative3.0%

        \[\leadsto \frac{\left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right) \cdot c0}{\color{blue}{\left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right) \cdot \left(w \cdot 2\right)}} \]
      3. times-frac2.9%

        \[\leadsto \color{blue}{\frac{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)}{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}} \cdot \frac{c0}{w \cdot 2}} \]
    5. Simplified31.5%

      \[\leadsto \color{blue}{\frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \sqrt{{\left(\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h}\right)}^{2} - {M}^{2}}} \cdot \frac{c0}{2 \cdot w}} \]
    6. Taylor expanded in c0 around -inf 22.2%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{-1 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}} \cdot \frac{c0}{2 \cdot w} \]
    7. Step-by-step derivation
      1. mul-1-neg22.2%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{\left(-\frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}} \cdot \frac{c0}{2 \cdot w} \]
      2. associate-*r*25.1%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{\left({D}^{2} \cdot h\right) \cdot w}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      3. *-commutative25.1%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{\left(h \cdot {D}^{2}\right)} \cdot w}\right)} \cdot \frac{c0}{2 \cdot w} \]
      4. *-commutative25.1%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{w \cdot \left(h \cdot {D}^{2}\right)}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      5. times-frac27.8%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\color{blue}{\frac{c0}{w} \cdot \frac{{d}^{2}}{h \cdot {D}^{2}}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      6. associate-/r*26.4%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0}{w} \cdot \color{blue}{\frac{\frac{{d}^{2}}{h}}{{D}^{2}}}\right)} \cdot \frac{c0}{2 \cdot w} \]
    8. Simplified26.4%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{\left(-\frac{c0}{w} \cdot \frac{\frac{{d}^{2}}{h}}{{D}^{2}}\right)}} \cdot \frac{c0}{2 \cdot w} \]
    9. Taylor expanded in M around 0 39.4%

      \[\leadsto \color{blue}{0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}} \]
    10. Step-by-step derivation
      1. associate-*r/39.4%

        \[\leadsto \color{blue}{\frac{0.25 \cdot \left({D}^{2} \cdot \left({M}^{2} \cdot h\right)\right)}{{d}^{2}}} \]
      2. associate-*r*40.9%

        \[\leadsto \frac{0.25 \cdot \color{blue}{\left(\left({D}^{2} \cdot {M}^{2}\right) \cdot h\right)}}{{d}^{2}} \]
      3. unpow240.9%

        \[\leadsto \frac{0.25 \cdot \left(\left(\color{blue}{\left(D \cdot D\right)} \cdot {M}^{2}\right) \cdot h\right)}{{d}^{2}} \]
      4. unpow240.9%

        \[\leadsto \frac{0.25 \cdot \left(\left(\left(D \cdot D\right) \cdot \color{blue}{\left(M \cdot M\right)}\right) \cdot h\right)}{{d}^{2}} \]
      5. swap-sqr52.1%

        \[\leadsto \frac{0.25 \cdot \left(\color{blue}{\left(\left(D \cdot M\right) \cdot \left(D \cdot M\right)\right)} \cdot h\right)}{{d}^{2}} \]
      6. unpow252.1%

        \[\leadsto \frac{0.25 \cdot \left(\color{blue}{{\left(D \cdot M\right)}^{2}} \cdot h\right)}{{d}^{2}} \]
      7. associate-/l*52.0%

        \[\leadsto \color{blue}{\frac{0.25}{\frac{{d}^{2}}{{\left(D \cdot M\right)}^{2} \cdot h}}} \]
      8. associate-/r*55.7%

        \[\leadsto \frac{0.25}{\color{blue}{\frac{\frac{{d}^{2}}{{\left(D \cdot M\right)}^{2}}}{h}}} \]
      9. *-commutative55.7%

        \[\leadsto \frac{0.25}{\frac{\frac{{d}^{2}}{{\color{blue}{\left(M \cdot D\right)}}^{2}}}{h}} \]
    11. Simplified55.7%

      \[\leadsto \color{blue}{\frac{0.25}{\frac{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}}{h}}} \]
    12. Step-by-step derivation
      1. expm1-log1p-u51.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{0.25}{\frac{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}}{h}}\right)\right)} \]
      2. expm1-udef43.6%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{0.25}{\frac{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}}{h}}\right)} - 1} \]
      3. associate-/r/43.6%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{0.25}{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}} \cdot h}\right)} - 1 \]
      4. div-inv43.6%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{\color{blue}{{d}^{2} \cdot \frac{1}{{\left(M \cdot D\right)}^{2}}}} \cdot h\right)} - 1 \]
      5. *-commutative43.6%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot \frac{1}{{\color{blue}{\left(D \cdot M\right)}}^{2}}} \cdot h\right)} - 1 \]
      6. pow-flip43.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot \color{blue}{{\left(D \cdot M\right)}^{\left(-2\right)}}} \cdot h\right)} - 1 \]
      7. *-commutative43.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot {\color{blue}{\left(M \cdot D\right)}}^{\left(-2\right)}} \cdot h\right)} - 1 \]
      8. metadata-eval43.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{\color{blue}{-2}}} \cdot h\right)} - 1 \]
    13. Applied egg-rr43.7%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{-2}} \cdot h\right)} - 1} \]
    14. Step-by-step derivation
      1. expm1-def51.7%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{-2}} \cdot h\right)\right)} \]
      2. expm1-log1p55.7%

        \[\leadsto \color{blue}{\frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{-2}} \cdot h} \]
      3. *-commutative55.7%

        \[\leadsto \color{blue}{h \cdot \frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{-2}}} \]
      4. associate-/r*55.9%

        \[\leadsto h \cdot \color{blue}{\frac{\frac{0.25}{{d}^{2}}}{{\left(M \cdot D\right)}^{-2}}} \]
      5. *-commutative55.9%

        \[\leadsto h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\color{blue}{\left(D \cdot M\right)}}^{-2}} \]
    15. Simplified55.9%

      \[\leadsto \color{blue}{h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\left(D \cdot M\right)}^{-2}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification62.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq -4 \cdot 10^{-48} \lor \neg \left(\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq 0\right) \land \frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq \infty:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(2 \cdot \frac{c0 \cdot {d}^{2}}{\left(w \cdot h\right) \cdot {D}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\left(D \cdot M\right)}^{-2}}\\ \end{array} \]

Alternative 2: 62.2% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0}{2 \cdot w}\\ t_1 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ t_2 := t_0 \cdot \left(t_1 + \sqrt{t_1 \cdot t_1 - M \cdot M}\right)\\ \mathbf{if}\;t_2 \leq -4 \cdot 10^{-48}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_2 \leq 0 \lor \neg \left(t_2 \leq \infty\right):\\ \;\;\;\;h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\left(D \cdot M\right)}^{-2}}\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \left(2 \cdot \left(\frac{c0}{w} \cdot \frac{{d}^{2}}{h \cdot {D}^{2}}\right)\right)\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ c0 (* 2.0 w)))
        (t_1 (/ (* c0 (* d d)) (* (* w h) (* D D))))
        (t_2 (* t_0 (+ t_1 (sqrt (- (* t_1 t_1) (* M M)))))))
   (if (<= t_2 -4e-48)
     t_2
     (if (or (<= t_2 0.0) (not (<= t_2 INFINITY)))
       (* h (/ (/ 0.25 (pow d 2.0)) (pow (* D M) -2.0)))
       (* t_0 (* 2.0 (* (/ c0 w) (/ (pow d 2.0) (* h (pow D 2.0))))))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = c0 / (2.0 * w);
	double t_1 = (c0 * (d * d)) / ((w * h) * (D * D));
	double t_2 = t_0 * (t_1 + sqrt(((t_1 * t_1) - (M * M))));
	double tmp;
	if (t_2 <= -4e-48) {
		tmp = t_2;
	} else if ((t_2 <= 0.0) || !(t_2 <= ((double) INFINITY))) {
		tmp = h * ((0.25 / pow(d, 2.0)) / pow((D * M), -2.0));
	} else {
		tmp = t_0 * (2.0 * ((c0 / w) * (pow(d, 2.0) / (h * pow(D, 2.0)))));
	}
	return tmp;
}
public static double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = c0 / (2.0 * w);
	double t_1 = (c0 * (d * d)) / ((w * h) * (D * D));
	double t_2 = t_0 * (t_1 + Math.sqrt(((t_1 * t_1) - (M * M))));
	double tmp;
	if (t_2 <= -4e-48) {
		tmp = t_2;
	} else if ((t_2 <= 0.0) || !(t_2 <= Double.POSITIVE_INFINITY)) {
		tmp = h * ((0.25 / Math.pow(d, 2.0)) / Math.pow((D * M), -2.0));
	} else {
		tmp = t_0 * (2.0 * ((c0 / w) * (Math.pow(d, 2.0) / (h * Math.pow(D, 2.0)))));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = c0 / (2.0 * w)
	t_1 = (c0 * (d * d)) / ((w * h) * (D * D))
	t_2 = t_0 * (t_1 + math.sqrt(((t_1 * t_1) - (M * M))))
	tmp = 0
	if t_2 <= -4e-48:
		tmp = t_2
	elif (t_2 <= 0.0) or not (t_2 <= math.inf):
		tmp = h * ((0.25 / math.pow(d, 2.0)) / math.pow((D * M), -2.0))
	else:
		tmp = t_0 * (2.0 * ((c0 / w) * (math.pow(d, 2.0) / (h * math.pow(D, 2.0)))))
	return tmp
function code(c0, w, h, D, d, M)
	t_0 = Float64(c0 / Float64(2.0 * w))
	t_1 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	t_2 = Float64(t_0 * Float64(t_1 + sqrt(Float64(Float64(t_1 * t_1) - Float64(M * M)))))
	tmp = 0.0
	if (t_2 <= -4e-48)
		tmp = t_2;
	elseif ((t_2 <= 0.0) || !(t_2 <= Inf))
		tmp = Float64(h * Float64(Float64(0.25 / (d ^ 2.0)) / (Float64(D * M) ^ -2.0)));
	else
		tmp = Float64(t_0 * Float64(2.0 * Float64(Float64(c0 / w) * Float64((d ^ 2.0) / Float64(h * (D ^ 2.0))))));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	t_0 = c0 / (2.0 * w);
	t_1 = (c0 * (d * d)) / ((w * h) * (D * D));
	t_2 = t_0 * (t_1 + sqrt(((t_1 * t_1) - (M * M))));
	tmp = 0.0;
	if (t_2 <= -4e-48)
		tmp = t_2;
	elseif ((t_2 <= 0.0) || ~((t_2 <= Inf)))
		tmp = h * ((0.25 / (d ^ 2.0)) / ((D * M) ^ -2.0));
	else
		tmp = t_0 * (2.0 * ((c0 / w) * ((d ^ 2.0) / (h * (D ^ 2.0)))));
	end
	tmp_2 = tmp;
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * N[(t$95$1 + N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -4e-48], t$95$2, If[Or[LessEqual[t$95$2, 0.0], N[Not[LessEqual[t$95$2, Infinity]], $MachinePrecision]], N[(h * N[(N[(0.25 / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[N[(D * M), $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(2.0 * N[(N[(c0 / w), $MachinePrecision] * N[(N[Power[d, 2.0], $MachinePrecision] / N[(h * N[Power[D, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c0}{2 \cdot w}\\
t_1 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\
t_2 := t_0 \cdot \left(t_1 + \sqrt{t_1 \cdot t_1 - M \cdot M}\right)\\
\mathbf{if}\;t_2 \leq -4 \cdot 10^{-48}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_2 \leq 0 \lor \neg \left(t_2 \leq \infty\right):\\
\;\;\;\;h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\left(D \cdot M\right)}^{-2}}\\

\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(2 \cdot \left(\frac{c0}{w} \cdot \frac{{d}^{2}}{h \cdot {D}^{2}}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < -3.9999999999999999e-48

    1. Initial program 79.8%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]

    if -3.9999999999999999e-48 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < 0.0 or +inf.0 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M)))))

    1. Initial program 2.4%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified3.6%

      \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
    3. Applied egg-rr3.0%

      \[\leadsto \color{blue}{\frac{c0 \cdot \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right)}{\left(w \cdot 2\right) \cdot \left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right)}} \]
    4. Step-by-step derivation
      1. *-commutative3.0%

        \[\leadsto \frac{\color{blue}{\left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right) \cdot c0}}{\left(w \cdot 2\right) \cdot \left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right)} \]
      2. *-commutative3.0%

        \[\leadsto \frac{\left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right) \cdot c0}{\color{blue}{\left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right) \cdot \left(w \cdot 2\right)}} \]
      3. times-frac2.9%

        \[\leadsto \color{blue}{\frac{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)}{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}} \cdot \frac{c0}{w \cdot 2}} \]
    5. Simplified31.5%

      \[\leadsto \color{blue}{\frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \sqrt{{\left(\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h}\right)}^{2} - {M}^{2}}} \cdot \frac{c0}{2 \cdot w}} \]
    6. Taylor expanded in c0 around -inf 22.2%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{-1 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}} \cdot \frac{c0}{2 \cdot w} \]
    7. Step-by-step derivation
      1. mul-1-neg22.2%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{\left(-\frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}} \cdot \frac{c0}{2 \cdot w} \]
      2. associate-*r*25.1%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{\left({D}^{2} \cdot h\right) \cdot w}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      3. *-commutative25.1%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{\left(h \cdot {D}^{2}\right)} \cdot w}\right)} \cdot \frac{c0}{2 \cdot w} \]
      4. *-commutative25.1%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{w \cdot \left(h \cdot {D}^{2}\right)}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      5. times-frac27.8%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\color{blue}{\frac{c0}{w} \cdot \frac{{d}^{2}}{h \cdot {D}^{2}}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      6. associate-/r*26.4%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0}{w} \cdot \color{blue}{\frac{\frac{{d}^{2}}{h}}{{D}^{2}}}\right)} \cdot \frac{c0}{2 \cdot w} \]
    8. Simplified26.4%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{\left(-\frac{c0}{w} \cdot \frac{\frac{{d}^{2}}{h}}{{D}^{2}}\right)}} \cdot \frac{c0}{2 \cdot w} \]
    9. Taylor expanded in M around 0 39.4%

      \[\leadsto \color{blue}{0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}} \]
    10. Step-by-step derivation
      1. associate-*r/39.4%

        \[\leadsto \color{blue}{\frac{0.25 \cdot \left({D}^{2} \cdot \left({M}^{2} \cdot h\right)\right)}{{d}^{2}}} \]
      2. associate-*r*40.9%

        \[\leadsto \frac{0.25 \cdot \color{blue}{\left(\left({D}^{2} \cdot {M}^{2}\right) \cdot h\right)}}{{d}^{2}} \]
      3. unpow240.9%

        \[\leadsto \frac{0.25 \cdot \left(\left(\color{blue}{\left(D \cdot D\right)} \cdot {M}^{2}\right) \cdot h\right)}{{d}^{2}} \]
      4. unpow240.9%

        \[\leadsto \frac{0.25 \cdot \left(\left(\left(D \cdot D\right) \cdot \color{blue}{\left(M \cdot M\right)}\right) \cdot h\right)}{{d}^{2}} \]
      5. swap-sqr52.1%

        \[\leadsto \frac{0.25 \cdot \left(\color{blue}{\left(\left(D \cdot M\right) \cdot \left(D \cdot M\right)\right)} \cdot h\right)}{{d}^{2}} \]
      6. unpow252.1%

        \[\leadsto \frac{0.25 \cdot \left(\color{blue}{{\left(D \cdot M\right)}^{2}} \cdot h\right)}{{d}^{2}} \]
      7. associate-/l*52.0%

        \[\leadsto \color{blue}{\frac{0.25}{\frac{{d}^{2}}{{\left(D \cdot M\right)}^{2} \cdot h}}} \]
      8. associate-/r*55.7%

        \[\leadsto \frac{0.25}{\color{blue}{\frac{\frac{{d}^{2}}{{\left(D \cdot M\right)}^{2}}}{h}}} \]
      9. *-commutative55.7%

        \[\leadsto \frac{0.25}{\frac{\frac{{d}^{2}}{{\color{blue}{\left(M \cdot D\right)}}^{2}}}{h}} \]
    11. Simplified55.7%

      \[\leadsto \color{blue}{\frac{0.25}{\frac{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}}{h}}} \]
    12. Step-by-step derivation
      1. expm1-log1p-u51.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{0.25}{\frac{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}}{h}}\right)\right)} \]
      2. expm1-udef43.6%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{0.25}{\frac{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}}{h}}\right)} - 1} \]
      3. associate-/r/43.6%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{0.25}{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}} \cdot h}\right)} - 1 \]
      4. div-inv43.6%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{\color{blue}{{d}^{2} \cdot \frac{1}{{\left(M \cdot D\right)}^{2}}}} \cdot h\right)} - 1 \]
      5. *-commutative43.6%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot \frac{1}{{\color{blue}{\left(D \cdot M\right)}}^{2}}} \cdot h\right)} - 1 \]
      6. pow-flip43.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot \color{blue}{{\left(D \cdot M\right)}^{\left(-2\right)}}} \cdot h\right)} - 1 \]
      7. *-commutative43.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot {\color{blue}{\left(M \cdot D\right)}}^{\left(-2\right)}} \cdot h\right)} - 1 \]
      8. metadata-eval43.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{\color{blue}{-2}}} \cdot h\right)} - 1 \]
    13. Applied egg-rr43.7%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{-2}} \cdot h\right)} - 1} \]
    14. Step-by-step derivation
      1. expm1-def51.7%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{-2}} \cdot h\right)\right)} \]
      2. expm1-log1p55.7%

        \[\leadsto \color{blue}{\frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{-2}} \cdot h} \]
      3. *-commutative55.7%

        \[\leadsto \color{blue}{h \cdot \frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{-2}}} \]
      4. associate-/r*55.9%

        \[\leadsto h \cdot \color{blue}{\frac{\frac{0.25}{{d}^{2}}}{{\left(M \cdot D\right)}^{-2}}} \]
      5. *-commutative55.9%

        \[\leadsto h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\color{blue}{\left(D \cdot M\right)}}^{-2}} \]
    15. Simplified55.9%

      \[\leadsto \color{blue}{h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\left(D \cdot M\right)}^{-2}}} \]

    if 0.0 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < +inf.0

    1. Initial program 72.5%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified72.1%

      \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
    3. Taylor expanded in c0 around inf 75.9%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(2 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)} \]
    4. Step-by-step derivation
      1. *-commutative75.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \color{blue}{\left(w \cdot h\right)}}\right) \]
      2. *-commutative75.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \frac{c0 \cdot {d}^{2}}{\color{blue}{\left(w \cdot h\right) \cdot {D}^{2}}}\right) \]
      3. associate-*r*73.0%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \frac{c0 \cdot {d}^{2}}{\color{blue}{w \cdot \left(h \cdot {D}^{2}\right)}}\right) \]
      4. times-frac72.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \color{blue}{\left(\frac{c0}{w} \cdot \frac{{d}^{2}}{h \cdot {D}^{2}}\right)}\right) \]
      5. *-commutative72.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \left(\frac{c0}{w} \cdot \frac{{d}^{2}}{\color{blue}{{D}^{2} \cdot h}}\right)\right) \]
    5. Simplified72.9%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(2 \cdot \left(\frac{c0}{w} \cdot \frac{{d}^{2}}{{D}^{2} \cdot h}\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification61.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq -4 \cdot 10^{-48}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right)\\ \mathbf{elif}\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq 0 \lor \neg \left(\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq \infty\right):\\ \;\;\;\;h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\left(D \cdot M\right)}^{-2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(2 \cdot \left(\frac{c0}{w} \cdot \frac{{d}^{2}}{h \cdot {D}^{2}}\right)\right)\\ \end{array} \]

Alternative 3: 62.3% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0}{2 \cdot w}\\ t_1 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ t_2 := t_0 \cdot \left(t_1 + \sqrt{t_1 \cdot t_1 - M \cdot M}\right)\\ \mathbf{if}\;t_2 \leq -4 \cdot 10^{-48}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_2 \leq 0 \lor \neg \left(t_2 \leq \infty\right):\\ \;\;\;\;h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\left(D \cdot M\right)}^{-2}}\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \left(2 \cdot \frac{c0 \cdot {d}^{2}}{w \cdot \left(h \cdot {D}^{2}\right)}\right)\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ c0 (* 2.0 w)))
        (t_1 (/ (* c0 (* d d)) (* (* w h) (* D D))))
        (t_2 (* t_0 (+ t_1 (sqrt (- (* t_1 t_1) (* M M)))))))
   (if (<= t_2 -4e-48)
     t_2
     (if (or (<= t_2 0.0) (not (<= t_2 INFINITY)))
       (* h (/ (/ 0.25 (pow d 2.0)) (pow (* D M) -2.0)))
       (* t_0 (* 2.0 (/ (* c0 (pow d 2.0)) (* w (* h (pow D 2.0))))))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = c0 / (2.0 * w);
	double t_1 = (c0 * (d * d)) / ((w * h) * (D * D));
	double t_2 = t_0 * (t_1 + sqrt(((t_1 * t_1) - (M * M))));
	double tmp;
	if (t_2 <= -4e-48) {
		tmp = t_2;
	} else if ((t_2 <= 0.0) || !(t_2 <= ((double) INFINITY))) {
		tmp = h * ((0.25 / pow(d, 2.0)) / pow((D * M), -2.0));
	} else {
		tmp = t_0 * (2.0 * ((c0 * pow(d, 2.0)) / (w * (h * pow(D, 2.0)))));
	}
	return tmp;
}
public static double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = c0 / (2.0 * w);
	double t_1 = (c0 * (d * d)) / ((w * h) * (D * D));
	double t_2 = t_0 * (t_1 + Math.sqrt(((t_1 * t_1) - (M * M))));
	double tmp;
	if (t_2 <= -4e-48) {
		tmp = t_2;
	} else if ((t_2 <= 0.0) || !(t_2 <= Double.POSITIVE_INFINITY)) {
		tmp = h * ((0.25 / Math.pow(d, 2.0)) / Math.pow((D * M), -2.0));
	} else {
		tmp = t_0 * (2.0 * ((c0 * Math.pow(d, 2.0)) / (w * (h * Math.pow(D, 2.0)))));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = c0 / (2.0 * w)
	t_1 = (c0 * (d * d)) / ((w * h) * (D * D))
	t_2 = t_0 * (t_1 + math.sqrt(((t_1 * t_1) - (M * M))))
	tmp = 0
	if t_2 <= -4e-48:
		tmp = t_2
	elif (t_2 <= 0.0) or not (t_2 <= math.inf):
		tmp = h * ((0.25 / math.pow(d, 2.0)) / math.pow((D * M), -2.0))
	else:
		tmp = t_0 * (2.0 * ((c0 * math.pow(d, 2.0)) / (w * (h * math.pow(D, 2.0)))))
	return tmp
function code(c0, w, h, D, d, M)
	t_0 = Float64(c0 / Float64(2.0 * w))
	t_1 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	t_2 = Float64(t_0 * Float64(t_1 + sqrt(Float64(Float64(t_1 * t_1) - Float64(M * M)))))
	tmp = 0.0
	if (t_2 <= -4e-48)
		tmp = t_2;
	elseif ((t_2 <= 0.0) || !(t_2 <= Inf))
		tmp = Float64(h * Float64(Float64(0.25 / (d ^ 2.0)) / (Float64(D * M) ^ -2.0)));
	else
		tmp = Float64(t_0 * Float64(2.0 * Float64(Float64(c0 * (d ^ 2.0)) / Float64(w * Float64(h * (D ^ 2.0))))));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	t_0 = c0 / (2.0 * w);
	t_1 = (c0 * (d * d)) / ((w * h) * (D * D));
	t_2 = t_0 * (t_1 + sqrt(((t_1 * t_1) - (M * M))));
	tmp = 0.0;
	if (t_2 <= -4e-48)
		tmp = t_2;
	elseif ((t_2 <= 0.0) || ~((t_2 <= Inf)))
		tmp = h * ((0.25 / (d ^ 2.0)) / ((D * M) ^ -2.0));
	else
		tmp = t_0 * (2.0 * ((c0 * (d ^ 2.0)) / (w * (h * (D ^ 2.0)))));
	end
	tmp_2 = tmp;
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * N[(t$95$1 + N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -4e-48], t$95$2, If[Or[LessEqual[t$95$2, 0.0], N[Not[LessEqual[t$95$2, Infinity]], $MachinePrecision]], N[(h * N[(N[(0.25 / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[N[(D * M), $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(2.0 * N[(N[(c0 * N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision] / N[(w * N[(h * N[Power[D, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c0}{2 \cdot w}\\
t_1 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\
t_2 := t_0 \cdot \left(t_1 + \sqrt{t_1 \cdot t_1 - M \cdot M}\right)\\
\mathbf{if}\;t_2 \leq -4 \cdot 10^{-48}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_2 \leq 0 \lor \neg \left(t_2 \leq \infty\right):\\
\;\;\;\;h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\left(D \cdot M\right)}^{-2}}\\

\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(2 \cdot \frac{c0 \cdot {d}^{2}}{w \cdot \left(h \cdot {D}^{2}\right)}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < -3.9999999999999999e-48

    1. Initial program 79.8%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]

    if -3.9999999999999999e-48 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < 0.0 or +inf.0 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M)))))

    1. Initial program 2.4%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified3.6%

      \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
    3. Applied egg-rr3.0%

      \[\leadsto \color{blue}{\frac{c0 \cdot \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right)}{\left(w \cdot 2\right) \cdot \left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right)}} \]
    4. Step-by-step derivation
      1. *-commutative3.0%

        \[\leadsto \frac{\color{blue}{\left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right) \cdot c0}}{\left(w \cdot 2\right) \cdot \left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right)} \]
      2. *-commutative3.0%

        \[\leadsto \frac{\left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right) \cdot c0}{\color{blue}{\left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right) \cdot \left(w \cdot 2\right)}} \]
      3. times-frac2.9%

        \[\leadsto \color{blue}{\frac{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)}{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}} \cdot \frac{c0}{w \cdot 2}} \]
    5. Simplified31.5%

      \[\leadsto \color{blue}{\frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \sqrt{{\left(\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h}\right)}^{2} - {M}^{2}}} \cdot \frac{c0}{2 \cdot w}} \]
    6. Taylor expanded in c0 around -inf 22.2%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{-1 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}} \cdot \frac{c0}{2 \cdot w} \]
    7. Step-by-step derivation
      1. mul-1-neg22.2%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{\left(-\frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}} \cdot \frac{c0}{2 \cdot w} \]
      2. associate-*r*25.1%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{\left({D}^{2} \cdot h\right) \cdot w}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      3. *-commutative25.1%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{\left(h \cdot {D}^{2}\right)} \cdot w}\right)} \cdot \frac{c0}{2 \cdot w} \]
      4. *-commutative25.1%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{w \cdot \left(h \cdot {D}^{2}\right)}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      5. times-frac27.8%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\color{blue}{\frac{c0}{w} \cdot \frac{{d}^{2}}{h \cdot {D}^{2}}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      6. associate-/r*26.4%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0}{w} \cdot \color{blue}{\frac{\frac{{d}^{2}}{h}}{{D}^{2}}}\right)} \cdot \frac{c0}{2 \cdot w} \]
    8. Simplified26.4%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{\left(-\frac{c0}{w} \cdot \frac{\frac{{d}^{2}}{h}}{{D}^{2}}\right)}} \cdot \frac{c0}{2 \cdot w} \]
    9. Taylor expanded in M around 0 39.4%

      \[\leadsto \color{blue}{0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}} \]
    10. Step-by-step derivation
      1. associate-*r/39.4%

        \[\leadsto \color{blue}{\frac{0.25 \cdot \left({D}^{2} \cdot \left({M}^{2} \cdot h\right)\right)}{{d}^{2}}} \]
      2. associate-*r*40.9%

        \[\leadsto \frac{0.25 \cdot \color{blue}{\left(\left({D}^{2} \cdot {M}^{2}\right) \cdot h\right)}}{{d}^{2}} \]
      3. unpow240.9%

        \[\leadsto \frac{0.25 \cdot \left(\left(\color{blue}{\left(D \cdot D\right)} \cdot {M}^{2}\right) \cdot h\right)}{{d}^{2}} \]
      4. unpow240.9%

        \[\leadsto \frac{0.25 \cdot \left(\left(\left(D \cdot D\right) \cdot \color{blue}{\left(M \cdot M\right)}\right) \cdot h\right)}{{d}^{2}} \]
      5. swap-sqr52.1%

        \[\leadsto \frac{0.25 \cdot \left(\color{blue}{\left(\left(D \cdot M\right) \cdot \left(D \cdot M\right)\right)} \cdot h\right)}{{d}^{2}} \]
      6. unpow252.1%

        \[\leadsto \frac{0.25 \cdot \left(\color{blue}{{\left(D \cdot M\right)}^{2}} \cdot h\right)}{{d}^{2}} \]
      7. associate-/l*52.0%

        \[\leadsto \color{blue}{\frac{0.25}{\frac{{d}^{2}}{{\left(D \cdot M\right)}^{2} \cdot h}}} \]
      8. associate-/r*55.7%

        \[\leadsto \frac{0.25}{\color{blue}{\frac{\frac{{d}^{2}}{{\left(D \cdot M\right)}^{2}}}{h}}} \]
      9. *-commutative55.7%

        \[\leadsto \frac{0.25}{\frac{\frac{{d}^{2}}{{\color{blue}{\left(M \cdot D\right)}}^{2}}}{h}} \]
    11. Simplified55.7%

      \[\leadsto \color{blue}{\frac{0.25}{\frac{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}}{h}}} \]
    12. Step-by-step derivation
      1. expm1-log1p-u51.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{0.25}{\frac{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}}{h}}\right)\right)} \]
      2. expm1-udef43.6%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{0.25}{\frac{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}}{h}}\right)} - 1} \]
      3. associate-/r/43.6%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{0.25}{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}} \cdot h}\right)} - 1 \]
      4. div-inv43.6%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{\color{blue}{{d}^{2} \cdot \frac{1}{{\left(M \cdot D\right)}^{2}}}} \cdot h\right)} - 1 \]
      5. *-commutative43.6%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot \frac{1}{{\color{blue}{\left(D \cdot M\right)}}^{2}}} \cdot h\right)} - 1 \]
      6. pow-flip43.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot \color{blue}{{\left(D \cdot M\right)}^{\left(-2\right)}}} \cdot h\right)} - 1 \]
      7. *-commutative43.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot {\color{blue}{\left(M \cdot D\right)}}^{\left(-2\right)}} \cdot h\right)} - 1 \]
      8. metadata-eval43.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{\color{blue}{-2}}} \cdot h\right)} - 1 \]
    13. Applied egg-rr43.7%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{-2}} \cdot h\right)} - 1} \]
    14. Step-by-step derivation
      1. expm1-def51.7%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{-2}} \cdot h\right)\right)} \]
      2. expm1-log1p55.7%

        \[\leadsto \color{blue}{\frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{-2}} \cdot h} \]
      3. *-commutative55.7%

        \[\leadsto \color{blue}{h \cdot \frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{-2}}} \]
      4. associate-/r*55.9%

        \[\leadsto h \cdot \color{blue}{\frac{\frac{0.25}{{d}^{2}}}{{\left(M \cdot D\right)}^{-2}}} \]
      5. *-commutative55.9%

        \[\leadsto h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\color{blue}{\left(D \cdot M\right)}}^{-2}} \]
    15. Simplified55.9%

      \[\leadsto \color{blue}{h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\left(D \cdot M\right)}^{-2}}} \]

    if 0.0 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < +inf.0

    1. Initial program 72.5%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified72.1%

      \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
    3. Taylor expanded in c0 around inf 75.9%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(2 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)} \]
    4. Step-by-step derivation
      1. *-commutative75.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \color{blue}{\left(w \cdot h\right)}}\right) \]
      2. *-commutative75.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \frac{c0 \cdot {d}^{2}}{\color{blue}{\left(w \cdot h\right) \cdot {D}^{2}}}\right) \]
      3. associate-*r*73.0%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \frac{c0 \cdot {d}^{2}}{\color{blue}{w \cdot \left(h \cdot {D}^{2}\right)}}\right) \]
      4. times-frac72.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \color{blue}{\left(\frac{c0}{w} \cdot \frac{{d}^{2}}{h \cdot {D}^{2}}\right)}\right) \]
      5. *-commutative72.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \left(\frac{c0}{w} \cdot \frac{{d}^{2}}{\color{blue}{{D}^{2} \cdot h}}\right)\right) \]
    5. Simplified72.9%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(2 \cdot \left(\frac{c0}{w} \cdot \frac{{d}^{2}}{{D}^{2} \cdot h}\right)\right)} \]
    6. Step-by-step derivation
      1. frac-times73.0%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \color{blue}{\frac{c0 \cdot {d}^{2}}{w \cdot \left({D}^{2} \cdot h\right)}}\right) \]
      2. *-commutative73.0%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \frac{c0 \cdot {d}^{2}}{w \cdot \color{blue}{\left(h \cdot {D}^{2}\right)}}\right) \]
    7. Applied egg-rr73.0%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \color{blue}{\frac{c0 \cdot {d}^{2}}{w \cdot \left(h \cdot {D}^{2}\right)}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification61.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq -4 \cdot 10^{-48}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right)\\ \mathbf{elif}\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq 0 \lor \neg \left(\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq \infty\right):\\ \;\;\;\;h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\left(D \cdot M\right)}^{-2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(2 \cdot \frac{c0 \cdot {d}^{2}}{w \cdot \left(h \cdot {D}^{2}\right)}\right)\\ \end{array} \]

Alternative 4: 62.2% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ t_1 := \frac{c0}{2 \cdot w} \cdot \left(t_0 + \sqrt{t_0 \cdot t_0 - M \cdot M}\right)\\ \mathbf{if}\;t_1 \leq -4 \cdot 10^{-48} \lor \neg \left(t_1 \leq 0\right) \land t_1 \leq \infty:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\left(D \cdot M\right)}^{-2}}\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ (* c0 (* d d)) (* (* w h) (* D D))))
        (t_1 (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))))
   (if (or (<= t_1 -4e-48) (and (not (<= t_1 0.0)) (<= t_1 INFINITY)))
     t_1
     (* h (/ (/ 0.25 (pow d 2.0)) (pow (* D M) -2.0))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	double t_1 = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
	double tmp;
	if ((t_1 <= -4e-48) || (!(t_1 <= 0.0) && (t_1 <= ((double) INFINITY)))) {
		tmp = t_1;
	} else {
		tmp = h * ((0.25 / pow(d, 2.0)) / pow((D * M), -2.0));
	}
	return tmp;
}
public static double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	double t_1 = (c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))));
	double tmp;
	if ((t_1 <= -4e-48) || (!(t_1 <= 0.0) && (t_1 <= Double.POSITIVE_INFINITY))) {
		tmp = t_1;
	} else {
		tmp = h * ((0.25 / Math.pow(d, 2.0)) / Math.pow((D * M), -2.0));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D))
	t_1 = (c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))
	tmp = 0
	if (t_1 <= -4e-48) or (not (t_1 <= 0.0) and (t_1 <= math.inf)):
		tmp = t_1
	else:
		tmp = h * ((0.25 / math.pow(d, 2.0)) / math.pow((D * M), -2.0))
	return tmp
function code(c0, w, h, D, d, M)
	t_0 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	t_1 = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M)))))
	tmp = 0.0
	if ((t_1 <= -4e-48) || (!(t_1 <= 0.0) && (t_1 <= Inf)))
		tmp = t_1;
	else
		tmp = Float64(h * Float64(Float64(0.25 / (d ^ 2.0)) / (Float64(D * M) ^ -2.0)));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	t_1 = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
	tmp = 0.0;
	if ((t_1 <= -4e-48) || (~((t_1 <= 0.0)) && (t_1 <= Inf)))
		tmp = t_1;
	else
		tmp = h * ((0.25 / (d ^ 2.0)) / ((D * M) ^ -2.0));
	end
	tmp_2 = tmp;
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 + N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -4e-48], And[N[Not[LessEqual[t$95$1, 0.0]], $MachinePrecision], LessEqual[t$95$1, Infinity]]], t$95$1, N[(h * N[(N[(0.25 / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[N[(D * M), $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\
t_1 := \frac{c0}{2 \cdot w} \cdot \left(t_0 + \sqrt{t_0 \cdot t_0 - M \cdot M}\right)\\
\mathbf{if}\;t_1 \leq -4 \cdot 10^{-48} \lor \neg \left(t_1 \leq 0\right) \land t_1 \leq \infty:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\left(D \cdot M\right)}^{-2}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < -3.9999999999999999e-48 or 0.0 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < +inf.0

    1. Initial program 76.5%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]

    if -3.9999999999999999e-48 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < 0.0 or +inf.0 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M)))))

    1. Initial program 2.4%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified3.6%

      \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
    3. Applied egg-rr3.0%

      \[\leadsto \color{blue}{\frac{c0 \cdot \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right)}{\left(w \cdot 2\right) \cdot \left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right)}} \]
    4. Step-by-step derivation
      1. *-commutative3.0%

        \[\leadsto \frac{\color{blue}{\left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right) \cdot c0}}{\left(w \cdot 2\right) \cdot \left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right)} \]
      2. *-commutative3.0%

        \[\leadsto \frac{\left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right) \cdot c0}{\color{blue}{\left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right) \cdot \left(w \cdot 2\right)}} \]
      3. times-frac2.9%

        \[\leadsto \color{blue}{\frac{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)}{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}} \cdot \frac{c0}{w \cdot 2}} \]
    5. Simplified31.5%

      \[\leadsto \color{blue}{\frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \sqrt{{\left(\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h}\right)}^{2} - {M}^{2}}} \cdot \frac{c0}{2 \cdot w}} \]
    6. Taylor expanded in c0 around -inf 22.2%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{-1 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}} \cdot \frac{c0}{2 \cdot w} \]
    7. Step-by-step derivation
      1. mul-1-neg22.2%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{\left(-\frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}} \cdot \frac{c0}{2 \cdot w} \]
      2. associate-*r*25.1%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{\left({D}^{2} \cdot h\right) \cdot w}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      3. *-commutative25.1%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{\left(h \cdot {D}^{2}\right)} \cdot w}\right)} \cdot \frac{c0}{2 \cdot w} \]
      4. *-commutative25.1%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{w \cdot \left(h \cdot {D}^{2}\right)}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      5. times-frac27.8%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\color{blue}{\frac{c0}{w} \cdot \frac{{d}^{2}}{h \cdot {D}^{2}}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      6. associate-/r*26.4%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0}{w} \cdot \color{blue}{\frac{\frac{{d}^{2}}{h}}{{D}^{2}}}\right)} \cdot \frac{c0}{2 \cdot w} \]
    8. Simplified26.4%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{\left(-\frac{c0}{w} \cdot \frac{\frac{{d}^{2}}{h}}{{D}^{2}}\right)}} \cdot \frac{c0}{2 \cdot w} \]
    9. Taylor expanded in M around 0 39.4%

      \[\leadsto \color{blue}{0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}} \]
    10. Step-by-step derivation
      1. associate-*r/39.4%

        \[\leadsto \color{blue}{\frac{0.25 \cdot \left({D}^{2} \cdot \left({M}^{2} \cdot h\right)\right)}{{d}^{2}}} \]
      2. associate-*r*40.9%

        \[\leadsto \frac{0.25 \cdot \color{blue}{\left(\left({D}^{2} \cdot {M}^{2}\right) \cdot h\right)}}{{d}^{2}} \]
      3. unpow240.9%

        \[\leadsto \frac{0.25 \cdot \left(\left(\color{blue}{\left(D \cdot D\right)} \cdot {M}^{2}\right) \cdot h\right)}{{d}^{2}} \]
      4. unpow240.9%

        \[\leadsto \frac{0.25 \cdot \left(\left(\left(D \cdot D\right) \cdot \color{blue}{\left(M \cdot M\right)}\right) \cdot h\right)}{{d}^{2}} \]
      5. swap-sqr52.1%

        \[\leadsto \frac{0.25 \cdot \left(\color{blue}{\left(\left(D \cdot M\right) \cdot \left(D \cdot M\right)\right)} \cdot h\right)}{{d}^{2}} \]
      6. unpow252.1%

        \[\leadsto \frac{0.25 \cdot \left(\color{blue}{{\left(D \cdot M\right)}^{2}} \cdot h\right)}{{d}^{2}} \]
      7. associate-/l*52.0%

        \[\leadsto \color{blue}{\frac{0.25}{\frac{{d}^{2}}{{\left(D \cdot M\right)}^{2} \cdot h}}} \]
      8. associate-/r*55.7%

        \[\leadsto \frac{0.25}{\color{blue}{\frac{\frac{{d}^{2}}{{\left(D \cdot M\right)}^{2}}}{h}}} \]
      9. *-commutative55.7%

        \[\leadsto \frac{0.25}{\frac{\frac{{d}^{2}}{{\color{blue}{\left(M \cdot D\right)}}^{2}}}{h}} \]
    11. Simplified55.7%

      \[\leadsto \color{blue}{\frac{0.25}{\frac{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}}{h}}} \]
    12. Step-by-step derivation
      1. expm1-log1p-u51.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{0.25}{\frac{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}}{h}}\right)\right)} \]
      2. expm1-udef43.6%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{0.25}{\frac{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}}{h}}\right)} - 1} \]
      3. associate-/r/43.6%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{0.25}{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}} \cdot h}\right)} - 1 \]
      4. div-inv43.6%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{\color{blue}{{d}^{2} \cdot \frac{1}{{\left(M \cdot D\right)}^{2}}}} \cdot h\right)} - 1 \]
      5. *-commutative43.6%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot \frac{1}{{\color{blue}{\left(D \cdot M\right)}}^{2}}} \cdot h\right)} - 1 \]
      6. pow-flip43.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot \color{blue}{{\left(D \cdot M\right)}^{\left(-2\right)}}} \cdot h\right)} - 1 \]
      7. *-commutative43.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot {\color{blue}{\left(M \cdot D\right)}}^{\left(-2\right)}} \cdot h\right)} - 1 \]
      8. metadata-eval43.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{\color{blue}{-2}}} \cdot h\right)} - 1 \]
    13. Applied egg-rr43.7%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{-2}} \cdot h\right)} - 1} \]
    14. Step-by-step derivation
      1. expm1-def51.7%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{-2}} \cdot h\right)\right)} \]
      2. expm1-log1p55.7%

        \[\leadsto \color{blue}{\frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{-2}} \cdot h} \]
      3. *-commutative55.7%

        \[\leadsto \color{blue}{h \cdot \frac{0.25}{{d}^{2} \cdot {\left(M \cdot D\right)}^{-2}}} \]
      4. associate-/r*55.9%

        \[\leadsto h \cdot \color{blue}{\frac{\frac{0.25}{{d}^{2}}}{{\left(M \cdot D\right)}^{-2}}} \]
      5. *-commutative55.9%

        \[\leadsto h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\color{blue}{\left(D \cdot M\right)}}^{-2}} \]
    15. Simplified55.9%

      \[\leadsto \color{blue}{h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\left(D \cdot M\right)}^{-2}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification61.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq -4 \cdot 10^{-48} \lor \neg \left(\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq 0\right) \land \frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq \infty:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right)\\ \mathbf{else}:\\ \;\;\;\;h \cdot \frac{\frac{0.25}{{d}^{2}}}{{\left(D \cdot M\right)}^{-2}}\\ \end{array} \]

Alternative 5: 62.3% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ t_1 := \frac{c0}{2 \cdot w} \cdot \left(t_0 + \sqrt{t_0 \cdot t_0 - M \cdot M}\right)\\ \mathbf{if}\;t_1 \leq -4 \cdot 10^{-48} \lor \neg \left(t_1 \leq 0\right) \land t_1 \leq \infty:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25}{\frac{\frac{{d}^{2}}{\left(D \cdot M\right) \cdot \left(D \cdot M\right)}}{h}}\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ (* c0 (* d d)) (* (* w h) (* D D))))
        (t_1 (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))))
   (if (or (<= t_1 -4e-48) (and (not (<= t_1 0.0)) (<= t_1 INFINITY)))
     t_1
     (/ 0.25 (/ (/ (pow d 2.0) (* (* D M) (* D M))) h)))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	double t_1 = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
	double tmp;
	if ((t_1 <= -4e-48) || (!(t_1 <= 0.0) && (t_1 <= ((double) INFINITY)))) {
		tmp = t_1;
	} else {
		tmp = 0.25 / ((pow(d, 2.0) / ((D * M) * (D * M))) / h);
	}
	return tmp;
}
public static double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	double t_1 = (c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))));
	double tmp;
	if ((t_1 <= -4e-48) || (!(t_1 <= 0.0) && (t_1 <= Double.POSITIVE_INFINITY))) {
		tmp = t_1;
	} else {
		tmp = 0.25 / ((Math.pow(d, 2.0) / ((D * M) * (D * M))) / h);
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D))
	t_1 = (c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))
	tmp = 0
	if (t_1 <= -4e-48) or (not (t_1 <= 0.0) and (t_1 <= math.inf)):
		tmp = t_1
	else:
		tmp = 0.25 / ((math.pow(d, 2.0) / ((D * M) * (D * M))) / h)
	return tmp
function code(c0, w, h, D, d, M)
	t_0 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	t_1 = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M)))))
	tmp = 0.0
	if ((t_1 <= -4e-48) || (!(t_1 <= 0.0) && (t_1 <= Inf)))
		tmp = t_1;
	else
		tmp = Float64(0.25 / Float64(Float64((d ^ 2.0) / Float64(Float64(D * M) * Float64(D * M))) / h));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	t_1 = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
	tmp = 0.0;
	if ((t_1 <= -4e-48) || (~((t_1 <= 0.0)) && (t_1 <= Inf)))
		tmp = t_1;
	else
		tmp = 0.25 / (((d ^ 2.0) / ((D * M) * (D * M))) / h);
	end
	tmp_2 = tmp;
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 + N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -4e-48], And[N[Not[LessEqual[t$95$1, 0.0]], $MachinePrecision], LessEqual[t$95$1, Infinity]]], t$95$1, N[(0.25 / N[(N[(N[Power[d, 2.0], $MachinePrecision] / N[(N[(D * M), $MachinePrecision] * N[(D * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / h), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\
t_1 := \frac{c0}{2 \cdot w} \cdot \left(t_0 + \sqrt{t_0 \cdot t_0 - M \cdot M}\right)\\
\mathbf{if}\;t_1 \leq -4 \cdot 10^{-48} \lor \neg \left(t_1 \leq 0\right) \land t_1 \leq \infty:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;\frac{0.25}{\frac{\frac{{d}^{2}}{\left(D \cdot M\right) \cdot \left(D \cdot M\right)}}{h}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < -3.9999999999999999e-48 or 0.0 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < +inf.0

    1. Initial program 76.5%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]

    if -3.9999999999999999e-48 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < 0.0 or +inf.0 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M)))))

    1. Initial program 2.4%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified3.6%

      \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
    3. Applied egg-rr3.0%

      \[\leadsto \color{blue}{\frac{c0 \cdot \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right)}{\left(w \cdot 2\right) \cdot \left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right)}} \]
    4. Step-by-step derivation
      1. *-commutative3.0%

        \[\leadsto \frac{\color{blue}{\left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right) \cdot c0}}{\left(w \cdot 2\right) \cdot \left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right)} \]
      2. *-commutative3.0%

        \[\leadsto \frac{\left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right) \cdot c0}{\color{blue}{\left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right) \cdot \left(w \cdot 2\right)}} \]
      3. times-frac2.9%

        \[\leadsto \color{blue}{\frac{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)}{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}} \cdot \frac{c0}{w \cdot 2}} \]
    5. Simplified31.5%

      \[\leadsto \color{blue}{\frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \sqrt{{\left(\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h}\right)}^{2} - {M}^{2}}} \cdot \frac{c0}{2 \cdot w}} \]
    6. Taylor expanded in c0 around -inf 22.2%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{-1 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}} \cdot \frac{c0}{2 \cdot w} \]
    7. Step-by-step derivation
      1. mul-1-neg22.2%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{\left(-\frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}} \cdot \frac{c0}{2 \cdot w} \]
      2. associate-*r*25.1%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{\left({D}^{2} \cdot h\right) \cdot w}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      3. *-commutative25.1%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{\left(h \cdot {D}^{2}\right)} \cdot w}\right)} \cdot \frac{c0}{2 \cdot w} \]
      4. *-commutative25.1%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{w \cdot \left(h \cdot {D}^{2}\right)}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      5. times-frac27.8%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\color{blue}{\frac{c0}{w} \cdot \frac{{d}^{2}}{h \cdot {D}^{2}}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      6. associate-/r*26.4%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0}{w} \cdot \color{blue}{\frac{\frac{{d}^{2}}{h}}{{D}^{2}}}\right)} \cdot \frac{c0}{2 \cdot w} \]
    8. Simplified26.4%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{\left(-\frac{c0}{w} \cdot \frac{\frac{{d}^{2}}{h}}{{D}^{2}}\right)}} \cdot \frac{c0}{2 \cdot w} \]
    9. Taylor expanded in M around 0 39.4%

      \[\leadsto \color{blue}{0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}} \]
    10. Step-by-step derivation
      1. associate-*r/39.4%

        \[\leadsto \color{blue}{\frac{0.25 \cdot \left({D}^{2} \cdot \left({M}^{2} \cdot h\right)\right)}{{d}^{2}}} \]
      2. associate-*r*40.9%

        \[\leadsto \frac{0.25 \cdot \color{blue}{\left(\left({D}^{2} \cdot {M}^{2}\right) \cdot h\right)}}{{d}^{2}} \]
      3. unpow240.9%

        \[\leadsto \frac{0.25 \cdot \left(\left(\color{blue}{\left(D \cdot D\right)} \cdot {M}^{2}\right) \cdot h\right)}{{d}^{2}} \]
      4. unpow240.9%

        \[\leadsto \frac{0.25 \cdot \left(\left(\left(D \cdot D\right) \cdot \color{blue}{\left(M \cdot M\right)}\right) \cdot h\right)}{{d}^{2}} \]
      5. swap-sqr52.1%

        \[\leadsto \frac{0.25 \cdot \left(\color{blue}{\left(\left(D \cdot M\right) \cdot \left(D \cdot M\right)\right)} \cdot h\right)}{{d}^{2}} \]
      6. unpow252.1%

        \[\leadsto \frac{0.25 \cdot \left(\color{blue}{{\left(D \cdot M\right)}^{2}} \cdot h\right)}{{d}^{2}} \]
      7. associate-/l*52.0%

        \[\leadsto \color{blue}{\frac{0.25}{\frac{{d}^{2}}{{\left(D \cdot M\right)}^{2} \cdot h}}} \]
      8. associate-/r*55.7%

        \[\leadsto \frac{0.25}{\color{blue}{\frac{\frac{{d}^{2}}{{\left(D \cdot M\right)}^{2}}}{h}}} \]
      9. *-commutative55.7%

        \[\leadsto \frac{0.25}{\frac{\frac{{d}^{2}}{{\color{blue}{\left(M \cdot D\right)}}^{2}}}{h}} \]
    11. Simplified55.7%

      \[\leadsto \color{blue}{\frac{0.25}{\frac{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}}{h}}} \]
    12. Step-by-step derivation
      1. unpow255.7%

        \[\leadsto \frac{0.25}{\frac{\frac{{d}^{2}}{\color{blue}{\left(M \cdot D\right) \cdot \left(M \cdot D\right)}}}{h}} \]
    13. Applied egg-rr55.7%

      \[\leadsto \frac{0.25}{\frac{\frac{{d}^{2}}{\color{blue}{\left(M \cdot D\right) \cdot \left(M \cdot D\right)}}}{h}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification61.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq -4 \cdot 10^{-48} \lor \neg \left(\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq 0\right) \land \frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq \infty:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25}{\frac{\frac{{d}^{2}}{\left(D \cdot M\right) \cdot \left(D \cdot M\right)}}{h}}\\ \end{array} \]

Alternative 6: 62.2% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ t_1 := \frac{c0}{2 \cdot w} \cdot \left(t_0 + \sqrt{t_0 \cdot t_0 - M \cdot M}\right)\\ \mathbf{if}\;t_1 \leq -4 \cdot 10^{-48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;0.25 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \left(h \cdot {d}^{-2}\right)\right)\\ \mathbf{elif}\;t_1 \leq \infty:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25}{\frac{\frac{{d}^{2}}{\left(D \cdot M\right) \cdot \left(D \cdot M\right)}}{h}}\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ (* c0 (* d d)) (* (* w h) (* D D))))
        (t_1 (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))))
   (if (<= t_1 -4e-48)
     t_1
     (if (<= t_1 0.0)
       (* 0.25 (* (pow (* D M) 2.0) (* h (pow d -2.0))))
       (if (<= t_1 INFINITY)
         t_1
         (/ 0.25 (/ (/ (pow d 2.0) (* (* D M) (* D M))) h)))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	double t_1 = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
	double tmp;
	if (t_1 <= -4e-48) {
		tmp = t_1;
	} else if (t_1 <= 0.0) {
		tmp = 0.25 * (pow((D * M), 2.0) * (h * pow(d, -2.0)));
	} else if (t_1 <= ((double) INFINITY)) {
		tmp = t_1;
	} else {
		tmp = 0.25 / ((pow(d, 2.0) / ((D * M) * (D * M))) / h);
	}
	return tmp;
}
public static double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	double t_1 = (c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))));
	double tmp;
	if (t_1 <= -4e-48) {
		tmp = t_1;
	} else if (t_1 <= 0.0) {
		tmp = 0.25 * (Math.pow((D * M), 2.0) * (h * Math.pow(d, -2.0)));
	} else if (t_1 <= Double.POSITIVE_INFINITY) {
		tmp = t_1;
	} else {
		tmp = 0.25 / ((Math.pow(d, 2.0) / ((D * M) * (D * M))) / h);
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D))
	t_1 = (c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))
	tmp = 0
	if t_1 <= -4e-48:
		tmp = t_1
	elif t_1 <= 0.0:
		tmp = 0.25 * (math.pow((D * M), 2.0) * (h * math.pow(d, -2.0)))
	elif t_1 <= math.inf:
		tmp = t_1
	else:
		tmp = 0.25 / ((math.pow(d, 2.0) / ((D * M) * (D * M))) / h)
	return tmp
function code(c0, w, h, D, d, M)
	t_0 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	t_1 = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M)))))
	tmp = 0.0
	if (t_1 <= -4e-48)
		tmp = t_1;
	elseif (t_1 <= 0.0)
		tmp = Float64(0.25 * Float64((Float64(D * M) ^ 2.0) * Float64(h * (d ^ -2.0))));
	elseif (t_1 <= Inf)
		tmp = t_1;
	else
		tmp = Float64(0.25 / Float64(Float64((d ^ 2.0) / Float64(Float64(D * M) * Float64(D * M))) / h));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	t_1 = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
	tmp = 0.0;
	if (t_1 <= -4e-48)
		tmp = t_1;
	elseif (t_1 <= 0.0)
		tmp = 0.25 * (((D * M) ^ 2.0) * (h * (d ^ -2.0)));
	elseif (t_1 <= Inf)
		tmp = t_1;
	else
		tmp = 0.25 / (((d ^ 2.0) / ((D * M) * (D * M))) / h);
	end
	tmp_2 = tmp;
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 + N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -4e-48], t$95$1, If[LessEqual[t$95$1, 0.0], N[(0.25 * N[(N[Power[N[(D * M), $MachinePrecision], 2.0], $MachinePrecision] * N[(h * N[Power[d, -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, Infinity], t$95$1, N[(0.25 / N[(N[(N[Power[d, 2.0], $MachinePrecision] / N[(N[(D * M), $MachinePrecision] * N[(D * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / h), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\
t_1 := \frac{c0}{2 \cdot w} \cdot \left(t_0 + \sqrt{t_0 \cdot t_0 - M \cdot M}\right)\\
\mathbf{if}\;t_1 \leq -4 \cdot 10^{-48}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;0.25 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \left(h \cdot {d}^{-2}\right)\right)\\

\mathbf{elif}\;t_1 \leq \infty:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;\frac{0.25}{\frac{\frac{{d}^{2}}{\left(D \cdot M\right) \cdot \left(D \cdot M\right)}}{h}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < -3.9999999999999999e-48 or 0.0 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < +inf.0

    1. Initial program 76.5%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]

    if -3.9999999999999999e-48 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < 0.0

    1. Initial program 34.7%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified33.9%

      \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
    3. Taylor expanded in c0 around -inf 45.9%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(-1 \cdot \left(c0 \cdot \left(-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)} + \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)\right) + 0.5 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot \left(h \cdot w\right)\right)}{c0 \cdot {d}^{2}}\right)} \]
    4. Step-by-step derivation
      1. +-commutative45.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(0.5 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot \left(h \cdot w\right)\right)}{c0 \cdot {d}^{2}} + -1 \cdot \left(c0 \cdot \left(-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)} + \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)\right)\right)} \]
      2. fma-def45.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\mathsf{fma}\left(0.5, \frac{{D}^{2} \cdot \left({M}^{2} \cdot \left(h \cdot w\right)\right)}{c0 \cdot {d}^{2}}, -1 \cdot \left(c0 \cdot \left(-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)} + \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)\right)\right)} \]
      3. times-frac45.8%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \color{blue}{\frac{{D}^{2}}{c0} \cdot \frac{{M}^{2} \cdot \left(h \cdot w\right)}{{d}^{2}}}, -1 \cdot \left(c0 \cdot \left(-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)} + \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)\right)\right) \]
      4. associate-*r*45.8%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2}}{c0} \cdot \frac{{M}^{2} \cdot \left(h \cdot w\right)}{{d}^{2}}, \color{blue}{\left(-1 \cdot c0\right) \cdot \left(-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)} + \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}\right) \]
      5. neg-mul-145.8%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2}}{c0} \cdot \frac{{M}^{2} \cdot \left(h \cdot w\right)}{{d}^{2}}, \color{blue}{\left(-c0\right)} \cdot \left(-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)} + \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)\right) \]
      6. distribute-lft1-in45.8%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2}}{c0} \cdot \frac{{M}^{2} \cdot \left(h \cdot w\right)}{{d}^{2}}, \left(-c0\right) \cdot \color{blue}{\left(\left(-1 + 1\right) \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}\right) \]
      7. metadata-eval45.8%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2}}{c0} \cdot \frac{{M}^{2} \cdot \left(h \cdot w\right)}{{d}^{2}}, \left(-c0\right) \cdot \left(\color{blue}{0} \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)\right) \]
      8. mul0-lft45.8%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2}}{c0} \cdot \frac{{M}^{2} \cdot \left(h \cdot w\right)}{{d}^{2}}, \left(-c0\right) \cdot \color{blue}{0}\right) \]
      9. distribute-lft-neg-in45.8%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2}}{c0} \cdot \frac{{M}^{2} \cdot \left(h \cdot w\right)}{{d}^{2}}, \color{blue}{-c0 \cdot 0}\right) \]
      10. distribute-rgt-neg-in45.8%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2}}{c0} \cdot \frac{{M}^{2} \cdot \left(h \cdot w\right)}{{d}^{2}}, \color{blue}{c0 \cdot \left(-0\right)}\right) \]
      11. metadata-eval45.8%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2}}{c0} \cdot \frac{{M}^{2} \cdot \left(h \cdot w\right)}{{d}^{2}}, c0 \cdot \color{blue}{0}\right) \]
    5. Simplified45.8%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\mathsf{fma}\left(0.5, \frac{{D}^{2}}{c0} \cdot \frac{{M}^{2} \cdot \left(h \cdot w\right)}{{d}^{2}}, c0 \cdot 0\right)} \]
    6. Taylor expanded in c0 around 0 40.4%

      \[\leadsto \color{blue}{0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}} \]
    7. Step-by-step derivation
      1. expm1-log1p-u40.4%

        \[\leadsto 0.25 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}\right)\right)} \]
      2. expm1-udef26.1%

        \[\leadsto 0.25 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}\right)} - 1\right)} \]
      3. div-inv26.1%

        \[\leadsto 0.25 \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\left({D}^{2} \cdot \left({M}^{2} \cdot h\right)\right) \cdot \frac{1}{{d}^{2}}}\right)} - 1\right) \]
      4. pow226.1%

        \[\leadsto 0.25 \cdot \left(e^{\mathsf{log1p}\left(\left({D}^{2} \cdot \left(\color{blue}{\left(M \cdot M\right)} \cdot h\right)\right) \cdot \frac{1}{{d}^{2}}\right)} - 1\right) \]
      5. associate-*r*32.5%

        \[\leadsto 0.25 \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\left(\left({D}^{2} \cdot \left(M \cdot M\right)\right) \cdot h\right)} \cdot \frac{1}{{d}^{2}}\right)} - 1\right) \]
      6. pow232.5%

        \[\leadsto 0.25 \cdot \left(e^{\mathsf{log1p}\left(\left(\left({D}^{2} \cdot \color{blue}{{M}^{2}}\right) \cdot h\right) \cdot \frac{1}{{d}^{2}}\right)} - 1\right) \]
      7. pow-prod-down41.4%

        \[\leadsto 0.25 \cdot \left(e^{\mathsf{log1p}\left(\left(\color{blue}{{\left(D \cdot M\right)}^{2}} \cdot h\right) \cdot \frac{1}{{d}^{2}}\right)} - 1\right) \]
      8. pow-flip41.4%

        \[\leadsto 0.25 \cdot \left(e^{\mathsf{log1p}\left(\left({\left(D \cdot M\right)}^{2} \cdot h\right) \cdot \color{blue}{{d}^{\left(-2\right)}}\right)} - 1\right) \]
      9. metadata-eval41.4%

        \[\leadsto 0.25 \cdot \left(e^{\mathsf{log1p}\left(\left({\left(D \cdot M\right)}^{2} \cdot h\right) \cdot {d}^{\color{blue}{-2}}\right)} - 1\right) \]
    8. Applied egg-rr41.4%

      \[\leadsto 0.25 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\left({\left(D \cdot M\right)}^{2} \cdot h\right) \cdot {d}^{-2}\right)} - 1\right)} \]
    9. Step-by-step derivation
      1. expm1-def76.8%

        \[\leadsto 0.25 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left({\left(D \cdot M\right)}^{2} \cdot h\right) \cdot {d}^{-2}\right)\right)} \]
      2. expm1-log1p77.7%

        \[\leadsto 0.25 \cdot \color{blue}{\left(\left({\left(D \cdot M\right)}^{2} \cdot h\right) \cdot {d}^{-2}\right)} \]
      3. associate-*l*78.1%

        \[\leadsto 0.25 \cdot \color{blue}{\left({\left(D \cdot M\right)}^{2} \cdot \left(h \cdot {d}^{-2}\right)\right)} \]
      4. *-commutative78.1%

        \[\leadsto 0.25 \cdot \left({\color{blue}{\left(M \cdot D\right)}}^{2} \cdot \left(h \cdot {d}^{-2}\right)\right) \]
    10. Simplified78.1%

      \[\leadsto 0.25 \cdot \color{blue}{\left({\left(M \cdot D\right)}^{2} \cdot \left(h \cdot {d}^{-2}\right)\right)} \]

    if +inf.0 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M)))))

    1. Initial program 0.0%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified1.3%

      \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
    3. Applied egg-rr1.9%

      \[\leadsto \color{blue}{\frac{c0 \cdot \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right)}{\left(w \cdot 2\right) \cdot \left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right)}} \]
    4. Step-by-step derivation
      1. *-commutative1.9%

        \[\leadsto \frac{\color{blue}{\left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right) \cdot c0}}{\left(w \cdot 2\right) \cdot \left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right)} \]
      2. *-commutative1.9%

        \[\leadsto \frac{\left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right) \cdot c0}{\color{blue}{\left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right) \cdot \left(w \cdot 2\right)}} \]
      3. times-frac1.9%

        \[\leadsto \color{blue}{\frac{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)}{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}} \cdot \frac{c0}{w \cdot 2}} \]
    5. Simplified29.8%

      \[\leadsto \color{blue}{\frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \sqrt{{\left(\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h}\right)}^{2} - {M}^{2}}} \cdot \frac{c0}{2 \cdot w}} \]
    6. Taylor expanded in c0 around -inf 19.8%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{-1 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}} \cdot \frac{c0}{2 \cdot w} \]
    7. Step-by-step derivation
      1. mul-1-neg19.8%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{\left(-\frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}} \cdot \frac{c0}{2 \cdot w} \]
      2. associate-*r*22.8%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{\left({D}^{2} \cdot h\right) \cdot w}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      3. *-commutative22.8%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{\left(h \cdot {D}^{2}\right)} \cdot w}\right)} \cdot \frac{c0}{2 \cdot w} \]
      4. *-commutative22.8%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{w \cdot \left(h \cdot {D}^{2}\right)}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      5. times-frac25.8%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\color{blue}{\frac{c0}{w} \cdot \frac{{d}^{2}}{h \cdot {D}^{2}}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      6. associate-/r*24.7%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0}{w} \cdot \color{blue}{\frac{\frac{{d}^{2}}{h}}{{D}^{2}}}\right)} \cdot \frac{c0}{2 \cdot w} \]
    8. Simplified24.7%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{\left(-\frac{c0}{w} \cdot \frac{\frac{{d}^{2}}{h}}{{D}^{2}}\right)}} \cdot \frac{c0}{2 \cdot w} \]
    9. Taylor expanded in M around 0 39.3%

      \[\leadsto \color{blue}{0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}} \]
    10. Step-by-step derivation
      1. associate-*r/39.3%

        \[\leadsto \color{blue}{\frac{0.25 \cdot \left({D}^{2} \cdot \left({M}^{2} \cdot h\right)\right)}{{d}^{2}}} \]
      2. associate-*r*39.9%

        \[\leadsto \frac{0.25 \cdot \color{blue}{\left(\left({D}^{2} \cdot {M}^{2}\right) \cdot h\right)}}{{d}^{2}} \]
      3. unpow239.9%

        \[\leadsto \frac{0.25 \cdot \left(\left(\color{blue}{\left(D \cdot D\right)} \cdot {M}^{2}\right) \cdot h\right)}{{d}^{2}} \]
      4. unpow239.9%

        \[\leadsto \frac{0.25 \cdot \left(\left(\left(D \cdot D\right) \cdot \color{blue}{\left(M \cdot M\right)}\right) \cdot h\right)}{{d}^{2}} \]
      5. swap-sqr50.1%

        \[\leadsto \frac{0.25 \cdot \left(\color{blue}{\left(\left(D \cdot M\right) \cdot \left(D \cdot M\right)\right)} \cdot h\right)}{{d}^{2}} \]
      6. unpow250.1%

        \[\leadsto \frac{0.25 \cdot \left(\color{blue}{{\left(D \cdot M\right)}^{2}} \cdot h\right)}{{d}^{2}} \]
      7. associate-/l*50.1%

        \[\leadsto \color{blue}{\frac{0.25}{\frac{{d}^{2}}{{\left(D \cdot M\right)}^{2} \cdot h}}} \]
      8. associate-/r*54.0%

        \[\leadsto \frac{0.25}{\color{blue}{\frac{\frac{{d}^{2}}{{\left(D \cdot M\right)}^{2}}}{h}}} \]
      9. *-commutative54.0%

        \[\leadsto \frac{0.25}{\frac{\frac{{d}^{2}}{{\color{blue}{\left(M \cdot D\right)}}^{2}}}{h}} \]
    11. Simplified54.0%

      \[\leadsto \color{blue}{\frac{0.25}{\frac{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}}{h}}} \]
    12. Step-by-step derivation
      1. unpow254.0%

        \[\leadsto \frac{0.25}{\frac{\frac{{d}^{2}}{\color{blue}{\left(M \cdot D\right) \cdot \left(M \cdot D\right)}}}{h}} \]
    13. Applied egg-rr54.0%

      \[\leadsto \frac{0.25}{\frac{\frac{{d}^{2}}{\color{blue}{\left(M \cdot D\right) \cdot \left(M \cdot D\right)}}}{h}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification61.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq -4 \cdot 10^{-48}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right)\\ \mathbf{elif}\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq 0:\\ \;\;\;\;0.25 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \left(h \cdot {d}^{-2}\right)\right)\\ \mathbf{elif}\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq \infty:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25}{\frac{\frac{{d}^{2}}{\left(D \cdot M\right) \cdot \left(D \cdot M\right)}}{h}}\\ \end{array} \]

Alternative 7: 41.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\\ \mathbf{if}\;h \leq -2.4 \cdot 10^{-279} \lor \neg \left(h \leq 7.4 \cdot 10^{-295}\right):\\ \;\;\;\;\frac{0.25}{\frac{\frac{{d}^{2}}{\left(D \cdot M\right) \cdot \left(D \cdot M\right)}}{h}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(t_0 + \sqrt{t_0 \cdot t_0 - M \cdot M}\right)\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (* (/ c0 (* w h)) (/ (* d d) (* D D)))))
   (if (or (<= h -2.4e-279) (not (<= h 7.4e-295)))
     (/ 0.25 (/ (/ (pow d 2.0) (* (* D M) (* D M))) h))
     (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M))))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 / (w * h)) * ((d * d) / (D * D));
	double tmp;
	if ((h <= -2.4e-279) || !(h <= 7.4e-295)) {
		tmp = 0.25 / ((pow(d, 2.0) / ((D * M) * (D * M))) / h);
	} else {
		tmp = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
	}
	return tmp;
}
real(8) function code(c0, w, h, d, d_1, m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d
    real(8), intent (in) :: d_1
    real(8), intent (in) :: m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (c0 / (w * h)) * ((d_1 * d_1) / (d * d))
    if ((h <= (-2.4d-279)) .or. (.not. (h <= 7.4d-295))) then
        tmp = 0.25d0 / (((d_1 ** 2.0d0) / ((d * m) * (d * m))) / h)
    else
        tmp = (c0 / (2.0d0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (m * m))))
    end if
    code = tmp
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 / (w * h)) * ((d * d) / (D * D));
	double tmp;
	if ((h <= -2.4e-279) || !(h <= 7.4e-295)) {
		tmp = 0.25 / ((Math.pow(d, 2.0) / ((D * M) * (D * M))) / h);
	} else {
		tmp = (c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = (c0 / (w * h)) * ((d * d) / (D * D))
	tmp = 0
	if (h <= -2.4e-279) or not (h <= 7.4e-295):
		tmp = 0.25 / ((math.pow(d, 2.0) / ((D * M) * (D * M))) / h)
	else:
		tmp = (c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))
	return tmp
function code(c0, w, h, D, d, M)
	t_0 = Float64(Float64(c0 / Float64(w * h)) * Float64(Float64(d * d) / Float64(D * D)))
	tmp = 0.0
	if ((h <= -2.4e-279) || !(h <= 7.4e-295))
		tmp = Float64(0.25 / Float64(Float64((d ^ 2.0) / Float64(Float64(D * M) * Float64(D * M))) / h));
	else
		tmp = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M)))));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	t_0 = (c0 / (w * h)) * ((d * d) / (D * D));
	tmp = 0.0;
	if ((h <= -2.4e-279) || ~((h <= 7.4e-295)))
		tmp = 0.25 / (((d ^ 2.0) / ((D * M) * (D * M))) / h);
	else
		tmp = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
	end
	tmp_2 = tmp;
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(N[(c0 / N[(w * h), $MachinePrecision]), $MachinePrecision] * N[(N[(d * d), $MachinePrecision] / N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[h, -2.4e-279], N[Not[LessEqual[h, 7.4e-295]], $MachinePrecision]], N[(0.25 / N[(N[(N[Power[d, 2.0], $MachinePrecision] / N[(N[(D * M), $MachinePrecision] * N[(D * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / h), $MachinePrecision]), $MachinePrecision], N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 + N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\\
\mathbf{if}\;h \leq -2.4 \cdot 10^{-279} \lor \neg \left(h \leq 7.4 \cdot 10^{-295}\right):\\
\;\;\;\;\frac{0.25}{\frac{\frac{{d}^{2}}{\left(D \cdot M\right) \cdot \left(D \cdot M\right)}}{h}}\\

\mathbf{else}:\\
\;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(t_0 + \sqrt{t_0 \cdot t_0 - M \cdot M}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if h < -2.3999999999999999e-279 or 7.3999999999999999e-295 < h

    1. Initial program 19.9%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified20.3%

      \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
    3. Applied egg-rr2.3%

      \[\leadsto \color{blue}{\frac{c0 \cdot \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right)}{\left(w \cdot 2\right) \cdot \left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right)}} \]
    4. Step-by-step derivation
      1. *-commutative2.3%

        \[\leadsto \frac{\color{blue}{\left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right) \cdot c0}}{\left(w \cdot 2\right) \cdot \left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right)} \]
      2. *-commutative2.3%

        \[\leadsto \frac{\left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right) \cdot c0}{\color{blue}{\left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right) \cdot \left(w \cdot 2\right)}} \]
      3. times-frac2.3%

        \[\leadsto \color{blue}{\frac{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)}{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}} \cdot \frac{c0}{w \cdot 2}} \]
    5. Simplified24.8%

      \[\leadsto \color{blue}{\frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \sqrt{{\left(\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h}\right)}^{2} - {M}^{2}}} \cdot \frac{c0}{2 \cdot w}} \]
    6. Taylor expanded in c0 around -inf 18.4%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{-1 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}} \cdot \frac{c0}{2 \cdot w} \]
    7. Step-by-step derivation
      1. mul-1-neg18.4%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{\left(-\frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}} \cdot \frac{c0}{2 \cdot w} \]
      2. associate-*r*20.2%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{\left({D}^{2} \cdot h\right) \cdot w}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      3. *-commutative20.2%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{\left(h \cdot {D}^{2}\right)} \cdot w}\right)} \cdot \frac{c0}{2 \cdot w} \]
      4. *-commutative20.2%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{w \cdot \left(h \cdot {D}^{2}\right)}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      5. times-frac22.3%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\color{blue}{\frac{c0}{w} \cdot \frac{{d}^{2}}{h \cdot {D}^{2}}}\right)} \cdot \frac{c0}{2 \cdot w} \]
      6. associate-/r*21.6%

        \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0}{w} \cdot \color{blue}{\frac{\frac{{d}^{2}}{h}}{{D}^{2}}}\right)} \cdot \frac{c0}{2 \cdot w} \]
    8. Simplified21.6%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{\left(-\frac{c0}{w} \cdot \frac{\frac{{d}^{2}}{h}}{{D}^{2}}\right)}} \cdot \frac{c0}{2 \cdot w} \]
    9. Taylor expanded in M around 0 32.9%

      \[\leadsto \color{blue}{0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}} \]
    10. Step-by-step derivation
      1. associate-*r/32.9%

        \[\leadsto \color{blue}{\frac{0.25 \cdot \left({D}^{2} \cdot \left({M}^{2} \cdot h\right)\right)}{{d}^{2}}} \]
      2. associate-*r*34.1%

        \[\leadsto \frac{0.25 \cdot \color{blue}{\left(\left({D}^{2} \cdot {M}^{2}\right) \cdot h\right)}}{{d}^{2}} \]
      3. unpow234.1%

        \[\leadsto \frac{0.25 \cdot \left(\left(\color{blue}{\left(D \cdot D\right)} \cdot {M}^{2}\right) \cdot h\right)}{{d}^{2}} \]
      4. unpow234.1%

        \[\leadsto \frac{0.25 \cdot \left(\left(\left(D \cdot D\right) \cdot \color{blue}{\left(M \cdot M\right)}\right) \cdot h\right)}{{d}^{2}} \]
      5. swap-sqr42.7%

        \[\leadsto \frac{0.25 \cdot \left(\color{blue}{\left(\left(D \cdot M\right) \cdot \left(D \cdot M\right)\right)} \cdot h\right)}{{d}^{2}} \]
      6. unpow242.7%

        \[\leadsto \frac{0.25 \cdot \left(\color{blue}{{\left(D \cdot M\right)}^{2}} \cdot h\right)}{{d}^{2}} \]
      7. associate-/l*42.6%

        \[\leadsto \color{blue}{\frac{0.25}{\frac{{d}^{2}}{{\left(D \cdot M\right)}^{2} \cdot h}}} \]
      8. associate-/r*44.7%

        \[\leadsto \frac{0.25}{\color{blue}{\frac{\frac{{d}^{2}}{{\left(D \cdot M\right)}^{2}}}{h}}} \]
      9. *-commutative44.7%

        \[\leadsto \frac{0.25}{\frac{\frac{{d}^{2}}{{\color{blue}{\left(M \cdot D\right)}}^{2}}}{h}} \]
    11. Simplified44.7%

      \[\leadsto \color{blue}{\frac{0.25}{\frac{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}}{h}}} \]
    12. Step-by-step derivation
      1. unpow244.7%

        \[\leadsto \frac{0.25}{\frac{\frac{{d}^{2}}{\color{blue}{\left(M \cdot D\right) \cdot \left(M \cdot D\right)}}}{h}} \]
    13. Applied egg-rr44.7%

      \[\leadsto \frac{0.25}{\frac{\frac{{d}^{2}}{\color{blue}{\left(M \cdot D\right) \cdot \left(M \cdot D\right)}}}{h}} \]

    if -2.3999999999999999e-279 < h < 7.3999999999999999e-295

    1. Initial program 66.7%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified66.7%

      \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification46.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \leq -2.4 \cdot 10^{-279} \lor \neg \left(h \leq 7.4 \cdot 10^{-295}\right):\\ \;\;\;\;\frac{0.25}{\frac{\frac{{d}^{2}}{\left(D \cdot M\right) \cdot \left(D \cdot M\right)}}{h}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)\\ \end{array} \]

Alternative 8: 42.9% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \frac{0.25}{\frac{\frac{{d}^{2}}{\left(D \cdot M\right) \cdot \left(D \cdot M\right)}}{h}} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (/ 0.25 (/ (/ (pow d 2.0) (* (* D M) (* D M))) h)))
double code(double c0, double w, double h, double D, double d, double M) {
	return 0.25 / ((pow(d, 2.0) / ((D * M) * (D * M))) / h);
}
real(8) function code(c0, w, h, d, d_1, m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d
    real(8), intent (in) :: d_1
    real(8), intent (in) :: m
    code = 0.25d0 / (((d_1 ** 2.0d0) / ((d * m) * (d * m))) / h)
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
	return 0.25 / ((Math.pow(d, 2.0) / ((D * M) * (D * M))) / h);
}
def code(c0, w, h, D, d, M):
	return 0.25 / ((math.pow(d, 2.0) / ((D * M) * (D * M))) / h)
function code(c0, w, h, D, d, M)
	return Float64(0.25 / Float64(Float64((d ^ 2.0) / Float64(Float64(D * M) * Float64(D * M))) / h))
end
function tmp = code(c0, w, h, D, d, M)
	tmp = 0.25 / (((d ^ 2.0) / ((D * M) * (D * M))) / h);
end
code[c0_, w_, h_, D_, d_, M_] := N[(0.25 / N[(N[(N[Power[d, 2.0], $MachinePrecision] / N[(N[(D * M), $MachinePrecision] * N[(D * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / h), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{0.25}{\frac{\frac{{d}^{2}}{\left(D \cdot M\right) \cdot \left(D \cdot M\right)}}{h}}
\end{array}
Derivation
  1. Initial program 22.7%

    \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
  2. Simplified23.1%

    \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
  3. Applied egg-rr2.2%

    \[\leadsto \color{blue}{\frac{c0 \cdot \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right)}{\left(w \cdot 2\right) \cdot \left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right)}} \]
  4. Step-by-step derivation
    1. *-commutative2.2%

      \[\leadsto \frac{\color{blue}{\left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right) \cdot c0}}{\left(w \cdot 2\right) \cdot \left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right)} \]
    2. *-commutative2.2%

      \[\leadsto \frac{\left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)\right) \cdot c0}{\color{blue}{\left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}\right) \cdot \left(w \cdot 2\right)}} \]
    3. times-frac2.2%

      \[\leadsto \color{blue}{\frac{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - \left({\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}\right)}{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{d}{D}\right)}^{4} \cdot {\left(\frac{c0}{w \cdot h}\right)}^{2} - {M}^{2}}} \cdot \frac{c0}{w \cdot 2}} \]
  5. Simplified23.4%

    \[\leadsto \color{blue}{\frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \sqrt{{\left(\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h}\right)}^{2} - {M}^{2}}} \cdot \frac{c0}{2 \cdot w}} \]
  6. Taylor expanded in c0 around -inf 17.3%

    \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{-1 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}} \cdot \frac{c0}{2 \cdot w} \]
  7. Step-by-step derivation
    1. mul-1-neg17.3%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{\left(-\frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}} \cdot \frac{c0}{2 \cdot w} \]
    2. associate-*r*19.0%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{\left({D}^{2} \cdot h\right) \cdot w}}\right)} \cdot \frac{c0}{2 \cdot w} \]
    3. *-commutative19.0%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{\left(h \cdot {D}^{2}\right)} \cdot w}\right)} \cdot \frac{c0}{2 \cdot w} \]
    4. *-commutative19.0%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0 \cdot {d}^{2}}{\color{blue}{w \cdot \left(h \cdot {D}^{2}\right)}}\right)} \cdot \frac{c0}{2 \cdot w} \]
    5. times-frac21.0%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\color{blue}{\frac{c0}{w} \cdot \frac{{d}^{2}}{h \cdot {D}^{2}}}\right)} \cdot \frac{c0}{2 \cdot w} \]
    6. associate-/r*20.4%

      \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \left(-\frac{c0}{w} \cdot \color{blue}{\frac{\frac{{d}^{2}}{h}}{{D}^{2}}}\right)} \cdot \frac{c0}{2 \cdot w} \]
  8. Simplified20.4%

    \[\leadsto \frac{0 + {M}^{2}}{\frac{c0}{w} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h} - \color{blue}{\left(-\frac{c0}{w} \cdot \frac{\frac{{d}^{2}}{h}}{{D}^{2}}\right)}} \cdot \frac{c0}{2 \cdot w} \]
  9. Taylor expanded in M around 0 31.5%

    \[\leadsto \color{blue}{0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}} \]
  10. Step-by-step derivation
    1. associate-*r/31.5%

      \[\leadsto \color{blue}{\frac{0.25 \cdot \left({D}^{2} \cdot \left({M}^{2} \cdot h\right)\right)}{{d}^{2}}} \]
    2. associate-*r*32.6%

      \[\leadsto \frac{0.25 \cdot \color{blue}{\left(\left({D}^{2} \cdot {M}^{2}\right) \cdot h\right)}}{{d}^{2}} \]
    3. unpow232.6%

      \[\leadsto \frac{0.25 \cdot \left(\left(\color{blue}{\left(D \cdot D\right)} \cdot {M}^{2}\right) \cdot h\right)}{{d}^{2}} \]
    4. unpow232.6%

      \[\leadsto \frac{0.25 \cdot \left(\left(\left(D \cdot D\right) \cdot \color{blue}{\left(M \cdot M\right)}\right) \cdot h\right)}{{d}^{2}} \]
    5. swap-sqr40.7%

      \[\leadsto \frac{0.25 \cdot \left(\color{blue}{\left(\left(D \cdot M\right) \cdot \left(D \cdot M\right)\right)} \cdot h\right)}{{d}^{2}} \]
    6. unpow240.7%

      \[\leadsto \frac{0.25 \cdot \left(\color{blue}{{\left(D \cdot M\right)}^{2}} \cdot h\right)}{{d}^{2}} \]
    7. associate-/l*40.6%

      \[\leadsto \color{blue}{\frac{0.25}{\frac{{d}^{2}}{{\left(D \cdot M\right)}^{2} \cdot h}}} \]
    8. associate-/r*43.3%

      \[\leadsto \frac{0.25}{\color{blue}{\frac{\frac{{d}^{2}}{{\left(D \cdot M\right)}^{2}}}{h}}} \]
    9. *-commutative43.3%

      \[\leadsto \frac{0.25}{\frac{\frac{{d}^{2}}{{\color{blue}{\left(M \cdot D\right)}}^{2}}}{h}} \]
  11. Simplified43.3%

    \[\leadsto \color{blue}{\frac{0.25}{\frac{\frac{{d}^{2}}{{\left(M \cdot D\right)}^{2}}}{h}}} \]
  12. Step-by-step derivation
    1. unpow243.3%

      \[\leadsto \frac{0.25}{\frac{\frac{{d}^{2}}{\color{blue}{\left(M \cdot D\right) \cdot \left(M \cdot D\right)}}}{h}} \]
  13. Applied egg-rr43.3%

    \[\leadsto \frac{0.25}{\frac{\frac{{d}^{2}}{\color{blue}{\left(M \cdot D\right) \cdot \left(M \cdot D\right)}}}{h}} \]
  14. Final simplification43.3%

    \[\leadsto \frac{0.25}{\frac{\frac{{d}^{2}}{\left(D \cdot M\right) \cdot \left(D \cdot M\right)}}{h}} \]

Alternative 9: 34.1% accurate, 151.0× speedup?

\[\begin{array}{l} \\ 0 \end{array} \]
(FPCore (c0 w h D d M) :precision binary64 0.0)
double code(double c0, double w, double h, double D, double d, double M) {
	return 0.0;
}
real(8) function code(c0, w, h, d, d_1, m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d
    real(8), intent (in) :: d_1
    real(8), intent (in) :: m
    code = 0.0d0
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
	return 0.0;
}
def code(c0, w, h, D, d, M):
	return 0.0
function code(c0, w, h, D, d, M)
	return 0.0
end
function tmp = code(c0, w, h, D, d, M)
	tmp = 0.0;
end
code[c0_, w_, h_, D_, d_, M_] := 0.0
\begin{array}{l}

\\
0
\end{array}
Derivation
  1. Initial program 22.7%

    \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
  2. Simplified23.1%

    \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
  3. Taylor expanded in c0 around -inf 2.3%

    \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(-1 \cdot \left(c0 \cdot \left(-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)} + \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)\right)\right)} \]
  4. Step-by-step derivation
    1. associate-*r*2.3%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(\left(-1 \cdot c0\right) \cdot \left(-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)} + \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)\right)} \]
    2. neg-mul-12.3%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\color{blue}{\left(-c0\right)} \cdot \left(-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)} + \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)\right) \]
    3. distribute-lft1-in2.3%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\left(-c0\right) \cdot \color{blue}{\left(\left(-1 + 1\right) \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}\right) \]
    4. metadata-eval2.3%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\left(-c0\right) \cdot \left(\color{blue}{0} \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)\right) \]
    5. mul0-lft26.6%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\left(-c0\right) \cdot \color{blue}{0}\right) \]
    6. distribute-lft-neg-in26.6%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(-c0 \cdot 0\right)} \]
    7. distribute-rgt-neg-in26.6%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(c0 \cdot \left(-0\right)\right)} \]
    8. metadata-eval26.6%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(c0 \cdot \color{blue}{0}\right) \]
  5. Simplified26.6%

    \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(c0 \cdot 0\right)} \]
  6. Taylor expanded in c0 around 0 31.1%

    \[\leadsto \color{blue}{0} \]
  7. Final simplification31.1%

    \[\leadsto 0 \]

Reproduce

?
herbie shell --seed 2023336 
(FPCore (c0 w h D d M)
  :name "Henrywood and Agarwal, Equation (13)"
  :precision binary64
  (* (/ c0 (* 2.0 w)) (+ (/ (* c0 (* d d)) (* (* w h) (* D D))) (sqrt (- (* (/ (* c0 (* d d)) (* (* w h) (* D D))) (/ (* c0 (* d d)) (* (* w h) (* D D)))) (* M M))))))