Henrywood and Agarwal, Equation (13)

Percentage Accurate: 25.0% → 43.0%
Time: 27.6s
Alternatives: 5
Speedup: 21.6×

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 5 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: 25.0% 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: 43.0% accurate, 1.2× speedup?

\[\begin{array}{l} d_m = \left|d\right| \\ \begin{array}{l} t_0 := \frac{c0}{2 \cdot w}\\ \mathbf{if}\;d_m \leq 1.45 \cdot 10^{+99} \lor \neg \left(d_m \leq 9.4 \cdot 10^{+120}\right) \land \left(d_m \leq 7.8 \cdot 10^{+131} \lor \neg \left(d_m \leq 6.8 \cdot 10^{+187}\right) \land d_m \leq 7 \cdot 10^{+287}\right):\\ \;\;\;\;t_0 \cdot \left(2 \cdot \frac{{\left(\frac{d_m}{D}\right)}^{2} \cdot \frac{c0}{w}}{h}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot 0\\ \end{array} \end{array} \]
d_m = (fabs.f64 d)
(FPCore (c0 w h D d_m M)
 :precision binary64
 (let* ((t_0 (/ c0 (* 2.0 w))))
   (if (or (<= d_m 1.45e+99)
           (and (not (<= d_m 9.4e+120))
                (or (<= d_m 7.8e+131)
                    (and (not (<= d_m 6.8e+187)) (<= d_m 7e+287)))))
     (* t_0 (* 2.0 (/ (* (pow (/ d_m D) 2.0) (/ c0 w)) h)))
     (* t_0 0.0))))
d_m = fabs(d);
double code(double c0, double w, double h, double D, double d_m, double M) {
	double t_0 = c0 / (2.0 * w);
	double tmp;
	if ((d_m <= 1.45e+99) || (!(d_m <= 9.4e+120) && ((d_m <= 7.8e+131) || (!(d_m <= 6.8e+187) && (d_m <= 7e+287))))) {
		tmp = t_0 * (2.0 * ((pow((d_m / D), 2.0) * (c0 / w)) / h));
	} else {
		tmp = t_0 * 0.0;
	}
	return tmp;
}
d_m = abs(d)
real(8) function code(c0, w, h, d, d_m, 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_m
    real(8), intent (in) :: m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = c0 / (2.0d0 * w)
    if ((d_m <= 1.45d+99) .or. (.not. (d_m <= 9.4d+120)) .and. (d_m <= 7.8d+131) .or. (.not. (d_m <= 6.8d+187)) .and. (d_m <= 7d+287)) then
        tmp = t_0 * (2.0d0 * ((((d_m / d) ** 2.0d0) * (c0 / w)) / h))
    else
        tmp = t_0 * 0.0d0
    end if
    code = tmp
end function
d_m = Math.abs(d);
public static double code(double c0, double w, double h, double D, double d_m, double M) {
	double t_0 = c0 / (2.0 * w);
	double tmp;
	if ((d_m <= 1.45e+99) || (!(d_m <= 9.4e+120) && ((d_m <= 7.8e+131) || (!(d_m <= 6.8e+187) && (d_m <= 7e+287))))) {
		tmp = t_0 * (2.0 * ((Math.pow((d_m / D), 2.0) * (c0 / w)) / h));
	} else {
		tmp = t_0 * 0.0;
	}
	return tmp;
}
d_m = math.fabs(d)
def code(c0, w, h, D, d_m, M):
	t_0 = c0 / (2.0 * w)
	tmp = 0
	if (d_m <= 1.45e+99) or (not (d_m <= 9.4e+120) and ((d_m <= 7.8e+131) or (not (d_m <= 6.8e+187) and (d_m <= 7e+287)))):
		tmp = t_0 * (2.0 * ((math.pow((d_m / D), 2.0) * (c0 / w)) / h))
	else:
		tmp = t_0 * 0.0
	return tmp
d_m = abs(d)
function code(c0, w, h, D, d_m, M)
	t_0 = Float64(c0 / Float64(2.0 * w))
	tmp = 0.0
	if ((d_m <= 1.45e+99) || (!(d_m <= 9.4e+120) && ((d_m <= 7.8e+131) || (!(d_m <= 6.8e+187) && (d_m <= 7e+287)))))
		tmp = Float64(t_0 * Float64(2.0 * Float64(Float64((Float64(d_m / D) ^ 2.0) * Float64(c0 / w)) / h)));
	else
		tmp = Float64(t_0 * 0.0);
	end
	return tmp
end
d_m = abs(d);
function tmp_2 = code(c0, w, h, D, d_m, M)
	t_0 = c0 / (2.0 * w);
	tmp = 0.0;
	if ((d_m <= 1.45e+99) || (~((d_m <= 9.4e+120)) && ((d_m <= 7.8e+131) || (~((d_m <= 6.8e+187)) && (d_m <= 7e+287)))))
		tmp = t_0 * (2.0 * ((((d_m / D) ^ 2.0) * (c0 / w)) / h));
	else
		tmp = t_0 * 0.0;
	end
	tmp_2 = tmp;
end
d_m = N[Abs[d], $MachinePrecision]
code[c0_, w_, h_, D_, d$95$m_, M_] := Block[{t$95$0 = N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[d$95$m, 1.45e+99], And[N[Not[LessEqual[d$95$m, 9.4e+120]], $MachinePrecision], Or[LessEqual[d$95$m, 7.8e+131], And[N[Not[LessEqual[d$95$m, 6.8e+187]], $MachinePrecision], LessEqual[d$95$m, 7e+287]]]]], N[(t$95$0 * N[(2.0 * N[(N[(N[Power[N[(d$95$m / D), $MachinePrecision], 2.0], $MachinePrecision] * N[(c0 / w), $MachinePrecision]), $MachinePrecision] / h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * 0.0), $MachinePrecision]]]
\begin{array}{l}
d_m = \left|d\right|

\\
\begin{array}{l}
t_0 := \frac{c0}{2 \cdot w}\\
\mathbf{if}\;d_m \leq 1.45 \cdot 10^{+99} \lor \neg \left(d_m \leq 9.4 \cdot 10^{+120}\right) \land \left(d_m \leq 7.8 \cdot 10^{+131} \lor \neg \left(d_m \leq 6.8 \cdot 10^{+187}\right) \land d_m \leq 7 \cdot 10^{+287}\right):\\
\;\;\;\;t_0 \cdot \left(2 \cdot \frac{{\left(\frac{d_m}{D}\right)}^{2} \cdot \frac{c0}{w}}{h}\right)\\

\mathbf{else}:\\
\;\;\;\;t_0 \cdot 0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < 1.4500000000000001e99 or 9.39999999999999987e120 < d < 7.8e131 or 6.7999999999999999e187 < d < 6.99999999999999951e287

    1. Initial program 27.3%

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

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

        \[\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. associate-/l/38.5%

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \frac{\color{blue}{\frac{c0}{w \cdot h} \cdot {d}^{2}}}{{D}^{2}}\right) \]
      4. associate-/l*38.2%

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

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \color{blue}{\left(\frac{c0}{h \cdot w} \cdot \frac{1}{\frac{{D}^{2}}{{d}^{2}}}\right)}\right) \]
      2. associate-/l/38.7%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \left(\color{blue}{\frac{\frac{c0}{w}}{h}} \cdot \frac{1}{\frac{{D}^{2}}{{d}^{2}}}\right)\right) \]
      3. clear-num38.7%

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

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

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

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

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

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

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

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

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

    if 1.4500000000000001e99 < d < 9.39999999999999987e120 or 7.8e131 < d < 6.7999999999999999e187 or 6.99999999999999951e287 < d

    1. Initial program 14.3%

      \[\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. Simplified17.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. Taylor expanded in c0 around -inf 0.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. mul-1-neg0.3%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\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)} \]
      2. distribute-lft-in0.1%

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{0} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification51.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 1.45 \cdot 10^{+99} \lor \neg \left(d \leq 9.4 \cdot 10^{+120}\right) \land \left(d \leq 7.8 \cdot 10^{+131} \lor \neg \left(d \leq 6.8 \cdot 10^{+187}\right) \land d \leq 7 \cdot 10^{+287}\right):\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(2 \cdot \frac{{\left(\frac{d}{D}\right)}^{2} \cdot \frac{c0}{w}}{h}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot 0\\ \end{array} \]

