Average Error: 14.1 → 7.9
Time: 7.9s
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 := {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}\\ t_1 := \sqrt{\frac{h}{\ell} \cdot \left(-0.25 \cdot \left(\frac{M}{d} \cdot \frac{M}{d}\right)\right)}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(D, t_1 \cdot w0, 0.5 \cdot \frac{\frac{w0}{D}}{t_1}\right)\\ \mathbf{elif}\;t_0 \leq 0.0002:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot {\left(\frac{0.5}{\frac{d}{M \cdot D}}\right)}^{2}}\\ \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 (* (pow (/ (* M D) (* 2.0 d)) 2.0) (/ h l)))
        (t_1 (sqrt (* (/ h l) (* -0.25 (* (/ M d) (/ M d)))))))
   (if (<= t_0 (- INFINITY))
     (fma D (* t_1 w0) (* 0.5 (/ (/ w0 D) t_1)))
     (if (<= t_0 0.0002)
       (* w0 (sqrt (- 1.0 (* (/ h l) (pow (/ 0.5 (/ d (* M D))) 2.0)))))
       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 = pow(((M * D) / (2.0 * d)), 2.0) * (h / l);
	double t_1 = sqrt(((h / l) * (-0.25 * ((M / d) * (M / d)))));
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = fma(D, (t_1 * w0), (0.5 * ((w0 / D) / t_1)));
	} else if (t_0 <= 0.0002) {
		tmp = w0 * sqrt((1.0 - ((h / l) * pow((0.5 / (d / (M * D))), 2.0))));
	} 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 = Float64((Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l))
	t_1 = sqrt(Float64(Float64(h / l) * Float64(-0.25 * Float64(Float64(M / d) * Float64(M / d)))))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = fma(D, Float64(t_1 * w0), Float64(0.5 * Float64(Float64(w0 / D) / t_1)));
	elseif (t_0 <= 0.0002)
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(h / l) * (Float64(0.5 / Float64(d / Float64(M * D))) ^ 2.0)))));
	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[(N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(h / l), $MachinePrecision] * N[(-0.25 * N[(N[(M / d), $MachinePrecision] * N[(M / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(D * N[(t$95$1 * w0), $MachinePrecision] + N[(0.5 * N[(N[(w0 / D), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.0002], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[Power[N[(0.5 / N[(d / N[(M * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $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 := {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}\\
t_1 := \sqrt{\frac{h}{\ell} \cdot \left(-0.25 \cdot \left(\frac{M}{d} \cdot \frac{M}{d}\right)\right)}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(D, t_1 \cdot w0, 0.5 \cdot \frac{\frac{w0}{D}}{t_1}\right)\\

\mathbf{elif}\;t_0 \leq 0.0002:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot {\left(\frac{0.5}{\frac{d}{M \cdot D}}\right)}^{2}}\\

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


\end{array}

Error

Derivation

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

    1. Initial program 64.0

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

      \[\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 56.4

      \[\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. Simplified48.4

      \[\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 -inf.0 < (*.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}} \]
    2. Simplified0.9

      \[\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 0.1

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

      \[\leadsto w0 \cdot \sqrt{1 - {\color{blue}{\left(\frac{0.5}{\frac{d}{D \cdot M}}\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.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell} \leq -\infty:\\ \;\;\;\;\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 - \frac{h}{\ell} \cdot {\left(\frac{0.5}{\frac{d}{M \cdot D}}\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \]

Reproduce

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