Average Error: 14.1 → 7.8
Time: 9.2s
Precision: binary64
\[ \begin{array}{c}[M, D] = \mathsf{sort}([M, D])\\ \end{array} \]
\[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
\[\begin{array}{l} t_0 := \sqrt{\frac{h}{\ell} \cdot \left(-0.25 \cdot \left(\frac{M}{d} \cdot \frac{M}{d}\right)\right)}\\ t_1 := {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+303}:\\ \;\;\;\;\mathsf{fma}\left(D, t_0 \cdot w0, 0.5 \cdot \frac{\frac{w0}{D}}{t_0}\right)\\ \mathbf{elif}\;t_1 \leq 0.0002:\\ \;\;\;\;w0 \cdot \sqrt{1 - t_1}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \]
(FPCore (w0 M D h l d)
 :precision binary64
 (* w0 (sqrt (- 1.0 (* (pow (/ (* M D) (* 2.0 d)) 2.0) (/ h l))))))
(FPCore (w0 M D h l d)
 :precision binary64
 (let* ((t_0 (sqrt (* (/ h l) (* -0.25 (* (/ M d) (/ M d))))))
        (t_1 (* (pow (/ (* M D) (* 2.0 d)) 2.0) (/ h l))))
   (if (<= t_1 -5e+303)
     (fma D (* t_0 w0) (* 0.5 (/ (/ w0 D) t_0)))
     (if (<= t_1 0.0002) (* w0 (sqrt (- 1.0 t_1))) w0))))
double code(double w0, double M, double D, double h, double l, double d) {
	return w0 * sqrt((1.0 - (pow(((M * D) / (2.0 * d)), 2.0) * (h / l))));
}
double code(double w0, double M, double D, double h, double l, double d) {
	double t_0 = sqrt(((h / l) * (-0.25 * ((M / d) * (M / d)))));
	double t_1 = pow(((M * D) / (2.0 * d)), 2.0) * (h / l);
	double tmp;
	if (t_1 <= -5e+303) {
		tmp = fma(D, (t_0 * w0), (0.5 * ((w0 / D) / t_0)));
	} else if (t_1 <= 0.0002) {
		tmp = w0 * sqrt((1.0 - t_1));
	} else {
		tmp = w0;
	}
	return tmp;
}
function code(w0, M, D, h, l, d)
	return Float64(w0 * sqrt(Float64(1.0 - Float64((Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l)))))
end
function code(w0, M, D, h, l, d)
	t_0 = sqrt(Float64(Float64(h / l) * Float64(-0.25 * Float64(Float64(M / d) * Float64(M / d)))))
	t_1 = Float64((Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l))
	tmp = 0.0
	if (t_1 <= -5e+303)
		tmp = fma(D, Float64(t_0 * w0), Float64(0.5 * Float64(Float64(w0 / D) / t_0)));
	elseif (t_1 <= 0.0002)
		tmp = Float64(w0 * sqrt(Float64(1.0 - t_1)));
	else
		tmp = w0;
	end
	return tmp
end
code[w0_, M_, D_, h_, l_, d_] := N[(w0 * N[Sqrt[N[(1.0 - N[(N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[w0_, M_, D_, h_, l_, d_] := Block[{t$95$0 = N[Sqrt[N[(N[(h / l), $MachinePrecision] * N[(-0.25 * N[(N[(M / d), $MachinePrecision] * N[(M / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+303], N[(D * N[(t$95$0 * w0), $MachinePrecision] + N[(0.5 * N[(N[(w0 / D), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.0002], N[(w0 * N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], w0]]]]
w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}
\begin{array}{l}
t_0 := \sqrt{\frac{h}{\ell} \cdot \left(-0.25 \cdot \left(\frac{M}{d} \cdot \frac{M}{d}\right)\right)}\\
t_1 := {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}\\
\mathbf{if}\;t_1 \leq -5 \cdot 10^{+303}:\\
\;\;\;\;\mathsf{fma}\left(D, t_0 \cdot w0, 0.5 \cdot \frac{\frac{w0}{D}}{t_0}\right)\\

\mathbf{elif}\;t_1 \leq 0.0002:\\
\;\;\;\;w0 \cdot \sqrt{1 - t_1}\\

\mathbf{else}:\\
\;\;\;\;w0\\


\end{array}

Error

Bits error versus w0

Bits error versus M

Bits error versus D

Bits error versus h

Bits error versus l

Bits error versus d

Derivation

  1. Split input into 3 regimes
  2. if (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l)) < -4.9999999999999997e303

    1. Initial program 63.6

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Simplified61.4

      \[\leadsto \color{blue}{w0 \cdot \sqrt{1 - {\left(M \cdot \frac{D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
    3. Taylor expanded in D around inf 55.5

      \[\leadsto \color{blue}{0.5 \cdot \frac{w0}{D \cdot \sqrt{-0.25 \cdot \frac{h \cdot {M}^{2}}{\ell \cdot {d}^{2}}}} + D \cdot \left(\sqrt{-0.25 \cdot \frac{{M}^{2} \cdot h}{{d}^{2} \cdot \ell}} \cdot w0\right)} \]
    4. Simplified46.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(D, \sqrt{\left(-0.25 \cdot \left(\frac{M}{d} \cdot \frac{M}{d}\right)\right) \cdot \frac{h}{\ell}} \cdot w0, 0.5 \cdot \frac{\frac{w0}{D}}{\sqrt{\left(-0.25 \cdot \left(\frac{M}{d} \cdot \frac{M}{d}\right)\right) \cdot \frac{h}{\ell}}}\right)} \]

    if -4.9999999999999997e303 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l)) < 2.0000000000000001e-4

    1. Initial program 0.1

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]

    if 2.0000000000000001e-4 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l))

    1. Initial program 63.1

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Simplified60.2

      \[\leadsto \color{blue}{w0 \cdot \sqrt{1 - {\left(M \cdot \frac{D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
    3. Taylor expanded in M around 0 16.2

      \[\leadsto \color{blue}{w0} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification7.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell} \leq -5 \cdot 10^{+303}:\\ \;\;\;\;\mathsf{fma}\left(D, \sqrt{\frac{h}{\ell} \cdot \left(-0.25 \cdot \left(\frac{M}{d} \cdot \frac{M}{d}\right)\right)} \cdot w0, 0.5 \cdot \frac{\frac{w0}{D}}{\sqrt{\frac{h}{\ell} \cdot \left(-0.25 \cdot \left(\frac{M}{d} \cdot \frac{M}{d}\right)\right)}}\right)\\ \mathbf{elif}\;{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell} \leq 0.0002:\\ \;\;\;\;w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \]

Reproduce

herbie shell --seed 2022178 
(FPCore (w0 M D h l d)
  :name "Henrywood and Agarwal, Equation (9a)"
  :precision binary64
  (* w0 (sqrt (- 1.0 (* (pow (/ (* M D) (* 2.0 d)) 2.0) (/ h l))))))