Alternative 2: 52.8% accurate, 0.3× speedup?

\[\begin{array}{l} d_m = \left|d\right| \\ \begin{array}{l} t_0 := \frac{c0}{2 \cdot w}\\ t_1 := \frac{c0 \cdot \left(d_m \cdot d_m\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ \mathbf{if}\;t_0 \cdot \left(t_1 + \sqrt{t_1 \cdot t_1 - M \cdot M}\right) \leq \infty:\\ \;\;\;\;t_0 \cdot \left(2 \cdot \left(\frac{c0}{\left(w \cdot h\right) \cdot {D}^{2}} \cdot {d_m}^{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25 \cdot \left({D}^{2} \cdot \left(h \cdot {M}^{2}\right)\right)}{{d_m}^{2}}\\ \end{array} \end{array} \]
d_m = (fabs.f64 d)
(FPCore (c0 w h D d_m M)
 :precision binary64
 (let* ((t_0 (/ c0 (* 2.0 w)))
        (t_1 (/ (* c0 (* d_m d_m)) (* (* w h) (* D D)))))
   (if (<= (* t_0 (+ t_1 (sqrt (- (* t_1 t_1) (* M M))))) INFINITY)
     (* t_0 (* 2.0 (* (/ c0 (* (* w h) (pow D 2.0))) (pow d_m 2.0))))
     (/ (* 0.25 (* (pow D 2.0) (* h (pow M 2.0)))) (pow d_m 2.0)))))
d_m = fabs(d);
double code(double c0, double w, double h, double D, double d_m, double M) {
	double t_0 = c0 / (2.0 * w);
	double t_1 = (c0 * (d_m * d_m)) / ((w * h) * (D * D));
	double tmp;
	if ((t_0 * (t_1 + sqrt(((t_1 * t_1) - (M * M))))) <= ((double) INFINITY)) {
		tmp = t_0 * (2.0 * ((c0 / ((w * h) * pow(D, 2.0))) * pow(d_m, 2.0)));
	} else {
		tmp = (0.25 * (pow(D, 2.0) * (h * pow(M, 2.0)))) / pow(d_m, 2.0);
	}
	return tmp;
}
d_m = Math.abs(d);
public static double code(double c0, double w, double h, double D, double d_m, double M) {
	double t_0 = c0 / (2.0 * w);
	double t_1 = (c0 * (d_m * d_m)) / ((w * h) * (D * D));
	double tmp;
	if ((t_0 * (t_1 + Math.sqrt(((t_1 * t_1) - (M * M))))) <= Double.POSITIVE_INFINITY) {
		tmp = t_0 * (2.0 * ((c0 / ((w * h) * Math.pow(D, 2.0))) * Math.pow(d_m, 2.0)));
	} else {
		tmp = (0.25 * (Math.pow(D, 2.0) * (h * Math.pow(M, 2.0)))) / Math.pow(d_m, 2.0);
	}
	return tmp;
}
d_m = math.fabs(d)
def code(c0, w, h, D, d_m, M):
	t_0 = c0 / (2.0 * w)
	t_1 = (c0 * (d_m * d_m)) / ((w * h) * (D * D))
	tmp = 0
	if (t_0 * (t_1 + math.sqrt(((t_1 * t_1) - (M * M))))) <= math.inf:
		tmp = t_0 * (2.0 * ((c0 / ((w * h) * math.pow(D, 2.0))) * math.pow(d_m, 2.0)))
	else:
		tmp = (0.25 * (math.pow(D, 2.0) * (h * math.pow(M, 2.0)))) / math.pow(d_m, 2.0)
	return tmp
d_m = abs(d)
function code(c0, w, h, D, d_m, M)
	t_0 = Float64(c0 / Float64(2.0 * w))
	t_1 = Float64(Float64(c0 * Float64(d_m * d_m)) / Float64(Float64(w * h) * Float64(D * D)))
	tmp = 0.0
	if (Float64(t_0 * Float64(t_1 + sqrt(Float64(Float64(t_1 * t_1) - Float64(M * M))))) <= Inf)
		tmp = Float64(t_0 * Float64(2.0 * Float64(Float64(c0 / Float64(Float64(w * h) * (D ^ 2.0))) * (d_m ^ 2.0))));
	else
		tmp = Float64(Float64(0.25 * Float64((D ^ 2.0) * Float64(h * (M ^ 2.0)))) / (d_m ^ 2.0));
	end
	return tmp
end
d_m = abs(d);
function tmp_2 = code(c0, w, h, D, d_m, M)
	t_0 = c0 / (2.0 * w);
	t_1 = (c0 * (d_m * d_m)) / ((w * h) * (D * D));
	tmp = 0.0;
	if ((t_0 * (t_1 + sqrt(((t_1 * t_1) - (M * M))))) <= Inf)
		tmp = t_0 * (2.0 * ((c0 / ((w * h) * (D ^ 2.0))) * (d_m ^ 2.0)));
	else
		tmp = (0.25 * ((D ^ 2.0) * (h * (M ^ 2.0)))) / (d_m ^ 2.0);
	end
	tmp_2 = tmp;
end
d_m = N[Abs[d], $MachinePrecision]
code[c0_, w_, h_, D_, d$95$m_, M_] := Block[{t$95$0 = N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c0 * N[(d$95$m * d$95$m), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[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], Infinity], N[(t$95$0 * N[(2.0 * N[(N[(c0 / N[(N[(w * h), $MachinePrecision] * N[Power[D, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[d$95$m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.25 * N[(N[Power[D, 2.0], $MachinePrecision] * N[(h * N[Power[M, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[d$95$m, 2.0], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
d_m = \left|d\right|

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

\mathbf{else}:\\
\;\;\;\;\frac{0.25 \cdot \left({D}^{2} \cdot \left(h \cdot {M}^{2}\right)\right)}{{d_m}^{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))))) < +inf.0

    1. Initial program 72.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. Simplified71.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. Taylor expanded in c0 around inf 75.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)} \]
    4. Step-by-step derivation
      1. associate-/l*73.4%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(2 \cdot \left(\frac{c0}{{D}^{2} \cdot \left(h \cdot w\right)} \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. Simplified2.4%

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\mathsf{fma}\left(-1, 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), 0.5 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot \left(h \cdot w\right)\right)}{c0 \cdot {d}^{2}}\right)} \]
      2. distribute-lft1-in2.6%

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(-1, c0 \cdot \left(\color{blue}{0} \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\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. associate-/r*3.2%

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

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

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

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

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

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

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

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

    \[\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 \infty:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(2 \cdot \left(\frac{c0}{\left(w \cdot h\right) \cdot {D}^{2}} \cdot {d}^{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25 \cdot \left({D}^{2} \cdot \left(h \cdot {M}^{2}\right)\right)}{{d}^{2}}\\ \end{array} \]

Alternative 3: 49.9% accurate, 0.4× speedup?

\[\begin{array}{l} d_m = \left|d\right| \\ \begin{array}{l} t_0 := \frac{c0}{2 \cdot w}\\ t_1 := \frac{c0 \cdot \left(d_m \cdot d_m\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ \mathbf{if}\;t_0 \cdot \left(t_1 + \sqrt{t_1 \cdot t_1 - M \cdot M}\right) \leq \infty:\\ \;\;\;\;t_0 \cdot \left(2 \cdot \left(\frac{c0}{\left(w \cdot h\right) \cdot {D}^{2}} \cdot {d_m}^{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot 0\\ \end{array} \end{array} \]
d_m = (fabs.f64 d)
(FPCore (c0 w h D d_m M)
 :precision binary64
 (let* ((t_0 (/ c0 (* 2.0 w)))
        (t_1 (/ (* c0 (* d_m d_m)) (* (* w h) (* D D)))))
   (if (<= (* t_0 (+ t_1 (sqrt (- (* t_1 t_1) (* M M))))) INFINITY)
     (* t_0 (* 2.0 (* (/ c0 (* (* w h) (pow D 2.0))) (pow d_m 2.0))))
     (* t_0 0.0))))
d_m = fabs(d);
double code(double c0, double w, double h, double D, double d_m, double M) {
	double t_0 = c0 / (2.0 * w);
	double t_1 = (c0 * (d_m * d_m)) / ((w * h) * (D * D));
	double tmp;
	if ((t_0 * (t_1 + sqrt(((t_1 * t_1) - (M * M))))) <= ((double) INFINITY)) {
		tmp = t_0 * (2.0 * ((c0 / ((w * h) * pow(D, 2.0))) * pow(d_m, 2.0)));
	} else {
		tmp = t_0 * 0.0;
	}
	return tmp;
}
d_m = Math.abs(d);
public static double code(double c0, double w, double h, double D, double d_m, double M) {
	double t_0 = c0 / (2.0 * w);
	double t_1 = (c0 * (d_m * d_m)) / ((w * h) * (D * D));
	double tmp;
	if ((t_0 * (t_1 + Math.sqrt(((t_1 * t_1) - (M * M))))) <= Double.POSITIVE_INFINITY) {
		tmp = t_0 * (2.0 * ((c0 / ((w * h) * Math.pow(D, 2.0))) * Math.pow(d_m, 2.0)));
	} else {
		tmp = t_0 * 0.0;
	}
	return tmp;
}
d_m = math.fabs(d)
def code(c0, w, h, D, d_m, M):
	t_0 = c0 / (2.0 * w)
	t_1 = (c0 * (d_m * d_m)) / ((w * h) * (D * D))
	tmp = 0
	if (t_0 * (t_1 + math.sqrt(((t_1 * t_1) - (M * M))))) <= math.inf:
		tmp = t_0 * (2.0 * ((c0 / ((w * h) * math.pow(D, 2.0))) * math.pow(d_m, 2.0)))
	else:
		tmp = t_0 * 0.0
	return tmp
d_m = abs(d)
function code(c0, w, h, D, d_m, M)
	t_0 = Float64(c0 / Float64(2.0 * w))
	t_1 = Float64(Float64(c0 * Float64(d_m * d_m)) / Float64(Float64(w * h) * Float64(D * D)))
	tmp = 0.0
	if (Float64(t_0 * Float64(t_1 + sqrt(Float64(Float64(t_1 * t_1) - Float64(M * M))))) <= Inf)
		tmp = Float64(t_0 * Float64(2.0 * Float64(Float64(c0 / Float64(Float64(w * h) * (D ^ 2.0))) * (d_m ^ 2.0))));
	else
		tmp = Float64(t_0 * 0.0);
	end
	return tmp
end
d_m = abs(d);
function tmp_2 = code(c0, w, h, D, d_m, M)
	t_0 = c0 / (2.0 * w);
	t_1 = (c0 * (d_m * d_m)) / ((w * h) * (D * D));
	tmp = 0.0;
	if ((t_0 * (t_1 + sqrt(((t_1 * t_1) - (M * M))))) <= Inf)
		tmp = t_0 * (2.0 * ((c0 / ((w * h) * (D ^ 2.0))) * (d_m ^ 2.0)));
	else
		tmp = t_0 * 0.0;
	end
	tmp_2 = tmp;
end
d_m = N[Abs[d], $MachinePrecision]
code[c0_, w_, h_, D_, d$95$m_, M_] := Block[{t$95$0 = N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c0 * N[(d$95$m * d$95$m), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[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], Infinity], N[(t$95$0 * N[(2.0 * N[(N[(c0 / N[(N[(w * h), $MachinePrecision] * N[Power[D, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[d$95$m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * 0.0), $MachinePrecision]]]]
\begin{array}{l}
d_m = \left|d\right|

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

\mathbf{else}:\\
\;\;\;\;t_0 \cdot 0\\


\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))))) < +inf.0

    1. Initial program 72.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. Simplified71.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. Taylor expanded in c0 around inf 75.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)} \]
    4. Step-by-step derivation
      1. associate-/l*73.4%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(2 \cdot \left(\frac{c0}{{D}^{2} \cdot \left(h \cdot w\right)} \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. Simplified2.4%

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

      \[\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. mul-1-neg2.0%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\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)} \]
      2. distribute-lft-in1.4%

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{0} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification50.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 \infty:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(2 \cdot \left(\frac{c0}{\left(w \cdot h\right) \cdot {D}^{2}} \cdot {d}^{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot 0\\ \end{array} \]

Alternative 4: 43.3% accurate, 1.2× speedup?

\[\begin{array}{l} d_m = \left|d\right| \\ \begin{array}{l} t_0 := \frac{c0}{2 \cdot w}\\ \mathbf{if}\;M \leq 1.35 \cdot 10^{-280} \lor \neg \left(M \leq 4.8 \cdot 10^{-205}\right):\\ \;\;\;\;t_0 \cdot \left(2 \cdot \left(\frac{c0}{h} \cdot \frac{{\left(\frac{d_m}{D}\right)}^{2}}{w}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot 0\\ \end{array} \end{array} \]
d_m = (fabs.f64 d)
(FPCore (c0 w h D d_m M)
 :precision binary64
 (let* ((t_0 (/ c0 (* 2.0 w))))
   (if (or (<= M 1.35e-280) (not (<= M 4.8e-205)))
     (* t_0 (* 2.0 (* (/ c0 h) (/ (pow (/ d_m D) 2.0) w))))
     (* t_0 0.0))))
d_m = fabs(d);
double code(double c0, double w, double h, double D, double d_m, double M) {
	double t_0 = c0 / (2.0 * w);
	double tmp;
	if ((M <= 1.35e-280) || !(M <= 4.8e-205)) {
		tmp = t_0 * (2.0 * ((c0 / h) * (pow((d_m / D), 2.0) / w)));
	} else {
		tmp = t_0 * 0.0;
	}
	return tmp;
}
d_m = abs(d)
real(8) function code(c0, w, h, d, d_m, 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_m
    real(8), intent (in) :: m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = c0 / (2.0d0 * w)
    if ((m <= 1.35d-280) .or. (.not. (m <= 4.8d-205))) then
        tmp = t_0 * (2.0d0 * ((c0 / h) * (((d_m / d) ** 2.0d0) / w)))
    else
        tmp = t_0 * 0.0d0
    end if
    code = tmp
end function
d_m = Math.abs(d);
public static double code(double c0, double w, double h, double D, double d_m, double M) {
	double t_0 = c0 / (2.0 * w);
	double tmp;
	if ((M <= 1.35e-280) || !(M <= 4.8e-205)) {
		tmp = t_0 * (2.0 * ((c0 / h) * (Math.pow((d_m / D), 2.0) / w)));
	} else {
		tmp = t_0 * 0.0;
	}
	return tmp;
}
d_m = math.fabs(d)
def code(c0, w, h, D, d_m, M):
	t_0 = c0 / (2.0 * w)
	tmp = 0
	if (M <= 1.35e-280) or not (M <= 4.8e-205):
		tmp = t_0 * (2.0 * ((c0 / h) * (math.pow((d_m / D), 2.0) / w)))
	else:
		tmp = t_0 * 0.0
	return tmp
d_m = abs(d)
function code(c0, w, h, D, d_m, M)
	t_0 = Float64(c0 / Float64(2.0 * w))
	tmp = 0.0
	if ((M <= 1.35e-280) || !(M <= 4.8e-205))
		tmp = Float64(t_0 * Float64(2.0 * Float64(Float64(c0 / h) * Float64((Float64(d_m / D) ^ 2.0) / w))));
	else
		tmp = Float64(t_0 * 0.0);
	end
	return tmp
end
d_m = abs(d);
function tmp_2 = code(c0, w, h, D, d_m, M)
	t_0 = c0 / (2.0 * w);
	tmp = 0.0;
	if ((M <= 1.35e-280) || ~((M <= 4.8e-205)))
		tmp = t_0 * (2.0 * ((c0 / h) * (((d_m / D) ^ 2.0) / w)));
	else
		tmp = t_0 * 0.0;
	end
	tmp_2 = tmp;
end
d_m = N[Abs[d], $MachinePrecision]
code[c0_, w_, h_, D_, d$95$m_, M_] := Block[{t$95$0 = N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[M, 1.35e-280], N[Not[LessEqual[M, 4.8e-205]], $MachinePrecision]], N[(t$95$0 * N[(2.0 * N[(N[(c0 / h), $MachinePrecision] * N[(N[Power[N[(d$95$m / D), $MachinePrecision], 2.0], $MachinePrecision] / w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * 0.0), $MachinePrecision]]]
\begin{array}{l}
d_m = \left|d\right|

\\
\begin{array}{l}
t_0 := \frac{c0}{2 \cdot w}\\
\mathbf{if}\;M \leq 1.35 \cdot 10^{-280} \lor \neg \left(M \leq 4.8 \cdot 10^{-205}\right):\\
\;\;\;\;t_0 \cdot \left(2 \cdot \left(\frac{c0}{h} \cdot \frac{{\left(\frac{d_m}{D}\right)}^{2}}{w}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t_0 \cdot 0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < 1.34999999999999992e-280 or 4.8000000000000004e-205 < M

    1. Initial program 25.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) \]
    2. Simplified27.4%

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

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

        \[\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. associate-/l/37.3%

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \frac{\color{blue}{\frac{c0}{w \cdot h} \cdot {d}^{2}}}{{D}^{2}}\right) \]
      4. associate-/l*37.5%

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

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

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \left(\frac{c0}{\color{blue}{w \cdot h}} \cdot \frac{1}{\frac{{D}^{2}}{{d}^{2}}}\right)\right) \]
      3. clear-num37.5%

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

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \left(\frac{c0}{w \cdot h} \cdot \color{blue}{\left(\frac{d}{D} \cdot \frac{d}{D}\right)}\right)\right) \]
      7. pow246.6%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \left(\frac{c0}{w \cdot h} \cdot \color{blue}{{\left(\frac{d}{D}\right)}^{2}}\right)\right) \]
      8. associate-*l/47.2%

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

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

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

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

    if 1.34999999999999992e-280 < M < 4.8000000000000004e-205

    1. Initial program 27.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. Simplified21.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. Taylor expanded in c0 around -inf 16.4%

      \[\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. mul-1-neg16.4%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\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)} \]
      2. distribute-lft-in16.4%

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{0} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification46.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq 1.35 \cdot 10^{-280} \lor \neg \left(M \leq 4.8 \cdot 10^{-205}\right):\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(2 \cdot \left(\frac{c0}{h} \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{w}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot 0\\ \end{array} \]

Alternative 5: 28.7% accurate, 21.6× speedup?

\[\begin{array}{l} d_m = \left|d\right| \\ \frac{c0}{2 \cdot w} \cdot 0 \end{array} \]
d_m = (fabs.f64 d)
(FPCore (c0 w h D d_m M) :precision binary64 (* (/ c0 (* 2.0 w)) 0.0))
d_m = fabs(d);
double code(double c0, double w, double h, double D, double d_m, double M) {
	return (c0 / (2.0 * w)) * 0.0;
}
d_m = abs(d)
real(8) function code(c0, w, h, d, d_m, 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_m
    real(8), intent (in) :: m
    code = (c0 / (2.0d0 * w)) * 0.0d0
end function
d_m = Math.abs(d);
public static double code(double c0, double w, double h, double D, double d_m, double M) {
	return (c0 / (2.0 * w)) * 0.0;
}
d_m = math.fabs(d)
def code(c0, w, h, D, d_m, M):
	return (c0 / (2.0 * w)) * 0.0
d_m = abs(d)
function code(c0, w, h, D, d_m, M)
	return Float64(Float64(c0 / Float64(2.0 * w)) * 0.0)
end
d_m = abs(d);
function tmp = code(c0, w, h, D, d_m, M)
	tmp = (c0 / (2.0 * w)) * 0.0;
end
d_m = N[Abs[d], $MachinePrecision]
code[c0_, w_, h_, D_, d$95$m_, M_] := N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * 0.0), $MachinePrecision]
\begin{array}{l}
d_m = \left|d\right|

\\
\frac{c0}{2 \cdot w} \cdot 0
\end{array}
Derivation
  1. Initial program 25.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) \]
  2. Simplified26.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 3.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)\right)} \]
  4. Step-by-step derivation
    1. mul-1-neg3.9%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\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)} \]
    2. distribute-lft-in3.5%

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

    \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{0} \]
  6. Final simplification26.9%

    \[\leadsto \frac{c0}{2 \cdot w} \cdot 0 \]

Reproduce

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