Average Error: 13.9 → 8.7
Time: 17.3s
Precision: binary64
Cost: 46916
\[ \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}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;w0 \cdot {\left({\left(e^{0.16666666666666666}\right)}^{\left(\mathsf{fma}\left(-2, -\log D, \log \left(-0.25 \cdot \left(\frac{h}{\ell} \cdot \left(\frac{M}{d} \cdot \frac{M}{d}\right)\right)\right)\right)\right)}\right)}^{3}\\ \mathbf{elif}\;t_0 \leq -1 \cdot 10^{-27}:\\ \;\;\;\;w0 \cdot \sqrt{1 - t_0}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 + -0.25 \cdot \frac{D \cdot \frac{h}{\frac{d}{M}}}{\frac{\ell}{D \cdot \frac{M}{d}}}}\\ \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))))
   (if (<= t_0 (- INFINITY))
     (*
      w0
      (pow
       (pow
        (exp 0.16666666666666666)
        (fma -2.0 (- (log D)) (log (* -0.25 (* (/ h l) (* (/ M d) (/ M d)))))))
       3.0))
     (if (<= t_0 -1e-27)
       (* w0 (sqrt (- 1.0 t_0)))
       (*
        w0
        (sqrt
         (+ 1.0 (* -0.25 (/ (* D (/ h (/ d M))) (/ l (* D (/ M d))))))))))))
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 tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = w0 * pow(pow(exp(0.16666666666666666), fma(-2.0, -log(D), log((-0.25 * ((h / l) * ((M / d) * (M / d))))))), 3.0);
	} else if (t_0 <= -1e-27) {
		tmp = w0 * sqrt((1.0 - t_0));
	} else {
		tmp = w0 * sqrt((1.0 + (-0.25 * ((D * (h / (d / M))) / (l / (D * (M / d)))))));
	}
	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))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(w0 * ((exp(0.16666666666666666) ^ fma(-2.0, Float64(-log(D)), log(Float64(-0.25 * Float64(Float64(h / l) * Float64(Float64(M / d) * Float64(M / d))))))) ^ 3.0));
	elseif (t_0 <= -1e-27)
		tmp = Float64(w0 * sqrt(Float64(1.0 - t_0)));
	else
		tmp = Float64(w0 * sqrt(Float64(1.0 + Float64(-0.25 * Float64(Float64(D * Float64(h / Float64(d / M))) / Float64(l / Float64(D * Float64(M / d))))))));
	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]}, If[LessEqual[t$95$0, (-Infinity)], N[(w0 * N[Power[N[Power[N[Exp[0.16666666666666666], $MachinePrecision], N[(-2.0 * (-N[Log[D], $MachinePrecision]) + N[Log[N[(-0.25 * N[(N[(h / l), $MachinePrecision] * N[(N[(M / d), $MachinePrecision] * N[(M / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -1e-27], N[(w0 * N[Sqrt[N[(1.0 - t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(1.0 + N[(-0.25 * N[(N[(D * N[(h / N[(d / M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(l / N[(D * N[(M / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
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}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;w0 \cdot {\left({\left(e^{0.16666666666666666}\right)}^{\left(\mathsf{fma}\left(-2, -\log D, \log \left(-0.25 \cdot \left(\frac{h}{\ell} \cdot \left(\frac{M}{d} \cdot \frac{M}{d}\right)\right)\right)\right)\right)}\right)}^{3}\\

\mathbf{elif}\;t_0 \leq -1 \cdot 10^{-27}:\\
\;\;\;\;w0 \cdot \sqrt{1 - t_0}\\

\mathbf{else}:\\
\;\;\;\;w0 \cdot \sqrt{1 + -0.25 \cdot \frac{D \cdot \frac{h}{\frac{d}{M}}}{\frac{\ell}{D \cdot \frac{M}{d}}}}\\


\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. Applied egg-rr61.4

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

      \[\leadsto w0 \cdot {\color{blue}{\left(e^{0.16666666666666666 \cdot \left(\log \left(-0.25 \cdot \frac{{M}^{2} \cdot h}{{d}^{2} \cdot \ell}\right) + -2 \cdot \log \left(\frac{1}{D}\right)\right)}\right)}}^{3} \]
    4. Simplified51.3

      \[\leadsto w0 \cdot {\color{blue}{\left({\left(e^{0.16666666666666666}\right)}^{\left(\mathsf{fma}\left(-2, -\log D, \log \left(-0.25 \cdot \left(\frac{h}{\ell} \cdot \left(\frac{M}{d} \cdot \frac{M}{d}\right)\right)\right)\right)\right)}\right)}}^{3} \]

    if -inf.0 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l)) < -1e-27

    1. Initial program 0.5

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

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

    1. Initial program 6.9

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

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

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

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

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

      \[\leadsto w0 \cdot \sqrt{1 - 0.25 \cdot \left(\frac{D}{\frac{\ell}{D}} \cdot \frac{h}{\color{blue}{\frac{d}{M} \cdot \frac{d}{M}}}\right)} \]
    7. Applied egg-rr4.0

      \[\leadsto w0 \cdot \sqrt{1 - 0.25 \cdot \color{blue}{\frac{D \cdot \frac{h}{\frac{d}{M}}}{\frac{\ell}{D} \cdot \frac{d}{M}}}} \]
    8. Applied egg-rr2.4

      \[\leadsto w0 \cdot \sqrt{1 - 0.25 \cdot \frac{D \cdot \frac{h}{\frac{d}{M}}}{\color{blue}{\frac{\ell}{\frac{M}{d} \cdot D}}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification8.7

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

Alternatives

Alternative 1
Error9.3
Cost28296
\[\begin{array}{l} t_0 := {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}\\ t_1 := \frac{h}{\frac{d}{M}}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;w0 \cdot \sqrt{1 + -0.25 \cdot \frac{t_1}{\frac{d}{M} \cdot \frac{\frac{\ell}{D}}{D}}}\\ \mathbf{elif}\;t_0 \leq -1 \cdot 10^{-27}:\\ \;\;\;\;w0 \cdot \sqrt{1 - t_0}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 + -0.25 \cdot \frac{D \cdot t_1}{\frac{\ell}{D \cdot \frac{M}{d}}}}\\ \end{array} \]
Alternative 2
Error9.1
Cost14344
\[\begin{array}{l} t_0 := w0 \cdot \sqrt{1 + -0.25 \cdot \frac{D \cdot \frac{h}{\frac{d}{M}}}{\frac{\ell}{D \cdot \frac{M}{d}}}}\\ \mathbf{if}\;\frac{h}{\ell} \leq -\infty:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\frac{h}{\ell} \leq -4 \cdot 10^{-67}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot {\left(\left(M \cdot D\right) \cdot \frac{0.5}{d}\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error11.8
Cost8008
\[\begin{array}{l} \mathbf{if}\;d \leq -9.2 \cdot 10^{-7}:\\ \;\;\;\;w0\\ \mathbf{elif}\;d \leq 1.3545223481716942 \cdot 10^{+116}:\\ \;\;\;\;w0 \cdot \sqrt{1 + -0.25 \cdot \frac{\frac{D \cdot \left(M \cdot h\right)}{d}}{\frac{d}{M} \cdot \frac{\ell}{D}}}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \]
Alternative 4
Error10.1
Cost7744
\[w0 \cdot \sqrt{1 + -0.25 \cdot \frac{D \cdot \frac{h}{\frac{d}{M}}}{\frac{\ell}{D \cdot \frac{M}{d}}}} \]
Alternative 5
Error13.5
Cost64
\[w0 \]

Error

Reproduce

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